# Mathematics Programs

### Raw Data File Mathematics

The program to perform mathematics on raw data file is called **rawmath**. Raw data can be either
entered by hand or created by a program such as **sfcwx** or **upairwx**.
Once a raw data file has been created, math can be performed on it using this program. The
output of these computations can either be sent to **mapplt** for plotting or
**grid** for gridding and contouring. The operations available with **rawmath**
are:

`rawmath rawa add rawb = rawc` |
Standard functions add, subtract, multiply, divide and modulus rawa, rawb, rawc are raw data files |

`rawmath rawa add #number = rawb` |
Add a constant number to a station. |

`rawmath rawa mul #number = rawc` |
Scale a value by number |

`rawmath sum rawa rawb ... = rawd` |
Sum station values |

`rawmath ext rawa = rawd` |
Extract a field from a raw file |

`rawmath rawa merge rawb = rawd` |
Merge two like raw files |

`rawmath series rawa rawb ...= rawd` |

Also "-" can be used for a filename to read from standard input or write to standard output. This can be used to change units or to scale output. For operations between files, stations are matched before the operation is performed. This can be used to get a plot of 24 hour temperature change:

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

### Grid File Mathematics

A program to perform mathematics on grid files is called **grdmath**. Grid data files are generally
not entered by hand but are generated from a gridding program such as **sfccalc**,
**upcalc**, and **grid** or by directly referencing a GRIB file.
Once the grid file exists, grdmath can be called and the output sent to programs such as **contour**
or **vector**. The operations available with **grdmath** are:

`grdmath grida add gridb = gridc` |
Standard functions add, subtract, multiply and divide grida, gridb, gridc, gridu, gridv are grid files |

`grdmath grida add #number = gridb` |
Add a constant number to a grid |

`grdmath grida mul #number = gridc ` |
Scale a grid by number |

`grdmath sum grida gridb ... = gridd` |
Sum grids |

`grdmath avg grida gridb ... = gridd` |
Average grids |

`grdmath dx grida = gridb` |
Finite difference in x |

`grdmath dy grida = gridb ` |
Finite difference in y |

`grdmath cvg gridu gridv = gridb` |
Convergence |

`grdmath vort gridu gridv = gridb` |
Vorticity |

`grdmath adv grida gridu gridv = gridb` |
Advection of grida |

`grdmath spd gridu gridv = gridb` |
Speed given u and v wind components |

`grdmath interp grida factor gridb = gridc` |
Interpolates between two grids using factor |

`grdmath grida add #cor = gridb` |
Add coriolis parameter to grida |

Also "-" can be used for a filename to read from standard input or write to standard output. For example, to convert the temps to Celsius:

sfccalc -re=us -va=st -pl=none -of=std -cu -pf=calc | \ grdmath - sub #32 = - | grdmath - mul #.555555 = - "Temperature (C)" | contour -in=5 -pl=cf -de=d -

Multiple grids can be moved around by using ():

( grdmath uwind.grd sub ugeos.grd = - ; grdmath vwind.grd sub vgeos.grd = - ) | vector -de=p -la "500 mb Ageos Wind vectors" - -

This will plot ageostrophic wind vectors. Notice that both the U and V component is read in through standard input.

For further information about WXP, email technical-support@weather.unisys.com

*Last updated by Dan Vietor on June 8, 1998*