You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 23 Next »

1.Introduction

1.1 Purpose of Toolkit

The purpose of the SDP Toolkit is primarily (1) to provide an interface to the ECS system, including Planning and Data Production System (PDPS), Communications System Management (CSMS) and Information Management, (2) to allow science software to be portable to different platforms at the DAAC, (3) to reduce redundant coding at the SCF, and (4) to provide value added functionality for science software development. The SDP Toolkit consists of a set of fully tested, fast, efficient and reliable C and FORTRAN language functions, customized for application to ECS.

A brief overview of the operations concept of the Toolkit follows. The Toolkit divides into two groups: Mandatory tools, which the system requires in science software, with checking to occur at DAAC Integration & Test time; and Optional tools, whose primary intention is to save SCF development effort by reducing redundancy.

1.2. Mandatory Tools

The following tools are Mandatory:

At the lowest level are the Error and Status Message (SMF, for Status Message Facility) tools, which provide general error handling, status log messaging, and interface to CSMS services (which are implemented as email and ftp services at the SCF). Essentially all Toolkit functions call the SMF tools for error handling; science software may also use most of the SMF functions. (The Toolkit takes no action itself regarding errors itself; this is left to the science software.)

At the next level are the Process Control (PC) tools, which provide the primary interface to the Planning and Data Production System (PDPS). A major use of these tools is to access physical filenames and file attributes; in addition, they retrieve user-defined parameters. Several Toolkit functions call PC tools.

Generic Input/Output (IO_Gen) tools are at the next level; these tools provide the means to open and close support, temporary and intermediate duration files. Native C and FORTRAN functions perform the actual reads and writes.

Memory allocation (MEM) tools consist of two groups: the first consists of simple wrappers on native C functions, the purpose being to track memory usage in the SDPS; the second consists of "shared memory" tools, which enable the sharing of memory among executables within a PGE.

The rest of the Mandatory tools are higher level, in that they depend on at least some of the lower level tools:

Level 0 access (IO_L0) tools access Level 0 data.

Metadata (MET) access tools allow science software to access, alter, write and append metadata.

Spacecraft ephemeris and attitude access (EPH) tools read ephemeris and attitude data.

Time and Date (TD) tools perform time and date conversions between selected time systems.

1.3 Optional Tools

The remaining tools are Optional:

Ancillary data Access (AA) functions access such data as NMC data and Digital Elevation (DEM) data.

Celestial Body Position (CBP) tools locate the Sun, the Moon and the planets.

Coordinate System Conversion (CSC) tools allow coordinate conversions between celestial reference, spacecraft body referenced, spacecraft orbital referenced, and Earth frames. They also perform related tasks such as locating the sub-satellite point (ground track) and finding the zenith and azimuth of vectors at Earth surface.

Constant and Unit Conversion (CUC) tools allow access to physical constants and unit conversions.

Digital Elevation Model (DEM) tools provide access to HDF-EOS DEM datasets. This will be the primary production DEM data.

The IMSL package provides mathematical and statistical support.

Graphics Support (if any, in the production environment) is TBD.

There are also some Test Tools, which are for use during development at the SCF only. These include an ephemeris and attitude simulator and a Level 0 file simulator.

For the most part the Optional tools are independent of each other, though all depend on the lower level tools, including SMF (all tools), PC, IO_Gen, and TD.

1.4 Toolkit Languages

The Toolkit is written in the C language. A macro package provides bindings to the C code from FORTRAN 77 (with a few exceptions coded directly in F77). These bindings appear to have no effect on processing speed. Where possible, the same Application Program Interface (API), i.e., calling sequence, has been used for both C and FORTRAN. Support of FORTRAN 90 requires no special bindings, since FORTRAN 77 is a subset of FORTRAN 90; testing the Toolkit with an F90 compiler confirms this.

Special note regarding FORTRAN: Programmers are strongly urged to include the IMPLICIT NONE statement at the beginning of every FORTRAN module. This prevents many types of error; in particular, there is less chance you could omit an include file needed for a Toolkit function.



1.5 Purpose of This Document

This document refers to those functions delivered as of the Release B.0 SCF Toolkit (April 1997). Each successive delivery increments the previous delivery with additional functionality, while maintaining a consistent user API. The document will be updated with each successive software delivery.

A user's guide (Release B.0 SCF Toolkit Users Guide, April1997) accompanies the Toolkit delivery. The intent of this guide was to serve as the sole documentation for use of the Toolkit. However, after review, several instrument teams pointed out that it was not useful as a simple introduction to the Toolkit; rather, it resembled the detail and complexity of Unix "man" pages. This document intends to fill that gap.

The purpose of this document is to provide a simple, easy to use guide to Toolkit function usage, through a step-by-step format, including many examples in C and FORTRAN. The intended audience is both science software programmers and their supervisors. After reading it, the user will be able to use the Toolkit API in constructing instrument data production code or incorporating Toolkit calls into heritage code.

This document is necessarily not a comprehensive one; the TK5.2 version of the Users Guide is the definitive source. It contains details such as Toolkit installation instructions, requirements trace, detailed description of inputs and output data and parameters, and so on. For purposes of this document, we assume that the user has a copy of the Toolkit already installed on his/her system, including especially the setting of Toolkit environment variables.



1.6 Document Format

Each of the tool groups delivered to date is listed in its own section. An overview sub-section explains the general usage of the tool group. For each tool, we include: a short explanation of what it's for; step-by-step guide to usage by example, for C and FORTRAN; and a Notes section which includes dependencies on other Toolkit functions, files and environment variables. The examples given are for illustrative purposes only; for compilable examples, please refer to the software test drivers that are part of the Toolkit delivery package.

The Status/Message (SMF), Process Control (PC), and Ancillary Data Access (AA) tool groups are exceptions to the format, in that they need extensive explanation regarding their use as a whole; their "Overview" sections are very long.

2.1.1 Introduction

The Error/Status Message (a.k.a. SMF, for "Status Message Facility") Tools are the lowest level of the Toolkit, since nearly all of the other Toolkit functions call these tools. Their purpose is to provide an error and status message handling mechanism for use in science software (and in Toolkit functions), and to provide means to send log files, informational messages and output data files to DAAC personnel or to remote users.

