# GRDMASK

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
GRID FILE FORMATS
GEOGRAPHICAL AND TIME COORDINATES
EXAMPLES
SEE ALSO

## NAME

grdmask − Create mask grid files from xy paths.

## SYNOPSIS

grdmask pathfiles −G mask_grd_file] −I xinc[unit][=|+][/yinc[unit][=|+]] −R west/east/south/north[r] [ −A[m|p] ] [ −F ] [ −H[i][nrec] ] [ −N out/edge/in ] [ −S search_radius[m|c|k|K] ] [ −V ] [ −:[i|o] ] [ −bi[s|S|d|D[ncol]|c[var1/...]] ] [ −f colinfo ] [ −m[flag] ]

## DESCRIPTION

grdmask can operate in two different modes. 1. It reads one or more xy-files that each define a closed polygon. The nodes defined by the specified region and lattice spacing will be set equal to one of three possible values depending on whether the node is outside, on the polygon perimeter, or inside the polygon. The resulting mask may be used in subsequent operations involving grdmath to mask out data from polygonal areas. 2. The xy-files simply represent data point locations and the mask is set to the inside or outside value depending on whether a node is within a maximum distance from the nearest data point. If the distance specified is zero then only the nodes nearest each data point are considered "inside".
pathfiles

The name of 1 or more ASCII [or binary, see −b] files holding the polygon(s) or data points.

| −G |  | Name of resulting output mask grid file. (See GRID FILE FORMATS below).

−I

x_inc [and optionally y_inc] is the grid spacing. Optionally, append a suffix modifier. Geographical (degrees) coordinates: Append m to indicate arc minutes or c to indicate arc seconds. If one of the units e, k, i, or n is appended instead, the increment is assumed to be given in meter, km, miles, or nautical miles, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on ELLIPSOID). If /y_inc is given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude. All coordinates: If = is appended then the corresponding max x (east) or y (north) may be slightly adjusted to fit exactly the given increment [by default the increment may be adjusted slightly to fit the given domain]. Finally, instead of giving an increment you may specify the number of nodes desired by appending + to the supplied integer argument; the increment is then recalculated from the number of nodes and the domain. The resulting increment value depends on whether you have selected a gridline-registered or pixel-registered grid; see Appendix B for details. Note: if −R grdfile is used then grid spacing has already been initialized; use −I to override the values.

−R

xmin, xmax, ymin, and ymax specify the Region of interest. For geographic regions, these limits correspond to west, east, south, and north and you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands −Rg and −Rd stand for global domain (0/360 and -180/+180 in longitude respectively, with -90/+90 in latitude). Alternatively, specify the name of an existing grid file and the −R settings (and grid spacing, if applicable) are copied from the grid. For calendar time coordinates you may either give (a) relative time (relative to the selected TIME_EPOCH and in the selected TIME_UNIT; append t to −JX|x), or (b) absolute time of the form [date]T[clock] (append T to −JX|x). At least one of date and clock must be present; the T is always required. The date string must be of the form [-]yyyy[-mm[-dd]] (Gregorian calendar) or yyyy[-Www[-d]] (ISO week calendar), while the clock string must be of the form hh:mm:ss[.xxx]. The use of delimiters and their type and positions must be exactly as indicated (however, input, output and plot formats are customizable; see gmtdefaults).

## OPTIONS

| −A |  | If the input data are geographic (as indicated by −fi) then the sides in the polygons will be approximated by great circle arcs. When using the −A sides will be regarded as straight lines. Alternatively, append m to have sides first follow meridians, then parallels. Or append p to first follow parallels, then meridians.
| −F |  | Force pixel node registration [Default is gridline registration]. (Node registrations are defined in GMT Cookbook Appendix B on grid file formats.)
| −H |  | Input file(s) has header record(s). If used, the default number of header records is N_HEADER_RECS. Use −Hi if only input data should have header records [Default will write out header records if the input data have them]. Blank lines and lines starting with # are always skipped.
| −N |  | Sets the values that will be assigned to nodes that are outside the polygons, on the edge, or inside. Values can be any number, including the textstring NaN [Default is 0/0/1].

−S

Set nodes depending on their distance from the nearest data point. Nodes within radius [0] from a data point are considered inside. Append m to indicate minutes or c to indicate seconds. Append k to indicate km (implies −R and −I are in degrees, and we will use a fast flat Earth approximation to calculate distance). For more accuracy, use uppercase K if distances should be calculated along geodesics. However, if the current ELLIPSOID is spherical then great circle calculations are used. If −S is not set then we consider the input data to define closed polygon(s) instead.

| −V |  | Selects verbose mode, which will send progress reports to stderr [Default runs "silently"].
| −bi |  | Selects binary input. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of columns in your binary input file if it exceeds the columns needed by the program. Or append c if the input file is netCDF. Optionally, append var1/var2/... to specify the variables to be read. [Default is 2 input columns].

−f

Special formatting of input and/or output columns (time or geographical data). Specify i or o to make this apply only to input or output [Default applies to both]. Give one or more columns (or column ranges) separated by commas. Append T (absolute calendar time), t (relative time in chosen TIME_UNIT since TIME_EPOCH), x (longitude), y (latitude), or f (floating point) to each column or column range item. Shorthand −f[i|o]g means −f[i|o]0x,1y (geographic coordinates).

| −m |  | Multiple segment file. Segments are separated by a record whose first character is flag. [Default is ’>’].

## GRID FILE FORMATS

By default GMT writes out grid as single precision floats in a COARDS-complaint netCDF file format. However, GMT is able to produce grid files in many other commonly used grid file formats and also facilitates so called "packing" of grids, writing out floating point data as 2- or 4-byte integers. To specify the precision, scale and offset, the user should add the suffix =id[/scale/offset[/nan]], where id is a two-letter identifier of the grid type and precision, and scale and offset are optional scale factor and offset to be applied to all grid values, and nan is the value used to indicate missing data. See grdreformat(1) and Section 4.17 of the GMT Technical Reference and Cookbook for more information.

When writing a netCDF file, the grid is stored by default with the variable name "z". To specify another variable name varname, append ?varname to the file name. Note that you may need to escape the special meaning of ? in your shell program by putting a backslash in front of it, or by placing the filename and suffix between quotes or double quotes.

## GEOGRAPHICAL AND TIME COORDINATES

When the output grid type is netCDF, the coordinates will be labeled "longitude", "latitude", or "time" based on the attributes of the input data or grid (if any) or on the −f or −R options. For example, both −f0x −f1t and −R 90w/90e/0t/3t will result in a longitude/time grid. When the x, y, or z coordinate is time, it will be stored in the grid as relative time since epoch as specified by TIME_UNIT and TIME_EPOCH in the .gmtdefaults file or on the command line. In addition, the unit attribute of the time variable will indicate both this unit and epoch.

## EXAMPLES

To set all nodes inside and on the polygons coastline_*.xy to 0, and outside points to 1, do

grdmask coastline_*.xy −R-60/-40/-40/-30 −I 5m −N 1/0/0 −G land_mask.grd −V

To set nodes within 50 km of data points to 1 and other nodes to NaN, do

grdmask data.xyz −R-60/-40/-40/-30 −I 5m −N NaN/1/1 −S 50k −G data_mask.grd −V

## SEE ALSO

GMT(1), grdlandmask(1), grdmath(1), grdclip(1), psmask(1), psclip(1)