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.
@@ -0,0 +1,431 @@
1
+ #include "internal.h"
2
+
3
+ /* ---------------------------------------------------------- */
4
+ /* Inquiry */
5
+ /* ---------------------------------------------------------- */
6
+
7
+ static VALUE
8
+ rb_nc_inq_attname (VALUE self, VALUE rncid, VALUE rvarid, VALUE rattnum)
9
+ {
10
+ char name[NC_MAX_NAME + 1];
11
+
12
+ NC_CHECK(nc_inq_attname(NUM2INT(rncid), NUM2INT(rvarid), NUM2INT(rattnum), name));
13
+ return rb_utf8_str_new_cstr(name);
14
+ }
15
+
16
+ static VALUE
17
+ rb_nc_inq_attid (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
18
+ {
19
+ int attnum, st;
20
+
21
+ st = nc_inq_attid(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &attnum);
22
+ if ( st == NC_ENOTATT ) {
23
+ return Qnil;
24
+ }
25
+ if ( st != NC_NOERR ) {
26
+ nc_raise(st);
27
+ }
28
+ return INT2NUM(attnum);
29
+ }
30
+
31
+ static VALUE
32
+ rb_nc_inq_att (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
33
+ {
34
+ nc_type xtype;
35
+ size_t len;
36
+
37
+ NC_CHECK(nc_inq_att(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &xtype, &len));
38
+ return rb_ary_new_from_args(2, INT2NUM(xtype), SIZET2NUM(len));
39
+ }
40
+
41
+ static VALUE
42
+ rb_nc_inq_atttype (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
43
+ {
44
+ nc_type xtype;
45
+
46
+ NC_CHECK(nc_inq_atttype(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &xtype));
47
+ return INT2NUM(xtype);
48
+ }
49
+
50
+ static VALUE
51
+ rb_nc_inq_attlen (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
52
+ {
53
+ size_t len;
54
+
55
+ NC_CHECK(nc_inq_attlen(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &len));
56
+ return SIZET2NUM(len);
57
+ }
58
+
59
+ static VALUE
60
+ rb_nc_rename_att (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname, VALUE rnewname)
61
+ {
62
+ NC_CHECK(nc_rename_att(NUM2INT(rncid), NUM2INT(rvarid),
63
+ StringValueCStr(rname), StringValueCStr(rnewname)));
64
+ return Qnil;
65
+ }
66
+
67
+ static VALUE
68
+ rb_nc_del_att (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
69
+ {
70
+ NC_CHECK(nc_del_att(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname)));
71
+ return Qnil;
72
+ }
73
+
74
+ static VALUE
75
+ rb_nc_copy_att (VALUE self, VALUE rncid_in, VALUE rvarid_in, VALUE rname,
76
+ VALUE rncid_out, VALUE rvarid_out)
77
+ {
78
+ NC_CHECK(nc_copy_att(NUM2INT(rncid_in), NUM2INT(rvarid_in), StringValueCStr(rname),
79
+ NUM2INT(rncid_out), NUM2INT(rvarid_out)));
80
+ return Qnil;
81
+ }
82
+
83
+ /* ---------------------------------------------------------- */
84
+ /* Typed put / get */
85
+ /* ---------------------------------------------------------- */
86
+
87
+ static inline VALUE
88
+ att_value_to_ary (VALUE rvalue)
89
+ {
90
+ if ( RB_TYPE_P(rvalue, T_ARRAY) ) {
91
+ return rvalue;
92
+ }
93
+ return rb_ary_new_from_args(1, rvalue);
94
+ }
95
+
96
+ static VALUE
97
+ rb_nc_put_att_text (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname, VALUE rtext)
98
+ {
99
+ StringValue(rtext);
100
+ NC_CHECK(nc_put_att_text(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname),
101
+ (size_t) RSTRING_LEN(rtext), RSTRING_PTR(rtext)));
102
+ return Qnil;
103
+ }
104
+
105
+ static VALUE
106
+ rb_nc_get_att_text (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
107
+ {
108
+ VALUE out;
109
+ size_t len;
110
+
111
+ NC_CHECK(nc_inq_attlen(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &len));
112
+ /* Text comes back as UTF-8, NC_STRING's encoding too: netCDF has no
113
+ other, and CF attributes are text in practice. */
114
+ out = rb_str_buf_new((long) len);
115
+ rb_str_set_len(out, (long) len);
116
+ rb_enc_associate(out, rb_utf8_encoding());
117
+ NC_CHECK(nc_get_att_text(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname),
118
+ RSTRING_PTR(out)));
119
+ return out;
120
+ }
121
+
122
+ /* As in C, `xtype` is the attribute's type on disk and the suffix names
123
+ the type of the values in memory; libnetcdf converts between them. */
124
+ #define DEFINE_ATT_NUM(suffix, ctype, num2c, c2num) \
125
+ static VALUE \
126
+ rb_nc_put_att_##suffix (VALUE self, VALUE rncid, VALUE rvarid, \
127
+ VALUE rname, VALUE rxtype, VALUE rvalue) \
128
+ { \
129
+ VALUE rary, vbuf; \
130
+ ctype *buf; \
131
+ long n, i; \
132
+ int st; \
133
+ \
134
+ rary = att_value_to_ary(rvalue); \
135
+ n = RARRAY_LEN(rary); \
136
+ buf = ALLOCV_N(ctype, vbuf, (n > 0 ? n : 1)); \
137
+ for (i=0; i<n; i++) { \
138
+ buf[i] = (ctype) num2c(RARRAY_AREF(rary, i)); \
139
+ } \
140
+ st = nc_put_att_##suffix(NUM2INT(rncid), NUM2INT(rvarid), \
141
+ StringValueCStr(rname), \
142
+ NUM2INT(rxtype), (size_t) n, buf); \
143
+ ALLOCV_END(vbuf); \
144
+ if ( st != NC_NOERR ) { \
145
+ nc_raise(st); \
146
+ } \
147
+ return Qnil; \
148
+ } \
149
+ \
150
+ static VALUE \
151
+ rb_nc_get_att_##suffix (VALUE self, VALUE rncid, VALUE rvarid, \
152
+ VALUE rname) \
153
+ { \
154
+ VALUE out; \
155
+ ctype *buf; \
156
+ size_t len, i; \
157
+ int st; \
158
+ \
159
+ NC_CHECK(nc_inq_attlen(NUM2INT(rncid), NUM2INT(rvarid), \
160
+ StringValueCStr(rname), &len)); \
161
+ buf = ALLOC_N(ctype, (len > 0 ? len : 1)); \
162
+ st = nc_get_att_##suffix(NUM2INT(rncid), NUM2INT(rvarid), \
163
+ StringValueCStr(rname), buf); \
164
+ if ( st != NC_NOERR ) { \
165
+ xfree(buf); \
166
+ nc_raise(st); \
167
+ } \
168
+ out = rb_ary_new_capa((long) len); \
169
+ for (i=0; i<len; i++) { \
170
+ rb_ary_push(out, c2num(buf[i])); \
171
+ } \
172
+ xfree(buf); \
173
+ return out; \
174
+ }
175
+
176
+ DEFINE_ATT_NUM(schar, signed char, num_to_schar, INT2NUM)
177
+ DEFINE_ATT_NUM(uchar, unsigned char, num_to_uchar, UINT2NUM)
178
+ DEFINE_ATT_NUM(short, short, num_to_short, INT2NUM)
179
+ DEFINE_ATT_NUM(ushort, unsigned short, num_to_ushort, UINT2NUM)
180
+ DEFINE_ATT_NUM(int, int, NUM2INT, INT2NUM)
181
+ DEFINE_ATT_NUM(uint, unsigned int, num_to_uint, UINT2NUM)
182
+ DEFINE_ATT_NUM(longlong, long long, NUM2LL, LL2NUM)
183
+ DEFINE_ATT_NUM(ulonglong, unsigned long long, num_to_ulonglong, ULL2NUM)
184
+ DEFINE_ATT_NUM(float, float, NUM2DBL, DBL2NUM)
185
+ DEFINE_ATT_NUM(double, double, NUM2DBL, DBL2NUM)
186
+
187
+ static VALUE
188
+ rb_nc_put_att_string (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname, VALUE rvalue)
189
+ {
190
+ VALUE rary, rstr, vptrs;
191
+ char **ptrs;
192
+ long n, i;
193
+ int st;
194
+
195
+ rary = att_value_to_ary(rvalue);
196
+ n = RARRAY_LEN(rary);
197
+ ptrs = ALLOCV_N(char *, vptrs, n > 0 ? n : 1);
198
+ for (i=0; i<n; i++) {
199
+ rstr = RARRAY_AREF(rary, i);
200
+ if ( ! RB_TYPE_P(rstr, T_STRING) ) {
201
+ rb_raise(rb_eTypeError, "NC_STRING attribute elements must all be Strings");
202
+ }
203
+ ptrs[i] = StringValueCStr(rstr);
204
+ }
205
+ st = nc_put_att_string(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname),
206
+ (size_t) n, (const char **) ptrs);
207
+ ALLOCV_END(vptrs);
208
+ if ( st != NC_NOERR ) {
209
+ nc_raise(st);
210
+ }
211
+ return Qnil;
212
+ }
213
+
214
+ static VALUE
215
+ rb_nc_get_att_string (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
216
+ {
217
+ VALUE out;
218
+ char **ptrs;
219
+ size_t len, i;
220
+ int st;
221
+
222
+ NC_CHECK(nc_inq_attlen(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &len));
223
+ ptrs = ALLOC_N(char *, len > 0 ? len : 1);
224
+ for (i=0; i<len; i++) {
225
+ ptrs[i] = NULL;
226
+ }
227
+ st = nc_get_att_string(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), ptrs);
228
+ if ( st != NC_NOERR ) {
229
+ xfree(ptrs);
230
+ nc_raise(st);
231
+ }
232
+ out = rb_ary_new_capa((long) len);
233
+ for (i=0; i<len; i++) {
234
+ rb_ary_push(out, rb_utf8_str_new_cstr(ptrs[i] ? ptrs[i] : ""));
235
+ }
236
+ nc_free_string(len, ptrs);
237
+ xfree(ptrs);
238
+ return out;
239
+ }
240
+
241
+ /* ---------------------------------------------------------- */
242
+ /* Smart generic put / get */
243
+ /* ---------------------------------------------------------- */
244
+
245
+ /* The narrowest of NC_INT, NC_INT64 and NC_UINT64 that holds the Integer
246
+ `v`; NC_UINT64 only for a value past 2**63 - 1. Sized by bit count so
247
+ that no conversion can raise before the type is known. */
248
+ static nc_type
249
+ infer_int_xtype (VALUE v)
250
+ {
251
+ size_t bits;
252
+ long l;
253
+ int nlz;
254
+ bool pow2;
255
+
256
+ if ( FIXNUM_P(v) ) {
257
+ l = FIX2LONG(v);
258
+ return ( l >= INT_MIN && l <= INT_MAX ) ? NC_INT : NC_INT64;
259
+ }
260
+ bits = rb_absint_size(v, &nlz) * CHAR_BIT - (size_t) nlz;
261
+ if ( RBIGNUM_NEGATIVE_P(v) ) {
262
+ /* |v| up to 2**31 fits int, up to 2**63 long long */
263
+ pow2 = rb_absint_singlebit_p(v);
264
+ if ( bits <= 31 || ( bits == 32 && pow2 ) ) {
265
+ return NC_INT;
266
+ }
267
+ if ( bits <= 63 || ( bits == 64 && pow2 ) ) {
268
+ return NC_INT64;
269
+ }
270
+ }
271
+ else {
272
+ if ( bits <= 31 ) {
273
+ return NC_INT;
274
+ }
275
+ if ( bits <= 63 ) {
276
+ return NC_INT64;
277
+ }
278
+ if ( bits <= 64 ) {
279
+ return NC_UINT64;
280
+ }
281
+ }
282
+ rb_raise(rb_eRangeError, "integer %"PRIsVALUE" does not fit a 64-bit netCDF type", v);
283
+ }
284
+
285
+ static bool
286
+ is_int_negative (VALUE v)
287
+ {
288
+ return FIXNUM_P(v) ? FIX2LONG(v) < 0 : RBIGNUM_NEGATIVE_P(v);
289
+ }
290
+
291
+ static VALUE
292
+ rb_nc_put_att (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname, VALUE rval)
293
+ {
294
+ VALUE relem;
295
+ long n, i;
296
+ bool any_float, any_negative;
297
+ nc_type int_xt, xt;
298
+
299
+ if ( RB_TYPE_P(rval, T_STRING) ) {
300
+ return rb_nc_put_att_text(self, rncid, rvarid, rname, rval);
301
+ }
302
+ if ( RB_TYPE_P(rval, T_FIXNUM) || RB_TYPE_P(rval, T_BIGNUM) ) {
303
+ switch ( infer_int_xtype(rval) ) {
304
+ case NC_INT: return rb_nc_put_att_int(self, rncid, rvarid, rname, INT2NUM(NC_INT), rval);
305
+ case NC_INT64: return rb_nc_put_att_longlong(self, rncid, rvarid, rname, INT2NUM(NC_INT64), rval);
306
+ default: return rb_nc_put_att_ulonglong(self, rncid, rvarid, rname, INT2NUM(NC_UINT64), rval);
307
+ }
308
+ }
309
+ if ( RB_TYPE_P(rval, T_FLOAT) ) {
310
+ return rb_nc_put_att_double(self, rncid, rvarid, rname, INT2NUM(NC_DOUBLE), rval);
311
+ }
312
+ if ( RB_TYPE_P(rval, T_ARRAY) ) {
313
+ n = RARRAY_LEN(rval);
314
+ any_float = false;
315
+ any_negative = false;
316
+ int_xt = NC_INT; /* widened NC_INT -> NC_INT64 -> NC_UINT64 */
317
+ for (i=0; i<n; i++) {
318
+ relem = RARRAY_AREF(rval, i);
319
+ if ( RB_TYPE_P(relem, T_FLOAT) ) {
320
+ any_float = true;
321
+ }
322
+ else if ( RB_TYPE_P(relem, T_FIXNUM) || RB_TYPE_P(relem, T_BIGNUM) ) {
323
+ xt = infer_int_xtype(relem);
324
+ if ( xt == NC_UINT64 || ( xt == NC_INT64 && int_xt == NC_INT ) ) {
325
+ int_xt = xt;
326
+ }
327
+ if ( is_int_negative(relem) ) {
328
+ any_negative = true;
329
+ }
330
+ }
331
+ else {
332
+ rb_raise(rb_eTypeError, "unsupported element type in attribute array");
333
+ }
334
+ }
335
+ if ( any_float ) {
336
+ return rb_nc_put_att_double(self, rncid, rvarid, rname, INT2NUM(NC_DOUBLE), rval);
337
+ }
338
+ switch ( int_xt ) {
339
+ case NC_INT: return rb_nc_put_att_int(self, rncid, rvarid, rname, INT2NUM(NC_INT), rval);
340
+ case NC_INT64: return rb_nc_put_att_longlong(self, rncid, rvarid, rname, INT2NUM(NC_INT64), rval);
341
+ default:
342
+ if ( any_negative ) {
343
+ rb_raise(rb_eRangeError, "no netCDF integer type holds both a value past 2**63 - 1 "
344
+ "and a negative one");
345
+ }
346
+ return rb_nc_put_att_ulonglong(self, rncid, rvarid, rname, INT2NUM(NC_UINT64), rval);
347
+ }
348
+ }
349
+ rb_raise(rb_eTypeError, "unsupported attribute value type");
350
+ }
351
+
352
+ static VALUE
353
+ rb_nc_get_att (VALUE self, VALUE rncid, VALUE rvarid, VALUE rname)
354
+ {
355
+ VALUE out;
356
+ nc_type xt;
357
+ size_t len;
358
+
359
+ NC_CHECK(nc_inq_att(NUM2INT(rncid), NUM2INT(rvarid), StringValueCStr(rname), &xt, &len));
360
+
361
+ if ( xt == NC_CHAR ) {
362
+ return rb_nc_get_att_text(self, rncid, rvarid, rname);
363
+ }
364
+ if ( xt == NC_STRING ) {
365
+ out = rb_nc_get_att_string(self, rncid, rvarid, rname);
366
+ if ( len == 1 ) {
367
+ return rb_ary_entry(out, 0);
368
+ }
369
+ return out;
370
+ }
371
+
372
+ switch ( xt ) {
373
+ case NC_BYTE: out = rb_nc_get_att_schar(self, rncid, rvarid, rname); break;
374
+ case NC_UBYTE: out = rb_nc_get_att_uchar(self, rncid, rvarid, rname); break;
375
+ case NC_SHORT: out = rb_nc_get_att_short(self, rncid, rvarid, rname); break;
376
+ case NC_USHORT: out = rb_nc_get_att_ushort(self, rncid, rvarid, rname); break;
377
+ case NC_INT: out = rb_nc_get_att_int(self, rncid, rvarid, rname); break;
378
+ case NC_UINT: out = rb_nc_get_att_uint(self, rncid, rvarid, rname); break;
379
+ case NC_INT64: out = rb_nc_get_att_longlong(self, rncid, rvarid, rname); break;
380
+ case NC_UINT64: out = rb_nc_get_att_ulonglong(self, rncid, rvarid, rname); break;
381
+ case NC_FLOAT: out = rb_nc_get_att_float(self, rncid, rvarid, rname); break;
382
+ case NC_DOUBLE: out = rb_nc_get_att_double(self, rncid, rvarid, rname); break;
383
+ default: rb_raise(rb_eNotImpError, "unsupported attribute type: %d", xt);
384
+ }
385
+
386
+ if ( len == 1 ) {
387
+ return RARRAY_AREF(out, 0);
388
+ }
389
+ return out;
390
+ }
391
+
392
+ void
393
+ init_nc_att (void)
394
+ {
395
+ rb_define_module_function(mNetCDF, "nc_inq_attname", rb_nc_inq_attname, 3);
396
+ rb_define_module_function(mNetCDF, "nc_inq_attid", rb_nc_inq_attid, 3);
397
+ rb_define_module_function(mNetCDF, "nc_inq_att", rb_nc_inq_att, 3);
398
+ rb_define_module_function(mNetCDF, "nc_inq_atttype", rb_nc_inq_atttype, 3);
399
+ rb_define_module_function(mNetCDF, "nc_inq_attlen", rb_nc_inq_attlen, 3);
400
+ rb_define_module_function(mNetCDF, "nc_rename_att", rb_nc_rename_att, 4);
401
+ rb_define_module_function(mNetCDF, "nc_del_att", rb_nc_del_att, 3);
402
+ rb_define_module_function(mNetCDF, "nc_copy_att", rb_nc_copy_att, 5);
403
+
404
+ rb_define_module_function(mNetCDF, "nc_put_att_text", rb_nc_put_att_text, 4);
405
+ rb_define_module_function(mNetCDF, "nc_get_att_text", rb_nc_get_att_text, 3);
406
+ rb_define_module_function(mNetCDF, "nc_put_att_schar", rb_nc_put_att_schar, 5);
407
+ rb_define_module_function(mNetCDF, "nc_get_att_schar", rb_nc_get_att_schar, 3);
408
+ rb_define_module_function(mNetCDF, "nc_put_att_uchar", rb_nc_put_att_uchar, 5);
409
+ rb_define_module_function(mNetCDF, "nc_get_att_uchar", rb_nc_get_att_uchar, 3);
410
+ rb_define_module_function(mNetCDF, "nc_put_att_short", rb_nc_put_att_short, 5);
411
+ rb_define_module_function(mNetCDF, "nc_get_att_short", rb_nc_get_att_short, 3);
412
+ rb_define_module_function(mNetCDF, "nc_put_att_ushort", rb_nc_put_att_ushort, 5);
413
+ rb_define_module_function(mNetCDF, "nc_get_att_ushort", rb_nc_get_att_ushort, 3);
414
+ rb_define_module_function(mNetCDF, "nc_put_att_int", rb_nc_put_att_int, 5);
415
+ rb_define_module_function(mNetCDF, "nc_get_att_int", rb_nc_get_att_int, 3);
416
+ rb_define_module_function(mNetCDF, "nc_put_att_uint", rb_nc_put_att_uint, 5);
417
+ rb_define_module_function(mNetCDF, "nc_get_att_uint", rb_nc_get_att_uint, 3);
418
+ rb_define_module_function(mNetCDF, "nc_put_att_longlong", rb_nc_put_att_longlong, 5);
419
+ rb_define_module_function(mNetCDF, "nc_get_att_longlong", rb_nc_get_att_longlong, 3);
420
+ rb_define_module_function(mNetCDF, "nc_put_att_ulonglong", rb_nc_put_att_ulonglong, 5);
421
+ rb_define_module_function(mNetCDF, "nc_get_att_ulonglong", rb_nc_get_att_ulonglong, 3);
422
+ rb_define_module_function(mNetCDF, "nc_put_att_float", rb_nc_put_att_float, 5);
423
+ rb_define_module_function(mNetCDF, "nc_get_att_float", rb_nc_get_att_float, 3);
424
+ rb_define_module_function(mNetCDF, "nc_put_att_double", rb_nc_put_att_double, 5);
425
+ rb_define_module_function(mNetCDF, "nc_get_att_double", rb_nc_get_att_double, 3);
426
+ rb_define_module_function(mNetCDF, "nc_put_att_string", rb_nc_put_att_string, 4);
427
+ rb_define_module_function(mNetCDF, "nc_get_att_string", rb_nc_get_att_string, 3);
428
+
429
+ rb_define_module_function(mNetCDF, "nc_put_att", rb_nc_put_att, 4);
430
+ rb_define_module_function(mNetCDF, "nc_get_att", rb_nc_get_att, 3);
431
+ }
@@ -0,0 +1,74 @@
1
+ #include "internal.h"
2
+
3
+ static VALUE
4
+ rb_nc_def_dim (VALUE self, VALUE rncid, VALUE rname, VALUE rlen)
5
+ {
6
+ int dimid;
7
+ size_t len;
8
+
9
+ len = NUM2SIZET(rlen);
10
+ NC_CHECK(nc_def_dim(NUM2INT(rncid), StringValueCStr(rname), len, &dimid));
11
+ return INT2NUM(dimid);
12
+ }
13
+
14
+ /* returns dimid, or nil when the name does not exist */
15
+ static VALUE
16
+ rb_nc_inq_dimid (VALUE self, VALUE rncid, VALUE rname)
17
+ {
18
+ int dimid, st;
19
+
20
+ st = nc_inq_dimid(NUM2INT(rncid), StringValueCStr(rname), &dimid);
21
+ if ( st == NC_EBADDIM ) {
22
+ return Qnil;
23
+ }
24
+ if ( st != NC_NOERR ) {
25
+ nc_raise(st);
26
+ }
27
+ return INT2NUM(dimid);
28
+ }
29
+
30
+ static VALUE
31
+ rb_nc_inq_dim (VALUE self, VALUE rncid, VALUE rdimid)
32
+ {
33
+ char name[NC_MAX_NAME + 1];
34
+ size_t len;
35
+
36
+ NC_CHECK(nc_inq_dim(NUM2INT(rncid), NUM2INT(rdimid), name, &len));
37
+ return rb_ary_new_from_args(2, rb_utf8_str_new_cstr(name), SIZET2NUM(len));
38
+ }
39
+
40
+ static VALUE
41
+ rb_nc_inq_dimname (VALUE self, VALUE rncid, VALUE rdimid)
42
+ {
43
+ char name[NC_MAX_NAME + 1];
44
+
45
+ NC_CHECK(nc_inq_dimname(NUM2INT(rncid), NUM2INT(rdimid), name));
46
+ return rb_utf8_str_new_cstr(name);
47
+ }
48
+
49
+ static VALUE
50
+ rb_nc_inq_dimlen (VALUE self, VALUE rncid, VALUE rdimid)
51
+ {
52
+ size_t len;
53
+
54
+ NC_CHECK(nc_inq_dimlen(NUM2INT(rncid), NUM2INT(rdimid), &len));
55
+ return SIZET2NUM(len);
56
+ }
57
+
58
+ static VALUE
59
+ rb_nc_rename_dim (VALUE self, VALUE rncid, VALUE rdimid, VALUE rname)
60
+ {
61
+ NC_CHECK(nc_rename_dim(NUM2INT(rncid), NUM2INT(rdimid), StringValueCStr(rname)));
62
+ return Qnil;
63
+ }
64
+
65
+ void
66
+ init_nc_dim (void)
67
+ {
68
+ rb_define_module_function(mNetCDF, "nc_def_dim", rb_nc_def_dim, 3);
69
+ rb_define_module_function(mNetCDF, "nc_inq_dimid", rb_nc_inq_dimid, 2);
70
+ rb_define_module_function(mNetCDF, "nc_inq_dim", rb_nc_inq_dim, 2);
71
+ rb_define_module_function(mNetCDF, "nc_inq_dimname", rb_nc_inq_dimname, 2);
72
+ rb_define_module_function(mNetCDF, "nc_inq_dimlen", rb_nc_inq_dimlen, 2);
73
+ rb_define_module_function(mNetCDF, "nc_rename_dim", rb_nc_rename_dim, 3);
74
+ }