In this overview section, we walk you through the procedure of constructing your own error/status messages step-by-step, then show their application in log files, your own code, and in the Toolkit itself.

2.1.2 Constructing Your Own Error/Status Messages

This section explains how to use the Toolkit to construct files containing error and status messages, which your code can access at runtime.

The basic process of constructing these files consists of 2 steps: constructing the status message text file with an editor, then running the smfcompile utility provided in the Toolkit, before compiling and executing your code.


2.1.2.1 The status message text file

The first step is to type in your own messages into the status message text file using a text editor.

You may use as many status message text files as you like, provided you use a different seed number for each file (see "%SEED" field below).
For purposes of internal Toolkit efficiency, it is recommended that each set of error messages that correspond to a given set of modules in your code be defined in a separate file -- it is not efficient to mix them across module groupings, nor to put them all in one big file. For example, all messages pertaining to your geolocation processing might be in one file, and all related to ancillary data processing in another.

These files always have the suffix ".t". We present an example of this file, adapted from a prototype of the Toolkit that uses heritage AVHRR/Land Pathfinder code from GSFC. This file is also given in Appendix A of this document. These messages are examined further in the following sections.


# Status Message Text File for Toolkit AVHRR/Land Pathfinder
# prototype
#
%INSTR	= AVHRR
%LABEL	= PATHFINDER
%SEED 	= 99
PATHFINDER_F_OPEN_BINARY_FILE   FATAL_ERROR...opening binary file
PATHFINDER_F_MEM_ALLOC_FAIL     FATAL ERROR...allocating memory %s
PATHFINDER_F_OPEN_ANC_FILE      FATAL_ERROR...%s
PATHFINDER_W_CLOSE_GAC_FILE     WARNING...could not close GAC file
PATHFINDER_W_OZONE_FILE_MISSING	Ozone file not found
                                      ::PATHFINDER_A_ALT_FILE_USED
PATHFINDER_A_ALT_FILE_USED      Alternate file used		
PATHFINDER_W_EPH_FILE_NOT_FOUND	Ephemeris file not found
                                      ::PATHFINDER_A_ALT_FILE_USED
PATHFINDER_W_NO_LOG_FILES       WARNING: Problem sending log files
PATHFINDER_N_PROCESSING_DONE    SUCCESS: processing complete at %s

2.1.2.2 Constructing the status message text file header

The first 3 lines of this file are comments. The next 3 lines are required. They may appear only once per file, and must appear in this order.
%INSTR	= AVHRR
The "%INSTR" field is your instrument name.
%LABEL	= PATHFINDER
The label in the "%LABEL" field is arbitrary (see label below in this section) .

Both of the above fields must consist of 3 to 10 upper case letters.

%SEED 	= 99
The "%SEED" field is a seed number assigned to you by ECS/SDPS. Most teams have been allocated 5,000 seed values in a specified range. The purpose of seed numbers is to ensure unique error messages for each instrument team or development group.

Given the example here, the name of the status message text file containing all of this information is recommended to be "AVHRR_99.t".

2.1.2.3 Constructing the status definitions: Simple message

PATHFINDER_F_OPEN_BINARY_FILE   FATAL_ERROR...opening binary file

The remainder of the file contains the definition of your error and status messages. Each consists of a single status definition, of which there may be up to 510 per file. (If you need more, just make another file with a new "%LABEL".) Status definitions may span several lines, as whitespace is ignored. Each status definition consists of two parts.

PATHFINDER_F_OPEN_BINARY_FILE FATAL_ERROR...opening binary file

The first part, the mnemonic label, is what you will pass to the error/status reporting functions in your code. It consists of 3 tokens, and may consist of up to 30 uppercase letters and underscores.

PATHFINDER_F_OPEN_BINARY_FILE FATAL_ERROR...opening binary file

The first token in the mnemonic label must be identical to the "%LABEL" field, i.e., the label. This provides the means to separate messages by functional groups in the science software -- each group would have its own status message (".t") file, with the "%LABEL" field providing the group ID.

PATHFINDER_F_OPEN_BINARY_FILE  FATAL_ERROR...opening binary file

The second token in the mnemonic label is the status level. The following table contains a list of the possible levels. The order listed in this table is significant.

Table. Error/Status Message Levels. 
Level Name Description
_S_ Success Normal return value
_A_ Action For retrieving a string indicating action taken
_M_ Message Message returned by Toolkit
_U_ User information Informational message generated by user
_N_ Notice E.g., for data availability notices
_W_ Warning Possible problem in program
_E_ Error Error in program
_F_ Fatal error Fatal error in program

In our example the level of the message is "_F_", or fatal error. Note that the Toolkit itself takes no action based on the status level; that is the province of the science software. See the PGS_SMF_Test*Level tool sub-group in the Tool Description section for an explanation of how to utilize these levels. (Note that "Action" is not a valid status level.)

PATHFINDER_F_OPEN_BINARY_FILE  FATAL_ERROR...opening binary file

The third token in the mnemonic label indicates the content of the message.

PATHFINDER_F_OPEN_BINARY_FILE  FATAL_ERROR...opening binary file

The second part of the line entry in the status message text file, the message string, is the actual text that gets printed. It consists of up to 240 ASCII characters. Any whitespace is reduced to a single space.

What happens to the entries in the status message text file is the subject of the next section. A few more examples of status message text file entries are in order first.

2.1.2.4 Constructing the status definitions: Message with runtime value added

PATHFINDER_F_MEM_ALLOC_FAIL   FATAL ERROR...allocating memory %s

This example shows the possibility of adding the value of a variable to a message string, through the C language format specifier %s. See PGS_SMF_SetDynamicMsg in the Tool Description section for the method for doing this. (The FORTRAN 77 implementation of this is under study at this writing.)

2.1.2.5 Constructing the status definitions: Action message

PATHFINDER_A_ALT_FILE_USED		Alternate file used		

This example shows how to implement action messages in the status message text file. Action messages are simply a convenient way to specify in the status messages the action taken in response to a condition. It is easiest to explain this by example.

