gmt 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gmt/gmt.c +182 -33
  3. data/lib/gmt.rb +107 -4
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5a65a755a31688499a920ea9a2607b532559ff1
4
- data.tar.gz: 5485b4fe71d63e8042db9fd0f459ba5ec0b4bccd
3
+ metadata.gz: d165e67cb791e80aecdbed1b817c6ba15c1f82ef
4
+ data.tar.gz: 4ffda40ca008f338c9016e84326a2eb8f7242dfd
5
5
  SHA512:
6
- metadata.gz: 5f74d327f2ec1f15b2444eb61dfdab5fbcf4c1732e4e9164838a79d8108146881b87645d27ad427e304b6b8e3e70b7fa85568221fb6858888db78a3fcced3e52
7
- data.tar.gz: 426b2a729293828d069eb78c540adc689db325e7b87b4415ab826de4f13cb897d2bcbcf1359080985d3730febe3b3a2a373e4de86ee381262e3fdb2cd336e92e
6
+ metadata.gz: 69d55be3f508a2bb345622d90d7cda10363bd1ceb259a5f0f910c0daf96f91663cf17c9c2c693ddc17ac3ade4ea6e669b41b95a33a183ca0b8b6cfe6fbad3b35
7
+ data.tar.gz: 311b0e6840f3d366ef17ea756ae581be1c8d3aa20978eb1bbb997802ecc154674631dcdac614bf9a1cba0c4a866a159c258447fd8d0579852b3e61097f0a9697
data/ext/gmt/gmt.c CHANGED
@@ -8,6 +8,8 @@ typedef struct
8
8
  void *session;
9
9
  } gmt_t;
10
10
 
11
+ /* helpers */
12
+
11
13
  static void raise_unless_class_data(gmt_t *gmt)
12
14
  {
13
15
  if (gmt == NULL)
@@ -20,6 +22,62 @@ static void raise_if_error(int err, const char *module)
20
22
  rb_raise(rb_eRuntimeError, "failed call to GMT module %s", module);
21
23
  }
22
24
 
25
+ /* ruby object interface */
26
+
27
+ static void gmt_free(void *p)
28
+ {
29
+ gmt_t *gmt = p;
30
+
31
+ if (gmt->session)
32
+ {
33
+ GMT_Destroy_Session(gmt->session);
34
+ gmt->session = NULL;
35
+ }
36
+ }
37
+
38
+ static VALUE gmt_alloc(VALUE klass)
39
+ {
40
+ gmt_t *gmt;
41
+
42
+ VALUE obj = Data_Make_Struct(klass, gmt_t, NULL, gmt_free, gmt);
43
+
44
+ gmt->session = NULL;
45
+
46
+ return obj;
47
+ }
48
+
49
+ static VALUE gmt_init(VALUE self)
50
+ {
51
+ gmt_t *gmt;
52
+
53
+ Data_Get_Struct(self, gmt_t, gmt);
54
+
55
+ gmt->session =
56
+ GMT_Create_Session("Session name", 2, 0, NULL);
57
+
58
+ if (gmt->session == NULL)
59
+ rb_raise(rb_eNoMemError, "failed to create GMT session");
60
+
61
+ return self;
62
+ }
63
+
64
+ static VALUE gmt_release(VALUE self)
65
+ {
66
+ gmt_t *gmt;
67
+
68
+ Data_Get_Struct(self, gmt_t, gmt);
69
+
70
+ if (gmt->session)
71
+ {
72
+ GMT_Destroy_Session(gmt->session);
73
+ gmt->session = NULL;
74
+ }
75
+
76
+ return self;
77
+ }
78
+
79
+ /* hander for GMT functions */
80
+
23
81
  static VALUE gmt_simple(const char *name, int argc, VALUE *argv, VALUE self)
24
82
  {
25
83
  VALUE files, opts;
@@ -44,71 +102,135 @@ static VALUE gmt_simple(const char *name, int argc, VALUE *argv, VALUE self)
44
102
  return Qtrue;
45
103
  }
46
104
 
105
+ /* The GMT functions */
106
+
107
+ /* Mathematical Operations on Tables or Grids */
108
+
109
+ static VALUE gmt_gmtmath(int argc, VALUE *argv, VALUE self)
110
+ {
111
+ return gmt_simple("gmtmath", argc, argv, self);
112
+ }
113
+
47
114
  static VALUE gmt_makecpt(int argc, VALUE *argv, VALUE self)
48
115
  {
49
116
  return gmt_simple("makecpt", argc, argv, self);
50
117
  }
51
118
 
52
- static VALUE gmt_pstext(int argc, VALUE *argv, VALUE self)
119
+ static VALUE gmt_spectrum1d(int argc, VALUE *argv, VALUE self)
53
120
  {
54
- return gmt_simple("pstext", argc, argv, self);
121
+ return gmt_simple("spectrum1d", argc, argv, self);
55
122
  }
