1GRDREFORMAT(1) Generic Mapping Tools GRDREFORMAT(1)
2
3
4
6 grdreformat - Converting between different grid file formats.
7
9 grdreformat ingrdfile[=id[/scale/offset[/NaNvalue]]] outgrd‐
10 file[=id[/scale/offset[/NaNvalue]]] [ -N ] [ -Rwest/east/south/north[r]
11 ] [ -f[i|o]colinfo ] [ -V ]
12
14 grdreformat reads a grid file in one format and writes it out using
15 another format. As an option the user may select a subset of the data
16 to be written and to specify scaling, translation, and NaN-value.
17
18 ingrdfile
19 The grid file to be read. Append format =id code if not a stan‐
20 dard COARDS-compliant netCDF grid file. If =id is set (see
21 below), you may optionally append scale and offset. These
22 options will scale the data and then offset them with the speci‐
23 fied amounts after reading.
24 If scale and offset are supplied you may also append a value
25 that represents 'Not-a-Number' (for floating-point grids this is
26 unnecessary since the IEEE NaN is used; however integers need a
27 value which means no data available.)
28
29 outgrdfile
30 The grid file to be written. Append format =id code if not a
31 standard COARDS-compliant netCDF grid file. If =id is set (see
32 below), you may optionally append scale and offset. These
33 options are particularly practical when storing the data as
34 integers, first removing an offset and then scaling down the
35 values. Since the scale and offset are applied in reverse order
36 when reading, this does not affect the data values (except for
37 round-offs).
38 If scale and offset are supplied you may also append a value
39 that represents 'Not-a-Number' (for floating-point grids this is
40 unnecessary since the IEEE NaN is used; however integers need a
41 value which means no data available.)
42
44 -N Suppress the writing of the GMT header structure. This is use‐
45 ful when you want to write a native grid to be used by
46 grdraster. It only applies to native grids and is ignored for
47 netCDF output.
48
49 -R xmin, xmax, ymin, and ymax specify the Region of interest. For
50 geographic regions, these limits correspond to west, east,
51 south, and north and you may specify them in decimal degrees or
52 in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left
53 and upper right map coordinates are given instead of w/e/s/n.
54 The two shorthands -Rg and -Rd stand for global domain (0/360
55 and -180/+180 in longitude respectively, with -90/+90 in lati‐
56 tude). Alternatively, specify the name of an existing grid file
57 and the -R settings (and grid spacing, if applicable) are copied
58 from the grid. For calendar time coordinates you may either
59 give (a) relative time (relative to the selected TIME_EPOCH and
60 in the selected TIME_UNIT; append t to -JX|x), or (b) absolute
61 time of the form [date]T[clock] (append T to -JX|x). At least
62 one of date and clock must be present; the T is always required.
63 The date string must be of the form [-]yyyy[-mm[-dd]] (Gregorian
64 calendar) or yyyy[-Www[-d]] (ISO week calendar), while the clock
65 string must be of the form hh:mm:ss[.xxx]. The use of delim‐
66 iters and their type and positions must be exactly as indicated
67 (however, input, output and plot formats are customizable; see
68 gmtdefaults).
69
70 -V Selects verbose mode, which will send progress reports to stderr
71 [Default runs "silently"].
72
73 -f Special formatting of input and/or output columns (time or geo‐
74 graphical data). Specify i or o to make this apply only to
75 input or output [Default applies to both]. Give one or more
76 columns (or column ranges) separated by commas. Append T (abso‐
77 lute calendar time), t (relative time in chosen TIME_UNIT since
78 TIME_EPOCH), x (longitude), y (latitude), or f (floating point)
79 to each column or column range item. Shorthand -f[i|o]g means
80 -f[i|o]0x,1y (geographic coordinates).
81
83 By default, grids will be written as floating point data stored in
84 binary files using the netCDF format and meta-data structure. This for‐
85 mat is conform the COARDS conventions. GMT versions prior to 4.1 pro‐
86 duced netCDF files that did not conform to these conventions. Although
87 these files are still supported, their use is deprecated. To write
88 other than floating point COARDS-compliant netCDF files, append the =id
89 suffix to the filename outgrdfile.
90 When reading files, grdreformat and other GMT programs will automati‐
91 cally recognize any type of netCDF grid file. These can be in either
92 COARDS-compliant or pre-4.1 format, and contain floating-point or inte‐
93 ger data. To read other types of grid files, append the =id suffix to
94 the filename ingrdfile.
95
96 id GMT 3 netCDF legacy formats
97 cb GMT netCDF format (byte) (deprecated)
98 cs GMT netCDF format (short) (deprecated)
99 ci GMT netCDF format (int) (deprecated)
100 cf GMT netCDF format (float) (deprecated)
101 cd GMT netCDF format (double) (deprecated)
102
103 id GMT native binary formats
104 bm GMT native, C-binary format (bit-mask)
105 bb GMT native, C-binary format (byte)
106 bs GMT native, C-binary format (short)
107 bi GMT native, C-binary format (int)
108 bf GMT native, C-binary format (float)
109 bd GMT native, C-binary format (double)
110
111 id GMT 4 netCDF standard
112 nb GMT netCDF format (byte) (COARDS-compliant)
113 ns GMT netCDF format (short) (COARDS-compliant)
114 ni GMT netCDF format (int) (COARDS-compliant)
115 nf GMT netCDF format (float) (COARDS-compliant) [DEFAULT]
116 nd GMT netCDF format (double) (COARDS-compliant)
117
118 id Misc formats
119 rb SUN rasterfile format (8-bit standard)
120 rf GEODAS grid format GRD98 (NGDC)
121 sf Golden Software Surfer format 6 (float)
122 sd Golden Software Surfer format 7 (double, read-only)
123 af Atlantic Geoscience Center format AGC (float)
124 gd Import through GDAL (convert to float) -- NON-STANDARD
125
127 The standard format used for gdrfiles is based on netCDF and conforms
128 to the COARDS conventions. Files written in this format can be read by
129 numerous third-party programs and are platform-independent. Some disk-
130 space can be saved by storing the data as bytes or shorts in stead of
131 integers. Use the scale and offset parameters to make this work without
132 loss of data range or significance. For more details, see Appendix B.
133
134 Multi-variable grid files
135 By default, GMT programs will read the first 2-dimensional grid con‐
136 tained in a COARDS-compliant netCDF file. Alternatively, use ingrd‐
137 file?varname (ahead of any optional suffix =id) to specify the
138 requested variable varname. Since ? has special meaning as a wildcard,
139 escape this meaning by placing the full filename and suffix between
140 quotes.
141
142 Multi-dimensional grids
143 To extract one layer or level from a 3-dimensional grid stored in a
144 COARDS-compliant netCDF file, append both the name of the variable and
145 the index associated with the layer (starting at zero) in the form:
146 ingrdfile?varname[layer]. Alternatively, specify the value associated
147 with that layer using parentheses in stead of brackets: ingridfile?var‐
148 name(level).
149 In a similar way layers can be extracted from 4- or even 5-dimensional
150 grids. For example, if a grid has the dimensions (parameter, time,
151 depth, latitude, longitude), a map can be selected by using: ingrid‐
152 file?varname(parameter,time,depth).
153 Since question marks, brackets and parentheses have special meanings on
154 the command line, escape these meanings by placing the full filename
155 and suffix between quotes.
156
158 For binary native GMT files the size of the GMT grdheader block is
159 hsize = 892 bytes, and the total size of the file is hsize + nx * ny *
160 item_size, where item_size is the size in bytes of each element (1, 2,
161 4). Bit grids are stored using 4-byte integers, each holding 32 bits,
162 so for these files the size equation is modified by using ceil (nx /
163 32) * 4 instead of nx. Note that these files are platform-dependent.
164 Files written on Little Endian machines (e.g. PCs) can not be read on
165 Big Endian machines (e.g. most workstations). Also note that it is not
166 possible for GMT to determine uniquely if a 4-byte grid is float or
167 int; in such cases it is best to use the =ID mechanism to specify the
168 file format. For header and grid details, see Appendix B.
169
171 Regardless of the precision of the input data, GMT programs that create
172 grid files will internally hold the grids in 4-byte floating point
173 arrays. This is done to conserve memory and furthermore most if not
174 all real data can be stored using 4-byte floating point values. Data
175 with higher precision (i.e., double precision values) will lose that
176 precision once GMT operates on the grid or writes out new grids. To
177 limit loss of precision when processing data you should always consider
178 normalizing the data prior to processing.
179
181 To extract the second layer from a 3-dimensional grid named temp from a
182 COARDS-compliant netCDF file climate.grd:
183
184 grdreformat climate.grd?temp[1] temp.grd -V
185
186 To create a 4-byte native floating point grid from the COARDS-compliant
187 netCDF file data.grd:
188
189 grdreformat data.grd ras_data.b4=bf -V
190
191 To make a 2-byte short integer file, scale it by 10, subtract 32000,
192 setting NaNs to -9999, do
193
194 grdreformat values.grd shorts.i2=bs/10/-32000/-9999 -V
195
196 To create a Sun standard 8-bit rasterfile for a subset of the data file
197 image.grd, assuming the range in image.grd is 0-1 and we need 0-255,
198 run
199
200 grdreformat image.grd -R-60/-40/-40/-30 image.ras8=rb/255/0 -V
201
202 To convert etopo2.grd to etopo2.i2 that can be used by grdraster, try
203
204 grdreformat etopo2.grd etopo2.i2=bs -N -V
205
207 GMT(1), grdmath(1)
208
209
210
211GMT 4.5.6 10 Mar 2011 GRDREFORMAT(1)