grd2xyz - Convert grid file to data table
grd2xyz grid [ -C[f|i] ] [ -Rregion ] [ -V[level] ] [ -W[weight] ] [ -Z[flags] ] [ -bobinary ] [ -dnodata ] [ -fflags ] [ -ho[n] ] [ -oflags ] [ -sflags ]
Note: No space is allowed between the option flag and the associated arguments.
grd2xyz reads one or more binary 2-D grid files and writes out xyz-triplets in ASCII [or binary] format to standard output. Modify the precision of the ASCII output format by editing the FORMAT_FLOAT_OUT parameter in your gmt.conf file or use --D_FORMAT=format on the command line, or choose binary output using single or double precision storage. As an option you may output z-values without the (x,y) coordinates; see -Z below.
Write a 1-column ASCII [or binary] table. Output will be organized according to the specified ordering convention contained in flags. If data should be written by rows, make flags start with T (op) if first row is y = ymax or B (ottom) if first row is y = ymin. Then, append L or R to indicate that first element should start at left or right end of row. Likewise for column formats: start with L or R to position first column, and then append T or B to position first element in a row. For gridline registered grids: If grid is periodic in x but the written data should not contain the (redundant) column at x = xmax, append x. For grid periodic in y, skip writing the redundant row at y = ymax by appending y. If the byte-order needs to be swapped, append w. Select one of several data types (all binary except a):
Default format is scanline orientation of ASCII numbers: -ZTLa. Note that -Z only applies to 1-column output.
The ASCII output formats of numerical data are controlled by parameters in your gmt.conf file. Longitude and latitude are formatted according to FORMAT_GEO_OUT, whereas other values are formatted according to FORMAT_FLOAT_OUT. Be aware that the format in effect can lead to loss of precision in the output, which can lead to various problems downstream. If you find the output is not written with enough precision, consider switching to binary output (-bo if available) or specify more decimals using the FORMAT_FLOAT_OUT setting.
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 1- or 2-byte integers. (more ...)
Time coordinates in netCDF grids, be it the x, y, or z coordinate, will be recognized as such. The variable’s unit attribute is parsed to determine the unit and epoch of the time coordinate in the grid. Values are then converted to the internal time system specified by TIME_UNIT and TIME_EPOCH in the gmt.conf file or on the command line. The default output is relative time in that time system, or absolute time when using the option -f0T, -f1T, or -f2T for x, y, or z coordinate, respectively.
To edit individual values in the 5’ by 5’ hawaii_grv.nc file, dump the .nc to ASCII:
gmt grd2xyz hawaii_grv.nc > hawaii_grv.xyz
To write a single precision binary file without the x,y positions from the file raw_data.nc file, using scanline orientation, run
gmt grd2xyz raw_data.nc -ZTLf > hawaii_grv.b