netcdf 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +34 -0
- data/LICENSE +21 -0
- data/README.md +82 -0
- data/docs/00_introduction.md +34 -0
- data/docs/01_getting_started.md +127 -0
- data/docs/02_buffers.md +95 -0
- data/docs/03_reference.md +410 -0
- data/ext/netcdf/extconf.rb +61 -0
- data/ext/netcdf/internal.h +64 -0
- data/ext/netcdf/nc_att.c +431 -0
- data/ext/netcdf/nc_dim.c +74 -0
- data/ext/netcdf/nc_file.c +349 -0
- data/ext/netcdf/nc_group.c +171 -0
- data/ext/netcdf/nc_io.c +1284 -0
- data/ext/netcdf/nc_types.c +278 -0
- data/ext/netcdf/nc_var.c +551 -0
- data/ext/netcdf/netcdf.c +289 -0
- data/lib/netcdf/version.rb +3 -0
- data/lib/netcdf.rb +29 -0
- data/netcdf.gemspec +30 -0
- metadata +66 -0
data/ext/netcdf/nc_var.c
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
#include "internal.h"
|
|
2
|
+
|
|
3
|
+
/* ---------------------------------------------------------- */
|
|
4
|
+
/* Definition / inquiry */
|
|
5
|
+
/* ---------------------------------------------------------- */
|
|
6
|
+
|
|
7
|
+
static VALUE
|
|
8
|
+
rb_nc_def_var (VALUE self, VALUE rncid, VALUE rname, VALUE rxtype, VALUE rdimids)
|
|
9
|
+
{
|
|
10
|
+
VALUE vids;
|
|
11
|
+
int *ids;
|
|
12
|
+
long ndims, i;
|
|
13
|
+
int varid, st;
|
|
14
|
+
|
|
15
|
+
Check_Type(rdimids, T_ARRAY);
|
|
16
|
+
ndims = RARRAY_LEN(rdimids);
|
|
17
|
+
vids = 0;
|
|
18
|
+
ids = NULL;
|
|
19
|
+
if ( ndims > 0 ) {
|
|
20
|
+
ids = ALLOCV_N(int, vids, ndims);
|
|
21
|
+
for (i=0; i<ndims; i++) {
|
|
22
|
+
ids[i] = NUM2INT(RARRAY_AREF(rdimids, i));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
st = nc_def_var(NUM2INT(rncid), StringValueCStr(rname), NUM2INT(rxtype),
|
|
26
|
+
(int) ndims, ids, &varid);
|
|
27
|
+
if ( ids ) {
|
|
28
|
+
ALLOCV_END(vids);
|
|
29
|
+
}
|
|
30
|
+
if ( st != NC_NOERR ) {
|
|
31
|
+
nc_raise(st);
|
|
32
|
+
}
|
|
33
|
+
return INT2NUM(varid);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static VALUE
|
|
37
|
+
rb_nc_inq_varid (VALUE self, VALUE rncid, VALUE rname)
|
|
38
|
+
{
|
|
39
|
+
int varid, st;
|
|
40
|
+
|
|
41
|
+
st = nc_inq_varid(NUM2INT(rncid), StringValueCStr(rname), &varid);
|
|
42
|
+
if ( st == NC_ENOTVAR ) {
|
|
43
|
+
return Qnil;
|
|
44
|
+
}
|
|
45
|
+
if ( st != NC_NOERR ) {
|
|
46
|
+
nc_raise(st);
|
|
47
|
+
}
|
|
48
|
+
return INT2NUM(varid);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static VALUE
|
|
52
|
+
rb_nc_inq_var (VALUE self, VALUE rncid, VALUE rvarid)
|
|
53
|
+
{
|
|
54
|
+
char name[NC_MAX_NAME + 1];
|
|
55
|
+
int dimids[NC_MAX_VAR_DIMS];
|
|
56
|
+
VALUE rdimids;
|
|
57
|
+
nc_type xtype;
|
|
58
|
+
int ndims, natts, i;
|
|
59
|
+
|
|
60
|
+
NC_CHECK(nc_inq_var(NUM2INT(rncid), NUM2INT(rvarid), name, &xtype,
|
|
61
|
+
&ndims, dimids, &natts));
|
|
62
|
+
rdimids = rb_ary_new_capa(ndims);
|
|
63
|
+
for (i=0; i<ndims; i++) {
|
|
64
|
+
rb_ary_push(rdimids, INT2NUM(dimids[i]));
|
|
65
|
+
}
|
|
66
|
+
return rb_ary_new_from_args(5,
|
|
67
|
+
rb_utf8_str_new_cstr(name), INT2NUM(xtype),
|
|
68
|
+
INT2NUM(ndims), rdimids, INT2NUM(natts));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static VALUE
|
|
72
|
+
rb_nc_inq_varname (VALUE self, VALUE rncid, VALUE rvarid)
|
|
73
|
+
{
|
|
74
|
+
char name[NC_MAX_NAME + 1];
|
|
75
|
+
|
|
76
|
+
NC_CHECK(nc_inq_varname(NUM2INT(rncid), NUM2INT(rvarid), name));
|
|
77
|
+
return rb_utf8_str_new_cstr(name);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static VALUE
|
|
81
|
+
rb_nc_inq_vartype (VALUE self, VALUE rncid, VALUE rvarid)
|
|
82
|
+
{
|
|
83
|
+
nc_type t;
|
|
84
|
+
|
|
85
|
+
NC_CHECK(nc_inq_vartype(NUM2INT(rncid), NUM2INT(rvarid), &t));
|
|
86
|
+
return INT2NUM(t);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static VALUE
|
|
90
|
+
rb_nc_inq_varndims (VALUE self, VALUE rncid, VALUE rvarid)
|
|
91
|
+
{
|
|
92
|
+
int n;
|
|
93
|
+
|
|
94
|
+
NC_CHECK(nc_inq_varndims(NUM2INT(rncid), NUM2INT(rvarid), &n));
|
|
95
|
+
return INT2NUM(n);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static VALUE
|
|
99
|
+
rb_nc_inq_vardimid (VALUE self, VALUE rncid, VALUE rvarid)
|
|
100
|
+
{
|
|
101
|
+
int dimids[NC_MAX_VAR_DIMS];
|
|
102
|
+
VALUE out;
|
|
103
|
+
int ndims, i;
|
|
104
|
+
|
|
105
|
+
NC_CHECK(nc_inq_varndims(NUM2INT(rncid), NUM2INT(rvarid), &ndims));
|
|
106
|
+
NC_CHECK(nc_inq_vardimid(NUM2INT(rncid), NUM2INT(rvarid), dimids));
|
|
107
|
+
out = rb_ary_new_capa(ndims);
|
|
108
|
+
for (i=0; i<ndims; i++) {
|
|
109
|
+
rb_ary_push(out, INT2NUM(dimids[i]));
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static VALUE
|
|
115
|
+
rb_nc_inq_varnatts (VALUE self, VALUE rncid, VALUE rvarid)
|
|
116
|
+
{
|
|
117
|
+
int n;
|
|
118
|
+
|
|
119
|
+
NC_CHECK(nc_inq_varnatts(NUM2INT(rncid), NUM2INT(rvarid), &n));
|
|
120
|
+
return INT2NUM(n);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static VALUE
|
|
124
|
+
rb_nc_rename_var (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
|
|
125
|
+
{
|
|
126
|
+
NC_CHECK(nc_rename_var(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname)));
|
|
127
|
+
return Qnil;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ---------------------------------------------------------- */
|
|
131
|
+
/* NetCDF-4 per-variable options */
|
|
132
|
+
/* ---------------------------------------------------------- */
|
|
133
|
+
|
|
134
|
+
static VALUE
|
|
135
|
+
rb_nc_def_var_fill (VALUE self, VALUE rncid, VALUE rvarid, VALUE rno_fill, VALUE rfill)
|
|
136
|
+
{
|
|
137
|
+
union {
|
|
138
|
+
signed char c; unsigned char uc;
|
|
139
|
+
short s; unsigned short us;
|
|
140
|
+
int i; unsigned int ui;
|
|
141
|
+
long long ll; unsigned long long ull;
|
|
142
|
+
float f; double d;
|
|
143
|
+
} v;
|
|
144
|
+
void *vp;
|
|
145
|
+
int ncid, varid, no_fill;
|
|
146
|
+
nc_type xt;
|
|
147
|
+
|
|
148
|
+
ncid = NUM2INT(rncid);
|
|
149
|
+
varid = NUM2INT(rvarid);
|
|
150
|
+
no_fill = RTEST(rno_fill) ? 1 : 0;
|
|
151
|
+
|
|
152
|
+
NC_CHECK(nc_inq_vartype(ncid, varid, &xt));
|
|
153
|
+
|
|
154
|
+
if ( NIL_P(rfill) ) {
|
|
155
|
+
NC_CHECK(nc_def_var_fill(ncid, varid, no_fill, NULL));
|
|
156
|
+
return Qnil;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
vp = NULL;
|
|
160
|
+
switch ( xt ) {
|
|
161
|
+
case NC_CHAR:
|
|
162
|
+
StringValue(rfill);
|
|
163
|
+
if ( RSTRING_LEN(rfill) < 1 ) {
|
|
164
|
+
rb_raise(rb_eArgError, "fill_value string must be non-empty");
|
|
165
|
+
}
|
|
166
|
+
vp = RSTRING_PTR(rfill);
|
|
167
|
+
break;
|
|
168
|
+
case NC_BYTE: v.c = num_to_schar(rfill); vp = &v.c; break;
|
|
169
|
+
case NC_UBYTE: v.uc = num_to_uchar(rfill); vp = &v.uc; break;
|
|
170
|
+
case NC_SHORT: v.s = num_to_short(rfill); vp = &v.s; break;
|
|
171
|
+
case NC_USHORT: v.us = num_to_ushort(rfill); vp = &v.us; break;
|
|
172
|
+
case NC_INT: v.i = NUM2INT(rfill); vp = &v.i; break;
|
|
173
|
+
case NC_UINT: v.ui = num_to_uint(rfill); vp = &v.ui; break;
|
|
174
|
+
case NC_INT64: v.ll = NUM2LL(rfill); vp = &v.ll; break;
|
|
175
|
+
case NC_UINT64: v.ull = num_to_ulonglong(rfill); vp = &v.ull; break;
|
|
176
|
+
case NC_FLOAT: v.f = (float) NUM2DBL(rfill); vp = &v.f; break;
|
|
177
|
+
case NC_DOUBLE: v.d = NUM2DBL(rfill); vp = &v.d; break;
|
|
178
|
+
default:
|
|
179
|
+
rb_raise(rb_eNotImpError, "unsupported nc_type: %d", xt);
|
|
180
|
+
}
|
|
181
|
+
NC_CHECK(nc_def_var_fill(ncid, varid, no_fill, vp));
|
|
182
|
+
return Qnil;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
static VALUE
|
|
186
|
+
rb_nc_inq_var_fill (VALUE self, VALUE rncid, VALUE rvarid)
|
|
187
|
+
{
|
|
188
|
+
union {
|
|
189
|
+
signed char c; unsigned char uc;
|
|
190
|
+
short s; unsigned short us;
|
|
191
|
+
int i; unsigned int ui;
|
|
192
|
+
long long ll; unsigned long long ull;
|
|
193
|
+
float f; double d;
|
|
194
|
+
char text;
|
|
195
|
+
} v;
|
|
196
|
+
VALUE rfill;
|
|
197
|
+
int ncid, varid, no_fill;
|
|
198
|
+
nc_type xt;
|
|
199
|
+
|
|
200
|
+
ncid = NUM2INT(rncid);
|
|
201
|
+
varid = NUM2INT(rvarid);
|
|
202
|
+
|
|
203
|
+
NC_CHECK(nc_inq_vartype(ncid, varid, &xt));
|
|
204
|
+
/* libnetcdf writes a whole element of the variable's type into `v`,
|
|
205
|
+
so refuse any type the union below cannot hold before asking --
|
|
206
|
+
an opaque's element can be any size. */
|
|
207
|
+
if ( nc_xtype_size(xt) < 0 ) {
|
|
208
|
+
rb_raise(rb_eNotImpError, "unsupported nc_type: %d", xt);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
memset(&v, 0, sizeof(v));
|
|
212
|
+
NC_CHECK(nc_inq_var_fill(ncid, varid, &no_fill, &v));
|
|
213
|
+
|
|
214
|
+
switch ( xt ) {
|
|
215
|
+
case NC_CHAR: rfill = rb_utf8_str_new(&v.text, 1); break;
|
|
216
|
+
case NC_BYTE: rfill = INT2NUM(v.c); break;
|
|
217
|
+
case NC_UBYTE: rfill = UINT2NUM(v.uc); break;
|
|
218
|
+
case NC_SHORT: rfill = INT2NUM(v.s); break;
|
|
219
|
+
case NC_USHORT: rfill = UINT2NUM(v.us); break;
|
|
220
|
+
case NC_INT: rfill = INT2NUM(v.i); break;
|
|
221
|
+
case NC_UINT: rfill = UINT2NUM(v.ui); break;
|
|
222
|
+
case NC_INT64: rfill = LL2NUM(v.ll); break;
|
|
223
|
+
case NC_UINT64: rfill = ULL2NUM(v.ull); break;
|
|
224
|
+
case NC_FLOAT: rfill = DBL2NUM(v.f); break;
|
|
225
|
+
case NC_DOUBLE: rfill = DBL2NUM(v.d); break;
|
|
226
|
+
default:
|
|
227
|
+
rb_raise(rb_eNotImpError, "unsupported nc_type: %d", xt);
|
|
228
|
+
}
|
|
229
|
+
return rb_ary_new_from_args(2, no_fill ? Qtrue : Qfalse, rfill);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static VALUE
|
|
233
|
+
rb_nc_def_var_deflate (VALUE self, VALUE rncid, VALUE rvarid,
|
|
234
|
+
VALUE rshuffle, VALUE rdeflate, VALUE rlevel)
|
|
235
|
+
{
|
|
236
|
+
NC_CHECK(nc_def_var_deflate(NUM2INT(rncid), NUM2INT(rvarid),
|
|
237
|
+
RTEST(rshuffle), RTEST(rdeflate), NUM2INT(rlevel)));
|
|
238
|
+
return Qnil;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
static VALUE
|
|
242
|
+
rb_nc_inq_var_deflate (VALUE self, VALUE rncid, VALUE rvarid)
|
|
243
|
+
{
|
|
244
|
+
int shuffle, deflate, level;
|
|
245
|
+
|
|
246
|
+
NC_CHECK(nc_inq_var_deflate(NUM2INT(rncid), NUM2INT(rvarid),
|
|
247
|
+
&shuffle, &deflate, &level));
|
|
248
|
+
return rb_ary_new_from_args(3,
|
|
249
|
+
shuffle ? Qtrue : Qfalse,
|
|
250
|
+
deflate ? Qtrue : Qfalse,
|
|
251
|
+
INT2NUM(level));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static VALUE
|
|
255
|
+
rb_nc_def_var_chunking (VALUE self, VALUE rncid, VALUE rvarid,
|
|
256
|
+
VALUE rstorage, VALUE rsizes)
|
|
257
|
+
{
|
|
258
|
+
size_t sizes[NC_MAX_VAR_DIMS];
|
|
259
|
+
int ncid, varid, storage, ndims;
|
|
260
|
+
|
|
261
|
+
ncid = NUM2INT(rncid);
|
|
262
|
+
varid = NUM2INT(rvarid);
|
|
263
|
+
storage = NUM2INT(rstorage);
|
|
264
|
+
|
|
265
|
+
if ( storage == NC_CHUNKED ) {
|
|
266
|
+
NC_CHECK(nc_inq_varndims(ncid, varid, &ndims));
|
|
267
|
+
ary_to_sizet(rsizes, ndims, "chunksizes", sizes);
|
|
268
|
+
}
|
|
269
|
+
NC_CHECK(nc_def_var_chunking(ncid, varid, storage,
|
|
270
|
+
( storage == NC_CHUNKED ) ? sizes : NULL));
|
|
271
|
+
return Qnil;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static VALUE
|
|
275
|
+
rb_nc_inq_var_chunking (VALUE self, VALUE rncid, VALUE rvarid)
|
|
276
|
+
{
|
|
277
|
+
VALUE rsizes;
|
|
278
|
+
size_t *sizes;
|
|
279
|
+
int ncid, varid, ndims, storage, st, i;
|
|
280
|
+
|
|
281
|
+
ncid = NUM2INT(rncid);
|
|
282
|
+
varid = NUM2INT(rvarid);
|
|
283
|
+
|
|
284
|
+
NC_CHECK(nc_inq_varndims(ncid, varid, &ndims));
|
|
285
|
+
|
|
286
|
+
sizes = ALLOC_N(size_t, ndims > 0 ? ndims : 1);
|
|
287
|
+
st = nc_inq_var_chunking(ncid, varid, &storage, sizes);
|
|
288
|
+
if ( st != NC_NOERR ) {
|
|
289
|
+
xfree(sizes);
|
|
290
|
+
nc_raise(st);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
rsizes = rb_ary_new_capa(ndims);
|
|
294
|
+
for (i=0; i<ndims; i++) {
|
|
295
|
+
rb_ary_push(rsizes, SIZET2NUM(sizes[i]));
|
|
296
|
+
}
|
|
297
|
+
xfree(sizes);
|
|
298
|
+
return rb_ary_new_from_args(2, INT2NUM(storage), rsizes);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
static VALUE
|
|
302
|
+
rb_nc_def_var_fletcher32 (VALUE self, VALUE rncid, VALUE rvarid, VALUE ron)
|
|
303
|
+
{
|
|
304
|
+
NC_CHECK(nc_def_var_fletcher32(NUM2INT(rncid), NUM2INT(rvarid),
|
|
305
|
+
RTEST(ron) ? NC_FLETCHER32 : NC_NOCHECKSUM));
|
|
306
|
+
return Qnil;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
static VALUE
|
|
310
|
+
rb_nc_inq_var_fletcher32 (VALUE self, VALUE rncid, VALUE rvarid)
|
|
311
|
+
{
|
|
312
|
+
int v;
|
|
313
|
+
|
|
314
|
+
NC_CHECK(nc_inq_var_fletcher32(NUM2INT(rncid), NUM2INT(rvarid), &v));
|
|
315
|
+
return ( v == NC_FLETCHER32 ) ? Qtrue : Qfalse;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static VALUE
|
|
319
|
+
rb_nc_def_var_endian (VALUE self, VALUE rncid, VALUE rvarid, VALUE rendian)
|
|
320
|
+
{
|
|
321
|
+
NC_CHECK(nc_def_var_endian(NUM2INT(rncid), NUM2INT(rvarid), NUM2INT(rendian)));
|
|
322
|
+
return Qnil;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
static VALUE
|
|
326
|
+
rb_nc_inq_var_endian (VALUE self, VALUE rncid, VALUE rvarid)
|
|
327
|
+
{
|
|
328
|
+
int e;
|
|
329
|
+
|
|
330
|
+
NC_CHECK(nc_inq_var_endian(NUM2INT(rncid), NUM2INT(rvarid), &e));
|
|
331
|
+
return INT2NUM(e);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/* ---------------------------------------------------------- */
|
|
335
|
+
/* Filter (NetCDF-4 / HDF5 — register HDF5 filter on a var) */
|
|
336
|
+
/* ---------------------------------------------------------- */
|
|
337
|
+
|
|
338
|
+
#ifdef HAVE_NC_DEF_VAR_FILTER
|
|
339
|
+
/* nc_def_var_filter(ncid, varid, filter_id, params)
|
|
340
|
+
* filter_id : Integer (e.g. 32015 for Zstd)
|
|
341
|
+
* params : Array<Integer> (raw unsigned 32-bit values) */
|
|
342
|
+
static VALUE
|
|
343
|
+
rb_nc_def_var_filter (VALUE self, VALUE rncid, VALUE rvarid, VALUE rid, VALUE rparams)
|
|
344
|
+
{
|
|
345
|
+
VALUE vparams;
|
|
346
|
+
unsigned int *params;
|
|
347
|
+
long n, i;
|
|
348
|
+
int st;
|
|
349
|
+
|
|
350
|
+
Check_Type(rparams, T_ARRAY);
|
|
351
|
+
n = RARRAY_LEN(rparams);
|
|
352
|
+
params = ALLOCV_N(unsigned int, vparams, n > 0 ? n : 1);
|
|
353
|
+
for (i=0; i<n; i++) {
|
|
354
|
+
params[i] = NUM2UINT(RARRAY_AREF(rparams, i));
|
|
355
|
+
}
|
|
356
|
+
st = nc_def_var_filter(NUM2INT(rncid), NUM2INT(rvarid),
|
|
357
|
+
NUM2UINT(rid), (size_t) n, params);
|
|
358
|
+
ALLOCV_END(vparams);
|
|
359
|
+
if ( st != NC_NOERR ) {
|
|
360
|
+
nc_raise(st);
|
|
361
|
+
}
|
|
362
|
+
return Qnil;
|
|
363
|
+
}
|
|
364
|
+
#endif /* HAVE_NC_DEF_VAR_FILTER */
|
|
365
|
+
|
|
366
|
+
#ifdef HAVE_NC_INQ_VAR_FILTER_INFO
|
|
367
|
+
/* Returns the param list for one filter on a var, or nil if the variable
|
|
368
|
+
doesn't carry that filter. */
|
|
369
|
+
static VALUE
|
|
370
|
+
rb_nc_inq_var_filter_info (VALUE self, VALUE rncid, VALUE rvarid, VALUE rid)
|
|
371
|
+
{
|
|
372
|
+
VALUE out;
|
|
373
|
+
unsigned int *params;
|
|
374
|
+
unsigned int id;
|
|
375
|
+
size_t n, i;
|
|
376
|
+
int ncid, varid, st;
|
|
377
|
+
|
|
378
|
+
ncid = NUM2INT(rncid);
|
|
379
|
+
varid = NUM2INT(rvarid);
|
|
380
|
+
id = NUM2UINT(rid);
|
|
381
|
+
|
|
382
|
+
st = nc_inq_var_filter_info(ncid, varid, id, &n, NULL);
|
|
383
|
+
if ( st == NC_ENOFILTER ) {
|
|
384
|
+
return Qnil;
|
|
385
|
+
}
|
|
386
|
+
if ( st != NC_NOERR ) {
|
|
387
|
+
nc_raise(st);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
params = ALLOC_N(unsigned int, n > 0 ? n : 1);
|
|
391
|
+
st = nc_inq_var_filter_info(ncid, varid, id, NULL, params);
|
|
392
|
+
if ( st != NC_NOERR ) {
|
|
393
|
+
xfree(params);
|
|
394
|
+
nc_raise(st);
|
|
395
|
+
}
|
|
396
|
+
out = rb_ary_new_capa((long) n);
|
|
397
|
+
for (i=0; i<n; i++) {
|
|
398
|
+
rb_ary_push(out, UINT2NUM(params[i]));
|
|
399
|
+
}
|
|
400
|
+
xfree(params);
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
#endif /* HAVE_NC_INQ_VAR_FILTER_INFO */
|
|
404
|
+
|
|
405
|
+
#ifdef HAVE_NC_INQ_VAR_FILTER_IDS
|
|
406
|
+
/* Returns the list of filter IDs registered on a variable. */
|
|
407
|
+
static VALUE
|
|
408
|
+
rb_nc_inq_var_filter_ids (VALUE self, VALUE rncid, VALUE rvarid)
|
|
409
|
+
{
|
|
410
|
+
VALUE out;
|
|
411
|
+
unsigned int *ids;
|
|
412
|
+
size_t n, i;
|
|
413
|
+
int ncid, varid, st;
|
|
414
|
+
|
|
415
|
+
ncid = NUM2INT(rncid);
|
|
416
|
+
varid = NUM2INT(rvarid);
|
|
417
|
+
|
|
418
|
+
NC_CHECK(nc_inq_var_filter_ids(ncid, varid, &n, NULL));
|
|
419
|
+
ids = ALLOC_N(unsigned int, n > 0 ? n : 1);
|
|
420
|
+
st = nc_inq_var_filter_ids(ncid, varid, NULL, ids);
|
|
421
|
+
if ( st != NC_NOERR ) {
|
|
422
|
+
xfree(ids);
|
|
423
|
+
nc_raise(st);
|
|
424
|
+
}
|
|
425
|
+
out = rb_ary_new_capa((long) n);
|
|
426
|
+
for (i=0; i<n; i++) {
|
|
427
|
+
rb_ary_push(out, UINT2NUM(ids[i]));
|
|
428
|
+
}
|
|
429
|
+
xfree(ids);
|
|
430
|
+
return out;
|
|
431
|
+
}
|
|
432
|
+
#endif /* HAVE_NC_INQ_VAR_FILTER_IDS */
|
|
433
|
+
|
|
434
|
+
#ifdef HAVE_NC_INQ_FILTER_AVAIL
|
|
435
|
+
/* Returns true if the given filter is available in the linked libnetcdf
|
|
436
|
+
for the given file's format. nc_inq_filter_avail returns NC_NOERR when
|
|
437
|
+
it's usable, NC_ENOFILTER otherwise. */
|
|
438
|
+
static VALUE
|
|
439
|
+
rb_nc_inq_filter_avail (VALUE self, VALUE rncid, VALUE rid)
|
|
440
|
+
{
|
|
441
|
+
int st;
|
|
442
|
+
|
|
443
|
+
st = nc_inq_filter_avail(NUM2INT(rncid), NUM2UINT(rid));
|
|
444
|
+
if ( st == NC_NOERR ) {
|
|
445
|
+
return Qtrue;
|
|
446
|
+
}
|
|
447
|
+
if ( st == NC_ENOFILTER ) {
|
|
448
|
+
return Qfalse;
|
|
449
|
+
}
|
|
450
|
+
nc_raise(st);
|
|
451
|
+
}
|
|
452
|
+
#endif
|
|
453
|
+
|
|
454
|
+
/* ---------------------------------------------------------- */
|
|
455
|
+
/* Quantize (lossy bit-grooming for floating-point data) */
|
|
456
|
+
/* ---------------------------------------------------------- */
|
|
457
|
+
|
|
458
|
+
#ifdef HAVE_NC_DEF_VAR_QUANTIZE
|
|
459
|
+
static VALUE
|
|
460
|
+
rb_nc_def_var_quantize (VALUE self, VALUE rncid, VALUE rvarid, VALUE rmode, VALUE rnsd)
|
|
461
|
+
{
|
|
462
|
+
NC_CHECK(nc_def_var_quantize(NUM2INT(rncid), NUM2INT(rvarid),
|
|
463
|
+
NUM2INT(rmode), NUM2INT(rnsd)));
|
|
464
|
+
return Qnil;
|
|
465
|
+
}
|
|
466
|
+
#endif
|
|
467
|
+
|
|
468
|
+
#ifdef HAVE_NC_INQ_VAR_QUANTIZE
|
|
469
|
+
static VALUE
|
|
470
|
+
rb_nc_inq_var_quantize (VALUE self, VALUE rncid, VALUE rvarid)
|
|
471
|
+
{
|
|
472
|
+
int mode, nsd;
|
|
473
|
+
|
|
474
|
+
NC_CHECK(nc_inq_var_quantize(NUM2INT(rncid), NUM2INT(rvarid), &mode, &nsd));
|
|
475
|
+
return rb_ary_new_from_args(2, INT2NUM(mode), INT2NUM(nsd));
|
|
476
|
+
}
|
|
477
|
+
#endif
|
|
478
|
+
|
|
479
|
+
/* ---------------------------------------------------------- */
|
|
480
|
+
/* Per-variable chunk cache */
|
|
481
|
+
/* ---------------------------------------------------------- */
|
|
482
|
+
|
|
483
|
+
static VALUE
|
|
484
|
+
rb_nc_set_var_chunk_cache (VALUE self, VALUE rncid, VALUE rvarid,
|
|
485
|
+
VALUE rsize, VALUE rnelems, VALUE rpreemption)
|
|
486
|
+
{
|
|
487
|
+
NC_CHECK(nc_set_var_chunk_cache(NUM2INT(rncid), NUM2INT(rvarid),
|
|
488
|
+
NUM2SIZET(rsize), NUM2SIZET(rnelems),
|
|
489
|
+
(float) NUM2DBL(rpreemption)));
|
|
490
|
+
return Qnil;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
static VALUE
|
|
494
|
+
rb_nc_get_var_chunk_cache (VALUE self, VALUE rncid, VALUE rvarid)
|
|
495
|
+
{
|
|
496
|
+
size_t size, nelems;
|
|
497
|
+
float pre;
|
|
498
|
+
|
|
499
|
+
NC_CHECK(nc_get_var_chunk_cache(NUM2INT(rncid), NUM2INT(rvarid),
|
|
500
|
+
&size, &nelems, &pre));
|
|
501
|
+
return rb_ary_new_from_args(3, SIZET2NUM(size), SIZET2NUM(nelems),
|
|
502
|
+
DBL2NUM((double) pre));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
void
|
|
506
|
+
init_nc_var (void)
|
|
507
|
+
{
|
|
508
|
+
rb_define_module_function(mNetCDF, "nc_def_var", rb_nc_def_var, 4);
|
|
509
|
+
rb_define_module_function(mNetCDF, "nc_inq_varid", rb_nc_inq_varid, 2);
|
|
510
|
+
rb_define_module_function(mNetCDF, "nc_inq_var", rb_nc_inq_var, 2);
|
|
511
|
+
rb_define_module_function(mNetCDF, "nc_inq_varname", rb_nc_inq_varname, 2);
|
|
512
|
+
rb_define_module_function(mNetCDF, "nc_inq_vartype", rb_nc_inq_vartype, 2);
|
|
513
|
+
rb_define_module_function(mNetCDF, "nc_inq_varndims", rb_nc_inq_varndims, 2);
|
|
514
|
+
rb_define_module_function(mNetCDF, "nc_inq_vardimid", rb_nc_inq_vardimid, 2);
|
|
515
|
+
rb_define_module_function(mNetCDF, "nc_inq_varnatts", rb_nc_inq_varnatts, 2);
|
|
516
|
+
rb_define_module_function(mNetCDF, "nc_rename_var", rb_nc_rename_var, 3);
|
|
517
|
+
|
|
518
|
+
rb_define_module_function(mNetCDF, "nc_def_var_fill", rb_nc_def_var_fill, 4);
|
|
519
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_fill", rb_nc_inq_var_fill, 2);
|
|
520
|
+
rb_define_module_function(mNetCDF, "nc_def_var_deflate", rb_nc_def_var_deflate, 5);
|
|
521
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_deflate", rb_nc_inq_var_deflate, 2);
|
|
522
|
+
rb_define_module_function(mNetCDF, "nc_def_var_chunking", rb_nc_def_var_chunking, 4);
|
|
523
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_chunking", rb_nc_inq_var_chunking, 2);
|
|
524
|
+
rb_define_module_function(mNetCDF, "nc_def_var_fletcher32", rb_nc_def_var_fletcher32, 3);
|
|
525
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_fletcher32", rb_nc_inq_var_fletcher32, 2);
|
|
526
|
+
rb_define_module_function(mNetCDF, "nc_def_var_endian", rb_nc_def_var_endian, 3);
|
|
527
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_endian", rb_nc_inq_var_endian, 2);
|
|
528
|
+
|
|
529
|
+
#ifdef HAVE_NC_DEF_VAR_FILTER
|
|
530
|
+
rb_define_module_function(mNetCDF, "nc_def_var_filter", rb_nc_def_var_filter, 4);
|
|
531
|
+
#endif
|
|
532
|
+
#ifdef HAVE_NC_INQ_VAR_FILTER_INFO
|
|
533
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_filter_info", rb_nc_inq_var_filter_info, 3);
|
|
534
|
+
#endif
|
|
535
|
+
#ifdef HAVE_NC_INQ_VAR_FILTER_IDS
|
|
536
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_filter_ids", rb_nc_inq_var_filter_ids, 2);
|
|
537
|
+
#endif
|
|
538
|
+
#ifdef HAVE_NC_INQ_FILTER_AVAIL
|
|
539
|
+
rb_define_module_function(mNetCDF, "nc_inq_filter_avail", rb_nc_inq_filter_avail, 2);
|
|
540
|
+
#endif
|
|
541
|
+
|
|
542
|
+
#ifdef HAVE_NC_DEF_VAR_QUANTIZE
|
|
543
|
+
rb_define_module_function(mNetCDF, "nc_def_var_quantize", rb_nc_def_var_quantize, 4);
|
|
544
|
+
#endif
|
|
545
|
+
#ifdef HAVE_NC_INQ_VAR_QUANTIZE
|
|
546
|
+
rb_define_module_function(mNetCDF, "nc_inq_var_quantize", rb_nc_inq_var_quantize, 2);
|
|
547
|
+
#endif
|
|
548
|
+
|
|
549
|
+
rb_define_module_function(mNetCDF, "nc_set_var_chunk_cache", rb_nc_set_var_chunk_cache, 5);
|
|
550
|
+
rb_define_module_function(mNetCDF, "nc_get_var_chunk_cache", rb_nc_get_var_chunk_cache, 2);
|
|
551
|
+
}
|