HP 3000 Manuals

INEXT'/HPINEXT [ Compiler Library/XL Reference Manual ] MPE/iX 5.0 Documentation


Compiler Library/XL Reference Manual

INEXT'/HPINEXT 

INEXT'  and HPINEXT are two names for the same utility procedure.
INEXT'/HPINEXT converts a number in storage (in one of four internal
representations) to a byte array for an output string of ASCII digits.
The internal representations are:

 *  SHORTINT
 *  REAL
 *  INTEGER
 *  LONGREAL

See the "Comments" section for more details.

Declaration 

        TYPE bytearray = PACKED ARRAY [1..N] OF CHAR;
        PROCEDURE HPINEXT  (
                  ANYVAR value      : INTEGER;
                         datatype   : SHORTINT;
                         fieldwidth : SHORTINT;
                         decplaces  : SHORTINT;
                         kind       : SHORTINT;
                         scale      : SHORTINT;
                  ANYVAR charstring : bytearray;
                     VAR error      : SHORTINT
                       )
        OPTION UNCHECKABLE_ANYVAR;
        EXTERNAL;

Attributes 

Parameters        value =          32-bit pointer (address) to the first
(Input):                          word of the internal representation to
                                  be converted.

                 datatype =       The type of internal representation:

                                        0  =  SHORTINT
                                        1  =  REAL
                                       -1  =  INTEGER
                                       -2  =  LONGREAL

                 fieldwidth =     Field width w of the ASCII string,
                                  including all special characters.  See
                                  the kind parameter description for more
                                  details.

                                  Set fieldwidth to at least decplaces+6
                                  to allow for special characters when
                                  kind equals 3 (Gw.d format) or 2 (Dw.d 
                                  format) or 1 (Ew.d format).  If a
                                  positive scale factor is also used, set
                                  fieldwidth to at least decplaces+7.

                 decplaces =      The number of fractional digits d in
                                  the ASCII string.  If decplaces is
                                  equal to zero, no fractional digits are
                                  included in the output, even though a
                                  decimal point is included.  If
                                  fieldwidth <= zero or decplaces < zero,
                                  an error is implied and error is set to
                                  -1.

                 kind =           The kind of conversion desired.  See
                                  Table 3-2 for a list of possible values
                                  of kind.

          Table 3-2.  Values of kind and Associated Formats 

---------------------------------------------------------------------------------------------
|                           |              |                                                |
|       Value of kind       |    Format    |                    Example                     |
|                           |              |                                                |
---------------------------------------------------------------------------------------------
|                           |              |                                                |
|             3             | Gw.d         | See "Comments" for more details.               |
|                           |              |                                                |
|             2             | Dw.d         | 0.12345D+04                                    |
|                           |              |                                                |
|             1             | Ew.d         | 0.12345E+04                                    |
|                           |              |                                                |
|             0             | Iw           | 1234                                           |
|                           |              |                                                |
|            -1             | Nw.d         | 1,234.5                                        |
|                           |              |                                                |
|            -2             | Mw.d         | $1,234.5                                       |
|                           |              |                                                |
|            -3             | Fw.d         | 1234.5                                         |
|                           |              |                                                |
---------------------------------------------------------------------------------------------

                 scale =          The scale factor (see "Comments" for
                                  more details).

Parameters        charstring =     Pointer to the first byte array for
(Output):                         the ASCII string output.  The result
                                  occupies the first fieldwidth
                                  characters (bytes) in this array.

                 error =          Is -1 if fieldwidth is too small for
                                  the result in the specified kind.  If
                                  decplaces < zero, or if fieldwidth <=
                                  zero, the byte array is filled with
                                  asterisks (*).  The error parameter is
                                  zero if the result is valid.

Results:                    See "Parameters (Output)" above for details.

HP FORTRAN 77/XL:           Use the $ALIAS directive to call INEXT' ; use
                            the system intrinsic statement to call
                            HPINEXT.

Errors:                     See "Parameters (Output)" above for details.

