The command resource specifies the files and values to use in the
mathematical operations along with the function to perform. The commands are of the
following formats:

funcF1 F2 ... = FO [Type] [Date]

F1 oper F2 =FO [Type] [Date]

The file specifications (F1,F2) can either be a filename or a number. The
filename can be specified with an extension to define a specific grid within a multiple
grid file:

filename[-field]

The field specification can be a column number or a field identifier. The field
identifier is a string that accompanies a column header in the raw file or a string that
precedes the data such as HGIRG=5.24

FO is the specific output filename. All filenames are prepended with the grid_pathresource value unless a full path is
specified.

Type and Date are optional strings used to modify the information header
of the grid file. This is useful in making sure the resulting grid has the proper
information since the math functions often misrepresent the final data type.

The grdmath program performs mathematical operation on gridpoint data. The functions
and the filenames are interpreted from the command line as part of the command resource.
There are two syntax's used.

Algebraic Format

The first form uses an algebraic approach:

F1 oper F2 =FO [Type] [Date]

where the operator (oper) is a simple algebraic operator:

add

sub

mul

div

mod - modulus operator (remainder of A/B)

ge - returns value if greater than or equal to second value, otherwise
returns missing

le - returns value if less than or equal to second value, otherwise
returns missing

The values F1 and F2 represent either filenames or numeric
values. The numeric values have the following syntax:

#number

The number listed can be any integer or floating point number. This option also
allows the specification of the Coriolis force (#cor). This value is
calculated for each grid point and added, subtracted, etc based on the math function.

The filenames have the following syntax:

filename[-field]

where filenameis the name of the grid file to use. If a relative
path is used, the value of the raw_path is prepended to the filename. The
filename can be "std" where standard input is used.

The extra information following the "-" defines which field to use
within a raw file. The field specification can be a column number or a field identifier.
The field identifier is a string that accompanies a column header in the raw file
or a string that precedes the data such as HGIRG=5.24

The FO specifies the output filename which stores the result of the
calculation. If a relative path is specified, the value of the grid_path is
prepended to the filename. This can be a file name tag which can be used to
construct a filename based on the date of the first raw file. The filename can be
"std" where standard output is used.

The Type specification is optional but can be used to set the new data
type in the grid file information header. When the grid is contoured, the data type is put
in the upper left hand corner of the plot. The rawmath program will attempt to
create a new data type label but many times this is incorrect. This allows the user
to correct the output data type.

The Date specification is optional but just like the Type specification
if the result of the calculations is incorrect.

Function Format

funcF1 F2 ... = FO [Type] [Date]

Much of the specification for this format is the same as in the algebraic format. The
difference is that there are more functions and some functions take more than 2
filenames/values. Here is a list of the functions and their required fields:

MANIPULATION - produces hybrid raw files

extfile1-field = ofileExtracts a specific field from a raw file.

copy file1 = ofileCopies the initial grid field in file1 to the output file. This
is useful when converting units or extracting a single grid from a multigrid file.

MATHEMATICS - performs math functions and returns a new raw file

max file1 file2 ... = ofileComputes the maximum value at each gridpoint based on the values in the files file1,
file2, etc. More than two files can be listed

min file1 file2 ... = ofileComputes the minimum value at each gridpoint based on the values in the files file1,
file2, etc. More than two files can be listed

sum file1 file2 ... = ofileComputes the sum of each gridpoint based on the values in the files file1, file2, etc.
More than two files can be listed.

NOTE: When more than one raw file is used, the station IDs (column 1 of the raw
file) are matched to give results per station location. If a station is missing from one
or the other file, it is omitted from the output file. This can be overridden by
specifying the miss parameter. This will give all missing stations the value
specified with the parameter. This allows sparse reporting parameters such as
precipitation to set zero (0) as a missing value so that all station that did not report
precipitation will get a value of 0 and be saved into the output file.

This example used the pipe mechanism to save using an intermediate file. First the
temperature file is offset by -32 and the result is written to standard output. It is then
piped to rawmath to multiply the result by 5/9 to get the desired output. The result is
saved back into a new raw file with a new title reflecting the unit change.

This subtracts two raw files produced by sfcwx to produce a 24 hour temperature change.
In the case, sfcwx is used to select station data for the US but instead of saving to
file, the result is written to standard output and piped to rawmath. The resulting raw
file is then displayed with mapplt.

In order to tally 24 hour precipitation data, rawmath can be used to add these values
on a daily basis:

will create raw files containing 24 hour precipitation data. To add them into a monthly
database:

rawmath prec_jun.raw add prec15.raw = prec_jun.raw -pa=miss:0

or

rawmath sum prec??.raw = prec_jun.raw -pa=miss:0

The miss:0 parameter specifies to keep stations missing in one but not both data
files by substituting the value 0 for the missing station. Using the above example,
if Chicago (ORD) did not report precipitation on the 15th, the ORD value from the monthly
database would normally be discarded. To maintain ORD in the output file, miss:0
must be specified. This will say to use the value listed (miss:value) to add
to the value of ORD in the monthly database to put the resulting value in the output file.
You can create the monthly database raw file with:

The series function allow data from several raw files to be incorporated into one raw
file. The default is to give the IDs from the first file the number 1, the second file 2,
and so on. The ident parameter is used to isolate LAF from each raw file. Again,
the miss:0 is used to put the value 0 in the output raw file even if LAF did not
report a precipitation value for that that day. The -fm=%3.2f specifies to format
the output in the raw file as %3.2f (in C). The result will be: