# grdedit

Modify header or content of a grid

## Synopsis

gmt grdedit ingrid [ -A ] [ -C b|c|n|p ] [ -D[+x xname][+y yname][+z zname][+c[-|cpt]][+d dname][+s scale][+o offset][+n invalid][+t title][+r remark][+v varname] ] [ -E[a|e|h|l|r|t|v] ] [ -G outgrid ] [ -J parameters ] [ -L[+n|p] ] [ -N table ] [ -R region ] [ -S ] [ -T ] [ -V[level] ] [ -bi binary ] [ -di nodata[+c col] ] [ -e regexp ] [ -f flags ] [ -h headers ] [ -i flags ] [ -w flags ] [ -:[i|o] ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.

## Description

grdedit reads the header information in a binary 2-D grid file and replaces the information with values provided on the command line [if any]. As an option, global, geographical grids (with 360 degrees longitude range) can be rotated in the east-west direction, and individual nodal values can be replaced from a table of x, y, z values. grdedit only operates on files containing a grid header. Note: If it is important to retain the original data you should use -G to save the modified grid to a new file.

## Required Arguments

ingrid[=ID|?varname][+b band][+d divisor][+n invalid][+o offset][+s scale]

> Optionally, append =ID for reading a specific file format [Default is =nf] or ?varname for a specific netCDF variable [Default is the first 2-D grid found by GMT]. The following modifiers are supported:

> > - +b - Select a band [Default is 0].

> > - +d - Divide data values by the given divisor [Default is 1].

> > - +n - Replace data values matching invalid with NaN.

> > - +o - Offset data values by the given offset [Default is 0].

> > - +s - Scale data values by the given scale [Default is 1].

> Note: Any offset is added after any scaling.

## Optional Arguments

-A

  If necessary, adjust the file’s x_inc, y_inc to be compatible with its domain (or a new domain set with -R). Older grid files (i.e., created prior to GMT 3.1) often had excessive slop in x_inc, y_inc and an adjustment is necessary. Newer files are created correctly.

-Cb|c|n|p

  Normally, output grids store the current module’s command-line history. Use -C to specify what the output grid’s command history should be: Append directive b to write both the previous and the current module’s command histories, c to only write the current module’s command history, n to save no history whatsoever [Default], or select p to instead save only the previous command history.

-D[+x xname][+y yname][+z zname][+c[-|cpt]][+d dname][+s scale][+o offset][+n invalid][+t title][+r remark][+v varname]

  Control names and units of netCDF grid and cube meta-data. For dimensions with units, add the unit in square bracket (e.g., “distance [km]”). Select one or more of these modifiers:

  - +c - Append cpt to set a default CPT for this grid [turbo] or give - to remove any default CPT already set.

  - +d - Set dname, the data value name.

  - +n - Set the invalid number used to indicate a NaN or missing value.

  - +o - Set the offset to add to data after first scaling the data [0].

  - +r - Set a remark used for this grid (any sentence you prefer).

  - +s - Set the scale used fto multiply data values after they are read [1].

  - +t - Set a title used for this grid (any sentence you prefer).

  - +v - Append varname, the variable name of the data set.

  - +x - Append xname, the name of the x-coordinate (and optional unit in brackets).

  - +y - Append yname, the name of the y-coordinate (and optional unit in brackets).

  - +z - For 3-D cubes; append zname, the name of the z-coordinate (and optional unit in brackets).

  Give a blank name to completely reset a particular string. Use quotes to group texts with more than one word. If any of your text contains plus symbols you need to escape them (place a backslash before each plus-sign) so they are not confused with the option modifiers. Alternatively, you can place the entire double-quoted string inside single quotes. If you have shell variables that contain plus symbols you cannot use single quotes but you can escape the plus symbols in a variable using constructs like ${variable/+/\+}. Note that for geographic grids and cubes (-fg), xname and yname are set automatically. Normally, the data netCDF variable is called “z” (grid) or “cube” (data cube). You can rename this netCDF variable via +v.

-E[a|e|h|l|r|t|v]

  Transform the grid in one of six ways and (for l|r|t) interchange the x and y information: -Ea will flip the grid both horizontally and vertically, -Ee will exchange the x (longitude) and y (latitude) dimensions, -Eh will flip the grid horizontally (left-to-right), -El will rotate the grid 90 degrees counter-clockwise (left), -Er will rotate the grid 90 degrees clockwise (right), -Et will transpose the grid [Default], -Ev will flip the grid vertically (top-to-bottom). Incompatible with the other options (except -G).

-G outgrid[=ID][+d divisor][+n invalid][+o offset|a][+s scale|a][:driver[dataType][+c options]]

> Optionally, append =ID for writing a specific file format. The following modifiers are supported:

> > - +d - Divide data values by given divisor [Default is 1].

> > - +n - Replace data values matching invalid with a NaN.

> > - +o - Offset data values by the given offset, or append a for automatic range offset to preserve precision for integer grids [Default is 0].

> > - +s - Scale data values by the given scale, or append a for automatic scaling to preserve precision for integer grids [Default is 1].

> Note: Any offset is added before any scaling. +sa also sets +oa (unless overridden). To write specific formats via GDAL, use =gd and supply driver (and optionally dataType) and/or one or more concatenated GDAL -co options using +c. See the “Writing grids and images” cookbook section for more details.

-J parameters

  Specify the projection. Use the -J syntax to save the georeferencing info as CF-1 compliant metadata in netCDF grids. This metadata will be recognized by GDAL.

-L[+n|p]

  Adjust the longitude values in the grid (only applies to geographic grids). By default we will try to adjust west and east so that west >= -180 or east <= +180, but this depends on the range of the longitudes. Append +n to force negative longitude values and +p to force positive longitude values.

-N table

  Read the ASCII (or binary; see -bi) file table and replace the corresponding nodal values in the grid with these x,y,z values.

-R xmin/xmax/ymin/ymax[+r][+u unit]

  Specify the region of interest. The new limits will replace those in the grid, and the x_inc, y_inc values are adjusted, if necessary. Note: Here, -R does not select a sub-region of the input grid but instead simply replaces the domain of the grid. (See full description) (See cookbook information).

-S

  For global, geographical grids only. Grid values will be shifted longitudinally according to the new borders given in -R.

-T

  Make necessary changes in the header to convert a gridline-registered grid to a pixel-registered grid, or vice-versa. Basically, gridline-registered grids will have their domain extended by half the x- and y-increments whereas pixel-registered grids will have their domain shrunk by the same amount. This is a non-destructive grid change; see Switching registrations.

-V[level]

  Select verbosity level [w]. (See full description) (See cookbook information).

-bi record[+b|l] (more …)

  Select native binary format for primary table input. [Default is 3 input columns].

-di nodata[+c col] (more …)

  Replace input columns that equal nodata with NaN.

-e[~]“pattern” | -e[~]/regexp/[i] (more …)

  Only accept data records that match the given pattern.

-f[i|o]colinfo (more …)

  Specify data types of input and/or output columns.

-h[i|o][n][+c][+d][+m segheader][+r remark][+t title] (more …)

  Skip or produce header record(s).

-i cols[+l][+d divisor][+s scale|d|k][+o offset][,…][,t[word]] (more …)

  Select input columns and transformations (0 is first column, t is trailing text, append word to read one word only).

-wy|a|w|d|h|m|s|c period[/phase][+c col] (more …)

  Convert an input coordinate to a cyclical coordinate.

-^ or just -

  Print a short message about the syntax of the command, then exit (Note: on Windows just use -).

-+ or just +

  Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.

-? or no arguments

  Print a complete usage (help) message, including the explanation of all options, then exit.

--PAR=value

  Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.

## 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 -R90w/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 gmt.conf file or on the command line. In addition, the unit attribute of the time variable will indicate both this unit and epoch.

## Examples

Note: Below are some examples of valid syntax for this module. The examples that use remote files (file names starting with `@`) can be cut and pasted into your terminal for testing. Other commands requiring input files are just dummy examples of the types of uses that are common but cannot be run verbatim as written.

Let us assume the file data.nc covers the area 300/310/10/30. We want to change the boundaries from geodetic longitudes to geographic and put a new title in the header. We accomplish this by:

    gmt grdedit data.nc -R-60/-50/10/30 -D+t"Gravity Anomalies"

The grid world.nc has the limits 0/360/-72/72. To shift the data so that the limits would be -180/180/-72/72, use:

    gmt grdedit world.nc -R-180/180/-72/72 -S

The file junk.nc was created prior to GMT 3.1 with incompatible -R and -I arguments. To reset the x- and y-increments we run:

    gmt grdedit junk.nc -A

The file junk.nc was created prior to GMT 4.1.3 and does not contain the required information to indicate that the grid is geographic. To add this information, run:

    gmt grdedit junk.nc -fg

To rotate the grid oblique.nc 90 degrees counter-clockwise and write out the rotated grid to a new file, run:

    gmt grdedit oblique.nc -El -Goblique_rot.nc

To ensure that the grid depths.nc only has positive longitude values, run:

    gmt grdedit depths.nc -L+p

The grid bad.nc has latitude as x-coordinates an longitude as y-coordinates. We can exchange the two dimension by running:

    gmt grdedit bad.nc -Ee -Gnew.nc

## Notes

This module is not a general editor for netCDF files. If your netCDF file contains more than one 2-D (or higher dimension) data layer, then only the selected layer will be written out if changes are requested. Likewise, if you have additional netCDF attributes then those will also be lost in any revised output.

## See Also

gmt, grd2xyz, grdfill, grdinfo, xyz2grd