gmt 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/gmt/extconf.rb +17 -2
- data/ext/gmt/gmt.c +46 -120
- data/lib/gmt.rb +123 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb3e6c00f7441e68367685e8e81ae9ab37d7b7df
|
4
|
+
data.tar.gz: 607921342ff51b589eb0a45cd29338f9b7103c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc29e208845fd2506a567ec89baf60b561a20df1fad75fd23b6b20c06692e224e69b5181175494e294678fe2cfbb1b28fceffa67222ec06533ce1904f10740a0
|
7
|
+
data.tar.gz: 078abee21e2518de7647b0c070ee5ddc57e7b11190b2a026d8f4873069841a0c81721e87a2daa7b72120f94b9c2248b5f366d67634eca9d5f8355c9aa1c0057d
|
data/ext/gmt/extconf.rb
CHANGED
@@ -2,8 +2,23 @@ require 'mkmf'
|
|
2
2
|
|
3
3
|
$CFLAGS << ' -std=c99'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
6
|
+
HEADER_BASE = [
|
7
|
+
'/opt/local/include',
|
8
|
+
'/usr/local/include',
|
9
|
+
INCLUDEDIR,
|
10
|
+
'/usr/include',
|
11
|
+
]
|
12
|
+
HEADER_GMT = HEADER_BASE.map { |dir| File.join(dir, 'gmt') }
|
13
|
+
HEADER_DIRS = HEADER_GMT + HEADER_BASE
|
14
|
+
|
15
|
+
LIBDIR = RbConfig::CONFIG['libdir']
|
16
|
+
LIB_DIRS = [
|
17
|
+
'/opt/local/lib',
|
18
|
+
'/usr/local/lib',
|
19
|
+
LIBDIR,
|
20
|
+
'/usr/lib'
|
21
|
+
]
|
7
22
|
|
8
23
|
dir_config('gmt', HEADER_DIRS, LIB_DIRS)
|
9
24
|
|
data/ext/gmt/gmt.c
CHANGED
@@ -104,134 +104,52 @@ static VALUE gmt_simple(const char *name, int argc, VALUE *argv, VALUE self)
|
|
104
104
|
|
105
105
|
/* The GMT functions */
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
return gmt_simple("gmtmath", argc, argv, self);
|
112
|
-
}
|
113
|
-
|
114
|
-
static VALUE gmt_makecpt(int argc, VALUE *argv, VALUE self)
|
115
|
-
{
|
116
|
-
return gmt_simple("makecpt", argc, argv, self);
|
107
|
+
#define GMT_FUN(name) \
|
108
|
+
static VALUE gmt_ ## name (int argc, VALUE *argv, VALUE self) \
|
109
|
+
{ \
|
110
|
+
return gmt_simple(#name, argc, argv, self); \
|
117
111
|
}
|
118
112
|
|
119
|
-
|
120
|
-
{
|
121
|
-
return gmt_simple("spectrum1d", argc, argv, self);
|
122
|
-
}
|
113
|
+
/* Filtering of 1-D and 2-D Data */
|
123
114
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
115
|
+
GMT_FUN(blockmean)
|
116
|
+
GMT_FUN(blockmedian)
|
117
|
+
GMT_FUN(blockmode)
|
118
|
+
GMT_FUN(filter1d)
|
119
|
+
GMT_FUN(grdfilter)
|
128
120
|
|
129
|
-
|
130
|
-
{
|
131
|
-
return gmt_simple("sphdistance", argc, argv, self);
|
132
|
-
}
|
121
|
+
/* Mathematical Operations on Tables or Grids */
|
133
122
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
123
|
+
GMT_FUN(gmtmath)
|
124
|
+
GMT_FUN(makecpt)
|
125
|
+
GMT_FUN(spectrum1d)
|
126
|
+
GMT_FUN(sph2grd)
|
127
|
+
GMT_FUN(sphdistance)
|
128
|
+
GMT_FUN(sphtriangulate)
|
138
129
|
|
139
130
|
/* Plotting of 1-D and 2-D Data */
|
140
131
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
{
|
163
|
-
return gmt_simple("grdview", argc, argv, self);
|
164
|
-
}
|
165
|
-
|
166
|
-
static VALUE gmt_psbasemap(int argc, VALUE *argv, VALUE self)
|
167
|
-
{
|
168
|
-
return gmt_simple("psbasemap", argc, argv, self);
|
169
|
-
}
|
170
|
-
|
171
|
-
static VALUE gmt_psclip(int argc, VALUE *argv, VALUE self)
|
172
|
-
{
|
173
|
-
return gmt_simple("psclip", argc, argv, self);
|
174
|
-
}
|
175
|
-
|
176
|
-
static VALUE gmt_pscoast(int argc, VALUE *argv, VALUE self)
|
177
|
-
{
|
178
|
-
return gmt_simple("pscoast", argc, argv, self);
|
179
|
-
}
|
180
|
-
|
181
|
-
static VALUE gmt_pscontour(int argc, VALUE *argv, VALUE self)
|
182
|
-
{
|
183
|
-
return gmt_simple("pscontour", argc, argv, self);
|
184
|
-
}
|
185
|
-
|
186
|
-
static VALUE gmt_pshistogram(int argc, VALUE *argv, VALUE self)
|
187
|
-
{
|
188
|
-
return gmt_simple("pshistogram", argc, argv, self);
|
189
|
-
}
|
190
|
-
|
191
|
-
static VALUE gmt_psimage(int argc, VALUE *argv, VALUE self)
|
192
|
-
{
|
193
|
-
return gmt_simple("psimage", argc, argv, self);
|
194
|
-
}
|
195
|
-
|
196
|
-
static VALUE gmt_pslegend(int argc, VALUE *argv, VALUE self)
|
197
|
-
{
|
198
|
-
return gmt_simple("pslegend", argc, argv, self);
|
199
|
-
}
|
200
|
-
|
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);
|
234
|
-
}
|
132
|
+
GMT_FUN(gmtlogo)
|
133
|
+
GMT_FUN(grdcontour)
|
134
|
+
GMT_FUN(grdimage)
|
135
|
+
GMT_FUN(grdvector)
|
136
|
+
GMT_FUN(grdview)
|
137
|
+
GMT_FUN(psbasemap)
|
138
|
+
GMT_FUN(psclip)
|
139
|
+
GMT_FUN(pscoast)
|
140
|
+
GMT_FUN(pscontour)
|
141
|
+
GMT_FUN(pshistogram)
|
142
|
+
GMT_FUN(psimage)
|
143
|
+
GMT_FUN(pslegend)
|
144
|
+
GMT_FUN(psmask)
|
145
|
+
GMT_FUN(psrose)
|
146
|
+
GMT_FUN(psscale)
|
147
|
+
GMT_FUN(pstext)
|
148
|
+
GMT_FUN(pswiggle)
|
149
|
+
GMT_FUN(psxy)
|
150
|
+
GMT_FUN(psxyz)
|
151
|
+
|
152
|
+
#undef GMT_FUN
|
235
153
|
|
236
154
|
void Init_gmt(void)
|
237
155
|
{
|
@@ -241,6 +159,14 @@ void Init_gmt(void)
|
|
241
159
|
rb_define_method(cGMT, "initialize", gmt_init, 0);
|
242
160
|
rb_define_method(cGMT, "free", gmt_release, 0);
|
243
161
|
|
162
|
+
/* Filtering of 1-D and 2-D Data */
|
163
|
+
|
164
|
+
rb_define_private_method(cGMT, "blockmean_c", gmt_blockmean, -1);
|
165
|
+
rb_define_private_method(cGMT, "blockmedian_c", gmt_blockmedian, -1);
|
166
|
+
rb_define_private_method(cGMT, "blockmode_c", gmt_blockmode, -1);
|
167
|
+
rb_define_private_method(cGMT, "filter1d_c", gmt_filter1d, -1);
|
168
|
+
rb_define_private_method(cGMT, "grdfilter_c", gmt_grdfilter, -1);
|
169
|
+
|
244
170
|
/* Mathematical Operations on Tables or Grids */
|
245
171
|
|
246
172
|
rb_define_private_method(cGMT, "gmtmath_c", gmt_gmtmath, -1);
|
data/lib/gmt.rb
CHANGED
@@ -30,69 +30,157 @@
|
|
30
30
|
# Those familiar with GMT will recognise the +-R+ (range) and +-J+ (projection)
|
31
31
|
# options which are now keys for the program options hash.
|
32
32
|
#
|
33
|
-
#
|
34
|
-
|
33
|
+
# == The session
|
34
|
+
#
|
35
|
+
# All GMT functions (modules in the GMT parlance) require a session context,
|
36
|
+
# and an instance of the GMT class is exactly such a context.
|
37
|
+
#
|
38
|
+
# gmt = GMT.new
|
39
|
+
#
|
40
|
+
# There are no arguments for the constructor.
|
41
|
+
#
|
42
|
+
# == GMT functions
|
43
|
+
#
|
44
|
+
# Each GMT function is available as instance method, and each has the same
|
45
|
+
# signatures: several _arguments_, typically input files, followed by a
|
46
|
+
# single options hash. The options has corresponds to the command-line
|
47
|
+
# options of the GMT program; hence the shell command
|
48
|
+
#
|
49
|
+
# gmt makecpt -Cgebco depths.txt -i2 -Z -E24 > my_depths.cpt
|
50
|
+
#
|
51
|
+
# would be replicated by the Ruby
|
52
|
+
#
|
53
|
+
# gmt = GMT.new
|
54
|
+
# gmt.makecpt('depths.txt',
|
55
|
+
# :C => 'gebco', :i => 2, :Z => nil, :E => 24, :> => 'my_depths.cpt')
|
56
|
+
#
|
57
|
+
# Note that
|
58
|
+
# - the single argument (the input file <code>'depths.txt'</code>) preceeds
|
59
|
+
# the options hash
|
60
|
+
# - the options hash has keys which are symbols
|
61
|
+
# - options which lack arguments correspond to hash keys with nil values
|
62
|
+
# <code>:Z => nil</code>.
|
63
|
+
# - the output redirection is _also_ treated as hash option, with key
|
64
|
+
# <code>:></code> and value which is the output file.
|
65
|
+
#
|
66
|
+
# == PostScript functions
|
67
|
+
#
|
68
|
+
# When creating complex PostScript plots one needs to make several calls to
|
69
|
+
# GMT functions, to use the +-O+ and +-K+ options, and to append output of
|
70
|
+
# the second and subsequent calls (rather than overwriting). This is tiresome
|
71
|
+
# and error-prone on the command-line, and more so in the "options hash"
|
72
|
+
# representation in the Ruby module.
|
73
|
+
#
|
74
|
+
# So we add some syntatactic sugar for these PostScript functions: if the
|
75
|
+
# options hash has the keys +:position+ (with values one of +:first+, +:middle+,
|
76
|
+
# or +:last+) and +:file+ (with the value of the ouptut file), then the
|
77
|
+
# +-O+ and +-K+ options and the output redirection are handled by the class.
|
78
|
+
# So one might write
|
79
|
+
#
|
80
|
+
# gmt = GMT.new
|
81
|
+
# gmt.psbasemap( …, :file => 'map.ps', :position => :first)
|
82
|
+
# gmt.pstext( …, :file => 'map.ps', :position => :middle)
|
83
|
+
# gmt.psxy( …, :file => 'map.ps', :position => :middle)
|
84
|
+
# gmt.pslogo( …, :file => 'map.ps', :position => :last)
|
85
|
+
#
|
35
86
|
class GMT
|
36
87
|
|
37
88
|
class << self
|
38
89
|
|
39
90
|
private
|
40
91
|
|
41
|
-
def opts_normalise(options)
|
42
|
-
file = options.delete(:file)
|
43
|
-
position = options.delete(:position)
|
44
|
-
if file && position then
|
45
|
-
file_options =
|
46
|
-
case position
|
47
|
-
when :first
|
48
|
-
{ :K => nil, :> => file }
|
49
|
-
when :middle
|
50
|
-
{ :O => nil, :K => nil, :>> => file }
|
51
|
-
when :last
|
52
|
-
{ :O => nil, :>> => file }
|
53
|
-
else
|
54
|
-
raise ArguemntError, 'position should be :first, :middle or :last'
|
55
|
-
end
|
56
|
-
options.merge(file_options)
|
57
|
-
else
|
58
|
-
options
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def method_c(method)
|
63
|
-
[method.to_s, 'c'].join('_').to_sym
|
64
|
-
end
|
65
|
-
|
66
92
|
# @macro [attach] wrapper_ps
|
93
|
+
#
|
94
|
+
# A PostScript function (accepts +:file+ and +:position+ options).
|
67
95
|
# @method $1(*files, options)
|
68
96
|
# @param [Array<String>] files The input files
|
69
97
|
# @param [Hash] options The GMT command-line options in hash form
|
70
98
|
# @return [Boolean] +true+ on success
|
71
99
|
# @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
|
72
100
|
def wrapper_ps(method)
|
73
|
-
define_method(method) do |*
|
74
|
-
self.send(
|
75
|
-
*
|
76
|
-
|
101
|
+
define_method(method) do |*args, options|
|
102
|
+
self.send(api_function(method),
|
103
|
+
*string_arguments(args),
|
104
|
+
postscript_options(options))
|
77
105
|
end
|
78
106
|
end
|
79
107
|
|
80
108
|
# @macro [attach] wrapper_other
|
81
|
-
# @method $1(*
|
82
|
-
# @param [Array<String>]
|
109
|
+
# @method $1(*arguments, options)
|
110
|
+
# @param [Array<String>] arguments The arguments
|
83
111
|
# @param [Hash] options The GMT command-line options in hash form
|
84
112
|
# @return [Boolean] +true+ on success
|
85
113
|
# @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
|
86
114
|
def wrapper_other(method)
|
87
|
-
define_method(method) do |*args|
|
88
|
-
self.send(
|
115
|
+
define_method(method) do |*args, options|
|
116
|
+
self.send(api_function(method),
|
117
|
+
*string_arguments(args),
|
118
|
+
options)
|
89
119
|
end
|
90
120
|
end
|
91
121
|
|
92
122
|
end
|
93
123
|
|
124
|
+
private
|
125
|
+
|
126
|
+
# the name of the C function
|
127
|
+
|
128
|
+
def api_function(method)
|
129
|
+
[method.to_s, 'c'].join('_').to_sym
|
130
|
+
end
|
131
|
+
|
132
|
+
# convert non-option arguments to strings
|
133
|
+
|
134
|
+
def string_arguments(args)
|
135
|
+
args.map(&:to_s)
|
136
|
+
end
|
137
|
+
|
138
|
+
# for GMT modules which produce PostScript, convert the
|
139
|
+
# convenience options (:position, :file) to the hash
|
140
|
+
# equivalent of the -K, -O options, and the creation of
|
141
|
+
# or appending to the PostScript output file
|
142
|
+
|
143
|
+
def postscript_options(options)
|
144
|
+
file = options.delete(:file)
|
145
|
+
position = options.delete(:position)
|
146
|
+
if file && position then
|
147
|
+
file_options =
|
148
|
+
case position
|
149
|
+
when :first
|
150
|
+
{ :K => nil, :> => file }
|
151
|
+
when :middle
|
152
|
+
{ :O => nil, :K => nil, :>> => file }
|
153
|
+
when :last
|
154
|
+
{ :O => nil, :>> => file }
|
155
|
+
else
|
156
|
+
raise ArguemntError, 'position should be :first, :middle or :last'
|
157
|
+
end
|
158
|
+
options.merge(file_options)
|
159
|
+
else
|
160
|
+
options
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
94
164
|
public
|
95
165
|
|
166
|
+
### Filtering of 1-D and 2-D Data
|
167
|
+
|
168
|
+
# L2 (x,y,z) table data filter/decimator
|
169
|
+
wrapper_other :blockmean
|
170
|
+
|
171
|
+
# L1 (x,y,z) table data filter/decimator
|
172
|
+
wrapper_other :blockmedian
|
173
|
+
|
174
|
+
# Mode estimate (x,y,z) table data filter/decimator
|
175
|
+
wrapper_other :blockmode
|
176
|
+
|
177
|
+
# Time domain filtering of 1-D data tables
|
178
|
+
wrapper_other :filter1d
|
179
|
+
|
180
|
+
# Filter 2-D gridded data sets in the space domain
|
181
|
+
wrapper_other :grdfilter
|
182
|
+
|
183
|
+
|
96
184
|
### Mathematical Operations on Tables or Grids
|
97
185
|
|
98
186
|
# Mathematical operations on table data
|
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.
|
4
|
+
version: 0.0.7
|
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-06-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|