WXP
Program Reference

gridmath

Sections

NAME

gridmath - Mathematical manipulation program for grids

SYNOPSIS

gridmath [parameters...] operations

PARAMETERS

Command Line Resource Default Description
-h help No Lists basic help information.
-df=filename default wxp.cfg Sets the name of the resource file.
-na=name name the program name Specifies the name used in resource file parsing.
batch
-me=level message out2 Specifies level of messages to be displayed
-fp=path file_path the current directory Specifies location of database files.
-gp=path grid_path the current directory Specifies location of gridded output files from WXP.
-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
file_param
-pa=param[,param...] parameter none Specifies addition parameters to program.
command 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 [Info] [Date]
  • F1 operF2 = FO [Info] [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 resrc: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 resrc:grid_path resource value unless a full path is specified.

Info and Date are optional strings used to modify the information header date/time header in 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 grddmath program performs mathematical operation on gridpoint data. The functions and the filenames are interpreted from the command line as part of the resrc:command resource. There are two syntax's used.

Algebraic Format

The first form uses an algebraic approach:

F1 oper F2 = FO [Info] [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.

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 full path is used, the file is used unmodified. If a relative path is used, the name is first treated as a name convention. If it's a valid name convention, then a filename is constructed from it and the value of the current resource. Otherwise, the value of the resec:grid_path is prepended to the filename. The filename can be "std" where standard input is used. If the filename is preceded with a "^", the filename is treated as a model value. The model.lup file is then queried for the name convention and any grid piecing that needs to be done.

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 prog:gribfile 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. /p>

The FO specifies the output filename which stores the result of the calculation. If a relative path is specified, the value of the resrc:grid_path is prepended to the filename. The filename can be "std" where standard output is used.

The Info 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 gridmath 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 Info specification if the result of the calculations is incorrect.

Function Format

func F1 F2 ... = FO [Info] [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 October 2013