PATHFINDER_W_OZONE_FILE_MISSING	Ozone file not found ::PATHFINDER_A_ALT_FILE_USED

(Note: All of the above must appear on a single line)

Above is an example action definition.

PATHFINDER_A_ALT_FILE_USED

is the action label, with level "_A_". If in the course of processing your program tries to open the ozone file, but does not find it, then it may set the warning message

PATHFINDER_W_OZONE_FILE_MISSING.

The Toolkit then writes the string "Ozone file not found" to the Status log file. (See section 2.1.3, "Log files", for explanation of different log files.) You might want the response you take to be written to a log file, using a pre- defined message; this can be done using the action definition. If your lower level module returned PATHFINDER_W_OZONE_FILE_MISSING, then you can call Toolkit function PGS_SMF_GetActionByCode with this mnemonic as input, and get back the string "Alternate file used". You could then use the PGS_SMF_GenerateStatusReport function to write this string to the Report log file. This string could be just as easily written to the Status Log file by using the PGS_SMF_SetDynamicMsg tool.

Note that it is up to the user to specify the alternate action, such as opening the alternate file. The Toolkit takes no action itself. That is, the accessing and writing of the action message and the actual action taken are completely independent of each other.

Action labels must not be used as stand-alone messages, i.e., they must never appear explicitly in your code. They can only be tacked on to other messages as in the above example.

Usage of this function is optional.

2.1.2.6 Running the smfcompile utility

Now that preparation of your status message text file is complete, you need to generate files that your program can use -- it does not use the status message text file directly. Do this by executing the smfcompile utility.

i) For use in C, the procedure is to run from the Unix command line

$PGSBIN/smfcompile -f AVHRR_99.t -r -i

This creates two files. $PGSINC/PGS_PATHFINDER_99.h is the C include file, and $PGSMSG/PGS_99 is the runtime ASCII message file.

ii) In FORTRAN 77 and FORTRAN 90, run from the Unix command line

$PGSBIN/smfcompile -f AVHRR_99.t -f77

This creates two files. $PGSINC/PGS_PATHFINDER_99.f is the FORTRAN include file, and $PGSMSG/PGS_99 is the runtime ASCII message file.

iii) In Ada, run from the Unix command line

$PGSBIN/smfcompile -f AVHRR_99.t -ada

This creates two files. $PGSINC/PGS_PATHFINDER_99.ada is the Ada package specification file, and $PGSMSG/PGS_99 is the runtime ASCII message file.

You should never modify either one of the two files created by smfcompile. The status message text file AVHRR_99.t is the only file you should ever edit.

The runtime ASCII message file is independent of language, while the include or package specification file is language dependent.

Once you have constructed your status message text file, you can modify it. If you only modify the text of the messages, and not the mnemonic labels, then you do not need to recompile your code; you only need to rerun smfcompile. This is because the include files (PGS_PATHFINDER.h, .f. or .ada) do not contain the text of the message, only the mnemonic and its internal code. If you do add or change mnemonic labels, then you will need to recompile your code, after rerunning smfcompile.

The source code for the smfcompile utility is $PGSSRC/SMF/PGS_SMF_Comp.c .

2.1.3 Log files

Before we get into how to use the messages in your code, an explanation of log files is in order. There are 3 log files generated by the Toolkit: the Status log file, the User log file, and the Report log file. All of these files are opened automatically the first time they are needed. They are identified respectively as LogStatus, LogUser, and LogReport in the default Process Control file $PGS_PC_INFO_FILE ($PGSRUN/PCF.v5), as explained in the Process Control section below. The Toolkit does not delete existing log files, but instead appends new information to them.

In order to use Toolkit log files at the SCF, you must use either PGS_PC_Shell.sh or PGS_PC_InitCom to initialize the Toolkit.
(This is done by the system at the DAAC.)

2.1.3.1 Status log file

The Status log file is automatically updated every time either your code or the Toolkit code calls one of the Toolkit functions PGS_SMF_Set*Msg. Thus this file captures all error and status information concerning a program.

Here we explain in detail what you see in the log file, using an example.

11:PGS_PC_GetPCSDataGetIndex():PGSPC_W_NO_DATA_PRESENT:76807
The data requested is not in the line found.

Each entry consists of two lines, followed by a blank line. This example is a warning message generated by a Toolkit function. The first line contains configuration and other information.

11:PGS_PC_GetPCSDataGetIndex():PGSPC_W_NO_DATA_PRESENT:76807

The first number (1) is the Production Run ID; the second (1) is the Software (version) ID. These parameters are obtained by the Toolkit from the process control file $PGS_PC_INFO_FILE, as explained in the Process Control section below.

11:PGS_PC_GetPCSDataGetIndex():PGSPC_W_NO_DATA_PRESENT:76807

The next entry is the name of the function that set the message, through use of one of the Toolkit functions PGS_SMF_Set*Msg.

11:PGS_PC_GetPCSDataGetIndex():PGSPC_W_NO_DATA_PRESENT:76807

The next entry is the mnemonic label of the message.

11:PGS_PC_GetPCSDataGetIndex():PGSPC_W_NO_DATA_PRESENT:76807
The final entry on this line is the SMF error code, which is used internally by the Toolkit to identify the error or status.
The data requested is not in the line found.

The second line is the text of the message. For your messages, this is the message string that you typed into the status message text file AVHRR_99.t, as explained above.

2.1.3.2 User log file

The User log file is automatically updated every time your code calls one of the Toolkit functions PGS_SMF_Set*Msg, and the message level is of type "_U_" or "_N_". Thus this file consists of the subset of status messages that are of particular interest to you. (No Toolkit functions use messages of these two levels.)

11:():PATHFINDER_N_PROCESSING_DONE:813585
SUCCESS: AVHRR processing complete at Mon Sep 19 17:37:47 1994

Since this message is of level "_N_", it appears in the User log file (and also the Status log file).

2.1.3.3 Report log file

The Report log file is updated each time you make a call to Toolkit function PGS_SMF_GenerateStatusReport. This function takes as input any string, and simply writes it to this file. The messages you generated in AVHRR_99.t are not necessarily used. Thus this file is a way for you to send arbitrary information to a log file. No Toolkit functions call this function, so you are in complete control of what gets written to the Report log file.

