SPECPR Users’ Manual                                            Page 8-f20.1

F20:  Text File Input and Output                                 Alias: read
Special Function 20 has two parts to it.  The first part reads data from a
text file (for example, one that was generated by any program or by
using the system editor).  The second part writes data from a specpr
file into a text file.
With both parts there are options to include
errors or wavelengths or both.  Data, errors, and wavelengths may be
written either in standard Fortran format ’f15.6’ or in
exponential ’1pe15.6’ format, depending on the user’s option.
The program works with one set of numbers per line i.e. wavelength, data
and errors.  Without the wavelength option, the order is data,
errors, and without the error option the order is wavelength, data
When writing the data to a specpr record (i.e v123), the
program will put the error values in the next consecutive specpr file
(i.e v124).

Using Function 20
To run function 20, type


from math operations.  The routine
will prompt you for what part (reading or writing) you want to
do.  Type

              r   for reading data,
              re  for reading data and errors,
              w   for writing
              we  for writing data and errors.

If you are writing to a text file, you are given an option for format. Type

              f    for f format (Fortran format F15.6), or
              e    for exponential format (Fortran 1pe15.6).

Next if you are writing, you are asked if wavelengths are to be included. Type

              y          for yes to include wavelengths, and
              <return>   or any other character for no.

Then you are instructed to enter the filename of the text to which you will read or write data. Currently, the file name must be 40 characters or less. Be sure that when you are reading, the file is in your directory, or you must give the full file name (i.e /u/smith/dataf). When reading, f20 will prompt you for the starting column number where the data begins (e.g. col. 1 - 80). Default is column one(1). Columns are character columns, not columns of numbers. The routine does not count tabs properly, and if a tab or control character is encountered, it is treated as an error and the read is terminated. After reading the data, you can exit normally to plot and write the data, or elect to read the data again (type r to redo). If you are writing data to a text file you will be asked the file id and record number of the specpr file that the data are from (v, w, d, u, or y). When the operation is finished you have the option to redo the operation or exit. Type r to redo the operation at this point or e or x to exit. You can thus write many text files without leaving f20.

Setting Up the Text File There are two ways of setting up a UNIX text file that can be read by f20. First, and the easiest, is directed output. Output the data to the terminal and direct it to a file. In your program write to the terminal:

           10     format(1x,1pe15.6)

or with errors

           10     format(1x,1pe15.6,1pe15.6)

and run the program using this method

progname > filename

where progname is the program executable file and filename is the file to be read by f20. Second, you can write your data directly into a file. You must open the file and write to it. See your local Fortran manual on how to write ascii files. When reading, enter f20 from math operations and when prompted for your input/output filename, type in the filename of that you assigned to the text file in the above examples. The program will print out the channel number and the data value of that channel. The last channel number printed is the number of channels in the file (or the number of data values read by f20).

An f20 Example (square the data and add 1.0)

1) Operate on data using your own programs:

2) Put these values in v34 (with, for example the editor f14):

       channel 1: 0.99
                2: 0.90
                3: 0.70
                4: 0.40

3) Write v34 to file ’testa’ using f20 and e format

4) Run program ’testprog <testa >testb’

5) Read testb into specpr using f20

6) List the 4 channels

Fortran program "testprog":

                           program testprog
                            real x,y
                            do 100 i = 1, 4852
                                read (5,1) x
                    1           format (1pe15.6)
                    c do a computation:
                                y = x*x +1.0
                                write (6,1) y
                    100     continue