FORTRAN 90+: FORMATTING
Formatting the READ and WRITE functions simply requires replacing the second asterisk (READ(*,*)) with a string of CHARACTERS. The format string can be either inserted as a CHARACTER variable or parameter or as the text itself. The format for using READ and WRITE is
WRITE(*,"(format strings)") variables that are output READ(*,"(format strings)") variables that are input
Strings follow a simple format that is summed up in
- w describes the maximum length.
- m describes the minimum length.
- d describes the number of places after the decimal point.
- e describes the the number of places in an exponent.
Type | Variations | Format |
---|---|---|
INTEGER | Iw or Iw.m | |
REAL | Decimal form | Fw.d |
Exponential form | Ew.d or Ee | |
Scientific form | ESw.d or ESe | |
Engineering form | ENw.d or ENe | |
LOGICAL | Lw | |
CHARACTER | Aw | |
Positioning | Horizontal | nX |
Tabbing | Tc,TLc and TRc | |
Vertical | / | |
Others | Grouping | r(...) |
Format Scanning Control | : | |
Sign Control | S, SP and SS | |
Blank Control | BN and BZ |
INTEGERS
When using the symbol [Iw.m] to format text the first symbol [I] tells the compiler how to handle INTEGER variables. The next symbol tells the compiler the maximum number of spaces to use when writing an INTEGER. The second symbol [.m] tells the compiler the minimum number of spaces to fill with integers.
- m must be positive and equal to or less than the w symbol.
- If .m is 4 and the number is 3 digits long than the compiler will put a zero in front of your number.
- If the number is longer than the symbol .m then no change will be made to the number.
- If the format is defined as I5.5 or I5, but the number is -1234, a series of asterisks will result because there are only 5 possible spaces that must be integers so the complete number can not be printed.
LOGICALS
When using the LOGICAL symbol [Lw] to format text the first symbol [L] tells the compiler how to handle LOGICALs. The second symbol [w] tells the compiler how many spaces to use when printing the T or F for .TRUE. or .FALSE. respectively. If the w is a 5 the compiler will print 4 empty spaces followed by a T or F.
CHARACTERS
When using the CHARACTER symbol [Aw] the A describes how to write CHARACTER string. The w describes how many spaces to use when writing a CHARACTER string. If w is longer than the length of the string then extra spaces will be printed to the left of the sting. If w is shorter than the length of the string then the number of characters up to the length of w (from left to right) are printed, then the rest are truncated.
Next Page →
Next Page →