2.1.3.4 Where the log files go

The Toolkit writes the log files to directory $PGSHOME/runtime. You can get these files sent to a remote machine through use of either PGS_PC_Shell.sh, or PGS_PC_InitCom and PGS_PC_TermCom (See section 3.1.4.4 for more information regarding the sending of files).

2.1.3.5 Log files are not deleted by Toolkit

The Toolkit writes to log files in "append" mode. This means that the log files will remain until you delete them. The log files are designed this way in order to accept input from several executables from a single PGE. When testing at the SCF, you might want to manually delete these files occasionally to save disk space. Alternatively you could delete them in your test script before each run. In the production system, the SDPS will delete the log files between successive executions of a PGE.


2.1.4 Using error/status messages in your code

This section provides pointers to the major functions which you need to use to implement error/status messaging in your code. Only a brief summary is given in this section; the explanations of the individual Toolkit functions, along with detailed examples of usage, appear in the Tool Descriptions section.

2.1.4.1 Writing error/status messages to log files

The simplest thing to do is to save an error message, once your code detects an error. This is done by calling one of the functions PGS_SMF_Set*Msg. The Toolkit automatically writes to the log file the message string corresponding to the mnemonic label which you supply as input. The message is saved in memory to the internal status message buffer for future use. There are 3 tools that perform this function:

Tool PGS_SMF_SetStaticMsg does this for a pre-defined message.

Tool PGS_SMF_SetDynamicMsg does this for dynamic data such as the value of variables at runtime, when used in conjunction with another tool (See section 2.1.4.2 for information on message retrieval tools).

Tool PGS_SMF_SetUNIXMsg does this for error codes returned from Unix system calls.

Since the Toolkit writes these messages to the Status log file automatically, this is all you need to do, if this is all you want.

If you want to write an arbitrary string to a log file at runtime, without benefit of your previously constructed error/status messages, use tool PGS_SMF_GenerateStatusReport . It writes to the Report log file. One use you could make of this method is to write really important messages such as unexpected errors to the Report log file. Such errors are written to the Status log file, but may be hard to separate from the many Toolkit messages in that file. Since you control everything that is written to the Report log file, this will assure that the message gets your attention.

In order for all of the above functions to work, an entry for each log file must appear in the Process Control file $PGS_PC_INFO_FILE. The default version of this file $PGSRUN/PCF.v5 contains these entries already, so if you use this file that is already done for you.

2.1.4.2 Retrieving messages in your code

If for some reason you wish to retrieve the message inside your program, use the PGS_SMF_Get* functions.

PGS_SMF_GetMsg retrieves the message currently in the internal status message buffer, as set previously by a PGS_SMF_Set*Msg function. This message has already been automatically written to the Status log file by the time you do this, so it is not really necessary to ever call this function.

PGS_SMF_GetMsgByCode retrieves a message string given its mnemonic label. It is useful for constructing dynamic messages, as shown in the examples for PGS_SMF_SetDynamicMsg in the Tool Descriptions section.

You can also get the Action part of a given mnemonic label, by calling function PGS_SMF_GetActionByCode . This may be useful if you want to write the action message to the Report log file.

2.1.4.3 Returning error/status codes from your lower-level modules

You may wish to use error/status messages as the return value of your own modules. The advantage to this is that you can then switch on either the mnemonic label code itself, or on its status level, in the module that calls your lower-level function.

To do this, your module must be a function, and it must return a variable of type PGSt_SMF_status (C) or INTEGER (FORTRAN).

To switch on the status level of a returned value, use the PGS_SMF_Test*Level functions. These include PGS_SMF_TestStatusLevel, which returns the status level given a mnemonic label, and the set of functions PGS_SMF_TestFatalLevel, PGS_SMF_TestErrorLevel, PGS_SMF_TestWarningLevel, PGS_SMF_TestUserInfoLevel, PGS_SMF_TestNoticeLevel, PGS_SMF_TestMessageLevel, and PGS_SMF_TestSuccessLevel, which all return PGS_TRUE or PGS_FALSE depending on whether the input mnemonic label is of that level or not.

2.1.4.4 Sending files to a remote machine

Toolkit function PGS_SMF_SendRuntimeData is used to mark files of your choice for sending to a remote machine.
The actual process of sending both these files and Toolkit log files to the remote machine is handled through use of either PGS_PC_Shell.sh, or PGS_PC_InitCom and PGS_PC_TermCom.

These functions also automatically send email to a user on a remote machine.
Sending of files and email may be disabled by resetting the TransmitFlag (logical 10109) in the Process Control file.

Note that the feature of the Toolkit which allows file and e-mail transmission is indended for SCF use only. In the DAAC environment, these services will be performed through the Data Server subscription mechanism.

2.1.4.5 Miscellaneous functions

PGS_SMF_SetArithmeticTrap accepts the name of your signal handling function, which the system will then use in the event of an arithmetic error, thus avoiding a core dump. Due to unforeseen implementation difficulties, this tools was never officially released. For details on the problems encountered, please read the signal handling investigation summary.

PGS_SMF_GetInstrName returns the name of the instrument, given an error/status mnemonic label. PGS_SMF_CreateMsgTag returns a string containing configuration information, for use in stamping your own messages.


2.1.5 How the Toolkit itself uses error/status messages

The Toolkit itself makes extensive use of PGS_SMF_* functions for error checking purposes. Much effort has gone into assuring that the maximum number of possible errors will be trapped, without sacrificing the speed and efficiency of the Toolkit code.

Nearly all Toolkit functions are of type PGSt_SMF_status in C, or INTEGER in FORTRAN, which means that they return a status or error value that may be checked and acted on using PGS_SMF_* functions.

Toolkit runtime ASCII message files have filenames of the form $PGSMSG/PGS_?, where ? = 1 to 13. They are derived from status message text files with filenames of the form $PGSMSG/PGS_grp_?.t, where grp = Toolkit group name (SMF, PC, IO, ...) and ? = 1 to 13. The corresponding include files have filenames of the form $PGSINC/PGS_grp_?.h (C), $PGSINC/PGS_grp_?.f (FORTRAN ), and $PGSINC/PGS_grp_?.ada (Ada).