56
123
 
57
- static VALUE gmt_psxy(int argc, VALUE *argv, VALUE self)
124
+ static VALUE gmt_sph2grd(int argc, VALUE *argv, VALUE self)
58
125
  {
59
- return gmt_simple("psxy", argc, argv, self);
126
+ return gmt_simple("sph2grd", argc, argv, self);
60
127
  }
61
128
 
62
- static void gmt_free(void *p)
129
+ static VALUE gmt_sphdistance(int argc, VALUE *argv, VALUE self)
63
130
  {
64
- gmt_t *gmt = p;
131
+ return gmt_simple("sphdistance", argc, argv, self);
132
+ }
65
133
 
66
- if (gmt->session)
67
- {
68
- GMT_Destroy_Session(gmt->session);
69
- gmt->session = NULL;
70
- }
134
+ static VALUE gmt_sphtriangulate(int argc, VALUE *argv, VALUE self)
135
+ {
136
+ return gmt_simple("sphtriangulate", argc, argv, self);
71
137
  }
72
138
 
73
- static VALUE gmt_alloc(VALUE klass)
139
+ /* Plotting of 1-D and 2-D Data */
140
+
141
+ static VALUE gmt_gmtlogo(int argc, VALUE *argv, VALUE self)
74
142
  {
75
- gmt_t *gmt;
143
+ return gmt_simple("gmtlogo", argc, argv, self);
144
+ }
76
145
 
77
- VALUE obj = Data_Make_Struct(klass, gmt_t, NULL, gmt_free, gmt);
146
+ static VALUE gmt_grdcontour(int argc, VALUE *argv, VALUE self)
147
+ {
148
+ return gmt_simple("grdcontour", argc, argv, self);
149
+ }
78
150
 
79
- gmt->session = NULL;
151
+ static VALUE gmt_grdimage(int argc, VALUE *argv, VALUE self)
152
+ {
153
+ return gmt_simple("grdimage", argc, argv, self);
154
+ }
80
155
 
81
- return obj;
156
+ static VALUE gmt_grdvector(int argc, VALUE *argv, VALUE self)
157
+ {
158
+ return gmt_simple("grdvector", argc, argv, self);
82
159
  }
83
160
 
84
- static VALUE gmt_init(VALUE self)
161
+ static VALUE gmt_grdview(int argc, VALUE *argv, VALUE self)
85
162
  {
86
- gmt_t *gmt;
163
+ return gmt_simple("grdview", argc, argv, self);
164
+ }
87
165
 
88
- Data_Get_Struct(self, gmt_t, gmt);
166
+ static VALUE gmt_psbasemap(int argc, VALUE *argv, VALUE self)
167
+ {
168
+ return gmt_simple("psbasemap", argc, argv, self);
169
+ }
89
170
 
90
- gmt->session =
91
- GMT_Create_Session("Session name", 2, 0, NULL);
171
+ static VALUE gmt_psclip(int argc, VALUE *argv, VALUE self)
172
+ {
173
+ return gmt_simple("psclip", argc, argv, self);
174
+ }
92
175
 
93
- if (gmt->session == NULL)
94
- rb_raise(rb_eNoMemError, "failed to create GMT session");
176
+ static VALUE gmt_pscoast(int argc, VALUE *argv, VALUE self)
177
+ {
178
+ return gmt_simple("pscoast", argc, argv, self);
179
+ }
95
180
 
96
- return self;
181
+ static VALUE gmt_pscontour(int argc, VALUE *argv, VALUE self)
182
+ {
183
+ return gmt_simple("pscontour", argc, argv, self);
97
184
  }
98
185
 
99
- static VALUE gmt_release(VALUE self)
186
+ static VALUE gmt_pshistogram(int argc, VALUE *argv, VALUE self)
100
187
  {
101
- gmt_t *gmt;
188
+ return gmt_simple("pshistogram", argc, argv, self);
189
+ }
102
190
 
103
- Data_Get_Struct(self, gmt_t, gmt);
191
+ static VALUE gmt_psimage(int argc, VALUE *argv, VALUE self)
192
+ {
193
+ return gmt_simple("psimage", argc, argv, self);
194
+ }
104
195
 
105
- if (gmt->session)
106
- {
107
- GMT_Destroy_Session(gmt->session);
108
- gmt->session = NULL;
109
- }
196
+ static VALUE gmt_pslegend(int argc, VALUE *argv, VALUE self)
197
+ {
198
+ return gmt_simple("pslegend", argc, argv, self);
199
+ }
110
200
 
