WXP version 5
Program Reference

RAWMATH

Sections

NAME

rawmath - Mathematical manipulation program for raw files

SYNOPSIS

rawmath [parameters...] operations

PARAMETERS

Command Line Resource Default Description
-h help No Lists basic help information.
-df=filename default .wxpdef Sets the name of the resource file.
-na=name name rawmath Specifies the name used in resource file parsing.
-ba batch No Run program in batch mode
-me=level message out2 Specifies level of messages to be displayed
-fp=filepath file_path current directory Specifies location of database files.  All raw files used in this program are assumed to be in the file_path directory.
-rp=rawpath raw_path current directory Specifies the location/path of input and output raw files.
-of=out_file out_file wxp Specifies what type of output raw file the program will produce. The input file type is queries when the file is opened but the user may change the output file type.  The options are:
  • wxp - ASCII WXP raw file format
-pf=file_param file_param prompt user,
use in batch mode
Specifies how to deal with writing to files that already exist. Possible values are:
  • Use - use the existing file, don't overwrite.  The program sometimes terminates when this occurs.  This is especially true for decoders which perform no other operation than to create this file.
  • Over - overwrite the existing file
  • App - append the information onto the end of the existing file
-pa=param[,param...] parameter None Extra parameters:
  • miss:#
    Specifies value to use for all missing stations in a file to file operation.
  • noattr
    Specifies to remove attribute information when writing to the output file.
command command None 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:
  • func F1 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_path resource 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.

DESCRIPTION

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:

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 filename is 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

func F1 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

MATHEMATICS - performs math functions and returns a new raw file

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.

EXAMPLES

To convert Fahrenheit to Celsius:

   rawmath st_f.raw sub #32 = - | \
   rawmath - mul #.555555 = st_c.raw "Temperature (C)"

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.

To difference two grids:

   ( sfcwx -re=us -pr=3 -va=temp -of=std -dr=none -cu=la ; \
     sfcwx -re=us -pr=3 -va=temp -of=std -dr=none -cu=la-24 ) | \
     rawmath - sub - = - "24 hour Temp change (F)" | \
     mapplt -re=us -de=d -

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:

   sfcwx 12061597 -va=r2 -pr=4 -of=prec15.raw -dr=none -re=us
   sfcwx 12061697 -va=r2 -pr=4 -of=prec16.raw -dr=none -re=us

or

   sfcwx -ho=12 -cu -va=r2 -pr=4 -of=prec17.raw -dr=none -re=us

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:

   rawmath prec01.raw add #0 = prec_jun.raw "Monthly precip (in)" "June 1993"

This is a simple way to just copy the values from the prec01.raw file to the prec_jun.raw file. To plot the results:

   mapplt -fm=.2 -re=us -sc=.5 prec_jun.raw

To compare to normal:

   rawmath prec_jun.raw div prec_norm_jun.raw = - | 
   rawmath - mul #100 = prec_normp_jun.raw "Percent of June normal prec"

To plot the results:

   mapplt -fm=.0 -re=us -sc=.5 prec_normp_jun.raw

Rawmath can also develop time series with the "series" function":

   rawmath series prec10.raw prec11.raw prec12.raw ...= - \
     -id=LAF -pa=miss:0 -fm=%3.2f "Daily precip for LAF" "NOV-DEC 1996"

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:

   WXPRAW
   NOV-DEC 1996
   Daily precip for LAF (in)
   1 0.00
   2 0.00
   3 0.00
   4 0.35
   5 0.67
   6 0.64
   ...

To override the ID specification, add a user specified ID after the filename:

   rawmath series prec10.raw:10_NOV prec11.raw:11_NOV prec12.raw:12_NOV \
      ...= - -id=LAF -pa=miss:0 -fm=3.2 "Daily precip for LAF" "NOV-DEC 1993"

The result is:

   WXPRAW
   NOV-DEC 1996
   Daily precip for LAF
   10_NOV 0.00
   11_NOV 0.00
   12_NOV 0.00
   13_NOV 0.35
   14_NOV 0.67
   15_NOV 0.64
   ...

To plot the data using mapplt:

   mapplt -pd=cat,0,0,3,2,30,2 -cod=cyan:w5 \
     -pp=lalo:3:.2,bar:0,mark:none prec_LAF.raw

Rawmath has the capability of creating time series of SHEF data. For example, rawmath could be used to create a new raw file with:

   rawmath series 12111996.shf-HGIRG:NOV19 12112096.shf-HGIRG:NOV20 \
      12112196.shf-HGIRG:NOV21 12112296.shf-HGIRG:NOV22 = series.raw -id=LAFI3 \
      -fm=%5.2f "SHEF-HGIRG for LAFI3"

   WXPRAW
   12Z 19 NOV 93
   SHEF-HGIRG for LAFI3
   NOV19 15.43
   NOV20 13.75
   NOV21 11.05
   NOV22  9.39

The mapplt program will create a time-value plot:

mapplt -pd=cat,0,5,2,2,3,15 -pp=line,mark:1,lalo:1:1 -de=d series.raw

This uses the series function to extract HGIRG data from the SHEF raw files. This is labeled by day for the station LAFI3.

FILES

SEE ALSO


Last updated July 27, 1998