The Toolkit bases no action on the severity of error levels; that task is left to the science software. In particular, the Toolkit never returns a fatal error, nor exits a program. In general, returned values from Toolkit functions are either of status levels "_S_", "_W_", or "_E_". The only time the Toolkit itself acts on the status level of a message is when it sends user-generated messages of status level "_N_" or "_U_" to the User log file, as explained in section 2.1.3, Log files.

Switching on the level of error is the province of the PGS_SMF_Test*Level set of tools. These tools are for use in the science software.

Since a message is written to the Status log file every time a PGS_SMF_Set*Msg function is called, many of these messages will be generated by Toolkit functions, in the event of warnings or errors. If a low-level Toolkit function detects an error or warning, it will write a message to the Status log file, then return the appropriate message to its calling function. That function also will write to the log file, if it is unable to handle the error, and return an appropriate error or warning message to its calling function. So a single error or warning can result in several messages in the log file; this enables traceability of the problem. The Status log file is in fact the only source of traceability for Toolkit errors.

There is a special case where warning messages are generated, when in fact there is no anomaly in processing. See the entry for PGS_IO_Gen_Open.

This concludes the "Overview" section of the error/status messaging tools.



3.1 Overview

3.1.1 Introduction

The next highest level of the Toolkit above the SMF tools includes the Process Control (PC) tools. Their purpose is to provide a direct interface between the science software and the rest of the SDPS, including accessing file attributes (data about files), physical filenames (for use by HDF functions), and other functions. These tools are used internally by many Toolkit functions, such as Generic I/O, Ancillary Access, and other tools.

There are two sets of PC tools: the Command tools, which are callable from Unix shell scripts, and the API tools, callable from C and Fortran. Much of the functionality is duplicated between these two groups; many of the Command tools are simple wrappers on the C code of the API tools, with some exceptions.
For more information about the Command tools see below.
Note: Most of the information in this overview applies to both Command tools and API tools; in particular, both read from the same Process Control File.

The Process Control File (PCF) is central to the PC tools. At the SCF, you construct a PCF using a text editor, one for each PGE. These PCFs are part of the delivery of your software to the DAAC. Your software will access files by logical identifiers (essentially integers, defined by mnemonics). The PCF maps these logical identifiers to physical references (currently physical file names and directories). Each logical identifier corresponds to one or more physical references, or versions. At the SCF, you can use any physical reference you like. In the production environment, the physical reference is supplied by the DAAC. Details are given below.

In this overview section, we walk you through the procedure of constructing your own Process Control File step-by-step, then explain the workings of the pccheck utility, which checks the format of this file. The PCF is read by most of the PC tools (directly or indirectly), and is the current mechanism by which the Toolkit interfaces with the rest of the SDPS. The mechanism may change in the future, but the interface to your code will not.

3.1.2 Constructing your Process Control file

This section explains how to customize a Process Control File for use in your code.

A default Process Control File (PCF) is included in the TK5.1.1 delivery. It contains entries which are either required or optional for use of many Toolkit functions. This file is named $PGSRUN/PCF.relA.template. The particular example we use here is from the Pathfinder AVHRR/Land Toolkit Prototype study. The complete example file appears in Appendix B of this document.

It is recommended that you start with the same (customized) copy of the PCF each time you run at the SCF, especially if you are using temporary files in your processing. You don't want previous temporary file references in the PCF, since these files are deleted by the system (unless you are not using PGS_PC_Shell.sh or PGS_PC_TermCom).

The Unix environment variable $PGS_PC_INFO_FILE must point to your Process Control file in order for the Toolkit to work at all.

We go through the example file section-by-section. The sections of a Process Control file include:

All sections of the PCF, except the SYSTEM RUNTIME PARAMETERS and USER- DEFINED RUNTIME PARAMETERS sections, consist of names, locations and other data about physical files. Each of these sections has a default file location, which is at the beginning of the section. The default file location is delimited by a '!' in column one of the PCF. This location points to the default directory in which these files are stored. This may be overridden for individual files, by inserting the fully-qualified physical directory path, as explained below. The PRODUCT INPUT section provides a detailed example of considerations that apply to all sections that involve files. Explanations of other sections provide only differences unique to those sections.

General considerations:


#   Process Control File: Pathfinder AVHRR/Land Toolkit
#      Prototype
#
#   Env variable PGS_PC_INFO_FILE must point to this file

Comments in a PCF are any lines that begin in the first column with "#".


?   SYSTEM RUNTIME PARAMETERS

The "?" symbol in the first column defines this line as the subject of the section. These nine subject names must not be changed nor deleted from the PCF.

Blank lines are not allowed.

Pipe character "|" must be used to delimit fields.

The exclamation point "!" must be used to designate the default file location. This must appear before any file entries in each section of the PCF.

The entire length of any line in the PCF may not exceed 1000 characters.

Different sections of the PCF have different numbers of required and optional fields for each entry. In the examples below, each entry is identified as required or optional.

3.1.2.1 SYSTEM RUNTIME PARAMETERS

?   SYSTEM RUNTIME PARAMETERS
# ----------------------------------------------------------
# Production Run ID - unique production run identifier
# ----------------------------------------------------------
1

This string identifies the particular run of your algorithm at the SDPS. This field is required, and may be up to 200 characters. It cannot be the string "0".


# ----------------------------------------------------------
# Software ID - unique software configuration 
identifier
# ----------------------------------------------------------
1

This string identifies the particular software of which your PGE consists. This field is required, and may be up to 200 characters. It cannot be the string "0".

In the production system, both of these fields are written into the PCF by the SDP Planning and Scheduling sub-system. At the SCF, you may use any string you like. Note that the 'Production Run Id' value is used in the naming of Temporary and Intermediate files.

Currently these are the only two fields allowed in this section. DAAC and hardware identification are being considered as additions to the configuration data, for future deliveries of the Toolkit.

3.1.2.2 PRODUCT INPUT

