FORTRAN 77 Language Reference

Changing I/O Initialization with IOINIT

Traditional FORTRAN environments usually assume carriage control on all logical units. They usually interpret blank spaces on input as zeroes, and often provide attachment of global file names to logical units at runtime. The routine IOINIT(3F) can be called to specify these I/O control parameters. This routine:

Example: IOINIT and logical unit preattachment:


	CALL IOINIT ( .TRUE., .FALSE., .FALSE., 'FORT', .FALSE.) 

For the above call, the FORTRAN runtime system looks in the environment for names of the form FORTnn, and then opens the corresponding logical unit for sequential formatted I/O.

With the above example, suppose your program opened unit 7, as follows:


	OPEN( UNIT=07, FORM='FORMATTED' )

The FORTRAN runtime system looks in the environment for the FORT07 file, and connects it to unit 7.

In general, names must be of the form PREFIXnn, where the particular PREFIX is specified in the call to IOINIT, and nn is the logical unit to be opened. Unit numbers less than 10 must include the leading 0. For details, see IOINIT(3F) and the Sun Fortran Library Reference.

Example: Attach external files ini1.inp and ini1.out to units 1 and 2:

In sh:


demo$ TST01=ini1.inp 
demo$ TST02=ini1.out 
demo$ export TST01 TST02 

In csh:


demo% setenv TST01 ini1.inp
demo% setenv TST02 ini1.out

Example: Attach the files, ini1.inp and ini1.out, to units 1 and 2:


demo% cat ini1.f 
	CHARACTER PRFX*8 
	LOGICAL CCTL, BZRO, APND, VRBOSE 
	DATA CCTL, BZRO, APND, PRFX, VRBOSE 
& 		/.TRUE., .FALSE., .FALSE., 'TST', .FALSE. / 
C 
	CALL IOINIT( CCTL, BZRO, APND, PRFX, VRBOSE ) 
	READ( 1, *) I, B, N 
	WRITE( *, *) 'I = ', I, ' B = ', B, ' N = ', N 
	WRITE( 2, *) I, B, N 
	END 
demo% cat $TST01
 12 3.14159012 6
demo% f77 ini1.f
ini1.f: 
 MAIN: 
demo% a.out 
 I =   12 B =     3.14159 N =   6
demo% cat $TST02
   12    3.14159  6

IOINIT should prove adequate for most programs as written. However, it is written in FORTRAN so that it can serve as an example for similar user-supplied routines. A copy can be retrieved as follows:


demo% cp /opt/SUNWspro/SC5.0/src/ioinit.f  .