111
- return self;
201
+ static VALUE gmt_psmask(int argc, VALUE *argv, VALUE self)
202
+ {
203
+ return gmt_simple("psmask", argc, argv, self);
204
+ }
205
+
206
+ static VALUE gmt_psrose(int argc, VALUE *argv, VALUE self)
207
+ {
208
+ return gmt_simple("psrose", argc, argv, self);
209
+ }
210
+
211
+ static VALUE gmt_psscale(int argc, VALUE *argv, VALUE self)
212
+ {
213
+ return gmt_simple("psscale", argc, argv, self);
214
+ }
215
+
216
+ static VALUE gmt_pstext(int argc, VALUE *argv, VALUE self)
217
+ {
218
+ return gmt_simple("pstext", argc, argv, self);
219
+ }
220
+
221
+ static VALUE gmt_pswiggle(int argc, VALUE *argv, VALUE self)
222
+ {
223
+ return gmt_simple("pswiggle", argc, argv, self);
224
+ }
225
+
226
+ static VALUE gmt_psxy(int argc, VALUE *argv, VALUE self)
227
+ {
228
+ return gmt_simple("psxy", argc, argv, self);
229
+ }
230
+
231
+ static VALUE gmt_psxyz(int argc, VALUE *argv, VALUE self)
232
+ {
233
+ return gmt_simple("psxyz", argc, argv, self);
112
234
  }
113
235
 
114
236
  void Init_gmt(void)
@@ -119,7 +241,34 @@ void Init_gmt(void)
119
241
  rb_define_method(cGMT, "initialize", gmt_init, 0);
120
242
  rb_define_method(cGMT, "free", gmt_release, 0);
121
243
 
244
+ /* Mathematical Operations on Tables or Grids */
245
+
246
+ rb_define_private_method(cGMT, "gmtmath_c", gmt_gmtmath, -1);
122
247
  rb_define_private_method(cGMT, "makecpt_c", gmt_makecpt, -1);
248
+ rb_define_private_method(cGMT, "spectrum1d_c", gmt_spectrum1d, -1);
249
+ rb_define_private_method(cGMT, "sph2grd_c", gmt_sph2grd, -1);
250
+ rb_define_private_method(cGMT, "sphdistance_c", gmt_sphdistance, -1);
251
+ rb_define_private_method(cGMT, "sphtriangulate_c", gmt_sphtriangulate, -1);
252
+
253
+ /* Plotting of 1-D and 2-D Data */
254
+
255
+ rb_define_private_method(cGMT, "gmtlogo_c", gmt_gmtlogo, -1);
256
+ rb_define_private_method(cGMT, "grdcontour_c", gmt_grdcontour, -1);
257
+ rb_define_private_method(cGMT, "grdimage_c", gmt_grdimage, -1);
258
+ rb_define_private_method(cGMT, "grdvector_c", gmt_grdvector, -1);
259
+ rb_define_private_method(cGMT, "grdview_c", gmt_grdview, -1);
260
+ rb_define_private_method(cGMT, "psbasemap_c", gmt_psbasemap, -1);
261
+ rb_define_private_method(cGMT, "psclip_c", gmt_psclip, -1);
262
+ rb_define_private_method(cGMT, "pscoast_c", gmt_pscoast, -1);
263
+ rb_define_private_method(cGMT, "pscontour_c", gmt_pscontour, -1);
264
+ rb_define_private_method(cGMT, "pshistogram_c", gmt_pshistogram, -1);
265
+ rb_define_private_method(cGMT, "psimage_c", gmt_psimage, -1);
266
+ rb_define_private_method(cGMT, "pslegend_c", gmt_pslegend, -1);
267
+ rb_define_private_method(cGMT, "psmask_c", gmt_psmask, -1);
268
+ rb_define_private_method(cGMT, "psrose_c", gmt_psrose, -1);
269
+ rb_define_private_method(cGMT, "psscale_c", gmt_psscale, -1);
123
270
  rb_define_private_method(cGMT, "pstext_c", gmt_pstext, -1);
271
+ rb_define_private_method(cGMT, "pswiggle_c", gmt_pswiggle, -1);
124
272
  rb_define_private_method(cGMT, "psxy_c", gmt_psxy, -1);
273
+ rb_define_private_method(cGMT, "psxyz_c", gmt_psxyz, -1);
125
274
  }
data/lib/gmt.rb CHANGED
@@ -1,6 +1,36 @@
1
- # === Generic Mapping Tools (GMT) interface for Ruby
1
+ # This class provides a native extension accessing the programs of
2
+ # the {http://gmt.soest.hawaii.edu/home Generic Mapping Tools};
3
+ # an open source collection of about 80 command-line tools for
4
+ # manipulating geographic and Cartesian data sets (including filtering,
5
+ # trend fitting, gridding, projecting, etc.) and producing PostScript
6
+ # illustrations ranging from simple x–y plots via contour maps to
7
+ # artificially illuminated surfaces and 3D perspective views
2
8
  #