This section is for primary data files used as input to create standard products. This includes such files as ancillary data, Level 0 data, and standard products output from other PGEs; in general, all of your input files.


?   PRODUCT INPUT FILES 
# [ next line is for default location ]
! ~/runtime

Environment variable PGSHOME/runtime is the default location of the files in this section, unless it is overridden for individual files, as explained below. Note that the tilde character "~" is equated to the environment variable PGSHOME. This is true throughout the entire PCF. This particular default file location $PGSHOME/runtime must not be changed, because of the way the Toolkit Ancillary Data Access input files are handled. Default file locations of all other sections of the PCF may be changed to whatever you like.


# ----------------------------------------------------------
# Pathfinder AVHRR/Land input files
# ----------------------------------------------------------
201|87002002709.no9_gac|||||1
401|goldtopolandsea8.bin|||||1
402|gridtoms_1987_sngl_ntwk|||||1
403|ephem8788.dat|||||1
404|timecorr8788.dat|||||1
405|SDSannotations.dat|||||1
406|HDFmetadata.dat|||||1
410|jan021987.proclog|||||1


201|87002002709.no9_gac|||||1

The first entry in this section is used as an example; it is the primary input file for Pathfinder AVHRR/Land processing.


201|87002002709.no9_gac|||||1

Field 1 is the link between your software and this PCF entry, the logical identifier. This identifier should be associated with a mnemonic in your code, at the beginning of the module where you use PGS_IO_Gen_Open to open this file, as shown below. This field is required, and must be an integer, of type PGSt_integer (long) in C, INTEGER in Fortran. Science software may use any positive integer for logical identifiers, except integers in the range 10,000-10,999; these numbers are reserved for the Toolkit.

In C, the form of this is


#define GAC_FILE 201

In Fortran,

      PARAMETER (GAC_FILE=201)

You then use GAC_FILE as an input parameter to Toolkit function PGS_IO_Gen_Open.

Note that while you can use hard-coded numbers in calling sequences, instead of mnemonics (C) or parameters (Fortran), this will make things difficult for integration and test, and also for maintainance; this practice is strongly discouraged.


201|87002002709.no9_gac|||||1

Field 2 is the file reference, currently the actual physical filename, unqualified (i.e., without directory information). In the future production system, this mechanism may change (for example to a Universal Reference), but this will not affect the science software. This field is required, and is a string of up to 256 characters.


201|87002002709.no9_gac|||||1

Field 3 is the path name, for overriding the default directory. In this example, the Toolkit will look for this file in location $PGSHOME/runtime/87002002709.no9_gac. If instead this entry were


201|87002002709.no9_gac|/fire2/toma/data||||1

then the Toolkit would look for this file in /fire2/toma/data/87002002709.no9_gac. This field is optional, and is a string of up to 100 characters.


201|87002002709.no9_gac|||||1

Field 4, blank here, is reserved for future use.


201|87002002709.no9_gac|||||1

Field 5, blank here, is the universal reference. It may contain any string of up to 150 characters. This value may be returned by calling the function PGS_PC_GetUniversalRef.


201|87002002709.no9_gac|||||1

Field 6, blank here, is the attribute location. It is the name of a file that contains data about the file of Field 2. This file must be in the same directory as the file in Field 2. This field is optional, and is a string of up to 256 characters. For an example of an attribute file, see the descriptions of the PGS_PC_Get*Attr Tools.


201|87002002709.no9_gac|||||1

Field 7 is the sequence number. It is used if there is more than one physical file associated with the logical identifier of Field 1, which is normally only the case for PRODUCT INPUT and PRODUCT OUTPUT files.
At the SCF, you must assign this sequence number to each instance of the file in the PCF; at the DAAC, this is done by the production system.
The actual value of the sequence number is not relevant to your code; it is an internal number used by the production system.
At the SCF, you must list these sequence numbers in the PCF starting with the largest first, then decrementing by one, down to the smallest (1), as shown in the example.

The version number, which is used as an argument to Toolkit functions that access different instances of a file, is not the same as sequence number. The version number is the order which the files are listed in the PCF, from smallest (1) to largest.
As an example, if the PCF contains the entries

201|87002002710.no9_gac|||||2
201|87002002709.no9_gac|||||1

then file 87002002710.no9_gac is version #1 (sequence #2), and file 87002002709.no9_gac is version #2 (sequence #1).
No information about file content may be inferred from sequence number. This number is for internal system use only.
Use the version number, i.e., the order of listing of PCF entries, as the input to appropriate Toolkit functions.

(As you may have noticed, it so happens that the the version numbers specified in your code run opposite to the sequence numbers defined in the PCF.)

Field 7 is required for PRODUCT INPUT and PRODUCT OUTPUT files (but is optional for all other sections of the PCF). It must be an integer.

The rest of the entries in the PRODUCT INPUT section of the Pathfinder AVHRR/Land Toolkit Prototype file (Appendix B ), in the section labeled "Toolkit product input files", are Toolkit files. These are normally not modified.

3.1.2.3 PRODUCT OUTPUT

This section is for standard product output files.

?   PRODUCT OUTPUT FILES 
# [ next line is for default location ]
! ~/runtime
#
# ----------------------------------------------------------
# Pathfinder AVHRR/Land main output file
# ----------------------------------------------------------
301|test11.hdf|||||1

This file is defined in C code as


#define HDF_FILE      301

or in Fortran code as

      PARAMETER (HDF_FILE=301)

It resides in directory $PGSHOME/runtime. It does not have an attribute file.

This section has the same fields as PRODUCT INPUT.

3.1.2.4 SUPPORT INPUT

This section is primarily for files that are input to Toolkit functions. Ordinarily, you would not modify any entries in this section. An exception to this is the template files used for ancillary files; see the Ancillary Data Access Tools section.


?   SUPPORT INPUT FILES 
# [ next line is for default location ]
! ~/runtime
#
# ----------------------------------------------------------
# Pathfinder AVHRR/Land support input files
# ----------------------------------------------------------

They reside in directory $PGSHOME/runtime. They have no attribute files.

This section has the same fields as PRODUCT INPUT and PRODUCT OUTPUT, except that Field 7 is not required>

