Fortran Library Reference

ioinit: Initialize I/O Properties

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:

IOINIT does the following:

Persistence of File I/O Properties

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.

Internal Flags

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.

Source Code

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.

Usage: ioinit

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).

Restrictions

Note the following restrictions:

Description of Arguments

These are the arguments for ioinit.

cctl (Carriage Control)

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.

bzro (Blanks)

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.

apnd (Append)

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.

prefix (Automatic File Connection)

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".

vrbose (IOINIT Activity)

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.

In sh:


demo$ FORT01=mydata 
demo$ FORT12=myresults 
demo$ export FORT01 FORT12 
demo$ myprogram 

In csh:


demo% setenv FORT01 mydata 
demo% setenv FORT12 myresults 
demo% myprogram

With either shell, the ioinit call in the above example gives these results:

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:

ioinit()--sh:


demo$ FORT01=tioinit.data 
demo$ FORT12=tioinit.au 
demo$ export FORT01 FORT12
demo$ 

ioinit()--csh:


demo% a.out 
demo% cat tioinit.au 
abc 123 
PDQ 789 

ioinit()--Run and test:


demo% a.out 
demo% cat tioinit.au 
abc 123 
PDQ 789