netcdf-nmatrix 0.8.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/.gitignore +5 -0
- data/ChangeLog +396 -0
- data/Gemfile +4 -0
- data/INSTALL +62 -0
- data/LICENSE.txt +59 -0
- data/README.md +8 -0
- data/Rakefile +2 -0
- data/ToDo +1 -0
- data/demo/README +14 -0
- data/demo/demo1-create-alt.rb +35 -0
- data/demo/demo1-create.rb +35 -0
- data/demo/demo2-graphic.rb +67 -0
- data/demo/demo3-ncepclim.rb +178 -0
- data/demo/demo4-copy.rb +32 -0
- data/doc/README_JP.txt +152 -0
- data/doc/Ref_man.html +1482 -0
- data/doc/Ref_man.rd +1312 -0
- data/doc/Ref_man_jp.html +1445 -0
- data/doc/Ref_man_jp.rd +1276 -0
- data/doc/to_html +7 -0
- data/extconf.rb +173 -0
- data/lib/netcdf.rb +804 -0
- data/lib/netcdf_miss.rb +203 -0
- data/lib/version.rb +5 -0
- data/netcdfraw.c +4780 -0
- data/ruby-netcdf.gemspec +33 -0
- data/test/aref_aset.rb +37 -0
- data/test/char_var.rb +25 -0
- data/test/clone.rb +54 -0
- data/test/create_tmp.rb +15 -0
- data/test/def_var_with_dim.rb +14 -0
- data/test/factor_offset.rb +53 -0
- data/test/putatt.cdl +23 -0
- data/test/putatt.rb +56 -0
- data/test/test.cdl +31 -0
- data/test/test.rb +195 -0
- data/test/type.rb +13 -0
- metadata +120 -0
data/lib/netcdf_miss.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require "numru/netcdf"
|
2
|
+
require "narray_miss"
|
3
|
+
|
4
|
+
module NumRu
|
5
|
+
|
6
|
+
class NetCDFVar
|
7
|
+
|
8
|
+
def get_with_miss(*args)
|
9
|
+
__interpret_missing_params if !defined?(@missval)
|
10
|
+
data = simple_get(*args)
|
11
|
+
if @vmin || @vmax
|
12
|
+
if @vmin
|
13
|
+
mask = (data >= @vmin)
|
14
|
+
mask = mask.and(data <= @vmax) if @vmax
|
15
|
+
else
|
16
|
+
mask = (data <= @vmax)
|
17
|
+
end
|
18
|
+
data = NArrayMiss.to_nam(data, mask)
|
19
|
+
elsif @missval # only missing_value is present.
|
20
|
+
mask = (data.ne(@missval))
|
21
|
+
data = NArrayMiss.to_nam(data, mask)
|
22
|
+
end
|
23
|
+
data
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_with_miss_and_scaling(*args)
|
27
|
+
__interpret_missing_params if !defined?(@missval)
|
28
|
+
data = simple_get(*args)
|
29
|
+
if @vmin || @vmax
|
30
|
+
if @vmin
|
31
|
+
mask = (data >= @vmin)
|
32
|
+
mask = mask.and(data <= @vmax) if @vmax
|
33
|
+
else
|
34
|
+
mask = (data <= @vmax)
|
35
|
+
end
|
36
|
+
data = NArrayMiss.to_nam(data, mask)
|
37
|
+
elsif @missval # only missing_value is present.
|
38
|
+
mask = (data.ne(@missval))
|
39
|
+
data = NArrayMiss.to_nam(data, mask)
|
40
|
+
end
|
41
|
+
data = unpack( data )
|
42
|
+
data
|
43
|
+
end
|
44
|
+
|
45
|
+
def put_with_miss(data, *args)
|
46
|
+
if data.is_a?( NArrayMiss )
|
47
|
+
__interpret_missing_params if !defined?(@missval)
|
48
|
+
if @missval
|
49
|
+
simple_put(data.to_na(@missval), *args)
|
50
|
+
else
|
51
|
+
simple_put(data.to_na, *args)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
simple_put(data, *args)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def put_with_miss_and_scaling(data, *args)
|
59
|
+
if data.is_a?( NArrayMiss )
|
60
|
+
__interpret_missing_params if !defined?(@missval)
|
61
|
+
if @missval
|
62
|
+
data = pack( data )
|
63
|
+
data = data.to_na(@missval)
|
64
|
+
else
|
65
|
+
data = pack( data )
|
66
|
+
data = data.to_na
|
67
|
+
end
|
68
|
+
simple_put(data, *args)
|
69
|
+
else
|
70
|
+
scaled_put(data, *args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
######### private ##########
|
75
|
+
|
76
|
+
def __interpret_missing_params
|
77
|
+
# Interprets the specification of missing data,
|
78
|
+
# either by valid_range, (valid_min and/or valid_max), or missing_value.
|
79
|
+
# (unlike the NetCDF User's guide (NUG), missing_value is interpreted,
|
80
|
+
# but valid_* has a higher precedence.)
|
81
|
+
# Always sets @missval whether missing_value is defined or not,
|
82
|
+
# since it will be used as a fill value for data missing.
|
83
|
+
#
|
84
|
+
@vmin = att('valid_min')
|
85
|
+
@vmin = @vmin.get if @vmin # kept in a NArray(size==1) to consv type
|
86
|
+
@vmax = att('valid_max')
|
87
|
+
@vmax = @vmax.get if @vmax # kept in a NArray(size==1) to consv type
|
88
|
+
vrange = att('valid_range')
|
89
|
+
vrange = vrange.get if vrange
|
90
|
+
if vrange
|
91
|
+
vrange.sort!
|
92
|
+
@vmin = vrange[0..0] # kept in... (same)
|
93
|
+
@vmax = vrange[-1..-1] # kept in... (same)
|
94
|
+
end
|
95
|
+
@missval = att('missing_value') || att('_FillValue')
|
96
|
+
@missval = @missval.get if @missval # kept in... (same)
|
97
|
+
|
98
|
+
sf = att('scale_factor')
|
99
|
+
ao = att('add_offset')
|
100
|
+
if ( sf || ao )
|
101
|
+
## Both NUG & CF conventions requires to specify the valid
|
102
|
+
## range with respect to the external (i.e. packed) values.
|
103
|
+
## However, some conventions require specification
|
104
|
+
## with respect to unpacked values. The following
|
105
|
+
## is to support such cases as well:
|
106
|
+
thres_tp = [ self.typecode, NArray::LINT ].max
|
107
|
+
@missval = pack(@missval) if @missval && @missval.typecode > thres_tp
|
108
|
+
@vmin = pack(@vmin) if @vmin && @vmin.typecode > thres_tp
|
109
|
+
@vmax = pack(@vmax) if @vmax && @vmax.typecode > thres_tp
|
110
|
+
end
|
111
|
+
|
112
|
+
if @missval
|
113
|
+
if @vmin && @vmax
|
114
|
+
if @vmin[0] <= @missval[0] && @missval[0] <= @vmax[0]
|
115
|
+
warn "WARNING: missing_value #{@missval[0]} is in the valid range #{@vmin[0]}..#{@vmax[0]} --> will be ignored (#{__FILE__}:#{__LINE__})"
|
116
|
+
end
|
117
|
+
else
|
118
|
+
if @vmin && @missval[0] >= @vmin[0]
|
119
|
+
warn "WARNING: missing_value #{@missval[0]} >= valid min #{@vmin[0]} --> will be ignored (#{__FILE__}:#{__LINE__})"
|
120
|
+
elsif @vmax && @missval[0] <= @vmax[0]
|
121
|
+
warn "WARNING: missing_value #{@missval[0]} <= valid min #{@vmin[0]} --> will be ignored (#{__FILE__}:#{__LINE__})"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
else
|
125
|
+
realtc = NArray::SFLOAT
|
126
|
+
if @vmin
|
127
|
+
if @vmin[0] >= 0
|
128
|
+
@missval = ( @vmin.typecode>=realtc ? 0.99*@vmin : @vmin-1 )
|
129
|
+
else
|
130
|
+
@missval = ( @vmin.typecode>=realtc ? 1.01*@vmin : @vmin-1 )
|
131
|
+
end
|
132
|
+
elsif @vmax
|
133
|
+
if @vmax[0] >= 0
|
134
|
+
@missval = ( @vmax.typecode>=realtc ? 1.01*@vmax : @vmax+1 )
|
135
|
+
else
|
136
|
+
@missval = ( @vmax.typecode>=realtc ? 0.99*@vmax : @vmax+1 )
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
private :__interpret_missing_params
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
if $0 == __FILE__
|
150
|
+
include NumRu
|
151
|
+
|
152
|
+
filename = "tmp.nc"
|
153
|
+
print "creating ",filename,"...\n"
|
154
|
+
file=NetCDF.create(filename)
|
155
|
+
nx = 10
|
156
|
+
dimx = file.def_dim("x",nx)
|
157
|
+
xf = file.def_var("xf","sfloat",[dimx])
|
158
|
+
xfn = file.def_var("xfn","sfloat",[dimx])
|
159
|
+
xf.put_att("valid_range",[-1e12,1e12])
|
160
|
+
f = 10 ** (2*NArray.sfloat(nx).indgen!)
|
161
|
+
xr = file.def_var("xr","sint",[dimx])
|
162
|
+
xr.put_att("valid_max",[0.5])
|
163
|
+
xr.put_att("scale_factor",1e-4)
|
164
|
+
xr.put_att("add_offset",0.5)
|
165
|
+
xr2 = file.def_var("xr2","sint",[dimx])
|
166
|
+
xr2.put_att("valid_max",NArray.sint(1).fill!(1000))
|
167
|
+
xr2.put_att("scale_factor",1e-4)
|
168
|
+
xr2.put_att("add_offset",0.5)
|
169
|
+
r = NArray.sfloat(nx).indgen!/nx
|
170
|
+
file.enddef
|
171
|
+
xf.put(f)
|
172
|
+
xfn.put(f)
|
173
|
+
xr.scaled_put(r)
|
174
|
+
file.close
|
175
|
+
|
176
|
+
file = NetCDF.open(filename,'r+')
|
177
|
+
xf = file.var('xf')
|
178
|
+
xfn = file.var('xfn')
|
179
|
+
p "f0"
|
180
|
+
xf.get.each{|v| print "#{v} "} ; print "\n"
|
181
|
+
p( 'f1', nam = xf.get_with_miss )
|
182
|
+
def xf.get(*args); get_with_miss(*args); end
|
183
|
+
p( 'f12', xf[2..-3].to_na )
|
184
|
+
p( 'fn10', xfn.get_with_miss )
|
185
|
+
p( 'fn11', xfn.get_with_miss_and_scaling )
|
186
|
+
nam.invalidation([0,1])
|
187
|
+
p 'f2', nam
|
188
|
+
xf.put_with_miss(nam)
|
189
|
+
p( 'f3', xf.get_with_miss )
|
190
|
+
xr = file.var('xr')
|
191
|
+
p "r0"
|
192
|
+
xr.simple_get.each{|v| print "#{v} "} ; print "\n"
|
193
|
+
p( 'r1', xr.get_with_miss_and_scaling )
|
194
|
+
def xr.get(*args); get_with_miss_and_scaling(*args); end
|
195
|
+
def xr.put(*args); put_with_miss_and_scaling(*args); end
|
196
|
+
#xr[0..3] = xr[0..3]*10
|
197
|
+
p( 'r2', xr.get_with_miss_and_scaling )
|
198
|
+
p 'r',r
|
199
|
+
xr2.put_with_miss_and_scaling(r)
|
200
|
+
p 'xr2',xr2.get_with_miss_and_scaling
|
201
|
+
file.close
|
202
|
+
print "** ncdump tmp.nc **\n", `ncdump tmp.nc`
|
203
|
+
end
|
data/lib/version.rb
ADDED
data/netcdfraw.c
ADDED
@@ -0,0 +1,4780 @@
|
|
1
|
+
#include<stdio.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
#define HAVE_RB_ARRAY_CONST_PTR
|
4
|
+
#include "nmatrix.h"
|
5
|
+
#include "nm_memory.h"
|
6
|
+
#include<netcdf.h>
|
7
|
+
#include<string.h>
|
8
|
+
|
9
|
+
#define RGET_CLASS(class_over, x) (rb_const_get(class_over, rb_intern(x)))
|
10
|
+
#define RGET_CLASS_TOP(x) (RGET_CLASS(rb_cObject, x))
|
11
|
+
#define RFCALL_10_ON(obj, name) (rb_funcall(obj, rb_intern(name), 0))
|
12
|
+
#define RFCALL_11_ON(obj, name, arg1) (rb_funcall(obj, rb_intern(name), 1, arg1))
|
13
|
+
#define RFCALL_12_ON(obj, name, arg1, arg2) (rb_funcall(obj, rb_intern(name), 2, arg1, arg2))
|
14
|
+
#define CR_STR(c_str)(rb_str_new2(c_str))
|
15
|
+
#define CR_PSTR(c_str)(rb_p(CR_STR(c_str)))
|
16
|
+
#define CR_SYM(c_str)(ID2SYM(rb_intern(c_str)))
|
17
|
+
|
18
|
+
/* When ruby-netcdf was based on narray it
|
19
|
+
* used column-major (Fortran) ordering for all indices.
|
20
|
+
* Now it uses nmatrix we have switched to row-major
|
21
|
+
* but we provide the COLMAJOR macro in case someone ever
|
22
|
+
* wants to reverse this */
|
23
|
+
#define ROWMAJOR(length, i) i
|
24
|
+
#define COLMAJOR(length, i) length-1-i
|
25
|
+
#define RCMAJOR(length, i) ROWMAJOR(length, i)
|
26
|
+
|
27
|
+
|
28
|
+
/* for compatibility with ruby 1.6 */
|
29
|
+
#ifndef RSTRING_PTR
|
30
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
31
|
+
#endif
|
32
|
+
#ifndef RSTRING_LEN
|
33
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
34
|
+
#endif
|
35
|
+
#ifndef RARRAY_PTR
|
36
|
+
#define RARRAY_PTR(a) (RARRAY(a)->ptr)
|
37
|
+
#endif
|
38
|
+
#ifndef RARRAY_LEN
|
39
|
+
#define RARRAY_LEN(a) (RARRAY(a)->len)
|
40
|
+
#endif
|
41
|
+
#ifndef StringValueCStr
|
42
|
+
#define StringValueCStr(s) STR2CSTR(s)
|
43
|
+
#endif
|
44
|
+
#ifndef SafeStringValue
|
45
|
+
#define SafeStringValue(s) Check_SafeStr(s)
|
46
|
+
#endif
|
47
|
+
|
48
|
+
VALUE cNMatrix;
|
49
|
+
typedef size_t na_shape_t;
|
50
|
+
extern const size_t DTYPE_SIZES[NM_NUM_DTYPES];
|
51
|
+
size_t nm_storage_count_max_elements(const NM_DENSE_STORAGE* storage);
|
52
|
+
|
53
|
+
/* Data to NMatrix */
|
54
|
+
|
55
|
+
/* memcpy(ary->ptr,nc_ptr,na_sizeof[NA_SINT]*ary->total); \ */
|
56
|
+
|
57
|
+
#define C_to_NMatrix(v, nm_type, rank, shape, ptr, typecast)\
|
58
|
+
{\
|
59
|
+
v = nm_make_object(nm_type, rank, shape); \
|
60
|
+
ptr = (typecast)NM_DENSE_ELEMENTS(v); \
|
61
|
+
}
|
62
|
+
#define Cbyte_to_NMatrix(v, rank, shape, up) \
|
63
|
+
C_to_NMatrix(v, "byte", rank, shape, up, unsigned char*)
|
64
|
+
|
65
|
+
#define Csint_to_NMatrix(v, rank, shape, sp) \
|
66
|
+
C_to_NMatrix(v, "int16", rank, shape, sp, short *)
|
67
|
+
|
68
|
+
#define Clint_to_NMatrix(v, rank, shape, lp) \
|
69
|
+
C_to_NMatrix(v, "int32", rank, shape, lp, int *)
|
70
|
+
|
71
|
+
#define Cfloat_to_NMatrix(v, rank, shape, fp) \
|
72
|
+
C_to_NMatrix(v, "float32", rank, shape, fp, float *)
|
73
|
+
|
74
|
+
#define Cdouble_to_NMatrix(v, rank, shape, dp); \
|
75
|
+
C_to_NMatrix(v, "float64", rank, shape, dp, double *)
|
76
|
+
|
77
|
+
/* Array or NMatrix to pointer and length (with no new allocation) */
|
78
|
+
|
79
|
+
#define NMatrix_to_C(obj, nm_type, typecast, ptr)\
|
80
|
+
{\
|
81
|
+
obj = nm_cast_object(obj, nm_type); \
|
82
|
+
ptr = (typecast) NM_DENSE_ELEMENTS(obj); \
|
83
|
+
}
|
84
|
+
#define NMatrix_to_C_len(obj, nm_type, typecast, ptr, len)\
|
85
|
+
{\
|
86
|
+
NMatrix_to_C(obj, nm_type, typecast, ptr);\
|
87
|
+
len = NM_DENSE_COUNT(obj); \
|
88
|
+
}
|
89
|
+
/*len = FIX2INT(rb_funcall(obj, rb_intern("size"), 0)); \*/
|
90
|
+
#define NMatrix_to_C_len_shape(obj, nm_type, typecast, ptr, len, shape)\
|
91
|
+
{\
|
92
|
+
NMatrix_to_C_len(obj, nm_type, typecast, ptr, len);\
|
93
|
+
shape = NM_STORAGE_DENSE(obj)->shape;\
|
94
|
+
}
|
95
|
+
|
96
|
+
#define NMatrix_to_Cfloat_len(obj, ptr, len) \
|
97
|
+
NMatrix_to_C_len(obj, "float32", float *, ptr, len);
|
98
|
+
|
99
|
+
#define NMatrix_to_Cfloat_len_shape(obj, ptr, len, shape) \
|
100
|
+
NMatrix_to_C_len_shape(obj, "float32", float *, ptr, len, shape);
|
101
|
+
|
102
|
+
#define NMatrix_to_Cdouble_len(obj, ptr, len) \
|
103
|
+
NMatrix_to_C_len(obj, "float64", double *, ptr, len);
|
104
|
+
|
105
|
+
#define NMatrix_to_Cdouble_len_shape(obj, ptr, len, shape) \
|
106
|
+
NMatrix_to_C_len_shape(obj, "float64", double *, ptr, len, shape);
|
107
|
+
|
108
|
+
#define NMatrix_to_Cbyte_len(obj, ptr, len) \
|
109
|
+
NMatrix_to_C_len(obj, "byte", unsigned char *, ptr, len);
|
110
|
+
|
111
|
+
#define NMatrix_to_Cbyte_len_shape(obj, ptr, len, shape) \
|
112
|
+
NMatrix_to_C_len_shape(obj, "byte", unsigned char *, ptr, len, shape);
|
113
|
+
|
114
|
+
#define NMatrix_to_Csint_len(obj, ptr, len) \
|
115
|
+
NMatrix_to_C_len(obj, "int16", short *, ptr, len);
|
116
|
+
|
117
|
+
#define NMatrix_to_Csint_len_shape(obj, ptr, len, shape) \
|
118
|
+
NMatrix_to_C_len_shape(obj, "int16", short *, ptr, len, shape);
|
119
|
+
|
120
|
+
#define NMatrix_to_Clint_len(obj, ptr, len) \
|
121
|
+
NMatrix_to_C_len(obj, "int32", int *, ptr, len);
|
122
|
+
|
123
|
+
#define NMatrix_to_Clint_len_shape(obj, ptr, len, shape) \
|
124
|
+
NMatrix_to_C_len_shape(obj, "int32", int *, ptr, len, shape);
|
125
|
+
|
126
|
+
|
127
|
+
/* Array or NMatrix to pointer (with no new allocation) */
|
128
|
+
|
129
|
+
#define NMatrix_to_Cfloat(obj, ptr) \
|
130
|
+
NMatrix_to_C(obj, "float32", float *, ptr);
|
131
|
+
|
132
|
+
#define NMatrix_to_Cdouble(obj, ptr) \
|
133
|
+
NMatrix_to_C(obj, "float64", double *, ptr);
|
134
|
+
|
135
|
+
#define NMatrix_to_Cbyte(obj, ptr) \
|
136
|
+
NMatrix_to_C(obj, "byte", unsigned char *, ptr);
|
137
|
+
|
138
|
+
#define NMatrix_to_Csint(obj, ptr) \
|
139
|
+
NMatrix_to_C(obj, "int16", short *, ptr);
|
140
|
+
|
141
|
+
#define NMatrix_to_Clint(obj, ptr) \
|
142
|
+
NMatrix_to_C(obj, "int32", int *, ptr);
|
143
|
+
|
144
|
+
#define NC_RAISE(status) rb_raise(err_status2class(status),"%s",(nc_strerror(status)))
|
145
|
+
#define NC_RAISE2(status, str) rb_raise(err_status2class(status),"%s (%s)",nc_strerror(status),(str) )
|
146
|
+
|
147
|
+
static VALUE mNumRu = 0;
|
148
|
+
static VALUE cNetCDF;
|
149
|
+
static VALUE cNetCDFDim;
|
150
|
+
static VALUE cNetCDFAtt;
|
151
|
+
static VALUE cNetCDFVar;
|
152
|
+
|
153
|
+
static VALUE rb_eNetcdfError;
|
154
|
+
static VALUE rb_eNetcdfBadid;
|
155
|
+
static VALUE rb_eNetcdfNfile;
|
156
|
+
static VALUE rb_eNetcdfExist;
|
157
|
+
static VALUE rb_eNetcdfInval;
|
158
|
+
static VALUE rb_eNetcdfPerm;
|
159
|
+
static VALUE rb_eNetcdfNotindefine;
|
160
|
+
static VALUE rb_eNetcdfIndefine;
|
161
|
+
static VALUE rb_eNetcdfInvalcoords;
|
162
|
+
static VALUE rb_eNetcdfMaxdims;
|
163
|
+
static VALUE rb_eNetcdfNameinuse;
|
164
|
+
static VALUE rb_eNetcdfNotatt;
|
165
|
+
static VALUE rb_eNetcdfMaxatts;
|
166
|
+
static VALUE rb_eNetcdfBadtype;
|
167
|
+
static VALUE rb_eNetcdfBaddim;
|
168
|
+
static VALUE rb_eNetcdfUnlimpos;
|
169
|
+
static VALUE rb_eNetcdfMaxvars;
|
170
|
+
static VALUE rb_eNetcdfNotvar;
|
171
|
+
static VALUE rb_eNetcdfGlobal;
|
172
|
+
static VALUE rb_eNetcdfNotnc;
|
173
|
+
static VALUE rb_eNetcdfSts;
|
174
|
+
static VALUE rb_eNetcdfMaxname;
|
175
|
+
static VALUE rb_eNetcdfUnlimit;
|
176
|
+
static VALUE rb_eNetcdfNorecvars;
|
177
|
+
static VALUE rb_eNetcdfChar;
|
178
|
+
static VALUE rb_eNetcdfEdge;
|
179
|
+
static VALUE rb_eNetcdfStride;
|
180
|
+
static VALUE rb_eNetcdfBadname;
|
181
|
+
static VALUE rb_eNetcdfRange;
|
182
|
+
static VALUE rb_eNetcdfNomem;
|
183
|
+
|
184
|
+
/* Special Error */
|
185
|
+
/* Global error status */
|
186
|
+
|
187
|
+
static VALUE rb_eNetcdfFatal;
|
188
|
+
|
189
|
+
/* Global options variable. Used to determine behavior of error handler. */
|
190
|
+
|
191
|
+
static VALUE rb_eNetcdfEntool;
|
192
|
+
static VALUE rb_eNetcdfExdr;
|
193
|
+
static VALUE rb_eNetcdfSyserr;
|
194
|
+
|
195
|
+
|
196
|
+
struct Netcdf{
|
197
|
+
int ncid;
|
198
|
+
char *name;
|
199
|
+
int closed;
|
200
|
+
};
|
201
|
+
|
202
|
+
struct NetCDFDim{
|
203
|
+
int dimid;
|
204
|
+
int ncid;
|
205
|
+
};
|
206
|
+
|
207
|
+
struct NetCDFVar{
|
208
|
+
int varid;
|
209
|
+
int ncid;
|
210
|
+
VALUE file;
|
211
|
+
};
|
212
|
+
|
213
|
+
struct NetCDFAtt{
|
214
|
+
int varid;
|
215
|
+
int ncid;
|
216
|
+
char *name;
|
217
|
+
};
|
218
|
+
|
219
|
+
static struct Netcdf *
|
220
|
+
NetCDF_init(int ncid,char *filename)
|
221
|
+
{
|
222
|
+
struct Netcdf *Netcdffile;
|
223
|
+
Netcdffile=xmalloc(sizeof(struct Netcdf));
|
224
|
+
Netcdffile->ncid=ncid;
|
225
|
+
Netcdffile->closed=0;
|
226
|
+
Netcdffile->name=xmalloc((strlen(filename)+1)*sizeof(char));
|
227
|
+
strcpy(Netcdffile->name,filename);
|
228
|
+
return(Netcdffile);
|
229
|
+
}
|
230
|
+
|
231
|
+
static struct NetCDFDim *
|
232
|
+
NetCDF_dim_init(int ncid,int dimid)
|
233
|
+
{
|
234
|
+
struct NetCDFDim *Netcdf_dim;
|
235
|
+
Netcdf_dim=xmalloc(sizeof(struct NetCDFDim));
|
236
|
+
Netcdf_dim->dimid=dimid;
|
237
|
+
Netcdf_dim->ncid=ncid;
|
238
|
+
return(Netcdf_dim);
|
239
|
+
}
|
240
|
+
|
241
|
+
static struct NetCDFVar *
|
242
|
+
NetCDF_var_init(int ncid,int varid,VALUE file)
|
243
|
+
{
|
244
|
+
struct NetCDFVar *Netcdf_var;
|
245
|
+
Netcdf_var=xmalloc(sizeof(struct NetCDFVar));
|
246
|
+
Netcdf_var->varid=varid;
|
247
|
+
Netcdf_var->ncid=ncid;
|
248
|
+
Netcdf_var->file=file;
|
249
|
+
return(Netcdf_var);
|
250
|
+
}
|
251
|
+
static struct NetCDFAtt *
|
252
|
+
NetCDF_att_init(int ncid,int varid,char *attname)
|
253
|
+
{
|
254
|
+
struct NetCDFAtt *Netcdf_att;
|
255
|
+
Netcdf_att=xmalloc(sizeof(struct NetCDFAtt));
|
256
|
+
Netcdf_att->ncid=ncid;
|
257
|
+
Netcdf_att->varid=varid;
|
258
|
+
Netcdf_att->name=xmalloc((strlen(attname)+1)*sizeof(char));
|
259
|
+
strcpy(Netcdf_att->name,attname);
|
260
|
+
return(Netcdf_att);
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
static VALUE nm_cast_object(VALUE obj, const char * dtype){
|
265
|
+
|
266
|
+
VALUE hash;
|
267
|
+
hash = RFCALL_10_ON(RGET_CLASS_TOP("Hash"), "new");
|
268
|
+
RFCALL_12_ON(hash, "[]=", CR_SYM("dtype"), CR_SYM(dtype));
|
269
|
+
return RFCALL_11_ON(obj, "cast", hash);
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
* Create a dense matrix with the given parameters. A drop in replacement
|
275
|
+
* for na_make_object
|
276
|
+
*
|
277
|
+
* Returns a properly-wrapped Ruby object as a VALUE.
|
278
|
+
*
|
279
|
+
*/
|
280
|
+
static VALUE nm_make_object(const char * dtype, size_t dim, size_t* shape) {
|
281
|
+
VALUE arr, hash;
|
282
|
+
size_t i;
|
283
|
+
|
284
|
+
arr = RFCALL_10_ON(RGET_CLASS_TOP("Array"), "new");
|
285
|
+
for(i=0;i<dim;i++) RFCALL_12_ON(arr, "[]=", INT2FIX(i), INT2FIX((int)shape[i]));
|
286
|
+
hash = RFCALL_10_ON(RGET_CLASS_TOP("Hash"), "new");
|
287
|
+
RFCALL_12_ON(hash, "[]=", CR_SYM("dtype"), CR_SYM(dtype));
|
288
|
+
return RFCALL_12_ON(cNMatrix,"zeros",arr, hash);
|
289
|
+
|
290
|
+
|
291
|
+
/*Don't need to handle case where the elements are ruby objects as
|
292
|
+
* this is currently not supported by this interface */
|
293
|
+
/*if (dtype == nm::RUBYOBJ) {*/
|
294
|
+
/*nm_register_values(reinterpret_cast<VALUE*>(elements), length);*/
|
295
|
+
/*}*/
|
296
|
+
|
297
|
+
/*NM_NMATRIX* nm;*/
|
298
|
+
/*size_t nm_dim;*/
|
299
|
+
/*size_t* shape_copy;*/
|
300
|
+
/*size_t length;*/
|
301
|
+
/*size_t i;*/
|
302
|
+
/*void* elements;*/
|
303
|
+
|
304
|
+
/*length = 1;*/
|
305
|
+
/*for (i=0;i>dim;i++) length = length * shape[i];*/
|
306
|
+
|
307
|
+
/*nm_dim = dim;*/
|
308
|
+
/*shape_copy = NM_ALLOC_N(size_t, nm_dim);*/
|
309
|
+
/*memcpy(shape_copy, shape, sizeof(size_t)*nm_dim);*/
|
310
|
+
|
311
|
+
/*// Create storage*/
|
312
|
+
/*elements = NM_ALLOC_N(char, DTYPE_SIZES[dtype]*length);*/
|
313
|
+
|
314
|
+
/*// allocate and create the matrix and its storage*/
|
315
|
+
/*nm = nm_create(DENSE_STORE, nm_dense_storage_create(dtype, shape_copy, dim, elements, length));*/
|
316
|
+
|
317
|
+
/*nm_register_nmatrix(nm);*/
|
318
|
+
|
319
|
+
/*VALUE to_return = Data_Wrap_Struct(cNMatrix, nm_mark, nm_delete, nm);*/
|
320
|
+
|
321
|
+
/*nm_unregister_nmatrix(nm);*/
|
322
|
+
/**//*if (dtype == nm::RUBYOBJ) {*/
|
323
|
+
/**//*nm_unregister_values(reinterpret_cast<VALUE*>(elements), length);*/
|
324
|
+
/**//*}*/
|
325
|
+
|
326
|
+
/*// tell Ruby about the matrix and its storage, particularly how to garbage collect it.*/
|
327
|
+
/*return to_return;*/
|
328
|
+
}
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
void
|
339
|
+
Netcdf_att_free(struct NetCDFAtt *Netcdf_att)
|
340
|
+
{
|
341
|
+
free(Netcdf_att->name);
|
342
|
+
free(Netcdf_att);
|
343
|
+
}
|
344
|
+
|
345
|
+
void
|
346
|
+
NetCDF_var_free(struct NetCDFVar *Netcdf_var)
|
347
|
+
{
|
348
|
+
free(Netcdf_var);
|
349
|
+
}
|
350
|
+
|
351
|
+
void
|
352
|
+
NetCDF_dim_free(struct NetCDFDim *Netcdf_dim)
|
353
|
+
{
|
354
|
+
free(Netcdf_dim);
|
355
|
+
}
|
356
|
+
|
357
|
+
void
|
358
|
+
NetCDF_free(struct Netcdf *Netcdffile)
|
359
|
+
{
|
360
|
+
if (!Netcdffile->closed){
|
361
|
+
nc_close(Netcdffile->ncid); /* no error check -- not to stop during GC */
|
362
|
+
}
|
363
|
+
free(Netcdffile->name);
|
364
|
+
free(Netcdffile);
|
365
|
+
}
|
366
|
+
|
367
|
+
static VALUE
|
368
|
+
err_status2class(int status)
|
369
|
+
{
|
370
|
+
if(NC_ISSYSERR(status)){
|
371
|
+
return(rb_eNetcdfSyserr);
|
372
|
+
}
|
373
|
+
switch(status)
|
374
|
+
{
|
375
|
+
case(NC_EBADID):
|
376
|
+
return(rb_eNetcdfBadid);break;
|
377
|
+
case(NC_ENFILE):
|
378
|
+
return(rb_eNetcdfNfile);break;
|
379
|
+
case(NC_EEXIST):
|
380
|
+
return(rb_eNetcdfExist);break;
|
381
|
+
case(NC_EINVAL):
|
382
|
+
return(rb_eNetcdfInval);break;
|
383
|
+
case(NC_EPERM):
|
384
|
+
return(rb_eNetcdfPerm);break;
|
385
|
+
case(NC_ENOTINDEFINE):
|
386
|
+
return(rb_eNetcdfNotindefine);break;
|
387
|
+
case(NC_EINDEFINE):
|
388
|
+
return(rb_eNetcdfIndefine);break;
|
389
|
+
case(NC_EINVALCOORDS):
|
390
|
+
return(rb_eNetcdfInvalcoords);break;
|
391
|
+
case(NC_EMAXDIMS):
|
392
|
+
return(rb_eNetcdfMaxdims);break;
|
393
|
+
case(NC_ENAMEINUSE):
|
394
|
+
return(rb_eNetcdfNameinuse);break;
|
395
|
+
case(NC_ENOTATT):
|
396
|
+
return(rb_eNetcdfNotatt);break;
|
397
|
+
case(NC_EMAXATTS):
|
398
|
+
return(rb_eNetcdfMaxatts);break;
|
399
|
+
case(NC_EBADTYPE):
|
400
|
+
return(rb_eNetcdfBadtype);break;
|
401
|
+
case(NC_EBADDIM):
|
402
|
+
return(rb_eNetcdfBaddim);break;
|
403
|
+
case(NC_EUNLIMPOS):
|
404
|
+
return(rb_eNetcdfUnlimpos);break;
|
405
|
+
case(NC_EMAXVARS):
|
406
|
+
return(rb_eNetcdfMaxvars);break;
|
407
|
+
case(NC_ENOTVAR):
|
408
|
+
return(rb_eNetcdfNotvar);break;
|
409
|
+
case(NC_EGLOBAL):
|
410
|
+
return(rb_eNetcdfGlobal);break;
|
411
|
+
case(NC_ENOTNC):
|
412
|
+
return(rb_eNetcdfNotnc);break;
|
413
|
+
case(NC_ESTS):
|
414
|
+
return(rb_eNetcdfSts);break;
|
415
|
+
case(NC_EMAXNAME):
|
416
|
+
return(rb_eNetcdfMaxname);break;
|
417
|
+
case(NC_EUNLIMIT):
|
418
|
+
return(rb_eNetcdfUnlimit);break;
|
419
|
+
case(NC_ENORECVARS):
|
420
|
+
return(rb_eNetcdfNorecvars);break;
|
421
|
+
case(NC_ECHAR):
|
422
|
+
return(rb_eNetcdfChar);break;
|
423
|
+
case(NC_EEDGE):
|
424
|
+
return(rb_eNetcdfEdge);break;
|
425
|
+
case(NC_ESTRIDE):
|
426
|
+
return(rb_eNetcdfStride);break;
|
427
|
+
case(NC_EBADNAME):
|
428
|
+
return(rb_eNetcdfBadname);break;
|
429
|
+
case(NC_ERANGE):
|
430
|
+
return(rb_eNetcdfRange);break;
|
431
|
+
case(NC_ENOMEM):
|
432
|
+
return(rb_eNetcdfNomem);break;
|
433
|
+
/* case(NC_ENTOOL):
|
434
|
+
return(rb_eNetcdfEntool);break; */
|
435
|
+
case(NC_EXDR):
|
436
|
+
return(rb_eNetcdfExdr);break;
|
437
|
+
case(NC_SYSERR):
|
438
|
+
return(rb_eNetcdfSyserr);break;
|
439
|
+
case(NC_FATAL):
|
440
|
+
return(rb_eNetcdfFatal);break;
|
441
|
+
}
|
442
|
+
return rb_eNetcdfError;
|
443
|
+
}
|
444
|
+
|
445
|
+
static const char*
|
446
|
+
nctype2nmtype(int nctype){
|
447
|
+
switch(nctype){
|
448
|
+
case NC_CHAR:
|
449
|
+
return("byte");
|
450
|
+
case NC_BYTE:
|
451
|
+
return("byte");
|
452
|
+
case NC_SHORT:
|
453
|
+
return("int16");
|
454
|
+
case NC_INT:
|
455
|
+
return("int32");
|
456
|
+
case NC_FLOAT:
|
457
|
+
return("float32");
|
458
|
+
case NC_DOUBLE:
|
459
|
+
return("float64");
|
460
|
+
default:
|
461
|
+
rb_raise(rb_eNetcdfError, "No such netcdf type number %d\n",nctype);
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
static int
|
466
|
+
nctype2nmtypecode(int nctype){
|
467
|
+
switch(nctype){
|
468
|
+
case NC_CHAR:
|
469
|
+
return(BYTE);
|
470
|
+
case NC_BYTE:
|
471
|
+
return(BYTE);
|
472
|
+
case NC_SHORT:
|
473
|
+
return(INT16);
|
474
|
+
case NC_INT:
|
475
|
+
return(INT32);
|
476
|
+
case NC_FLOAT:
|
477
|
+
return(FLOAT32);
|
478
|
+
case NC_DOUBLE:
|
479
|
+
return(FLOAT64);
|
480
|
+
default:
|
481
|
+
rb_raise(rb_eNetcdfError, "No such netcdf type number %d\n",nctype);
|
482
|
+
}
|
483
|
+
}
|
484
|
+
|
485
|
+
static int
|
486
|
+
nmtype2nctype(char *nmtype)
|
487
|
+
{
|
488
|
+
if(strcmp(nmtype,"byte")==0) return(NC_BYTE);
|
489
|
+
else if(strcmp(nmtype,"byte")==0) return(NC_CHAR);
|
490
|
+
else if(strcmp(nmtype,"text")==0) return(NC_CHAR); /* alias of char */
|
491
|
+
else if(strcmp(nmtype,"string")==0) return(NC_CHAR); /* alias of char */
|
492
|
+
else if(strcmp(nmtype,"int16")==0) return(NC_SHORT);
|
493
|
+
else if(strcmp(nmtype,"int32")==0) return(NC_INT);
|
494
|
+
else if(strcmp(nmtype,"float32")==0) return(NC_FLOAT);
|
495
|
+
else if(strcmp(nmtype,"float64")==0) return(NC_DOUBLE);
|
496
|
+
else rb_raise(rb_eNetcdfError, "No such NMatrix type '%s'",nmtype);
|
497
|
+
}
|
498
|
+
|
499
|
+
static int
|
500
|
+
nmtypecode2nctype(int nmtypecode)
|
501
|
+
{
|
502
|
+
if(nmtypecode==BYTE) return(NC_BYTE);
|
503
|
+
else if(nmtypecode==INT16) return(NC_SHORT);
|
504
|
+
else if(nmtypecode==INT32) return(NC_INT);
|
505
|
+
else if(nmtypecode==FLOAT32) return(NC_FLOAT);
|
506
|
+
else if(nmtypecode==FLOAT64) return(NC_DOUBLE);
|
507
|
+
else rb_raise(rb_eNetcdfError, "No such NMatrix typecode '%d'",nmtypecode);
|
508
|
+
}
|
509
|
+
|
510
|
+
static void
|
511
|
+
nc_mark_obj(struct NetCDFVar *netcdf_var)
|
512
|
+
{
|
513
|
+
VALUE ptr;
|
514
|
+
|
515
|
+
ptr = netcdf_var->file;
|
516
|
+
rb_gc_mark(ptr);
|
517
|
+
}
|
518
|
+
|
519
|
+
|
520
|
+
VALUE
|
521
|
+
NetCDF_clone(VALUE file)
|
522
|
+
{
|
523
|
+
VALUE clone;
|
524
|
+
struct Netcdf *nc1, *nc2;
|
525
|
+
|
526
|
+
Data_Get_Struct(file, struct Netcdf, nc1);
|
527
|
+
nc2 = NetCDF_init(nc1->ncid, nc1->name);
|
528
|
+
clone = Data_Wrap_Struct(cNetCDF, 0, NetCDF_free, nc2);
|
529
|
+
CLONESETUP(clone, file);
|
530
|
+
return clone;
|
531
|
+
}
|
532
|
+
|
533
|
+
VALUE
|
534
|
+
NetCDF_dim_clone(VALUE dim)
|
535
|
+
{
|
536
|
+
VALUE clone;
|
537
|
+
struct NetCDFDim *nd1, *nd2;
|
538
|
+
|
539
|
+
Data_Get_Struct(dim, struct NetCDFDim, nd1);
|
540
|
+
nd2 = NetCDF_dim_init(nd1->ncid, nd1->dimid);
|
541
|
+
clone = Data_Wrap_Struct(cNetCDFDim, 0, NetCDF_dim_free, nd2);
|
542
|
+
CLONESETUP(clone, dim);
|
543
|
+
return clone;
|
544
|
+
}
|
545
|
+
|
546
|
+
VALUE
|
547
|
+
NetCDF_att_clone(VALUE att)
|
548
|
+
{
|
549
|
+
VALUE clone;
|
550
|
+
struct NetCDFAtt *na1, *na2;
|
551
|
+
|
552
|
+
Data_Get_Struct(att, struct NetCDFAtt, na1);
|
553
|
+
na2 = NetCDF_att_init(na1->ncid, na1->varid, na1->name);
|
554
|
+
clone = Data_Wrap_Struct(cNetCDFAtt, 0, Netcdf_att_free, na2);
|
555
|
+
CLONESETUP(clone, att);
|
556
|
+
return clone;
|
557
|
+
}
|
558
|
+
|
559
|
+
VALUE
|
560
|
+
NetCDF_var_clone(VALUE var)
|
561
|
+
{
|
562
|
+
VALUE clone;
|
563
|
+
struct NetCDFVar *nv1, *nv2;
|
564
|
+
|
565
|
+
Data_Get_Struct(var, struct NetCDFVar, nv1);
|
566
|
+
nv2 = NetCDF_var_init(nv1->ncid, nv1->varid, nv1->file);
|
567
|
+
clone = Data_Wrap_Struct(cNetCDFVar, nc_mark_obj, NetCDF_var_free, nv2);
|
568
|
+
CLONESETUP(clone, var);
|
569
|
+
return clone;
|
570
|
+
}
|
571
|
+
|
572
|
+
VALUE
|
573
|
+
NetCDF_inq_libvers(VALUE mod)
|
574
|
+
{
|
575
|
+
VALUE str;
|
576
|
+
str = rb_str_new2(nc_inq_libvers());
|
577
|
+
return(str);
|
578
|
+
}
|
579
|
+
|
580
|
+
VALUE
|
581
|
+
NetCDF_close(file)
|
582
|
+
VALUE file;
|
583
|
+
{
|
584
|
+
int status;
|
585
|
+
int ncid;
|
586
|
+
struct Netcdf *Netcdffile;
|
587
|
+
|
588
|
+
if (rb_safe_level() >= 3 && !OBJ_TAINTED(file)) {
|
589
|
+
rb_raise(rb_eSecurityError, "Insecure: can't close");
|
590
|
+
}
|
591
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
592
|
+
ncid=Netcdffile->ncid;
|
593
|
+
if(!Netcdffile->closed){
|
594
|
+
status = nc_close(ncid);
|
595
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
596
|
+
Netcdffile->closed = 1;
|
597
|
+
} else {
|
598
|
+
rb_warn("file %s is already closed", Netcdffile->name);
|
599
|
+
}
|
600
|
+
return Qnil;
|
601
|
+
}
|
602
|
+
|
603
|
+
VALUE
|
604
|
+
NetCDF_def_dim(VALUE file,VALUE dim_name,VALUE length)
|
605
|
+
{
|
606
|
+
char* c_dim_name;
|
607
|
+
size_t c_length;
|
608
|
+
int ncid;
|
609
|
+
int dimidp;
|
610
|
+
int status;
|
611
|
+
struct Netcdf *Netcdffile;
|
612
|
+
struct NetCDFDim *Netcdf_dim;
|
613
|
+
VALUE Dimension;
|
614
|
+
|
615
|
+
rb_secure(1);
|
616
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
617
|
+
|
618
|
+
Check_Type(dim_name,T_STRING);
|
619
|
+
c_dim_name=RSTRING_PTR(dim_name);
|
620
|
+
c_length=NUM2UINT(length);
|
621
|
+
ncid=Netcdffile->ncid;
|
622
|
+
|
623
|
+
status = nc_def_dim(ncid,c_dim_name,c_length,&dimidp);
|
624
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
625
|
+
|
626
|
+
Netcdf_dim = NetCDF_dim_init(ncid,dimidp);
|
627
|
+
|
628
|
+
Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
629
|
+
return Dimension;
|
630
|
+
}
|
631
|
+
|
632
|
+
|
633
|
+
static VALUE
|
634
|
+
NetCDF_put_att_char(int ncid, char *name,VALUE value,VALUE atttype, int varid)
|
635
|
+
{
|
636
|
+
int status;
|
637
|
+
struct NetCDFAtt *ncatt;
|
638
|
+
|
639
|
+
/* check atttype (not necessarily needed but it's better to do it) */
|
640
|
+
if (TYPE(atttype) == T_STRING){
|
641
|
+
if ( nmtype2nctype(RSTRING_PTR(atttype)) != NC_CHAR ) {
|
642
|
+
rb_raise(rb_eNetcdfError,
|
643
|
+
"attribute type must be 'char' (or nil) for a String value");
|
644
|
+
}
|
645
|
+
} else if (TYPE(atttype) != T_NIL) {
|
646
|
+
rb_raise(rb_eNetcdfError,
|
647
|
+
"type specfication must be by a string or nil");
|
648
|
+
}
|
649
|
+
/* put value */
|
650
|
+
Check_Type(value,T_STRING);
|
651
|
+
status = nc_put_att_text(ncid, varid, name,
|
652
|
+
RSTRING_LEN(value), RSTRING_PTR(value));
|
653
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
654
|
+
|
655
|
+
ncatt = NetCDF_att_init(ncid,varid,name);
|
656
|
+
return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,ncatt));
|
657
|
+
}
|
658
|
+
|
659
|
+
static VALUE
|
660
|
+
NetCDF_put_att_numeric(int ncid, char *name,VALUE value,VALUE atttype, int varid)
|
661
|
+
{
|
662
|
+
VALUE val, hash, arr;
|
663
|
+
int nc_typecode, status, len;
|
664
|
+
char *ptr;
|
665
|
+
struct NetCDFAtt *ncatt;
|
666
|
+
|
667
|
+
hash = RFCALL_10_ON(RGET_CLASS_TOP("Hash"), "new");
|
668
|
+
/* check atttype and cast to an appropriate NMatrix if needed */
|
669
|
+
|
670
|
+
if (TYPE(atttype) != T_NIL){
|
671
|
+
RFCALL_12_ON(hash, "[]=", ID2SYM(rb_intern("dtype")), ID2SYM(rb_intern(RSTRING_PTR(atttype))));
|
672
|
+
nc_typecode = nmtype2nctype(RSTRING_PTR(atttype));
|
673
|
+
if (!NM_IsNMatrix(value)){
|
674
|
+
if (TYPE(value)!=T_ARRAY){
|
675
|
+
arr = RFCALL_10_ON(RGET_CLASS_TOP("Array"), "new");
|
676
|
+
RFCALL_11_ON(arr, "push", value);
|
677
|
+
value = arr;
|
678
|
+
}
|
679
|
+
/*RFCALL_11_ON(value, "push", CR_SYM(RSTRING_PTR(atttype)));*/
|
680
|
+
RFCALL_11_ON(value, "push", hash);
|
681
|
+
CR_PSTR("Creating nmatrix");
|
682
|
+
rb_p(value);
|
683
|
+
rb_p(hash);
|
684
|
+
value = rb_funcall2(cNMatrix, rb_intern("[]"), RARRAY_LEN(value), RARRAY_PTR(value));
|
685
|
+
rb_p(value);
|
686
|
+
}
|
687
|
+
else{
|
688
|
+
RFCALL_11_ON(value, "cast", hash);
|
689
|
+
}
|
690
|
+
} else {
|
691
|
+
if (TYPE(value)==T_ARRAY) {
|
692
|
+
val = RARRAY_PTR(value)[0]; /* to check the 1st elemnt if Array */
|
693
|
+
} else {
|
694
|
+
arr = RFCALL_10_ON(RGET_CLASS_TOP("Array"), "new");
|
695
|
+
RFCALL_11_ON(arr, "push", value);
|
696
|
+
val = value;
|
697
|
+
value = arr;
|
698
|
+
}
|
699
|
+
switch(TYPE(val)){
|
700
|
+
case T_FIXNUM:
|
701
|
+
case T_BIGNUM:
|
702
|
+
nc_typecode = NC_INT;
|
703
|
+
/*RFCALL_11_ON(value, "push", rb_intern("int32"));*/
|
704
|
+
RFCALL_12_ON(hash, "[]=", CR_SYM("dtype"), CR_SYM("int32"));
|
705
|
+
RFCALL_11_ON(value, "push", hash);
|
706
|
+
value = rb_funcall2(cNMatrix, rb_intern("[]"), RARRAY_LEN(value), RARRAY_PTR(value));
|
707
|
+
/*value = RFCALL_12_ON(cNMatrix, "[]", value, hash);*/
|
708
|
+
break;
|
709
|
+
case T_FLOAT:
|
710
|
+
nc_typecode = NC_DOUBLE;
|
711
|
+
/*RFCALL_11_ON(value, "push", rb_intern("float64"));*/
|
712
|
+
/*value = RFCALL_12_ON(cNMatrix, "[]", value, rb_intern("float64"));*/
|
713
|
+
RFCALL_12_ON(hash, "[]=", CR_SYM("dtype"), CR_SYM("float64"));
|
714
|
+
RFCALL_11_ON(value, "push", hash);
|
715
|
+
value = rb_funcall2(cNMatrix, rb_intern("[]"), RARRAY_LEN(value), RARRAY_PTR(value));
|
716
|
+
/*value = RFCALL_12_ON(cNMatrix, "[]", value, hash);*/
|
717
|
+
break;
|
718
|
+
case T_DATA:
|
719
|
+
if ( NM_IsNMatrix(value) ){
|
720
|
+
nc_typecode = nmtypecode2nctype(NM_DTYPE(value));
|
721
|
+
} else {
|
722
|
+
rb_raise(rb_eNetcdfError,"value has a wrong data type");
|
723
|
+
}
|
724
|
+
break;
|
725
|
+
default:
|
726
|
+
rb_raise(rb_eNetcdfError,
|
727
|
+
"value (or its first element) has a wrong type");
|
728
|
+
}
|
729
|
+
}
|
730
|
+
|
731
|
+
/* put value */
|
732
|
+
|
733
|
+
len = NM_DENSE_COUNT(value);
|
734
|
+
ptr = NM_DENSE_ELEMENTS(value);
|
735
|
+
switch(nc_typecode){
|
736
|
+
case NC_BYTE:
|
737
|
+
status = nc_put_att_uchar(ncid,varid,name,NC_BYTE,len,(unsigned char *)ptr);
|
738
|
+
break;
|
739
|
+
case NC_SHORT:
|
740
|
+
status = nc_put_att_short(ncid,varid,name,NC_SHORT,len,(short *)ptr);
|
741
|
+
break;
|
742
|
+
case NC_INT:
|
743
|
+
status = nc_put_att_int(ncid,varid,name,NC_INT,len,(int *)ptr);
|
744
|
+
break;
|
745
|
+
case NC_FLOAT:
|
746
|
+
status = nc_put_att_float(ncid,varid,name,NC_FLOAT,len,(float *)ptr);
|
747
|
+
break;
|
748
|
+
case NC_DOUBLE:
|
749
|
+
status = nc_put_att_double(ncid,varid,name,NC_DOUBLE,len,(double*)ptr);
|
750
|
+
break;
|
751
|
+
default:
|
752
|
+
rb_raise(rb_eNetcdfError,
|
753
|
+
"unsupported type. code = %d",nc_typecode);
|
754
|
+
}
|
755
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
756
|
+
|
757
|
+
ncatt = NetCDF_att_init(ncid,varid,name);
|
758
|
+
return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,ncatt));
|
759
|
+
}
|
760
|
+
|
761
|
+
static VALUE
|
762
|
+
NetCDF_put_att__(int ncid, char *name, VALUE value, VALUE atttype, int varid)
|
763
|
+
/*
|
764
|
+
* atttype: nil or a String ("string","int",etc). If nil,
|
765
|
+
* the type of attribute is determined from the type of value
|
766
|
+
*/
|
767
|
+
{
|
768
|
+
switch(TYPE(value)){
|
769
|
+
case T_STRING:
|
770
|
+
return(NetCDF_put_att_char(ncid, name, value, atttype, varid));
|
771
|
+
default:
|
772
|
+
return(NetCDF_put_att_numeric(ncid, name, value, atttype, varid));
|
773
|
+
}
|
774
|
+
}
|
775
|
+
|
776
|
+
VALUE
|
777
|
+
NetCDF_put_att(VALUE file,VALUE att_name,VALUE value,VALUE atttype)
|
778
|
+
/*
|
779
|
+
* atttype: nil or a String ("string","int",etc). If nil,
|
780
|
+
* the type of attribute is determined from the type of value
|
781
|
+
*/
|
782
|
+
{
|
783
|
+
struct Netcdf *ncfile;
|
784
|
+
char *name;
|
785
|
+
|
786
|
+
rb_secure(1);
|
787
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
788
|
+
Check_Type(att_name,T_STRING);
|
789
|
+
name = RSTRING_PTR(att_name);
|
790
|
+
|
791
|
+
return( NetCDF_put_att__(ncfile->ncid, name, value, atttype, NC_GLOBAL) );
|
792
|
+
}
|
793
|
+
|
794
|
+
VALUE
|
795
|
+
NetCDF_put_att_var(VALUE var,VALUE att_name,VALUE value,VALUE atttype)
|
796
|
+
/*
|
797
|
+
* atttype: nil or a String ("string","int",etc). If nil,
|
798
|
+
* the type of attribute is determined from the type of value
|
799
|
+
*/
|
800
|
+
{
|
801
|
+
struct NetCDFVar *ncvar;
|
802
|
+
char *name;
|
803
|
+
|
804
|
+
rb_secure(1);
|
805
|
+
Data_Get_Struct(var,struct NetCDFVar,ncvar);
|
806
|
+
Check_Type(att_name,T_STRING);
|
807
|
+
name = RSTRING_PTR(att_name);
|
808
|
+
|
809
|
+
return( NetCDF_put_att__(ncvar->ncid, name, value, atttype, ncvar->varid));
|
810
|
+
}
|
811
|
+
|
812
|
+
|
813
|
+
VALUE
|
814
|
+
NetCDF_def_var(VALUE file,VALUE var_name,VALUE vartype,VALUE dimensions)
|
815
|
+
{
|
816
|
+
int ncid;
|
817
|
+
char *c_var_name;
|
818
|
+
static int xtype;
|
819
|
+
long c_ndims;
|
820
|
+
int varidp;
|
821
|
+
int dimidp;
|
822
|
+
int i=0;
|
823
|
+
int status;
|
824
|
+
char *c_dim_name;
|
825
|
+
int c_dimids[NC_MAX_DIMS];
|
826
|
+
struct Netcdf *Netcdffile;
|
827
|
+
struct NetCDFVar *Netcdf_var;
|
828
|
+
struct NetCDFDim *Netcdf_dim;
|
829
|
+
VALUE Var;
|
830
|
+
|
831
|
+
rb_secure(1);
|
832
|
+
Check_Type(var_name,T_STRING);
|
833
|
+
Check_Type(dimensions,T_ARRAY);
|
834
|
+
|
835
|
+
c_var_name=RSTRING_PTR(var_name);
|
836
|
+
c_ndims=RARRAY_LEN(dimensions);
|
837
|
+
|
838
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
839
|
+
ncid=Netcdffile->ncid;
|
840
|
+
|
841
|
+
if (TYPE(vartype) == T_STRING){
|
842
|
+
xtype = nmtype2nctype(RSTRING_PTR(vartype));
|
843
|
+
} else if (TYPE(vartype) == T_FIXNUM){
|
844
|
+
xtype = nmtypecode2nctype(NUM2INT(vartype));
|
845
|
+
} else {
|
846
|
+
rb_raise(rb_eNetcdfError,
|
847
|
+
"type specfication must be by a string or nil");
|
848
|
+
}
|
849
|
+
|
850
|
+
for(i=0;i<c_ndims;i++){
|
851
|
+
switch(TYPE(RARRAY_PTR(dimensions)[RCMAJOR(c_ndims, i)])){
|
852
|
+
case T_STRING:
|
853
|
+
Check_Type(RARRAY_PTR(dimensions)[RCMAJOR(c_ndims,i)],T_STRING);
|
854
|
+
c_dim_name=StringValueCStr(RARRAY_PTR(dimensions)[RCMAJOR(c_ndims,i)]);
|
855
|
+
status=nc_inq_dimid(ncid,c_dim_name,&dimidp);
|
856
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
857
|
+
c_dimids[i]=dimidp;
|
858
|
+
break;
|
859
|
+
case T_DATA:
|
860
|
+
Data_Get_Struct(RARRAY_PTR(dimensions)[RCMAJOR(c_ndims,i)],struct NetCDFDim,Netcdf_dim);
|
861
|
+
c_dimids[i]=Netcdf_dim->dimid;
|
862
|
+
break;
|
863
|
+
default:
|
864
|
+
rb_raise(rb_eNetcdfError, "No such object of the netCDF dimension class.");
|
865
|
+
}
|
866
|
+
}
|
867
|
+
|
868
|
+
status = nc_def_var(ncid,c_var_name,xtype,c_ndims,c_dimids,&varidp);
|
869
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
870
|
+
|
871
|
+
Netcdf_var = NetCDF_var_init(ncid,varidp,file);
|
872
|
+
|
873
|
+
Var=Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var);
|
874
|
+
return Var;
|
875
|
+
}
|
876
|
+
|
877
|
+
VALUE
|
878
|
+
NetCDF_dim(VALUE file,VALUE dim_name)
|
879
|
+
{
|
880
|
+
int ncid;
|
881
|
+
char *c_dim_name;
|
882
|
+
int dimidp;
|
883
|
+
int status;
|
884
|
+
struct Netcdf *Netcdffile;
|
885
|
+
struct NetCDFDim *Netcdf_dim;
|
886
|
+
VALUE Dimension;
|
887
|
+
|
888
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
889
|
+
ncid=Netcdffile->ncid;
|
890
|
+
Check_Type(dim_name,T_STRING);
|
891
|
+
c_dim_name=RSTRING_PTR(dim_name);
|
892
|
+
|
893
|
+
status = nc_inq_dimid(ncid,c_dim_name,&dimidp);
|
894
|
+
if(status !=NC_NOERR){
|
895
|
+
if(status == NC_EBADDIM){
|
896
|
+
return(Qnil); /*2003/08/27 back to orig (from changes on 2003/02/03)*/
|
897
|
+
} else{
|
898
|
+
NC_RAISE(status);
|
899
|
+
}
|
900
|
+
}
|
901
|
+
|
902
|
+
Netcdf_dim=NetCDF_dim_init(ncid,dimidp);
|
903
|
+
|
904
|
+
Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
905
|
+
return Dimension;
|
906
|
+
}
|
907
|
+
|
908
|
+
VALUE
|
909
|
+
NetCDF_var(VALUE file,VALUE var_name)
|
910
|
+
{
|
911
|
+
int ncid;
|
912
|
+
int status;
|
913
|
+
int varidp;
|
914
|
+
char *c_var_name;
|
915
|
+
struct Netcdf *Netcdffile;
|
916
|
+
struct NetCDFVar *Netcdf_var;
|
917
|
+
VALUE Variable;
|
918
|
+
|
919
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
920
|
+
ncid=Netcdffile->ncid;
|
921
|
+
Check_Type(var_name,T_STRING);
|
922
|
+
c_var_name=RSTRING_PTR(var_name);
|
923
|
+
|
924
|
+
status=nc_inq_varid(ncid,c_var_name,&varidp);
|
925
|
+
if(status != NC_NOERR){
|
926
|
+
if(status == NC_ENOTVAR){
|
927
|
+
return(Qnil); /*2003/08/27 back to orig (from changes on 2003/02/03)*/
|
928
|
+
} else{
|
929
|
+
NC_RAISE(status);
|
930
|
+
}
|
931
|
+
}
|
932
|
+
|
933
|
+
Netcdf_var = NetCDF_var_init(ncid,varidp,file);
|
934
|
+
Variable = Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var);
|
935
|
+
return Variable;
|
936
|
+
}
|
937
|
+
|
938
|
+
VALUE
|
939
|
+
NetCDF_att(VALUE file,VALUE att_name)
|
940
|
+
{
|
941
|
+
int ncid;
|
942
|
+
int status;
|
943
|
+
int attnump;
|
944
|
+
char *c_att_name;
|
945
|
+
struct Netcdf *Netcdffile;
|
946
|
+
struct NetCDFAtt *Netcdf_att;
|
947
|
+
VALUE Attribute;
|
948
|
+
|
949
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
950
|
+
ncid=Netcdffile->ncid;
|
951
|
+
Check_Type(att_name,T_STRING);
|
952
|
+
c_att_name=RSTRING_PTR(att_name);
|
953
|
+
|
954
|
+
|
955
|
+
status = nc_inq_attid(ncid,NC_GLOBAL,c_att_name,&attnump);
|
956
|
+
if(status != NC_NOERR){
|
957
|
+
if(status == NC_ENOTATT){
|
958
|
+
return(Qnil);
|
959
|
+
}
|
960
|
+
else{
|
961
|
+
NC_RAISE(status);
|
962
|
+
}
|
963
|
+
}
|
964
|
+
|
965
|
+
Netcdf_att = NetCDF_att_init(ncid,NC_GLOBAL,c_att_name);
|
966
|
+
|
967
|
+
Attribute = Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att);
|
968
|
+
|
969
|
+
return Attribute;
|
970
|
+
}
|
971
|
+
VALUE
|
972
|
+
NetCDF_fill(VALUE file,VALUE mode)
|
973
|
+
{
|
974
|
+
int ncid;
|
975
|
+
int status;
|
976
|
+
struct Netcdf *Netcdffile;
|
977
|
+
int old_modep;
|
978
|
+
|
979
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
980
|
+
ncid = Netcdffile->ncid;
|
981
|
+
if(mode==Qfalse){
|
982
|
+
status = nc_set_fill(ncid,NC_NOFILL,&old_modep);
|
983
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
984
|
+
}
|
985
|
+
else if(mode == Qtrue){
|
986
|
+
status = nc_set_fill(ncid,NC_FILL,&old_modep);
|
987
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
988
|
+
}
|
989
|
+
else
|
990
|
+
rb_raise(rb_eNetcdfError,"Usage:self.fill(true) or self.fill(false)");
|
991
|
+
return Qnil;
|
992
|
+
}
|
993
|
+
|
994
|
+
VALUE
|
995
|
+
NetCDF_redef(VALUE file)
|
996
|
+
{
|
997
|
+
int ncid;
|
998
|
+
int status;
|
999
|
+
struct Netcdf *Netcdffile;
|
1000
|
+
|
1001
|
+
rb_secure(1);
|
1002
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
1003
|
+
ncid=Netcdffile->ncid;
|
1004
|
+
status = nc_redef(ncid);
|
1005
|
+
if(status !=NC_NOERR){
|
1006
|
+
if(status == NC_EINDEFINE){
|
1007
|
+
return Qnil;
|
1008
|
+
}
|
1009
|
+
else{
|
1010
|
+
NC_RAISE(status);
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
return Qtrue;
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
VALUE
|
1017
|
+
NetCDF_enddef(VALUE file)
|
1018
|
+
{
|
1019
|
+
int ncid;
|
1020
|
+
int status;
|
1021
|
+
struct Netcdf *Netcdffile;
|
1022
|
+
|
1023
|
+
rb_secure(1);
|
1024
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
1025
|
+
ncid=Netcdffile->ncid;
|
1026
|
+
status = nc_enddef(ncid);
|
1027
|
+
if(status !=NC_NOERR){
|
1028
|
+
if(status == NC_ENOTINDEFINE){
|
1029
|
+
return Qnil;
|
1030
|
+
}
|
1031
|
+
else{
|
1032
|
+
NC_RAISE(status);
|
1033
|
+
}
|
1034
|
+
}
|
1035
|
+
return Qtrue;
|
1036
|
+
}
|
1037
|
+
|
1038
|
+
VALUE
|
1039
|
+
NetCDF_whether_in_define_mode(VALUE file)
|
1040
|
+
{
|
1041
|
+
/* returns true if the NetCDF object is currently in the define mode,
|
1042
|
+
false if in the data mode, and
|
1043
|
+
nil if else (possibly the file is read-only, or some other
|
1044
|
+
error occurred)
|
1045
|
+
*/
|
1046
|
+
int ncid;
|
1047
|
+
int status;
|
1048
|
+
struct Netcdf *Netcdffile;
|
1049
|
+
|
1050
|
+
rb_secure(1);
|
1051
|
+
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
1052
|
+
ncid=Netcdffile->ncid;
|
1053
|
+
status = nc_redef(ncid);
|
1054
|
+
if(status == NC_EINDEFINE){
|
1055
|
+
return Qtrue;
|
1056
|
+
} else if(status == NC_NOERR) {
|
1057
|
+
/* was in the data mode --> recover the data mode and report false */
|
1058
|
+
status = nc_enddef(ncid);
|
1059
|
+
if(status == NC_NOERR) {
|
1060
|
+
return Qfalse;
|
1061
|
+
} else {
|
1062
|
+
return Qnil;
|
1063
|
+
}
|
1064
|
+
} else {
|
1065
|
+
return Qnil;
|
1066
|
+
}
|
1067
|
+
}
|
1068
|
+
|
1069
|
+
VALUE
|
1070
|
+
NetCDF_open(VALUE mod,VALUE filename,VALUE omode)
|
1071
|
+
{
|
1072
|
+
int status;
|
1073
|
+
int ncid;
|
1074
|
+
char* c_filename;
|
1075
|
+
int c_omode;
|
1076
|
+
struct Netcdf *ncfile;
|
1077
|
+
VALUE retval;
|
1078
|
+
|
1079
|
+
Check_Type(filename,T_STRING);
|
1080
|
+
SafeStringValue(filename);
|
1081
|
+
c_filename=RSTRING_PTR(filename);
|
1082
|
+
Check_Type(omode,T_FIXNUM);
|
1083
|
+
c_omode=NUM2INT(omode);
|
1084
|
+
|
1085
|
+
status = nc_open(c_filename,c_omode,&ncid);
|
1086
|
+
if(status !=NC_NOERR){NC_RAISE2(status,c_filename);}
|
1087
|
+
|
1088
|
+
ncfile = NetCDF_init(ncid,c_filename);
|
1089
|
+
retval = Data_Wrap_Struct(cNetCDF,0,NetCDF_free,ncfile);
|
1090
|
+
return( retval );
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
VALUE
|
1094
|
+
NetCDF_create(VALUE mod,VALUE filename,VALUE cmode)
|
1095
|
+
{
|
1096
|
+
int ncid;
|
1097
|
+
int status;
|
1098
|
+
char* c_filename;
|
1099
|
+
int c_cmode;
|
1100
|
+
struct Netcdf *ncfile;
|
1101
|
+
|
1102
|
+
Check_Type(filename,T_STRING);
|
1103
|
+
SafeStringValue(filename);
|
1104
|
+
c_filename=RSTRING_PTR(filename);
|
1105
|
+
Check_Type(cmode,T_FIXNUM);
|
1106
|
+
c_cmode=NUM2INT(cmode);
|
1107
|
+
|
1108
|
+
status = nc_create(c_filename,c_cmode,&ncid);
|
1109
|
+
if(status != NC_NOERR) NC_RAISE2(status, c_filename);
|
1110
|
+
|
1111
|
+
ncfile = NetCDF_init(ncid,c_filename);
|
1112
|
+
return( Data_Wrap_Struct(cNetCDF,0,NetCDF_free,ncfile) );
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
VALUE
|
1116
|
+
NetCDF_ndims(VALUE file)
|
1117
|
+
{
|
1118
|
+
int ncid;
|
1119
|
+
int ndimsp;
|
1120
|
+
VALUE Integer;
|
1121
|
+
int status;
|
1122
|
+
struct Netcdf *ncfile;
|
1123
|
+
|
1124
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1125
|
+
ncid=ncfile->ncid;
|
1126
|
+
status = nc_inq_ndims(ncid,&ndimsp);
|
1127
|
+
if(status != NC_NOERR) NC_RAISE (status);
|
1128
|
+
Integer = INT2NUM(ndimsp);
|
1129
|
+
return Integer;
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
VALUE
|
1133
|
+
NetCDF_nvars(VALUE file)
|
1134
|
+
{
|
1135
|
+
int ncid;
|
1136
|
+
int nvarsp;
|
1137
|
+
int status;
|
1138
|
+
VALUE Integer;
|
1139
|
+
struct Netcdf *ncfile;
|
1140
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1141
|
+
ncid=ncfile->ncid;
|
1142
|
+
status = nc_inq_nvars(ncid,&nvarsp);
|
1143
|
+
if(status != NC_NOERR) NC_RAISE (status);
|
1144
|
+
Integer = INT2NUM(nvarsp);
|
1145
|
+
return Integer;
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
VALUE
|
1149
|
+
NetCDF_natts(VALUE file)
|
1150
|
+
{
|
1151
|
+
int ncid;
|
1152
|
+
int nattsp;
|
1153
|
+
int status;
|
1154
|
+
VALUE Integer;
|
1155
|
+
struct Netcdf *ncfile;
|
1156
|
+
|
1157
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1158
|
+
ncid=ncfile->ncid;
|
1159
|
+
status=nc_inq_natts(ncid,&nattsp);
|
1160
|
+
if(status != NC_NOERR) NC_RAISE (status);
|
1161
|
+
Integer = INT2NUM(nattsp);
|
1162
|
+
return Integer;
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
VALUE
|
1166
|
+
NetCDF_unlimited(VALUE file)
|
1167
|
+
{
|
1168
|
+
int ncid;
|
1169
|
+
int unlimdimidp;
|
1170
|
+
int status;
|
1171
|
+
struct Netcdf *ncfile;
|
1172
|
+
struct NetCDFDim *Netcdf_dim;
|
1173
|
+
VALUE Dimension;
|
1174
|
+
|
1175
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1176
|
+
ncid=ncfile->ncid;
|
1177
|
+
status=nc_inq_unlimdim(ncid,&unlimdimidp);
|
1178
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
1179
|
+
|
1180
|
+
Netcdf_dim = NetCDF_dim_init(ncid,unlimdimidp);
|
1181
|
+
|
1182
|
+
/* If unlimdimidp=-1,No unlimited dimension is defined in the netCDF dataset */
|
1183
|
+
if(unlimdimidp != -1)
|
1184
|
+
{
|
1185
|
+
Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
1186
|
+
return Dimension;
|
1187
|
+
}
|
1188
|
+
else
|
1189
|
+
{
|
1190
|
+
return Qnil;
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
VALUE
|
1195
|
+
NetCDF_sync(VALUE file)
|
1196
|
+
{
|
1197
|
+
int ncid;
|
1198
|
+
int status;
|
1199
|
+
struct Netcdf *ncfile;
|
1200
|
+
|
1201
|
+
rb_secure(1);
|
1202
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1203
|
+
ncid=ncfile->ncid;
|
1204
|
+
status = nc_sync(ncid);
|
1205
|
+
if(status !=NC_NOERR) NC_RAISE (status);
|
1206
|
+
return Qnil;
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
VALUE
|
1210
|
+
NetCDF_path(VALUE file)
|
1211
|
+
{
|
1212
|
+
char *path;
|
1213
|
+
struct Netcdf *ncfile;
|
1214
|
+
|
1215
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1216
|
+
path=ncfile->name;
|
1217
|
+
return(rb_str_new2(path));
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
VALUE
|
1221
|
+
NetCDF_dim_length(VALUE Dim)
|
1222
|
+
{
|
1223
|
+
int ncid;
|
1224
|
+
int status;
|
1225
|
+
int dimid;
|
1226
|
+
size_t lengthp;
|
1227
|
+
struct NetCDFDim *Netcdf_dim;
|
1228
|
+
|
1229
|
+
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
1230
|
+
ncid=Netcdf_dim->ncid;
|
1231
|
+
dimid=Netcdf_dim->dimid;
|
1232
|
+
|
1233
|
+
status = nc_inq_dimlen(ncid,dimid,&lengthp);
|
1234
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1235
|
+
|
1236
|
+
return(INT2NUM(lengthp));
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
VALUE
|
1240
|
+
NetCDF_dim_name(VALUE Dim,VALUE dimension_newname)
|
1241
|
+
{
|
1242
|
+
int ncid;
|
1243
|
+
int status;
|
1244
|
+
int dimid;
|
1245
|
+
char *c_dim_name;
|
1246
|
+
struct NetCDFDim *Netcdf_dim;
|
1247
|
+
|
1248
|
+
rb_secure(1);
|
1249
|
+
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
1250
|
+
ncid=Netcdf_dim->ncid;
|
1251
|
+
dimid=Netcdf_dim->dimid;
|
1252
|
+
Check_Type(dimension_newname,T_STRING);
|
1253
|
+
c_dim_name = StringValueCStr(dimension_newname);
|
1254
|
+
|
1255
|
+
status = nc_rename_dim(ncid,dimid,c_dim_name);
|
1256
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
1257
|
+
|
1258
|
+
return Qnil;
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
VALUE
|
1262
|
+
NetCDF_dim_inqname(VALUE Dim)
|
1263
|
+
{
|
1264
|
+
int ncid;
|
1265
|
+
int status;
|
1266
|
+
int dimid;
|
1267
|
+
char c_dim_name[NC_MAX_NAME];
|
1268
|
+
struct NetCDFDim *Netcdf_dim;
|
1269
|
+
VALUE str;
|
1270
|
+
|
1271
|
+
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
1272
|
+
ncid=Netcdf_dim->ncid;
|
1273
|
+
dimid=Netcdf_dim->dimid;
|
1274
|
+
|
1275
|
+
status = nc_inq_dimname(ncid,dimid,c_dim_name);
|
1276
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
1277
|
+
|
1278
|
+
str = rb_str_new2(c_dim_name);
|
1279
|
+
OBJ_TAINT(str);
|
1280
|
+
return(str);
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
VALUE
|
1284
|
+
NetCDF_dim_whether_unlimited(VALUE Dim)
|
1285
|
+
{
|
1286
|
+
int status;
|
1287
|
+
int uldid;
|
1288
|
+
struct NetCDFDim *Netcdf_dim;
|
1289
|
+
|
1290
|
+
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
1291
|
+
status=nc_inq_unlimdim(Netcdf_dim->ncid,&uldid);
|
1292
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
1293
|
+
if(Netcdf_dim->dimid == uldid){
|
1294
|
+
return(Qtrue);
|
1295
|
+
} else {
|
1296
|
+
return(Qfalse);
|
1297
|
+
}
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
VALUE
|
1301
|
+
NetCDF_att_inq_name(VALUE Att)
|
1302
|
+
{
|
1303
|
+
char *c_att_name;
|
1304
|
+
struct NetCDFAtt *Netcdf_att;
|
1305
|
+
VALUE str;
|
1306
|
+
|
1307
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1308
|
+
c_att_name=Netcdf_att->name;
|
1309
|
+
|
1310
|
+
str = rb_str_new2(c_att_name);
|
1311
|
+
OBJ_TAINT(str);
|
1312
|
+
return(str);
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
VALUE
|
1316
|
+
NetCDF_att_rename(VALUE Att,VALUE new_att_name)
|
1317
|
+
{
|
1318
|
+
int ncid;
|
1319
|
+
int status;
|
1320
|
+
int varid;
|
1321
|
+
char *c_att_name;
|
1322
|
+
char *c_new_att_name;
|
1323
|
+
struct NetCDFAtt *Netcdf_att;
|
1324
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1325
|
+
ncid=Netcdf_att->ncid;
|
1326
|
+
varid=Netcdf_att->varid;
|
1327
|
+
|
1328
|
+
c_att_name=Netcdf_att->name;
|
1329
|
+
|
1330
|
+
Check_Type(new_att_name,T_STRING);
|
1331
|
+
SafeStringValue(new_att_name);
|
1332
|
+
c_new_att_name=StringValueCStr(new_att_name);
|
1333
|
+
|
1334
|
+
status = nc_rename_att(ncid,varid,c_att_name,c_new_att_name);
|
1335
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1336
|
+
|
1337
|
+
strcpy(Netcdf_att->name,c_new_att_name);
|
1338
|
+
return Qnil;
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
VALUE
|
1342
|
+
NetCDF_id2dim(VALUE file,VALUE dimid)
|
1343
|
+
{
|
1344
|
+
int ncid;
|
1345
|
+
int c_dimid;
|
1346
|
+
struct Netcdf *ncfile;
|
1347
|
+
struct NetCDFDim *Netcdf_dim;
|
1348
|
+
VALUE Dim;
|
1349
|
+
|
1350
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1351
|
+
ncid=ncfile->ncid;
|
1352
|
+
Check_Type(dimid,T_FIXNUM);
|
1353
|
+
c_dimid=NUM2INT(dimid);
|
1354
|
+
Netcdf_dim = NetCDF_dim_init(ncid,c_dimid);
|
1355
|
+
Dim=Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
1356
|
+
return(Dim);
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
VALUE
|
1360
|
+
NetCDF_id2var(VALUE file,VALUE varid)
|
1361
|
+
{
|
1362
|
+
int ncid;
|
1363
|
+
int c_varid;
|
1364
|
+
struct Netcdf *ncfile;
|
1365
|
+
struct NetCDFVar *Netcdf_var;
|
1366
|
+
VALUE Var;
|
1367
|
+
|
1368
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1369
|
+
ncid=ncfile->ncid;
|
1370
|
+
Check_Type(varid,T_FIXNUM);
|
1371
|
+
c_varid=NUM2INT(varid);
|
1372
|
+
Netcdf_var = NetCDF_var_init(ncid,c_varid,file);
|
1373
|
+
Var=Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var);
|
1374
|
+
return(Var);
|
1375
|
+
}
|
1376
|
+
|
1377
|
+
|
1378
|
+
VALUE
|
1379
|
+
NetCDF_id2att(VALUE file,VALUE attnum)
|
1380
|
+
{
|
1381
|
+
int ncid;
|
1382
|
+
int c_attnum;
|
1383
|
+
int status;
|
1384
|
+
struct Netcdf *ncfile;
|
1385
|
+
struct NetCDFAtt *Netcdf_att;
|
1386
|
+
char *c_att_name;
|
1387
|
+
VALUE Att;
|
1388
|
+
c_att_name=ALLOCA_N(char,NC_MAX_NAME);
|
1389
|
+
|
1390
|
+
Data_Get_Struct(file,struct Netcdf,ncfile);
|
1391
|
+
ncid=ncfile->ncid;
|
1392
|
+
|
1393
|
+
Check_Type(attnum,T_FIXNUM);
|
1394
|
+
c_attnum=NUM2INT(attnum);
|
1395
|
+
|
1396
|
+
status = nc_inq_attname(ncid,NC_GLOBAL,c_attnum,c_att_name);
|
1397
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1398
|
+
|
1399
|
+
Netcdf_att=NetCDF_att_init(ncid,NC_GLOBAL,c_att_name);
|
1400
|
+
|
1401
|
+
Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att);
|
1402
|
+
return(Att);
|
1403
|
+
|
1404
|
+
}
|
1405
|
+
|
1406
|
+
#if NCVER >= 400
|
1407
|
+
/* USAGE
|
1408
|
+
NetCDFVar#deflate(deflate_level, shuffle=false)
|
1409
|
+
*/
|
1410
|
+
VALUE
|
1411
|
+
NetCDF_var_deflate(int argc, VALUE *argv, VALUE Var)
|
1412
|
+
{
|
1413
|
+
int ncid, varid, status;
|
1414
|
+
struct NetCDFVar *Netcdf_var;
|
1415
|
+
|
1416
|
+
int shuffle;
|
1417
|
+
/* If non-zero, turn on the shuffle filter.
|
1418
|
+
|
1419
|
+
http://www.unidata.ucar.edu/software/netcdf/papers/AMS_2008.pdf :
|
1420
|
+
The shuffle algorithm changes the byte order in the data stream;
|
1421
|
+
when used with integers that are all close together, this
|
1422
|
+
results in a better compression ratio. There is no benefit
|
1423
|
+
from using the shuffle filter without also using
|
1424
|
+
compression.
|
1425
|
+
|
1426
|
+
MEMO by horinouchi: shuffling filter was also effective for float
|
1427
|
+
variables in some test (demo5-netcdf4.rb).
|
1428
|
+
*/
|
1429
|
+
int deflate_level;
|
1430
|
+
int deflate=1;
|
1431
|
+
/* Always set to non-zero:
|
1432
|
+
See https://www.unidata.ucar.edu/software/netcdf/docs/netcdf-c/nc_005fdef_005fvar_005fdeflate.html#nc_005fdef_005fvar_005fdeflate
|
1433
|
+
If non-zero, turn on the deflate filter at the
|
1434
|
+
level specified by the deflate_level parameter.
|
1435
|
+
*/
|
1436
|
+
|
1437
|
+
if (argc>2 || argc<1) rb_raise(rb_eArgError,
|
1438
|
+
"wrong # of arguments (%d). It must be 1 or 2", argc);
|
1439
|
+
|
1440
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1441
|
+
ncid = Netcdf_var->ncid;
|
1442
|
+
varid = Netcdf_var->varid;
|
1443
|
+
|
1444
|
+
deflate_level = NUM2INT(argv[0]);
|
1445
|
+
|
1446
|
+
if (argc==1) {
|
1447
|
+
shuffle = 0; /* default: false */
|
1448
|
+
} else {
|
1449
|
+
if ( argv[1] == Qnil || argv[1] == Qfalse ) {
|
1450
|
+
shuffle = 0;
|
1451
|
+
} else {
|
1452
|
+
shuffle = 1;
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
status = nc_def_var_deflate(ncid, varid, shuffle, deflate, deflate_level);
|
1457
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1458
|
+
|
1459
|
+
return(Var);
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
VALUE
|
1463
|
+
NetCDF_var_deflate_params(VALUE Var)
|
1464
|
+
{
|
1465
|
+
int ncid, varid, status;
|
1466
|
+
struct NetCDFVar *Netcdf_var;
|
1467
|
+
int shufflep, deflatep, deflate_levelp;
|
1468
|
+
VALUE sh, df, params;
|
1469
|
+
|
1470
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1471
|
+
ncid = Netcdf_var->ncid;
|
1472
|
+
varid = Netcdf_var->varid;
|
1473
|
+
status = nc_inq_var_deflate(ncid, varid, &shufflep, &deflatep,
|
1474
|
+
&deflate_levelp);
|
1475
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1476
|
+
if (shufflep==0) {sh=Qfalse;} else {sh=Qtrue;}
|
1477
|
+
if (deflatep==0) {df=Qfalse;} else {df=Qtrue;}
|
1478
|
+
params = rb_ary_new3(3, sh, df, INT2NUM(deflate_levelp) );
|
1479
|
+
return(params);
|
1480
|
+
}
|
1481
|
+
|
1482
|
+
VALUE
|
1483
|
+
NetCDF_var_set_endian(VALUE Var, VALUE endian)
|
1484
|
+
{
|
1485
|
+
int ncid, varid, status;
|
1486
|
+
struct NetCDFVar *Netcdf_var;
|
1487
|
+
|
1488
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1489
|
+
ncid = Netcdf_var->ncid;
|
1490
|
+
varid = Netcdf_var->varid;
|
1491
|
+
status = nc_def_var_endian(ncid, varid, NUM2INT(endian));
|
1492
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1493
|
+
return(Var);
|
1494
|
+
}
|
1495
|
+
|
1496
|
+
VALUE
|
1497
|
+
NetCDF_var_endian(VALUE Var)
|
1498
|
+
{
|
1499
|
+
int ncid, varid, status;
|
1500
|
+
struct NetCDFVar *Netcdf_var;
|
1501
|
+
int endian;
|
1502
|
+
|
1503
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1504
|
+
ncid = Netcdf_var->ncid;
|
1505
|
+
varid = Netcdf_var->varid;
|
1506
|
+
status = nc_inq_var_endian(ncid, varid, &endian);
|
1507
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1508
|
+
return(INT2FIX(endian));
|
1509
|
+
}
|
1510
|
+
|
1511
|
+
#endif
|
1512
|
+
|
1513
|
+
VALUE
|
1514
|
+
NetCDF_var_id2att(VALUE Var,VALUE attnum)
|
1515
|
+
{
|
1516
|
+
int ncid;
|
1517
|
+
int c_attnum;
|
1518
|
+
int status;
|
1519
|
+
int c_varid;
|
1520
|
+
struct NetCDFVar *Netcdf_var;
|
1521
|
+
struct NetCDFAtt *Netcdf_att;
|
1522
|
+
char *c_att_name;
|
1523
|
+
VALUE Att;
|
1524
|
+
|
1525
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1526
|
+
ncid=Netcdf_var->ncid;
|
1527
|
+
c_varid=Netcdf_var->varid;
|
1528
|
+
|
1529
|
+
Check_Type(attnum,T_FIXNUM);
|
1530
|
+
c_attnum=NUM2INT(attnum);
|
1531
|
+
|
1532
|
+
c_att_name=ALLOCA_N(char,NC_MAX_NAME);
|
1533
|
+
|
1534
|
+
status = nc_inq_attname(ncid,c_varid,c_attnum,c_att_name);
|
1535
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1536
|
+
|
1537
|
+
Netcdf_att=NetCDF_att_init(ncid,c_varid,c_att_name);
|
1538
|
+
Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att);
|
1539
|
+
return(Att);
|
1540
|
+
}
|
1541
|
+
|
1542
|
+
VALUE
|
1543
|
+
NetCDF_var_dims(VALUE Var)
|
1544
|
+
{
|
1545
|
+
int ncid, *dimids, ndims, varid, i, status;
|
1546
|
+
struct NetCDFVar *Netcdf_var;
|
1547
|
+
struct NetCDFDim *Netcdf_dim;
|
1548
|
+
VALUE Dims;
|
1549
|
+
|
1550
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1551
|
+
ncid = Netcdf_var->ncid;
|
1552
|
+
varid = Netcdf_var->varid;
|
1553
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
1554
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1555
|
+
dimids=ALLOCA_N(int,ndims);
|
1556
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
1557
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1558
|
+
Dims = rb_ary_new();
|
1559
|
+
for(i=0;i<ndims;i++){
|
1560
|
+
Netcdf_dim = NetCDF_dim_init(ncid,dimids[RCMAJOR(ndims,i)]);
|
1561
|
+
rb_ary_push(Dims,
|
1562
|
+
Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim));
|
1563
|
+
}
|
1564
|
+
return(Dims);
|
1565
|
+
}
|
1566
|
+
|
1567
|
+
VALUE
|
1568
|
+
NetCDF_var_dim(VALUE Var, VALUE ith)
|
1569
|
+
{
|
1570
|
+
int ncid, *dimids, ndims, varid, status, c_ith;
|
1571
|
+
struct NetCDFVar *Netcdf_var;
|
1572
|
+
struct NetCDFDim *Netcdf_dim;
|
1573
|
+
VALUE Dim;
|
1574
|
+
|
1575
|
+
Check_Type(ith,T_FIXNUM);
|
1576
|
+
c_ith=NUM2INT(ith);
|
1577
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1578
|
+
ncid = Netcdf_var->ncid;
|
1579
|
+
varid = Netcdf_var->varid;
|
1580
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
1581
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1582
|
+
if(c_ith < 0 || c_ith >= ndims) {
|
1583
|
+
rb_raise(rb_eNetcdfError, "dimension count less than zero or greater than ndims-1");
|
1584
|
+
}
|
1585
|
+
dimids=ALLOCA_N(int,ndims);
|
1586
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
1587
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1588
|
+
Netcdf_dim = NetCDF_dim_init(ncid,dimids[ndims-1-c_ith]);
|
1589
|
+
Dim = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
1590
|
+
return(Dim);
|
1591
|
+
}
|
1592
|
+
|
1593
|
+
VALUE
|
1594
|
+
NetCDF_att_copy(VALUE Att,VALUE Var_or_File)
|
1595
|
+
{
|
1596
|
+
int ncid_in,ncid_out;
|
1597
|
+
int status;
|
1598
|
+
int varid_in,varid_out;
|
1599
|
+
char *att_name;
|
1600
|
+
struct NetCDFAtt *Netcdf_att;
|
1601
|
+
struct NetCDFVar *Netcdf_var;
|
1602
|
+
struct Netcdf *ncfile;
|
1603
|
+
struct NetCDFAtt *Netcdf_att_out;
|
1604
|
+
|
1605
|
+
rb_secure(1);
|
1606
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1607
|
+
ncid_in=Netcdf_att->ncid;
|
1608
|
+
varid_in=Netcdf_att->varid;
|
1609
|
+
att_name=Netcdf_att->name;
|
1610
|
+
|
1611
|
+
if( rb_obj_is_kind_of(Var_or_File, cNetCDFVar) ){
|
1612
|
+
Data_Get_Struct(Var_or_File,struct NetCDFVar, Netcdf_var);
|
1613
|
+
ncid_out=Netcdf_var->ncid;
|
1614
|
+
varid_out=Netcdf_var->varid;
|
1615
|
+
} else if ( rb_obj_is_kind_of(Var_or_File, cNetCDF) ){
|
1616
|
+
Data_Get_Struct(Var_or_File,struct Netcdf, ncfile);
|
1617
|
+
ncid_out=ncfile->ncid;
|
1618
|
+
varid_out=NC_GLOBAL;
|
1619
|
+
} else {
|
1620
|
+
rb_raise(rb_eNetcdfError,"The argument must be a NetCDFVar or a NetCDF");
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
status = nc_copy_att(ncid_in,varid_in,att_name,ncid_out,varid_out);
|
1624
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1625
|
+
Netcdf_att_out = NetCDF_att_init(ncid_out,varid_out,att_name);
|
1626
|
+
return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att_out));
|
1627
|
+
}
|
1628
|
+
|
1629
|
+
VALUE
|
1630
|
+
NetCDF_att_atttype(VALUE Att)
|
1631
|
+
{
|
1632
|
+
int ncid;
|
1633
|
+
int varid;
|
1634
|
+
int status;
|
1635
|
+
char *att_name;
|
1636
|
+
const char *Attname;
|
1637
|
+
struct NetCDFAtt *Netcdf_att;
|
1638
|
+
nc_type xtypep;
|
1639
|
+
|
1640
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1641
|
+
ncid = Netcdf_att->ncid;
|
1642
|
+
varid = Netcdf_att->varid;
|
1643
|
+
att_name = Netcdf_att->name;
|
1644
|
+
|
1645
|
+
status = nc_inq_atttype(ncid,varid,att_name,&xtypep);
|
1646
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1647
|
+
|
1648
|
+
Attname = nctype2nmtype(xtypep);
|
1649
|
+
return(rb_str_new2(Attname));
|
1650
|
+
}
|
1651
|
+
|
1652
|
+
VALUE
|
1653
|
+
NetCDF_att_typecode(VALUE Att)
|
1654
|
+
{
|
1655
|
+
int ncid;
|
1656
|
+
int varid;
|
1657
|
+
int status;
|
1658
|
+
char *att_name;
|
1659
|
+
struct NetCDFAtt *Netcdf_att;
|
1660
|
+
nc_type xtypep;
|
1661
|
+
|
1662
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1663
|
+
ncid = Netcdf_att->ncid;
|
1664
|
+
varid = Netcdf_att->varid;
|
1665
|
+
att_name = Netcdf_att->name;
|
1666
|
+
|
1667
|
+
status = nc_inq_atttype(ncid,varid,att_name,&xtypep);
|
1668
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1669
|
+
|
1670
|
+
return(INT2NUM(nctype2nmtypecode(xtypep)));
|
1671
|
+
}
|
1672
|
+
|
1673
|
+
VALUE
|
1674
|
+
NetCDF_att_delete(VALUE Att)
|
1675
|
+
{
|
1676
|
+
int ncid;
|
1677
|
+
int status;
|
1678
|
+
int varid;
|
1679
|
+
char *c_att_name;
|
1680
|
+
struct NetCDFAtt *Netcdf_att;
|
1681
|
+
|
1682
|
+
rb_secure(1);
|
1683
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1684
|
+
|
1685
|
+
ncid=Netcdf_att->ncid;
|
1686
|
+
varid=Netcdf_att->varid;
|
1687
|
+
c_att_name=Netcdf_att->name;
|
1688
|
+
|
1689
|
+
status = nc_del_att(ncid,varid,c_att_name);
|
1690
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1691
|
+
|
1692
|
+
return Qnil;
|
1693
|
+
}
|
1694
|
+
|
1695
|
+
VALUE
|
1696
|
+
NetCDF_att_put(VALUE Att,VALUE value,VALUE atttype)
|
1697
|
+
/*
|
1698
|
+
* atttype: nil or a String ("string","int",etc). If nil,
|
1699
|
+
* the type of attribute is determined from the type of value
|
1700
|
+
*/
|
1701
|
+
{
|
1702
|
+
struct NetCDFAtt *ncatt;
|
1703
|
+
|
1704
|
+
rb_secure(1);
|
1705
|
+
Data_Get_Struct(Att,struct NetCDFAtt,ncatt);
|
1706
|
+
return( NetCDF_put_att__(ncatt->ncid, ncatt->name, value,
|
1707
|
+
atttype, ncatt->varid) );
|
1708
|
+
}
|
1709
|
+
|
1710
|
+
VALUE
|
1711
|
+
NetCDF_att_get(VALUE Att)
|
1712
|
+
{
|
1713
|
+
int ncid;
|
1714
|
+
int varid;
|
1715
|
+
char *c_attname;
|
1716
|
+
int status;
|
1717
|
+
struct NetCDFAtt *Netcdf_att;
|
1718
|
+
nc_type xtypep;
|
1719
|
+
size_t lenp;
|
1720
|
+
na_shape_t attlen[1]; /* NMatrix uses int instead of size_t */
|
1721
|
+
char *tp;
|
1722
|
+
unsigned char *up;
|
1723
|
+
short *sp;
|
1724
|
+
int *ip;
|
1725
|
+
float *fp;
|
1726
|
+
double *dp;
|
1727
|
+
VALUE NMatrix;
|
1728
|
+
VALUE str;
|
1729
|
+
|
1730
|
+
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
1731
|
+
ncid = Netcdf_att->ncid;
|
1732
|
+
varid = Netcdf_att->varid;
|
1733
|
+
c_attname = Netcdf_att->name;
|
1734
|
+
|
1735
|
+
status = nc_inq_atttype(ncid,varid,c_attname,&xtypep);
|
1736
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1737
|
+
|
1738
|
+
switch(xtypep){
|
1739
|
+
case NC_CHAR:
|
1740
|
+
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
1741
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1742
|
+
tp = ALLOCA_N(char,lenp+1);
|
1743
|
+
tp[lenp]= '\0';
|
1744
|
+
status = nc_get_att_text(ncid,varid,c_attname,tp);
|
1745
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1746
|
+
str = rb_str_new2(tp);
|
1747
|
+
OBJ_TAINT(str);
|
1748
|
+
return(str);
|
1749
|
+
break;
|
1750
|
+
case NC_BYTE:
|
1751
|
+
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
1752
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1753
|
+
|
1754
|
+
attlen[0]=lenp;
|
1755
|
+
Cbyte_to_NMatrix(NMatrix,1,attlen,up);
|
1756
|
+
|
1757
|
+
status = nc_get_att_uchar(ncid,varid,c_attname,up);
|
1758
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1759
|
+
|
1760
|
+
OBJ_TAINT(NMatrix);
|
1761
|
+
return NMatrix;
|
1762
|
+
break;
|
1763
|
+
case NC_SHORT:
|
1764
|
+
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
1765
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1766
|
+
|
1767
|
+
attlen[0]=lenp;
|
1768
|
+
Csint_to_NMatrix(NMatrix,1,attlen,sp);
|
1769
|
+
|
1770
|
+
status = nc_get_att_short(ncid,varid,c_attname,sp);
|
1771
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1772
|
+
OBJ_TAINT(NMatrix);
|
1773
|
+
return NMatrix;
|
1774
|
+
break;
|
1775
|
+
case NC_INT:
|
1776
|
+
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
1777
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1778
|
+
|
1779
|
+
attlen[0]=lenp;
|
1780
|
+
Clint_to_NMatrix(NMatrix,1,attlen,ip);
|
1781
|
+
|
1782
|
+
status = nc_get_att_int(ncid,varid,c_attname,ip);
|
1783
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1784
|
+
|
1785
|
+
OBJ_TAINT(NMatrix);
|
1786
|
+
return NMatrix;
|
1787
|
+
break;
|
1788
|
+
case NC_FLOAT:
|
1789
|
+
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
1790
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1791
|
+
|
1792
|
+
attlen[0]=lenp;
|
1793
|
+
Cfloat_to_NMatrix(NMatrix,1,attlen,fp);
|
1794
|
+
|
1795
|
+
status = nc_get_att_float(ncid,varid,c_attname,fp);
|
1796
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1797
|
+
|
1798
|
+
OBJ_TAINT(NMatrix);
|
1799
|
+
return NMatrix;
|
1800
|
+
break;
|
1801
|
+
case NC_DOUBLE:
|
1802
|
+
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
1803
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1804
|
+
|
1805
|
+
attlen[0]=lenp;
|
1806
|
+
Cdouble_to_NMatrix(NMatrix,1,attlen,dp);
|
1807
|
+
|
1808
|
+
status = nc_get_att_double(ncid,varid,c_attname,dp);
|
1809
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1810
|
+
OBJ_TAINT(NMatrix);
|
1811
|
+
return NMatrix;
|
1812
|
+
break;
|
1813
|
+
default:
|
1814
|
+
rb_raise(rb_eNetcdfError,"atttype isn't supported in netCDF");
|
1815
|
+
}
|
1816
|
+
return Qnil;
|
1817
|
+
}
|
1818
|
+
|
1819
|
+
|
1820
|
+
VALUE
|
1821
|
+
NetCDF_var_inq_name(VALUE Var)
|
1822
|
+
{
|
1823
|
+
int ncid;
|
1824
|
+
int status;
|
1825
|
+
int varid;
|
1826
|
+
char c_var_name[NC_MAX_NAME];
|
1827
|
+
struct NetCDFVar *Netcdf_var;
|
1828
|
+
VALUE Var_name;
|
1829
|
+
|
1830
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1831
|
+
|
1832
|
+
ncid=Netcdf_var->ncid;
|
1833
|
+
varid=Netcdf_var->varid;
|
1834
|
+
status = nc_inq_varname(ncid,varid,c_var_name);
|
1835
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1836
|
+
|
1837
|
+
Var_name=rb_str_new2(c_var_name);
|
1838
|
+
OBJ_TAINT(Var_name);
|
1839
|
+
return Var_name;
|
1840
|
+
}
|
1841
|
+
|
1842
|
+
VALUE
|
1843
|
+
NetCDF_var_ndims(VALUE Var)
|
1844
|
+
{
|
1845
|
+
int ncid;
|
1846
|
+
int status;
|
1847
|
+
int varid;
|
1848
|
+
int ndimsp;
|
1849
|
+
struct NetCDFVar *Netcdf_var;
|
1850
|
+
VALUE Var_ndims;
|
1851
|
+
|
1852
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1853
|
+
|
1854
|
+
ncid=Netcdf_var->ncid;
|
1855
|
+
varid=Netcdf_var->varid;
|
1856
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
1857
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1858
|
+
Var_ndims=INT2FIX(ndimsp);
|
1859
|
+
return Var_ndims;
|
1860
|
+
}
|
1861
|
+
|
1862
|
+
VALUE
|
1863
|
+
NetCDF_var_vartype(VALUE Var)
|
1864
|
+
{
|
1865
|
+
int ncid;
|
1866
|
+
int status;
|
1867
|
+
int varid;
|
1868
|
+
nc_type xtypep;
|
1869
|
+
struct NetCDFVar *Netcdf_var;
|
1870
|
+
const char *Vartype;
|
1871
|
+
|
1872
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1873
|
+
|
1874
|
+
ncid=Netcdf_var->ncid;
|
1875
|
+
varid=Netcdf_var->varid;
|
1876
|
+
|
1877
|
+
status = nc_inq_vartype(ncid,varid,&xtypep);
|
1878
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1879
|
+
|
1880
|
+
Vartype=nctype2nmtype(xtypep);
|
1881
|
+
return(rb_str_new2(Vartype));
|
1882
|
+
}
|
1883
|
+
|
1884
|
+
VALUE
|
1885
|
+
NetCDF_var_typecode(VALUE Var)
|
1886
|
+
{
|
1887
|
+
int ncid;
|
1888
|
+
int status;
|
1889
|
+
int varid;
|
1890
|
+
nc_type xtypep;
|
1891
|
+
struct NetCDFVar *Netcdf_var;
|
1892
|
+
|
1893
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1894
|
+
|
1895
|
+
ncid=Netcdf_var->ncid;
|
1896
|
+
varid=Netcdf_var->varid;
|
1897
|
+
|
1898
|
+
status = nc_inq_vartype(ncid,varid,&xtypep);
|
1899
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
1900
|
+
|
1901
|
+
return(INT2NUM(nctype2nmtypecode(xtypep)));
|
1902
|
+
}
|
1903
|
+
|
1904
|
+
|
1905
|
+
VALUE
|
1906
|
+
NetCDF_var_natts(VALUE Var)
|
1907
|
+
{
|
1908
|
+
int ncid;
|
1909
|
+
int status;
|
1910
|
+
int varid;
|
1911
|
+
int nattsp;
|
1912
|
+
struct NetCDFVar *Netcdf_var;
|
1913
|
+
VALUE Var_natts;
|
1914
|
+
|
1915
|
+
|
1916
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1917
|
+
|
1918
|
+
ncid=Netcdf_var->ncid;
|
1919
|
+
varid=Netcdf_var->varid;
|
1920
|
+
|
1921
|
+
status= nc_inq_varnatts(ncid,varid,&nattsp);
|
1922
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
1923
|
+
|
1924
|
+
Var_natts=INT2FIX(nattsp);
|
1925
|
+
return Var_natts;
|
1926
|
+
}
|
1927
|
+
|
1928
|
+
VALUE
|
1929
|
+
NetCDF_var_file(VALUE Var)
|
1930
|
+
{
|
1931
|
+
struct NetCDFVar *Netcdf_var;
|
1932
|
+
/* VALUE file; */
|
1933
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1934
|
+
|
1935
|
+
return (Netcdf_var->file);
|
1936
|
+
}
|
1937
|
+
|
1938
|
+
VALUE
|
1939
|
+
NetCDF_var_rename(VALUE Var,VALUE var_new_name)
|
1940
|
+
{
|
1941
|
+
int ncid;
|
1942
|
+
int status;
|
1943
|
+
int varid;
|
1944
|
+
char *c_var_new_name;
|
1945
|
+
struct NetCDFVar *Netcdf_var;
|
1946
|
+
|
1947
|
+
rb_secure(1);
|
1948
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1949
|
+
ncid=Netcdf_var->ncid;
|
1950
|
+
varid=Netcdf_var->varid;
|
1951
|
+
|
1952
|
+
Check_Type(var_new_name,T_STRING);
|
1953
|
+
c_var_new_name=StringValueCStr(var_new_name);
|
1954
|
+
|
1955
|
+
status = nc_rename_var(ncid,varid,c_var_new_name);
|
1956
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
1957
|
+
|
1958
|
+
return Qnil;
|
1959
|
+
}
|
1960
|
+
|
1961
|
+
VALUE
|
1962
|
+
NetCDF_var_att(VALUE Var,VALUE att_name)
|
1963
|
+
{
|
1964
|
+
int ncid;
|
1965
|
+
int status;
|
1966
|
+
int varid;
|
1967
|
+
char *c_att_name;
|
1968
|
+
int c_attnump;
|
1969
|
+
struct NetCDFVar *Netcdf_var;
|
1970
|
+
struct NetCDFAtt *Netcdf_att;
|
1971
|
+
VALUE Att;
|
1972
|
+
|
1973
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
1974
|
+
|
1975
|
+
ncid=Netcdf_var->ncid;
|
1976
|
+
varid=Netcdf_var->varid;
|
1977
|
+
|
1978
|
+
Check_Type(att_name,T_STRING);
|
1979
|
+
c_att_name=StringValueCStr(att_name);
|
1980
|
+
|
1981
|
+
status = nc_inq_attid(ncid,varid,c_att_name,&c_attnump);
|
1982
|
+
if(status == NC_NOERR){
|
1983
|
+
Netcdf_att=NetCDF_att_init(ncid,varid,c_att_name);
|
1984
|
+
Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att);
|
1985
|
+
return Att;
|
1986
|
+
}
|
1987
|
+
else if(status == NC_ENOTATT){
|
1988
|
+
return Qnil;
|
1989
|
+
}
|
1990
|
+
else{
|
1991
|
+
NC_RAISE(status);
|
1992
|
+
return Qnil;
|
1993
|
+
}
|
1994
|
+
}
|
1995
|
+
|
1996
|
+
/* Redifinition of the "==" and "eql?" methods */
|
1997
|
+
|
1998
|
+
VALUE
|
1999
|
+
NetCDF_eql(VALUE filea,VALUE fileb)
|
2000
|
+
{
|
2001
|
+
struct Netcdf *ncfilea;
|
2002
|
+
struct Netcdf *ncfileb;
|
2003
|
+
|
2004
|
+
if( rb_obj_is_kind_of(fileb, cNetCDF) ){
|
2005
|
+
Data_Get_Struct(filea,struct Netcdf,ncfilea);
|
2006
|
+
Data_Get_Struct(fileb,struct Netcdf,ncfileb);
|
2007
|
+
|
2008
|
+
if(ncfilea->ncid == ncfileb->ncid &&
|
2009
|
+
strcmp(ncfilea->name,ncfileb->name)==0){
|
2010
|
+
return Qtrue;
|
2011
|
+
} else {
|
2012
|
+
return Qfalse;
|
2013
|
+
}
|
2014
|
+
} else {
|
2015
|
+
return Qfalse;
|
2016
|
+
}
|
2017
|
+
}
|
2018
|
+
|
2019
|
+
VALUE
|
2020
|
+
NetCDF_var_eql(VALUE Vara,VALUE Varb)
|
2021
|
+
{
|
2022
|
+
struct NetCDFVar *Netcdf_vara;
|
2023
|
+
struct NetCDFVar *Netcdf_varb;
|
2024
|
+
|
2025
|
+
if( rb_obj_is_kind_of(Varb, cNetCDFVar) ){
|
2026
|
+
Data_Get_Struct(Vara,struct NetCDFVar,Netcdf_vara);
|
2027
|
+
Data_Get_Struct(Varb,struct NetCDFVar,Netcdf_varb);
|
2028
|
+
|
2029
|
+
if(Netcdf_vara->ncid == Netcdf_varb->ncid &&
|
2030
|
+
Netcdf_vara->varid == Netcdf_varb->varid){
|
2031
|
+
return Qtrue;
|
2032
|
+
} else {
|
2033
|
+
return Qfalse;
|
2034
|
+
}
|
2035
|
+
} else {
|
2036
|
+
return Qfalse;
|
2037
|
+
}
|
2038
|
+
}
|
2039
|
+
|
2040
|
+
VALUE
|
2041
|
+
NetCDF_dim_eql(VALUE Dima,VALUE Dimb)
|
2042
|
+
{
|
2043
|
+
struct NetCDFDim *Netcdf_dima;
|
2044
|
+
struct NetCDFDim *Netcdf_dimb;
|
2045
|
+
|
2046
|
+
if( rb_obj_is_kind_of(Dimb, cNetCDFDim) ){
|
2047
|
+
Data_Get_Struct(Dima,struct NetCDFDim,Netcdf_dima);
|
2048
|
+
Data_Get_Struct(Dimb,struct NetCDFDim,Netcdf_dimb);
|
2049
|
+
|
2050
|
+
if(Netcdf_dima->ncid == Netcdf_dimb->ncid &&
|
2051
|
+
Netcdf_dima->dimid == Netcdf_dimb->dimid){
|
2052
|
+
return Qtrue;
|
2053
|
+
} else {
|
2054
|
+
return Qfalse;
|
2055
|
+
}
|
2056
|
+
} else {
|
2057
|
+
return Qfalse;
|
2058
|
+
}
|
2059
|
+
}
|
2060
|
+
|
2061
|
+
VALUE
|
2062
|
+
NetCDF_att_eql(VALUE Atta,VALUE Attb)
|
2063
|
+
{
|
2064
|
+
struct NetCDFAtt *Netcdf_atta;
|
2065
|
+
struct NetCDFAtt *Netcdf_attb;
|
2066
|
+
|
2067
|
+
if( rb_obj_is_kind_of(Attb, cNetCDFAtt) ){
|
2068
|
+
Data_Get_Struct(Atta,struct NetCDFAtt,Netcdf_atta);
|
2069
|
+
Data_Get_Struct(Attb,struct NetCDFAtt,Netcdf_attb);
|
2070
|
+
|
2071
|
+
if(Netcdf_atta->ncid == Netcdf_atta->ncid &&
|
2072
|
+
Netcdf_atta->varid == Netcdf_attb->varid &&
|
2073
|
+
strcmp(Netcdf_atta->name,Netcdf_attb->name)==0){
|
2074
|
+
return Qtrue;
|
2075
|
+
} else {
|
2076
|
+
return Qfalse;
|
2077
|
+
}
|
2078
|
+
} else {
|
2079
|
+
return Qfalse;
|
2080
|
+
}
|
2081
|
+
}
|
2082
|
+
|
2083
|
+
/* Follow methods is to connect "NMatrix" with "Netcdf" */
|
2084
|
+
VALUE
|
2085
|
+
NetCDF_get_var_char(VALUE Var)
|
2086
|
+
{
|
2087
|
+
int ncid;
|
2088
|
+
int varid;
|
2089
|
+
int status;
|
2090
|
+
unsigned char *ptr;
|
2091
|
+
struct NetCDFVar *Netcdf_var;
|
2092
|
+
int i=0;
|
2093
|
+
int ndimsp;
|
2094
|
+
int *dimids;
|
2095
|
+
size_t lengthp;
|
2096
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2097
|
+
VALUE NMatrix;
|
2098
|
+
|
2099
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2100
|
+
ncid = Netcdf_var->ncid;
|
2101
|
+
varid = Netcdf_var->varid;
|
2102
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
2103
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2104
|
+
dimids = ALLOCA_N(int,ndimsp);
|
2105
|
+
if (ndimsp != 0){
|
2106
|
+
shape = ALLOCA_N(na_shape_t,ndimsp);
|
2107
|
+
for(i=0;i<ndimsp;i++){
|
2108
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2109
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2110
|
+
nc_inq_dimlen(ncid,dimids[i],&lengthp);
|
2111
|
+
shape[ndimsp-1-i]=lengthp;
|
2112
|
+
}
|
2113
|
+
} else {
|
2114
|
+
ndimsp = 1;
|
2115
|
+
shape = ALLOCA_N(na_shape_t,1);
|
2116
|
+
shape[0]=1;
|
2117
|
+
}
|
2118
|
+
|
2119
|
+
Cbyte_to_NMatrix(NMatrix,ndimsp,shape,ptr);
|
2120
|
+
|
2121
|
+
status = nc_get_var_text(ncid,varid,(char *)ptr);
|
2122
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2123
|
+
|
2124
|
+
OBJ_TAINT(NMatrix);
|
2125
|
+
return NMatrix;
|
2126
|
+
}
|
2127
|
+
|
2128
|
+
VALUE
|
2129
|
+
NetCDF_get_var_byte(VALUE Var)
|
2130
|
+
{
|
2131
|
+
int ncid;
|
2132
|
+
int varid;
|
2133
|
+
int status;
|
2134
|
+
unsigned char *ptr;
|
2135
|
+
struct NetCDFVar *Netcdf_var;
|
2136
|
+
int i=0;
|
2137
|
+
int ndimsp;
|
2138
|
+
int *dimids;
|
2139
|
+
size_t lengthp;
|
2140
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2141
|
+
VALUE NMatrix;
|
2142
|
+
|
2143
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2144
|
+
ncid = Netcdf_var->ncid;
|
2145
|
+
varid = Netcdf_var->varid;
|
2146
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
2147
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2148
|
+
dimids = ALLOCA_N(int,ndimsp);
|
2149
|
+
if (ndimsp != 0){
|
2150
|
+
shape = ALLOCA_N(na_shape_t,ndimsp);
|
2151
|
+
for(i=0;i<ndimsp;i++){
|
2152
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2153
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2154
|
+
nc_inq_dimlen(ncid,dimids[i],&lengthp);
|
2155
|
+
shape[ndimsp-1-i]=lengthp;
|
2156
|
+
}
|
2157
|
+
} else {
|
2158
|
+
ndimsp = 1;
|
2159
|
+
shape = ALLOCA_N(na_shape_t,1);
|
2160
|
+
shape[0]=1;
|
2161
|
+
}
|
2162
|
+
|
2163
|
+
Cbyte_to_NMatrix(NMatrix,ndimsp,shape,ptr);
|
2164
|
+
|
2165
|
+
status = nc_get_var_uchar(ncid,varid,ptr);
|
2166
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2167
|
+
|
2168
|
+
OBJ_TAINT(NMatrix);
|
2169
|
+
return NMatrix;
|
2170
|
+
}
|
2171
|
+
|
2172
|
+
VALUE
|
2173
|
+
NetCDF_get_var_sint(VALUE Var)
|
2174
|
+
{
|
2175
|
+
int ncid;
|
2176
|
+
int varid;
|
2177
|
+
int status;
|
2178
|
+
short *ptr;
|
2179
|
+
struct NetCDFVar *Netcdf_var;
|
2180
|
+
int i=0;
|
2181
|
+
int ndimsp;
|
2182
|
+
int *dimids;
|
2183
|
+
size_t lengthp;
|
2184
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2185
|
+
VALUE NMatrix;
|
2186
|
+
|
2187
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2188
|
+
ncid = Netcdf_var->ncid;
|
2189
|
+
varid = Netcdf_var->varid;
|
2190
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
2191
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2192
|
+
dimids = ALLOCA_N(int,ndimsp);
|
2193
|
+
if (ndimsp != 0){
|
2194
|
+
shape = ALLOCA_N(na_shape_t,ndimsp);
|
2195
|
+
for(i=0;i<ndimsp;i++){
|
2196
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2197
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2198
|
+
nc_inq_dimlen(ncid,dimids[i],&lengthp);
|
2199
|
+
shape[ndimsp-1-i]=lengthp;
|
2200
|
+
}
|
2201
|
+
} else {
|
2202
|
+
ndimsp = 1;
|
2203
|
+
shape = ALLOCA_N(na_shape_t,1);
|
2204
|
+
shape[0]=1;
|
2205
|
+
}
|
2206
|
+
|
2207
|
+
Csint_to_NMatrix(NMatrix,ndimsp,shape,ptr);
|
2208
|
+
|
2209
|
+
status = nc_get_var_short(ncid,varid,ptr);
|
2210
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2211
|
+
|
2212
|
+
OBJ_TAINT(NMatrix);
|
2213
|
+
return NMatrix;
|
2214
|
+
}
|
2215
|
+
|
2216
|
+
VALUE
|
2217
|
+
NetCDF_get_var_int(VALUE Var)
|
2218
|
+
{
|
2219
|
+
int ncid;
|
2220
|
+
int varid;
|
2221
|
+
int status;
|
2222
|
+
int *ptr;
|
2223
|
+
struct NetCDFVar *Netcdf_var;
|
2224
|
+
int i=0;
|
2225
|
+
int ndimsp;
|
2226
|
+
int *dimids;
|
2227
|
+
size_t lengthp;
|
2228
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2229
|
+
VALUE NMatrix;
|
2230
|
+
|
2231
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2232
|
+
ncid = Netcdf_var->ncid;
|
2233
|
+
varid = Netcdf_var->varid;
|
2234
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
2235
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2236
|
+
dimids = ALLOCA_N(int,ndimsp);
|
2237
|
+
if (ndimsp != 0){
|
2238
|
+
shape = ALLOCA_N(na_shape_t,ndimsp);
|
2239
|
+
for(i=0;i<ndimsp;i++){
|
2240
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2241
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2242
|
+
nc_inq_dimlen(ncid,dimids[i],&lengthp);
|
2243
|
+
shape[ndimsp-1-i]=lengthp;
|
2244
|
+
}
|
2245
|
+
} else {
|
2246
|
+
ndimsp = 1;
|
2247
|
+
shape = ALLOCA_N(na_shape_t,1);
|
2248
|
+
shape[0]=1;
|
2249
|
+
}
|
2250
|
+
|
2251
|
+
Clint_to_NMatrix(NMatrix,ndimsp,shape,ptr);
|
2252
|
+
|
2253
|
+
status = nc_get_var_int(ncid,varid,ptr);
|
2254
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2255
|
+
|
2256
|
+
OBJ_TAINT(NMatrix);
|
2257
|
+
return NMatrix;
|
2258
|
+
}
|
2259
|
+
|
2260
|
+
VALUE
|
2261
|
+
NetCDF_get_var_float(VALUE Var)
|
2262
|
+
{
|
2263
|
+
int ncid;
|
2264
|
+
int varid;
|
2265
|
+
int status;
|
2266
|
+
float *ptr;
|
2267
|
+
struct NetCDFVar *Netcdf_var;
|
2268
|
+
int i=0;
|
2269
|
+
int ndimsp;
|
2270
|
+
int *dimids;
|
2271
|
+
size_t lengthp;
|
2272
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2273
|
+
VALUE NMatrix;
|
2274
|
+
|
2275
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2276
|
+
ncid = Netcdf_var->ncid;
|
2277
|
+
varid = Netcdf_var->varid;
|
2278
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
2279
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2280
|
+
dimids = ALLOCA_N(int,ndimsp);
|
2281
|
+
if (ndimsp != 0){
|
2282
|
+
shape = ALLOCA_N(na_shape_t,ndimsp);
|
2283
|
+
for(i=0;i<ndimsp;i++){
|
2284
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2285
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2286
|
+
nc_inq_dimlen(ncid,dimids[i],&lengthp);
|
2287
|
+
shape[ndimsp-1-i]=lengthp;
|
2288
|
+
}
|
2289
|
+
} else {
|
2290
|
+
ndimsp = 1;
|
2291
|
+
shape = ALLOCA_N(na_shape_t,1);
|
2292
|
+
shape[0]=1;
|
2293
|
+
}
|
2294
|
+
|
2295
|
+
Cfloat_to_NMatrix(NMatrix,ndimsp,shape,ptr);
|
2296
|
+
|
2297
|
+
status = nc_get_var_float(ncid,varid,ptr);
|
2298
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2299
|
+
|
2300
|
+
OBJ_TAINT(NMatrix);
|
2301
|
+
return NMatrix;
|
2302
|
+
}
|
2303
|
+
|
2304
|
+
VALUE
|
2305
|
+
NetCDF_get_var_double(VALUE Var)
|
2306
|
+
{
|
2307
|
+
int ncid;
|
2308
|
+
int varid;
|
2309
|
+
int status;
|
2310
|
+
double *ptr;
|
2311
|
+
struct NetCDFVar *Netcdf_var;
|
2312
|
+
int i=0;
|
2313
|
+
int ndimsp;
|
2314
|
+
int *dimids;
|
2315
|
+
size_t lengthp;
|
2316
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2317
|
+
VALUE NMatrix;
|
2318
|
+
|
2319
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2320
|
+
ncid = Netcdf_var->ncid;
|
2321
|
+
varid = Netcdf_var->varid;
|
2322
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
2323
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2324
|
+
dimids = ALLOCA_N(int,ndimsp);
|
2325
|
+
if (ndimsp != 0){
|
2326
|
+
shape = ALLOCA_N(na_shape_t,ndimsp);
|
2327
|
+
for(i=0;i<ndimsp;i++){
|
2328
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2329
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2330
|
+
nc_inq_dimlen(ncid,dimids[i],&lengthp);
|
2331
|
+
shape[ndimsp-1-i]=lengthp;
|
2332
|
+
}
|
2333
|
+
} else {
|
2334
|
+
ndimsp = 1;
|
2335
|
+
shape = ALLOCA_N(na_shape_t,1);
|
2336
|
+
shape[0]=1;
|
2337
|
+
}
|
2338
|
+
|
2339
|
+
Cdouble_to_NMatrix(NMatrix,ndimsp,shape,ptr);
|
2340
|
+
|
2341
|
+
status = nc_get_var_double(ncid,varid,ptr);
|
2342
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2343
|
+
|
2344
|
+
OBJ_TAINT(NMatrix);
|
2345
|
+
return NMatrix;
|
2346
|
+
}
|
2347
|
+
|
2348
|
+
VALUE
|
2349
|
+
NetCDF_get_var1_char(VALUE Var,VALUE start)
|
2350
|
+
{
|
2351
|
+
int ncid;
|
2352
|
+
int varid;
|
2353
|
+
int status;
|
2354
|
+
unsigned char *ptr;
|
2355
|
+
int i;
|
2356
|
+
struct NetCDFVar *Netcdf_var;
|
2357
|
+
int l_start;
|
2358
|
+
size_t *c_start;
|
2359
|
+
int ndims;
|
2360
|
+
int dimids[NC_MAX_DIMS];
|
2361
|
+
size_t dimlen;
|
2362
|
+
na_shape_t *c_count;
|
2363
|
+
VALUE NMatrix;
|
2364
|
+
|
2365
|
+
|
2366
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2367
|
+
ncid = Netcdf_var->ncid;
|
2368
|
+
varid = Netcdf_var->varid;
|
2369
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
2370
|
+
if(status != NC_NOERR)NC_RAISE(status);
|
2371
|
+
if(ndims == 0) {
|
2372
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2373
|
+
}
|
2374
|
+
|
2375
|
+
Check_Type(start,T_ARRAY);
|
2376
|
+
if(RARRAY_LEN(start) < ndims) {
|
2377
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
2378
|
+
}
|
2379
|
+
|
2380
|
+
c_start=ALLOCA_N(size_t,ndims);
|
2381
|
+
c_count=ALLOCA_N(na_shape_t,ndims);
|
2382
|
+
for(i=0;i<ndims;i++){
|
2383
|
+
l_start = NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2384
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2385
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2386
|
+
if(l_start < 0) {
|
2387
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2388
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2389
|
+
l_start += dimlen;
|
2390
|
+
}
|
2391
|
+
c_start[i]=l_start;
|
2392
|
+
|
2393
|
+
c_count[i]=1;
|
2394
|
+
}
|
2395
|
+
|
2396
|
+
|
2397
|
+
|
2398
|
+
|
2399
|
+
Cbyte_to_NMatrix(NMatrix,ndims,c_count,ptr);
|
2400
|
+
status = nc_get_var1_text(ncid,varid,c_start,(char *)ptr);
|
2401
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2402
|
+
|
2403
|
+
OBJ_TAINT(NMatrix);
|
2404
|
+
return NMatrix;
|
2405
|
+
|
2406
|
+
}
|
2407
|
+
|
2408
|
+
VALUE
|
2409
|
+
NetCDF_get_var1_byte(VALUE Var,VALUE start)
|
2410
|
+
{
|
2411
|
+
int ncid;
|
2412
|
+
int varid;
|
2413
|
+
int status;
|
2414
|
+
unsigned char *ptr;
|
2415
|
+
int i;
|
2416
|
+
struct NetCDFVar *Netcdf_var;
|
2417
|
+
int l_start;
|
2418
|
+
size_t *c_start;
|
2419
|
+
int ndims;
|
2420
|
+
int dimids[NC_MAX_DIMS];
|
2421
|
+
size_t dimlen;
|
2422
|
+
na_shape_t *c_count;
|
2423
|
+
VALUE NMatrix;
|
2424
|
+
|
2425
|
+
|
2426
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2427
|
+
ncid = Netcdf_var->ncid;
|
2428
|
+
varid = Netcdf_var->varid;
|
2429
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
2430
|
+
if(status != NC_NOERR)NC_RAISE(status);
|
2431
|
+
if(ndims == 0) {
|
2432
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2433
|
+
}
|
2434
|
+
|
2435
|
+
Check_Type(start,T_ARRAY);
|
2436
|
+
if(RARRAY_LEN(start) < ndims) {
|
2437
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
2438
|
+
}
|
2439
|
+
|
2440
|
+
c_start=ALLOCA_N(size_t,ndims);
|
2441
|
+
c_count=ALLOCA_N(na_shape_t,ndims);
|
2442
|
+
for(i=0;i<ndims;i++){
|
2443
|
+
l_start = NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2444
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2445
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2446
|
+
if(l_start < 0) {
|
2447
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2448
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2449
|
+
l_start += dimlen;
|
2450
|
+
}
|
2451
|
+
c_start[i]=l_start;
|
2452
|
+
|
2453
|
+
c_count[i]=1;
|
2454
|
+
}
|
2455
|
+
|
2456
|
+
|
2457
|
+
|
2458
|
+
|
2459
|
+
Cbyte_to_NMatrix(NMatrix,ndims,c_count,ptr);
|
2460
|
+
status = nc_get_var1_uchar(ncid,varid,c_start,ptr);
|
2461
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2462
|
+
|
2463
|
+
OBJ_TAINT(NMatrix);
|
2464
|
+
return NMatrix;
|
2465
|
+
|
2466
|
+
}
|
2467
|
+
|
2468
|
+
VALUE
|
2469
|
+
NetCDF_get_var1_sint(VALUE Var,VALUE start)
|
2470
|
+
{
|
2471
|
+
int ncid;
|
2472
|
+
int varid;
|
2473
|
+
int status;
|
2474
|
+
short *ptr;
|
2475
|
+
int i;
|
2476
|
+
struct NetCDFVar *Netcdf_var;
|
2477
|
+
int l_start;
|
2478
|
+
size_t *c_start;
|
2479
|
+
int ndims;
|
2480
|
+
int dimids[NC_MAX_DIMS];
|
2481
|
+
size_t dimlen;
|
2482
|
+
na_shape_t *c_count;
|
2483
|
+
VALUE NMatrix;
|
2484
|
+
|
2485
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2486
|
+
ncid = Netcdf_var->ncid;
|
2487
|
+
varid = Netcdf_var->varid;
|
2488
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
2489
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2490
|
+
if(ndims == 0) {
|
2491
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2492
|
+
}
|
2493
|
+
|
2494
|
+
Check_Type(start,T_ARRAY);
|
2495
|
+
if(RARRAY_LEN(start) < ndims) {
|
2496
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
2497
|
+
}
|
2498
|
+
|
2499
|
+
c_start=ALLOCA_N(size_t,ndims);
|
2500
|
+
c_count=ALLOCA_N(na_shape_t,ndims);
|
2501
|
+
for(i=0;i<ndims;i++){
|
2502
|
+
l_start = NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2503
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2504
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2505
|
+
if(l_start < 0) {
|
2506
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2507
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2508
|
+
l_start += dimlen;
|
2509
|
+
}
|
2510
|
+
c_start[i]=l_start;
|
2511
|
+
c_count[i]=1;
|
2512
|
+
}
|
2513
|
+
|
2514
|
+
Csint_to_NMatrix(NMatrix,ndims,c_count,ptr);
|
2515
|
+
|
2516
|
+
status = nc_get_var1_short(ncid,varid,c_start,ptr);
|
2517
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2518
|
+
|
2519
|
+
OBJ_TAINT(NMatrix);
|
2520
|
+
return NMatrix;
|
2521
|
+
|
2522
|
+
}
|
2523
|
+
|
2524
|
+
VALUE
|
2525
|
+
NetCDF_get_var1_int(VALUE Var,VALUE start)
|
2526
|
+
{
|
2527
|
+
int ncid;
|
2528
|
+
int varid;
|
2529
|
+
int status;
|
2530
|
+
int *ptr;
|
2531
|
+
int i;
|
2532
|
+
struct NetCDFVar *Netcdf_var;
|
2533
|
+
int l_start;
|
2534
|
+
size_t *c_start;
|
2535
|
+
int ndims;
|
2536
|
+
int dimids[NC_MAX_DIMS];
|
2537
|
+
size_t dimlen;
|
2538
|
+
na_shape_t *c_count;
|
2539
|
+
VALUE NMatrix;
|
2540
|
+
|
2541
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2542
|
+
ncid = Netcdf_var->ncid;
|
2543
|
+
varid = Netcdf_var->varid;
|
2544
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
2545
|
+
if(status != NC_NOERR)NC_RAISE(status);
|
2546
|
+
if(ndims == 0) {
|
2547
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2548
|
+
}
|
2549
|
+
|
2550
|
+
Check_Type(start,T_ARRAY);
|
2551
|
+
if(RARRAY_LEN(start) < ndims) {
|
2552
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
2553
|
+
}
|
2554
|
+
|
2555
|
+
c_start=ALLOCA_N(size_t,ndims);
|
2556
|
+
c_count=ALLOCA_N(na_shape_t,ndims);
|
2557
|
+
for(i=0;i<ndims;i++){
|
2558
|
+
l_start = NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2559
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2560
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2561
|
+
if(l_start < 0) {
|
2562
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2563
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2564
|
+
l_start += dimlen;
|
2565
|
+
}
|
2566
|
+
c_start[i]=l_start;
|
2567
|
+
c_count[i]=1;
|
2568
|
+
}
|
2569
|
+
|
2570
|
+
Clint_to_NMatrix(NMatrix,ndims,c_count,ptr);
|
2571
|
+
|
2572
|
+
status = nc_get_var1_int(ncid,varid,c_start,ptr);
|
2573
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2574
|
+
|
2575
|
+
OBJ_TAINT(NMatrix);
|
2576
|
+
return NMatrix;
|
2577
|
+
|
2578
|
+
}
|
2579
|
+
|
2580
|
+
VALUE
|
2581
|
+
NetCDF_get_var1_float(VALUE Var,VALUE start)
|
2582
|
+
{
|
2583
|
+
int ncid;
|
2584
|
+
int varid;
|
2585
|
+
int status;
|
2586
|
+
float *ptr;
|
2587
|
+
int i;
|
2588
|
+
struct NetCDFVar *Netcdf_var;
|
2589
|
+
int l_start;
|
2590
|
+
size_t *c_start;
|
2591
|
+
int ndims;
|
2592
|
+
int dimids[NC_MAX_DIMS];
|
2593
|
+
size_t dimlen;
|
2594
|
+
na_shape_t *c_count;
|
2595
|
+
VALUE NMatrix;
|
2596
|
+
|
2597
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2598
|
+
ncid = Netcdf_var->ncid;
|
2599
|
+
varid = Netcdf_var->varid;
|
2600
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
2601
|
+
if(status != NC_NOERR)NC_RAISE(status);
|
2602
|
+
if(ndims == 0) {
|
2603
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2604
|
+
}
|
2605
|
+
|
2606
|
+
Check_Type(start,T_ARRAY);
|
2607
|
+
if(RARRAY_LEN(start) < ndims) {
|
2608
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
2609
|
+
}
|
2610
|
+
|
2611
|
+
c_start=ALLOCA_N(size_t,ndims);
|
2612
|
+
c_count=ALLOCA_N(na_shape_t,ndims);
|
2613
|
+
for(i=0;i<ndims;i++){
|
2614
|
+
l_start = NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2615
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
2616
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2617
|
+
if(l_start < 0) {
|
2618
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2619
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2620
|
+
l_start += dimlen;
|
2621
|
+
}
|
2622
|
+
c_start[i]=l_start;
|
2623
|
+
c_count[i]=1;
|
2624
|
+
}
|
2625
|
+
|
2626
|
+
Cfloat_to_NMatrix(NMatrix,ndims,c_count,ptr);
|
2627
|
+
|
2628
|
+
status = nc_get_var1_float(ncid,varid,c_start,ptr);
|
2629
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2630
|
+
|
2631
|
+
OBJ_TAINT(NMatrix);
|
2632
|
+
return NMatrix;
|
2633
|
+
|
2634
|
+
}
|
2635
|
+
|
2636
|
+
VALUE
|
2637
|
+
NetCDF_get_var1_double(VALUE Var,VALUE start)
|
2638
|
+
{
|
2639
|
+
int ncid;
|
2640
|
+
int varid;
|
2641
|
+
int status;
|
2642
|
+
double *ptr;
|
2643
|
+
int i;
|
2644
|
+
struct NetCDFVar *Netcdf_var;
|
2645
|
+
int l_start;
|
2646
|
+
size_t *c_start;
|
2647
|
+
int ndims;
|
2648
|
+
int dimids[NC_MAX_DIMS];
|
2649
|
+
size_t dimlen;
|
2650
|
+
na_shape_t *c_count;
|
2651
|
+
VALUE NMatrix;
|
2652
|
+
|
2653
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2654
|
+
ncid = Netcdf_var->ncid;
|
2655
|
+
varid = Netcdf_var->varid;
|
2656
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
2657
|
+
if(status != NC_NOERR)NC_RAISE(status);
|
2658
|
+
if(ndims == 0) {
|
2659
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2660
|
+
}
|
2661
|
+
|
2662
|
+
Check_Type(start,T_ARRAY);
|
2663
|
+
if(RARRAY_LEN(start) < ndims) {
|
2664
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
2665
|
+
}
|
2666
|
+
|
2667
|
+
c_start=ALLOCA_N(size_t,ndims);
|
2668
|
+
c_count=ALLOCA_N(na_shape_t,ndims);
|
2669
|
+
for(i=0;i<ndims;i++){
|
2670
|
+
l_start = NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2671
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2672
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
2673
|
+
if(l_start < 0) {
|
2674
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2675
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2676
|
+
l_start += dimlen;
|
2677
|
+
}
|
2678
|
+
c_start[i]=l_start;
|
2679
|
+
c_count[i]=1;
|
2680
|
+
}
|
2681
|
+
|
2682
|
+
Cdouble_to_NMatrix(NMatrix,ndims,c_count,ptr);
|
2683
|
+
|
2684
|
+
status = nc_get_var1_double(ncid,varid,c_start,ptr);
|
2685
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2686
|
+
|
2687
|
+
OBJ_TAINT(NMatrix);
|
2688
|
+
return NMatrix;
|
2689
|
+
|
2690
|
+
}
|
2691
|
+
|
2692
|
+
VALUE
|
2693
|
+
NetCDF_get_vars_char(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
2694
|
+
{
|
2695
|
+
int ncid;
|
2696
|
+
int varid;
|
2697
|
+
int status;
|
2698
|
+
unsigned char *ptr;
|
2699
|
+
int i;
|
2700
|
+
struct NetCDFVar *Netcdf_var;
|
2701
|
+
int l_start, l_end;
|
2702
|
+
size_t *c_start;
|
2703
|
+
size_t *c_count;
|
2704
|
+
ptrdiff_t *c_stride;
|
2705
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2706
|
+
int ndims;
|
2707
|
+
int *dimids;
|
2708
|
+
size_t dimlen;
|
2709
|
+
VALUE NMatrix;
|
2710
|
+
|
2711
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2712
|
+
ncid = Netcdf_var->ncid;
|
2713
|
+
varid = Netcdf_var->varid;
|
2714
|
+
|
2715
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
2716
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2717
|
+
if(ndims == 0) {
|
2718
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2719
|
+
}
|
2720
|
+
|
2721
|
+
dimids = ALLOCA_N(int,ndims);
|
2722
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2723
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2724
|
+
|
2725
|
+
Check_Type(start,T_ARRAY);
|
2726
|
+
if(RARRAY_LEN(start) < ndims){
|
2727
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
2728
|
+
}
|
2729
|
+
c_start = ALLOCA_N(size_t,ndims);
|
2730
|
+
for(i=0; i<ndims; i++){
|
2731
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2732
|
+
|
2733
|
+
if(l_start < 0) {
|
2734
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
2735
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2736
|
+
l_start += dimlen;
|
2737
|
+
}
|
2738
|
+
c_start[i]=l_start;
|
2739
|
+
}
|
2740
|
+
|
2741
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
2742
|
+
switch(TYPE(stride)){
|
2743
|
+
case T_NIL:
|
2744
|
+
for(i=0; i<ndims; i++){
|
2745
|
+
c_stride[i]=1;
|
2746
|
+
}
|
2747
|
+
break;
|
2748
|
+
default:
|
2749
|
+
Check_Type(stride,T_ARRAY);
|
2750
|
+
if(RARRAY_LEN(stride) < ndims) {
|
2751
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride is too short\n");
|
2752
|
+
}
|
2753
|
+
for(i=0;i<ndims; i++){
|
2754
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
2755
|
+
if(c_stride[i]==0){
|
2756
|
+
rb_raise(rb_eNetcdfError,"stride cannot be zero\n");
|
2757
|
+
}
|
2758
|
+
}
|
2759
|
+
}
|
2760
|
+
|
2761
|
+
c_count=ALLOCA_N(size_t,ndims);
|
2762
|
+
switch(TYPE(end)){
|
2763
|
+
case T_NIL:
|
2764
|
+
for(i=0; i<ndims; i++){
|
2765
|
+
nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2766
|
+
c_count[i]=(dimlen-c_start[i]-1)/c_stride[i]+1;
|
2767
|
+
}
|
2768
|
+
break;
|
2769
|
+
default:
|
2770
|
+
Check_Type(end,T_ARRAY);
|
2771
|
+
if(RARRAY_LEN(end) <ndims) {
|
2772
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
2773
|
+
}
|
2774
|
+
for(i=0; i<ndims; i++){
|
2775
|
+
l_end= NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
2776
|
+
if(l_end < 0) {
|
2777
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2778
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2779
|
+
l_end +=dimlen;
|
2780
|
+
}
|
2781
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
2782
|
+
}
|
2783
|
+
}
|
2784
|
+
|
2785
|
+
|
2786
|
+
shape = ALLOCA_N(na_shape_t,ndims);
|
2787
|
+
for(i=0;i<ndims;i++){
|
2788
|
+
shape[RCMAJOR(ndims,i)]=c_count[i];
|
2789
|
+
}
|
2790
|
+
|
2791
|
+
Cbyte_to_NMatrix(NMatrix,ndims,shape,ptr);
|
2792
|
+
|
2793
|
+
status = nc_get_vars_text(ncid,varid,c_start,c_count,c_stride,(char *)ptr);
|
2794
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2795
|
+
|
2796
|
+
OBJ_TAINT(NMatrix);
|
2797
|
+
return NMatrix;
|
2798
|
+
}
|
2799
|
+
|
2800
|
+
VALUE
|
2801
|
+
NetCDF_get_vars_byte(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
2802
|
+
{
|
2803
|
+
int ncid;
|
2804
|
+
int varid;
|
2805
|
+
int status;
|
2806
|
+
unsigned char *ptr;
|
2807
|
+
int i;
|
2808
|
+
struct NetCDFVar *Netcdf_var;
|
2809
|
+
int l_start, l_end;
|
2810
|
+
size_t *c_start;
|
2811
|
+
size_t *c_count;
|
2812
|
+
ptrdiff_t *c_stride;
|
2813
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2814
|
+
int ndims;
|
2815
|
+
int *dimids;
|
2816
|
+
size_t dimlen;
|
2817
|
+
VALUE NMatrix;
|
2818
|
+
|
2819
|
+
CR_PSTR("Starting");
|
2820
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2821
|
+
ncid = Netcdf_var->ncid;
|
2822
|
+
varid = Netcdf_var->varid;
|
2823
|
+
|
2824
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
2825
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2826
|
+
if(ndims == 0) {
|
2827
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2828
|
+
}
|
2829
|
+
|
2830
|
+
dimids = ALLOCA_N(int,ndims);
|
2831
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2832
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2833
|
+
|
2834
|
+
Check_Type(start,T_ARRAY);
|
2835
|
+
if(RARRAY_LEN(start) < ndims){
|
2836
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
2837
|
+
}
|
2838
|
+
c_start = ALLOCA_N(size_t,ndims);
|
2839
|
+
for(i=0; i<ndims; i++){
|
2840
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2841
|
+
|
2842
|
+
if(l_start < 0) {
|
2843
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
2844
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2845
|
+
l_start += dimlen;
|
2846
|
+
}
|
2847
|
+
c_start[i]=l_start;
|
2848
|
+
}
|
2849
|
+
|
2850
|
+
CR_PSTR("Converting stride");
|
2851
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
2852
|
+
switch(TYPE(stride)){
|
2853
|
+
case T_NIL:
|
2854
|
+
for(i=0; i<ndims; i++){
|
2855
|
+
c_stride[i]=1;
|
2856
|
+
}
|
2857
|
+
break;
|
2858
|
+
default:
|
2859
|
+
Check_Type(stride,T_ARRAY);
|
2860
|
+
if(RARRAY_LEN(stride) < ndims) {
|
2861
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride is too short\n");
|
2862
|
+
}
|
2863
|
+
for(i=0;i<ndims; i++){
|
2864
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
2865
|
+
if(c_stride[i]==0){
|
2866
|
+
rb_raise(rb_eNetcdfError,"stride cannot be zero\n");
|
2867
|
+
}
|
2868
|
+
}
|
2869
|
+
}
|
2870
|
+
|
2871
|
+
CR_PSTR("Converting count");
|
2872
|
+
c_count=ALLOCA_N(size_t,ndims);
|
2873
|
+
switch(TYPE(end)){
|
2874
|
+
case T_NIL:
|
2875
|
+
for(i=0; i<ndims; i++){
|
2876
|
+
nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2877
|
+
c_count[i]=(dimlen-c_start[i]-1)/c_stride[i]+1;
|
2878
|
+
}
|
2879
|
+
break;
|
2880
|
+
default:
|
2881
|
+
Check_Type(end,T_ARRAY);
|
2882
|
+
if(RARRAY_LEN(end) <ndims) {
|
2883
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
2884
|
+
}
|
2885
|
+
for(i=0; i<ndims; i++){
|
2886
|
+
l_end= NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
2887
|
+
if(l_end < 0) {
|
2888
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2889
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2890
|
+
l_end +=dimlen;
|
2891
|
+
}
|
2892
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
2893
|
+
}
|
2894
|
+
}
|
2895
|
+
|
2896
|
+
|
2897
|
+
shape = ALLOCA_N(na_shape_t,ndims);
|
2898
|
+
for(i=0;i<ndims;i++){
|
2899
|
+
shape[RCMAJOR(ndims,i)]=c_count[i];
|
2900
|
+
}
|
2901
|
+
|
2902
|
+
CR_PSTR("Converting to NMatrix");
|
2903
|
+
|
2904
|
+
Cbyte_to_NMatrix(NMatrix,ndims,shape,ptr);
|
2905
|
+
|
2906
|
+
CR_PSTR("Reading variable");
|
2907
|
+
status = nc_get_vars_uchar(ncid,varid,c_start,c_count,c_stride,ptr);
|
2908
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2909
|
+
|
2910
|
+
CR_PSTR("Finished");
|
2911
|
+
OBJ_TAINT(NMatrix);
|
2912
|
+
return NMatrix;
|
2913
|
+
}
|
2914
|
+
|
2915
|
+
VALUE
|
2916
|
+
NetCDF_get_vars_sint(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
2917
|
+
{
|
2918
|
+
int ncid;
|
2919
|
+
int varid;
|
2920
|
+
int status;
|
2921
|
+
short *ptr;
|
2922
|
+
int i;
|
2923
|
+
struct NetCDFVar *Netcdf_var;
|
2924
|
+
int l_start, l_end;
|
2925
|
+
size_t *c_start;
|
2926
|
+
size_t *c_count;
|
2927
|
+
ptrdiff_t *c_stride;
|
2928
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
2929
|
+
int ndims;
|
2930
|
+
int *dimids;
|
2931
|
+
size_t dimlen;
|
2932
|
+
VALUE NMatrix;
|
2933
|
+
|
2934
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
2935
|
+
ncid = Netcdf_var->ncid;
|
2936
|
+
varid = Netcdf_var->varid;
|
2937
|
+
|
2938
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
2939
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2940
|
+
if(ndims == 0) {
|
2941
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
2942
|
+
}
|
2943
|
+
|
2944
|
+
dimids = ALLOCA_N(int,ndims);
|
2945
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
2946
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2947
|
+
|
2948
|
+
Check_Type(start,T_ARRAY);
|
2949
|
+
if(RARRAY_LEN(start) < ndims){
|
2950
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
2951
|
+
}
|
2952
|
+
c_start = ALLOCA_N(size_t,ndims);
|
2953
|
+
for(i=0; i<ndims; i++){
|
2954
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
2955
|
+
|
2956
|
+
if(l_start < 0) {
|
2957
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
2958
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
2959
|
+
l_start += dimlen;
|
2960
|
+
}
|
2961
|
+
c_start[i]=l_start;
|
2962
|
+
}
|
2963
|
+
|
2964
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
2965
|
+
switch(TYPE(stride)){
|
2966
|
+
case T_NIL:
|
2967
|
+
for(i=0; i<ndims; i++){
|
2968
|
+
c_stride[i]=1;
|
2969
|
+
}
|
2970
|
+
break;
|
2971
|
+
default:
|
2972
|
+
Check_Type(stride,T_ARRAY);
|
2973
|
+
if(RARRAY_LEN(stride) < ndims) {
|
2974
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride is too short\n");
|
2975
|
+
}
|
2976
|
+
for(i=0;i<ndims; i++){
|
2977
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
2978
|
+
if(c_stride[i]==0){
|
2979
|
+
rb_raise(rb_eNetcdfError,"stride cannot be zero\n");
|
2980
|
+
}
|
2981
|
+
}
|
2982
|
+
}
|
2983
|
+
|
2984
|
+
c_count=ALLOCA_N(size_t,ndims);
|
2985
|
+
switch(TYPE(end)){
|
2986
|
+
case T_NIL:
|
2987
|
+
for(i=0; i<ndims; i++){
|
2988
|
+
nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
2989
|
+
c_count[i]=(dimlen-c_start[i]-1)/c_stride[i]+1;
|
2990
|
+
}
|
2991
|
+
break;
|
2992
|
+
default:
|
2993
|
+
Check_Type(end,T_ARRAY);
|
2994
|
+
if(RARRAY_LEN(end) <ndims) {
|
2995
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
2996
|
+
}
|
2997
|
+
for(i=0; i<ndims; i++){
|
2998
|
+
l_end= NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
2999
|
+
if(l_end < 0) {
|
3000
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3001
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3002
|
+
l_end +=dimlen;
|
3003
|
+
}
|
3004
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
3005
|
+
}
|
3006
|
+
}
|
3007
|
+
|
3008
|
+
|
3009
|
+
shape = ALLOCA_N(na_shape_t,ndims);
|
3010
|
+
for(i=0;i<ndims;i++){
|
3011
|
+
shape[RCMAJOR(ndims,i)]=c_count[i];
|
3012
|
+
}
|
3013
|
+
|
3014
|
+
Csint_to_NMatrix(NMatrix,ndims,shape,ptr);
|
3015
|
+
|
3016
|
+
|
3017
|
+
status = nc_get_vars_short(ncid,varid,c_start,c_count,c_stride,ptr);
|
3018
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3019
|
+
|
3020
|
+
OBJ_TAINT(NMatrix);
|
3021
|
+
return NMatrix;
|
3022
|
+
}
|
3023
|
+
|
3024
|
+
VALUE
|
3025
|
+
NetCDF_get_vars_int(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
3026
|
+
{
|
3027
|
+
int ncid;
|
3028
|
+
int varid;
|
3029
|
+
int status;
|
3030
|
+
int *ptr;
|
3031
|
+
int i;
|
3032
|
+
struct NetCDFVar *Netcdf_var;
|
3033
|
+
int l_start, l_end;
|
3034
|
+
size_t *c_start;
|
3035
|
+
size_t *c_count;
|
3036
|
+
ptrdiff_t *c_stride;
|
3037
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
3038
|
+
int ndims;
|
3039
|
+
int *dimids;
|
3040
|
+
size_t dimlen;
|
3041
|
+
VALUE NMatrix;
|
3042
|
+
|
3043
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3044
|
+
ncid = Netcdf_var->ncid;
|
3045
|
+
varid = Netcdf_var->varid;
|
3046
|
+
|
3047
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3048
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3049
|
+
if(ndims == 0) {
|
3050
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
3051
|
+
}
|
3052
|
+
|
3053
|
+
dimids = ALLOCA_N(int,ndims);
|
3054
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3055
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3056
|
+
|
3057
|
+
Check_Type(start,T_ARRAY);
|
3058
|
+
if(RARRAY_LEN(start) < ndims){
|
3059
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
3060
|
+
}
|
3061
|
+
c_start = ALLOCA_N(size_t,ndims);
|
3062
|
+
for(i=0; i<ndims; i++){
|
3063
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3064
|
+
|
3065
|
+
if(l_start < 0) {
|
3066
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
3067
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3068
|
+
l_start += dimlen;
|
3069
|
+
}
|
3070
|
+
c_start[i]=l_start;
|
3071
|
+
}
|
3072
|
+
|
3073
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
3074
|
+
switch(TYPE(stride)){
|
3075
|
+
case T_NIL:
|
3076
|
+
for(i=0; i<ndims; i++){
|
3077
|
+
c_stride[i]=1;
|
3078
|
+
}
|
3079
|
+
break;
|
3080
|
+
default:
|
3081
|
+
Check_Type(stride,T_ARRAY);
|
3082
|
+
if(RARRAY_LEN(stride) < ndims) {
|
3083
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride is too short\n");
|
3084
|
+
}
|
3085
|
+
for(i=0;i<ndims; i++){
|
3086
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
3087
|
+
if(c_stride[i]==0){
|
3088
|
+
rb_raise(rb_eNetcdfError,"stride cannot be zero\n");
|
3089
|
+
}
|
3090
|
+
}
|
3091
|
+
}
|
3092
|
+
|
3093
|
+
c_count=ALLOCA_N(size_t,ndims);
|
3094
|
+
switch(TYPE(end)){
|
3095
|
+
case T_NIL:
|
3096
|
+
for(i=0; i<ndims; i++){
|
3097
|
+
nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3098
|
+
c_count[i]=(dimlen-c_start[i]-1)/c_stride[i]+1;
|
3099
|
+
}
|
3100
|
+
break;
|
3101
|
+
default:
|
3102
|
+
Check_Type(end,T_ARRAY);
|
3103
|
+
if(RARRAY_LEN(end) <ndims) {
|
3104
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
3105
|
+
}
|
3106
|
+
for(i=0; i<ndims; i++){
|
3107
|
+
l_end= NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
3108
|
+
if(l_end < 0) {
|
3109
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3110
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3111
|
+
l_end +=dimlen;
|
3112
|
+
}
|
3113
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
3114
|
+
}
|
3115
|
+
}
|
3116
|
+
|
3117
|
+
|
3118
|
+
shape = ALLOCA_N(na_shape_t,ndims);
|
3119
|
+
for(i=0;i<ndims;i++){
|
3120
|
+
shape[RCMAJOR(ndims,i)]=c_count[i];
|
3121
|
+
}
|
3122
|
+
|
3123
|
+
Clint_to_NMatrix(NMatrix,ndims,shape,ptr);
|
3124
|
+
|
3125
|
+
|
3126
|
+
status = nc_get_vars_int(ncid,varid,c_start,c_count,c_stride,ptr);
|
3127
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3128
|
+
|
3129
|
+
OBJ_TAINT(NMatrix);
|
3130
|
+
return NMatrix;
|
3131
|
+
}
|
3132
|
+
|
3133
|
+
VALUE
|
3134
|
+
NetCDF_get_vars_float(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
3135
|
+
{
|
3136
|
+
int ncid;
|
3137
|
+
int varid;
|
3138
|
+
int status;
|
3139
|
+
float *ptr;
|
3140
|
+
int i;
|
3141
|
+
struct NetCDFVar *Netcdf_var;
|
3142
|
+
int l_start, l_end;
|
3143
|
+
size_t *c_start;
|
3144
|
+
size_t *c_count;
|
3145
|
+
ptrdiff_t *c_stride;
|
3146
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
3147
|
+
int ndims;
|
3148
|
+
int *dimids;
|
3149
|
+
size_t dimlen;
|
3150
|
+
VALUE NMatrix;
|
3151
|
+
|
3152
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3153
|
+
ncid = Netcdf_var->ncid;
|
3154
|
+
varid = Netcdf_var->varid;
|
3155
|
+
|
3156
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3157
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3158
|
+
if(ndims == 0) {
|
3159
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
3160
|
+
}
|
3161
|
+
|
3162
|
+
dimids = ALLOCA_N(int,ndims);
|
3163
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3164
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3165
|
+
|
3166
|
+
Check_Type(start,T_ARRAY);
|
3167
|
+
if(RARRAY_LEN(start) < ndims){
|
3168
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
3169
|
+
}
|
3170
|
+
c_start = ALLOCA_N(size_t,ndims);
|
3171
|
+
for(i=0; i<ndims; i++){
|
3172
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3173
|
+
|
3174
|
+
if(l_start < 0) {
|
3175
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
3176
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3177
|
+
l_start += dimlen;
|
3178
|
+
}
|
3179
|
+
c_start[i]=l_start;
|
3180
|
+
}
|
3181
|
+
|
3182
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
3183
|
+
switch(TYPE(stride)){
|
3184
|
+
case T_NIL:
|
3185
|
+
for(i=0; i<ndims; i++){
|
3186
|
+
c_stride[i]=1;
|
3187
|
+
}
|
3188
|
+
break;
|
3189
|
+
default:
|
3190
|
+
Check_Type(stride,T_ARRAY);
|
3191
|
+
if(RARRAY_LEN(stride) < ndims) {
|
3192
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride is too short\n");
|
3193
|
+
}
|
3194
|
+
for(i=0;i<ndims; i++){
|
3195
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
3196
|
+
if(c_stride[i]==0){
|
3197
|
+
rb_raise(rb_eNetcdfError,"stride cannot be zero\n");
|
3198
|
+
}
|
3199
|
+
}
|
3200
|
+
}
|
3201
|
+
|
3202
|
+
c_count=ALLOCA_N(size_t,ndims);
|
3203
|
+
switch(TYPE(end)){
|
3204
|
+
case T_NIL:
|
3205
|
+
for(i=0; i<ndims; i++){
|
3206
|
+
nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3207
|
+
c_count[i]=(dimlen-c_start[i]-1)/c_stride[i]+1;
|
3208
|
+
}
|
3209
|
+
break;
|
3210
|
+
default:
|
3211
|
+
Check_Type(end,T_ARRAY);
|
3212
|
+
if(RARRAY_LEN(end) <ndims) {
|
3213
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
3214
|
+
}
|
3215
|
+
for(i=0; i<ndims; i++){
|
3216
|
+
l_end= NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
3217
|
+
if(l_end < 0) {
|
3218
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3219
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3220
|
+
l_end +=dimlen;
|
3221
|
+
}
|
3222
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
3223
|
+
}
|
3224
|
+
}
|
3225
|
+
|
3226
|
+
|
3227
|
+
shape = ALLOCA_N(na_shape_t,ndims);
|
3228
|
+
for(i=0;i<ndims;i++){
|
3229
|
+
shape[RCMAJOR(ndims,i)]=c_count[i];
|
3230
|
+
}
|
3231
|
+
|
3232
|
+
Cfloat_to_NMatrix(NMatrix,ndims,shape,ptr);
|
3233
|
+
|
3234
|
+
|
3235
|
+
status = nc_get_vars_float(ncid,varid,c_start,c_count,c_stride,ptr);
|
3236
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3237
|
+
|
3238
|
+
OBJ_TAINT(NMatrix);
|
3239
|
+
return NMatrix;
|
3240
|
+
}
|
3241
|
+
|
3242
|
+
VALUE
|
3243
|
+
NetCDF_get_vars_double(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
3244
|
+
{
|
3245
|
+
int ncid;
|
3246
|
+
int varid;
|
3247
|
+
int status;
|
3248
|
+
double *ptr;
|
3249
|
+
int i;
|
3250
|
+
struct NetCDFVar *Netcdf_var;
|
3251
|
+
int l_start, l_end;
|
3252
|
+
size_t *c_start;
|
3253
|
+
size_t *c_count;
|
3254
|
+
ptrdiff_t *c_stride;
|
3255
|
+
na_shape_t *shape; /* NMatrix uses int instead of size_t */
|
3256
|
+
int ndims;
|
3257
|
+
int *dimids;
|
3258
|
+
size_t dimlen;
|
3259
|
+
VALUE NMatrix;
|
3260
|
+
|
3261
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3262
|
+
ncid = Netcdf_var->ncid;
|
3263
|
+
varid = Netcdf_var->varid;
|
3264
|
+
|
3265
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3266
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3267
|
+
if(ndims == 0) {
|
3268
|
+
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
3269
|
+
}
|
3270
|
+
|
3271
|
+
dimids = ALLOCA_N(int,ndims);
|
3272
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3273
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3274
|
+
|
3275
|
+
Check_Type(start,T_ARRAY);
|
3276
|
+
if(RARRAY_LEN(start) < ndims){
|
3277
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
3278
|
+
}
|
3279
|
+
c_start = ALLOCA_N(size_t,ndims);
|
3280
|
+
for(i=0; i<ndims; i++){
|
3281
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3282
|
+
|
3283
|
+
if(l_start < 0) {
|
3284
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
3285
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3286
|
+
l_start += dimlen;
|
3287
|
+
}
|
3288
|
+
c_start[i]=l_start;
|
3289
|
+
}
|
3290
|
+
|
3291
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
3292
|
+
switch(TYPE(stride)){
|
3293
|
+
case T_NIL:
|
3294
|
+
for(i=0; i<ndims; i++){
|
3295
|
+
c_stride[i]=1;
|
3296
|
+
}
|
3297
|
+
break;
|
3298
|
+
default:
|
3299
|
+
Check_Type(stride,T_ARRAY);
|
3300
|
+
if(RARRAY_LEN(stride) < ndims) {
|
3301
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride is too short\n");
|
3302
|
+
}
|
3303
|
+
for(i=0;i<ndims; i++){
|
3304
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
3305
|
+
if(c_stride[i]==0){
|
3306
|
+
rb_raise(rb_eNetcdfError,"stride cannot be zero\n");
|
3307
|
+
}
|
3308
|
+
}
|
3309
|
+
}
|
3310
|
+
|
3311
|
+
c_count=ALLOCA_N(size_t,ndims);
|
3312
|
+
switch(TYPE(end)){
|
3313
|
+
case T_NIL:
|
3314
|
+
for(i=0; i<ndims; i++){
|
3315
|
+
nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3316
|
+
c_count[i]=(dimlen-c_start[i]-1)/c_stride[i]+1;
|
3317
|
+
}
|
3318
|
+
break;
|
3319
|
+
default:
|
3320
|
+
Check_Type(end,T_ARRAY);
|
3321
|
+
if(RARRAY_LEN(end) <ndims) {
|
3322
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
3323
|
+
}
|
3324
|
+
for(i=0; i<ndims; i++){
|
3325
|
+
l_end= NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
3326
|
+
if(l_end < 0) {
|
3327
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3328
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3329
|
+
l_end +=dimlen;
|
3330
|
+
}
|
3331
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
3332
|
+
}
|
3333
|
+
}
|
3334
|
+
|
3335
|
+
|
3336
|
+
shape = ALLOCA_N(na_shape_t,ndims);
|
3337
|
+
for(i=0;i<ndims;i++){
|
3338
|
+
shape[RCMAJOR(ndims,i)]=c_count[i];
|
3339
|
+
}
|
3340
|
+
|
3341
|
+
Cdouble_to_NMatrix(NMatrix,ndims,shape,ptr);
|
3342
|
+
|
3343
|
+
status = nc_get_vars_double(ncid,varid,c_start,c_count,c_stride,ptr);
|
3344
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3345
|
+
|
3346
|
+
OBJ_TAINT(NMatrix);
|
3347
|
+
return NMatrix;
|
3348
|
+
}
|
3349
|
+
|
3350
|
+
|
3351
|
+
VALUE
|
3352
|
+
NetCDF_put_var_char(VALUE Var,VALUE NMatrix)
|
3353
|
+
{
|
3354
|
+
int ncid;
|
3355
|
+
int varid;
|
3356
|
+
int status;
|
3357
|
+
unsigned char *ptr,scalar;
|
3358
|
+
na_shape_t len,i=0;
|
3359
|
+
int j;
|
3360
|
+
struct NetCDFVar *Netcdf_var;
|
3361
|
+
na_shape_t nc_tlen=1;
|
3362
|
+
int ndimsp;
|
3363
|
+
int dimids[NC_MAX_DIMS];
|
3364
|
+
size_t lengthp;
|
3365
|
+
char *var_name;
|
3366
|
+
|
3367
|
+
rb_secure(1);
|
3368
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3369
|
+
ncid=Netcdf_var->ncid;
|
3370
|
+
varid=Netcdf_var->varid;
|
3371
|
+
|
3372
|
+
NMatrix_to_Cbyte_len(NMatrix,ptr,len);
|
3373
|
+
|
3374
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
3375
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3376
|
+
for(j=0;j<ndimsp;j++){
|
3377
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3378
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3379
|
+
nc_inq_dimlen(ncid,dimids[j],&lengthp);
|
3380
|
+
nc_tlen=lengthp*nc_tlen;
|
3381
|
+
}
|
3382
|
+
if(len == 1 && len != nc_tlen){
|
3383
|
+
scalar = *ptr;
|
3384
|
+
ptr = ALLOCA_N(unsigned char,nc_tlen);
|
3385
|
+
for(i=0;i<nc_tlen;i++){ptr[i]=scalar;}
|
3386
|
+
} else if(len != nc_tlen){
|
3387
|
+
var_name=ALLOCA_N(char,NC_MAX_NAME);
|
3388
|
+
status = nc_inq_varname(ncid,varid,var_name);
|
3389
|
+
if(status != NC_NOERR) NC_RAISE(status );
|
3390
|
+
rb_raise(rb_eNetcdfError,"Length of NMatrix don't equal to length of total array in the '%s'\n",var_name);
|
3391
|
+
}
|
3392
|
+
status = nc_put_var_text(ncid,varid,(char *)ptr);
|
3393
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
3394
|
+
return Qnil;
|
3395
|
+
}
|
3396
|
+
|
3397
|
+
VALUE
|
3398
|
+
NetCDF_put_var_byte(VALUE Var,VALUE NMatrix)
|
3399
|
+
{
|
3400
|
+
int ncid;
|
3401
|
+
int varid;
|
3402
|
+
int status;
|
3403
|
+
unsigned char *ptr,scalar;
|
3404
|
+
na_shape_t len,i=0;
|
3405
|
+
int j;
|
3406
|
+
struct NetCDFVar *Netcdf_var;
|
3407
|
+
na_shape_t nc_tlen=1;
|
3408
|
+
int ndimsp;
|
3409
|
+
int dimids[NC_MAX_DIMS];
|
3410
|
+
size_t lengthp;
|
3411
|
+
char *var_name;
|
3412
|
+
|
3413
|
+
rb_secure(1);
|
3414
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3415
|
+
ncid=Netcdf_var->ncid;
|
3416
|
+
varid=Netcdf_var->varid;
|
3417
|
+
|
3418
|
+
NMatrix_to_Cbyte_len(NMatrix,ptr,len);
|
3419
|
+
|
3420
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
3421
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3422
|
+
for(j=0;j<ndimsp;j++){
|
3423
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3424
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3425
|
+
nc_inq_dimlen(ncid,dimids[j],&lengthp);
|
3426
|
+
nc_tlen=lengthp*nc_tlen;
|
3427
|
+
}
|
3428
|
+
if(len == 1 && len != nc_tlen){
|
3429
|
+
scalar = *ptr;
|
3430
|
+
ptr = ALLOCA_N(unsigned char,nc_tlen);
|
3431
|
+
for(i=0;i<nc_tlen;i++){ptr[i]=scalar;}
|
3432
|
+
} else if(len != nc_tlen){
|
3433
|
+
var_name=ALLOCA_N(char,NC_MAX_NAME);
|
3434
|
+
status = nc_inq_varname(ncid,varid,var_name);
|
3435
|
+
if(status != NC_NOERR) NC_RAISE(status );
|
3436
|
+
rb_raise(rb_eNetcdfError,"Length of NMatrix don't equal to length of total array in the '%s'\n",var_name);
|
3437
|
+
}
|
3438
|
+
status = nc_put_var_uchar(ncid,varid,ptr);
|
3439
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
3440
|
+
return Qnil;
|
3441
|
+
}
|
3442
|
+
|
3443
|
+
VALUE
|
3444
|
+
NetCDF_put_var_short(VALUE Var,VALUE NMatrix)
|
3445
|
+
{
|
3446
|
+
int ncid;
|
3447
|
+
int varid;
|
3448
|
+
int status;
|
3449
|
+
short *ptr,scalar;
|
3450
|
+
na_shape_t len,i=0;
|
3451
|
+
int j;
|
3452
|
+
struct NetCDFVar *Netcdf_var;
|
3453
|
+
na_shape_t nc_tlen=1;
|
3454
|
+
int ndimsp;
|
3455
|
+
int dimids[NC_MAX_DIMS];
|
3456
|
+
size_t lengthp;
|
3457
|
+
char *var_name;
|
3458
|
+
|
3459
|
+
rb_secure(1);
|
3460
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3461
|
+
ncid=Netcdf_var->ncid;
|
3462
|
+
varid=Netcdf_var->varid;
|
3463
|
+
NMatrix_to_Csint_len(NMatrix,ptr,len);
|
3464
|
+
|
3465
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
3466
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3467
|
+
for(j=0;j<ndimsp;j++){
|
3468
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3469
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3470
|
+
nc_inq_dimlen(ncid,dimids[j],&lengthp);
|
3471
|
+
nc_tlen=lengthp*nc_tlen;
|
3472
|
+
}
|
3473
|
+
if(len == 1 && len != nc_tlen){
|
3474
|
+
scalar = *ptr;
|
3475
|
+
ptr = ALLOCA_N(short,nc_tlen);
|
3476
|
+
for(i=0;i<nc_tlen;i++){ptr[i]=scalar;}
|
3477
|
+
} else if(len != nc_tlen){
|
3478
|
+
var_name=ALLOCA_N(char,NC_MAX_NAME);
|
3479
|
+
status = nc_inq_varname(ncid,varid,var_name);
|
3480
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3481
|
+
rb_raise(rb_eNetcdfError,"Length of NMatrix don't equal to length of total array length in the '%s'\n",var_name);
|
3482
|
+
}
|
3483
|
+
|
3484
|
+
status = nc_put_var_short(ncid,varid,ptr);
|
3485
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
3486
|
+
return Qnil;
|
3487
|
+
}
|
3488
|
+
|
3489
|
+
VALUE
|
3490
|
+
NetCDF_put_var_int(VALUE Var,VALUE NMatrix)
|
3491
|
+
{
|
3492
|
+
int ncid;
|
3493
|
+
int varid;
|
3494
|
+
int status;
|
3495
|
+
int *ptr,scalar;
|
3496
|
+
na_shape_t len,i=0;
|
3497
|
+
struct NetCDFVar *Netcdf_var;
|
3498
|
+
na_shape_t nc_tlen=1;
|
3499
|
+
int ndimsp;
|
3500
|
+
int dimids[NC_MAX_DIMS];
|
3501
|
+
size_t lengthp;
|
3502
|
+
char *var_name;
|
3503
|
+
int j;
|
3504
|
+
|
3505
|
+
rb_secure(1);
|
3506
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3507
|
+
ncid=Netcdf_var->ncid;
|
3508
|
+
varid=Netcdf_var->varid;
|
3509
|
+
|
3510
|
+
NMatrix_to_Clint_len(NMatrix,ptr,len);
|
3511
|
+
|
3512
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
3513
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3514
|
+
for(j=0;j<ndimsp;j++){
|
3515
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3516
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3517
|
+
nc_inq_dimlen(ncid,dimids[j],&lengthp);
|
3518
|
+
nc_tlen=lengthp*nc_tlen;
|
3519
|
+
}
|
3520
|
+
if(len == 1 && len != nc_tlen){
|
3521
|
+
scalar = *ptr;
|
3522
|
+
ptr = ALLOCA_N(int,nc_tlen);
|
3523
|
+
for(i=0;i<nc_tlen;i++){ptr[i]=scalar;}
|
3524
|
+
} else if(len != nc_tlen){
|
3525
|
+
var_name=ALLOCA_N(char,NC_MAX_NAME);
|
3526
|
+
status = nc_inq_varname(ncid,varid,var_name);
|
3527
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3528
|
+
rb_raise(rb_eNetcdfError,"Length of NMatrix don't equal to length of total array length in the '%s'\n",var_name);
|
3529
|
+
}
|
3530
|
+
|
3531
|
+
|
3532
|
+
status = nc_put_var_int(ncid,varid,ptr);
|
3533
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
3534
|
+
return Qnil;
|
3535
|
+
}
|
3536
|
+
|
3537
|
+
|
3538
|
+
VALUE
|
3539
|
+
NetCDF_put_var_float(VALUE Var,VALUE NMatrix)
|
3540
|
+
{
|
3541
|
+
int ncid;
|
3542
|
+
int varid;
|
3543
|
+
int status;
|
3544
|
+
float *ptr,scalar;
|
3545
|
+
na_shape_t len,i=0;
|
3546
|
+
int j;
|
3547
|
+
struct NetCDFVar *Netcdf_var;
|
3548
|
+
na_shape_t nc_tlen=1;
|
3549
|
+
int ndimsp;
|
3550
|
+
int dimids[NC_MAX_DIMS];
|
3551
|
+
size_t lengthp;
|
3552
|
+
char *var_name;
|
3553
|
+
|
3554
|
+
|
3555
|
+
rb_secure(1);
|
3556
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3557
|
+
ncid=Netcdf_var->ncid;
|
3558
|
+
varid=Netcdf_var->varid;
|
3559
|
+
|
3560
|
+
NMatrix_to_Cfloat_len(NMatrix,ptr,len);
|
3561
|
+
|
3562
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
3563
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3564
|
+
for(j=0;j<ndimsp;j++){
|
3565
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3566
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3567
|
+
nc_inq_dimlen(ncid,dimids[j],&lengthp);
|
3568
|
+
nc_tlen=lengthp*nc_tlen;
|
3569
|
+
}
|
3570
|
+
if(len == 1 && len != nc_tlen){
|
3571
|
+
scalar = *ptr;
|
3572
|
+
ptr = ALLOCA_N(float,nc_tlen);
|
3573
|
+
for(i=0;i<nc_tlen;i++){ptr[i]=scalar;}
|
3574
|
+
} else if(len != nc_tlen){
|
3575
|
+
var_name=ALLOCA_N(char,NC_MAX_NAME);
|
3576
|
+
status = nc_inq_varname(ncid,varid,var_name);
|
3577
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3578
|
+
rb_raise(rb_eNetcdfError,"Length of NMatrix don't equal to length of total array length in the '%s'\n",var_name);
|
3579
|
+
}
|
3580
|
+
|
3581
|
+
status = nc_put_var_float(ncid,varid,ptr);
|
3582
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
3583
|
+
return Qnil;
|
3584
|
+
}
|
3585
|
+
|
3586
|
+
VALUE
|
3587
|
+
NetCDF_put_var_double(VALUE Var,VALUE NMatrix)
|
3588
|
+
{
|
3589
|
+
int ncid;
|
3590
|
+
int varid;
|
3591
|
+
int status;
|
3592
|
+
double *ptr,scalar;
|
3593
|
+
na_shape_t len,i=0;
|
3594
|
+
struct NetCDFVar *Netcdf_var;
|
3595
|
+
na_shape_t nc_tlen=1;
|
3596
|
+
int ndimsp;
|
3597
|
+
int dimids[NC_MAX_DIMS];
|
3598
|
+
size_t lengthp;
|
3599
|
+
char *var_name;
|
3600
|
+
int j;
|
3601
|
+
|
3602
|
+
|
3603
|
+
rb_secure(1);
|
3604
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3605
|
+
ncid=Netcdf_var->ncid;
|
3606
|
+
varid=Netcdf_var->varid;
|
3607
|
+
|
3608
|
+
NMatrix_to_Cdouble_len(NMatrix,ptr,len);
|
3609
|
+
|
3610
|
+
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
3611
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3612
|
+
for(j=0;j<ndimsp;j++){
|
3613
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3614
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3615
|
+
nc_inq_dimlen(ncid,dimids[j],&lengthp);
|
3616
|
+
nc_tlen=lengthp*nc_tlen;
|
3617
|
+
}
|
3618
|
+
if(len == 1 && len != nc_tlen){
|
3619
|
+
scalar = *ptr;
|
3620
|
+
ptr = ALLOCA_N(double,nc_tlen);
|
3621
|
+
for(i=0;i<nc_tlen;i++){ptr[i]=scalar;}
|
3622
|
+
} else if(len != nc_tlen){
|
3623
|
+
var_name=ALLOCA_N(char,NC_MAX_NAME);
|
3624
|
+
status = nc_inq_varname(ncid,varid,var_name);
|
3625
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3626
|
+
rb_raise(rb_eNetcdfError,"Length of NMatrix don't equal to length of total array length in the '%s'\n",var_name);
|
3627
|
+
}
|
3628
|
+
|
3629
|
+
status = nc_put_var_double(ncid,varid,ptr);
|
3630
|
+
if(status !=NC_NOERR) NC_RAISE(status);
|
3631
|
+
return Qnil;
|
3632
|
+
}
|
3633
|
+
|
3634
|
+
VALUE
|
3635
|
+
NetCDF_put_var1_char(VALUE Var,VALUE NMatrix,VALUE start)
|
3636
|
+
{
|
3637
|
+
int ncid;
|
3638
|
+
int varid;
|
3639
|
+
int status;
|
3640
|
+
unsigned char *ptr;
|
3641
|
+
int i;
|
3642
|
+
struct NetCDFVar *Netcdf_var;
|
3643
|
+
int l_start;
|
3644
|
+
size_t *c_start;
|
3645
|
+
int ndims;
|
3646
|
+
int *dimids;
|
3647
|
+
size_t dimlen;
|
3648
|
+
|
3649
|
+
rb_secure(1);
|
3650
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3651
|
+
ncid=Netcdf_var->ncid;
|
3652
|
+
varid=Netcdf_var->varid;
|
3653
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3654
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3655
|
+
|
3656
|
+
|
3657
|
+
dimids = ALLOCA_N(int,ndims);
|
3658
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3659
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3660
|
+
|
3661
|
+
Check_Type(start,T_ARRAY);
|
3662
|
+
if(RARRAY_LEN(start) <ndims) {
|
3663
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
3664
|
+
}
|
3665
|
+
|
3666
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3667
|
+
for(i=0;i<ndims;i++){
|
3668
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3669
|
+
|
3670
|
+
if(l_start < 0) {
|
3671
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3672
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3673
|
+
l_start += dimlen;
|
3674
|
+
}
|
3675
|
+
c_start[i]=l_start;
|
3676
|
+
|
3677
|
+
}
|
3678
|
+
NMatrix_to_Cbyte(NMatrix,ptr);
|
3679
|
+
|
3680
|
+
status = nc_put_var1_text(ncid,varid,c_start,(char *)ptr);
|
3681
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3682
|
+
return Qnil;
|
3683
|
+
}
|
3684
|
+
|
3685
|
+
VALUE
|
3686
|
+
NetCDF_put_var1_byte(VALUE Var,VALUE NMatrix,VALUE start)
|
3687
|
+
{
|
3688
|
+
int ncid;
|
3689
|
+
int varid;
|
3690
|
+
int status;
|
3691
|
+
unsigned char *ptr;
|
3692
|
+
int i;
|
3693
|
+
struct NetCDFVar *Netcdf_var;
|
3694
|
+
int l_start;
|
3695
|
+
size_t *c_start;
|
3696
|
+
int ndims;
|
3697
|
+
int *dimids;
|
3698
|
+
size_t dimlen;
|
3699
|
+
|
3700
|
+
rb_secure(1);
|
3701
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3702
|
+
ncid=Netcdf_var->ncid;
|
3703
|
+
varid=Netcdf_var->varid;
|
3704
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3705
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3706
|
+
|
3707
|
+
|
3708
|
+
dimids = ALLOCA_N(int,ndims);
|
3709
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3710
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3711
|
+
|
3712
|
+
Check_Type(start,T_ARRAY);
|
3713
|
+
if(RARRAY_LEN(start) <ndims) {
|
3714
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
3715
|
+
}
|
3716
|
+
|
3717
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3718
|
+
for(i=0;i<ndims;i++){
|
3719
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3720
|
+
|
3721
|
+
if(l_start < 0) {
|
3722
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3723
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3724
|
+
l_start += dimlen;
|
3725
|
+
}
|
3726
|
+
c_start[i]=l_start;
|
3727
|
+
|
3728
|
+
}
|
3729
|
+
NMatrix_to_Cbyte(NMatrix,ptr);
|
3730
|
+
|
3731
|
+
status = nc_put_var1_uchar(ncid,varid,c_start,ptr);
|
3732
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3733
|
+
return Qnil;
|
3734
|
+
}
|
3735
|
+
|
3736
|
+
VALUE
|
3737
|
+
NetCDF_put_var1_sint(VALUE Var,VALUE NMatrix,VALUE start)
|
3738
|
+
{
|
3739
|
+
int ncid;
|
3740
|
+
int varid;
|
3741
|
+
int status;
|
3742
|
+
short *ptr;
|
3743
|
+
int i;
|
3744
|
+
struct NetCDFVar *Netcdf_var;
|
3745
|
+
int l_start;
|
3746
|
+
size_t *c_start;
|
3747
|
+
int ndims;
|
3748
|
+
int *dimids;
|
3749
|
+
size_t dimlen;
|
3750
|
+
|
3751
|
+
rb_secure(1);
|
3752
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3753
|
+
ncid=Netcdf_var->ncid;
|
3754
|
+
varid=Netcdf_var->varid;
|
3755
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3756
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3757
|
+
|
3758
|
+
|
3759
|
+
dimids = ALLOCA_N(int,ndims);
|
3760
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3761
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3762
|
+
|
3763
|
+
Check_Type(start,T_ARRAY);
|
3764
|
+
if(RARRAY_LEN(start) <ndims) {
|
3765
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
3766
|
+
}
|
3767
|
+
|
3768
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3769
|
+
for(i=0;i<ndims;i++){
|
3770
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3771
|
+
|
3772
|
+
if(l_start < 0) {
|
3773
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3774
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3775
|
+
l_start += dimlen;
|
3776
|
+
}
|
3777
|
+
c_start[i]=l_start;
|
3778
|
+
|
3779
|
+
}
|
3780
|
+
NMatrix_to_Csint(NMatrix,ptr);
|
3781
|
+
|
3782
|
+
status = nc_put_var1_short(ncid,varid,c_start,ptr);
|
3783
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3784
|
+
return Qnil;
|
3785
|
+
}
|
3786
|
+
VALUE
|
3787
|
+
NetCDF_put_var1_int(VALUE Var,VALUE NMatrix,VALUE start)
|
3788
|
+
{
|
3789
|
+
int ncid;
|
3790
|
+
int varid;
|
3791
|
+
int status;
|
3792
|
+
int *ptr;
|
3793
|
+
int i;
|
3794
|
+
struct NetCDFVar *Netcdf_var;
|
3795
|
+
int l_start;
|
3796
|
+
size_t *c_start;
|
3797
|
+
int ndims;
|
3798
|
+
int *dimids;
|
3799
|
+
size_t dimlen;
|
3800
|
+
|
3801
|
+
rb_secure(1);
|
3802
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3803
|
+
ncid=Netcdf_var->ncid;
|
3804
|
+
varid=Netcdf_var->varid;
|
3805
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3806
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3807
|
+
|
3808
|
+
|
3809
|
+
dimids = ALLOCA_N(int,ndims);
|
3810
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3811
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3812
|
+
|
3813
|
+
Check_Type(start,T_ARRAY);
|
3814
|
+
if(RARRAY_LEN(start) <ndims) {
|
3815
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
3816
|
+
}
|
3817
|
+
|
3818
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3819
|
+
for(i=0;i<ndims;i++){
|
3820
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3821
|
+
|
3822
|
+
if(l_start < 0) {
|
3823
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3824
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3825
|
+
l_start += dimlen;
|
3826
|
+
}
|
3827
|
+
c_start[i]=l_start;
|
3828
|
+
|
3829
|
+
}
|
3830
|
+
NMatrix_to_Clint(NMatrix,ptr);
|
3831
|
+
|
3832
|
+
status = nc_put_var1_int(ncid,varid,c_start,ptr);
|
3833
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3834
|
+
return Qnil;
|
3835
|
+
}
|
3836
|
+
|
3837
|
+
VALUE
|
3838
|
+
NetCDF_put_var1_float(VALUE Var,VALUE NMatrix,VALUE start)
|
3839
|
+
{
|
3840
|
+
int ncid;
|
3841
|
+
int varid;
|
3842
|
+
int status;
|
3843
|
+
float *ptr;
|
3844
|
+
int i;
|
3845
|
+
struct NetCDFVar *Netcdf_var;
|
3846
|
+
int l_start;
|
3847
|
+
size_t *c_start;
|
3848
|
+
int ndims;
|
3849
|
+
int *dimids;
|
3850
|
+
size_t dimlen;
|
3851
|
+
|
3852
|
+
rb_secure(1);
|
3853
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3854
|
+
ncid=Netcdf_var->ncid;
|
3855
|
+
varid=Netcdf_var->varid;
|
3856
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3857
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3858
|
+
|
3859
|
+
|
3860
|
+
dimids = ALLOCA_N(int,ndims);
|
3861
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3862
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3863
|
+
|
3864
|
+
Check_Type(start,T_ARRAY);
|
3865
|
+
if(RARRAY_LEN(start) <ndims) {
|
3866
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
3867
|
+
}
|
3868
|
+
|
3869
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3870
|
+
for(i=0;i<ndims;i++){
|
3871
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3872
|
+
|
3873
|
+
if(l_start < 0) {
|
3874
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3875
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3876
|
+
l_start += dimlen;
|
3877
|
+
}
|
3878
|
+
c_start[i]=l_start;
|
3879
|
+
|
3880
|
+
}
|
3881
|
+
NMatrix_to_Cfloat(NMatrix,ptr);
|
3882
|
+
|
3883
|
+
status = nc_put_var1_float(ncid,varid,c_start,ptr);
|
3884
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3885
|
+
return Qnil;
|
3886
|
+
}
|
3887
|
+
|
3888
|
+
VALUE
|
3889
|
+
NetCDF_put_var1_double(VALUE Var,VALUE NMatrix,VALUE start)
|
3890
|
+
{
|
3891
|
+
int ncid;
|
3892
|
+
int varid;
|
3893
|
+
int status;
|
3894
|
+
double *ptr;
|
3895
|
+
int i;
|
3896
|
+
struct NetCDFVar *Netcdf_var;
|
3897
|
+
int l_start;
|
3898
|
+
size_t *c_start;
|
3899
|
+
int ndims;
|
3900
|
+
int *dimids;
|
3901
|
+
size_t dimlen;
|
3902
|
+
|
3903
|
+
rb_secure(1);
|
3904
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3905
|
+
ncid=Netcdf_var->ncid;
|
3906
|
+
varid=Netcdf_var->varid;
|
3907
|
+
status = nc_inq_varndims(ncid,varid,&ndims);
|
3908
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3909
|
+
|
3910
|
+
|
3911
|
+
dimids = ALLOCA_N(int,ndims);
|
3912
|
+
status = nc_inq_vardimid(ncid,varid,dimids);
|
3913
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3914
|
+
|
3915
|
+
Check_Type(start,T_ARRAY);
|
3916
|
+
if(RARRAY_LEN(start) <ndims) {
|
3917
|
+
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
3918
|
+
}
|
3919
|
+
|
3920
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3921
|
+
for(i=0;i<ndims;i++){
|
3922
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
3923
|
+
|
3924
|
+
if(l_start < 0) {
|
3925
|
+
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
3926
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3927
|
+
l_start += dimlen;
|
3928
|
+
}
|
3929
|
+
c_start[i]=l_start;
|
3930
|
+
|
3931
|
+
}
|
3932
|
+
NMatrix_to_Cdouble(NMatrix,ptr);
|
3933
|
+
|
3934
|
+
status = nc_put_var1_double(ncid,varid,c_start,ptr);
|
3935
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3936
|
+
return Qnil;
|
3937
|
+
}
|
3938
|
+
|
3939
|
+
|
3940
|
+
VALUE
|
3941
|
+
NetCDF_put_vars_char(VALUE Var,VALUE NMatrix,VALUE start,VALUE end,VALUE stride)
|
3942
|
+
{
|
3943
|
+
int ncid;
|
3944
|
+
int varid;
|
3945
|
+
int status;
|
3946
|
+
unsigned char *ptr,scalar;
|
3947
|
+
na_shape_t len;
|
3948
|
+
size_t c_count_all=1;
|
3949
|
+
struct NetCDFVar *Netcdf_var;
|
3950
|
+
int l_start, l_end;
|
3951
|
+
size_t *c_start;
|
3952
|
+
size_t *c_count;
|
3953
|
+
ptrdiff_t *c_stride;
|
3954
|
+
int ndims;
|
3955
|
+
size_t i;
|
3956
|
+
int j;
|
3957
|
+
na_shape_t *shape;
|
3958
|
+
int *dimids;
|
3959
|
+
size_t dimlen;
|
3960
|
+
|
3961
|
+
rb_secure(1);
|
3962
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
3963
|
+
ncid=Netcdf_var->ncid;
|
3964
|
+
varid=Netcdf_var->varid;
|
3965
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
3966
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3967
|
+
|
3968
|
+
dimids=ALLOCA_N(int,ndims);
|
3969
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
3970
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3971
|
+
|
3972
|
+
Check_Type(start,T_ARRAY);
|
3973
|
+
if(RARRAY_LEN(start) < ndims) {
|
3974
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
3975
|
+
}
|
3976
|
+
c_start=ALLOCA_N(size_t,ndims);
|
3977
|
+
for(j=0; j<ndims; j++){
|
3978
|
+
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-j]);
|
3979
|
+
|
3980
|
+
if(l_start < 0) {
|
3981
|
+
status = nc_inq_dimlen(ncid, dimids[j], &dimlen);
|
3982
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
3983
|
+
l_start += dimlen;
|
3984
|
+
}
|
3985
|
+
c_start[j]=l_start;
|
3986
|
+
}
|
3987
|
+
|
3988
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
3989
|
+
switch(TYPE(stride)){
|
3990
|
+
case T_NIL:
|
3991
|
+
for(j=0; j<ndims; j++){
|
3992
|
+
c_stride[j]=1;
|
3993
|
+
}
|
3994
|
+
break;
|
3995
|
+
default:
|
3996
|
+
Check_Type(stride,T_ARRAY);
|
3997
|
+
if(RARRAY_LEN(stride) < ndims) {
|
3998
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
3999
|
+
}
|
4000
|
+
for(j=0; j<ndims; j++){
|
4001
|
+
c_stride[j]=NUM2INT(RARRAY_PTR(stride)[ndims-1-j]);
|
4002
|
+
if(c_stride[j]==0) {
|
4003
|
+
rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
4004
|
+
}
|
4005
|
+
}
|
4006
|
+
}
|
4007
|
+
|
4008
|
+
NMatrix_to_Cbyte_len_shape(NMatrix,ptr,len,shape);
|
4009
|
+
|
4010
|
+
c_count=ALLOCA_N(size_t,ndims);
|
4011
|
+
switch(TYPE(end)){
|
4012
|
+
case T_NIL:
|
4013
|
+
for(j=0; j<ndims; j++){
|
4014
|
+
c_count[j]=shape[j];
|
4015
|
+
}
|
4016
|
+
c_count_all=len;
|
4017
|
+
break;
|
4018
|
+
default:
|
4019
|
+
Check_Type(end,T_ARRAY);
|
4020
|
+
if(RARRAY_LEN(end) < ndims) {
|
4021
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
4022
|
+
}
|
4023
|
+
for(j=0; j<ndims; j++){
|
4024
|
+
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-j]);
|
4025
|
+
if(l_end < 0) {
|
4026
|
+
status = nc_inq_dimlen(ncid, dimids[j], &dimlen);
|
4027
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4028
|
+
l_end += dimlen;
|
4029
|
+
}
|
4030
|
+
c_count[j]=(l_end-c_start[j])/c_stride[j]+1;
|
4031
|
+
c_count_all=c_count[j]*c_count_all;
|
4032
|
+
}
|
4033
|
+
if(len == 1 && len != c_count_all){
|
4034
|
+
scalar = *ptr;
|
4035
|
+
ptr = ALLOCA_N(unsigned char,c_count_all);
|
4036
|
+
for(i=0;i<c_count_all;i++){ptr[i]=scalar;}
|
4037
|
+
} else if(len != c_count_all) {
|
4038
|
+
rb_raise(rb_eNetcdfError,
|
4039
|
+
"lengh of the array does not agree with that of the subset\n");
|
4040
|
+
}
|
4041
|
+
}
|
4042
|
+
|
4043
|
+
status = nc_put_vars_text(ncid,varid,c_start,c_count,c_stride,(char *)ptr);
|
4044
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4045
|
+
return Qnil;
|
4046
|
+
}
|
4047
|
+
|
4048
|
+
VALUE
|
4049
|
+
NetCDF_put_vars_byte(VALUE Var,VALUE NMatrix,VALUE start,VALUE end,VALUE stride)
|
4050
|
+
{
|
4051
|
+
int ncid;
|
4052
|
+
int varid;
|
4053
|
+
int status;
|
4054
|
+
unsigned char *ptr,scalar;
|
4055
|
+
na_shape_t len;
|
4056
|
+
size_t c_count_all=1;
|
4057
|
+
struct NetCDFVar *Netcdf_var;
|
4058
|
+
int l_start, l_end;
|
4059
|
+
size_t *c_start;
|
4060
|
+
size_t *c_count;
|
4061
|
+
ptrdiff_t *c_stride;
|
4062
|
+
int ndims,i;
|
4063
|
+
size_t iszt;
|
4064
|
+
na_shape_t *shape;
|
4065
|
+
int *dimids;
|
4066
|
+
size_t dimlen;
|
4067
|
+
|
4068
|
+
rb_secure(1);
|
4069
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
4070
|
+
ncid=Netcdf_var->ncid;
|
4071
|
+
varid=Netcdf_var->varid;
|
4072
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
4073
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4074
|
+
|
4075
|
+
dimids=ALLOCA_N(int,ndims);
|
4076
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
4077
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4078
|
+
|
4079
|
+
Check_Type(start,T_ARRAY);
|
4080
|
+
if(RARRAY_LEN(start) < ndims) {
|
4081
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
4082
|
+
}
|
4083
|
+
c_start=ALLOCA_N(size_t,ndims);
|
4084
|
+
for(i=0; i<ndims; i++){
|
4085
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
4086
|
+
|
4087
|
+
if(l_start < 0) {
|
4088
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4089
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4090
|
+
l_start += dimlen;
|
4091
|
+
}
|
4092
|
+
c_start[i]=l_start;
|
4093
|
+
}
|
4094
|
+
|
4095
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
4096
|
+
switch(TYPE(stride)){
|
4097
|
+
case T_NIL:
|
4098
|
+
for(i=0; i<ndims; i++){
|
4099
|
+
c_stride[i]=1;
|
4100
|
+
}
|
4101
|
+
break;
|
4102
|
+
default:
|
4103
|
+
Check_Type(stride,T_ARRAY);
|
4104
|
+
if(RARRAY_LEN(stride) < ndims) {
|
4105
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
4106
|
+
}
|
4107
|
+
for(i=0; i<ndims; i++){
|
4108
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
4109
|
+
if(c_stride[i]==0) {
|
4110
|
+
rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
4111
|
+
}
|
4112
|
+
}
|
4113
|
+
}
|
4114
|
+
|
4115
|
+
NMatrix_to_Cbyte_len_shape(NMatrix,ptr,len,shape);
|
4116
|
+
|
4117
|
+
c_count=ALLOCA_N(size_t,ndims);
|
4118
|
+
switch(TYPE(end)){
|
4119
|
+
case T_NIL:
|
4120
|
+
for(i=0; i<ndims; i++){
|
4121
|
+
c_count[i]=shape[i];
|
4122
|
+
}
|
4123
|
+
c_count_all=len;
|
4124
|
+
break;
|
4125
|
+
default:
|
4126
|
+
Check_Type(end,T_ARRAY);
|
4127
|
+
if(RARRAY_LEN(end) < ndims) {
|
4128
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
4129
|
+
}
|
4130
|
+
for(i=0; i<ndims; i++){
|
4131
|
+
l_end=NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
4132
|
+
if(l_end < 0) {
|
4133
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4134
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4135
|
+
l_end += dimlen;
|
4136
|
+
}
|
4137
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
4138
|
+
c_count_all=c_count[i]*c_count_all;
|
4139
|
+
}
|
4140
|
+
if(len == 1 && len != c_count_all){
|
4141
|
+
scalar = *ptr;
|
4142
|
+
ptr = ALLOCA_N(unsigned char,c_count_all);
|
4143
|
+
for(iszt=0;iszt<c_count_all;iszt++){ptr[iszt]=scalar;}
|
4144
|
+
} else if(len != c_count_all) {
|
4145
|
+
rb_raise(rb_eNetcdfError,
|
4146
|
+
"lengh of the array does not agree with that of the subset\n");
|
4147
|
+
}
|
4148
|
+
}
|
4149
|
+
|
4150
|
+
status = nc_put_vars_uchar(ncid,varid,c_start,c_count,c_stride,ptr);
|
4151
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4152
|
+
return Qnil;
|
4153
|
+
}
|
4154
|
+
|
4155
|
+
VALUE
|
4156
|
+
NetCDF_put_vars_sint(VALUE Var,VALUE NMatrix,VALUE start,VALUE end,VALUE stride)
|
4157
|
+
{
|
4158
|
+
int ncid;
|
4159
|
+
int varid;
|
4160
|
+
int status;
|
4161
|
+
short *ptr,scalar;
|
4162
|
+
na_shape_t len;
|
4163
|
+
size_t c_count_all=1;
|
4164
|
+
struct NetCDFVar *Netcdf_var;
|
4165
|
+
int l_start, l_end;
|
4166
|
+
size_t *c_start;
|
4167
|
+
size_t *c_count;
|
4168
|
+
ptrdiff_t *c_stride;
|
4169
|
+
int ndims,i;
|
4170
|
+
size_t iszt;
|
4171
|
+
na_shape_t *shape;
|
4172
|
+
int *dimids;
|
4173
|
+
size_t dimlen;
|
4174
|
+
|
4175
|
+
rb_secure(1);
|
4176
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
4177
|
+
ncid=Netcdf_var->ncid;
|
4178
|
+
varid=Netcdf_var->varid;
|
4179
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
4180
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4181
|
+
|
4182
|
+
dimids=ALLOCA_N(int,ndims);
|
4183
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
4184
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4185
|
+
|
4186
|
+
Check_Type(start,T_ARRAY);
|
4187
|
+
if(RARRAY_LEN(start) < ndims) {
|
4188
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
4189
|
+
}
|
4190
|
+
c_start=ALLOCA_N(size_t,ndims);
|
4191
|
+
for(i=0; i<ndims; i++){
|
4192
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
4193
|
+
|
4194
|
+
if(l_start < 0) {
|
4195
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4196
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4197
|
+
l_start += dimlen;
|
4198
|
+
}
|
4199
|
+
c_start[i]=l_start;
|
4200
|
+
}
|
4201
|
+
|
4202
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
4203
|
+
switch(TYPE(stride)){
|
4204
|
+
case T_NIL:
|
4205
|
+
for(i=0; i<ndims; i++){
|
4206
|
+
c_stride[i]=1;
|
4207
|
+
}
|
4208
|
+
break;
|
4209
|
+
default:
|
4210
|
+
Check_Type(stride,T_ARRAY);
|
4211
|
+
if(RARRAY_LEN(stride) < ndims) {
|
4212
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
4213
|
+
}
|
4214
|
+
for(i=0; i<ndims; i++){
|
4215
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
4216
|
+
if(c_stride[i]==0) {
|
4217
|
+
rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
4218
|
+
}
|
4219
|
+
}
|
4220
|
+
}
|
4221
|
+
|
4222
|
+
NMatrix_to_Csint_len_shape(NMatrix,ptr,len,shape);
|
4223
|
+
|
4224
|
+
c_count=ALLOCA_N(size_t,ndims);
|
4225
|
+
switch(TYPE(end)){
|
4226
|
+
case T_NIL:
|
4227
|
+
for(i=0; i<ndims; i++){
|
4228
|
+
c_count[i]=shape[i];
|
4229
|
+
}
|
4230
|
+
c_count_all=len;
|
4231
|
+
break;
|
4232
|
+
default:
|
4233
|
+
Check_Type(end,T_ARRAY);
|
4234
|
+
if(RARRAY_LEN(end) < ndims) {
|
4235
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
4236
|
+
}
|
4237
|
+
for(i=0; i<ndims; i++){
|
4238
|
+
l_end=NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
4239
|
+
if(l_end < 0) {
|
4240
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4241
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4242
|
+
l_end += dimlen;
|
4243
|
+
}
|
4244
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
4245
|
+
c_count_all=c_count[i]*c_count_all;
|
4246
|
+
}
|
4247
|
+
if(len == 1 && len != c_count_all){
|
4248
|
+
scalar = *ptr;
|
4249
|
+
ptr = ALLOCA_N(short,c_count_all);
|
4250
|
+
for(iszt=0;iszt<c_count_all;iszt++){ptr[iszt]=scalar;}
|
4251
|
+
} else if(len != c_count_all) {
|
4252
|
+
rb_raise(rb_eNetcdfError,
|
4253
|
+
"lengh of the array does not agree with that of the subset\n");
|
4254
|
+
}
|
4255
|
+
}
|
4256
|
+
|
4257
|
+
status = nc_put_vars_short(ncid,varid,c_start,c_count,c_stride,ptr);
|
4258
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4259
|
+
return Qnil;
|
4260
|
+
}
|
4261
|
+
|
4262
|
+
|
4263
|
+
VALUE
|
4264
|
+
NetCDF_put_vars_int(VALUE Var,VALUE NMatrix,VALUE start,VALUE end,VALUE stride)
|
4265
|
+
{
|
4266
|
+
int ncid;
|
4267
|
+
int varid;
|
4268
|
+
int status;
|
4269
|
+
int *ptr,scalar;
|
4270
|
+
na_shape_t len;
|
4271
|
+
size_t c_count_all=1;
|
4272
|
+
struct NetCDFVar *Netcdf_var;
|
4273
|
+
int l_start, l_end;
|
4274
|
+
size_t *c_start;
|
4275
|
+
size_t *c_count;
|
4276
|
+
ptrdiff_t *c_stride;
|
4277
|
+
int ndims,i;
|
4278
|
+
size_t iszt;
|
4279
|
+
na_shape_t *shape;
|
4280
|
+
int *dimids;
|
4281
|
+
size_t dimlen;
|
4282
|
+
|
4283
|
+
rb_secure(1);
|
4284
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
4285
|
+
ncid=Netcdf_var->ncid;
|
4286
|
+
varid=Netcdf_var->varid;
|
4287
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
4288
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4289
|
+
|
4290
|
+
dimids=ALLOCA_N(int,ndims);
|
4291
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
4292
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4293
|
+
|
4294
|
+
Check_Type(start,T_ARRAY);
|
4295
|
+
if(RARRAY_LEN(start) < ndims) {
|
4296
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
4297
|
+
}
|
4298
|
+
c_start=ALLOCA_N(size_t,ndims);
|
4299
|
+
for(i=0; i<ndims; i++){
|
4300
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
4301
|
+
|
4302
|
+
if(l_start < 0) {
|
4303
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4304
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4305
|
+
l_start += dimlen;
|
4306
|
+
}
|
4307
|
+
c_start[i]=l_start;
|
4308
|
+
}
|
4309
|
+
|
4310
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
4311
|
+
switch(TYPE(stride)){
|
4312
|
+
case T_NIL:
|
4313
|
+
for(i=0; i<ndims; i++){
|
4314
|
+
c_stride[i]=1;
|
4315
|
+
}
|
4316
|
+
break;
|
4317
|
+
default:
|
4318
|
+
Check_Type(stride,T_ARRAY);
|
4319
|
+
if(RARRAY_LEN(stride) < ndims) {
|
4320
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
4321
|
+
}
|
4322
|
+
for(i=0; i<ndims; i++){
|
4323
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
4324
|
+
if(c_stride[i]==0) {
|
4325
|
+
rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
4326
|
+
}
|
4327
|
+
}
|
4328
|
+
}
|
4329
|
+
|
4330
|
+
NMatrix_to_Clint_len_shape(NMatrix,ptr,len,shape);
|
4331
|
+
|
4332
|
+
c_count=ALLOCA_N(size_t,ndims);
|
4333
|
+
switch(TYPE(end)){
|
4334
|
+
case T_NIL:
|
4335
|
+
for(i=0; i<ndims; i++){
|
4336
|
+
c_count[i]=shape[i];
|
4337
|
+
}
|
4338
|
+
c_count_all=len;
|
4339
|
+
break;
|
4340
|
+
default:
|
4341
|
+
Check_Type(end,T_ARRAY);
|
4342
|
+
if(RARRAY_LEN(end) < ndims) {
|
4343
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
4344
|
+
}
|
4345
|
+
for(i=0; i<ndims; i++){
|
4346
|
+
l_end=NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
4347
|
+
if(l_end < 0) {
|
4348
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4349
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4350
|
+
l_end += dimlen;
|
4351
|
+
}
|
4352
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
4353
|
+
c_count_all=c_count[i]*c_count_all;
|
4354
|
+
}
|
4355
|
+
if(len == 1 && len != c_count_all){
|
4356
|
+
scalar = *ptr;
|
4357
|
+
ptr = ALLOCA_N(int,c_count_all);
|
4358
|
+
for(iszt=0;iszt<c_count_all;iszt++){ptr[iszt]=scalar;}
|
4359
|
+
} else if(len != c_count_all) {
|
4360
|
+
rb_raise(rb_eNetcdfError,
|
4361
|
+
"length of the array does not agree with that of the subset\n");
|
4362
|
+
}
|
4363
|
+
}
|
4364
|
+
|
4365
|
+
status = nc_put_vars_int(ncid,varid,c_start,c_count,c_stride,ptr);
|
4366
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4367
|
+
return Qnil;
|
4368
|
+
}
|
4369
|
+
|
4370
|
+
|
4371
|
+
VALUE
|
4372
|
+
NetCDF_put_vars_float(VALUE Var,VALUE NMatrix,VALUE start,VALUE end,VALUE stride)
|
4373
|
+
{
|
4374
|
+
int ncid;
|
4375
|
+
int varid;
|
4376
|
+
int status;
|
4377
|
+
float *ptr,scalar;
|
4378
|
+
na_shape_t len;
|
4379
|
+
size_t c_count_all=1;
|
4380
|
+
struct NetCDFVar *Netcdf_var;
|
4381
|
+
int l_start, l_end;
|
4382
|
+
size_t *c_start;
|
4383
|
+
size_t *c_count;
|
4384
|
+
ptrdiff_t *c_stride;
|
4385
|
+
int ndims,i;
|
4386
|
+
size_t iszt;
|
4387
|
+
na_shape_t *shape;
|
4388
|
+
int *dimids;
|
4389
|
+
size_t dimlen;
|
4390
|
+
|
4391
|
+
rb_secure(1);
|
4392
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
4393
|
+
ncid=Netcdf_var->ncid;
|
4394
|
+
varid=Netcdf_var->varid;
|
4395
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
4396
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4397
|
+
|
4398
|
+
dimids=ALLOCA_N(int,ndims);
|
4399
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
4400
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4401
|
+
|
4402
|
+
Check_Type(start,T_ARRAY);
|
4403
|
+
if(RARRAY_LEN(start) < ndims) {
|
4404
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
4405
|
+
}
|
4406
|
+
c_start=ALLOCA_N(size_t,ndims);
|
4407
|
+
for(i=0; i<ndims; i++){
|
4408
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
4409
|
+
|
4410
|
+
if(l_start < 0) {
|
4411
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4412
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4413
|
+
l_start += dimlen;
|
4414
|
+
}
|
4415
|
+
c_start[i]=l_start;
|
4416
|
+
}
|
4417
|
+
|
4418
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
4419
|
+
switch(TYPE(stride)){
|
4420
|
+
case T_NIL:
|
4421
|
+
for(i=0; i<ndims; i++){
|
4422
|
+
c_stride[i]=1;
|
4423
|
+
}
|
4424
|
+
break;
|
4425
|
+
default:
|
4426
|
+
Check_Type(stride,T_ARRAY);
|
4427
|
+
if(RARRAY_LEN(stride) < ndims) {
|
4428
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
4429
|
+
}
|
4430
|
+
for(i=0; i<ndims; i++){
|
4431
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
4432
|
+
if(c_stride[i]==0) {
|
4433
|
+
rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
4434
|
+
}
|
4435
|
+
}
|
4436
|
+
}
|
4437
|
+
|
4438
|
+
NMatrix_to_Cfloat_len_shape(NMatrix,ptr,len,shape);
|
4439
|
+
|
4440
|
+
c_count=ALLOCA_N(size_t,ndims);
|
4441
|
+
switch(TYPE(end)){
|
4442
|
+
case T_NIL:
|
4443
|
+
for(i=0; i<ndims; i++){
|
4444
|
+
c_count[i]=shape[i];
|
4445
|
+
}
|
4446
|
+
c_count_all=len;
|
4447
|
+
break;
|
4448
|
+
default:
|
4449
|
+
Check_Type(end,T_ARRAY);
|
4450
|
+
if(RARRAY_LEN(end) < ndims) {
|
4451
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
4452
|
+
}
|
4453
|
+
for(i=0; i<ndims; i++){
|
4454
|
+
l_end=NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
4455
|
+
if(l_end < 0) {
|
4456
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4457
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4458
|
+
l_end += dimlen;
|
4459
|
+
}
|
4460
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
4461
|
+
c_count_all=c_count[i]*c_count_all;
|
4462
|
+
}
|
4463
|
+
if(len == 1 && len != c_count_all){
|
4464
|
+
scalar = *ptr;
|
4465
|
+
ptr = ALLOCA_N(float,c_count_all);
|
4466
|
+
for(iszt=0;iszt<c_count_all;iszt++){ptr[iszt]=scalar;}
|
4467
|
+
} else if(len != c_count_all) {
|
4468
|
+
rb_raise(rb_eNetcdfError,
|
4469
|
+
"lengh of the array does not agree with that of the subset\n");
|
4470
|
+
}
|
4471
|
+
}
|
4472
|
+
|
4473
|
+
status = nc_put_vars_float(ncid,varid,c_start,c_count,c_stride,ptr);
|
4474
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4475
|
+
return Qnil;
|
4476
|
+
}
|
4477
|
+
|
4478
|
+
|
4479
|
+
VALUE
|
4480
|
+
NetCDF_put_vars_double(VALUE Var,VALUE NMatrix,VALUE start,VALUE end,VALUE stride)
|
4481
|
+
{
|
4482
|
+
int ncid;
|
4483
|
+
int varid;
|
4484
|
+
int status;
|
4485
|
+
double *ptr,scalar;
|
4486
|
+
na_shape_t len;
|
4487
|
+
size_t c_count_all=1;
|
4488
|
+
struct NetCDFVar *Netcdf_var;
|
4489
|
+
int l_start, l_end;
|
4490
|
+
size_t *c_start;
|
4491
|
+
size_t *c_count;
|
4492
|
+
ptrdiff_t *c_stride;
|
4493
|
+
int ndims,i;
|
4494
|
+
size_t iszt;
|
4495
|
+
na_shape_t *shape;
|
4496
|
+
int *dimids;
|
4497
|
+
size_t dimlen;
|
4498
|
+
|
4499
|
+
rb_secure(1);
|
4500
|
+
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
4501
|
+
ncid=Netcdf_var->ncid;
|
4502
|
+
varid=Netcdf_var->varid;
|
4503
|
+
status = nc_inq_varndims(ncid, varid, &ndims);
|
4504
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4505
|
+
|
4506
|
+
dimids=ALLOCA_N(int,ndims);
|
4507
|
+
status = nc_inq_vardimid(ncid, varid, dimids);
|
4508
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4509
|
+
|
4510
|
+
Check_Type(start,T_ARRAY);
|
4511
|
+
if(RARRAY_LEN(start) < ndims) {
|
4512
|
+
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
4513
|
+
}
|
4514
|
+
c_start=ALLOCA_N(size_t,ndims);
|
4515
|
+
for(i=0; i<ndims; i++){
|
4516
|
+
l_start=NUM2INT(RARRAY_PTR(start)[RCMAJOR(ndims,i)]);
|
4517
|
+
|
4518
|
+
if(l_start < 0) {
|
4519
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4520
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4521
|
+
l_start += dimlen;
|
4522
|
+
}
|
4523
|
+
c_start[i]=l_start;
|
4524
|
+
}
|
4525
|
+
|
4526
|
+
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
4527
|
+
switch(TYPE(stride)){
|
4528
|
+
case T_NIL:
|
4529
|
+
for(i=0; i<ndims; i++){
|
4530
|
+
c_stride[i]=1;
|
4531
|
+
}
|
4532
|
+
break;
|
4533
|
+
default:
|
4534
|
+
Check_Type(stride,T_ARRAY);
|
4535
|
+
if(RARRAY_LEN(stride) < ndims) {
|
4536
|
+
rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
4537
|
+
}
|
4538
|
+
for(i=0; i<ndims; i++){
|
4539
|
+
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[RCMAJOR(ndims,i)]);
|
4540
|
+
if(c_stride[i]==0) {
|
4541
|
+
rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
4542
|
+
}
|
4543
|
+
}
|
4544
|
+
}
|
4545
|
+
|
4546
|
+
NMatrix_to_Cdouble_len_shape(NMatrix,ptr,len,shape);
|
4547
|
+
|
4548
|
+
c_count=ALLOCA_N(size_t,ndims);
|
4549
|
+
switch(TYPE(end)){
|
4550
|
+
case T_NIL:
|
4551
|
+
for(i=0; i<ndims; i++){
|
4552
|
+
c_count[i]=shape[i];
|
4553
|
+
}
|
4554
|
+
c_count_all=len;
|
4555
|
+
break;
|
4556
|
+
default:
|
4557
|
+
Check_Type(end,T_ARRAY);
|
4558
|
+
if(RARRAY_LEN(end) < ndims) {
|
4559
|
+
rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
4560
|
+
}
|
4561
|
+
for(i=0; i<ndims; i++){
|
4562
|
+
l_end=NUM2INT(RARRAY_PTR(end)[RCMAJOR(ndims,i)]);
|
4563
|
+
if(l_end < 0) {
|
4564
|
+
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
4565
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4566
|
+
l_end += dimlen;
|
4567
|
+
}
|
4568
|
+
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
4569
|
+
c_count_all=c_count[i]*c_count_all;
|
4570
|
+
}
|
4571
|
+
if(len == 1 && len != c_count_all){
|
4572
|
+
scalar = *ptr;
|
4573
|
+
ptr = ALLOCA_N(double,c_count_all);
|
4574
|
+
for(iszt=0;iszt<c_count_all;iszt++){ptr[iszt]=scalar;}
|
4575
|
+
} else if(len != c_count_all) {
|
4576
|
+
rb_raise(rb_eNetcdfError,
|
4577
|
+
"lengh of the array does not agree with that of the subset\n");
|
4578
|
+
}
|
4579
|
+
}
|
4580
|
+
|
4581
|
+
status = nc_put_vars_double(ncid,varid,c_start,c_count,c_stride,ptr);
|
4582
|
+
if(status != NC_NOERR) NC_RAISE(status);
|
4583
|
+
return Qnil;
|
4584
|
+
}
|
4585
|
+
|
4586
|
+
void
|
4587
|
+
Init_netcdfraw(void)
|
4588
|
+
{
|
4589
|
+
cNMatrix = RGET_CLASS_TOP("NMatrix");
|
4590
|
+
|
4591
|
+
mNumRu = rb_define_module("NumRu");
|
4592
|
+
|
4593
|
+
/* Difinitions of the classes */
|
4594
|
+
cNetCDF = rb_define_class_under(mNumRu, "NetCDF", rb_cObject);
|
4595
|
+
cNetCDFDim = rb_define_class_under(mNumRu, "NetCDFDim", rb_cObject);
|
4596
|
+
cNetCDFAtt = rb_define_class_under(mNumRu, "NetCDFAtt", rb_cObject);
|
4597
|
+
cNetCDFVar = rb_define_class_under(mNumRu, "NetCDFVar", rb_cObject);
|
4598
|
+
|
4599
|
+
rb_eNetcdfError = rb_define_class("NetcdfError",rb_eStandardError);
|
4600
|
+
rb_eNetcdfBadid = rb_define_class("NetcdfBadid",rb_eNetcdfError);
|
4601
|
+
rb_eNetcdfNfile = rb_define_class("NetcdfNfile",rb_eNetcdfError);
|
4602
|
+
rb_eNetcdfExist = rb_define_class("NetcdfExist",rb_eNetcdfError);
|
4603
|
+
rb_eNetcdfInval = rb_define_class("NetcdfInval",rb_eNetcdfError);
|
4604
|
+
rb_eNetcdfPerm = rb_define_class("NetcdfPerm",rb_eNetcdfError);
|
4605
|
+
rb_eNetcdfNotindefine = rb_define_class("NetcdfNotindefine",rb_eNetcdfError);
|
4606
|
+
rb_eNetcdfIndefine = rb_define_class("NetcdfIndefine",rb_eNetcdfError);
|
4607
|
+
rb_eNetcdfInvalcoords = rb_define_class("NetcdfInvalcoords",rb_eNetcdfError);
|
4608
|
+
rb_eNetcdfMaxdims = rb_define_class("NetcdfMaxdims",rb_eNetcdfError);
|
4609
|
+
rb_eNetcdfNameinuse = rb_define_class("NetcdfNameinuse",rb_eNetcdfError);
|
4610
|
+
rb_eNetcdfNotatt = rb_define_class("NetcdfNotatt",rb_eNetcdfError);
|
4611
|
+
rb_eNetcdfMaxatts = rb_define_class("NetcdfMaxatts",rb_eNetcdfError);
|
4612
|
+
rb_eNetcdfBadtype = rb_define_class("NetcdfBadtype",rb_eNetcdfError);
|
4613
|
+
rb_eNetcdfBaddim = rb_define_class("NetcdfBaddim",rb_eNetcdfError);
|
4614
|
+
rb_eNetcdfUnlimpos = rb_define_class("NetcdFUnlimpos",rb_eNetcdfError);
|
4615
|
+
rb_eNetcdfMaxvars = rb_define_class("NetcdfMaxvars",rb_eNetcdfError);
|
4616
|
+
rb_eNetcdfNotvar = rb_define_class("NetcdfNotvar",rb_eNetcdfError);
|
4617
|
+
rb_eNetcdfGlobal = rb_define_class("NetcdfGlobal",rb_eNetcdfError);
|
4618
|
+
rb_eNetcdfNotnc = rb_define_class("NetcdfNotnc",rb_eNetcdfError);
|
4619
|
+
rb_eNetcdfSts = rb_define_class("NetcdfSts",rb_eNetcdfError);
|
4620
|
+
rb_eNetcdfMaxname = rb_define_class("NetcdfMaxname",rb_eNetcdfError);
|
4621
|
+
rb_eNetcdfUnlimit = rb_define_class("NetcdfUnlimit",rb_eNetcdfError);
|
4622
|
+
rb_eNetcdfNorecvars = rb_define_class("NetcdfNorecvars",rb_eNetcdfError);
|
4623
|
+
rb_eNetcdfChar = rb_define_class("NetcdfChar",rb_eNetcdfError);
|
4624
|
+
rb_eNetcdfEdge = rb_define_class("NetcdfEdge",rb_eNetcdfError);
|
4625
|
+
rb_eNetcdfStride = rb_define_class("NetcdfStride",rb_eNetcdfError);
|
4626
|
+
rb_eNetcdfBadname = rb_define_class("NetcdfBadname",rb_eNetcdfError);
|
4627
|
+
/* N.B. following must match value in ncx.h */
|
4628
|
+
rb_eNetcdfRange = rb_define_class("NetcdfRange",rb_eNetcdfError);
|
4629
|
+
rb_eNetcdfNomem = rb_define_class("NetcdfNomem",rb_eNetcdfError);
|
4630
|
+
/* Global error status */
|
4631
|
+
rb_eNetcdfEntool = rb_define_class("NetcdfEntool",rb_eNetcdfError);
|
4632
|
+
rb_eNetcdfExdr = rb_define_class("NetcdfExdr",rb_eNetcdfError);
|
4633
|
+
rb_eNetcdfSyserr = rb_define_class("NetcdfSyserr",rb_eNetcdfError);
|
4634
|
+
/* Global options variable. Used to determine behavior of error handler. */
|
4635
|
+
rb_eNetcdfFatal = rb_define_class("NetcdfFatal",rb_eNetcdfError);
|
4636
|
+
|
4637
|
+
/* Class Constants Definition */
|
4638
|
+
rb_define_const(cNetCDF, "NC_NOWRITE", INT2FIX(NC_NOWRITE));
|
4639
|
+
rb_define_const(cNetCDF, "NC_WRITE", INT2FIX(NC_WRITE));
|
4640
|
+
rb_define_const(cNetCDF, "NC_SHARE", INT2FIX(NC_SHARE));
|
4641
|
+
rb_define_const(cNetCDF, "NC_CLOBBER", INT2FIX(NC_CLOBBER));
|
4642
|
+
rb_define_const(cNetCDF, "NC_NOCLOBBER", INT2FIX(NC_NOCLOBBER));
|
4643
|
+
#if NCVER >= 400
|
4644
|
+
rb_define_const(cNetCDF, "NC_64BIT_OFFSET", INT2FIX(NC_64BIT_OFFSET));
|
4645
|
+
/* NC_64BIT_OFFSET supports large files in the class data format */
|
4646
|
+
rb_define_const(cNetCDF, "NC_NETCDF4", INT2FIX(NC_NETCDF4));
|
4647
|
+
rb_define_const(cNetCDF, "NC_CLASSIC_MODEL", INT2FIX(NC_CLASSIC_MODEL));
|
4648
|
+
/* for use as ( NC_NETCDF4 | NC_CLASSIC_MODEL ) to ensure the classic
|
4649
|
+
data model in NetCDF4 by disabling new features like groups */
|
4650
|
+
rb_define_const(cNetCDF, "NC_ENDIAN_NATIVE", INT2FIX(NC_ENDIAN_NATIVE));
|
4651
|
+
rb_define_const(cNetCDF, "NC_ENDIAN_LITTLE", INT2FIX(NC_ENDIAN_LITTLE));
|
4652
|
+
rb_define_const(cNetCDF, "NC_ENDIAN_BIG", INT2FIX(NC_ENDIAN_BIG));
|
4653
|
+
#endif
|
4654
|
+
|
4655
|
+
#ifdef NARRAY_BIGMEM
|
4656
|
+
rb_define_const(cNetCDF, "SUPPORT_BIGMEM", Qtrue);
|
4657
|
+
#else
|
4658
|
+
rb_define_const(cNetCDF, "SUPPORT_BIGMEM", Qfalse);
|
4659
|
+
#endif
|
4660
|
+
|
4661
|
+
/* Difinitions of the ruby methods */
|
4662
|
+
/* The methods of the NetCDF class */
|
4663
|
+
rb_define_singleton_method(cNetCDF,"libvers",NetCDF_inq_libvers,0);
|
4664
|
+
rb_define_singleton_method(cNetCDF,"nc_open",NetCDF_open,2);
|
4665
|
+
rb_define_method(cNetCDF,"clone",NetCDF_clone,0);
|
4666
|
+
rb_define_method(cNetCDF,"close",NetCDF_close,0);
|
4667
|
+
/* rb_define_singleton_method(cNetCDF,"new",NetCDF_open,2); */
|
4668
|
+
rb_define_singleton_method(cNetCDF,"nc_create",NetCDF_create,2);
|
4669
|
+
rb_define_method(cNetCDF,"def_dim",NetCDF_def_dim,2);
|
4670
|
+
rb_define_method(cNetCDF,"def_var",NetCDF_def_var,3);
|
4671
|
+
rb_define_method(cNetCDF,"put_attraw",NetCDF_put_att,3);
|
4672
|
+
rb_define_method(cNetCDF,"redef",NetCDF_redef,0);
|
4673
|
+
rb_define_method(cNetCDF,"enddef",NetCDF_enddef,0);
|
4674
|
+
rb_define_method(cNetCDF,"define_mode?",NetCDF_whether_in_define_mode,0);
|
4675
|
+
rb_define_method(cNetCDF,"fill",NetCDF_fill,1);
|
4676
|
+
rb_define_method(cNetCDF,"ndims",NetCDF_ndims,0);
|
4677
|
+
rb_define_method(cNetCDF,"nvars",NetCDF_nvars,0);
|
4678
|
+
rb_define_method(cNetCDF,"natts",NetCDF_natts,0);
|
4679
|
+
rb_define_method(cNetCDF,"sync",NetCDF_sync,0);
|
4680
|
+
rb_define_method(cNetCDF,"path",NetCDF_path,0);
|
4681
|
+
rb_define_method(cNetCDF,"dim",NetCDF_dim,1);
|
4682
|
+
rb_define_method(cNetCDF,"var",NetCDF_var,1);
|
4683
|
+
rb_define_method(cNetCDF,"att",NetCDF_att,1);
|
4684
|
+
rb_define_method(cNetCDF,"unlimited",NetCDF_unlimited,0);
|
4685
|
+
rb_define_private_method(cNetCDF,"id2var",NetCDF_id2var,1);
|
4686
|
+
rb_define_private_method(cNetCDF,"id2dim",NetCDF_id2dim,1);
|
4687
|
+
rb_define_private_method(cNetCDF,"id2att",NetCDF_id2att,1);
|
4688
|
+
rb_define_method(cNetCDF,"==",NetCDF_eql,1);
|
4689
|
+
/* rb_define_method(cNetCDF,"eql?",NetCDF_eql,1); */
|
4690
|
+
|
4691
|
+
/* The methods of the NetCDFDim class */
|
4692
|
+
rb_define_method(cNetCDFDim,"clone",NetCDF_dim_clone,0);
|
4693
|
+
rb_define_method(cNetCDFDim,"length",NetCDF_dim_length,0);
|
4694
|
+
rb_define_method(cNetCDFDim,"name=",NetCDF_dim_name,1);
|
4695
|
+
rb_define_method(cNetCDFDim,"name",NetCDF_dim_inqname,0);
|
4696
|
+
rb_define_method(cNetCDFDim,"unlimited?",NetCDF_dim_whether_unlimited,0);
|
4697
|
+
rb_define_method(cNetCDFDim,"==",NetCDF_dim_eql,1);
|
4698
|
+
/* rb_define_method(cNetCDFDim,"eql?",NetCDF_dim_eql,1); */
|
4699
|
+
|
4700
|
+
/* The methods of the NetCDFAtt class */
|
4701
|
+
rb_define_method(cNetCDFAtt,"clone",NetCDF_att_clone,0);
|
4702
|
+
rb_define_method(cNetCDFAtt,"name",NetCDF_att_inq_name,0);
|
4703
|
+
rb_define_method(cNetCDFAtt,"name=",NetCDF_att_rename,1);
|
4704
|
+
rb_define_method(cNetCDFAtt,"delete",NetCDF_att_delete,0);
|
4705
|
+
rb_define_method(cNetCDFAtt,"copy",NetCDF_att_copy,1);
|
4706
|
+
rb_define_method(cNetCDFAtt,"atttype",NetCDF_att_atttype,0);
|
4707
|
+
rb_define_method(cNetCDFAtt,"typecode",NetCDF_att_typecode,0);
|
4708
|
+
rb_define_method(cNetCDFAtt,"==",NetCDF_att_eql,1);
|
4709
|
+
/* rb_define_method(cNetCDFAtt,"eql?",NetCDF_att_eql,1); */
|
4710
|
+
rb_define_method(cNetCDFAtt,"putraw",NetCDF_att_put,2);
|
4711
|
+
rb_define_method(cNetCDFAtt,"get",NetCDF_att_get,0);
|
4712
|
+
|
4713
|
+
/* The methods of the NetCDFVar class */
|
4714
|
+
#if NCVER >= 400
|
4715
|
+
rb_define_method(cNetCDFVar,"deflate",NetCDF_var_deflate,-1);
|
4716
|
+
rb_define_method(cNetCDFVar,"deflate_params",NetCDF_var_deflate_params,0);
|
4717
|
+
rb_define_method(cNetCDFVar,"endian=",NetCDF_var_set_endian,1);
|
4718
|
+
rb_define_method(cNetCDFVar,"endian",NetCDF_var_endian,0);
|
4719
|
+
#endif
|
4720
|
+
rb_define_method(cNetCDFVar,"clone",NetCDF_var_clone,0);
|
4721
|
+
rb_define_method(cNetCDFVar,"name",NetCDF_var_inq_name,0);
|
4722
|
+
rb_define_method(cNetCDFVar,"ndims",NetCDF_var_ndims,0);
|
4723
|
+
rb_define_method(cNetCDFVar,"vartype",NetCDF_var_vartype,0);
|
4724
|
+
rb_define_method(cNetCDFVar,"typecode",NetCDF_var_typecode,0);
|
4725
|
+
rb_define_method(cNetCDFVar,"ntype",NetCDF_var_vartype,0);
|
4726
|
+
rb_define_method(cNetCDFVar,"natts",NetCDF_var_natts,0);
|
4727
|
+
rb_define_method(cNetCDFVar,"file",NetCDF_var_file,0);
|
4728
|
+
rb_define_method(cNetCDFVar,"name=",NetCDF_var_rename,1);
|
4729
|
+
rb_define_method(cNetCDFVar,"att",NetCDF_var_att,1);
|
4730
|
+
rb_define_method(cNetCDFVar,"put_attraw",NetCDF_put_att_var,3);
|
4731
|
+
rb_define_method(cNetCDFVar,"dims",NetCDF_var_dims,0);
|
4732
|
+
rb_define_method(cNetCDFVar,"dim",NetCDF_var_dim,1);
|
4733
|
+
/*rb_define_private_method(cNetCDFVar,"id2dim",NetCDF_var_id2dim,1); */
|
4734
|
+
rb_define_private_method(cNetCDFVar,"id2att",NetCDF_var_id2att,1);
|
4735
|
+
rb_define_method(cNetCDFVar,"==",NetCDF_var_eql,1);
|
4736
|
+
/* rb_define_method(cNetCDFVar,"eql?",NetCDF_var_eql,1); */
|
4737
|
+
|
4738
|
+
/* The "get*" or "put*" methods in the NetCDFVar class */
|
4739
|
+
rb_define_method(cNetCDFVar,"put_var_char",NetCDF_put_var_char,1);
|
4740
|
+
rb_define_method(cNetCDFVar,"put_var_byte",NetCDF_put_var_byte,1);
|
4741
|
+
rb_define_method(cNetCDFVar,"put_var_sint",NetCDF_put_var_short,1);
|
4742
|
+
rb_define_method(cNetCDFVar,"put_var_int",NetCDF_put_var_int,1);
|
4743
|
+
rb_define_method(cNetCDFVar,"put_var_sfloat",NetCDF_put_var_float,1);
|
4744
|
+
rb_define_method(cNetCDFVar,"put_var_float",NetCDF_put_var_double,1);
|
4745
|
+
|
4746
|
+
rb_define_method(cNetCDFVar,"put_vars_char",NetCDF_put_vars_char,4);
|
4747
|
+
rb_define_method(cNetCDFVar,"put_vars_byte",NetCDF_put_vars_byte,4);
|
4748
|
+
rb_define_method(cNetCDFVar,"put_vars_sint",NetCDF_put_vars_sint,4);
|
4749
|
+
rb_define_method(cNetCDFVar,"put_vars_int",NetCDF_put_vars_int,4);
|
4750
|
+
rb_define_method(cNetCDFVar,"put_vars_sfloat",NetCDF_put_vars_float,4);
|
4751
|
+
rb_define_method(cNetCDFVar,"put_vars_float",NetCDF_put_vars_double,4);
|
4752
|
+
|
4753
|
+
rb_define_method(cNetCDFVar,"put_var1_char",NetCDF_put_var1_char,2);
|
4754
|
+
rb_define_method(cNetCDFVar,"put_var1_byte",NetCDF_put_var1_byte,2);
|
4755
|
+
rb_define_method(cNetCDFVar,"put_var1_sint",NetCDF_put_var1_sint,2);
|
4756
|
+
rb_define_method(cNetCDFVar,"put_var1_int",NetCDF_put_var1_int,2);
|
4757
|
+
rb_define_method(cNetCDFVar,"put_var1_sfloat",NetCDF_put_var1_float,2);
|
4758
|
+
rb_define_method(cNetCDFVar,"put_var1_float",NetCDF_put_var1_double,2);
|
4759
|
+
|
4760
|
+
rb_define_method(cNetCDFVar,"get_var_char",NetCDF_get_var_char,0);
|
4761
|
+
rb_define_method(cNetCDFVar,"get_var_byte",NetCDF_get_var_byte,0);
|
4762
|
+
rb_define_method(cNetCDFVar,"get_var_sint",NetCDF_get_var_sint,0);
|
4763
|
+
rb_define_method(cNetCDFVar,"get_var_int",NetCDF_get_var_int,0);
|
4764
|
+
rb_define_method(cNetCDFVar,"get_var_sfloat",NetCDF_get_var_float,0);
|
4765
|
+
rb_define_method(cNetCDFVar,"get_var_float",NetCDF_get_var_double,0);
|
4766
|
+
|
4767
|
+
rb_define_method(cNetCDFVar,"get_vars_char",NetCDF_get_vars_char,3);
|
4768
|
+
rb_define_method(cNetCDFVar,"get_vars_byte",NetCDF_get_vars_byte,3);
|
4769
|
+
rb_define_method(cNetCDFVar,"get_vars_sint",NetCDF_get_vars_sint,3);
|
4770
|
+
rb_define_method(cNetCDFVar,"get_vars_int",NetCDF_get_vars_int,3);
|
4771
|
+
rb_define_method(cNetCDFVar,"get_vars_sfloat",NetCDF_get_vars_float,3);
|
4772
|
+
rb_define_method(cNetCDFVar,"get_vars_float",NetCDF_get_vars_double,3);
|
4773
|
+
|
4774
|
+
rb_define_method(cNetCDFVar,"get_var1_char",NetCDF_get_var1_char,1);
|
4775
|
+
rb_define_method(cNetCDFVar,"get_var1_byte",NetCDF_get_var1_byte,1);
|
4776
|
+
rb_define_method(cNetCDFVar,"get_var1_sint",NetCDF_get_var1_sint,1);
|
4777
|
+
rb_define_method(cNetCDFVar,"get_var1_int",NetCDF_get_var1_int,1);
|
4778
|
+
rb_define_method(cNetCDFVar,"get_var1_sfloat",NetCDF_get_var1_float,1);
|
4779
|
+
rb_define_method(cNetCDFVar,"get_var1_float",NetCDF_get_var1_double,1);
|
4780
|
+
}
|