There are no support input files in the Pathfinder AVHRR/Land Toolkit Prototype.

The entries in the SUPPORT INPUT section of the Pathfinder AVHRR/Land Toolkit Prototype file (Appendix B ) are Toolkit files, mostly to support the Ancillary Data Access (AA) Tools. You may modify these, as explained in the AA Tools section of this document.

3.1.2.5 SUPPORT OUTPUT

This section is primarily for files that are output from Toolkit functions

?   SUPPORT OUTPUT FILES 
# [ next line is for default location ]
! ~/runtime
#

This section has the same fields as PRODUCT INPUT and PRODUCT OUTPUT, except that Field 7 is not required.

There are no support output files in the Pathfinder AVHRR/Land Toolkit Prototype.

The Toolkit files in this section support the SMF Log files . You may change the names of the files and directories if you want, but not the logical identifier (Field 1).

3.1.2.6 USER-DEFINED RUNTIME PARAMETERS

This section of the PCF is different from the other sections in that it does not contain information about files. Instead, it may be used to obtain other kinds of information from the production environment.

?   USER DEFINED RUNTIME PARAMETERS
#
# ----------------------------------------------------------
# Pathfinder AVHRR/Land runtime parameters
# ----------------------------------------------------------
601|requested_size_x|409
602|requested_size_y|128
603|wait_time|3
601|requested_size_x|409

Field 1 is as always the logical identifier. This field is required.

601|requested_size_x|409

Field 2 is the parameter name. It is an optional text string of up to 200 characters. The Toolkit ignores this field; its intended use is for identification in this PCF, so you may enter whatever you like here. In the Pathfinder AVHRR/Land Toolkit Prototype, the name of the variable in the code is used for this purpose.

601|requested_size_x|409

Field 3 is the parameter value. This is read into your code as a string of up to 200 characters by the Toolkit (PGS_PC_GetConfigData). Your code is responsible for any necessary conversion. e.g. to integer. This field is required.

Toolkit files in this section support the sending of files and email to remote locations. For an explanation of these entries in the PCF, see the Notes section of the Tool Description for PGS_SMF_SendRuntimeData.

3.1.2.7 INTERMEDIATE INPUT

?   INTERMEDIATE INPUT
# [ next line is for default location]
! ~/runtime
#

This section and the next are for intermediate files, or files that will exist for longer than a single PGE, but are not standard products. This section is for intermediate input files.

This section has the same fields as PRODUCT INPUT and PRODUCT OUTPUT, except that Field 7 is not required. The unqualified file name (Field 2) is ordinarily the name of a file that was generated as an INTERMEDIATE OUTPUT file by a previous run of this PGE. At the SCF, if you are testing successive runs of a PGE which share intermediate files, you need to make sure that the logical identifier is the same in the PCF that you use for all the runs. If you are accessing the intermediate file from a different PGE than the one that created it, you also need to make sure that the mnemonic definitions in your code reference the same logical identifier. You should also copy over the file name if you use a different PCF.

How intermediate files are handled in the production environment, specifically how long they stay around, has not been determined at this writing.

Use function PGS_IO_Gen_Temp_Open (C) or PGS_IO_Gen_Temp_OpenF (Fortran) to open intermediate files.

There are no intermediate files in the Pathfinder AVHRR/Land Toolkit Prototype.

3.1.2.8 INTERMEDIATE OUTPUT

?   INTERMEDIATE OUTPUT
# [next line is for default location]
! ~/runtime
#

This section is for intermediate output files.

Entries for this section of the PCF are created by the Toolkit; you do not need to enter values.

This section has the same fields as PRODUCT INPUT and PRODUCT OUTPUT, except that Field 7 is not required. The unqualified file name (Field 2) is generated by the Toolkit.

How intermediate files are handled in the production environment, specifically how long they stay around, has not been determined at this writing.

Use function PGS_IO_Gen_Temp_Open (C) or PGS_IO_Gen_Temp_OpenF (Fortran) to open intermediate files.

There are no intermediate files in the Pathfinder AVHRR/Land Toolkit Prototype.

3.1.2.9 TEMPORARY IO

Temporary files are files that exist only for the duration of a single PGE; the production system deletes these files automatically on PGE termination. (You may use the function PGS_IO_Gen_Temp_Delete to do this at the SCF.) Since a single PGE may consist of several of your executables, this section is part of the PCF to enable these files to be passed among these executables.

Entries for this section of the PCF are created by the Toolkit; you do not need to enter values. The unqualified file name (Field 2) is generated by the Toolkit.

?   TEMPORARY IO
# [ next line is for default location ]
! ~/runtime
#
# ----------------------------------------------------------
# Pathfinder AVHRR/Land temporary file
# ----------------------------------------------------------
901|pc1157318822894183312||0|0|0|0

This file is defined in C code as

#define BINARY_OUTPUT		901

or in Fortran code as

      PARAMETER (BINARY_OUTPUT=901)

It resides in directory $PGSHOME/runtime. It has no attribute file.

If you are sharing this temporary file among executables in the same PGE, then you need to have the same #define or PARAMETER statement in the code for each appropriate executable.

Use function PGS_IO_Gen_Temp_Open (C) or PGS_IO_Gen_Temp_OpenF (Fortran) to open temporary files. Use function PGS_IO_Gen_Temp_Delete to delete files you no longer need within a PGE.

This section has the same fields as PRODUCT INPUT and PRODUCT OUTPUT, except that Field 7 is not required.

3.1.2.10 End of PCF

All PCFs must end with the line

? END

Any information after this line is ignored.

3.1.3 Checking your Process Control File

Now that you have created your PCF, you can use it from your software through use of the Toolkit. However, you might want to check it to see if you have entered everything correctly. You can do this by using the pccheck utility, a Unix executable included with the Toolkit. This program is compiled at the time of Toolkit installation, and is located in directory $PGSBIN. You execute shell script pccheck.sh, which calls executable pctcheck; its source code is $PGSSRC/PC/PGS_PC_Check.c . To run it on your file mypcfile, on the Unix command line type

$PGSBIN/pccheck.sh -i mypcfile

If there are any errors in your file, you will see messages of the form

