WXP version 5
Program Reference

GRDMATH

Sections

NAME

grdmath - Mathematical manipulation program for grids

SYNOPSIS

grdmath [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 grdmath 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.
-gp=gridpath grid_path current directory Specifies the location/path of input and output grid files.
-gt=grid_type grid_type first grid Specifies the grid type number from the GRIB file.  If none is specified, only the first grid is used.
-of=out_file out_file wxp Specifies what type of output grid 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 grid file format
  • wxpb - Binary WXP grid file format
  • cdf - NetCDF grid 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 (reserved for future use)
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 operF2 = 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[+time:level:var[:units]]

The time, level, var, unit definitions are listed in the description section (also see filename resource).

The number must be preceded number sign "#" as in "#5.6".

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 operF2 = 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
or
#cor

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[+time:level:var[:units]]
or
filename[#num[:units]]

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

The extra information following the "+" or "#" defines which grid to use within a multigrid file. The value of num represents the sequence number of the grid in the file.  Grids are numbered starting at 0 (zero).  This number can be determined through a griblook listing.  

The values of time, level, and var make it possible to specify the grid based on typical grid information.  Possible values for each are:

The unit specification allows the user to change the units of the grid before performing the math.  

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.  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 grdmath 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:

QUERY - queries information from the grid, no grid output

STATISTICS - prints values, no grid output

MANIPULATION - produces hybrid grids

MATHEMATICS - performs math functions and returns a grid

NOTE: The file specifications can be replaced by numeric constants with the syntax:

#number

in most of the above functions.  For example, the number 5.32 would be entered "#5.32".

EXAMPLES

To get information on the grid:

   grdmath info uwnd.grd
   WXP analysis for 0500Z 21 DEC 96-Surface U wind component (m/s) 
   Model: 1 Ltype: 1 Level: 0 Var: 33 Hour: 0 Grid: 2 
   Proj: 1 Lat: 43.00 Lon: -93.00 NX: 25 NY: 17 DX: 1.10 DY: 1.10 
   Domain: pstereo::-93.000:::,43.000,-93.000,25,17,1.1000,1.1000 

To difference two grids:

   grdmath temp18.grd sub temp12.grd = diff.grd \
     "6 hour temp change (F)" "12-18Z 12 JUN 96"

This subtracts two grids produced by sfccalc to produce a 6 hour temperature change. The two quoted expressions change the grid title and date information.

To convert Fahrenheit to Celsius:

   grdmath copy tempF.grd:C = tempC.grd

This just copies the first grid into the second but the units of the first grid are changed after reading so the final grid has the new units.

To find the max and min of a grid:

   grdmath maxmin uwnd.grd
   8.024727 -5.086694

To piece two grids together:

   grdmath piece 2x1 96122012.gmi+24:850:temp:C \
      96122012.gmj+24:850:temp:C = 850_temp.grd

This will piece together two aviation grids for Europe and Asia.  The "+" in the filename separates the filename from the specification of grid information for parsing.  In this case, the 24 hour 850 mb temperature field will be parsed from the multi-grid files.  The ":C" specifies to convert the output to Celsius prior to piecing so the resultant pieced grid is in Celsius.

To remap a grid, you just list to grid to remap and the plot_domain specification:

   grdmath remap 850_temp.grd europe = 850_temp_e.grd

With the remap capability, you can difference grids that are not on the same projection such as model grids and those produced from WXP.

PIPING COMMANDS

This is a powerful concept that allows the output of one WXP command acts as the input to another.  You can use either "-" or "std" to represent a filename that is either written to standard output or read in from standard input.  Here is an example of computing wind speed from component wind fields and then contouring the output:

   grdmath spd uwnd.grd vwnd.grd = - | contour -ba -

You can derive the grids directly from a program like sfccalc:

   ( sfccalc -cu=la -re=mw -va=uwnd -pl=none -of=std -me=print; \
     sfccalc -cu=la -re=mw -va=vwnd -pl=none -of=std -me=print ) | \
     grdmath spd - - = - | contour -ba - 

FILES

SEE ALSO


Last updated June 10, 1998