3
- # Here we will have some documentation
9
+ # An example of usage:
10
+ #
11
+ # require 'gmt'
12
+ #
13
+ # common = {
14
+ # file: 'output.ps',
15
+ # R: '0/3/0/2',
16
+ # J: 'x1i'
17
+ # }
18
+ # gmt = GMT.new
19
+ # gmt.psxy('dots.xy',
20
+ # common.merge(
21
+ # position: :first,
22
+ # S: 'c0.50c',
23
+ # G: 'blue'))
24
+ # gmt.psxy('dots.xy',
25
+ # common.merge(
26
+ # position: :last,
27
+ # S: 'c0.25c',
28
+ # G: 'red'))
29
+ #
30
+ # Those familiar with GMT will recognise the +-R+ (range) and +-J+ (projection)
31
+ # options which are now keys for the program options hash.
32
+ #
33
+ # More details to follow ...
4
34
 
5
35
  class GMT
6
36
 
@@ -38,6 +68,7 @@ class GMT
38
68
  # @param [Array<String>] files The input files
39
69
  # @param [Hash] options The GMT command-line options in hash form
40
70
  # @return [Boolean] +true+ on success
71
+ # @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
41
72
  def wrapper_ps(method)
42
73
  define_method(method) do |*files, options|
43
74
  self.send(GMT.send(:method_c, method),
@@ -51,6 +82,7 @@ class GMT
51
82
  # @param [Array<String>] files The input files
52
83
  # @param [Hash] options The GMT command-line options in hash form
53
84
  # @return [Boolean] +true+ on success
85
+ # @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
54
86
  def wrapper_other(method)
55
87
  define_method(method) do |*args|
56
88
  self.send(GMT.send(:method_c, method), *args)
@@ -61,14 +93,85 @@ class GMT
61
93
 
62
94
  public
63
95
 
96
+ ### Mathematical Operations on Tables or Grids
97
+
98
+ # Mathematical operations on table data
99
+ wrapper_other :gmtmath
100
+
101
+ # Make color palette tables
102
+ wrapper_other :makecpt
103
+
104
+ # Compute various spectral estimates from time-series
105
+ wrapper_other :spectrum1d
106
+
107
+ # Compute grid from spherical harmonic coefficients
108
+ wrapper_other :sph2grd
109
+
110
+ # Make grid of distances to nearest points on a sphere
111
+ wrapper_other :sphdistance
112
+
113
+ # Delaunay or Voronoi construction of spherical lon,lat data
114
+ wrapper_other :sphtriangulate
115
+
116
+
117
+ ### Plotting of 1-D and 2-D Data
118
+
119
+ # Plot the GMT logo on maps
120
+ wrapper_ps :gmtlogo
121
+
122
+ # Contouring of 2-D gridded data sets
123
+ wrapper_ps :grdcontour
124
+
125
+ # Produce images from 2-D gridded data sets
126
+ wrapper_ps :grdimage
127
+
128
+ # Plotting of 2-D gridded vector fields
129
+ wrapper_ps :grdvector
130
+
131
+ # 3-D perspective imaging of 2-D gridded data sets
132
+ wrapper_ps :grdview
133
+
134
+ # Create a basemap plot
135
+ wrapper_ps :psbasemap
136
+
137
+ # Use polygon files to define clipping paths
138
+ wrapper_ps :psclip
139
+
140
+ # Plot (and fill) coastlines, borders, and rivers on maps
141
+ wrapper_ps :pscoast
142
+
143
+ # Contour or image raw table data by triangulation
144
+ wrapper_ps :pscontour
145
+
146
+ # Plot a histogram
147
+ wrapper_ps :pshistogram
148
+
149
+ # Plot Sun raster files on a map
150
+ wrapper_ps :psimage
151
+
152
+ # Plot a legend on a map
153
+ wrapper_ps :pslegend
154
+
155
+ # Create overlay to mask out regions on maps
156
+ wrapper_ps :psmask
157
+
158
+ # Plot sector or rose diagrams
159
+ wrapper_ps :psrose
160
+
161
+ # Plot gray scale or color scale on maps
162
+ wrapper_ps :psscale
163
+
64
164
  # Plot text strings on maps
65
165
  wrapper_ps :pstext
66
166
 
167
+ # Draw table data time-series along track on maps
168
+ wrapper_ps :pswiggle
169
+
67
170
  # Plot symbols, polygons, and lines on maps
68
171
  wrapper_ps :psxy
69
172
 
70
- # Make color palette tables
71
- wrapper_other :makecpt
173
+ # Plot symbols, polygons, and lines in 3-D
174
+ wrapper_ps :psxyz
72
175
 
73
176
  end
74
177
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - J.J. Green
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler