Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

GMT_Appendix_B.tex 20 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
  1. %------------------------------------------
  2. % $Id$
  3. %
  4. % The GMT Documentation Project
  5. % Copyright (c) 2000-2012.
  6. % P. Wessel, W. H. F. Smith, R. Scharroo, and J. Luis
  7. %------------------------------------------
  8. %
  9. \chapter{\gmt\ file formats}
  10. \label{app:B}
  11. \thispagestyle{headings}
  12. \section{Table data}
  13. \index{Table!format}
  14. These files have \emph{N} records which have \emph{M} fields each.
  15. All programs that handle tables can read multicolumn files. \GMT\ can
  16. read both ASCII, native binary, and netCDF table data.
  17. \subsection{ASCII tables}
  18. \index{Table!ASCII}
  19. \index{ASCII tables}
  20. \index{Table!multisegment}
  21. \subsubsection{Optional file header records}
  22. The first data record may be preceded by one or more header records.
  23. Any records that begins with '\#' is considered a header or comment
  24. line and are always processed correctly. If your data file has leading
  25. header records that do \emph{not} start with '\#' then you must
  26. make sure to use the \Opt{h} option and set
  27. the parameter \textbf{IO\_N\_HEADER\_RECS} in the \filename{gmt.conf} file
  28. (\GMT\ default is one header record if \Opt{h} is given; you may also
  29. use \Opt{h}\emph{nrecs} directly). Fields
  30. within a record must be separated by spaces, tabs, or commas.
  31. Each field can be an integer or floating-point number or a geographic
  32. coordinate string using the [+$|$-]dd[:mm[:ss]][W$|$S$|$N$|$E$|$w$|$s$|$n$|$e] format.
  33. Thus, 12:30:44.5W, 17.5S, 1:00:05, and 200:45E are all valid input strings.
  34. On output, fields will be separated by the character given by the parameter \textbf{IO\_COL\_SEPARATOR},
  35. which by default is a TAB.
  36. \subsubsection{Optional segment header records}
  37. When dealing with time- or (\emph{x,y})-series it is usually
  38. convenient to have each profile in separate files.
  39. However, this may sometimes prove impractical due to large numbers
  40. of profiles. An example is files of digitized lineations where
  41. the number of individual features may range into the thousands.
  42. One file per feature would in this case be unreasonable and
  43. furthermore clog up the directory. \GMT\ provides a mechanism for
  44. keeping more than one profile in a file. Such files are called
  45. \emph{multiple segment files} and are identical to the ones
  46. just outlined except that they have segment headers interspersed with
  47. data records that signal the start of a new segment.
  48. The segment headers may be of any format, but all must have the same
  49. character in the first column. The unique character is by default
  50. '$>$', but you can override that by modifying the \textbf{IO\_SEGMENT\_MARKER}
  51. default setting. Programs can examine the segment headers to see if they
  52. contain \Opt{D} for a distance value, \Opt{W} and \Opt{G} options for specifying pen and
  53. fill attributes for individual segments, \Opt{Z} to change
  54. color via a CPT file, \Opt{L} for label specifications, or \Opt{T} for
  55. general-purpose text descriptions. These settings
  56. (and occasionally others) will override the corresponding command line options.
  57. \GMT\ also provides for two special values for \textbf{IO\_SEGMENT\_MARKER} that can
  58. make interoperability with other software packages easier. Choose the marker \textbf{B}
  59. to have blank lines recognized as segment breaks, or use \textbf{N} to have data records
  60. whose fields equal NaN mean segment breaks (e.g., as used by GNU Octave or Matlab).
  61. When these markers are used then no other segment header will be considered. Note that
  62. \textbf{IO\_SEGMENT\_MARKER} can be set differently for input and output.
  63. \subsection{Binary tables}
  64. \index{Table!binary}
  65. \index{Binary tables}
  66. \index{Input!binary \Opt{bi}}
  67. \index{Output!binary \Opt{bo}}
  68. \index{\Opt{bi} (select binary input)}
  69. \index{\Opt{bo} (select binary output)}
  70. \GMT\ programs also support native binary tables to speed up input-output
  71. for i/o-intensive tasks like gridding and preprocessing. Files
  72. may have a header section and the \Opt{h}\emph{n} option can be used to skip the
  73. first \emph{n} bytes. The data record can be in any format, mixing different data types
  74. and even containing byte-swapped items. For input, specify \Opt{bi} and append
  75. one or more comma-separated combinations of
  76. \emph{n}\textbf{t}, where \textbf{t} is one of \textbf{c} (signed byte),
  77. \textbf{u} (unsigned byte), \textbf{h} (signed 2-byte int), \textbf{U} (unsigned
  78. 2-byte int), \textbf{i} (signed 4-byte int), \textbf{I} (unsigned 4-byte int),
  79. \textbf{l} (signed 8-byte int), \textbf{L} (unsigned 8-byte int), \textbf{f}
  80. (4-byte single-precision float), and \textbf{d} (8-byte double-precision
  81. float). Append \textbf{w} to any item to force byte-swapping.
  82. Alternatively, append \textbf{+L} or \textbf{+B} to indicate that the entire data file
  83. should be read as little- or big-endian, respectively.
  84. Here, \emph{n} is the consecutive number of each data type in your binary input file; the
  85. total number may exceeds the columns actually needed by the program. If no
  86. \emph{n} is specified we assume that \textbf{t} applies to all columns and
  87. that \emph{n} is implied by the expectation of the program.
  88. Multiple segment files are allowed and the
  89. segment headers are assumed to be records where all the fields equal
  90. NaN.
  91. \subsection{NetCDF tables}
  92. \index{Table!netCDF}
  93. \index{NetCDF tables}
  94. \index{Input!binary \Opt{bi}}
  95. \index{\Opt{bi} (select binary input)}
  96. More and more programs are now producing binary data in the netCDF format, and so \GMT\ programs
  97. started to support tabular netCDF data (files containing one or more 1-dimensional arrays) starting with \GMT\ version 4.3.0.
  98. Because of the meta data contained in those files, reading them is much less complex than reading native binary tables,
  99. and even than ASCII tables. \GMT\ programs will read as many 1-dimensional columns as are needed by the program, starting with the first
  100. 1-dimensional it can find in the file. To specifically specify which variables are to be read,
  101. append the suffix \textbf{?}\emph{var1}\textbf{/}\emph{var2}\textbf{/}\emph{...} to the netCDF file name
  102. or add the option \Opt{bic}\emph{var1}\textbf{/}\emph{var2}\textbf{/}\emph{...}, where \emph{var1}, \emph{var2}, etc.\
  103. are the names of the variables to be processed. The latter option is particularly practical when more
  104. than one file is read: the \Opt{bic} option will apply to all files.
  105. Currently, \GMT\ only reads, but does not write, netCDF tabular data.
  106. \section{Grid files}
  107. \subsection{NetCDF files}
  108. \index{grid file!formats!netCDF|(}
  109. \index{grid file!formats!COARDS|(}
  110. \index{grid file!formats!CF-1.0|(}
  111. By default, \GMT\ stores 2-D grids as COARDS-compliant netCDF files.
  112. COARDS (which stands for Cooperative Ocean/Atmosphere Research Data Service) is a convention used by
  113. many agencies distributing gridded data for ocean and atmosphere research. Sticking to
  114. this convention allows \GMT\ to read gridded data provided by other institutes
  115. and other programs. Conversely, other general domain programs
  116. will be able to read grids created by \GMT.
  117. COARDS is a subset of a more extensive convention for netCDF data called CF-1.0 (Climate and
  118. Forecast, version 1.0). Hence, \GMT\ grids are also automatically CF-1.0-compliant.
  119. However, since CF-1.0 has more general application than COARDS, not all CF-1.0 compliant netCDF files
  120. can be read by \GMT.
  121. The netCDF grid file in \GMT\ has several attributes (See Table~\ref{tbl:netcdf-format})
  122. to describe the content. The routine
  123. that deals with netCDF grid files is sufficiently flexible so that grid files slightly deviating
  124. from the standards used by \GMT\ can also be read.
  125. \begin{table}
  126. \centering
  127. \begin{tabular}{|l|l|} \hline
  128. \multicolumn{1}{|c}{\emph{Attribute}} & \multicolumn{1}{|c|}{\emph{Description}} \\ \hline
  129. \multicolumn{2}{|c|}{\emph{Global attributes}} \\ \hline
  130. Conventions & COARDS, CF-1.0 (optional) \\ \hline
  131. title & Title (optional) \\ \hline
  132. source & How file was created (optional) \\ \hline
  133. registration & 0 for gridline node registration (default), 1 for pixel registration \\ \hline
  134. \multicolumn{2}{|c|}{\emph{$x$- and $y$-variable attributes}} \\ \hline
  135. long\_name & Coordinate name (default: ``Longitude'' and ``Latitude'') \\ \hline
  136. units & Unit of the coordinate (default: ``degrees\_east'' and ``degrees\_north'') \\ \hline
  137. actual\_range & Minimum and maximum $x$ and $y$ of region; if absent \\
  138. (or valid\_range) & the first and last $x$- and $y$-values are queried \\ \hline
  139. \multicolumn{2}{|c|}{\emph{$z$-variable attributes}} \\ \hline
  140. long\_name & Name of the variable (default: ``z'') \\ \hline
  141. units & Unit of the variable (no default) \\ \hline
  142. scale\_factor & Factor to multiply $z$ with (default: 1) \\ \hline
  143. add\_offset & Offset to add to scaled $z$ (default: 0) \\ \hline
  144. actual\_range & Minimum and maximum $z$ (optional) \\ \hline
  145. \_FillValue & Value associated with missing data points; if absent an\\
  146. (or missing\_value) & appropriate default value is assumed, depending on data type. \\ \hline
  147. \end{tabular}
  148. \caption{Attributes of default \gmt\ grid file in COARDS-compliant netCDF format.}
  149. \label{tbl:netcdf-format}
  150. \end{table}
  151. By default, the first 2-dimensional variable in a netCDF file will by read as the $z$ variable
  152. and the coordinate axes $x$ and $y$ will be determined from the dimensions of the $z$ variable.
  153. \GMT\ will recognize whether the $y$ (latitude) variable increases or decreases. Both forms of
  154. data storage are handled appropriately.
  155. For more information on the use of COARDS-compliant netCDF files, and on how to load
  156. multi-dimensional grids, read Section~\ref{sec:netcdf}.
  157. \GMT\ also allows other formats to be read. In addition to
  158. the default netCDF format it can use binary floating points, short
  159. integers, bytes, and bits, as well as 8-bit Sun raster files (colormap
  160. ignored). Additional formats may be used by supplying read/write
  161. functions and linking these with the \GMT\ libraries.
  162. The source file \filename{gmt\_customio.c} has the information that
  163. programmers will need to augment \GMT\ to read custom grid files. We
  164. anticipate that the number of pre-programmed formats will increase as
  165. enterprising users implement what they need. See Section~\ref{sec:grdformats}
  166. for more information.
  167. \index{grid file!formats!netCDF|)}
  168. \index{grid file!formats!COARDS|)}
  169. \index{grid file!formats!CF-1.0|)}
  170. \subsection{Gridline and Pixel node registration}
  171. Scanline format means that the data are stored in rows (\emph{y} = constant)
  172. going from the ``top'' ($y = y_{max}$ (north)) to the ``bottom''
  173. ($y = y_{min}$ (south)). Data within each row are ordered from
  174. ``left'' ($x = x_{min}$ (west)) to ``right'' ($x = x_{max}$
  175. (east)). The \emph{registration} signals how the nodes are laid out.
  176. The grid is always defined as the intersections of all \emph{x}
  177. ( \( x = x_{min}, x_{min} + x_{inc}, x_{min} + 2 \cdot x_{inc}, \ldots, x_{max} \) )
  178. and \emph{y} ( \( y = y_{min}, y_{min} + y_{inc}, y_{min} + 2 \cdot y_{inc}, \ldots, y_{max} \) )
  179. lines. The two scenarios differ as to which area each data point represents.
  180. The default node registration in \GMT\ is gridline node registration. Most
  181. programs can handle both types, and for some programs like \GMTprog{grdimage}
  182. a pixel registered file makes more sense. Utility programs like
  183. \GMTprog{grdsample} and \GMTprog{grdproject} will allow you to convert
  184. from one format to the other; \GMTprog{grdedit} can make changes to the grid header
  185. and convert a pixel- to a gridline-registered grid, or \emph{vice versa}.
  186. The grid registration is determined by the common \GMT\ \Opt{r} option
  187. (see Section~\ref{sec:grid_registration}).
  188. \subsection{Boundary Conditions for operations on grids}
  189. \index{grid file!boundary conditions|(}
  190. \GMT\ has the option to specify boundary conditions in some programs
  191. that operate on grids (e.g., \GMTprog{grdsample}, \GMTprog{grdgradient},
  192. \GMTprog{grdtrack}, \GMTprog{nearneighbor}, and
  193. \GMTprog{grdview}, to name a few. The desired condition can be set with
  194. the common \GMT\ option \Opt{n}; see Section \ref{sec:resample}. The boundary conditions come into play
  195. when interpolating or computing derivatives near the limits of the
  196. region covered by the grid. The \emph{default} boundary
  197. conditions used are those which are ``natural'' for the boundary
  198. of a minimum curvature interpolating surface.
  199. If the user knows that the data are periodic in \emph{x} (and/or
  200. \emph{y}), or that the data cover a sphere with \emph{x},\emph{y}
  201. representing \emph{longitude},\emph{latitude}, then there are better
  202. choices for the boundary conditions.
  203. Periodic conditions on \emph{x} (and/or \emph{y}) are chosen by
  204. specifying \emph{x} (and/or \emph{y}) as the boundary condition flags;
  205. global spherical cases are specified using the \emph{g} (geographical)
  206. flag. Behavior of these conditions is as follows:
  207. \begin{description}
  208. \index{grid file!boundary conditions!periodic}
  209. \item[Periodic] conditions on $x$ indicate that the data are
  210. periodic in the distance ($x_{max} - x_{min}$) and thus repeat
  211. values after every $N = (x_{max} - x_{min})/x_{inc}$. Note that
  212. this implies that in a grid-registered file the values in the first
  213. and last columns are equal, since these are located at $x = x_{min}$
  214. and $x = x_{max}$, and there are $N + 1$ columns in the file.
  215. This is not the case in a pixel-registered file, where there are only
  216. $N$ and the first and last columns are located at
  217. $x_{min} + x_{inc}/2$ and $x_{max} - x_{inc}/2$. If $y$ is
  218. periodic all the same holds for $y$.
  219. \item[Geographical] conditions indicate the following:
  220. \index{grid file!boundary conditions!geographical}
  221. \begin{enumerate}
  222. \item If $(x_{max} - x_{min}) \geq 360$ and also 180 modulo $x_{inc} = 0$
  223. then a periodic condition is used on $x$ with a period of 360;
  224. else a default condition is used on the $x$ boundaries.
  225. \item If condition 1 is true and also $y_{max} = 90$ then a
  226. ``north pole condition'' is used at $y_{max}$, else a default
  227. condition is used there.
  228. \item If condition 1 is true and also $y_{min} = -90$ then a
  229. ``south pole condition'' is used at $y_{min}$, else a default
  230. condition is used there.
  231. \end{enumerate}
  232. ``Pole conditions'' use a 180\DS\ phase-shift of the data,
  233. requiring 180 modulo $x_{inc} = 0$.
  234. \item[Default] boundary conditions are
  235. \index{grid file!boundary conditions!default}
  236. \[ \nabla^2 f = \frac{\partial}{\partial n} \nabla^2 f = 0 \]
  237. on the boundary, where $f(x, y)$ is represented by the values in
  238. the grid file, and $\partial/\partial n$ is the derivative in the direction normal to a
  239. boundary, and
  240. \[ \nabla^2 = \left(\frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2}\right) \]
  241. is the two-dimensional Laplacian operator.
  242. \end{description}
  243. \index{grid file!boundary conditions|)}
  244. \subsection{Native binary grid files}
  245. \index{grid file!native binary|(}
  246. The old style native grid file format that was common in earlier version of \GMT\ is still
  247. supported, although the use of netCDF\index{grid file!formats!netCDF} files is strongly recommended.
  248. The file starts with a header of 892 bytes containing a number of attributes defining the content.
  249. The \GMTprog{grdedit} utility program will allow you to edit parts of
  250. the header of an existing grid file. The attributes listed in Table~\ref{tbl:grdheader}
  251. are contained within the header record in the order given (except the $z$-array which
  252. is not part of the header structure, but makes up the rest of the file). As this header
  253. was designed long before 64-bit architectures became available, the jump from
  254. the first three integers to the subsequent doubles in the structure does not occur on a
  255. 16-byte alignment. While \GMT\ handles the reading of these structures correctly, enterprising
  256. programmers must take care to read this header correctly (see our code for details).
  257. \begin{table}
  258. \centering
  259. \begin{tabular}{|l|l|} \hline
  260. \multicolumn{1}{|c}{\emph{Parameter}} & \multicolumn{1}{|c|}{\emph{Description}} \\ \hline
  261. \textbf{int} \emph{nx} & Number of nodes in the $x$-dimension \\ \hline
  262. \textbf{int} \emph{ny} & Number of nodes in the y-dimension \\ \hline
  263. \textbf{int} \emph{registration} & 0 for grid line registration, 1 for pixel registration \\ \hline
  264. \textbf{double} \emph{x\_min} & Minimum $x$-value of region \\ \hline
  265. \textbf{double} \emph{x\_max} & Maximum $x$-value of region \\ \hline
  266. \textbf{double} \emph{y\_min} & Minimum $y$-value of region \\ \hline
  267. \textbf{double} \emph{y\_max} & Maximum $y$-value of region \\ \hline
  268. \textbf{double} \emph{z\_min} & Minimum $z$-value in data set \\ \hline
  269. \textbf{double} \emph{z\_max} & Maximum $z$-value in data set \\ \hline
  270. \textbf{double} \emph{x\_inc} & Node spacing in $x$-dimension \\ \hline
  271. \textbf{double} \emph{y\_inc} & Node spacing in $y$-dimension \\ \hline
  272. \textbf{double} \emph{z\_scale\_factor} & Factor to multiply $z$-values after read \\ \hline
  273. \textbf{double} \emph{z\_add\_offset} & Offset to add to scaled $z$-values \\ \hline
  274. \textbf{char} \emph{x\_units}[80] & Units of the $x$-dimension \\ \hline
  275. \textbf{char} \emph{y\_units}[80] & Units of the $y$-dimension \\ \hline
  276. \textbf{char} \emph{z\_units}[80] & Units of the $z$-dimension \\ \hline
  277. \textbf{char} \emph{title}[80] & Descriptive title of the data set \\ \hline
  278. \textbf{char} \emph{command}[320] & Command line that produced the grid file \\ \hline
  279. \textbf{char} \emph{remark}[160] & Any additional comments \\ \hline \hline
  280. \textbf{TYPE} \emph{z}[nx*ny] & 1-D array with $z$-values in scanline format \\ \hline
  281. \end{tabular}
  282. \caption{\gmt\ grid file header record. \textbf{TYPE} can be \textbf{char}, \textbf{short}, \textbf{int},
  283. \textbf{float}, or {\bf
  284. double}.}
  285. \label{tbl:grdheader}
  286. \end{table}
  287. \index{grid file!native binary|)}
  288. \section{Sun raster files}
  289. \index{Raster file!format}
  290. The Sun raster file format consists of a header followed by a series
  291. of unsigned 1-byte integers that represents the bit-pattern. Bits
  292. are scanline oriented, and each row must contain an even number of
  293. bytes. The predefined 1-bit
  294. patterns in \GMT\ have dimensions of 64 by 64, but other sizes will be
  295. accepted when using the \Opt{Gp$|$P} option. The Sun header structure
  296. is outline in Table~\ref{tbl:sunheader}.
  297. \begin{table}[H]
  298. \centering
  299. \begin{tabular}{|l|l|} \hline
  300. \multicolumn{1}{|c}{\emph{Parameter}} & \multicolumn{1}{|c|}{\emph{Description}} \\ \hline
  301. \textbf{int} \emph{ras\_magic} & Magic number \\ \hline
  302. \textbf{int} \emph{ras\_width} & Width (pixels) of image \\ \hline
  303. \textbf{int} \emph{ras\_height} & Height (pixels) of image \\ \hline
  304. \textbf{int} \emph{ras\_depth} & Depth (1, 8, 24, 32 bits) of pixel \\ \hline
  305. \textbf{int} \emph{ras\_length} & Length (bytes) of image \\ \hline
  306. \textbf{int} \emph{ras\_type} & Type of file; see RT\_* below \\ \hline
  307. \textbf{int} \emph{ras\_maptype} & Type of colormap; see RMT\_* below \\ \hline
  308. \textbf{int} \emph{ras\_maplength} & Length (bytes) of following map \\ \hline
  309. \end{tabular}
  310. \caption{Structure of a Sun raster file.}
  311. \label{tbl:sunheader}
  312. \end{table}
  313. After the header, the color map (if \emph{ras\_maptype} is not RMT\_NONE)
  314. follows for \emph{ras\_maplength} bytes, followed by an image of
  315. \emph{ras\_length} bytes. Some related definitions are given in Table~\ref{tbl:sundef}.
  316. \begin{table}[H]
  317. \index{Raster file!definitions}
  318. \centering
  319. \begin{tabular}{|l|l|} \hline
  320. \multicolumn{1}{|c}{\emph{Macro name}} & \multicolumn{1}{|c|}{\emph{Description}} \\ \hline
  321. RAS\_MAGIC & 0x59a66a95 \\ \hline
  322. RT\_STANDARD & 1 (Raw pixrect image in 68000 byte order) \\ \hline
  323. RT\_BYTE\_ENCODED & 2 (Run-length compression of bytes) \\ \hline
  324. RT\_FORMAT\_RGB & 3 ([X]RGB instead of [X]BGR) \\ \hline
  325. RMT\_NONE & 0 (ras\_maplength is expected to be 0) \\ \hline
  326. RMT\_EQUAL\_RGB & 1 (red[ras\_maplength/3],green[],blue[]) \\ \hline
  327. \end{tabular}
  328. \caption{Sun macro definitions relevant to raster files.}
  329. \label{tbl:sundef}
  330. \end{table}
  331. Numerous public-domain programs exist, such as \progname{xv} and
  332. \progname{convert} (in the ImageMagick package), that will translate
  333. between various raster file formats such as tiff, gif, jpeg, and
  334. Sun raster. Raster patterns may be created with \GMT\ plotting
  335. tools by generating \PS\ plots that can be rasterized
  336. by \progname{ghostscript} and translated into the right raster format.
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...