The IOINIT routine (FORTRAN 77 only) establishes properties of file I/O for files opened after the call to IOINIT. The file I/O properties that IOINIT controls are as follows:
Carriage control: Recognize carriage control on any logical unit.
Blanks/zeroes: Treat blanks in input data fields as blanks or zeroes.
File position: Open files at beginning or at end-of-file.
Prefix: Find and open files named prefixNN, 0 £ NN £ 19.
IOINIT does the following:
Initializes global parameters specifying f77 file I/O properties
Opens logical units 0 through 19 with the specified file I/O properties--attaches externally defined files to logical units at runtime
The file I/O properties apply as long as the connection exists. If you close the unit, the properties no longer apply. The exception is the preassigned units 5 and 6, to which carriage control and blanks/zeroes apply at any time.
IOINIT uses labeled common to communicate with the runtime I/O system. It stores internal flags in the equivalent of the following labeled common block:
INTEGER*2 IEOF, ICTL, IBZR COMMON /__IOIFLG/ IEOF, ICTL, IBZR ! Not in user name space
In releases prior to SC 3.0.1, the labeled common block was named IOIFLG. The name changed subsequently to _ _IOIFLG to prevent conflicts with any user-defined common blocks.
Some user needs are not satisfied with a generic version of IOINIT, so we provide the source code. It is written in FORTRAN 77. The location is:
<install>/SUNWspro/SC5.0/src/ioinit.f
where <install> is usually /opt for a standard installation of the Sun Fortran software package.
The ioinit subroutine is called by:
call ioinit ( cctl, bzro, apnd, prefix, vrbose ) |
|||
---|---|---|---|
cctl |
logical |
Input |
True: Recognize carriage control, all formatted output (except unit 0) |
bzro |
logical |
Input |
True: Treat trailing and imbedded blanks as zeroes. |
apnd |
logical |
Input |
True: Open files at EoF. Append. |
prefix |
character*n |
Input |
Nonblank: For unit NN, seek and open file prefixNN |
vrbose |
logical |
Input |
True: Report ioinit activity as it happens |
See also getarg(3F) and getenv(3F).
Note the following restrictions:
prefix can be no longer than 30 characters.
A path name associated with an environment name can be no longer than 255 characters.
These are the arguments for ioinit.
By default, carriage control is not recognized on any logical unit. If cctl is .TRUE., then carriage control is recognized on formatted output to all logical units, except unit 0, the diagnostic channel. Otherwise, the default is restored.
By default, trailing and embedded blanks in input data fields are ignored. If bzro is .TRUE., then such blanks are treated as zeros. Otherwise, the default is restored.
By default, all files opened for sequential access are positioned at their beginning. It is sometimes necessary or convenient to open at the end-of-file, so that a write will append to the existing data. If apnd is .TRUE., then files opened subsequently on any logical unit are positioned at their end upon opening. A value of .FALSE. restores the default behavior.
If the argument prefix is a nonblank string, then names of the form prefixNN are sought in the program environment. The value associated with each such name found is used to open the logical unit NN for formatted sequential access.
This search and connection is provided only for NN between 0 and 19, inclusive. For NN > 19, nothing is done; see "Source Code".
If the argument vrbose is .TRUE., then IOINIT reports on its own activity.
Example: The program myprogram has the following ioinit call:
call ioinit( .true., .false., .false., 'FORT', .false.)
You can assign file name in at least two ways.
demo$ FORT01=mydata demo$ FORT12=myresults demo$ export FORT01 FORT12 demo$ myprogram
demo% setenv FORT01 mydata demo% setenv FORT12 myresults demo% myprogram
With either shell, the ioinit call in the above example gives these results:
Open logical unit 1 to the file, mydata.
Open logical unit 12 to the file, myresults.
Both files are positioned at their beginning.
Any formatted output has column 1 removed and interpreted as carriage control.
Embedded and trailing blanks are to be ignored on input.
Example: ioinit()--list and compile:
demo% cat tioinit.f character*3 s call ioinit( .true., .false., .false., 'FORT', .false.) do i = 1, 2 read( 1, '(a3,i4)') s, n write( 12, 10 ) s, n end do 10 format(a3,i4) end demo% cat tioinit.data abc 123 PDQ 789 demo% f77 -silent tioinit.f demo%
You can set environment variables as follows, using either sh or csh:
demo$ FORT01=tioinit.data demo$ FORT12=tioinit.au demo$ export FORT01 FORT12 demo$
demo% a.out demo% cat tioinit.au abc 123 PDQ 789
demo% a.out demo% cat tioinit.au abc 123 PDQ 789