Assign Those LUN's

John C. Adams, Jr.
208 Kaywood Avenue
Tullahoma, TN 37388



Introduction

     In using the Microsoft FORTRAN package on the TRS-80
Model III computer the F80 compiler utilizes several
different buffers, or logical units, for passing data to
and from external devices such as disk drives, line
printers, and the video display.  Unless otherwise
specified, logical unit numbers (LUN's) are assigned in
Microsoft FORTRAN as follows:

          LUN 1 and 3-5 to the screen or keyboard
          LUN 2 to the line printer
          LUN 6-10 to the disk drives.

In order to perform input and output (I/O) operations, you
must first open a LUN between the computer and the I/O
device.  This is accomplished through an OPEN subroutine
call using the following syntax:

          CALL OPEN( logical unit number, 'filename',
                     logical record length )

where the logical record length (LRL) is the length in
bytes of each record.  The LRL must be an integer constant
or variable whose value lies between 1 and 256; it must be
large enough to allow storage of all your data for that
record.  In practice the necessary length depends on your
FORMAT statements and whether you are using direct or
sequential disk accessing.

     Most FORTRAN applications utilize an input file, an
output file, and perhaps a data file for I/O communications
between the user and the computer.  It is up to the user to
provide all necessary LUN and LRL information within
his/her program, as well as all corresponding filenames.
Enter INOUT, which is a general FORTRAN utility subroutine
that can be INCLUDEd in your FORTRAN program to provide
this capability.

Subroutine INOUT

     Subroutine INOUT assigns LUN's (and corresponding
LRL's and filenames) for input, output, and data files
based on user keyboard (interactive) responses to screen
prompt messages.  With reference to the public domain disk
file named INOUT/FOR, INOUT returns the LUN for the input
file (LUNIN), the LUN for the output file (LUNOUT), and the
LUN for a data file (LUNDAT) to the calling program as
integer arguments in the subroutine call.  If any LUN is
entered by the user as a value greater than five (5), the
user is asked to input the corresponding filename and LRL.
In addition, if the output file LUN is entered as two (2),
the user is prompted to ready the line printer for output.
Any and all OPEN's are automatically generated within INOUT
based upon the user-supplied responses.  Note that all
output WRITE statements in subroutine INOUT are assigned to
unit three (3) which is the video display while all input
READ statements are assigned to unit five (5) which also
corresponds to the video.

     Given in public domain disk file TESTIO/FOR is a
simple test program called TESTIO which illustrates how
subroutine INOUT can be easily INCLUDEd into any FORTRAN
program.  Once INOUT has been called at the beginning of
your program, the LUN's for input, output, and data files
are available for use.  Any and all further I/O and
associated file manipulations can be performed using these
LUN's, e.g.,

           READ( LUNIN, 100 ) AUTO,BIKE,WAGON
           WRITE( LUNOUT, 200 ) HELP,TEMP
           WRITE( LUNDAT ) (PLOT(I),I=1,10)
           REWIND LUNDAT
           ENDFILE LUNOUT

Program TESTIO contains examples of such LUN usage where a
binary data file is written to LUNDAT, rewound, and read
with output to LUNOUT using the number of data entries as
controlled by input on LUNIN.  It is suggested that the
following be used as input to TESTIO:

           LUN for Input File (LUNIN) = 5
           LUN for Output File (LUNOUT) = 3
           LUN for Data File (LUNDAT) = 8
           Name of Data File:Drive = TESTIO/DAT:1
           LRL for Data FIle (LRLDF) = 100

Experiment with other values, especially with regard to LRL
for the data file.

     It is necessary for the user to plan his/her usage of
LUN's properly.  For example, if there is no requirement
for data file I/O in your program, simply answer the data
file query with a file number between one and five (don't
use two which is reserved for the line printer) that has
not been used for either input or output files.  Subroutine
INOUT checks to be certain that you have not previously
assigned a LUN to the current input value; if so, you are
prompted to re-enter the current LUN using a different
value.  However, there is no checking for duplication of
data file names or drives in INOUT so that it is the total
responsibility of the user to assure that all data files
are properly assigned.  In a similar manner it is up to the
user to properly assign the LRL's for each file based upon
the data requirements for that file.  If in doubt as to the
LRL entry, use 256 which is the default value assigned by
TRSDOS to its files.
