FORTRAN 77 Language Reference

Runtime Formats

You can put the format specifier into an object that you can change during execution. Doing so improves flexibility. There is some increase in execution time because this kind of format specifier is parsed every time the I/O statement is executed. These are also called variable formats.

The object must be one of the following kinds:

You must provide the delimiting left and right parentheses, but not the word FORMAT, and not a statement number.

You must declare the object so that it is big enough to hold the entire format. For instance, '(8X,12I)' does not fit in an INTEGER*4 or a CHARACTER*4 object.

Examples: Runtime formats in character expressions and integer arrays


demo% cat runtim.f 
	CHARACTER CS*8 
	CHARACTER CA(1:7)*1 /'(','1','X',',','I','2',')'/ 
	CHARACTER S(1:7)*6 
	INTEGER*4 IA(2) 
	STRUCTURE / STR / 
		CHARACTER*4 A 
		INTEGER*4 K 
	END STRUCTURE 
	CHARACTER*8 LEFT, RIGHT 
	RECORD /STR/ R 
	N = 9 
	CS = '(I8)' 
	WRITE( *, CS ) N 		! Character Scalar 
	CA(2) = '6' 
	WRITE( *, CA ) N 	! Character Array 
	S(2) = '(I8)' 
	WRITE( *, S(2) ) N 	! Element of Character Array 
	IA(1) = '(I8)' 
	WRITE(*, IA ) N 	! Integer Array 
	R.A = '(I8)' 
	WRITE( *, R.A ) N 	! Field Of Record 
	LEFT = '(I' 
	RIGHT = '8)' 
	WRITE(*, LEFT // RIGHT ) N ! Concatenate 
	END 
demo% f77 -silent runtim.f 
demo% a.out 
       9 
       9 
       9 
       9 
       9 
       9 
demo%

: