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_N.tex 11 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
  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{Custom Plot Symbols}
  10. \label{app:N}
  11. \index{symbols!custom}
  12. \thispagestyle{headings}
  13. \section{Background}
  14. \index{Custom Symbols}
  15. \index{Symbols, custom}
  16. The \GMT\ tools \GMTprog{psxy.c} and \GMTprog{psxyz.c} are capable of using
  17. custom symbols as alternatives to the built-in, standard geometrical shapes
  18. like circles, triangles, and many others. One the command line, custom
  19. symbols are selected via the \Opt{Sk}\emph{symbolname}[.\emph{size}] symbol
  20. selection, where \emph{symbolname} refers to a special symbol definition
  21. file called \filename{symbolname.def} that must be available via the standard
  22. \GMT\ user paths. Several custom symbols comes pre-configured with \GMT\
  23. (see Figure~\ref{fig:GMT_App_N_1})
  24. \GMTfig[h]{GMT_App_N_1}{Custom plot symbols supported by \gmt. Note that we
  25. only show the symbol outline and not any fill. These are all single-parameter symbols.
  26. Be aware that some symbols may have a hardwired fill or no-fill component,
  27. while others duplicate what is already available as standard built-in symbols.}
  28. You may find it convenient to examine some of these and use them as a starting
  29. point for your own design; they can be found in \GMT's share/custom directory.
  30. % The following file will contain more \GMTfig commands when needed.
  31. % \input{GMT_Appendix_N_inc.tex}
  32. \section{The macro language}
  33. To make your own custom plot symbol, you will need to design your own *.def files.
  34. This section defines the language used to build custom symbols. You can place these
  35. definition files in your current directory or your .gmt user directory. When designing
  36. the symbol, you are doing so in a relative coordinate system centered on (0,0). This point
  37. will be mapped to the actual location specified by your data coordinates. Furthermore,
  38. your symbol should be constructed within the domain ${-\frac{1}{2},+\frac{1}{2},-\frac{1}{2},+\frac{1}{2}}$,
  39. resulting in a 1 by 1 relative canvas. This 1 x 1 box will be scaled by your actual
  40. symbol size when plotted.
  41. \subsection{Comment lines}
  42. Your definition file may have any number of comment lines, defined to begin with
  43. the character \#. These are skipped by \GMT\ but provides a mechanism for you to
  44. clarify what your symbol does.
  45. \subsection{Symbol variables}
  46. Simple symbols, such as circles and triangles, only take a single parameter: the
  47. symbol size, which is either given on the command line (via \Opt{Sk}) or as part
  48. of the input data. However, more complicated symbols, such as the ellipse or vector symbols,
  49. may require more parameters. If your custom symbol requires more than the single size parameter
  50. you must include the line
  51. \begin{quote}
  52. \textbf{N}: \emph{n\_extra\_parameters} [\emph{types}]
  53. \end{quote}
  54. before any other macro commands. It is an optional statement in that \emph{n\_extra\_parameters} will
  55. default to 0 unless explicitly set. By default the extra parameters are considered to be quantities
  56. that should be passed directly to the symbol machinery. However, you can use the \emph{types} argument
  57. to specify different types of parameters. The available types are
  58. \begin{description}
  59. \item [a]: Geographic angle, to be converted to map angle given the current map projection.
  60. \item [l]: Length, i.e., an additional length scale (in cm, inch, or point as per {\bf PROJ\_LENGTH\_UNIT}) in addition to the given symbol size.
  61. \item [o]: Other, i.e., a quantity to be passed to the custom symbol as is.
  62. \end{description}
  63. To use the extra parameters in your macro you address them as \$1, \$2, etc.
  64. \subsection{Macro commands}
  65. The custom symbol language contains commands to rotate the relative coordinate system,
  66. draw free-form polygons and lines, change the current fill and/or pen, and include basic
  67. geometric symbols as part of the overall design (e.g., circles, triangles, etc.).
  68. The available commands are listed in
  69. Table~\ref{tbl:custsymb}.
  70. \begin{table}[H]
  71. \small
  72. \centering
  73. \begin{tabular}{|l|c|l|l|} \hline
  74. Name & Code & Purpose & Arguments \\ \hline
  75. rotate & \textbf{R} & Rotate the coordinate system & $\alpha$ \\ \hline
  76. moveto & \textbf{M} & Set a new anchor point & $x_0, y_0$ \\ \hline
  77. drawto & \textbf{D} & Draw line from previous point & $x, y$ \\ \hline
  78. arc & \textbf{A} & Append circular arc to existing path & $x_c, y_c, r, \alpha_1, \alpha_2$ \\ \hline
  79. stroke & \textbf{S} & Stroke existing path only & \\ \hline \hline
  80. texture & \textbf{T} & Change current pen and fill & \\ \hline \hline
  81. star & \textbf{a} & Plot a star & $x, y$,\emph{size} \\ \hline
  82. circle & \textbf{c} & Plot a circle & $x, y$,\emph{size} \\ \hline
  83. diamond & \textbf{d} & Plot a diamond & $x, y$,\emph{size} \\ \hline
  84. ellipse & \textbf{e} & Plot a ellipse & $x, y, \alpha$,\emph{major},\emph{minor} \\ \hline
  85. octagon & \textbf{g} & Plot an octagon & $x, y$,\emph{size} \\ \hline
  86. hexagon & \textbf{h} & Plot a hexagon & $x, y$,\emph{size} \\ \hline
  87. invtriangle & \textbf{i} & Plot an inverted triangle & $x, y$,\emph{size} \\ \hline
  88. letter & \textbf{l} & Plot a letter & $x, y$,\emph{size}, \emph{string} \\ \hline
  89. marc & \textbf{m} & Plot a math arc & $x, y, r, \alpha_1, \alpha_2$ \\ \hline
  90. pentagon & \textbf{n} & Plot a pentagon & $x, y$,\emph{size} \\ \hline
  91. plus & \textbf{+} & Plot a plus sign & $x, y$,\emph{size} \\ \hline
  92. rect & \textbf{r} & Plot a rectangle & $x, y$, \emph{width}, \emph{height} \\ \hline
  93. square & \textbf{s} & Plot a square & $x, y$,\emph{size} \\ \hline
  94. triangle & \textbf{t} & Plot a triangle & $x, y$,\emph{size} \\ \hline
  95. wedge & \textbf{w} & Plot a wedge & $x, y, r, \alpha_1, \alpha_2$ \\ \hline
  96. cross & \textbf{x} & Plot a cross & $x, y$,\emph{size} \\ \hline
  97. x-dash & \textbf{-} & Plot a x-dash & $x, y$,\emph{size} \\ \hline
  98. y-dash & \textbf{y} & Plot a y-dash & $x, y$,\emph{size} \\ \hline
  99. \end{tabular}
  100. \label{tbl:custsymb}
  101. \caption{List of macro codes used to define custom symbols. Note that arguments are given first with the symbol code at the end.
  102. All angles are expected in degrees. The \textbf{S} macro is only used if you just want to draw a line and not close/fill it as
  103. a polygon [Default]; place it on its own line after your last path construction operator.}
  104. \end{table}
  105. For \textbf{M}, \textbf{T}, and all the lower-case symbol codes you may optionally append specific pens (with \Opt{W}\emph{pen})
  106. and fills (with \Opt{G}\emph{pen}). These settings will override the pens and fills you may have specified
  107. on the command line. Passing \Opt{G}- or \Opt{W}- means no fill or outline, respectively.
  108. \subsection{Conditional statements}
  109. There are two types of conditional statements in the macro language: A simple condition
  110. preceding a single command, or a more elaborate if--then--elseif--else construct. In any test you
  111. may use one (and only one) of many logical operators, as listed in Table~\ref{tbl:custop}.
  112. \begin{table}[H]
  113. \small
  114. \centering
  115. \begin{tabular}{|c|l|} \hline
  116. Operator & Purpose \\ \hline
  117. $<$ & Is \emph{var} less than \emph{constant}? \\ \hline
  118. $<$= & Is \emph{var} less than or equal to \emph{constant}? \\ \hline
  119. == & Is \emph{var} equal to \emph{constant}? \\ \hline
  120. != & Is \emph{var} not equal to \emph{constant}? \\ \hline
  121. $>$= & Is \emph{var} greater than or equal to \emph{constant}? \\ \hline
  122. $>$ & Is \emph{var} greater than \emph{constant}? \\ \hline
  123. \% & Does \emph{var} have a remainder with \emph{constant}? \\ \hline
  124. !\% & Is \emph{var} an exact multiple of \emph{constant}? \\ \hline
  125. $<>$ & Is \emph{var} within the exclusive range of \emph{constant}? \\ \hline
  126. [] & Is \emph{var} within the inclusive range of \emph{constant}? \\ \hline
  127. $<$] & Is \emph{var} within the in/ex-clusive range of \emph{constant}? \\ \hline
  128. [$>$ & Is \emph{var} within the ex/in-clusive range of \emph{constant}? \\ \hline
  129. \end{tabular}
  130. \label{tbl:custop}
  131. \caption{List of operators to use for logical tests. The equality and inequality operators
  132. may be compared to NaN. Note that the last four range operators
  133. expect \emph{constant} to contain two colon-separated values (e.g., 0:9.5).}
  134. \end{table}
  135. \subsubsection{Simple conditional test}
  136. The simple if-test uses a one-line format, defined as
  137. \begin{quote}
  138. \textbf{if} \emph{var OP constant} \textbf{then} \emph{command}
  139. \end{quote}
  140. where \emph{var} must be one of the symbol parameters, specified as \$1, \$2, \$3, etc.
  141. You must document what these additional parameters control. For example, to plot a
  142. small cyan circle at (0.2, 0.3) with diameter 0.4 only if \$2 exceeds 45 you would write
  143. \begin{verbatim}
  144. if $2 > 45 then 0.2 0.3 0.4 c -Gcyan
  145. \end{verbatim}
  146. Note that this form of the conditional test has no mechanism for an \textbf{else} branch, but this can be accomplished
  147. by repeating the test but reversing the logic for the second copy, e.g.,
  148. \begin{verbatim}
  149. if $1 > 10 then 0 0 0.5 c -Gred
  150. if $1 <= 10 then 0 0 0.5 c -Gblue
  151. \end{verbatim}
  152. or you may instead consider the complete conditional construct below.
  153. \subsubsection{Complete conditional test}
  154. The complete conditional test uses a multi-line format, such as
  155. \begin{tabbing}
  156. \textbf{if} \emph{var} \= \emph{OP constant} \textbf{then} \{ \\
  157. \> $<$one or more lines with commands$>$ \\
  158. \} \textbf{elseif} \emph{var OP constant} \textbf{then} \{ \\
  159. \> $<$one or more lines with commands$>$ \\
  160. \} \textbf{else} \{ \\
  161. \> $<$one or more lines with commands$>$ \\
  162. \}
  163. \end{tabbing}
  164. The \textbf{elseif} (one or more) and \textbf{else} branches are optional. Note that the syntax is strictly enforced,
  165. meaning the opening brace must appear after \textbf{then} with nothing following it, and the closing brace
  166. must appear by itself with no other text, and that the \textbf{elseif} and \textbf{else} statements must have both closing
  167. and opening braces on the same line (and nothing else). You may nest tests as well (up to 10 levels deep), e.g.,
  168. \begin{verbatim}
  169. if $1 > 45 then {
  170. if $2 [> 0:10 then 0 0 0.5 c -Gred
  171. } elseif $1 < 15 then {
  172. if $2 [> 0:10 then 0 0 0.5 c -Ggreen
  173. } else {
  174. if $2 [> 10:20 then {
  175. 0 0 M -W1p,blue
  176. 0.3 0.3 D
  177. S
  178. 0.3 0.3 0.3 c -Gcyan
  179. }
  180. }
  181. \end{verbatim}
  182. %\subsection{PostScript symbols}
  183. % [This may or may not be implemented in the future ]
  184. %For very complicated symbols it may in fact be simpler to design the entire symbol in
  185. %the \PS\ language. In that case, your definition file may only contain the macro code
  186. %\textbf{N} (if needed), and the rest of the file should contain the \PS\ code for the symbol,
  187. %starting with the naming \texttt{/Sk\_}\emph{symbolname} and ending with the line \texttt{def}. Your
  188. %\PS\ code will be passed the symbol size and all \emph{n\_extra\_parameters} you have specified (if any).
  189. %\GMT\ will automatically encapsulate the symbol within a \emph{gsave--grestore} pair, thus limiting
  190. %any changes to the \PS\ state you may cause to the symbol execution only.
Tip!

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

Comments

Loading...