Error - problem with version number in Standard input file
Line number:  23
Line:  401|goldtopolandsea8.bin|||||

In this example the version number was omitted from the STANDARD INPUT file entry.

At the end, you will see a summary of the form

Check of mypcfile completed
Errors found:  7
Warnings found:  0

For this utility, a pccheck error is defined as a PCF entry that will cause a Toolkit PC function to return an error message. A pccheck warning is defined as an incorrect entry that will not cause the Toolkit trouble, but may cause the PGE to operate incorrectly. For example, a blank character in the file name field does not bother a Toolkit PC function, since it simply returns the string as is; pccheck will not return an error. But a blank character will certainly cause a Unix error, when the file open is attempted by a Toolkit function; pccheck will return a warning to this effect. Output is returned to stdout (usually the screen).

This is a simple explanation of how the pccheck utility works. For details, including a list of error messages, and information about other command line options, see "Validating Process Control Files", sec. C.2 of Appendix C, in the Toolkit Users Guide.

3.1.4 Metadata considerations

Protoype metadata (MET) tools, which format standard product metadata for ingest to the data server(SDS), will be available in the next Toolkit delivery.

For the present, the only Toolkit functions that deal with data about data are the tools PGS_PC_GetFileAttr, PGS_PC_GetFileAttrCom and PGS_PC_GetFileByAttr. These functions are involved in retrieving file "attribute" data from the system, via the Process Control file. Essentially, you can get character string metadata from a text file using these functions.

Since details about how the production system handles metadata are not yet available, this mechanism was determined to be the best that can be done about this issue at the moment. Every effort will be made to keep the calling sequence unchanged for these tools in the future. However, given the uncertainties about this issue, this cannot be guaranteed.

3.1.5 Command tools for use in shell scripts

This section briefly describes the usage of the set of Command tools, which are callable from Unix shell scripts. These tools are generally identified by the suffix "Com" in the function name.

Tool PGS_PC_Shell.sh is used to call your PGE. It is strongly recommended that you call your PGE from this function during testing at the SCF; among other things, it enables Toolkit (not user) shared memory, which speeds execution of certain Toolkit functions.
You must use either this tool or PGS_PC_InitCom if you want to enable the creation of Toolkit log files.
You must use either this tool or PGS_PC_TermCom if you want to send any files to a remote machine, through use of function PGS_SMF_SendRuntimeData.

Tools PGS_PC_InitCom and PGS_PC_TermCom are used to initialize and terminate your PGE respectively.
Ordinarily you would not use these, as they are called internally by PGS_PC_Shell.sh. They are included in the Toolkit documentation for reference in case you wish to customize PGS_PC_Shell.sh for some reason; however, please note that any such customization is not part of your delivery to the DAAC.

Note: The above three functions are used at the DAAC as well as at your SCF; however, it is not necessary to include them in scripts that you deliver to the DAAC for Integration and Test. They are included as part of the Toolkit delivery for your use in testing at the SCF.
The three functions are to be used outside of your PGE.

The rest of the PGS_PC_*Com tools are simply wrappers on Toolkit API tools. These functions are for use inside your PGE.

Further details are given in the Tool Descriptions.

3.2 Process Control (PC) Tool descriptions

3.2.1 PGS_PC_InitCom

Short explanation of what it's for: Command line function for initializing the Toolkit for use with your PGE.
Normally not used at the SCF, since its functionality is fully covered by PGS_PC_Shell.sh.

This function is in file: $PGSSRC/PC/PGS_PC_InitCom.c

Shell example:

# Execute a PGE, enabling Toolkit (not user) shared memory, 
#    and also initializing creation of Toolkit log files,
# and have an SMF Cache size of 50.

unix% PGS_PC_InitCom 1 1 50

Notes:

You might want to use this function if you decide to write a custom script to call your PGE, in lieu of using PGS_PC_Shell.sh; however, please note that any such customization is not part of your delivery to the DAAC.

This function enables your PGE to

  • Use Toolkit (not user) shared memory, which speeds up Toolkit processing
  • Automatically load the Process Control File into Toolkit shared memory
  • Automatically create Toolkit log files

The first argument of this function is for turning on or off Toolkit (not user) shared memory, if available; the second argument is for turning on or off creation of Toolkit log files. The third argument is to specify the amount (in records) of SMF Cache memory to reserve for the storage of SMF messages.

In the example "unix%" is the Unix command line prompt.

For this particular function, the example is identical for any Unix shell.

3.2.2 PGS_PC_GenUniqueID

Short explanation of what it's for: Generates a string that uniquely identifies your standard product output file. May be used as file metadata.

This function is in file: $PGSSRC/PC/PGS_PC_GenUniqueID.c

Examples:

The examples assume the following exist in the Process Control File (PCF):

?   SYSTEM RUNTIME PARAMETERS
# ----------------------------------------------------------
# Production Run ID - unique production instance identifier
# ----------------------------------------------------------
1
# ----------------------------------------------------------
# Software ID - unique software configuration identifier
# ----------------------------------------------------------
1
C example:
#include <PGS_PC.h> 
#define HDF_FILE      301
char uniqueID[PGSd_PC_LABEL_SIZE_MAX];
PGSt_SMF_status returnStatus;
/*
Begin example
*/
returnStatus = PGS_PC_GenUniqueID(HDF_FILE,uniqueID);
/*
Variable uniqueID now contains the string
"PRID - 1 SID - 1 PRODID - 301"
*/
Fortran example:
      IMPLICIT NONE
      INCLUDE 'PGS_SMF.f'
      INCLUDE 'PGS_PC.f'
      INCLUDE 'PGS_PC_9.f'
      INTEGER pgs_pc_genuniqueid
      INTEGER HDF_FILE
      PARAMETER(HDF_FILE=301)
      CHARACTER*200 uniqueid
      INTEGER returnstatus
C
C Begin example
C
      returnstatus = pgs_pc_genuniqueid(HDF_FILE,uniqueid)
C
C Variable uniqueid now contains the string
C 'PRID - 1 SID - 1 PRODID - 301'
C
Notes:

The mechanism for using the output of this function as file metadata has not yet been defined.

  • No labels