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:
|
-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:
|
-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:
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:
- add
- sub
- mul
- div
- mod - modulus operator (remainder of A/B)
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:
- time: init,06,12,18,24,30,36,42,48,60,72,d3,d4,d5,d6,d7,d8,d9,d10
- level: sfc, sl (sea level), trop, wind, 1000, 850, 700, 500, 400, 300, 200, 100
- var: temp, rhum, pres, vvel, uwnd, vwnd, prec, lift
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
- info file
This prints out a 4 line report on the contents of the grid including data type and grid domain. - domain file
Prints only the grid domain in a format compatible with the plot_domain resource. - val file id ID
Prints the value interpolated from the grid based on the location of a specified station ID - val file ll lat,lon
Prints the value interpolated from the grid based on a specified latitude and longitude - val file x,y
Prints the value interpolated from the grid based on a specified gridpoint location (0,0 is up, right) - loc file id ID
Prints the gridpoint location of the specified station ID - loc file ll lat,lon
Prints the gridpoint location of the specified latitude and longitude
STATISTICS - prints values, no grid output
- max file
Prints the maximum value of the grid - min file
Prints the minimum value of the grid - maxmin file
Prints both the max and the min of the grid - avg file
Prints the average value of the grid - avgnum file
Prints the average value of the grid along with the number of valid gridpoints
MANIPULATION - produces hybrid grids
- copy file1 = ofile
Copies 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. - piece nxxny file1 file2 ... = ofile
This pieces together multiple grids into one composite grid. The number of grids to piece are specified by the nx and ny parameters. The component grids start with file1 in the upper right corner. The next grid is placed just to the right of the first grid in the first row (if nx > 1). The piecing continues until the first row is complete where the next row is then filled. - remap file plot_domain = ofile
This will remap a grid using simple interpolation to a new grid as specified in the plot_domain specification. ofile will contain the remapped grid.
MATHEMATICS - performs math functions and returns a grid
- max file1 file2 ... = ofile
Computes 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 ... = ofile
Computes 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 ... = ofile
Computes the sum of each gridpoint based on the values in the files file1, file2, etc. More than two files can be listed. - add file1 file2 ... = ofile
Same as sum - avg file1 file2 ... = ofile
Computes the average at each gridpoint based on the values in the files file1, file2, etc. More than two files can be listed - interp file1 file2|value file3 = ofile
This interpolates between the grid specified in file1 and the grid in file3 based on the value specified either in file2 or the value. This does a simple linear interpolation. A value of .5 would essentially give an average. A value of .8 will return a value that is .8 of the way to the second grid. - sub file1 file2 = ofile
This subtracts file2 from file1. - thick file1 file2 = ofile
Same as sub - mul file1 file2 = ofile
Multiplies the grids in file1 and file2. - div file1 file2 = ofile
Divides the values in file1 by the values in file2. - mod file1 file2 = ofile
Does the modulus of file1 divided by file2. This produces the remainder of the division computation. - sqrt file1 = ofile
Does the square root of all values in file1. - abs file1 = ofile
Returns the absolute value of the values in file1. - log file1 = ofile
Takes the logarithm of each value in file1 - log10 file1 = ofile
Takes the logarithm base 10 of each value in file1 - exp file1 = ofile
Exponentiates (ex) the values in file1 . This is the inverse of the log function - pow file1 file2 = ofile
This performs for power function of the values in file1 raised to the power of the values in file2. - sin file1 = ofile
Performs the trigonometric function sine of the values in file1. Input values are in degrees - cos file1 = ofile
Performs the trigonometric function cosine of the values in file1. Input values are in degrees - tan file1 = ofile
Performs the trigonometric function tangent of the values in file1. Input values are in degrees - asin file1 = ofile
Performs the trigonometric function arcsine of the values in file1. Output values are in degrees - acos file1 = ofile
Performs the trigonometric function arccosine of the values in file1. Output values are in degrees - atan file1 = ofile
Performs the trigonometric function arctangent of the values in file1. Output values are in degrees - atan2 file1 file2 = ofile
Performs the trigonometric function arctangent of the values in file1 divided by file2. The sign of 2 values determines the quadrant. This is the equivalent of the C atan2 function. Output values are in degrees - dewp file1 file2 = ofile
Computes the dewpoint based on temperature in file1 and the relative humidity in file2 - rhum file1 file2 = ofile
Computes the relative humidity based on temperature in file1 and the dewpoint in file2 - wetblb file1 file2 = ofile
Computes the wetbulb temperature based on temperature in file1 and the relative humidity or dewpoint in file2. - wchill file1 file2 [file3] = ofile
Computes the wind chill temperature based on the temperature in file1 and wind speed in file2, or the U wind component in file2 and the V wind component in file3. - heat file1 file2 = ofile
Computes the heat index temperature based on temperature in file1 and the relative humidity or dewpoint in file2. - theta file1 [file2] = ofile
Computes the potential temperature based on temperature in file1 and the pressure in file2. The pressure is optional if file1 is on a pressure surface (ie 500mb). - thetae file1 file2 [file3] = ofile
Computes the equivalent potential temperature based on temperature in file1, the relative humidity or dewpoint in file2 and the pressure in file3. The pressure is optional if file1 is on a pressure surface (ie 500mb). - thetav file1 file2 [file3] = ofile
Computes the virtual potential temperature based on temperature in file1, the relative humidity or dewpoint in file2 and the pressure in file3. The pressure is optional if file1 is on a pressure surface (ie 500mb). - vtemp file1 file2 [file3] = ofile
Computes the virtual temperature based on temperature in file1, the relative humidity or dewpoint in file2 and the pressure in file3. The pressure is optional if file1 is on a pressure surface (ie 500mb). - vapor file1 [file2] = ofile
Computes the vapor pressure based on dewpoint in file1, or the temperature in file1 and the relative humidity in file2. - shum file1 [file2] [file3] = ofile
Computes the specific humidity based on dewpoint in file1 and pressure in file2, or temperature in file1, relative humidity in file2 and pressure in file3. The pressure is optional if file1 is on a pressure surface (ie 500mb). - mixrat file1 [file2] [file3] = ofile
Computes the mixing ratio based on dewpoint in file1 and pressure in file2, or temperature in file1, relative humidity in file2 and pressure in file3. The pressure is optional if file1 is on a pressure surface (ie 500mb). - spd file1 file2 = ofile
Computes the wind speed based on U wind component in file1 and the V wind component in file2. - mag file1 file2 = ofile
Computes the vector magnitude based on X component in file1 and the Y component in file2. - dir file1 file2 = ofile
Computes the vector/wind direction based on X/U wind component in file1 and the Y V wind component in file2. - ugeos file1 = ofile
Computes the U geostrophic wind component based on geopotential height in file1. - vgeos file1 = ofile
Computes the V geostrophic wind component based on geopotential height in file1. - uq file1 file2 = ofile
Computes the U Q-vector component based on geopotential height in file1 and temperature in file2. - vq file1 file2 = ofile
Computes the V Q-vector component based on geopotential height in file1 and temperature in file2. - dx file1 = ofile
Finite differences (dfile1/dx) the grid file1 in the X direction. - dy file1 = ofile
Finite differences (dfile1/dy) the grid file1 in the Y direction. - grad file = xfile yfile
Gradient of the grid. Outputs 2 grids, one for the X component and the second for the Y component. - vdiff xfile1 yfile1 xfile2 yfile2 = xfile yfile
Computes a vector difference. Outputs 2 grids: X and Y. - dot xfile1 yfile1 xfile2 yfile2 = ofile
Computes a dot product. - cross xfile1 yfile1 xfile2 yfile2 = xfile yfile
Computes a vector cross product. Outputs 2 grids: X and Y. - lapl file1 = ofile
Computes the Laplacian of file1. - conv file1 file2 [file3] = ofile
Computes the convergence of the vector/wind field based on the U wind component in file1 and the V wind component in file2. If file3 is specified, the convergence is done on the grid field in file3. - diverg file1 file2 [file3] = ofile
Computes the divergence of the vector/wind field based on the U wind component in file1 and the V wind component in file2. If file3 is specified, the divergence is done on the grid field in file3. - def1 file1 file2 = ofile
Computes the first deformation term of the vector/wind field based on the U wind component in file1 and the V wind component in file2. - def2 file1 file2 = ofile
Computes the second deformation term of the vector/wind field based on the U wind component in file1 and the V wind component in file2. - rvort file1 file2 = ofile
Computes the vorticity or curl of the vector/wind field based on the U wind component in file1 and the V wind component in file2. - avort file1 file2 = ofile
Computes the absolute vorticity of the wind field based on the U wind component in file1 and the V wind component in file2. - adv file1 file2 file3 = ofile
Computes the advection of a specified field in file3 by the wind with the U wind component in file1 and the V wind component in file2.
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