## `generate::Macrofort::setIOSettings` -- sets I/O settings

#### Introduction

`Mac::setIOSettings` (where `Mac:=generate::Macrofort`) sets the unit or channel numbers for the input and output of the FORTRAN code generated by `Mac::genFor`.

#### Call(s)

`generate::Macrofort::setIOSettings(inputf,outputf)`

#### Parameters

`inputf,outputf` | - | integers for I/O specifications.

#### Returns

the void object of domain type `DOM_NULL`

#### Side Effects

Resets the I/O settings for the FORTRAN code generated by `generate::Macrofort::genFor`.

#### Related Functions

`generate::Macrofort::init`, `generate::Macrofort::genFor`

#### Details

- In FORTRAN, `read`, `write`, `open` and `close` statements require unit (or channel) numbers. In this sample of FORTRAN code:

                  read(5,100) x
                  write(6,200) y

  the first entry in the `read` instruction is the unit number of the file (or device) by which the input x is read. Similarly, the first entry in the `write` instruction is the unit number of the file (or device) on which y is to be output.

  `Mac::setIOSettings` (where `Mac:=generate::Macrofort`) is used with `Mac::genFor` and `Mac::init` (see these programs for more details) and adjusts the (internal) global I/O unit settings for FORTRAN. The default setting for these variables is respectively 5 and 6 for FORTRAN read and write statements which are made by an initial call to `Mac::init`.

  These I/O settings are needed internally for Macrofort Macro instructions such as e.g. while-do loops. The user also has the choice of injecting his own choice of unit number for `open` and `close` and `read` and `write` statements quite independently from these global variables. This allows the FORTRAN code to read input from several different ascii files without having to call `Mac::setIOSettings` each time. However, in general practice, it suffices to call this procedure once and define I/O variables common to both the user and Macrofort for all `read`, `write`, `open` and `close` statements.

#### Example 1

Example of `"openm"` Macrofort Statement.

This example illustrates that one can use the Macrofort global variable for the FORTRAN input unit number or some other choice. The resulting FORTRAN code can read data from different files.

First initialize Macrofort and open the ascii file `"test.f"`:

    >> Mac:=generate::Macrofort:
       Mac::init():
       Mac::openOutputFile("test.f"):

Set global FORTRAN I/O settings at 5 and 6 respectively:

    >> inputf := 5:  outputf := 6:
       Mac::SetIOSettings(inputf, outputf):

Generate Open statement with input setting at 10 and then at `inputf`:

    >> Mac::genFor(["openm", 10, "toto.data", old,
                    ["readm", 10, ["i10"], [j]]]):
       Mac::genFor(["openm", inputf, "toto2.data", old,
                    ["readm", inputf, ["i10"], [j]]]):
       Mac::closeOutputFile():
       delete j, old, inputf, outputf:

The output file `test.f` is:

                open(unit=10,file='toto.data',status='old')
                read(10,2000) j
           2000 format(i10)
                close(10)
                open(unit=5,file='toto2.data',status='old')
                read(5,2001) j
           2001 format(i10)
                close(5)

#### Example 2

Example of Macro `"whilem"` Macrofort Statement.

This example uses the Macrofort internal global variable for the FORTRAN output instructions needed in the while-do loop made by the FORTRAN `write` instruction (via the macro `"writem"`) inside the `"whilem"` Macrofort instruction.

    >> Mac::openOutputFile("test2.f"):
       Mac::genFor(["whilem", abs(a) > eps, ["equal", a, big],
                    [["equal", a, a/2.0], ["equal", b,2 ]], 1000]):
       Mac::closeOutputFile():
       delete a, b, big, eps:

The output file `test2.f` is:

          c
          c     WHILE  (eps < abs(a)) DO <WHILE_LIST> (1)
          c
          c     WHILE LOOP INITIALIZATION
                    maxwhile1 = 1000
                    nwhile1 = 0
                  a = big
          c
          c     WHILE LOOP BEGINNING
           1000 continue
          c
          c     WHILE LOOP TERMINATION TESTS
                if (eps.lt.abs(a)) then
                  if (nwhile1.le.maxwhile1) then
          c
          c         NEW LOOP ITERATION
                    nwhile1 = nwhile1+1
          c
          c         <WHILE_LIST>
                    a = 0.5E0*a
                    b = 2
                  goto 1000
                  else
          c
          c         WHILE LOOP TERMINATION :
          c         BYPASSING THE MAXIMUM ITERATION NUMBER
                    write(6,2002)
           2002     format(' maxwhile1 ')
                  endif
          c
          c     NORMAL WHILE LOOP TERMINATION
                endif
          c     WHILE LOOP END (1)

See the help-file for `Mac::genFor` for a more comprehensive list of examples.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000