Format is an executable statement
This command is used to tell the computer specifically how you want your output to be displayed or how to read it. It must have a line label number before it. This is because a format statement needs to be referenced by a READ or WRITE statement. Even though format statements can be placed anywhere in the program unit using them, it is generally recommended that you put them at the end of in program unit ( main program, subroutine, function) in which they are used, if they are used by more than one READ or WRITE statement.
The general form of a format statement is as follows:
2000 format ( edit descriptors )
As you can see from above, the only two additional things that must be included with a format statement are a line label number and a string of edit descriptors. The line label number is necessary so that the referencing READ or WRITE statement knows were to go to pick up the proper format information. The edit descriptors are what tell the compiler how the data is supposed to be input or output. A list describing each individual edit descriptor can be found in the Optional Descriptors Section.
To output a 3 by 3 matrix called data
write (*,2000)((a(i,j),j=1,3),i=1,3) 2000 format ((1x,3(f5.2,2x)))
Note on parenthesis: When they are used in a format statement the computer will loop through the entire thing once. Then if there is additional information left to be output (or input), it wraps around to the last left parenthesis (unless that parenthesis is preceded by a repeat descriptor) in the FORMAT, and all contents of the FORMAT beyond that parenthesis are reused until all variables are printed, or another FORMAT wrap around is needed. Each wrap around in the use of a FORMAT, causes a new line to be started. Also, the "3" that appears before the last set of imbedded parenthesis, tells the compiler to loop through the edit descriptors embedded in those parentheses three times without forcing a new line on each pass. In this example the presence of this repeat count "3" causes the wrap after output of elements a(1,1) a(1,2) and a(1,3) to go to the edit descriptor "1x", beginning the next line with one space before printing a(2,1), a(2,2) and a(2,3). Note on the write statement: If you look at the write statement you will notice the two implied do loops in it. For further information on IMPLIED DO loops see the statement definitions.
array1.f, array2.f and format.f
lectures eighteen, twenty two, twenty three
Written by Jason Wehr : firstname.lastname@example.org and Maintained by John Mahaffy : email@example.com