This article describes how to create a custom output file in FACSIMILE.

Generally the built in PSTREAM command is adequate for generating output files from your FACSIMILE models. However, sometimes you may wish to create output in a different format. Some of the reasons why you would do this are.

1. You want to create a file in a specific format for another application.

2. You want more significant places in your output.

3. You want to include items in your output which cant be included in the PSTREAM command.

Required Steps

There are two blocks you need to include in your models in order to achieve this.

a. A block to generate a header for your output. This block will execute once in the model initialisation.

b. A block to write the data to your file. This block will called directly or indirectly  by your whenever clause.

Generating the Header

To generate the header we use a FACSIMILE block called INSTANT. This block is executed as it is encountered in your model code, so you should ensure it is after your file open statement.

To generate the header we use the WRITE statement. The first part of the write statement assignes a write buffer to a unit number (and hence a file). For this purpose the next part of the write statement is a text string. We use a string with the correct spacing so that the headings align withe data (see below).

Suppose our output file is connected to unit 10 and we want to print out the VARIABLES SP1,SP2,SP3,SP4 to 6 significant figures with TIME to 4 significant figures. The INSTANT block would look like this.

COMPILE INSTANT;
* This line opens the output file ;
OPEN 10 "MyPstream.OUT" ;
* The next lines create the names block ;
WRITE 1=10,
"  TIME        SP1           SP2           SP3           SP4" %;
**;

Notice we have included the OPEN statement in the instant block. The WRITE statement is over two lines so we can correctly space the title items without exceeding the 72 character limit. If we wanted a longer heading we could have two or more strings on consecutive lines separated by commas. The % at the end of the line causes the buffer to be written out to the file.

In FACSIMILE for Windows you may want to create a custom file for a process which expects a PSTREAM file. In this case you could add a first line as in a PSTREAM as below. It is easiest to cut and paste this line from a real PSTREAM to get the right format.

COMPILE INSTANT;
* This line opens the output file ;
OPEN 10 "MyPstream.OUT" ;
* This line creates the PSTREAM first line ;
WRITE 1=10," PRINT STREAM NO. 9" % ;
* The next lines create the names block ;
WRITE 1=10,
"  TIME        SP1           SP2           SP3           SP4" %;
**;

Writing the Data Out

To write out the data we use a formatted write statement. We write the TIME variable with 4 significant figures and field width of 12 and all the other variables with 6 significant figures and field width of 14. For further information about formatting see "The FACSIMILE User Guide" section 12.3. The write statement is placed in a user block called from the WHENEVER clause. It is normally convenient to use the block containing the PSTREAM calls. So our block would look like this.

COMPILE OUT ;
WRITE 1=10,(E12,4,(E14,6)),TIME,SP1,SP2,SP3,SP4 % ;
PSTREAM 1;
PSTREAM 2;
**;

Example Output

This is the first few lines of the file created using the first INSTANT block.

 TIME        SP1           SP2           SP3           SP4
 0.0000      0.000000      0.000000      2.690000E+18  0.000000
 1.0000E-01  2.325559E+10  3.760647E+13  2.689962E+18  5.619756E+04
 2.0000E-01  2.325543E+10  7.524737E+13  2.689925E+18  5.619756E+04
 3.0000E-01  2.325527E+10  1.128877E+14  2.689887E+18  5.619756E+04

And this is the first few lines of the file created using the second INSTANT block.

PRINT STREAM NO. 1
 TIME        SP1           SP2           SP3           SP4
 0.0000      0.000000      0.000000      2.690000E+18  0.000000
 1.0000E-01  2.325559E+10  3.760647E+13  2.689962E+18  5.619756E+04
 2.0000E-01  2.325543E+10  7.524737E+13  2.689925E+18  5.619756E+04
 3.0000E-01  2.325527E+10  1.128877E+14  2.689887E+18  5.619756E+04