FORTRAN 77 Language Reference

Positional Editing (T, nT, TRn, TLn, nX)

For horizontal positioning along the print line, f77 supports the forms:

TRn, TLn, Tn, nT, T

where n is a strictly positive integer. The format specifier T can appear by itself, or be preceded or followed by a positive nonzero number.

Tn--Absolute Columns

This tab reads from the nth column or writes to the nth column.

TLn--Relative Columns

This tab reads from the nth column to the left or writes to the nth column to the left.

TRn--Relative Columns

This tab reads from the nth column to the right or writes to the nth column to the right.

nTL--Relative Tab Stop

This tab tabs to the nth tab stop for both read and write. If n is omitted, this tab uses n = 1 and tabs to the next tab stop.

TL--Relative Tab Stop

This tab tabs to the next tab stop for both read and write. It is the same as the nTL with n omitted; it tabs to the next tab stop.

The rules and Restrictions for tabbing are:

nX--Positions

The nX edit specifier indicates that the transmission of the next character to or from a record is to occur at the position n characters forward from the current position.

On input, the nX edit specifier advances the record pointer by n positions, skipping n characters.

A position beyond the last character of the record can be specified if no characters are transmitted from such positions.

On output, the nX specifier writes n blanks.

The n defaults to 1.

Example: Input, Tn (absolute tabs):


demo% cat rtab.f 
	CHARACTER C*2, S*2 
	OPEN( 1, FILE='mytab.data') 
	DO I = 1, 2 
		READ( 1, 2 ) C, S 
2		FORMAT( T5, A2, T1, A2 ) 
		PRINT *, C, S 
	END DO 
	END 
demo%

The two-line data file is:


demo% cat mytab.data 
defguvwx 
12345678 
demo%

The run and the output are:


demo% a.out 
uvde 
5612 
demo%

The above example first reads columns 5 and 6, then columns 1 and 2.

Example: Output Tn (absolute tabs); this program writes an output file:


demo% cat otab.f 
	CHARACTER C*20 / "12345678901234567890" / 
	OPEN( 1, FILE='mytab.rep') 
	WRITE( 1, 2 ) C, ":", ":" 
2	FORMAT( A20, T10, A1, T20, A1 ) 
	END 
demo%

The output file is:


demo% cat mytab.rep 
123456789:123456789: 
demo%

The above example writes 20 characters, then changes columns 10 and 20.

Example: Input, TRn and TL n (relative tabs)--the program reads:


demo% cat rtabi.f 
	CHARACTER C, S, T 
	OPEN( 1, FILE='mytab.data') 
	DO I = 1, 2 
		READ( 1, 2 ) C, S, T 
2		FORMAT( A1, TR5, A1, TL4, A1 ) 
		PRINT *, C, S, T 
	END DO 
	END 
demo%

The two-line data file is:


demo% cat mytab.data 
defguvwx
12345678
demo%

The run and the output are:


demo% a.out 
dwg 
174 
demo%

The above example reads column 1, then tabs right 5 to column 7, then tabs left 4 to column 4.

Example: Output TR n and TL n (relative tabs)--this program writes an output file:


demo% cat rtabo.f 
	CHARACTER C*20 / "12345678901234567890" / 
	OPEN( 1, FILE='rtabo.rep') 
	WRITE( 1, 2 ) C, ":", ":" 
2	FORMAT( A20, TL11, A1, TR9, A1 ) 
	END 
demo%

The run shows nothing, but you can list the mytab.rep output file:


demo% cat rtabo.rep 
123456789:123456789: 
demo%

The above program writes 20 characters, tabs left 11 to column 10, then tabs right 9 to column 20.