next up previous contents
Next: The Input Parser Up: Fundamental PSI3 Functions Previous: Fundamental PSI3 Functions   Contents


The Structure of a PSI3 C Program

To function as part of the PSI package, a program must incorporate certain required elements. This section will discuss the header files, global variables, and functions required to integrate a C program into PSI3. Figure 1 presents a minimal PSI3 program, whose elements are described below.

Figure 1: The essential elements of a PSI3 C-language program.
\begin{figure}\begin{verbatim}...

The required include files are libipv1/ip_lib.h, libciomr/libciomr.h, libpsio/psio.h, and of course stdio.h. The first of these is for the Input Parser Library, Version 1 (libipv1.a), which is described in section 3.2. The second file contains function prototypes for the C Math Routines and old-style I/O library, libciomr.a. The third file analogously provides clean interface to functions of the new C I/O system described in section 3.3. The PSI libraries require that infile, outfile, and psi_file_prefix be global variables.

The integer function main() must be able to handle command-line arguments required by the PSI3 libraries. In particular, all PSI3 modules must be able to pass to the function psi_start() arguments for the user's input and output filenames, as well as a global file prefix to be used for naming standard binary and text data files. (NB: the default names for user input and output are input.dat and output.dat, respectively, though any name may be used.) The current standard for command-line arguments is for all module-specific arguments (e.g., -quiet, used in detci) before the input, output, and prefix values. The psi_start() function expect to find only these last three arguments at most, so the programmer should pass as argv[] the pointer to the first non-module-specific argument. The above example is appropriate for a PSI3 module that requires no command-line arguments apart from the input/output/prefix globals. See the PSI3 modules input and detci for more sophisticated examples. The final argument to psi_start() is an integer whose value indicates whether the output file should be overwitten (1) or appended (0). Most PSI3 modules should choose to append.

The psi_start() function initializes the user's input and output files and sets the global variables infile, outfile, and psi_file_prefix, based on (in order of priority) the above command-line arguments or the environmental variables PSI_INPUT, PSI_OUTPUT, and PSI_PREFIX. The value of the global file prefix can also be specified in the user's input file. The psi_start() function will also initialize the input parser and sets up a default keyword tree (described in detail in section 3.2). This step is required even if the program will not do any input parsing, because some of the functionality of the input parser is assumed by libciomr.a and libpsio.a. For instance, opening a binary file via psio_open() (see section 3.3) requires parsing the files section of the user's input so that a unit number (e.g. 52) can be translated into a filename.

The psi_stop() function shuts down the input parser and closes the user's input and output files.

Timing information (when the program starts and stops, and how much user, system, and wall-clock time it requires) can be printed to the output file by adding calls to tstart() and tstop() (from libciomr.a).

The sole purpose of the simple function gprgid() is to provide the input parser a means to determine the name of the current program. This allows the input parser to add the name of the program to the input parsing keyword tree. This function is used by libpsio.a, though the functionality it provides is rarely used.

NB: The library libciomr.a contains older I/O functions that have been superceded by functions in libpsio.a. However, you are encouraged to use the many non-I/O functions in libciomr.a.


next up previous contents
Next: The Input Parser Up: Fundamental PSI3 Functions Previous: Fundamental PSI3 Functions   Contents
psi 2003-01-07