HP 3000 Manuals

Format Specifications [ HP FORTRAN 77/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Programmer's Guide

Format Specifications 

This section describes the format and edit descriptors in detail.


NOTE In the examples for this chapter, Delta represents a blank space and _ represents eight binary zeros.
Integer Format Descriptors: I, O, K, @, Z The I, O, K, @, and Z format descriptors provide formatting for integer data types. The general specifications are: I[w[.m]] O[w[.m]] K[w[.m]] @[w[.m]] Z[w[.m]] where w is the width of the field, and m is the minimum number of digits to be output; if m is not used, a value of 1 is assumed. The Iw.m form is only used for output; on input, the m is ignored. The Input Field. The Iw format descriptor interprets the next w positions of the input record. You can omit the plus sign for positive integers; you must not have a decimal point in the input record. The input statement: READ(5, '(I3)') int can read any of the following input values: --------------------------------------------- | | | | Input Field | Equivalent Assignment | | | | --------------------------------------------- | | | | 12 | int = 12 | | | | | +12 | int = 12 | | | | | -12 | int = -12 | | | | | Delta 123 | int = 12 | | | | | +123 | int = 12 | | | | | -123 | int = -12 | | | | | 123456 | int = 123 | | | | | uparrow | | | | | | First column | | | of input field | | | | | --------------------------------------------- The O, K, and @ input field can have up to 11 octal digits; the O, K, and @ descriptors are interchangeable. The octal digits are: 0, 1, 2, 3, 4, 5, 6, and 7; plus or minus signs are not allowed. If any nondigit appears, (other than a blank), an error occurs. The variable receiving the octal value must be an INTEGER*2 or INTEGER*4 data type. The input statement: READ(5, '(O3)') ioctal can read any of the following input values: --------------------------------------------------------------------- | | | | Input Field | Equivalent Assignment | | | | --------------------------------------------------------------------- | | | | 123456 | ioctal = 83 (decimal equivalent of 123 octal)| | | | | 1234 | ioctal = 83 | | | | | 123 | ioctal = 83 | | | | | 12 | ioctal = 10 (decimal equivalent of 12 octal) | | | | | uparrow | | | | | | First column | | | of input field | | | | | --------------------------------------------------------------------- The Z input field contains these hexadecimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A or a, B or b, C or c, D or d, E or e, and F or f. If the number of digits is too long for the integer variable, undefined results occur. If a nonhexadecimal digit is used, an error occurs; no leading plus or minus sign on input is allowed. The variable receiving the hexadecimal input must be an INTEGER*2 or INTEGER*4 data type. The input statement: READ(5, '(Z3)') ihex can read any of the following input values: ------------------------------------------------------------------- | | | | Input Field | Equivalent Assignment | | | | ------------------------------------------------------------------- | | | | 12abcd | ihex = 298 (decimal equivalent of 123 hex) | | | | | 12ab | ihex = 298 | | | | | 12a | ihex = 298 | | | | | 12 | ihex = 18 (decimal equivalent of 12 hex) | | | | | 1 | ihex = 1 (decimal equivalent of 1 hex) | | | | | uparrow | | | | | | First column | | | of input field | | | | | ------------------------------------------------------------------- The Output Field. The I, O, K, @, and Z descriptors each produce a distinctive output format. The I and Z Output Format The I and Z format descriptors handle the output field in the same way. The I descriptor writes numbers in an integer format; the Z descriptor writes hexadecimal data. For the I or Z descriptor, if the field width w is smaller than the number of digits needed to represent the value, the field is filled with asterisks. If the field length w is greater than the length of the integer value, the integer is output right-justified in the field, with blanks on the left. For integer values, the output of a negative number requires a print position for the negative sign. If the Iw.m form is used and the output value is less than m positions, the value is preceded by zeros. If m equals zero, a 0 value is output as all blanks. For the Z descriptor, the optional m value specifies a minimum number of digits to be output, forcing leading zeros as necessary up to the first non-zero digit. The O, K, and @ Output Format The O, K, and @ format descriptors write octal data. The output field can have up to 6 octal digits for INTEGER*2 data and can have up to 11 digits for INTEGER*4 data. The octal digits are: 0, 1, 2, 3, 4, 5, 6, and 7; plus or minus signs are not displayed. If the field width w is smaller than the length of the integer value, the field is filled with asterisks. If the field length w is greater than the digits in the integer value, the integer is output right-justified in the field, with zeros on the left. The optional m value specifies a minimum number of digits to be output, forcing leading zeros as necessary up to the first non-zero digit. The following program compares the output generated by the I, O, and Z formats. PROGRAM int_outputs INTEGER*4 int int = 12 WRITE(6, '(11X, "I9", 15X, "O11", 15X, "Z9")') DO i = 1, 9 WRITE(6,100) int, int, int IF (i .NE. 9) int = int * 10 END DO 100 FORMAT (6X, "{", I9, "}", 6X, "{", O11, "}", 6X, "{", Z9, "}") STOP END The output from the program is as follows: I9 O11 Z9 { 12} { 14} { C} { 120} { 170} { 78} { 1200} { 2260} { 4B0} { 12000} { 27340} { 2EE0} { 120000} { 352300} { 1D4C0} { 1200000} { 4447600} { 124F80} { 12000000} { 55615400} { B71B00} {120000000} { 711607000} { 7270E00} {*********} {10741506000} { 47868C00} Real Format Descriptors: F, D, E, G The F, D, E, and G format descriptors provide formatting for REAL*4, REAL*8, REAL*16, COMPLEX*8 and COMPLEX*16 data types. Complex values are treated as pairs of real values. The general specifications are: F[w.d] E[w.d[Ee]] D[w.d] G[w.d[Ee]] where w is the total field width, d is the number of digits after the decimal point, and e is the number of digits for the exponent. The Input Field. The F, D, E, and G format descriptors handle the input field in the same way. The input field can consist of a REAL*4, REAL*8, or REAL*16 number in either floating-point or exponential form. If a decimal point is not supplied, it will be inserted d digits from the rightmost digit. The F descriptor is used most often, although any one of the format descriptors can be used for input of real data types. The input statement READ(5, '(F6.2)') a can read any of the following input values: ------------------------------------------------------- | | | | Input Field | Equivalent Assignment | | | | ------------------------------------------------------- | | | | Delta 123 | a = 1.23 | | | | | 123456 | a = 1234.56 | | | | | 12345678 | a = 1234.56 | | | | | +12345678 | a = 123.45 | | | | | 12.345 | a = 12.345 | | | | | -123.45 | a = -123.4 | | | | | 1234E3* | a = 12340.0 | | | | | 123E3 | a = 1230.0 | | | | | 123E-3 | a = 0.00123 | | | | | 12.E-3 | a = 0.120 | | | | | 1234D3 | a = 0.1234D+05 | | | | | 123.D3 | a = 0.123D+06 | | | | | blanks | a = 0.0 | | | | | uparrow | | | | | | First column | | | of input field | | | | | ------------------------------------------------------- * 1234E3--> 1234000--> 12340.00 If Ee falls within w field (Fw.d) then the number is expanded and the decimal is placed before the second digit from the right. 1) 1234E24 --> 1234E2 --> 123400 --> 1234.00 2) 1234E8 --> 1234E8 --> 1234 x 108 --> 1234 x 106 --> 1234E+9 3) 12345E8 --> 12345E --> 12345 --> 123.45 The Output Field. The F, E, D, and G descriptors each produce a distinctive output format. The F Output Format The F format descriptor writes numbers in a fixed-point format. That is, the decimal point can be fixed d places from the right of the number. The field width w should always be at least two greater than the total number of digits you want printed; this leaves room for a sign and a decimal point. The E Output Format The E format descriptor writes any floating-point type numbers in exponential format. The number is printed in normalized floating-point format; that is, the decimal point is moved to the left of the number. The letter E is printed before the exponent, which consists of a sign and two digits. The optional e specification in the Ew.dEe format changes the field width allocated for the exponent. The field width is two places if Ee is omitted. The D Output Format The D format descriptor writes any floating-point type numbers in exponential format. The D descriptor is the same as the E format descriptor. On D output format, the exponent character will always be the letter E. The G Output Format The G format descriptor writes numbers in either floating-point or exponential format, depending on the size of the number. The Gw.d format treats the d specification as the total number of significant digits to print. If possible, the number is printed as a floating-point number and the place where the exponent goes is padded with blanks. Otherwise, the number is printed in exponential form. The best way to see how the G format works is to print a column of numbers of various sizes. The numbers are placed in the field so that the numbers without an exponent line up under the numbers that do have an exponent. The following example compares the output produced by the F13.7, E13.7, and G13.7 formats. A field width of 13 was selected to represent the seven significant digits of the REAL*4 data, plus six overhead characters (sign, decimal point, E, sign, and two digits for the exponent). Because numbers are normalized for exponential format, seven digits after the decimal point must be specified to have all significant digits printed. PROGRAM real_formats * This program shows a comparison of the F, E, and G * format descriptors: REAL*4 realvalue realvalue = 0.1234567E-3 WRITE(6, '(12X, "F13.7", 16X, "E13.7", 16X, "G13.7")') DO i = 1, 14 WRITE(6,100) realvalue, realvalue, realvalue realvalue = realvalue * 10.0 END DO 100 FORMAT (6X,"{",F13.7,"}",6X,"{",E13.7,"}",6X,"{",G13.7,"}") END The output of the above program follows: F13.7 E13.7 G13.7 { .0001234} { .1234567E-03} { .1234567E-03} { .0012345} { .1234567E-02} { .1234567E-02} { .0123456} { .1234567E-01} { .1234567E-01} { .1234567} { .1234567E+00} { .1234567 } { 1.2345669} { .1234567E+01} { 1.234567 } { 12.3456688} { .1234567E+02} { 12.34567 } { 123.4566956} { .1234567E+03} { 123.4567 } { 1234.5668945} { .1234567E+04} { 1234.567 } {12345.6699219} { .1234567E+05} { 12345.67 } {*************} { .1234567E+06} { 123456.7 } {*************} { .1234567E+07} { 1234567. } {*************} { .1234567E+08} { .1234567E+08} {*************} { .1234567E+09} { .1234567E+09} {*************} { .1234567E+10} { .1234567E+10} Numbers are always right-justified into the output field, with the exception of non-exponential data formatted by the G descriptor, as shown above. Note that in the list printed by the F descriptor, only the leftmost seven digits of the number are significant. Also, positive numbers over 99999.99 cannot be printed in F13.7 format because eight places are taken up by the seven fractional digits and the decimal point, leaving only five places for digits to the left of the decimal point. If the numbers are negative, the sign takes up another one of these places and the minimum negative number becomes -9999.999. When a number is out of range for the specified field, the field is filled with asterisks indicating a range of more than six orders of magnitude. Character Format Descriptors: A, R The A and R format descriptors define fields for character data. The forms of the descriptors are: A[w] R[w] where w is the width of the field. If the field width w is omitted, the width of the field is equal to the length of the variable on input, or equal to the length of the character expression on output. The purpose of format descriptors is to convert characters between their internal representation and a string of ASCII characters. Character data, however, is represented internally in ASCII format; therefore, the A format descriptor merely specifies a field for input or output characters. If the A format descriptor is used without the w field width specification, the field width is automatically selected to be the same size as the character variable in the I/O list. For example, the program PROGRAM char_data CHARACTER*10 first, last first = 'Jane' last = 'Smith' WRITE(6, '(1X, "My name is ", 2A)') first, last WRITE(6, '(1X, "My name is ", 2A)') first(1:5), last(1:6) END writes the following: My name is Jane Delta Delta Delta Delta Delta Delta Smith Delta Delta Delta Delta Delta My name is Jane Delta Smith Delta The first WRITE statement effectively uses a 2A10 format descriptor because the variables first and last were declared to be 10 bytes in length. The second WRITE statement effectively uses A5, A6 format descriptors because the substrings specified in the output variable list are 5 and 6 bytes in length, respectively. The Rw format descriptor is an HP extension to the ANSI 77 Standard, which provides compatibility with other versions of FORTRAN. The difference between Aw and Rw occurs only when the specified field width w is less than the number of characters specified by the I/O variable. The differences are as follows: * Using the Aw format descriptor, input data is left-justified into the input variable. The remaining positions are blank-filled. On output, the leftmost characters of the output variable are written. This is shown in Figure 2-1 .
[FFN3]
Figure 2-1. The Aw Format Descriptor * Using the Rw format descriptor, input data is right-justified into the input variable. The initial positions are blank-filled. (ASCII null characters are represented by a byte of all blanks.) On output, the rightmost characters of the output variable are written. This is shown in Figure 2-2 .
[FFN4]
Figure 2-2. The Rw Format Descriptor If the specified field width w is greater than the number of characters specified by the I/O variable, the Aw and Rw format descriptors behave in the same way. Input data is taken from the rightmost characters of the input field. Output data is right-justified into the output field. This is shown in Figure 2-3 .
[FFN5]
Figure 2-3. The Aw and Rw Format Descriptors The Input Field. With the A descriptor, if the field width w is less than the length of the character variable, the characters are stored left-justified in the variable with the remainder of the variable filled with blank characters. With the R descriptor, if the field width w is less than the length of the character variable, the characters are stored right-justified in the variable, preceded by null characters. For example, the program: PROGRAM widthsmaller_input CHARACTER char1*10 ! Declare char1 to be 10 characters CHARACTER char2*10 ! Declare char2 to be 10 characters READ (5, '(A3)') char1 ! Read only 3 characters READ (5, '(R3)') char2 ! Read only 3 characters WRITE (6, '(1X, A)') char1 WRITE (6, '(1X, R)') char2 END with the input: ABC ABC writes the following: ABC ABC Note that the null characters are not printable. The actual value stored in char1 is: ABC Delta Delta Delta Delta Delta Delta Delta where Delta represents a blank space. The value stored in char2 is: _______ABC where _ represents eight binary zeros, or the ASCII null character (the null character is equivalent to CHAR (0)). With the A or R descriptor, if the field width w is larger than the length of the character variable, the rightmost characters are stored and the remaining characters are ignored. For example, the program below shows how character data is input. PROGRAM widthlarger_input CHARACTER char1*5 ! Declare char1 to be 5 characters CHARACTER char2*5 ! Declare char2 to be 5 characters READ (5, '(A10)') char1 ! Read 10 characters READ (5, '(R10)') char2 ! Read 10 characters WRITE (6, '(1X, A)') char1 ! Print what was stored in char1 WRITE (6, '(1X, R)') char2 ! Print what was stored in char2 END If the input to this program is: ABCDEFGHIJ ABCDEFGHIJ the value stored in char1 and char2 is: FGHIJ The Output Field. With the A descriptor, if the field width w is less than the length of the character variable, the leftmost characters in the variable are output. With the R descriptor, if the field width w is less than the length of the character variable, the rightmost characters in the variable are output. For example, the program: PROGRAM widthsmaller_output CHARACTER char*10 ! Declare char to be 10 characters char = 'ABCDEFGHIJ' WRITE (6, '(1X, A3)') char ! Write only 3 characters WRITE (6, '(1X, R3)') char ! Write only 3 characters END produces the following output: ABC HIJ With the A or R descriptor, if the field width w is greater than the length of the character variable, the characters are right-justified in the field, with blanks on the left. For example, the program: PROGRAM widthgreater_output CHARACTER char*5 ! Assign char to be 5 characters char = 'ABCDE' WRITE (6, '(1X, A10)') char ! Write 10 characters WRITE (6, '(1X, R10)') char ! Write 10 characters END produces the following output: Delta Delta Delta Delta Delta ABCDE Delta Delta Delta Delta Delta ABCDE The program below also shows how the A and R format descriptors differ. The program uses the input value abcdef. PROGRAM char_ex CHARACTER*3 alpha3, alpha3a CHARACTER*9 alpha9, alpha9a C INPUT using Aw and Rw format descriptors: C Each READ statement gets this 6-character input field: abcdef C Input Statement: Equivalent assignment: READ(5, '(A6)') alpha3 ! alpha3 = 'def' READ(5, '(R6)') alpha3 ! alpha3 = 'def' READ(5, '(A6)') alpha9 ! alpha9 = 'abcdef Delta Delta Delta ' READ(5, '(R6)') alpha9 ! alpha9 = '###abcdef' C (^ represents a blank character) C (# represents a null character) C OUTPUT using Aw and Rw format descriptors: alpha3a = 'abc' ! Assign data for alpha9a = 'abcdefghi' ! output examples C Output Statement: Characters written: WRITE(6, '(1X, A6)') alpha3a ! Delta Delta Delta abc WRITE(6, '(1X, R6)') alpha3a ! Delta Delta Delta abc C ( Delta represents a blank character) WRITE(6, '(1X, A6)') alpha9a ! abcdef WRITE(6, '(1X, R6)') alpha9a ! defghi END The A[w] and R[w] character format descriptors can be used with integer and real data types by specifying the NOSTANDARD compiler directive. The data is output in reverse order, starting at the right and progressing to the left. For example, the following program: program demo c Output numeric data with character format using an external write. INTEGER*4 i4 i4 = 4Habcd WRITE(6,100) i4 100 FORMAT(a) STOP END produces the following output if $NOSTANDARD or $NOSTANDARD IO is specified: dcba or produces the following output if $NOSTANDARD or $NOSTANDARD IO is not specified: abcd For more information refer to the HP FORTRAN 77/iX Reference. Logical Format Descriptor: L The L format descriptor defines fields for logical data. The form of the descriptor is: L[w] where w is the width of the field. The Input Field. If the first nonblank characters in the input field are T or .T, the value .TRUE. is stored in the logical variable. If the first nonblank characters in the input field are F or .F, the value .FALSE. is stored in the logical variable. If the first nonblank characters are not T, .T, F, or .F, an error occurs. Note that the lowercase letters t and f are also allowed. For example, the program below reads logical values: PROGRAM l_format_input LOGICAL logical1, logical2 READ (5, '(L5)') logical1 READ (5, '(L2)') logical2 PRINT *, logical1, logical2 END If the input to this program is: Delta Delta Delta T Delta F1 the value stored in logical1 is .TRUE. and the value in logical2 is .FALSE.. The Output Field. The letter T or F is right-justified in the output field depending on whether the value of the list item is .TRUE. or .FALSE.. For example, the program: PROGRAM l_format_output LOGICAL logical1, logical2 logical1 = .FALSE. logical2 = .TRUE. WRITE (6, '(1X, L5)') logical1 WRITE (6, '(1X, L2)') logical2 END produces the following output: Delta Delta Delta Delta F Delta T Repeating Specifications The format descriptors can be repeated by prefixing the descriptor with a positive, unsigned integer specifying the number of repetitions. For example, the statement: 100 FORMAT (3F10.5, 2I5) is equivalent to: 100 FORMAT (F10.5, F10.5, F10.5, I5, I5) A group of descriptors can be repeated by enclosing the group with parentheses and prefixing the group with a positive, unsigned integer. For example, the statement: 100 FORMAT (I5, 3(F10.5,2X)) is equivalent to: 100 FORMAT (I5, F10.5, 2X, F10.5, 2X, F10.5, 2X) Correspondence Between the I/O List and Format Descriptors Usually there is a one-to-one correspondence between the items in the I/O list and the accompanying format descriptors. If, however, there are fewer items in the I/O list than corresponding format descriptors, the remaining format descriptors are ignored. For example, the statements: a = 5.0 b = 7.0 WRITE(6, '(1X, F6.1, F6.2, " id = ", I5, I2)') a, b do not use the I5 and the I2 descriptors. However, the "id=" character constant is printed as follows: 5.0 7.00 id= The extra characters can be suppressed by using the colon edit descriptor. For example, the statement: WRITE(6, '(1X, F6.1, F6.2, :, " id= ", I5, I2)') a, b omits the trailing characters from the output line as follows: 5.0 7.00 See the colon edit descriptor description later in this chapter for further examples. When there are more items in the output list than corresponding format descriptors, the FORMAT statement is reused from the beginning. If the FORMAT statement contains nested (parenthesized) format descriptors, reuse begins with the rightmost nested group at the first level. For example, the statements below show what portion of the FORMAT statement is reused. WRITE(6,100) i, a, j, i1, a1, j1, i2, a2, j2 100 FORMAT(I3, 2X, F9.2, 2X, I5) uparrow ------reused------ uparrow WRITE(6, 200) i, a, j, a1, j1, a2, j2, a3, j3 200 FORMAT(I3, 2X, (F9.2, (2X, I5))) uparrow ---reused-- uparrow WRITE(6,300) i, a, j, j1, j2, j3, j4, j5, j6 300 FORMAT(I3, 2X, (F9.2, 2X), (I5)) uparrow uparrow reused The format statements above treat the first three data items i, a, and j in each I/O list the same. However, the reused portion of the format specification is altered by nested format specifications. The first FORMAT statement shows that, in the absence of nested format descriptors, the entire list of format descriptors is reused. The second FORMAT statement shows how the reused portion of the FORMAT statement can contain additional nested specifications. The third FORMAT statement shows that not all nested format specifications are reused. A program that does not have a one-to-one match between list elements and format descriptors is shown below: PROGRAM unmatched READ(5, 100) a, i, a1, i1, a2, i2, a3 100 FORMAT(F4.1, (I5, F5.1)) WRITE(6, 100) a, i, a1, i1, a2, i2, a3 END The program reads the variables as follows: a is input with format F4.1, i is input with format I5, and a1 is input with format F5.1. Then, the number of format descriptors is exhausted. Flow control returns to the specification (I5, F5.1) and i1 is input with format I5 and a2 is input with format F5.1. Then, the number of format descriptors is again exhausted. As before, flow control returns to the specification (I5, F5.1) and i2 is input with format I5 and a3 is input with format F5.1. Monetary Format Descriptor: M The Mw.d format descriptor defines a field for a real number without an exponent (fixed-point) written in monetary form. The general specification is: M[w.d] where w is the width of the field and d is the number of digits after the decimal point. The Input Field. On input, the Mw.d format descriptor causes interpretation of the next w positions of the input record as a real number without an exponent. The field width is expected (but not required) to have a dollar sign and comma(s) embedded in the data as described for Mw.d output (the dollar sign and commas are ignored). If commas are used, the usage must be consistent; that is, commas must occur every three digits of the nonfractional part of the input value. The field width can include "$", "&", and ",". The number is converted to an internal representation value for the variable (list element) currently using the format descriptor. The input statement: READ (5, '(M10.2)')a can read any of the following input values: ------------------------------------------------- | | | | Input | Assignment | | | | ------------------------------------------------- | | | | 123.45 | a = 123.45 | | | | ------------------------------------------------- | | | | $1234.56 | a = 1234.56 | | | | ------------------------------------------------- | | | | $1,234,567 | a = 12345.67 | | | | ------------------------------------------------- | | | | $12,345.4 | a = 12345.40 | | | | ------------------------------------------------- | | | | 1,234,567.99 | a = 1234567.00 | | | | ------------------------------------------------- | | | | -1234.56 | a = -1234.56 | | | | ------------------------------------------------- | | | | -$123.75 | a = -123.75 | | | | ------------------------------------------------- | | | | -$1,357.91 | a = -1357.91 | | | | ------------------------------------------------- | | | | 1,234 | a = 12.34 | | | | ------------------------------------------------- | | | | blanks | a = .00 | | | | ------------------------------------------------- The Output Field. On output, the Mw.d format descriptor causes output of a numeric value in ASCII character fixed-point form, right-justified with commas and a dollar sign. The least significant digit (position d) is rounded. If needed, a leading minus sign is printed before the dollar sign. In addition to the number of numeric digits, the field width w must allow for the number of commas expected plus four characters to hold the sign, the dollar sign, the decimal point, and a rollover digit (if necessary). If w is greater than the number of positions required for the output value, the output is right-justified in the field with blank spaces to the left. If w is less than the number of positions required, the output value of the entire field is filled with asterisks. PROGRAM m_format C This program demonstrates output with the monetary format REAL*4 money money = 12345.67 WRITE (6, '(25X, "M17.2")') DO i = 1,14 WRITE (6,100) money money = money * 3 END DO 100 FORMAT (18X, "{", M17.2, "}") STOP END The above program produces the following output: M17 2 { $12,345.67} { $37,037.01} { $111,111.02} { $333,333.06} { $999,999.19} { $2,999,997.50} { $8,999,992.00} { $26,999,976.00} { $80,999,928.00} { $242,999,776.00} { $728,999,296.00} {$2,186,997,760.00} {$6,560,993,280.00} {*****************} Numeration Format Descriptor: N The Nw.d field descriptor defines a field for a real number without an exponent (fixed-point) written in numeration form (that is, with commas, which are then ignored, in the input field). The general specification is: N[w.d] where w is the width of the field and d is the number of digits after the decimal point. The Input Field. On input, the Nw.d field descriptor causes interpretation of the next w positions of the input record as a real number without an exponent. The field width is expected (but not required) to have commas embedded in the data as described for Nw.d output (the commas are ignored). If commas are used, the usage must be consistent; that is, commas must occur every three digits of the nonfractional part of the input value. The number is converted to an internal representation value for the variable (list element) currently using the field descriptor. The input statement: READ (5, '(N10.2)') can read any of the following input values: ------------------------------------------------- | | | | Input | Assignment | | | | ------------------------------------------------- | | | | 123.56 | a = 123.56 | | | | ------------------------------------------------- | | | | 12,345.66 | a = 12345.66 | | | | ------------------------------------------------- | | | | 1,224,666 | a = 12246.66 | | | | ------------------------------------------------- | | | | -13,555.87 | a = -13555.87 | | | | ------------------------------------------------- | | | | +5,987.54 | a = 5987.54 | | | | ------------------------------------------------- | | | | 1,234,567.88 | a = 1234567.00 | | | | ------------------------------------------------- | | | | 3,456.78 | a = 3456.78 | | | | ------------------------------------------------- | | | | 4,567.89 | a = 4567.89 | | | | ------------------------------------------------- | | | | blanks | a = .00 | | | | ------------------------------------------------- The Output Field. On output, the Nw.d field descriptor causes output of a numeric value in ASCII character fixed-point form, right-justified with commas. The least significant digit is rounded. If needed, a leading minus sign is printed before the most significant digit. In addition to the number of numeric digits, the field width w must allow for the number of commas expected, plus three characters to hold the sign, the decimal point, and a rollover digit (if necessary). If w is greater than the number of positions required for the output value, the output is right-justified in the field with blank spaces to the left. If w is less than the number of positions required for the output value, the entire field is filled with asterisks. PROGRAM n_format C This program demonstrates output with the numeric format REAL*4 num num = 12345.67 WRITE (6, '(25X, "N17.2")') DO i = 1,14 WRITE (6,100) num num = num * 3 END DO 100 FORMAT (18X, "{", N17.2, "}") STOP END The above program produces the following output: N17.2 { 12,345.67} { 37,037.01} { 111,111.02} { 333,333.06} { 999,999.19} { 2,999,997.50} { 8,999,992.00} { 26,999,976.00} { 80,999,928.00} { 242,999,776.00} { 728,999,296.00} { 2,186,997,760.00} { 6,560,993,280.00} {19,682,979,840.00} Processing New Lines The /, NN, NL, and $ descriptors handle the control of new lines. The / Descriptor. The / edit descriptor terminates the current line and begins processing a new input or output line. On input, a slash indicates that data will come from the next line; on output, a slash indicates that data will be written to the next line. Commas separating edit descriptors and separating consecutive slashes are not needed. For example, the following program uses the / descriptor for input and output: PROGRAM slash_edit READ (5, 100) inta, intb, reala 100 FORMAT (I5, I3/F5.3) WRITE (6, 200) inta, intb, reala 200 FORMAT *(1X, 'Integer values = ',I5,' and ',I3 // ' Real value = ',F5.3) END If the input to this program is: 12345123 1.234 the output looks like this: Integer values = 12345 and 123 Real value = 1.234 The NL, NN, or $ Descriptor. The NL, NN, or $ edit descriptor controls the carriage return at the end of an output line or record. For compatibility with other versions of FORTRAN, the $ edit descriptor is equivalent to the NN descriptor. For a detailed description, refer to the HP FORTRAN 77/iX Reference.


MPE/iX 5.0 Documentation