The library routine IOINIT can also be used with f77 to attach logical units to specific files at runtime. IOINIT looks in the environment for names of a user-specified form and then opens the corresponding logical unit for sequential formatted I/O. Names must be of the general 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. See the Sun Fortran Library Reference, and the IOINIT(3F) man page. (The IOINIT facility is not implemented for f90.)
Example: Associate physical files test.inp and test.out in the current directory to logical units 1 and 2:
First, set the environment variables.
demo$ TST01=ini1.inp demo$ TST02=ini1.out demo$ export TST01 TST02
demo% setenv TST01 ini1.inp demo% setenv TST02 ini1.out
demo% cat ini1.f CHARACTER PRFX*8 LOGICAL CCTL, BZRO, APND, VRBOSE DATA CCTL, BZRO, APND, PRFX, VRBOSE & /.TRUE.,.FALSE.,.FALSE., 'TST',.FALSE. / CALL IOINIT( CCTL, BZRO, APND, PRFX, VRBOSE ) READ(1, *) I, B, N WRITE(2, *) I, B, N END demo%
With environment variables and ioinit, ini1.f reads ini1.inp and writes to ini1.out:
demo% cat ini1.inp 12 3.14159012 6 demo% f77 -silent -o tstinit ini1.f demo% tstinit demo% cat ini1.out 12 3.14159 6 demo%
IOINIT is adequate for most programs as written. However, it is written in Fortran specifically to serve as an example for similar user-supplied routines. Retrieve a copy from the following file, a part of the FORTRAN 77 package installation: /opt/SUNWspro/SC5.0/src/ioinit.f