Comments 

   1.  The result charstring is an array of ASCII digits; charstring can
       also include the sign character (-), a decimal point, and an
       exponent field for kind = 1 (for the Ew.d format) or kind = 2 (for
       the Dw.d format).  Generally, the exponent field includes the
       letter E or D followed by a signed two-digit integer.  If the
       absolute value of the exponent is greater than 99, the exponent
       field appears as a signed three-digit integer (without a preceding
       E). Alternatively, charstring can include a sign character (-), a
       dollar sign for kind = -2 (for the Mw.d format) and/or commas for
       kind = -2 or -3 (for the Mw.d or Nw.d formats).  (w equals the
       parameter fieldwidth and d equals the parameter decplaces.)

   2.  To use kind = 3 (Gw.d format), set decplaces to the number of
       significant digits and set fieldwidth to decplaces+6 to allow for
       special characters.  Then, kind = 3 is used as kind = -3 or 1
       (Fw.d or Ew.d format), according to the absolute value of the
       internal representation of value intlvalue, as shown in Table 3-3.

          Table 3-3.  Gw.d Formatting Rules 

-------------------------------------------------------------------------------------------
|                                            |                                            |
|                   Value                    |                Format Used                 |
|                                            |                                            |
-------------------------------------------------------------------------------------------
|                                            |                                            |
| intlvalue < 0.1                            | Ew.d                                       |
|                                            |                                            |
| 0.1 <= intlvalue < 1                       | F(w-4).d plus 4 spaces                     |
|                                            |                                            |
| 1 < intlvalue < 101                         | F(w-4).(d-1) plus 4 spaces                 |
|                                            |                                            |
| 101  <= intlvalue < 102                      | F(w-4).(d-2) plus 4 spaces                 |
|                                            |                                            |
| 102  <= intlvalue < 103                      | F(w-4).(d-3) plus 4 spaces                 |
|                                            |                                            |
| .                                          | .                                          |
|                                            |                                            |
| .                                          | .                                          |
|                                            |                                            |
| 10(d-1)  <= intlvalue < 10d                  | F(w-4).0 plus 4 spaces                     |
|                                            |                                            |
| 10d  <= intlvalue                           | Ew.d                                       |
|                                            |                                            |
-------------------------------------------------------------------------------------------

       In general, if the number of integer digits in intlvalue is
       greater than decplaces or equal to zero, kind = 1 is used (the
       Ew.d format).

       Examples 

       The following examples show how the Gw.d format is used.

       If you specify the format G12.6 and the value of intlvalue is
       1234.5, the equivalent Fw.d format is calculated as follows:
       because 103  < intlvalue < 104 , the format used is F(w-4).(d-4)
       plus four spaces.  Therefore, in this example, the equivalent Fw.d 
       format is F8.2 plus four spaces; the value stored is ล1234.50ลลลล.

       If you specify the format G13.7 and the value of intlvalue is
       123456.7, the equivalent Fw.d format is F(w-4).(d-6).  Therefore,
       in this example, the format used is F9.1 plus four spaces; the
       value stored is ล123456.7ลลลล.

       Finally, if you specify the format G9.2 and the value of intlvalue
       is 123.4, the equivalent Ew.d format is E9.2; the value stored is
       ลล.12E+03.

   3.  The scale parameter does not affect kind = 0.  When kind = 1 or 2,
       the result string uses these factors:

        *  The internal representation value fraction is multiplied by
           10s  (where s is scale).

        *  The internal representation value exponent is reduced by
           scale.

        *  When scale is <= zero, the charstring fraction has -scale
           leading zeros, followed by decplaces + scale significant
           digits.

        *  When scale is < zero, charstring has scale significant digits
           to the left of the decimal point and (decplaces - scale) + 1
           significant digits to the right of the decimal point.

        *  The least significant digit in charstring is rounded.

       For example, if intlvalue = 1234.5, kind = 1, fieldwidth = 11, and
       decplaces = 3, the following is true:

            If scale = 0,    charstring = ลลล.123E+04
            If scale = -2,   charstring = ลลล.001E+06
            If scale = 2,    charstring = ลล12.35E+02

       When kind = -3, -2, or -1, the result charstring is the internal
       representation intlvalue multiplied by 10s  (where s is scale); the
       result is then converted.

       For example, if intlvalue = 1234.5, kind = -3, fieldwidth = 11,
       and decplaces = 3, the following is true:

            If scale = 0,  charstring = ลลล1234.500
            If scale = -2, charstring = ลลลลล12.345
            If scale = 2,  charstring = ล123450.000

       When kind = -3, the following is true:

        *  If kind = 3 (Gw.d) is used as kind = -3(Fw.d), scale has no
           effect.

        *  If kind = 3 is used as kind = 1 (Ew.d),scale affects
           charstring as described for kind = 2 or 1.

   4.  When case significant, the names for the INEXT'/HPINEXT are in
       lower case.



MPE/iX 5.0 Documentation