|
0 |
From: Youhei SASAKI <uwabami@gfd-dennou.org>
|
|
1 |
Date: Fri, 22 May 2020 23:19:51 +0900
|
|
2 |
Subject: import upstream: Drop obsolete rb_secure, rb_safe_level
|
|
3 |
|
|
4 |
Signed-off-by: Youhei SASAKI <uwabami@gfd-dennou.org>
|
|
5 |
---
|
|
6 |
ext/numru/netcdfraw.c | 576 +++++++++++-----------
|
|
7 |
lib/numru/netcdf.rb | 1272 ++++++++++++++++++++++++-------------------------
|
|
8 |
2 files changed, 905 insertions(+), 943 deletions(-)
|
|
9 |
|
|
10 |
diff --git a/ext/numru/netcdfraw.c b/ext/numru/netcdfraw.c
|
|
11 |
index b3fdf77..6cc4de9 100644
|
|
12 |
--- a/ext/numru/netcdfraw.c
|
|
13 |
+++ b/ext/numru/netcdfraw.c
|
|
14 |
@@ -198,7 +198,7 @@ typedef int na_shape_t;
|
|
15 |
obj = na_cast_object(obj, NA_SINT); \
|
|
16 |
GetNArray(obj, na); \
|
|
17 |
ptr = (int16_t *) NA_PTR(na,0); \
|
|
18 |
-}
|
|
19 |
+}
|
|
20 |
#define Array_to_Clint(obj, ptr) \
|
|
21 |
{ \
|
|
22 |
struct NARRAY *na; \
|
|
23 |
@@ -257,7 +257,7 @@ static VALUE rb_eNetcdfFatal;
|
|
24 |
static VALUE rb_eNetcdfEntool;
|
|
25 |
static VALUE rb_eNetcdfExdr;
|
|
26 |
static VALUE rb_eNetcdfSyserr;
|
|
27 |
-
|
|
28 |
+
|
|
29 |
|
|
30 |
struct Netcdf{
|
|
31 |
int ncid;
|
|
32 |
@@ -290,7 +290,7 @@ NetCDF_init(int ncid,char *filename)
|
|
33 |
Netcdffile->ncid=ncid;
|
|
34 |
Netcdffile->closed=0;
|
|
35 |
Netcdffile->name=xmalloc((strlen(filename)+1)*sizeof(char));
|
|
36 |
- strcpy(Netcdffile->name,filename);
|
|
37 |
+ strcpy(Netcdffile->name,filename);
|
|
38 |
return(Netcdffile);
|
|
39 |
}
|
|
40 |
|
|
41 |
@@ -322,7 +322,7 @@ NetCDF_att_init(int ncid,int varid,char *attname)
|
|
42 |
Netcdf_att->ncid=ncid;
|
|
43 |
Netcdf_att->varid=varid;
|
|
44 |
Netcdf_att->name=xmalloc((strlen(attname)+1)*sizeof(char));
|
|
45 |
- strcpy(Netcdf_att->name,attname);
|
|
46 |
+ strcpy(Netcdf_att->name,attname);
|
|
47 |
return(Netcdf_att);
|
|
48 |
}
|
|
49 |
|
|
50 |
@@ -351,7 +351,7 @@ NetCDF_free(struct Netcdf *Netcdffile)
|
|
51 |
if (!Netcdffile->closed){
|
|
52 |
nc_close(Netcdffile->ncid); /* no error check -- not to stop during GC */
|
|
53 |
}
|
|
54 |
- free(Netcdffile->name);
|
|
55 |
+ free(Netcdffile->name);
|
|
56 |
free(Netcdffile);
|
|
57 |
}
|
|
58 |
|
|
59 |
@@ -576,14 +576,11 @@ NetCDF_close(file)
|
|
60 |
int ncid;
|
|
61 |
struct Netcdf *Netcdffile;
|
|
62 |
|
|
63 |
- if (rb_safe_level() >= 3 && !OBJ_TAINTED(file)) {
|
|
64 |
- rb_raise(rb_eSecurityError, "Insecure: can't close");
|
|
65 |
- }
|
|
66 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
67 |
ncid=Netcdffile->ncid;
|
|
68 |
if(!Netcdffile->closed){
|
|
69 |
status = nc_close(ncid);
|
|
70 |
- if(status != NC_NOERR) NC_RAISE(status);
|
|
71 |
+ if(status != NC_NOERR) NC_RAISE(status);
|
|
72 |
Netcdffile->closed = 1;
|
|
73 |
} else {
|
|
74 |
rb_warn("file %s is already closed", Netcdffile->name);
|
|
75 |
@@ -602,10 +599,9 @@ NetCDF_def_dim(VALUE file,VALUE dim_name,VALUE length)
|
|
76 |
struct Netcdf *Netcdffile;
|
|
77 |
struct NetCDFDim *Netcdf_dim;
|
|
78 |
VALUE Dimension;
|
|
79 |
-
|
|
80 |
- rb_secure(3);
|
|
81 |
+
|
|
82 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
83 |
-
|
|
84 |
+
|
|
85 |
Check_Type(dim_name,T_STRING);
|
|
86 |
c_dim_name=RSTRING_PTR(dim_name);
|
|
87 |
c_length=NUM2UINT(length);
|
|
88 |
@@ -696,19 +692,19 @@ NetCDF_put_att_numeric(int ncid, char *name,VALUE value,VALUE atttype, int varid
|
|
89 |
len = na_val->total;
|
|
90 |
ptr = na_val->ptr;
|
|
91 |
switch(na_typecode){
|
|
92 |
- case NA_BYTE:
|
|
93 |
+ case NA_BYTE:
|
|
94 |
status = nc_put_att_uchar(ncid,varid,name,NC_BYTE,len,(unsigned char *)ptr);
|
|
95 |
break;
|
|
96 |
- case NA_SINT:
|
|
97 |
+ case NA_SINT:
|
|
98 |
status = nc_put_att_short(ncid,varid,name,NC_SHORT,len,(short *)ptr);
|
|
99 |
break;
|
|
100 |
- case NA_LINT:
|
|
101 |
+ case NA_LINT:
|
|
102 |
status = nc_put_att_int(ncid,varid,name,NC_INT,len,(int *)ptr);
|
|
103 |
break;
|
|
104 |
- case NA_SFLOAT:
|
|
105 |
+ case NA_SFLOAT:
|
|
106 |
status = nc_put_att_float(ncid,varid,name,NC_FLOAT,len,(float *)ptr);
|
|
107 |
break;
|
|
108 |
- case NA_DFLOAT:
|
|
109 |
+ case NA_DFLOAT:
|
|
110 |
status = nc_put_att_double(ncid,varid,name,NC_DOUBLE,len,(double*)ptr);
|
|
111 |
break;
|
|
112 |
default:
|
|
113 |
@@ -746,7 +742,6 @@ NetCDF_put_att(VALUE file,VALUE att_name,VALUE value,VALUE atttype)
|
|
114 |
struct Netcdf *ncfile;
|
|
115 |
char *name;
|
|
116 |
|
|
117 |
- rb_secure(3);
|
|
118 |
Data_Get_Struct(file,struct Netcdf,ncfile);
|
|
119 |
Check_Type(att_name,T_STRING);
|
|
120 |
name = RSTRING_PTR(att_name);
|
|
121 |
@@ -764,7 +759,6 @@ NetCDF_put_att_var(VALUE var,VALUE att_name,VALUE value,VALUE atttype)
|
|
122 |
struct NetCDFVar *ncvar;
|
|
123 |
char *name;
|
|
124 |
|
|
125 |
- rb_secure(3);
|
|
126 |
Data_Get_Struct(var,struct NetCDFVar,ncvar);
|
|
127 |
Check_Type(att_name,T_STRING);
|
|
128 |
name = RSTRING_PTR(att_name);
|
|
129 |
@@ -791,20 +785,19 @@ NetCDF_def_var(VALUE file,VALUE var_name,VALUE vartype,VALUE dimensions)
|
|
130 |
struct NetCDFDim *Netcdf_dim;
|
|
131 |
VALUE Var;
|
|
132 |
|
|
133 |
- rb_secure(3);
|
|
134 |
Check_Type(var_name,T_STRING);
|
|
135 |
Check_Type(dimensions,T_ARRAY);
|
|
136 |
|
|
137 |
c_var_name=RSTRING_PTR(var_name);
|
|
138 |
c_ndims=RARRAY_LEN(dimensions);
|
|
139 |
-
|
|
140 |
+
|
|
141 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
142 |
ncid=Netcdffile->ncid;
|
|
143 |
|
|
144 |
if (TYPE(vartype) == T_STRING){
|
|
145 |
- xtype = natype2nctype(RSTRING_PTR(vartype));
|
|
146 |
+ xtype = natype2nctype(RSTRING_PTR(vartype));
|
|
147 |
} else if (TYPE(vartype) == T_FIXNUM){
|
|
148 |
- xtype = natypecode2nctype(NUM2INT(vartype));
|
|
149 |
+ xtype = natypecode2nctype(NUM2INT(vartype));
|
|
150 |
} else {
|
|
151 |
rb_raise(rb_eNetcdfError,
|
|
152 |
"type specification must be by a string or nil");
|
|
153 |
@@ -827,12 +820,12 @@ NetCDF_def_var(VALUE file,VALUE var_name,VALUE vartype,VALUE dimensions)
|
|
154 |
rb_raise(rb_eNetcdfError, "No such object of the netCDF dimension class.");
|
|
155 |
}
|
|
156 |
}
|
|
157 |
-
|
|
158 |
+
|
|
159 |
status = nc_def_var(ncid,c_var_name,xtype,c_ndims,c_dimids,&varidp);
|
|
160 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
161 |
-
|
|
162 |
+
|
|
163 |
Netcdf_var = NetCDF_var_init(ncid,varidp,file);
|
|
164 |
-
|
|
165 |
+
|
|
166 |
Var=Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var);
|
|
167 |
return Var;
|
|
168 |
}
|
|
169 |
@@ -852,10 +845,10 @@ NetCDF_dim(VALUE file,VALUE dim_name)
|
|
170 |
ncid=Netcdffile->ncid;
|
|
171 |
Check_Type(dim_name,T_STRING);
|
|
172 |
c_dim_name=RSTRING_PTR(dim_name);
|
|
173 |
-
|
|
174 |
+
|
|
175 |
status = nc_inq_dimid(ncid,c_dim_name,&dimidp);
|
|
176 |
if(status !=NC_NOERR){
|
|
177 |
- if(status == NC_EBADDIM){
|
|
178 |
+ if(status == NC_EBADDIM){
|
|
179 |
return(Qnil); /*2003/08/27 back to orig (from changes on 2003/02/03)*/
|
|
180 |
} else{
|
|
181 |
NC_RAISE(status);
|
|
182 |
@@ -863,14 +856,14 @@ NetCDF_dim(VALUE file,VALUE dim_name)
|
|
183 |
}
|
|
184 |
|
|
185 |
Netcdf_dim=NetCDF_dim_init(ncid,dimidp);
|
|
186 |
-
|
|
187 |
+
|
|
188 |
Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
|
189 |
return Dimension;
|
|
190 |
}
|
|
191 |
|
|
192 |
-VALUE
|
|
193 |
+VALUE
|
|
194 |
NetCDF_var(VALUE file,VALUE var_name)
|
|
195 |
-{
|
|
196 |
+{
|
|
197 |
int ncid;
|
|
198 |
int status;
|
|
199 |
int varidp;
|
|
200 |
@@ -883,16 +876,16 @@ NetCDF_var(VALUE file,VALUE var_name)
|
|
201 |
ncid=Netcdffile->ncid;
|
|
202 |
Check_Type(var_name,T_STRING);
|
|
203 |
c_var_name=RSTRING_PTR(var_name);
|
|
204 |
-
|
|
205 |
+
|
|
206 |
status=nc_inq_varid(ncid,c_var_name,&varidp);
|
|
207 |
if(status != NC_NOERR){
|
|
208 |
if(status == NC_ENOTVAR){
|
|
209 |
return(Qnil); /*2003/08/27 back to orig (from changes on 2003/02/03)*/
|
|
210 |
- } else{
|
|
211 |
+ } else{
|
|
212 |
NC_RAISE(status);
|
|
213 |
}
|
|
214 |
}
|
|
215 |
-
|
|
216 |
+
|
|
217 |
Netcdf_var = NetCDF_var_init(ncid,varidp,file);
|
|
218 |
Variable = Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var);
|
|
219 |
return Variable;
|
|
220 |
@@ -913,7 +906,7 @@ NetCDF_att(VALUE file,VALUE att_name)
|
|
221 |
ncid=Netcdffile->ncid;
|
|
222 |
Check_Type(att_name,T_STRING);
|
|
223 |
c_att_name=RSTRING_PTR(att_name);
|
|
224 |
-
|
|
225 |
+
|
|
226 |
|
|
227 |
status = nc_inq_attid(ncid,NC_GLOBAL,c_att_name,&attnump);
|
|
228 |
if(status != NC_NOERR){
|
|
229 |
@@ -924,11 +917,11 @@ NetCDF_att(VALUE file,VALUE att_name)
|
|
230 |
NC_RAISE(status);
|
|
231 |
}
|
|
232 |
}
|
|
233 |
-
|
|
234 |
+
|
|
235 |
Netcdf_att = NetCDF_att_init(ncid,NC_GLOBAL,c_att_name);
|
|
236 |
-
|
|
237 |
+
|
|
238 |
Attribute = Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att);
|
|
239 |
-
|
|
240 |
+
|
|
241 |
return Attribute;
|
|
242 |
}
|
|
243 |
VALUE
|
|
244 |
@@ -938,7 +931,7 @@ NetCDF_fill(VALUE file,VALUE mode)
|
|
245 |
int status;
|
|
246 |
struct Netcdf *Netcdffile;
|
|
247 |
int old_modep;
|
|
248 |
-
|
|
249 |
+
|
|
250 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
251 |
ncid = Netcdffile->ncid;
|
|
252 |
if(mode==Qfalse){
|
|
253 |
@@ -961,7 +954,6 @@ NetCDF_redef(VALUE file)
|
|
254 |
int status;
|
|
255 |
struct Netcdf *Netcdffile;
|
|
256 |
|
|
257 |
- rb_secure(3);
|
|
258 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
259 |
ncid=Netcdffile->ncid;
|
|
260 |
status = nc_redef(ncid);
|
|
261 |
@@ -976,18 +968,17 @@ NetCDF_redef(VALUE file)
|
|
262 |
return Qtrue;
|
|
263 |
}
|
|
264 |
|
|
265 |
-VALUE
|
|
266 |
+VALUE
|
|
267 |
NetCDF_enddef(VALUE file)
|
|
268 |
{
|
|
269 |
int ncid;
|
|
270 |
int status;
|
|
271 |
struct Netcdf *Netcdffile;
|
|
272 |
|
|
273 |
- rb_secure(3);
|
|
274 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
275 |
ncid=Netcdffile->ncid;
|
|
276 |
status = nc_enddef(ncid);
|
|
277 |
- if(status !=NC_NOERR){
|
|
278 |
+ if(status !=NC_NOERR){
|
|
279 |
if(status == NC_ENOTINDEFINE){
|
|
280 |
return Qnil;
|
|
281 |
}
|
|
282 |
@@ -998,7 +989,7 @@ NetCDF_enddef(VALUE file)
|
|
283 |
return Qtrue;
|
|
284 |
}
|
|
285 |
|
|
286 |
-VALUE
|
|
287 |
+VALUE
|
|
288 |
NetCDF_whether_in_define_mode(VALUE file)
|
|
289 |
{
|
|
290 |
/* returns true if the NetCDF object is currently in the define mode,
|
|
291 |
@@ -1010,7 +1001,6 @@ NetCDF_whether_in_define_mode(VALUE file)
|
|
292 |
int status;
|
|
293 |
struct Netcdf *Netcdffile;
|
|
294 |
|
|
295 |
- rb_secure(3);
|
|
296 |
Data_Get_Struct(file,struct Netcdf,Netcdffile);
|
|
297 |
ncid=Netcdffile->ncid;
|
|
298 |
status = nc_redef(ncid);
|
|
299 |
@@ -1030,7 +1020,7 @@ NetCDF_whether_in_define_mode(VALUE file)
|
|
300 |
}
|
|
301 |
|
|
302 |
VALUE
|
|
303 |
-NetCDF_open(VALUE mod,VALUE filename,VALUE omode)
|
|
304 |
+NetCDF_open(VALUE mod,VALUE filename,VALUE omode)
|
|
305 |
{
|
|
306 |
int status;
|
|
307 |
int ncid;
|
|
308 |
@@ -1044,7 +1034,7 @@ NetCDF_open(VALUE mod,VALUE filename,VALUE omode)
|
|
309 |
c_filename=RSTRING_PTR(filename);
|
|
310 |
Check_Type(omode,T_FIXNUM);
|
|
311 |
c_omode=NUM2INT(omode);
|
|
312 |
-
|
|
313 |
+
|
|
314 |
status = nc_open(c_filename,c_omode,&ncid);
|
|
315 |
if(status !=NC_NOERR){NC_RAISE2(status,c_filename);}
|
|
316 |
|
|
317 |
@@ -1061,13 +1051,13 @@ NetCDF_create(VALUE mod,VALUE filename,VALUE cmode)
|
|
318 |
char* c_filename;
|
|
319 |
int c_cmode;
|
|
320 |
struct Netcdf *ncfile;
|
|
321 |
-
|
|
322 |
+
|
|
323 |
Check_Type(filename,T_STRING);
|
|
324 |
SafeStringValue(filename);
|
|
325 |
c_filename=RSTRING_PTR(filename);
|
|
326 |
Check_Type(cmode,T_FIXNUM);
|
|
327 |
c_cmode=NUM2INT(cmode);
|
|
328 |
-
|
|
329 |
+
|
|
330 |
status = nc_create(c_filename,c_cmode,&ncid);
|
|
331 |
if(status != NC_NOERR) NC_RAISE2(status, c_filename);
|
|
332 |
|
|
333 |
@@ -1075,7 +1065,7 @@ NetCDF_create(VALUE mod,VALUE filename,VALUE cmode)
|
|
334 |
return( Data_Wrap_Struct(cNetCDF,0,NetCDF_free,ncfile) );
|
|
335 |
}
|
|
336 |
|
|
337 |
-VALUE
|
|
338 |
+VALUE
|
|
339 |
NetCDF_ndims(VALUE file)
|
|
340 |
{
|
|
341 |
int ncid;
|
|
342 |
@@ -1092,7 +1082,7 @@ NetCDF_ndims(VALUE file)
|
|
343 |
return Integer;
|
|
344 |
}
|
|
345 |
|
|
346 |
-VALUE
|
|
347 |
+VALUE
|
|
348 |
NetCDF_nvars(VALUE file)
|
|
349 |
{
|
|
350 |
int ncid;
|
|
351 |
@@ -1108,7 +1098,7 @@ NetCDF_nvars(VALUE file)
|
|
352 |
return Integer;
|
|
353 |
}
|
|
354 |
|
|
355 |
-VALUE
|
|
356 |
+VALUE
|
|
357 |
NetCDF_natts(VALUE file)
|
|
358 |
{
|
|
359 |
int ncid;
|
|
360 |
@@ -1139,10 +1129,10 @@ NetCDF_unlimited(VALUE file)
|
|
361 |
ncid=ncfile->ncid;
|
|
362 |
status=nc_inq_unlimdim(ncid,&unlimdimidp);
|
|
363 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
364 |
-
|
|
365 |
+
|
|
366 |
Netcdf_dim = NetCDF_dim_init(ncid,unlimdimidp);
|
|
367 |
-
|
|
368 |
- /* If unlimdimidp=-1,No unlimited dimension is defined in the netCDF dataset */
|
|
369 |
+
|
|
370 |
+ /* If unlimdimidp=-1,No unlimited dimension is defined in the netCDF dataset */
|
|
371 |
if(unlimdimidp != -1)
|
|
372 |
{
|
|
373 |
Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim);
|
|
374 |
@@ -1156,7 +1146,7 @@ NetCDF_unlimited(VALUE file)
|
|
375 |
|
|
376 |
#if NCVER >= 400
|
|
377 |
|
|
378 |
-VALUE
|
|
379 |
+VALUE
|
|
380 |
NetCDF_format(VALUE file)
|
|
381 |
{
|
|
382 |
int ncid;
|
|
383 |
@@ -1177,7 +1167,7 @@ NetCDF_format(VALUE file)
|
|
384 |
}
|
|
385 |
|
|
386 |
#endif
|
|
387 |
-
|
|
388 |
+
|
|
389 |
VALUE
|
|
390 |
NetCDF_sync(VALUE file)
|
|
391 |
{
|
|
392 |
@@ -1185,7 +1175,6 @@ NetCDF_sync(VALUE file)
|
|
393 |
int status;
|
|
394 |
struct Netcdf *ncfile;
|
|
395 |
|
|
396 |
- rb_secure(3);
|
|
397 |
Data_Get_Struct(file,struct Netcdf,ncfile);
|
|
398 |
ncid=ncfile->ncid;
|
|
399 |
status = nc_sync(ncid);
|
|
400 |
@@ -1198,7 +1187,7 @@ NetCDF_path(VALUE file)
|
|
401 |
{
|
|
402 |
char *path;
|
|
403 |
struct Netcdf *ncfile;
|
|
404 |
-
|
|
405 |
+
|
|
406 |
Data_Get_Struct(file,struct Netcdf,ncfile);
|
|
407 |
path=ncfile->name;
|
|
408 |
return(rb_str_new2(path));
|
|
409 |
@@ -1212,14 +1201,14 @@ NetCDF_dim_length(VALUE Dim)
|
|
410 |
int dimid;
|
|
411 |
size_t lengthp;
|
|
412 |
struct NetCDFDim *Netcdf_dim;
|
|
413 |
-
|
|
414 |
+
|
|
415 |
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
|
416 |
ncid=Netcdf_dim->ncid;
|
|
417 |
dimid=Netcdf_dim->dimid;
|
|
418 |
|
|
419 |
status = nc_inq_dimlen(ncid,dimid,&lengthp);
|
|
420 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
421 |
-
|
|
422 |
+
|
|
423 |
return(INT2NUM(lengthp));
|
|
424 |
}
|
|
425 |
|
|
426 |
@@ -1231,8 +1220,7 @@ NetCDF_dim_name(VALUE Dim,VALUE dimension_newname)
|
|
427 |
int dimid;
|
|
428 |
char *c_dim_name;
|
|
429 |
struct NetCDFDim *Netcdf_dim;
|
|
430 |
-
|
|
431 |
- rb_secure(3);
|
|
432 |
+
|
|
433 |
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
|
434 |
ncid=Netcdf_dim->ncid;
|
|
435 |
dimid=Netcdf_dim->dimid;
|
|
436 |
@@ -1241,7 +1229,7 @@ NetCDF_dim_name(VALUE Dim,VALUE dimension_newname)
|
|
437 |
|
|
438 |
status = nc_rename_dim(ncid,dimid,c_dim_name);
|
|
439 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
440 |
-
|
|
441 |
+
|
|
442 |
return Qnil;
|
|
443 |
}
|
|
444 |
|
|
445 |
@@ -1254,14 +1242,14 @@ NetCDF_dim_inqname(VALUE Dim)
|
|
446 |
char c_dim_name[NC_MAX_NAME];
|
|
447 |
struct NetCDFDim *Netcdf_dim;
|
|
448 |
VALUE str;
|
|
449 |
-
|
|
450 |
+
|
|
451 |
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
|
452 |
ncid=Netcdf_dim->ncid;
|
|
453 |
dimid=Netcdf_dim->dimid;
|
|
454 |
-
|
|
455 |
+
|
|
456 |
status = nc_inq_dimname(ncid,dimid,c_dim_name);
|
|
457 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
458 |
-
|
|
459 |
+
|
|
460 |
str = rb_str_new2(c_dim_name);
|
|
461 |
OBJ_TAINT(str);
|
|
462 |
return(str);
|
|
463 |
@@ -1273,7 +1261,7 @@ NetCDF_dim_whether_unlimited(VALUE Dim)
|
|
464 |
int status;
|
|
465 |
int uldid;
|
|
466 |
struct NetCDFDim *Netcdf_dim;
|
|
467 |
-
|
|
468 |
+
|
|
469 |
Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim);
|
|
470 |
status=nc_inq_unlimdim(Netcdf_dim->ncid,&uldid);
|
|
471 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
472 |
@@ -1293,7 +1281,7 @@ NetCDF_att_inq_name(VALUE Att)
|
|
473 |
|
|
474 |
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
|
475 |
c_att_name=Netcdf_att->name;
|
|
476 |
-
|
|
477 |
+
|
|
478 |
str = rb_str_new2(c_att_name);
|
|
479 |
OBJ_TAINT(str);
|
|
480 |
return(str);
|
|
481 |
@@ -1311,16 +1299,16 @@ NetCDF_att_rename(VALUE Att,VALUE new_att_name)
|
|
482 |
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
|
483 |
ncid=Netcdf_att->ncid;
|
|
484 |
varid=Netcdf_att->varid;
|
|
485 |
-
|
|
486 |
+
|
|
487 |
c_att_name=Netcdf_att->name;
|
|
488 |
-
|
|
489 |
+
|
|
490 |
Check_Type(new_att_name,T_STRING);
|
|
491 |
SafeStringValue(new_att_name);
|
|
492 |
c_new_att_name=StringValueCStr(new_att_name);
|
|
493 |
-
|
|
494 |
+
|
|
495 |
status = nc_rename_att(ncid,varid,c_att_name,c_new_att_name);
|
|
496 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
497 |
-
|
|
498 |
+
|
|
499 |
strcpy(Netcdf_att->name,c_new_att_name);
|
|
500 |
return Qnil;
|
|
501 |
}
|
|
502 |
@@ -1351,7 +1339,7 @@ NetCDF_id2var(VALUE file,VALUE varid)
|
|
503 |
struct Netcdf *ncfile;
|
|
504 |
struct NetCDFVar *Netcdf_var;
|
|
505 |
VALUE Var;
|
|
506 |
-
|
|
507 |
+
|
|
508 |
Data_Get_Struct(file,struct Netcdf,ncfile);
|
|
509 |
ncid=ncfile->ncid;
|
|
510 |
Check_Type(varid,T_FIXNUM);
|
|
511 |
@@ -1373,7 +1361,7 @@ NetCDF_id2att(VALUE file,VALUE attnum)
|
|
512 |
char *c_att_name;
|
|
513 |
VALUE Att;
|
|
514 |
c_att_name=ALLOCA_N(char,NC_MAX_NAME);
|
|
515 |
-
|
|
516 |
+
|
|
517 |
Data_Get_Struct(file,struct Netcdf,ncfile);
|
|
518 |
ncid=ncfile->ncid;
|
|
519 |
|
|
520 |
@@ -1401,7 +1389,7 @@ NetCDF_var_deflate(int argc, VALUE *argv, VALUE Var)
|
|
521 |
struct NetCDFVar *Netcdf_var;
|
|
522 |
|
|
523 |
int shuffle;
|
|
524 |
- /* If non-zero, turn on the shuffle filter.
|
|
525 |
+ /* If non-zero, turn on the shuffle filter.
|
|
526 |
|
|
527 |
http://www.unidata.ucar.edu/software/netcdf/papers/AMS_2008.pdf :
|
|
528 |
The shuffle algorithm changes the byte order in the data stream;
|
|
529 |
@@ -1421,7 +1409,7 @@ NetCDF_var_deflate(int argc, VALUE *argv, VALUE Var)
|
|
530 |
level specified by the deflate_level parameter.
|
|
531 |
*/
|
|
532 |
|
|
533 |
- if (argc>2 || argc<1) rb_raise(rb_eArgError,
|
|
534 |
+ if (argc>2 || argc<1) rb_raise(rb_eArgError,
|
|
535 |
"wrong # of arguments (%d). It must be 1 or 2", argc);
|
|
536 |
|
|
537 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
538 |
@@ -1457,7 +1445,7 @@ NetCDF_var_deflate_params(VALUE Var)
|
|
539 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
540 |
ncid = Netcdf_var->ncid;
|
|
541 |
varid = Netcdf_var->varid;
|
|
542 |
- status = nc_inq_var_deflate(ncid, varid, &shufflep, &deflatep,
|
|
543 |
+ status = nc_inq_var_deflate(ncid, varid, &shufflep, &deflatep,
|
|
544 |
&deflate_levelp);
|
|
545 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
546 |
if (shufflep==0) {sh=Qfalse;} else {sh=Qtrue;}
|
|
547 |
@@ -1508,7 +1496,7 @@ NetCDF_var_id2att(VALUE Var,VALUE attnum)
|
|
548 |
struct NetCDFAtt *Netcdf_att;
|
|
549 |
char *c_att_name;
|
|
550 |
VALUE Att;
|
|
551 |
-
|
|
552 |
+
|
|
553 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
554 |
ncid=Netcdf_var->ncid;
|
|
555 |
c_varid=Netcdf_var->varid;
|
|
556 |
@@ -1520,7 +1508,7 @@ NetCDF_var_id2att(VALUE Var,VALUE attnum)
|
|
557 |
|
|
558 |
status = nc_inq_attname(ncid,c_varid,c_attnum,c_att_name);
|
|
559 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
560 |
-
|
|
561 |
+
|
|
562 |
Netcdf_att=NetCDF_att_init(ncid,c_varid,c_att_name);
|
|
563 |
Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att);
|
|
564 |
return(Att);
|
|
565 |
@@ -1545,7 +1533,7 @@ NetCDF_var_dims(VALUE Var)
|
|
566 |
Dims = rb_ary_new();
|
|
567 |
for(i=0;i<ndims;i++){
|
|
568 |
Netcdf_dim = NetCDF_dim_init(ncid,dimids[ndims-1-i]);
|
|
569 |
- rb_ary_push(Dims,
|
|
570 |
+ rb_ary_push(Dims,
|
|
571 |
Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim));
|
|
572 |
}
|
|
573 |
return(Dims);
|
|
574 |
@@ -1589,7 +1577,6 @@ NetCDF_att_copy(VALUE Att,VALUE Var_or_File)
|
|
575 |
struct Netcdf *ncfile;
|
|
576 |
struct NetCDFAtt *Netcdf_att_out;
|
|
577 |
|
|
578 |
- rb_secure(3);
|
|
579 |
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
|
580 |
ncid_in=Netcdf_att->ncid;
|
|
581 |
varid_in=Netcdf_att->varid;
|
|
582 |
@@ -1635,7 +1622,7 @@ NetCDF_att_atttype(VALUE Att)
|
|
583 |
Attname = nctype2natype(xtypep);
|
|
584 |
return(rb_str_new2(Attname));
|
|
585 |
}
|
|
586 |
-
|
|
587 |
+
|
|
588 |
VALUE
|
|
589 |
NetCDF_att_typecode(VALUE Att)
|
|
590 |
{
|
|
591 |
@@ -1653,10 +1640,10 @@ NetCDF_att_typecode(VALUE Att)
|
|
592 |
|
|
593 |
status = nc_inq_atttype(ncid,varid,att_name,&xtypep);
|
|
594 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
595 |
-
|
|
596 |
+
|
|
597 |
return(INT2NUM(nctype2natypecode(xtypep)));
|
|
598 |
}
|
|
599 |
-
|
|
600 |
+
|
|
601 |
VALUE
|
|
602 |
NetCDF_att_delete(VALUE Att)
|
|
603 |
{
|
|
604 |
@@ -1666,7 +1653,6 @@ NetCDF_att_delete(VALUE Att)
|
|
605 |
char *c_att_name;
|
|
606 |
struct NetCDFAtt *Netcdf_att;
|
|
607 |
|
|
608 |
- rb_secure(3);
|
|
609 |
Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att);
|
|
610 |
|
|
611 |
ncid=Netcdf_att->ncid;
|
|
612 |
@@ -1675,7 +1661,7 @@ NetCDF_att_delete(VALUE Att)
|
|
613 |
|
|
614 |
status = nc_del_att(ncid,varid,c_att_name);
|
|
615 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
616 |
-
|
|
617 |
+
|
|
618 |
return Qnil;
|
|
619 |
}
|
|
620 |
|
|
621 |
@@ -1687,13 +1673,12 @@ NetCDF_att_put(VALUE Att,VALUE value,VALUE atttype)
|
|
622 |
*/
|
|
623 |
{
|
|
624 |
struct NetCDFAtt *ncatt;
|
|
625 |
-
|
|
626 |
- rb_secure(3);
|
|
627 |
+
|
|
628 |
Data_Get_Struct(Att,struct NetCDFAtt,ncatt);
|
|
629 |
- return( NetCDF_put_att__(ncatt->ncid, ncatt->name, value,
|
|
630 |
+ return( NetCDF_put_att__(ncatt->ncid, ncatt->name, value,
|
|
631 |
atttype, ncatt->varid) );
|
|
632 |
}
|
|
633 |
-
|
|
634 |
+
|
|
635 |
VALUE
|
|
636 |
NetCDF_att_get(VALUE Att)
|
|
637 |
{
|
|
638 |
@@ -1740,7 +1725,7 @@ NetCDF_att_get(VALUE Att)
|
|
639 |
|
|
640 |
attlen[0]=lenp;
|
|
641 |
Cbyte_to_NArray(NArray,1,attlen,up);
|
|
642 |
-
|
|
643 |
+
|
|
644 |
status = nc_get_att_uchar(ncid,varid,c_attname,up);
|
|
645 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
646 |
|
|
647 |
@@ -1753,7 +1738,7 @@ NetCDF_att_get(VALUE Att)
|
|
648 |
|
|
649 |
attlen[0]=lenp;
|
|
650 |
Csint_to_NArray(NArray,1,attlen,sp);
|
|
651 |
-
|
|
652 |
+
|
|
653 |
status = nc_get_att_short(ncid,varid,c_attname,sp);
|
|
654 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
655 |
OBJ_TAINT(NArray);
|
|
656 |
@@ -1762,10 +1747,10 @@ NetCDF_att_get(VALUE Att)
|
|
657 |
case NC_INT:
|
|
658 |
status = nc_inq_attlen(ncid,varid,c_attname,&lenp);
|
|
659 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
660 |
-
|
|
661 |
+
|
|
662 |
attlen[0]=lenp;
|
|
663 |
Clint_to_NArray(NArray,1,attlen,ip);
|
|
664 |
-
|
|
665 |
+
|
|
666 |
status = nc_get_att_int(ncid,varid,c_attname,ip);
|
|
667 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
668 |
|
|
669 |
@@ -1778,7 +1763,7 @@ NetCDF_att_get(VALUE Att)
|
|
670 |
|
|
671 |
attlen[0]=lenp;
|
|
672 |
Cfloat_to_NArray(NArray,1,attlen,fp);
|
|
673 |
-
|
|
674 |
+
|
|
675 |
status = nc_get_att_float(ncid,varid,c_attname,fp);
|
|
676 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
677 |
|
|
678 |
@@ -1791,7 +1776,7 @@ NetCDF_att_get(VALUE Att)
|
|
679 |
|
|
680 |
attlen[0]=lenp;
|
|
681 |
Cdouble_to_NArray(NArray,1,attlen,dp);
|
|
682 |
-
|
|
683 |
+
|
|
684 |
status = nc_get_att_double(ncid,varid,c_attname,dp);
|
|
685 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
686 |
OBJ_TAINT(NArray);
|
|
687 |
@@ -1803,7 +1788,7 @@ NetCDF_att_get(VALUE Att)
|
|
688 |
return Qnil;
|
|
689 |
}
|
|
690 |
|
|
691 |
-
|
|
692 |
+
|
|
693 |
VALUE
|
|
694 |
NetCDF_var_inq_name(VALUE Var)
|
|
695 |
{
|
|
696 |
@@ -1820,7 +1805,7 @@ NetCDF_var_inq_name(VALUE Var)
|
|
697 |
varid=Netcdf_var->varid;
|
|
698 |
status = nc_inq_varname(ncid,varid,c_var_name);
|
|
699 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
700 |
-
|
|
701 |
+
|
|
702 |
Var_name=rb_str_new2(c_var_name);
|
|
703 |
OBJ_TAINT(Var_name);
|
|
704 |
return Var_name;
|
|
705 |
@@ -1837,7 +1822,7 @@ NetCDF_var_ndims(VALUE Var)
|
|
706 |
VALUE Var_ndims;
|
|
707 |
|
|
708 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
709 |
-
|
|
710 |
+
|
|
711 |
ncid=Netcdf_var->ncid;
|
|
712 |
varid=Netcdf_var->varid;
|
|
713 |
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
|
714 |
@@ -1855,15 +1840,15 @@ NetCDF_var_vartype(VALUE Var)
|
|
715 |
nc_type xtypep;
|
|
716 |
struct NetCDFVar *Netcdf_var;
|
|
717 |
const char *Vartype;
|
|
718 |
-
|
|
719 |
+
|
|
720 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
721 |
-
|
|
722 |
+
|
|
723 |
ncid=Netcdf_var->ncid;
|
|
724 |
varid=Netcdf_var->varid;
|
|
725 |
|
|
726 |
status = nc_inq_vartype(ncid,varid,&xtypep);
|
|
727 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
728 |
-
|
|
729 |
+
|
|
730 |
Vartype=nctype2natype(xtypep);
|
|
731 |
return(rb_str_new2(Vartype));
|
|
732 |
}
|
|
733 |
@@ -1876,19 +1861,19 @@ NetCDF_var_typecode(VALUE Var)
|
|
734 |
int varid;
|
|
735 |
nc_type xtypep;
|
|
736 |
struct NetCDFVar *Netcdf_var;
|
|
737 |
-
|
|
738 |
+
|
|
739 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
740 |
-
|
|
741 |
+
|
|
742 |
ncid=Netcdf_var->ncid;
|
|
743 |
varid=Netcdf_var->varid;
|
|
744 |
|
|
745 |
status = nc_inq_vartype(ncid,varid,&xtypep);
|
|
746 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
747 |
-
|
|
748 |
+
|
|
749 |
return(INT2NUM(nctype2natypecode(xtypep)));
|
|
750 |
}
|
|
751 |
|
|
752 |
-
|
|
753 |
+
|
|
754 |
VALUE
|
|
755 |
NetCDF_var_natts(VALUE Var)
|
|
756 |
{
|
|
757 |
@@ -1898,16 +1883,16 @@ NetCDF_var_natts(VALUE Var)
|
|
758 |
int nattsp;
|
|
759 |
struct NetCDFVar *Netcdf_var;
|
|
760 |
VALUE Var_natts;
|
|
761 |
-
|
|
762 |
+
|
|
763 |
|
|
764 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
765 |
-
|
|
766 |
+
|
|
767 |
ncid=Netcdf_var->ncid;
|
|
768 |
varid=Netcdf_var->varid;
|
|
769 |
-
|
|
770 |
+
|
|
771 |
status= nc_inq_varnatts(ncid,varid,&nattsp);
|
|
772 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
773 |
-
|
|
774 |
+
|
|
775 |
Var_natts=INT2FIX(nattsp);
|
|
776 |
return Var_natts;
|
|
777 |
}
|
|
778 |
@@ -1918,7 +1903,7 @@ NetCDF_var_file(VALUE Var)
|
|
779 |
struct NetCDFVar *Netcdf_var;
|
|
780 |
/* VALUE file; */
|
|
781 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
782 |
-
|
|
783 |
+
|
|
784 |
return (Netcdf_var->file);
|
|
785 |
}
|
|
786 |
|
|
787 |
@@ -1930,15 +1915,14 @@ NetCDF_var_rename(VALUE Var,VALUE var_new_name)
|
|
788 |
int varid;
|
|
789 |
char *c_var_new_name;
|
|
790 |
struct NetCDFVar *Netcdf_var;
|
|
791 |
-
|
|
792 |
- rb_secure(3);
|
|
793 |
+
|
|
794 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
795 |
ncid=Netcdf_var->ncid;
|
|
796 |
varid=Netcdf_var->varid;
|
|
797 |
|
|
798 |
Check_Type(var_new_name,T_STRING);
|
|
799 |
c_var_new_name=StringValueCStr(var_new_name);
|
|
800 |
-
|
|
801 |
+
|
|
802 |
status = nc_rename_var(ncid,varid,c_var_new_name);
|
|
803 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
804 |
|
|
805 |
@@ -1958,13 +1942,13 @@ NetCDF_var_att(VALUE Var,VALUE att_name)
|
|
806 |
VALUE Att;
|
|
807 |
|
|
808 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
809 |
-
|
|
810 |
+
|
|
811 |
ncid=Netcdf_var->ncid;
|
|
812 |
varid=Netcdf_var->varid;
|
|
813 |
|
|
814 |
Check_Type(att_name,T_STRING);
|
|
815 |
c_att_name=StringValueCStr(att_name);
|
|
816 |
-
|
|
817 |
+
|
|
818 |
status = nc_inq_attid(ncid,varid,c_att_name,&c_attnump);
|
|
819 |
if(status == NC_NOERR){
|
|
820 |
Netcdf_att=NetCDF_att_init(ncid,varid,c_att_name);
|
|
821 |
@@ -1982,17 +1966,17 @@ NetCDF_var_att(VALUE Var,VALUE att_name)
|
|
822 |
|
|
823 |
/* Redifinition of the "==" and "eql?" methods */
|
|
824 |
|
|
825 |
-VALUE
|
|
826 |
+VALUE
|
|
827 |
NetCDF_eql(VALUE filea,VALUE fileb)
|
|
828 |
{
|
|
829 |
struct Netcdf *ncfilea;
|
|
830 |
struct Netcdf *ncfileb;
|
|
831 |
-
|
|
832 |
+
|
|
833 |
if( rb_obj_is_kind_of(fileb, cNetCDF) ){
|
|
834 |
Data_Get_Struct(filea,struct Netcdf,ncfilea);
|
|
835 |
Data_Get_Struct(fileb,struct Netcdf,ncfileb);
|
|
836 |
-
|
|
837 |
- if(ncfilea->ncid == ncfileb->ncid &&
|
|
838 |
+
|
|
839 |
+ if(ncfilea->ncid == ncfileb->ncid &&
|
|
840 |
strcmp(ncfilea->name,ncfileb->name)==0){
|
|
841 |
return Qtrue;
|
|
842 |
} else {
|
|
843 |
@@ -2008,12 +1992,12 @@ NetCDF_var_eql(VALUE Vara,VALUE Varb)
|
|
844 |
{
|
|
845 |
struct NetCDFVar *Netcdf_vara;
|
|
846 |
struct NetCDFVar *Netcdf_varb;
|
|
847 |
-
|
|
848 |
+
|
|
849 |
if( rb_obj_is_kind_of(Varb, cNetCDFVar) ){
|
|
850 |
Data_Get_Struct(Vara,struct NetCDFVar,Netcdf_vara);
|
|
851 |
Data_Get_Struct(Varb,struct NetCDFVar,Netcdf_varb);
|
|
852 |
|
|
853 |
- if(Netcdf_vara->ncid == Netcdf_varb->ncid &&
|
|
854 |
+ if(Netcdf_vara->ncid == Netcdf_varb->ncid &&
|
|
855 |
Netcdf_vara->varid == Netcdf_varb->varid){
|
|
856 |
return Qtrue;
|
|
857 |
} else {
|
|
858 |
@@ -2024,7 +2008,7 @@ NetCDF_var_eql(VALUE Vara,VALUE Varb)
|
|
859 |
}
|
|
860 |
}
|
|
861 |
|
|
862 |
-VALUE
|
|
863 |
+VALUE
|
|
864 |
NetCDF_dim_eql(VALUE Dima,VALUE Dimb)
|
|
865 |
{
|
|
866 |
struct NetCDFDim *Netcdf_dima;
|
|
867 |
@@ -2033,8 +2017,8 @@ NetCDF_dim_eql(VALUE Dima,VALUE Dimb)
|
|
868 |
if( rb_obj_is_kind_of(Dimb, cNetCDFDim) ){
|
|
869 |
Data_Get_Struct(Dima,struct NetCDFDim,Netcdf_dima);
|
|
870 |
Data_Get_Struct(Dimb,struct NetCDFDim,Netcdf_dimb);
|
|
871 |
-
|
|
872 |
- if(Netcdf_dima->ncid == Netcdf_dimb->ncid &&
|
|
873 |
+
|
|
874 |
+ if(Netcdf_dima->ncid == Netcdf_dimb->ncid &&
|
|
875 |
Netcdf_dima->dimid == Netcdf_dimb->dimid){
|
|
876 |
return Qtrue;
|
|
877 |
} else {
|
|
878 |
@@ -2050,16 +2034,16 @@ NetCDF_att_eql(VALUE Atta,VALUE Attb)
|
|
879 |
{
|
|
880 |
struct NetCDFAtt *Netcdf_atta;
|
|
881 |
struct NetCDFAtt *Netcdf_attb;
|
|
882 |
-
|
|
883 |
+
|
|
884 |
if( rb_obj_is_kind_of(Attb, cNetCDFAtt) ){
|
|
885 |
Data_Get_Struct(Atta,struct NetCDFAtt,Netcdf_atta);
|
|
886 |
Data_Get_Struct(Attb,struct NetCDFAtt,Netcdf_attb);
|
|
887 |
-
|
|
888 |
- if(Netcdf_atta->ncid == Netcdf_atta->ncid &&
|
|
889 |
- Netcdf_atta->varid == Netcdf_attb->varid &&
|
|
890 |
+
|
|
891 |
+ if(Netcdf_atta->ncid == Netcdf_atta->ncid &&
|
|
892 |
+ Netcdf_atta->varid == Netcdf_attb->varid &&
|
|
893 |
strcmp(Netcdf_atta->name,Netcdf_attb->name)==0){
|
|
894 |
return Qtrue;
|
|
895 |
- } else {
|
|
896 |
+ } else {
|
|
897 |
return Qfalse;
|
|
898 |
}
|
|
899 |
} else {
|
|
900 |
@@ -2104,7 +2088,7 @@ NetCDF_get_var_char(VALUE Var)
|
|
901 |
}
|
|
902 |
|
|
903 |
Cbyte_to_NArray(NArray,ndimsp,shape,ptr);
|
|
904 |
-
|
|
905 |
+
|
|
906 |
status = nc_get_var_text(ncid,varid,(char *)ptr);
|
|
907 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
908 |
|
|
909 |
@@ -2148,7 +2132,7 @@ NetCDF_get_var_byte(VALUE Var)
|
|
910 |
}
|
|
911 |
|
|
912 |
Cbyte_to_NArray(NArray,ndimsp,shape,ptr);
|
|
913 |
-
|
|
914 |
+
|
|
915 |
status = nc_get_var_uchar(ncid,varid,ptr);
|
|
916 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
917 |
|
|
918 |
@@ -2192,7 +2176,7 @@ NetCDF_get_var_sint(VALUE Var)
|
|
919 |
}
|
|
920 |
|
|
921 |
Csint_to_NArray(NArray,ndimsp,shape,ptr);
|
|
922 |
-
|
|
923 |
+
|
|
924 |
status = nc_get_var_short(ncid,varid,ptr);
|
|
925 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
926 |
|
|
927 |
@@ -2236,7 +2220,7 @@ NetCDF_get_var_int(VALUE Var)
|
|
928 |
}
|
|
929 |
|
|
930 |
Clint_to_NArray(NArray,ndimsp,shape,ptr);
|
|
931 |
-
|
|
932 |
+
|
|
933 |
status = nc_get_var_int(ncid,varid,ptr);
|
|
934 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
935 |
|
|
936 |
@@ -2324,7 +2308,7 @@ NetCDF_get_var_double(VALUE Var)
|
|
937 |
}
|
|
938 |
|
|
939 |
Cdouble_to_NArray(NArray,ndimsp,shape,ptr);
|
|
940 |
-
|
|
941 |
+
|
|
942 |
status = nc_get_var_double(ncid,varid,ptr);
|
|
943 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
944 |
|
|
945 |
@@ -2332,7 +2316,7 @@ NetCDF_get_var_double(VALUE Var)
|
|
946 |
return NArray;
|
|
947 |
}
|
|
948 |
|
|
949 |
-VALUE
|
|
950 |
+VALUE
|
|
951 |
NetCDF_get_var1_char(VALUE Var,VALUE start)
|
|
952 |
{
|
|
953 |
int ncid;
|
|
954 |
@@ -2349,7 +2333,7 @@ NetCDF_get_var1_char(VALUE Var,VALUE start)
|
|
955 |
na_shape_t *c_count;
|
|
956 |
VALUE NArray;
|
|
957 |
|
|
958 |
-
|
|
959 |
+
|
|
960 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
961 |
ncid = Netcdf_var->ncid;
|
|
962 |
varid = Netcdf_var->varid;
|
|
963 |
@@ -2358,12 +2342,12 @@ NetCDF_get_var1_char(VALUE Var,VALUE start)
|
|
964 |
if(ndims == 0) {
|
|
965 |
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
|
966 |
}
|
|
967 |
-
|
|
968 |
+
|
|
969 |
Check_Type(start,T_ARRAY);
|
|
970 |
if(RARRAY_LEN(start) < ndims) {
|
|
971 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
972 |
}
|
|
973 |
-
|
|
974 |
+
|
|
975 |
c_start=ALLOCA_N(size_t,ndims);
|
|
976 |
c_count=ALLOCA_N(na_shape_t,ndims);
|
|
977 |
for(i=0;i<ndims;i++){
|
|
978 |
@@ -2376,13 +2360,13 @@ NetCDF_get_var1_char(VALUE Var,VALUE start)
|
|
979 |
l_start += dimlen;
|
|
980 |
}
|
|
981 |
c_start[i]=l_start;
|
|
982 |
-
|
|
983 |
+
|
|
984 |
c_count[i]=1;
|
|
985 |
}
|
|
986 |
-
|
|
987 |
-
|
|
988 |
-
|
|
989 |
-
|
|
990 |
+
|
|
991 |
+
|
|
992 |
+
|
|
993 |
+
|
|
994 |
Cbyte_to_NArray(NArray,ndims,c_count,ptr);
|
|
995 |
status = nc_get_var1_text(ncid,varid,c_start,(char *)ptr);
|
|
996 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
997 |
@@ -2392,7 +2376,7 @@ NetCDF_get_var1_char(VALUE Var,VALUE start)
|
|
998 |
|
|
999 |
}
|
|
1000 |
|
|
1001 |
-VALUE
|
|
1002 |
+VALUE
|
|
1003 |
NetCDF_get_var1_byte(VALUE Var,VALUE start)
|
|
1004 |
{
|
|
1005 |
int ncid;
|
|
1006 |
@@ -2409,7 +2393,7 @@ NetCDF_get_var1_byte(VALUE Var,VALUE start)
|
|
1007 |
na_shape_t *c_count;
|
|
1008 |
VALUE NArray;
|
|
1009 |
|
|
1010 |
-
|
|
1011 |
+
|
|
1012 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1013 |
ncid = Netcdf_var->ncid;
|
|
1014 |
varid = Netcdf_var->varid;
|
|
1015 |
@@ -2418,12 +2402,12 @@ NetCDF_get_var1_byte(VALUE Var,VALUE start)
|
|
1016 |
if(ndims == 0) {
|
|
1017 |
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
|
1018 |
}
|
|
1019 |
-
|
|
1020 |
+
|
|
1021 |
Check_Type(start,T_ARRAY);
|
|
1022 |
if(RARRAY_LEN(start) < ndims) {
|
|
1023 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1024 |
}
|
|
1025 |
-
|
|
1026 |
+
|
|
1027 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1028 |
c_count=ALLOCA_N(na_shape_t,ndims);
|
|
1029 |
for(i=0;i<ndims;i++){
|
|
1030 |
@@ -2436,13 +2420,13 @@ NetCDF_get_var1_byte(VALUE Var,VALUE start)
|
|
1031 |
l_start += dimlen;
|
|
1032 |
}
|
|
1033 |
c_start[i]=l_start;
|
|
1034 |
-
|
|
1035 |
+
|
|
1036 |
c_count[i]=1;
|
|
1037 |
}
|
|
1038 |
-
|
|
1039 |
-
|
|
1040 |
-
|
|
1041 |
-
|
|
1042 |
+
|
|
1043 |
+
|
|
1044 |
+
|
|
1045 |
+
|
|
1046 |
Cbyte_to_NArray(NArray,ndims,c_count,ptr);
|
|
1047 |
status = nc_get_var1_uchar(ncid,varid,c_start,ptr);
|
|
1048 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1049 |
@@ -2452,7 +2436,7 @@ NetCDF_get_var1_byte(VALUE Var,VALUE start)
|
|
1050 |
|
|
1051 |
}
|
|
1052 |
|
|
1053 |
-VALUE
|
|
1054 |
+VALUE
|
|
1055 |
NetCDF_get_var1_sint(VALUE Var,VALUE start)
|
|
1056 |
{
|
|
1057 |
int ncid;
|
|
1058 |
@@ -2477,12 +2461,12 @@ NetCDF_get_var1_sint(VALUE Var,VALUE start)
|
|
1059 |
if(ndims == 0) {
|
|
1060 |
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
|
1061 |
}
|
|
1062 |
-
|
|
1063 |
+
|
|
1064 |
Check_Type(start,T_ARRAY);
|
|
1065 |
if(RARRAY_LEN(start) < ndims) {
|
|
1066 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1067 |
}
|
|
1068 |
-
|
|
1069 |
+
|
|
1070 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1071 |
c_count=ALLOCA_N(na_shape_t,ndims);
|
|
1072 |
for(i=0;i<ndims;i++){
|
|
1073 |
@@ -2497,9 +2481,9 @@ NetCDF_get_var1_sint(VALUE Var,VALUE start)
|
|
1074 |
c_start[i]=l_start;
|
|
1075 |
c_count[i]=1;
|
|
1076 |
}
|
|
1077 |
-
|
|
1078 |
+
|
|
1079 |
Csint_to_NArray(NArray,ndims,c_count,ptr);
|
|
1080 |
-
|
|
1081 |
+
|
|
1082 |
status = nc_get_var1_short(ncid,varid,c_start,ptr);
|
|
1083 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1084 |
|
|
1085 |
@@ -2508,7 +2492,7 @@ NetCDF_get_var1_sint(VALUE Var,VALUE start)
|
|
1086 |
|
|
1087 |
}
|
|
1088 |
|
|
1089 |
-VALUE
|
|
1090 |
+VALUE
|
|
1091 |
NetCDF_get_var1_int(VALUE Var,VALUE start)
|
|
1092 |
{
|
|
1093 |
int ncid;
|
|
1094 |
@@ -2533,12 +2517,12 @@ NetCDF_get_var1_int(VALUE Var,VALUE start)
|
|
1095 |
if(ndims == 0) {
|
|
1096 |
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
|
1097 |
}
|
|
1098 |
-
|
|
1099 |
+
|
|
1100 |
Check_Type(start,T_ARRAY);
|
|
1101 |
if(RARRAY_LEN(start) < ndims) {
|
|
1102 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1103 |
}
|
|
1104 |
-
|
|
1105 |
+
|
|
1106 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1107 |
c_count=ALLOCA_N(na_shape_t,ndims);
|
|
1108 |
for(i=0;i<ndims;i++){
|
|
1109 |
@@ -2553,9 +2537,9 @@ NetCDF_get_var1_int(VALUE Var,VALUE start)
|
|
1110 |
c_start[i]=l_start;
|
|
1111 |
c_count[i]=1;
|
|
1112 |
}
|
|
1113 |
-
|
|
1114 |
+
|
|
1115 |
Clint_to_NArray(NArray,ndims,c_count,ptr);
|
|
1116 |
-
|
|
1117 |
+
|
|
1118 |
status = nc_get_var1_int(ncid,varid,c_start,ptr);
|
|
1119 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1120 |
|
|
1121 |
@@ -2564,7 +2548,7 @@ NetCDF_get_var1_int(VALUE Var,VALUE start)
|
|
1122 |
|
|
1123 |
}
|
|
1124 |
|
|
1125 |
-VALUE
|
|
1126 |
+VALUE
|
|
1127 |
NetCDF_get_var1_float(VALUE Var,VALUE start)
|
|
1128 |
{
|
|
1129 |
int ncid;
|
|
1130 |
@@ -2589,12 +2573,12 @@ NetCDF_get_var1_float(VALUE Var,VALUE start)
|
|
1131 |
if(ndims == 0) {
|
|
1132 |
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
|
1133 |
}
|
|
1134 |
-
|
|
1135 |
+
|
|
1136 |
Check_Type(start,T_ARRAY);
|
|
1137 |
if(RARRAY_LEN(start) < ndims) {
|
|
1138 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1139 |
}
|
|
1140 |
-
|
|
1141 |
+
|
|
1142 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1143 |
c_count=ALLOCA_N(na_shape_t,ndims);
|
|
1144 |
for(i=0;i<ndims;i++){
|
|
1145 |
@@ -2609,9 +2593,9 @@ NetCDF_get_var1_float(VALUE Var,VALUE start)
|
|
1146 |
c_start[i]=l_start;
|
|
1147 |
c_count[i]=1;
|
|
1148 |
}
|
|
1149 |
-
|
|
1150 |
+
|
|
1151 |
Cfloat_to_NArray(NArray,ndims,c_count,ptr);
|
|
1152 |
-
|
|
1153 |
+
|
|
1154 |
status = nc_get_var1_float(ncid,varid,c_start,ptr);
|
|
1155 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1156 |
|
|
1157 |
@@ -2620,7 +2604,7 @@ NetCDF_get_var1_float(VALUE Var,VALUE start)
|
|
1158 |
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
-VALUE
|
|
1162 |
+VALUE
|
|
1163 |
NetCDF_get_var1_double(VALUE Var,VALUE start)
|
|
1164 |
{
|
|
1165 |
int ncid;
|
|
1166 |
@@ -2645,12 +2629,12 @@ NetCDF_get_var1_double(VALUE Var,VALUE start)
|
|
1167 |
if(ndims == 0) {
|
|
1168 |
rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n");
|
|
1169 |
}
|
|
1170 |
-
|
|
1171 |
+
|
|
1172 |
Check_Type(start,T_ARRAY);
|
|
1173 |
if(RARRAY_LEN(start) < ndims) {
|
|
1174 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1175 |
}
|
|
1176 |
-
|
|
1177 |
+
|
|
1178 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1179 |
c_count=ALLOCA_N(na_shape_t,ndims);
|
|
1180 |
for(i=0;i<ndims;i++){
|
|
1181 |
@@ -2665,9 +2649,9 @@ NetCDF_get_var1_double(VALUE Var,VALUE start)
|
|
1182 |
c_start[i]=l_start;
|
|
1183 |
c_count[i]=1;
|
|
1184 |
}
|
|
1185 |
-
|
|
1186 |
+
|
|
1187 |
Cdouble_to_NArray(NArray,ndims,c_count,ptr);
|
|
1188 |
-
|
|
1189 |
+
|
|
1190 |
status = nc_get_var1_double(ncid,varid,c_start,ptr);
|
|
1191 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1192 |
|
|
1193 |
@@ -2698,7 +2682,7 @@ NetCDF_get_vars_char(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1194 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1195 |
ncid = Netcdf_var->ncid;
|
|
1196 |
varid = Netcdf_var->varid;
|
|
1197 |
-
|
|
1198 |
+
|
|
1199 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1200 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1201 |
if(ndims == 0) {
|
|
1202 |
@@ -2708,7 +2692,7 @@ NetCDF_get_vars_char(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1203 |
dimids = ALLOCA_N(int,ndims);
|
|
1204 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1205 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1206 |
-
|
|
1207 |
+
|
|
1208 |
Check_Type(start,T_ARRAY);
|
|
1209 |
if(RARRAY_LEN(start) < ndims){
|
|
1210 |
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1211 |
@@ -2716,7 +2700,7 @@ NetCDF_get_vars_char(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1212 |
c_start = ALLOCA_N(size_t,ndims);
|
|
1213 |
for(i=0; i<ndims; i++){
|
|
1214 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1215 |
-
|
|
1216 |
+
|
|
1217 |
if(l_start < 0) {
|
|
1218 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1219 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1220 |
@@ -2769,14 +2753,14 @@ NetCDF_get_vars_char(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1221 |
}
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
-
|
|
1225 |
+
|
|
1226 |
shape = ALLOCA_N(na_shape_t,ndims);
|
|
1227 |
for(i=0;i<ndims;i++){
|
|
1228 |
shape[ndims-1-i]=c_count[i];
|
|
1229 |
}
|
|
1230 |
-
|
|
1231 |
+
|
|
1232 |
Cbyte_to_NArray(NArray,ndims,shape,ptr);
|
|
1233 |
-
|
|
1234 |
+
|
|
1235 |
status = nc_get_vars_text(ncid,varid,c_start,c_count,c_stride,(char *)ptr);
|
|
1236 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1237 |
|
|
1238 |
@@ -2806,7 +2790,7 @@ NetCDF_get_vars_byte(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1239 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1240 |
ncid = Netcdf_var->ncid;
|
|
1241 |
varid = Netcdf_var->varid;
|
|
1242 |
-
|
|
1243 |
+
|
|
1244 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1245 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1246 |
if(ndims == 0) {
|
|
1247 |
@@ -2816,7 +2800,7 @@ NetCDF_get_vars_byte(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1248 |
dimids = ALLOCA_N(int,ndims);
|
|
1249 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1250 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1251 |
-
|
|
1252 |
+
|
|
1253 |
Check_Type(start,T_ARRAY);
|
|
1254 |
if(RARRAY_LEN(start) < ndims){
|
|
1255 |
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1256 |
@@ -2824,7 +2808,7 @@ NetCDF_get_vars_byte(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1257 |
c_start = ALLOCA_N(size_t,ndims);
|
|
1258 |
for(i=0; i<ndims; i++){
|
|
1259 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1260 |
-
|
|
1261 |
+
|
|
1262 |
if(l_start < 0) {
|
|
1263 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1264 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1265 |
@@ -2877,14 +2861,14 @@ NetCDF_get_vars_byte(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1266 |
}
|
|
1267 |
}
|
|
1268 |
|
|
1269 |
-
|
|
1270 |
+
|
|
1271 |
shape = ALLOCA_N(na_shape_t,ndims);
|
|
1272 |
for(i=0;i<ndims;i++){
|
|
1273 |
shape[ndims-1-i]=c_count[i];
|
|
1274 |
}
|
|
1275 |
-
|
|
1276 |
+
|
|
1277 |
Cbyte_to_NArray(NArray,ndims,shape,ptr);
|
|
1278 |
-
|
|
1279 |
+
|
|
1280 |
status = nc_get_vars_uchar(ncid,varid,c_start,c_count,c_stride,ptr);
|
|
1281 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1282 |
|
|
1283 |
@@ -2914,7 +2898,7 @@ NetCDF_get_vars_sint(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1284 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1285 |
ncid = Netcdf_var->ncid;
|
|
1286 |
varid = Netcdf_var->varid;
|
|
1287 |
-
|
|
1288 |
+
|
|
1289 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1290 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1291 |
if(ndims == 0) {
|
|
1292 |
@@ -2924,7 +2908,7 @@ NetCDF_get_vars_sint(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1293 |
dimids = ALLOCA_N(int,ndims);
|
|
1294 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1295 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1296 |
-
|
|
1297 |
+
|
|
1298 |
Check_Type(start,T_ARRAY);
|
|
1299 |
if(RARRAY_LEN(start) < ndims){
|
|
1300 |
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1301 |
@@ -2932,7 +2916,7 @@ NetCDF_get_vars_sint(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1302 |
c_start = ALLOCA_N(size_t,ndims);
|
|
1303 |
for(i=0; i<ndims; i++){
|
|
1304 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1305 |
-
|
|
1306 |
+
|
|
1307 |
if(l_start < 0) {
|
|
1308 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1309 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1310 |
@@ -2984,19 +2968,19 @@ NetCDF_get_vars_sint(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1311 |
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
|
1312 |
}
|
|
1313 |
}
|
|
1314 |
-
|
|
1315 |
-
|
|
1316 |
+
|
|
1317 |
+
|
|
1318 |
shape = ALLOCA_N(na_shape_t,ndims);
|
|
1319 |
for(i=0;i<ndims;i++){
|
|
1320 |
shape[ndims-1-i]=c_count[i];
|
|
1321 |
}
|
|
1322 |
|
|
1323 |
Csint_to_NArray(NArray,ndims,shape,ptr);
|
|
1324 |
-
|
|
1325 |
+
|
|
1326 |
|
|
1327 |
status = nc_get_vars_short(ncid,varid,c_start,c_count,c_stride,ptr);
|
|
1328 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1329 |
-
|
|
1330 |
+
|
|
1331 |
OBJ_TAINT(NArray);
|
|
1332 |
return NArray;
|
|
1333 |
}
|
|
1334 |
@@ -3023,7 +3007,7 @@ NetCDF_get_vars_int(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1335 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1336 |
ncid = Netcdf_var->ncid;
|
|
1337 |
varid = Netcdf_var->varid;
|
|
1338 |
-
|
|
1339 |
+
|
|
1340 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1341 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1342 |
if(ndims == 0) {
|
|
1343 |
@@ -3033,7 +3017,7 @@ NetCDF_get_vars_int(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1344 |
dimids = ALLOCA_N(int,ndims);
|
|
1345 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1346 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1347 |
-
|
|
1348 |
+
|
|
1349 |
Check_Type(start,T_ARRAY);
|
|
1350 |
if(RARRAY_LEN(start) < ndims){
|
|
1351 |
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1352 |
@@ -3041,7 +3025,7 @@ NetCDF_get_vars_int(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1353 |
c_start = ALLOCA_N(size_t,ndims);
|
|
1354 |
for(i=0; i<ndims; i++){
|
|
1355 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1356 |
-
|
|
1357 |
+
|
|
1358 |
if(l_start < 0) {
|
|
1359 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1360 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1361 |
@@ -3094,14 +3078,14 @@ NetCDF_get_vars_int(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1362 |
}
|
|
1363 |
}
|
|
1364 |
|
|
1365 |
-
|
|
1366 |
+
|
|
1367 |
shape = ALLOCA_N(na_shape_t,ndims);
|
|
1368 |
for(i=0;i<ndims;i++){
|
|
1369 |
shape[ndims-1-i]=c_count[i];
|
|
1370 |
}
|
|
1371 |
|
|
1372 |
Clint_to_NArray(NArray,ndims,shape,ptr);
|
|
1373 |
-
|
|
1374 |
+
|
|
1375 |
|
|
1376 |
status = nc_get_vars_int(ncid,varid,c_start,c_count,c_stride,ptr);
|
|
1377 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1378 |
@@ -3132,7 +3116,7 @@ NetCDF_get_vars_float(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1379 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1380 |
ncid = Netcdf_var->ncid;
|
|
1381 |
varid = Netcdf_var->varid;
|
|
1382 |
-
|
|
1383 |
+
|
|
1384 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1385 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1386 |
if(ndims == 0) {
|
|
1387 |
@@ -3142,7 +3126,7 @@ NetCDF_get_vars_float(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1388 |
dimids = ALLOCA_N(int,ndims);
|
|
1389 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1390 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1391 |
-
|
|
1392 |
+
|
|
1393 |
Check_Type(start,T_ARRAY);
|
|
1394 |
if(RARRAY_LEN(start) < ndims){
|
|
1395 |
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1396 |
@@ -3150,7 +3134,7 @@ NetCDF_get_vars_float(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1397 |
c_start = ALLOCA_N(size_t,ndims);
|
|
1398 |
for(i=0; i<ndims; i++){
|
|
1399 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1400 |
-
|
|
1401 |
+
|
|
1402 |
if(l_start < 0) {
|
|
1403 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1404 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1405 |
@@ -3202,16 +3186,16 @@ NetCDF_get_vars_float(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1406 |
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
|
1407 |
}
|
|
1408 |
}
|
|
1409 |
-
|
|
1410 |
+
|
|
1411 |
|
|
1412 |
shape = ALLOCA_N(na_shape_t,ndims);
|
|
1413 |
for(i=0;i<ndims;i++){
|
|
1414 |
shape[ndims-1-i]=c_count[i];
|
|
1415 |
}
|
|
1416 |
-
|
|
1417 |
+
|
|
1418 |
Cfloat_to_NArray(NArray,ndims,shape,ptr);
|
|
1419 |
-
|
|
1420 |
-
|
|
1421 |
+
|
|
1422 |
+
|
|
1423 |
status = nc_get_vars_float(ncid,varid,c_start,c_count,c_stride,ptr);
|
|
1424 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1425 |
|
|
1426 |
@@ -3241,7 +3225,7 @@ NetCDF_get_vars_double(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1427 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1428 |
ncid = Netcdf_var->ncid;
|
|
1429 |
varid = Netcdf_var->varid;
|
|
1430 |
-
|
|
1431 |
+
|
|
1432 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1433 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1434 |
if(ndims == 0) {
|
|
1435 |
@@ -3251,7 +3235,7 @@ NetCDF_get_vars_double(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1436 |
dimids = ALLOCA_N(int,ndims);
|
|
1437 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1438 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1439 |
-
|
|
1440 |
+
|
|
1441 |
Check_Type(start,T_ARRAY);
|
|
1442 |
if(RARRAY_LEN(start) < ndims){
|
|
1443 |
rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1444 |
@@ -3259,7 +3243,7 @@ NetCDF_get_vars_double(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1445 |
c_start = ALLOCA_N(size_t,ndims);
|
|
1446 |
for(i=0; i<ndims; i++){
|
|
1447 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1448 |
-
|
|
1449 |
+
|
|
1450 |
if(l_start < 0) {
|
|
1451 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1452 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1453 |
@@ -3311,15 +3295,15 @@ NetCDF_get_vars_double(VALUE Var,VALUE start,VALUE end,VALUE stride)
|
|
1454 |
c_count[i]=(l_end-c_start[i])/c_stride[i]+1;
|
|
1455 |
}
|
|
1456 |
}
|
|
1457 |
-
|
|
1458 |
+
|
|
1459 |
|
|
1460 |
shape = ALLOCA_N(na_shape_t,ndims);
|
|
1461 |
for(i=0;i<ndims;i++){
|
|
1462 |
shape[ndims-1-i]=c_count[i];
|
|
1463 |
}
|
|
1464 |
-
|
|
1465 |
+
|
|
1466 |
Cdouble_to_NArray(NArray,ndims,shape,ptr);
|
|
1467 |
-
|
|
1468 |
+
|
|
1469 |
status = nc_get_vars_double(ncid,varid,c_start,c_count,c_stride,ptr);
|
|
1470 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1471 |
|
|
1472 |
@@ -3343,13 +3327,12 @@ NetCDF_put_var_char(VALUE Var,VALUE NArray)
|
|
1473 |
size_t lengthp;
|
|
1474 |
char *var_name;
|
|
1475 |
|
|
1476 |
- rb_secure(3);
|
|
1477 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1478 |
ncid=Netcdf_var->ncid;
|
|
1479 |
varid=Netcdf_var->varid;
|
|
1480 |
|
|
1481 |
Array_to_Cbyte_len(NArray,ptr,len);
|
|
1482 |
-
|
|
1483 |
+
|
|
1484 |
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
|
1485 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1486 |
for(i=0;i<ndimsp;i++){
|
|
1487 |
@@ -3388,13 +3371,12 @@ NetCDF_put_var_byte(VALUE Var,VALUE NArray)
|
|
1488 |
size_t lengthp;
|
|
1489 |
char *var_name;
|
|
1490 |
|
|
1491 |
- rb_secure(3);
|
|
1492 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1493 |
ncid=Netcdf_var->ncid;
|
|
1494 |
varid=Netcdf_var->varid;
|
|
1495 |
|
|
1496 |
Array_to_Cbyte_len(NArray,ptr,len);
|
|
1497 |
-
|
|
1498 |
+
|
|
1499 |
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
|
1500 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1501 |
for(i=0;i<ndimsp;i++){
|
|
1502 |
@@ -3433,12 +3415,11 @@ NetCDF_put_var_short(VALUE Var,VALUE NArray)
|
|
1503 |
size_t lengthp;
|
|
1504 |
char *var_name;
|
|
1505 |
|
|
1506 |
- rb_secure(3);
|
|
1507 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1508 |
ncid=Netcdf_var->ncid;
|
|
1509 |
varid=Netcdf_var->varid;
|
|
1510 |
Array_to_Csint_len(NArray,ptr,len);
|
|
1511 |
-
|
|
1512 |
+
|
|
1513 |
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
|
1514 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1515 |
for(i=0;i<ndimsp;i++){
|
|
1516 |
@@ -3478,7 +3459,6 @@ NetCDF_put_var_int(VALUE Var,VALUE NArray)
|
|
1517 |
size_t lengthp;
|
|
1518 |
char *var_name;
|
|
1519 |
|
|
1520 |
- rb_secure(3);
|
|
1521 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1522 |
ncid=Netcdf_var->ncid;
|
|
1523 |
varid=Netcdf_var->varid;
|
|
1524 |
@@ -3503,8 +3483,8 @@ NetCDF_put_var_int(VALUE Var,VALUE NArray)
|
|
1525 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1526 |
rb_raise(rb_eNetcdfError,"Length of NArray don't equal to length of total array length in the '%s'\n",var_name);
|
|
1527 |
}
|
|
1528 |
-
|
|
1529 |
-
|
|
1530 |
+
|
|
1531 |
+
|
|
1532 |
status = nc_put_var_int(ncid,varid,ptr);
|
|
1533 |
if(status !=NC_NOERR) NC_RAISE(status);
|
|
1534 |
return Qnil;
|
|
1535 |
@@ -3525,15 +3505,14 @@ NetCDF_put_var_float(VALUE Var,VALUE NArray)
|
|
1536 |
int dimids[NC_MAX_DIMS];
|
|
1537 |
size_t lengthp;
|
|
1538 |
char *var_name;
|
|
1539 |
-
|
|
1540 |
-
|
|
1541 |
- rb_secure(3);
|
|
1542 |
+
|
|
1543 |
+
|
|
1544 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1545 |
ncid=Netcdf_var->ncid;
|
|
1546 |
varid=Netcdf_var->varid;
|
|
1547 |
|
|
1548 |
Array_to_Cfloat_len(NArray,ptr,len);
|
|
1549 |
-
|
|
1550 |
+
|
|
1551 |
status = nc_inq_varndims(ncid,varid,&ndimsp);
|
|
1552 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1553 |
for(i=0;i<ndimsp;i++){
|
|
1554 |
@@ -3574,7 +3553,6 @@ NetCDF_put_var_double(VALUE Var,VALUE NArray)
|
|
1555 |
char *var_name;
|
|
1556 |
|
|
1557 |
|
|
1558 |
- rb_secure(3);
|
|
1559 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1560 |
ncid=Netcdf_var->ncid;
|
|
1561 |
varid=Netcdf_var->varid;
|
|
1562 |
@@ -3619,19 +3597,18 @@ NetCDF_put_var1_char(VALUE Var,VALUE NArray,VALUE start)
|
|
1563 |
int ndims;
|
|
1564 |
int *dimids;
|
|
1565 |
size_t dimlen;
|
|
1566 |
-
|
|
1567 |
- rb_secure(3);
|
|
1568 |
+
|
|
1569 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1570 |
ncid=Netcdf_var->ncid;
|
|
1571 |
varid=Netcdf_var->varid;
|
|
1572 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1573 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1574 |
|
|
1575 |
-
|
|
1576 |
+
|
|
1577 |
dimids = ALLOCA_N(int,ndims);
|
|
1578 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1579 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1580 |
-
|
|
1581 |
+
|
|
1582 |
Check_Type(start,T_ARRAY);
|
|
1583 |
if(RARRAY_LEN(start) <ndims) {
|
|
1584 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1585 |
@@ -3640,7 +3617,7 @@ NetCDF_put_var1_char(VALUE Var,VALUE NArray,VALUE start)
|
|
1586 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1587 |
for(i=0;i<ndims;i++){
|
|
1588 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1589 |
-
|
|
1590 |
+
|
|
1591 |
if(l_start < 0) {
|
|
1592 |
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
|
1593 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1594 |
@@ -3670,19 +3647,18 @@ NetCDF_put_var1_byte(VALUE Var,VALUE NArray,VALUE start)
|
|
1595 |
int ndims;
|
|
1596 |
int *dimids;
|
|
1597 |
size_t dimlen;
|
|
1598 |
-
|
|
1599 |
- rb_secure(3);
|
|
1600 |
+
|
|
1601 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1602 |
ncid=Netcdf_var->ncid;
|
|
1603 |
varid=Netcdf_var->varid;
|
|
1604 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1605 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1606 |
|
|
1607 |
-
|
|
1608 |
+
|
|
1609 |
dimids = ALLOCA_N(int,ndims);
|
|
1610 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1611 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1612 |
-
|
|
1613 |
+
|
|
1614 |
Check_Type(start,T_ARRAY);
|
|
1615 |
if(RARRAY_LEN(start) <ndims) {
|
|
1616 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1617 |
@@ -3691,7 +3667,7 @@ NetCDF_put_var1_byte(VALUE Var,VALUE NArray,VALUE start)
|
|
1618 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1619 |
for(i=0;i<ndims;i++){
|
|
1620 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1621 |
-
|
|
1622 |
+
|
|
1623 |
if(l_start < 0) {
|
|
1624 |
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
|
1625 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1626 |
@@ -3721,19 +3697,18 @@ NetCDF_put_var1_sint(VALUE Var,VALUE NArray,VALUE start)
|
|
1627 |
int ndims;
|
|
1628 |
int *dimids;
|
|
1629 |
size_t dimlen;
|
|
1630 |
-
|
|
1631 |
- rb_secure(3);
|
|
1632 |
+
|
|
1633 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1634 |
ncid=Netcdf_var->ncid;
|
|
1635 |
varid=Netcdf_var->varid;
|
|
1636 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1637 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1638 |
|
|
1639 |
-
|
|
1640 |
+
|
|
1641 |
dimids = ALLOCA_N(int,ndims);
|
|
1642 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1643 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1644 |
-
|
|
1645 |
+
|
|
1646 |
Check_Type(start,T_ARRAY);
|
|
1647 |
if(RARRAY_LEN(start) <ndims) {
|
|
1648 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1649 |
@@ -3742,7 +3717,7 @@ NetCDF_put_var1_sint(VALUE Var,VALUE NArray,VALUE start)
|
|
1650 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1651 |
for(i=0;i<ndims;i++){
|
|
1652 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1653 |
-
|
|
1654 |
+
|
|
1655 |
if(l_start < 0) {
|
|
1656 |
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
|
1657 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1658 |
@@ -3771,19 +3746,18 @@ NetCDF_put_var1_int(VALUE Var,VALUE NArray,VALUE start)
|
|
1659 |
int ndims;
|
|
1660 |
int *dimids;
|
|
1661 |
size_t dimlen;
|
|
1662 |
-
|
|
1663 |
- rb_secure(3);
|
|
1664 |
+
|
|
1665 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1666 |
ncid=Netcdf_var->ncid;
|
|
1667 |
varid=Netcdf_var->varid;
|
|
1668 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1669 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1670 |
|
|
1671 |
-
|
|
1672 |
+
|
|
1673 |
dimids = ALLOCA_N(int,ndims);
|
|
1674 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1675 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1676 |
-
|
|
1677 |
+
|
|
1678 |
Check_Type(start,T_ARRAY);
|
|
1679 |
if(RARRAY_LEN(start) <ndims) {
|
|
1680 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1681 |
@@ -3792,7 +3766,7 @@ NetCDF_put_var1_int(VALUE Var,VALUE NArray,VALUE start)
|
|
1682 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1683 |
for(i=0;i<ndims;i++){
|
|
1684 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1685 |
-
|
|
1686 |
+
|
|
1687 |
if(l_start < 0) {
|
|
1688 |
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
|
1689 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1690 |
@@ -3822,19 +3796,18 @@ NetCDF_put_var1_float(VALUE Var,VALUE NArray,VALUE start)
|
|
1691 |
int ndims;
|
|
1692 |
int *dimids;
|
|
1693 |
size_t dimlen;
|
|
1694 |
-
|
|
1695 |
- rb_secure(3);
|
|
1696 |
+
|
|
1697 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1698 |
ncid=Netcdf_var->ncid;
|
|
1699 |
varid=Netcdf_var->varid;
|
|
1700 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1701 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1702 |
|
|
1703 |
-
|
|
1704 |
+
|
|
1705 |
dimids = ALLOCA_N(int,ndims);
|
|
1706 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1707 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1708 |
-
|
|
1709 |
+
|
|
1710 |
Check_Type(start,T_ARRAY);
|
|
1711 |
if(RARRAY_LEN(start) <ndims) {
|
|
1712 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1713 |
@@ -3843,7 +3816,7 @@ NetCDF_put_var1_float(VALUE Var,VALUE NArray,VALUE start)
|
|
1714 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1715 |
for(i=0;i<ndims;i++){
|
|
1716 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1717 |
-
|
|
1718 |
+
|
|
1719 |
if(l_start < 0) {
|
|
1720 |
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
|
1721 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1722 |
@@ -3873,19 +3846,18 @@ NetCDF_put_var1_double(VALUE Var,VALUE NArray,VALUE start)
|
|
1723 |
int ndims;
|
|
1724 |
int *dimids;
|
|
1725 |
size_t dimlen;
|
|
1726 |
-
|
|
1727 |
- rb_secure(3);
|
|
1728 |
+
|
|
1729 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1730 |
ncid=Netcdf_var->ncid;
|
|
1731 |
varid=Netcdf_var->varid;
|
|
1732 |
status = nc_inq_varndims(ncid,varid,&ndims);
|
|
1733 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1734 |
|
|
1735 |
-
|
|
1736 |
+
|
|
1737 |
dimids = ALLOCA_N(int,ndims);
|
|
1738 |
status = nc_inq_vardimid(ncid,varid,dimids);
|
|
1739 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1740 |
-
|
|
1741 |
+
|
|
1742 |
Check_Type(start,T_ARRAY);
|
|
1743 |
if(RARRAY_LEN(start) <ndims) {
|
|
1744 |
rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n");
|
|
1745 |
@@ -3894,7 +3866,7 @@ NetCDF_put_var1_double(VALUE Var,VALUE NArray,VALUE start)
|
|
1746 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1747 |
for(i=0;i<ndims;i++){
|
|
1748 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1749 |
-
|
|
1750 |
+
|
|
1751 |
if(l_start < 0) {
|
|
1752 |
status = nc_inq_dimlen(ncid,dimids[i],&dimlen);
|
|
1753 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1754 |
@@ -3930,7 +3902,6 @@ NetCDF_put_vars_char(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1755 |
int *dimids;
|
|
1756 |
size_t dimlen;
|
|
1757 |
|
|
1758 |
- rb_secure(3);
|
|
1759 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1760 |
ncid=Netcdf_var->ncid;
|
|
1761 |
varid=Netcdf_var->varid;
|
|
1762 |
@@ -3943,12 +3914,12 @@ NetCDF_put_vars_char(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1763 |
|
|
1764 |
Check_Type(start,T_ARRAY);
|
|
1765 |
if(RARRAY_LEN(start) < ndims) {
|
|
1766 |
- rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1767 |
+ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1768 |
}
|
|
1769 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1770 |
for(i=0; i<ndims; i++){
|
|
1771 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1772 |
-
|
|
1773 |
+
|
|
1774 |
if(l_start < 0) {
|
|
1775 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1776 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1777 |
@@ -3956,7 +3927,7 @@ NetCDF_put_vars_char(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1778 |
}
|
|
1779 |
c_start[i]=l_start;
|
|
1780 |
}
|
|
1781 |
-
|
|
1782 |
+
|
|
1783 |
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
|
1784 |
switch(TYPE(stride)){
|
|
1785 |
case T_NIL:
|
|
1786 |
@@ -3967,12 +3938,12 @@ NetCDF_put_vars_char(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1787 |
default:
|
|
1788 |
Check_Type(stride,T_ARRAY);
|
|
1789 |
if(RARRAY_LEN(stride) < ndims) {
|
|
1790 |
- rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1791 |
+ rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1792 |
}
|
|
1793 |
for(i=0; i<ndims; i++){
|
|
1794 |
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[ndims-1-i]);
|
|
1795 |
if(c_stride[i]==0) {
|
|
1796 |
- rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1797 |
+ rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1798 |
}
|
|
1799 |
}
|
|
1800 |
}
|
|
1801 |
@@ -3990,7 +3961,7 @@ NetCDF_put_vars_char(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1802 |
default:
|
|
1803 |
Check_Type(end,T_ARRAY);
|
|
1804 |
if(RARRAY_LEN(end) < ndims) {
|
|
1805 |
- rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1806 |
+ rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1807 |
}
|
|
1808 |
for(i=0; i<ndims; i++){
|
|
1809 |
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-i]);
|
|
1810 |
@@ -4036,7 +4007,6 @@ NetCDF_put_vars_byte(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1811 |
int *dimids;
|
|
1812 |
size_t dimlen;
|
|
1813 |
|
|
1814 |
- rb_secure(3);
|
|
1815 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1816 |
ncid=Netcdf_var->ncid;
|
|
1817 |
varid=Netcdf_var->varid;
|
|
1818 |
@@ -4049,12 +4019,12 @@ NetCDF_put_vars_byte(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1819 |
|
|
1820 |
Check_Type(start,T_ARRAY);
|
|
1821 |
if(RARRAY_LEN(start) < ndims) {
|
|
1822 |
- rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1823 |
+ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1824 |
}
|
|
1825 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1826 |
for(i=0; i<ndims; i++){
|
|
1827 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1828 |
-
|
|
1829 |
+
|
|
1830 |
if(l_start < 0) {
|
|
1831 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1832 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1833 |
@@ -4062,7 +4032,7 @@ NetCDF_put_vars_byte(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1834 |
}
|
|
1835 |
c_start[i]=l_start;
|
|
1836 |
}
|
|
1837 |
-
|
|
1838 |
+
|
|
1839 |
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
|
1840 |
switch(TYPE(stride)){
|
|
1841 |
case T_NIL:
|
|
1842 |
@@ -4073,12 +4043,12 @@ NetCDF_put_vars_byte(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1843 |
default:
|
|
1844 |
Check_Type(stride,T_ARRAY);
|
|
1845 |
if(RARRAY_LEN(stride) < ndims) {
|
|
1846 |
- rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1847 |
+ rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1848 |
}
|
|
1849 |
for(i=0; i<ndims; i++){
|
|
1850 |
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[ndims-1-i]);
|
|
1851 |
if(c_stride[i]==0) {
|
|
1852 |
- rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1853 |
+ rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1854 |
}
|
|
1855 |
}
|
|
1856 |
}
|
|
1857 |
@@ -4096,7 +4066,7 @@ NetCDF_put_vars_byte(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1858 |
default:
|
|
1859 |
Check_Type(end,T_ARRAY);
|
|
1860 |
if(RARRAY_LEN(end) < ndims) {
|
|
1861 |
- rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1862 |
+ rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1863 |
}
|
|
1864 |
for(i=0; i<ndims; i++){
|
|
1865 |
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-i]);
|
|
1866 |
@@ -4142,7 +4112,6 @@ NetCDF_put_vars_sint(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1867 |
int *dimids;
|
|
1868 |
size_t dimlen;
|
|
1869 |
|
|
1870 |
- rb_secure(3);
|
|
1871 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1872 |
ncid=Netcdf_var->ncid;
|
|
1873 |
varid=Netcdf_var->varid;
|
|
1874 |
@@ -4155,12 +4124,12 @@ NetCDF_put_vars_sint(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1875 |
|
|
1876 |
Check_Type(start,T_ARRAY);
|
|
1877 |
if(RARRAY_LEN(start) < ndims) {
|
|
1878 |
- rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1879 |
+ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1880 |
}
|
|
1881 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1882 |
for(i=0; i<ndims; i++){
|
|
1883 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1884 |
-
|
|
1885 |
+
|
|
1886 |
if(l_start < 0) {
|
|
1887 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1888 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1889 |
@@ -4168,7 +4137,7 @@ NetCDF_put_vars_sint(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1890 |
}
|
|
1891 |
c_start[i]=l_start;
|
|
1892 |
}
|
|
1893 |
-
|
|
1894 |
+
|
|
1895 |
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
|
1896 |
switch(TYPE(stride)){
|
|
1897 |
case T_NIL:
|
|
1898 |
@@ -4179,12 +4148,12 @@ NetCDF_put_vars_sint(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1899 |
default:
|
|
1900 |
Check_Type(stride,T_ARRAY);
|
|
1901 |
if(RARRAY_LEN(stride) < ndims) {
|
|
1902 |
- rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1903 |
+ rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1904 |
}
|
|
1905 |
for(i=0; i<ndims; i++){
|
|
1906 |
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[ndims-1-i]);
|
|
1907 |
if(c_stride[i]==0) {
|
|
1908 |
- rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1909 |
+ rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1910 |
}
|
|
1911 |
}
|
|
1912 |
}
|
|
1913 |
@@ -4202,7 +4171,7 @@ NetCDF_put_vars_sint(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1914 |
default:
|
|
1915 |
Check_Type(end,T_ARRAY);
|
|
1916 |
if(RARRAY_LEN(end) < ndims) {
|
|
1917 |
- rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1918 |
+ rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1919 |
}
|
|
1920 |
for(i=0; i<ndims; i++){
|
|
1921 |
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-i]);
|
|
1922 |
@@ -4249,7 +4218,6 @@ NetCDF_put_vars_int(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1923 |
int *dimids;
|
|
1924 |
size_t dimlen;
|
|
1925 |
|
|
1926 |
- rb_secure(3);
|
|
1927 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1928 |
ncid=Netcdf_var->ncid;
|
|
1929 |
varid=Netcdf_var->varid;
|
|
1930 |
@@ -4262,12 +4230,12 @@ NetCDF_put_vars_int(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1931 |
|
|
1932 |
Check_Type(start,T_ARRAY);
|
|
1933 |
if(RARRAY_LEN(start) < ndims) {
|
|
1934 |
- rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1935 |
+ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
1936 |
}
|
|
1937 |
c_start=ALLOCA_N(size_t,ndims);
|
|
1938 |
for(i=0; i<ndims; i++){
|
|
1939 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
1940 |
-
|
|
1941 |
+
|
|
1942 |
if(l_start < 0) {
|
|
1943 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
1944 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
1945 |
@@ -4275,7 +4243,7 @@ NetCDF_put_vars_int(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1946 |
}
|
|
1947 |
c_start[i]=l_start;
|
|
1948 |
}
|
|
1949 |
-
|
|
1950 |
+
|
|
1951 |
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
|
1952 |
switch(TYPE(stride)){
|
|
1953 |
case T_NIL:
|
|
1954 |
@@ -4286,12 +4254,12 @@ NetCDF_put_vars_int(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1955 |
default:
|
|
1956 |
Check_Type(stride,T_ARRAY);
|
|
1957 |
if(RARRAY_LEN(stride) < ndims) {
|
|
1958 |
- rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1959 |
+ rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
1960 |
}
|
|
1961 |
for(i=0; i<ndims; i++){
|
|
1962 |
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[ndims-1-i]);
|
|
1963 |
if(c_stride[i]==0) {
|
|
1964 |
- rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1965 |
+ rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
1966 |
}
|
|
1967 |
}
|
|
1968 |
}
|
|
1969 |
@@ -4309,7 +4277,7 @@ NetCDF_put_vars_int(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1970 |
default:
|
|
1971 |
Check_Type(end,T_ARRAY);
|
|
1972 |
if(RARRAY_LEN(end) < ndims) {
|
|
1973 |
- rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1974 |
+ rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
1975 |
}
|
|
1976 |
for(i=0; i<ndims; i++){
|
|
1977 |
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-i]);
|
|
1978 |
@@ -4326,8 +4294,8 @@ NetCDF_put_vars_int(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1979 |
ptr = ALLOCA_N(int,c_count_all);
|
|
1980 |
for(i=0;i<c_count_all;i++){ptr[i]=scalar;}
|
|
1981 |
} else if(len != c_count_all) {
|
|
1982 |
- rb_raise(rb_eNetcdfError,
|
|
1983 |
- "length of the array does not agree with that of the subset\n");
|
|
1984 |
+ rb_raise(rb_eNetcdfError,
|
|
1985 |
+ "length of the array does not agree with that of the subset\n");
|
|
1986 |
}
|
|
1987 |
}
|
|
1988 |
|
|
1989 |
@@ -4356,7 +4324,6 @@ NetCDF_put_vars_float(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1990 |
int *dimids;
|
|
1991 |
size_t dimlen;
|
|
1992 |
|
|
1993 |
- rb_secure(3);
|
|
1994 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
1995 |
ncid=Netcdf_var->ncid;
|
|
1996 |
varid=Netcdf_var->varid;
|
|
1997 |
@@ -4369,12 +4336,12 @@ NetCDF_put_vars_float(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
1998 |
|
|
1999 |
Check_Type(start,T_ARRAY);
|
|
2000 |
if(RARRAY_LEN(start) < ndims) {
|
|
2001 |
- rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
2002 |
+ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
2003 |
}
|
|
2004 |
c_start=ALLOCA_N(size_t,ndims);
|
|
2005 |
for(i=0; i<ndims; i++){
|
|
2006 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
2007 |
-
|
|
2008 |
+
|
|
2009 |
if(l_start < 0) {
|
|
2010 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
2011 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
2012 |
@@ -4382,7 +4349,7 @@ NetCDF_put_vars_float(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
2013 |
}
|
|
2014 |
c_start[i]=l_start;
|
|
2015 |
}
|
|
2016 |
-
|
|
2017 |
+
|
|
2018 |
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
|
2019 |
switch(TYPE(stride)){
|
|
2020 |
case T_NIL:
|
|
2021 |
@@ -4393,12 +4360,12 @@ NetCDF_put_vars_float(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
2022 |
default:
|
|
2023 |
Check_Type(stride,T_ARRAY);
|
|
2024 |
if(RARRAY_LEN(stride) < ndims) {
|
|
2025 |
- rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
2026 |
+ rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
2027 |
}
|
|
2028 |
for(i=0; i<ndims; i++){
|
|
2029 |
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[ndims-1-i]);
|
|
2030 |
if(c_stride[i]==0) {
|
|
2031 |
- rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
2032 |
+ rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
2033 |
}
|
|
2034 |
}
|
|
2035 |
}
|
|
2036 |
@@ -4416,7 +4383,7 @@ NetCDF_put_vars_float(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride)
|
|
2037 |
default:
|
|
2038 |
Check_Type(end,T_ARRAY);
|
|
2039 |
if(RARRAY_LEN(end) < ndims) {
|
|
2040 |
- rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
2041 |
+ rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
2042 |
}
|
|
2043 |
for(i=0; i<ndims; i++){
|
|
2044 |
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-i]);
|
|
2045 |
@@ -4463,7 +4430,6 @@ NetCDF_put_vars_double(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride
|
|
2046 |
int *dimids;
|
|
2047 |
size_t dimlen;
|
|
2048 |
|
|
2049 |
- rb_secure(3);
|
|
2050 |
Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var);
|
|
2051 |
ncid=Netcdf_var->ncid;
|
|
2052 |
varid=Netcdf_var->varid;
|
|
2053 |
@@ -4476,12 +4442,12 @@ NetCDF_put_vars_double(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride
|
|
2054 |
|
|
2055 |
Check_Type(start,T_ARRAY);
|
|
2056 |
if(RARRAY_LEN(start) < ndims) {
|
|
2057 |
- rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
2058 |
+ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n");
|
|
2059 |
}
|
|
2060 |
c_start=ALLOCA_N(size_t,ndims);
|
|
2061 |
for(i=0; i<ndims; i++){
|
|
2062 |
l_start=NUM2INT(RARRAY_PTR(start)[ndims-1-i]);
|
|
2063 |
-
|
|
2064 |
+
|
|
2065 |
if(l_start < 0) {
|
|
2066 |
status = nc_inq_dimlen(ncid, dimids[i], &dimlen);
|
|
2067 |
if(status != NC_NOERR) NC_RAISE(status);
|
|
2068 |
@@ -4489,7 +4455,7 @@ NetCDF_put_vars_double(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride
|
|
2069 |
}
|
|
2070 |
c_start[i]=l_start;
|
|
2071 |
}
|
|
2072 |
-
|
|
2073 |
+
|
|
2074 |
c_stride=ALLOCA_N(ptrdiff_t,ndims);
|
|
2075 |
switch(TYPE(stride)){
|
|
2076 |
case T_NIL:
|
|
2077 |
@@ -4500,12 +4466,12 @@ NetCDF_put_vars_double(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride
|
|
2078 |
default:
|
|
2079 |
Check_Type(stride,T_ARRAY);
|
|
2080 |
if(RARRAY_LEN(stride) < ndims) {
|
|
2081 |
- rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
2082 |
+ rb_raise(rb_eNetcdfError, "Length of 'stride' is too short\n");
|
|
2083 |
}
|
|
2084 |
for(i=0; i<ndims; i++){
|
|
2085 |
c_stride[i]=NUM2INT(RARRAY_PTR(stride)[ndims-1-i]);
|
|
2086 |
if(c_stride[i]==0) {
|
|
2087 |
- rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
2088 |
+ rb_raise(rb_eNetcdfError, "stride cannot be zero\n");
|
|
2089 |
}
|
|
2090 |
}
|
|
2091 |
}
|
|
2092 |
@@ -4523,7 +4489,7 @@ NetCDF_put_vars_double(VALUE Var,VALUE NArray,VALUE start,VALUE end,VALUE stride
|
|
2093 |
default:
|
|
2094 |
Check_Type(end,T_ARRAY);
|
|
2095 |
if(RARRAY_LEN(end) < ndims) {
|
|
2096 |
- rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
2097 |
+ rb_raise(rb_eNetcdfError, "Length of 'end' is too short\n");
|
|
2098 |
}
|
|
2099 |
for(i=0; i<ndims; i++){
|
|
2100 |
l_end=NUM2INT(RARRAY_PTR(end)[ndims-1-i]);
|
|
2101 |
@@ -4589,7 +4555,7 @@ Init_netcdfraw(void)
|
|
2102 |
rb_eNetcdfEdge = rb_define_class("NetcdfEdge",rb_eNetcdfError);
|
|
2103 |
rb_eNetcdfStride = rb_define_class("NetcdfStride",rb_eNetcdfError);
|
|
2104 |
rb_eNetcdfBadname = rb_define_class("NetcdfBadname",rb_eNetcdfError);
|
|
2105 |
- /* N.B. following must match value in ncx.h */
|
|
2106 |
+ /* N.B. following must match value in ncx.h */
|
|
2107 |
rb_eNetcdfRange = rb_define_class("NetcdfRange",rb_eNetcdfError);
|
|
2108 |
rb_eNetcdfNomem = rb_define_class("NetcdfNomem",rb_eNetcdfError);
|
|
2109 |
/* Global error status */
|
|
2110 |
@@ -4607,10 +4573,10 @@ Init_netcdfraw(void)
|
|
2111 |
rb_define_const(cNetCDF, "NC_NOCLOBBER", INT2FIX(NC_NOCLOBBER));
|
|
2112 |
#if NCVER >= 400
|
|
2113 |
rb_define_const(cNetCDF, "NC_64BIT_OFFSET", INT2FIX(NC_64BIT_OFFSET));
|
|
2114 |
- /* NC_64BIT_OFFSET supports large files in the class data format */
|
|
2115 |
+ /* NC_64BIT_OFFSET supports large files in the class data format */
|
|
2116 |
rb_define_const(cNetCDF, "NC_NETCDF4", INT2FIX(NC_NETCDF4));
|
|
2117 |
rb_define_const(cNetCDF, "NC_CLASSIC_MODEL", INT2FIX(NC_CLASSIC_MODEL));
|
|
2118 |
- /* for use as ( NC_NETCDF4 | NC_CLASSIC_MODEL ) to ensure the classic
|
|
2119 |
+ /* for use as ( NC_NETCDF4 | NC_CLASSIC_MODEL ) to ensure the classic
|
|
2120 |
data model in NetCDF4 by disabling new features like groups */
|
|
2121 |
rb_define_const(cNetCDF, "NC_ENDIAN_NATIVE", INT2FIX(NC_ENDIAN_NATIVE));
|
|
2122 |
rb_define_const(cNetCDF, "NC_ENDIAN_LITTLE", INT2FIX(NC_ENDIAN_LITTLE));
|
|
2123 |
@@ -4621,7 +4587,7 @@ Init_netcdfraw(void)
|
|
2124 |
rb_define_const(cNetCDF, "NC_FORMAT_NETCDF4", INT2FIX(NC_FORMAT_NETCDF4));
|
|
2125 |
rb_define_const(cNetCDF, "NC_FORMAT_NETCDF4_CLASSIC", INT2FIX(NC_FORMAT_NETCDF4_CLASSIC));
|
|
2126 |
#endif
|
|
2127 |
-
|
|
2128 |
+
|
|
2129 |
#ifdef NARRAY_BIGMEM
|
|
2130 |
rb_define_const(cNetCDF, "SUPPORT_BIGMEM", Qtrue);
|
|
2131 |
#else
|
|
2132 |
@@ -4658,7 +4624,7 @@ Init_netcdfraw(void)
|
|
2133 |
rb_define_private_method(cNetCDF,"id2var",NetCDF_id2var,1);
|
|
2134 |
rb_define_private_method(cNetCDF,"id2dim",NetCDF_id2dim,1);
|
|
2135 |
rb_define_private_method(cNetCDF,"id2att",NetCDF_id2att,1);
|
|
2136 |
- rb_define_method(cNetCDF,"==",NetCDF_eql,1);
|
|
2137 |
+ rb_define_method(cNetCDF,"==",NetCDF_eql,1);
|
|
2138 |
/* rb_define_method(cNetCDF,"eql?",NetCDF_eql,1); */
|
|
2139 |
|
|
2140 |
/* The methods of the NetCDFDim class */
|
|
2141 |
@@ -4736,7 +4702,7 @@ Init_netcdfraw(void)
|
|
2142 |
rb_define_method(cNetCDFVar,"get_var_int",NetCDF_get_var_int,0);
|
|
2143 |
rb_define_method(cNetCDFVar,"get_var_sfloat",NetCDF_get_var_float,0);
|
|
2144 |
rb_define_method(cNetCDFVar,"get_var_float",NetCDF_get_var_double,0);
|
|
2145 |
-
|
|
2146 |
+
|
|
2147 |
rb_define_method(cNetCDFVar,"get_vars_char",NetCDF_get_vars_char,3);
|
|
2148 |
rb_define_method(cNetCDFVar,"get_vars_byte",NetCDF_get_vars_byte,3);
|
|
2149 |
rb_define_method(cNetCDFVar,"get_vars_sint",NetCDF_get_vars_sint,3);
|
|
2150 |
diff --git a/lib/numru/netcdf.rb b/lib/numru/netcdf.rb
|
|
2151 |
index 4e68f01..45722f5 100644
|
|
2152 |
--- a/lib/numru/netcdf.rb
|
|
2153 |
+++ b/lib/numru/netcdf.rb
|
|
2154 |
@@ -36,7 +36,7 @@ module NumRu
|
|
2155 |
raise("This method is available only for NetCDF >= 4") unless @@nc4
|
|
2156 |
case cmode
|
|
2157 |
when 0, nil, NC_CLASSIC_MODEL, /^CLASSIC$/i, NC_FORMAT_CLASSIC
|
|
2158 |
- # classic netcdf ver 3 fmt
|
|
2159 |
+ # classic netcdf ver 3 fmt
|
|
2160 |
@@cr_format = 0
|
|
2161 |
when NC_64BIT_OFFSET, /^64BIT_OFFSET$/i, NC_FORMAT_64BIT
|
|
2162 |
@@cr_format = NC_64BIT_OFFSET
|
|
2163 |
@@ -65,229 +65,225 @@ module NumRu
|
|
2164 |
end
|
|
2165 |
|
|
2166 |
def NetCDF.open(filename,mode="r",share=false)
|
|
2167 |
- call_create=false # false-> nc_open; true->nc_create
|
|
2168 |
- case(mode)
|
|
2169 |
- when "r","rb" # read only
|
|
2170 |
- mode=NC_NOWRITE
|
|
2171 |
- when "w","w+","wb","w+b" # overwrite if exits
|
|
2172 |
- call_create=true
|
|
2173 |
- mode=NC_CLOBBER
|
|
2174 |
- when "a","a+","r+","ab","a+b","r+b" # append if exits
|
|
2175 |
- if( File.exists?(filename) )
|
|
2176 |
- mode=NC_WRITE
|
|
2177 |
- else
|
|
2178 |
- call_create=true #(nonexsitent --> create)
|
|
2179 |
- mode=NC_CLOBBER
|
|
2180 |
- end
|
|
2181 |
- else
|
|
2182 |
- raise NetcdfError, "Mode #{mode} is not supported"
|
|
2183 |
- end
|
|
2184 |
- case(share)
|
|
2185 |
- when false
|
|
2186 |
- share=0
|
|
2187 |
- when true
|
|
2188 |
- share=NC_SHARE
|
|
2189 |
- else
|
|
2190 |
- raise NetcdfError, "We can't use the sharing mode you typed"
|
|
2191 |
- end
|
|
2192 |
- omode = mode | share
|
|
2193 |
- if(!call_create)
|
|
2194 |
- nc_open(filename,omode)
|
|
2195 |
- else
|
|
2196 |
- nc_create(filename,omode)
|
|
2197 |
- end
|
|
2198 |
- end
|
|
2199 |
-
|
|
2200 |
+ call_create=false # false-> nc_open; true->nc_create
|
|
2201 |
+ case(mode)
|
|
2202 |
+ when "r","rb" # read only
|
|
2203 |
+ mode=NC_NOWRITE
|
|
2204 |
+ when "w","w+","wb","w+b" # overwrite if exits
|
|
2205 |
+ call_create=true
|
|
2206 |
+ mode=NC_CLOBBER
|
|
2207 |
+ when "a","a+","r+","ab","a+b","r+b" # append if exits
|
|
2208 |
+ if( File.exists?(filename) )
|
|
2209 |
+ mode=NC_WRITE
|
|
2210 |
+ else
|
|
2211 |
+ call_create=true #(nonexsitent --> create)
|
|
2212 |
+ mode=NC_CLOBBER
|
|
2213 |
+ end
|
|
2214 |
+ else
|
|
2215 |
+ raise NetcdfError, "Mode #{mode} is not supported"
|
|
2216 |
+ end
|
|
2217 |
+ case(share)
|
|
2218 |
+ when false
|
|
2219 |
+ share=0
|
|
2220 |
+ when true
|
|
2221 |
+ share=NC_SHARE
|
|
2222 |
+ else
|
|
2223 |
+ raise NetcdfError, "We can't use the sharing mode you typed"
|
|
2224 |
+ end
|
|
2225 |
+ omode = mode | share
|
|
2226 |
+ if(!call_create)
|
|
2227 |
+ nc_open(filename,omode)
|
|
2228 |
+ else
|
|
2229 |
+ nc_create(filename,omode)
|
|
2230 |
+ end
|
|
2231 |
+ end
|
|
2232 |
+
|
|
2233 |
class << NetCDF
|
|
2234 |
alias new open
|
|
2235 |
end
|
|
2236 |
-
|
|
2237 |
-
|
|
2238 |
+
|
|
2239 |
+
|
|
2240 |
def NetCDF.create(filename,noclobber=false,share=false)
|
|
2241 |
case(noclobber)
|
|
2242 |
when false
|
|
2243 |
- noclobber=NC_CLOBBER
|
|
2244 |
+ noclobber=NC_CLOBBER
|
|
2245 |
when true
|
|
2246 |
- noclobber=NC_NOCLOBBER
|
|
2247 |
+ noclobber=NC_NOCLOBBER
|
|
2248 |
else
|
|
2249 |
- raise NetcdfError,"noclobber (2nd argument) must be true or false"
|
|
2250 |
+ raise NetcdfError,"noclobber (2nd argument) must be true or false"
|
|
2251 |
end
|
|
2252 |
case(share)
|
|
2253 |
when false
|
|
2254 |
- share=0
|
|
2255 |
+ share=0
|
|
2256 |
when true
|
|
2257 |
- share=NC_SHARE
|
|
2258 |
+ share=NC_SHARE
|
|
2259 |
else
|
|
2260 |
- raise NetcdfError,"share (3rd argument) must be true or false"
|
|
2261 |
+ raise NetcdfError,"share (3rd argument) must be true or false"
|
|
2262 |
end
|
|
2263 |
-
|
|
2264 |
+
|
|
2265 |
cmode=noclobber | share | @@cr_format
|
|
2266 |
nc_create(filename,cmode)
|
|
2267 |
end
|
|
2268 |
-
|
|
2269 |
+
|
|
2270 |
class << NetCDF
|
|
2271 |
- def clean_tmpfile(path)
|
|
2272 |
- proc {
|
|
2273 |
- print "removing ", path, "..." if $DEBUG
|
|
2274 |
- if File.exist?(path)
|
|
2275 |
- File.unlink(path)
|
|
2276 |
- end
|
|
2277 |
- print "done\n" if $DEBUG
|
|
2278 |
- }
|
|
2279 |
- end
|
|
2280 |
- protected :clean_tmpfile
|
|
2281 |
- end
|
|
2282 |
-
|
|
2283 |
- def NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.',
|
|
2284 |
- share=false)
|
|
2285 |
- basename = 'temp'
|
|
2286 |
- if $SAFE > 0 and tmpdir.tainted?
|
|
2287 |
- tmpdir = '.'
|
|
2288 |
- end
|
|
2289 |
-
|
|
2290 |
- n = 0
|
|
2291 |
- while true
|
|
2292 |
- begin
|
|
2293 |
- tmpname = sprintf('%s/%s%d_%d.nc', tmpdir, basename, $$, n)
|
|
2294 |
- unless File.exist?(tmpname)
|
|
2295 |
- netcdf = NetCDF.create(tmpname, true, share)
|
|
2296 |
- ObjectSpace.define_finalizer(netcdf,
|
|
2297 |
- NetCDF.clean_tmpfile(tmpname))
|
|
2298 |
- break
|
|
2299 |
- end
|
|
2300 |
- rescue
|
|
2301 |
- raise NetcdfError, "cannot generate tempfile `%s'" % tmpname if n >= Max_Try
|
|
2302 |
- end
|
|
2303 |
- n += 1
|
|
2304 |
- end
|
|
2305 |
- netcdf
|
|
2306 |
+ def clean_tmpfile(path)
|
|
2307 |
+ proc {
|
|
2308 |
+ print "removing ", path, "..." if $DEBUG
|
|
2309 |
+ if File.exist?(path)
|
|
2310 |
+ File.unlink(path)
|
|
2311 |
+ end
|
|
2312 |
+ print "done\n" if $DEBUG
|
|
2313 |
+ }
|
|
2314 |
+ end
|
|
2315 |
+ protected :clean_tmpfile
|
|
2316 |
+ end
|
|
2317 |
+
|
|
2318 |
+ def NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.',
|
|
2319 |
+ share=false)
|
|
2320 |
+ basename = 'temp'
|
|
2321 |
+ n = 0
|
|
2322 |
+ while true
|
|
2323 |
+ begin
|
|
2324 |
+ tmpname = sprintf('%s/%s%d_%d.nc', tmpdir, basename, $$, n)
|
|
2325 |
+ unless File.exist?(tmpname)
|
|
2326 |
+ netcdf = NetCDF.create(tmpname, true, share)
|
|
2327 |
+ ObjectSpace.define_finalizer(netcdf,
|
|
2328 |
+ NetCDF.clean_tmpfile(tmpname))
|
|
2329 |
+ break
|
|
2330 |
+ end
|
|
2331 |
+ rescue
|
|
2332 |
+ raise NetcdfError, "cannot generate tempfile `%s'" % tmpname if n >= Max_Try
|
|
2333 |
+ end
|
|
2334 |
+ n += 1
|
|
2335 |
+ end
|
|
2336 |
+ netcdf
|
|
2337 |
end
|
|
2338 |
|
|
2339 |
|
|
2340 |
def put_att(attname,val,atttype=nil)
|
|
2341 |
- put_attraw(attname,val,atttype)
|
|
2342 |
+ put_attraw(attname,val,atttype)
|
|
2343 |
end
|
|
2344 |
-
|
|
2345 |
+
|
|
2346 |
def def_var_with_dim(name, vartype, shape_ul0, dimnames)
|
|
2347 |
- # Same as def_var but defines dimensions first if needed.
|
|
2348 |
- # Use zero in shape to define an unlimited dimension.
|
|
2349 |
- if (shape_ul0.length != dimnames.length ) then
|
|
2350 |
- raise ArgumentError, 'lengths of shape and dimnames do not agree'
|
|
2351 |
- end
|
|
2352 |
- dims = []
|
|
2353 |
- dimnames.each_index{ |i|
|
|
2354 |
- dim = self.dim( dimnames[i] )
|
|
2355 |
- if ( dim != nil ) then
|
|
2356 |
- # dim exists --> check the length
|
|
2357 |
- if (shape_ul0[i] != dim.length_ul0 ) then
|
|
2358 |
- raise ArgumentError, "dimension length do not agree: #{i}th dim: "+\
|
|
2359 |
- "#{shape_ul0[i]} and #{dim.length_ul0}"
|
|
2360 |
- end
|
|
2361 |
- dims.push(dim)
|
|
2362 |
- else
|
|
2363 |
- # dim does not exist --> define it
|
|
2364 |
- dims.push( def_dim( dimnames[i], shape_ul0[i] ) )
|
|
2365 |
- end
|
|
2366 |
- }
|
|
2367 |
- def_var(name, vartype, dims)
|
|
2368 |
+ # Same as def_var but defines dimensions first if needed.
|
|
2369 |
+ # Use zero in shape to define an unlimited dimension.
|
|
2370 |
+ if (shape_ul0.length != dimnames.length ) then
|
|
2371 |
+ raise ArgumentError, 'lengths of shape and dimnames do not agree'
|
|
2372 |
+ end
|
|
2373 |
+ dims = []
|
|
2374 |
+ dimnames.each_index{ |i|
|
|
2375 |
+ dim = self.dim( dimnames[i] )
|
|
2376 |
+ if ( dim != nil ) then
|
|
2377 |
+ # dim exists --> check the length
|
|
2378 |
+ if (shape_ul0[i] != dim.length_ul0 ) then
|
|
2379 |
+ raise ArgumentError, "dimension length do not agree: #{i}th dim: "+\
|
|
2380 |
+ "#{shape_ul0[i]} and #{dim.length_ul0}"
|
|
2381 |
+ end
|
|
2382 |
+ dims.push(dim)
|
|
2383 |
+ else
|
|
2384 |
+ # dim does not exist --> define it
|
|
2385 |
+ dims.push( def_dim( dimnames[i], shape_ul0[i] ) )
|
|
2386 |
+ end
|
|
2387 |
+ }
|
|
2388 |
+ def_var(name, vartype, dims)
|
|
2389 |
end
|
|
2390 |
|
|
2391 |
# Iterators:
|
|
2392 |
def each_dim
|
|
2393 |
- num_dim=ndims()
|
|
2394 |
+ num_dim=ndims()
|
|
2395 |
for dimid in 0..num_dim-1
|
|
2396 |
- obj_Dim=id2dim(dimid)
|
|
2397 |
- yield(obj_Dim)
|
|
2398 |
+ obj_Dim=id2dim(dimid)
|
|
2399 |
+ yield(obj_Dim)
|
|
2400 |
end
|
|
2401 |
end
|
|
2402 |
-
|
|
2403 |
+
|
|
2404 |
def each_var
|
|
2405 |
num_var=nvars()
|
|
2406 |
for varid in 0..num_var-1
|
|
2407 |
- obj_Var=id2var(varid)
|
|
2408 |
- yield(obj_Var)
|
|
2409 |
+ obj_Var=id2var(varid)
|
|
2410 |
+ yield(obj_Var)
|
|
2411 |
end
|
|
2412 |
end
|
|
2413 |
-
|
|
2414 |
+
|
|
2415 |
def each_att
|
|
2416 |
num_att=natts()
|
|
2417 |
for attnum in 0..num_att-1
|
|
2418 |
- obj_Att=id2att(attnum)
|
|
2419 |
- yield(obj_Att)
|
|
2420 |
+ obj_Att=id2att(attnum)
|
|
2421 |
+ yield(obj_Att)
|
|
2422 |
end
|
|
2423 |
end
|
|
2424 |
-
|
|
2425 |
+
|
|
2426 |
def dims( names=nil ) # return all if names==nil
|
|
2427 |
- if names == nil
|
|
2428 |
- dims = (0..ndims()-1).collect{|dimid| id2dim(dimid)}
|
|
2429 |
- else
|
|
2430 |
- raise TypeError, "names is not an array" if ! names.is_a?(Array)
|
|
2431 |
- dims = names.collect{|name| dim(name)}
|
|
2432 |
- raise ArgumentError, "One or more dimensions do not exist" if dims.include?(nil)
|
|
2433 |
- end
|
|
2434 |
- dims
|
|
2435 |
+ if names == nil
|
|
2436 |
+ dims = (0..ndims()-1).collect{|dimid| id2dim(dimid)}
|
|
2437 |
+ else
|
|
2438 |
+ raise TypeError, "names is not an array" if ! names.is_a?(Array)
|
|
2439 |
+ dims = names.collect{|name| dim(name)}
|
|
2440 |
+ raise ArgumentError, "One or more dimensions do not exist" if dims.include?(nil)
|
|
2441 |
+ end
|
|
2442 |
+ dims
|
|
2443 |
end
|
|
2444 |
|
|
2445 |
def vars( names=nil ) # return all if names==nil
|
|
2446 |
- if names == nil
|
|
2447 |
- vars = (0..nvars()-1).collect{ |varid| id2var(varid) }
|
|
2448 |
- else
|
|
2449 |
- raise TypeError, "names is not an array" if ! names.is_a?(Array)
|
|
2450 |
- vars = names.collect{|name| var(name)}
|
|
2451 |
- raise ArgumentError, "One or more variables do not exist" if vars.include?(nil)
|
|
2452 |
- end
|
|
2453 |
- vars
|
|
2454 |
+ if names == nil
|
|
2455 |
+ vars = (0..nvars()-1).collect{ |varid| id2var(varid) }
|
|
2456 |
+ else
|
|
2457 |
+ raise TypeError, "names is not an array" if ! names.is_a?(Array)
|
|
2458 |
+ vars = names.collect{|name| var(name)}
|
|
2459 |
+ raise ArgumentError, "One or more variables do not exist" if vars.include?(nil)
|
|
2460 |
+ end
|
|
2461 |
+ vars
|
|
2462 |
end
|
|
2463 |
|
|
2464 |
def dim_names
|
|
2465 |
num_dim=ndims()
|
|
2466 |
names=[]
|
|
2467 |
for dimid in 0..num_dim-1
|
|
2468 |
- obj_Dim=id2dim(dimid)
|
|
2469 |
- names=names+[obj_Dim.name]
|
|
2470 |
+ obj_Dim=id2dim(dimid)
|
|
2471 |
+ names=names+[obj_Dim.name]
|
|
2472 |
end
|
|
2473 |
return names
|
|
2474 |
- end
|
|
2475 |
-
|
|
2476 |
+ end
|
|
2477 |
+
|
|
2478 |
def var_names
|
|
2479 |
num_var=nvars()
|
|
2480 |
names=[]
|
|
2481 |
for varid in 0..num_var-1
|
|
2482 |
- obj_Var=id2var(varid)
|
|
2483 |
- names=names+[obj_Var.name]
|
|
2484 |
+ obj_Var=id2var(varid)
|
|
2485 |
+ names=names+[obj_Var.name]
|
|
2486 |
end
|
|
2487 |
return names
|
|
2488 |
end
|
|
2489 |
-
|
|
2490 |
+
|
|
2491 |
def att_names
|
|
2492 |
num_att=natts()
|
|
2493 |
names=[]
|
|
2494 |
for attnum in 0..num_att-1
|
|
2495 |
- obj_Att=id2att(attnum)
|
|
2496 |
- names=names+[obj_Att.name]
|
|
2497 |
+ obj_Att=id2att(attnum)
|
|
2498 |
+ names=names+[obj_Att.name]
|
|
2499 |
end
|
|
2500 |
return names
|
|
2501 |
end
|
|
2502 |
-
|
|
2503 |
+
|
|
2504 |
def inspect
|
|
2505 |
"NetCDF:"+path
|
|
2506 |
end
|
|
2507 |
-
|
|
2508 |
+
|
|
2509 |
end
|
|
2510 |
-
|
|
2511 |
+
|
|
2512 |
class NetCDFVar
|
|
2513 |
-
|
|
2514 |
+
|
|
2515 |
class << NetCDFVar
|
|
2516 |
- def new(file,varname,mode="r",share=false)
|
|
2517 |
- if(file.is_a?(String))
|
|
2518 |
- file = NetCDF.open(file,mode,share)
|
|
2519 |
- elsif(!file.is_a?(NetCDF))
|
|
2520 |
- raise TypeError, "1st arg must be a NetCDF (file object) or a String (path)"
|
|
2521 |
- end
|
|
2522 |
- file.var(varname)
|
|
2523 |
- end
|
|
2524 |
+ def new(file,varname,mode="r",share=false)
|
|
2525 |
+ if(file.is_a?(String))
|
|
2526 |
+ file = NetCDF.open(file,mode,share)
|
|
2527 |
+ elsif(!file.is_a?(NetCDF))
|
|
2528 |
+ raise TypeError, "1st arg must be a NetCDF (file object) or a String (path)"
|
|
2529 |
+ end
|
|
2530 |
+ file.var(varname)
|
|
2531 |
+ end
|
|
2532 |
|
|
2533 |
- alias open new
|
|
2534 |
+ alias open new
|
|
2535 |
end
|
|
2536 |
|
|
2537 |
alias :rank :ndims
|
|
2538 |
@@ -295,516 +291,516 @@ module NumRu
|
|
2539 |
def each_att
|
|
2540 |
num_att=natts()
|
|
2541 |
for attnum in 0..num_att-1
|
|
2542 |
- obj_Att=id2att(attnum)
|
|
2543 |
- yield(obj_Att)
|
|
2544 |
+ obj_Att=id2att(attnum)
|
|
2545 |
+ yield(obj_Att)
|
|
2546 |
end
|
|
2547 |
end
|
|
2548 |
-
|
|
2549 |
+
|
|
2550 |
def dim_names
|
|
2551 |
ary = Array.new()
|
|
2552 |
dims.each{|dim| ary.push(dim.name)}
|
|
2553 |
ary
|
|
2554 |
end
|
|
2555 |
-
|
|
2556 |
- def att_names
|
|
2557 |
- num_att=natts()
|
|
2558 |
- names=[]
|
|
2559 |
- for attnum in 0..num_att-1
|
|
2560 |
- obj_Att=id2att(attnum)
|
|
2561 |
- names=names+[obj_Att.name]
|
|
2562 |
- end
|
|
2563 |
- return names
|
|
2564 |
- end
|
|
2565 |
-
|
|
2566 |
- def put_att(attname,val,atttype=nil)
|
|
2567 |
+
|
|
2568 |
+ def att_names
|
|
2569 |
+ num_att=natts()
|
|
2570 |
+ names=[]
|
|
2571 |
+ for attnum in 0..num_att-1
|
|
2572 |
+ obj_Att=id2att(attnum)
|
|
2573 |
+ names=names+[obj_Att.name]
|
|
2574 |
+ end
|
|
2575 |
+ return names
|
|
2576 |
+ end
|
|
2577 |
+
|
|
2578 |
+ def put_att(attname,val,atttype=nil)
|
|
2579 |
put_attraw(attname,val,atttype)
|
|
2580 |
- end
|
|
2581 |
+ end
|
|
2582 |
|
|
2583 |
- def shape_ul0
|
|
2584 |
+ def shape_ul0
|
|
2585 |
sh = []
|
|
2586 |
dims.each{|d|
|
|
2587 |
- if d.unlimited? then
|
|
2588 |
- sh.push(0)
|
|
2589 |
- else
|
|
2590 |
- sh.push(d.length)
|
|
2591 |
- end
|
|
2592 |
+ if d.unlimited? then
|
|
2593 |
+ sh.push(0)
|
|
2594 |
+ else
|
|
2595 |
+ sh.push(d.length)
|
|
2596 |
+ end
|
|
2597 |
}
|
|
2598 |
sh
|
|
2599 |
- end
|
|
2600 |
-
|
|
2601 |
- def shape_current
|
|
2602 |
+ end
|
|
2603 |
+
|
|
2604 |
+ def shape_current
|
|
2605 |
sh = []
|
|
2606 |
dims.each{|d|
|
|
2607 |
- sh.push(d.length)
|
|
2608 |
+ sh.push(d.length)
|
|
2609 |
}
|
|
2610 |
sh
|
|
2611 |
- end
|
|
2612 |
-
|
|
2613 |
- # The put and get methods in the NetCDFVar class
|
|
2614 |
-
|
|
2615 |
- def pack(na)
|
|
2616 |
- sf = att('scale_factor')
|
|
2617 |
- ao = att('add_offset')
|
|
2618 |
- if ( sf == nil && ao == nil ) then
|
|
2619 |
- na
|
|
2620 |
- else
|
|
2621 |
- na = NArray.to_na(na) if na.is_a?(Array)
|
|
2622 |
- if sf
|
|
2623 |
- csf = sf.get
|
|
2624 |
- raise NetcdfError,"scale_factor is not a numeric" if csf.is_a?(String)
|
|
2625 |
- raise NetcdfError, "scale_factor is not unique" if csf.length != 1
|
|
2626 |
- raise NetcdfError, "zero scale_factor" if csf[0] == 0
|
|
2627 |
- else
|
|
2628 |
- csf = nil
|
|
2629 |
- end
|
|
2630 |
- if ao
|
|
2631 |
- cao = ao.get
|
|
2632 |
- raise NetcdfError, "add_offset is not a numeric" if cao.is_a?(String)
|
|
2633 |
- raise NetcdfError, "add_offset is not unique" if cao.length != 1
|
|
2634 |
- else
|
|
2635 |
- cao = nil
|
|
2636 |
- end
|
|
2637 |
- if csf and cao
|
|
2638 |
- packed = (na - cao) / csf
|
|
2639 |
- elsif csf
|
|
2640 |
- packed = na / csf
|
|
2641 |
- elsif cao
|
|
2642 |
- packed = na - cao
|
|
2643 |
- end
|
|
2644 |
- if self.typecode <= NArray::LINT
|
|
2645 |
- packed = packed.round
|
|
2646 |
- end
|
|
2647 |
- packed
|
|
2648 |
- end
|
|
2649 |
- end
|
|
2650 |
-
|
|
2651 |
- def scaled_put(var,hash=nil)
|
|
2652 |
- simple_put( pack(var), hash)
|
|
2653 |
- end
|
|
2654 |
-
|
|
2655 |
- @@unpack_type = nil
|
|
2656 |
- class << NetCDFVar
|
|
2657 |
- def unpack_type
|
|
2658 |
- @@unpack_type
|
|
2659 |
- end
|
|
2660 |
- def unpack_type=(na_type)
|
|
2661 |
- if [NArray::BYTE, NArray::SINT, NArray::INT,
|
|
2662 |
- NArray::SFLOAT, NArray::FLOAT, nil].include?(na_type)
|
|
2663 |
- @@unpack_type = na_type
|
|
2664 |
- else
|
|
2665 |
- raise ArgumentError, "Arg must be one of NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, NArray::FLOAT"
|
|
2666 |
- end
|
|
2667 |
- end
|
|
2668 |
-
|
|
2669 |
- end
|
|
2670 |
-
|
|
2671 |
- def unpack(na)
|
|
2672 |
- sf = att('scale_factor')
|
|
2673 |
- ao = att('add_offset')
|
|
2674 |
- if ( sf == nil && ao == nil ) then
|
|
2675 |
- na
|
|
2676 |
- else
|
|
2677 |
- if sf
|
|
2678 |
- csf = sf.get
|
|
2679 |
- raise NetcdfError,"scale_factor is not a numeric" if csf.is_a?(String)
|
|
2680 |
- raise NetcdfError, "scale_factor is not unique" if csf.length != 1
|
|
2681 |
- raise NetcdfError, "zero scale_factor" if csf[0] == 0
|
|
2682 |
- else
|
|
2683 |
- csf =nil
|
|
2684 |
- end
|
|
2685 |
- if ao
|
|
2686 |
- cao = ao.get
|
|
2687 |
- raise NetcdfError, "add_offset is not a numeric" if cao.is_a?(String)
|
|
2688 |
- raise NetcdfError, "add_offset is not unique" if cao.length != 1
|
|
2689 |
- else
|
|
2690 |
- cao = nil
|
|
2691 |
- end
|
|
2692 |
- if csf and cao
|
|
2693 |
- una = na * csf + cao # csf & cao are NArray -> coerced to their types
|
|
2694 |
- elsif csf
|
|
2695 |
- una = na * csf
|
|
2696 |
- elsif cao
|
|
2697 |
- una = na + cao
|
|
2698 |
- end
|
|
2699 |
- una = una.to_type(@@unpack_type) if @@unpack_type
|
|
2700 |
- una
|
|
2701 |
- end
|
|
2702 |
- end
|
|
2703 |
-
|
|
2704 |
- def scaled_get(hash=nil)
|
|
2705 |
- unpack( simple_get(hash) )
|
|
2706 |
- end
|
|
2707 |
-
|
|
2708 |
- def simple_put(var,hash=nil)
|
|
2709 |
- if hash==nil
|
|
2710 |
- if self.vartype == "char"
|
|
2711 |
- put_var_char(var)
|
|
2712 |
- elsif self.vartype == "byte"
|
|
2713 |
- put_var_byte(var)
|
|
2714 |
- elsif self.vartype == "sint"
|
|
2715 |
- put_var_sint(var)
|
|
2716 |
- elsif self.vartype == "int"
|
|
2717 |
- put_var_int(var)
|
|
2718 |
- elsif self.vartype == "sfloat"
|
|
2719 |
- put_var_sfloat(var)
|
|
2720 |
- elsif self.vartype == "float"
|
|
2721 |
- put_var_float(var)
|
|
2722 |
- else
|
|
2723 |
- raise NetcdfError,"variable type isn't supported in netCDF"
|
|
2724 |
- end
|
|
2725 |
- elsif hash.key?("index")==true
|
|
2726 |
- if self.vartype == "char"
|
|
2727 |
- put_var1_char(var,hash["index"])
|
|
2728 |
- elsif self.vartype=="byte"
|
|
2729 |
- put_var1_byte(var,hash["index"])
|
|
2730 |
- elsif self.vartype=="sint"
|
|
2731 |
- put_var1_sint(var,hash["index"])
|
|
2732 |
- elsif self.vartype == "int"
|
|
2733 |
- put_var1_int(var,hash["index"])
|
|
2734 |
- elsif self.vartype == "sfloat"
|
|
2735 |
- put_var1_sfloat(var,hash["index"])
|
|
2736 |
- elsif self.vartype == "float"
|
|
2737 |
- put_var1_float(var,hash["index"])
|
|
2738 |
- else
|
|
2739 |
- raise NetcdfError,"variable type isn't supported in netCDF"
|
|
2740 |
- end
|
|
2741 |
- elsif hash.key?("start")==true
|
|
2742 |
- if hash.key?("end")==false && hash.key?("stride")==false
|
|
2743 |
- if self.vartype == "char"
|
|
2744 |
- put_vars_char(var,hash["start"],nil,nil)
|
|
2745 |
- elsif self.vartype=="byte"
|
|
2746 |
- put_vars_byte(var,hash["start"],nil,nil)
|
|
2747 |
- elsif self.vartype=="sint"
|
|
2748 |
- put_vars_sint(var,hash["start"],nil,nil)
|
|
2749 |
- elsif self.vartype=="int"
|
|
2750 |
- put_vars_int(var,hash["start"],nil,nil)
|
|
2751 |
- elsif self.vartype=="sfloat"
|
|
2752 |
- put_vars_sfloat(var,hash["start"],nil,nil)
|
|
2753 |
- elsif self.vartype=="float"
|
|
2754 |
- put_vars_float(var,hash["start"],nil,nil)
|
|
2755 |
- else
|
|
2756 |
- raise NetcdfError, "variable type isn't supported in netCDF"
|
|
2757 |
- end
|
|
2758 |
- elsif hash.key?("end")==true && hash.key?("stride") == false
|
|
2759 |
- if self.vartype == "char"
|
|
2760 |
- put_vars_char(var,hash["start"],hash["end"],nil)
|
|
2761 |
- elsif self.vartype=="byte"
|
|
2762 |
- put_vars_byte(var,hash["start"],hash["end"],nil)
|
|
2763 |
- elsif self.vartype=="sint"
|
|
2764 |
- put_vars_sint(var,hash["start"],hash["end"],nil)
|
|
2765 |
- elsif self.vartype=="int"
|
|
2766 |
- put_vars_int(var,hash["start"],hash["end"],nil)
|
|
2767 |
- elsif self.vartype == "sfloat"
|
|
2768 |
- put_vars_sfloat(var,hash["start"],hash["end"],nil)
|
|
2769 |
- elsif self.vartype =="float"
|
|
2770 |
- put_vars_float(var,hash["start"],hash["end"],nil)
|
|
2771 |
- else
|
|
2772 |
- raise NetcdfError, "variable type isn't supported in netCDF"
|
|
2773 |
- end
|
|
2774 |
- elsif hash.key?("end")==false && hash.key?("stride")==true
|
|
2775 |
- if self.vartype == "char"
|
|
2776 |
- put_vars_char(var,hash["start"],nil,hash["stride"])
|
|
2777 |
- elsif self.vartype=="byte"
|
|
2778 |
- put_vars_byte(var,hash["start"],nil,hash["stride"])
|
|
2779 |
- elsif self.vartype=="sint"
|
|
2780 |
- put_vars_sint(var,hash["start"],nil,hash["stride"])
|
|
2781 |
- elsif self.vartype=="int"
|
|
2782 |
- put_vars_int(var,hash["start"],nil,hash["stride"])
|
|
2783 |
- elsif self.vartype=="sfloat"
|
|
2784 |
- put_vars_sfloat(var,hash["start"],nil,hash["stride"])
|
|
2785 |
- elsif self.vartype=="float"
|
|
2786 |
- put_vars_float(var,hash["start"],nil,hash["stride"])
|
|
2787 |
- else
|
|
2788 |
- raise NetcdfError, "variable type isn't supported in netCDF"
|
|
2789 |
- end
|
|
2790 |
- else hash.key?("end")==true && hash.key?("stride")==true
|
|
2791 |
- if self.vartype == "char"
|
|
2792 |
- put_vars_char(var,hash["start"],hash["end"],hash["stride"])
|
|
2793 |
- elsif self.vartype=="byte"
|
|
2794 |
- put_vars_byte(var,hash["start"],hash["end"],hash["stride"])
|
|
2795 |
- elsif self.vartype=="sint"
|
|
2796 |
- put_vars_sint(var,hash["start"],hash["end"],hash["stride"])
|
|
2797 |
- elsif self.vartype=="int"
|
|
2798 |
- put_vars_int(var,hash["start"],hash["end"],hash["stride"])
|
|
2799 |
- elsif self.vartype=="sfloat"
|
|
2800 |
- put_vars_sfloat(var,hash["start"],hash["end"],hash["stride"])
|
|
2801 |
- elsif self.vartype=="float"
|
|
2802 |
- put_vars_float(var,hash["start"],hash["end"],hash["stride"])
|
|
2803 |
- else
|
|
2804 |
- raise NetcdfError, "variable type isn't supported in netCDF"
|
|
2805 |
- end
|
|
2806 |
- end
|
|
2807 |
- else
|
|
2808 |
- raise ArgumentError,"{'start'}=>[ARRAY] or {'index'}=>[ARRAY] is needed"
|
|
2809 |
- end
|
|
2810 |
- end
|
|
2811 |
-
|
|
2812 |
- alias put simple_put
|
|
2813 |
-
|
|
2814 |
- def simple_get(hash=nil)
|
|
2815 |
- t_var = self.vartype
|
|
2816 |
- if hash == nil
|
|
2817 |
- if t_var == "char"
|
|
2818 |
- get_var_char
|
|
2819 |
- elsif t_var == "byte"
|
|
2820 |
- get_var_byte
|
|
2821 |
- elsif t_var == "sint"
|
|
2822 |
- get_var_sint
|
|
2823 |
- elsif t_var == "int"
|
|
2824 |
- get_var_int
|
|
2825 |
- elsif t_var == "sfloat"
|
|
2826 |
- get_var_sfloat
|
|
2827 |
- elsif t_var == "float"
|
|
2828 |
- get_var_float
|
|
2829 |
- else
|
|
2830 |
- raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
|
2831 |
- end
|
|
2832 |
- elsif hash.key?("index")==true
|
|
2833 |
- ind = hash["index"]
|
|
2834 |
- if t_var == "char"
|
|
2835 |
- get_var1_char(ind)
|
|
2836 |
- elsif t_var == "byte"
|
|
2837 |
- get_var1_byte(ind)
|
|
2838 |
- elsif t_var == "sint"
|
|
2839 |
- get_var1_sint(ind)
|
|
2840 |
- elsif t_var == "int"
|
|
2841 |
- get_var1_int(ind)
|
|
2842 |
- elsif t_var == "sfloat"
|
|
2843 |
- get_var1_sfloat(ind)
|
|
2844 |
- elsif t_var == "float"
|
|
2845 |
- get_var1_float(ind)
|
|
2846 |
- else
|
|
2847 |
- raise NetcdfError,"variable type #{t_var} isn't supported in netCDF"
|
|
2848 |
- end
|
|
2849 |
- elsif hash.key?("start")==true
|
|
2850 |
- h_sta = hash["start"]
|
|
2851 |
- h_end = hash["end"] # can be nill
|
|
2852 |
- h_str = hash["stride"] # can be nill
|
|
2853 |
- if NetCDF.nc4? && h_str && ((xstr=h_str[0]) != 1)
|
|
2854 |
- # Tentative treatment for the very slow netcdf-4 reading with step.
|
|
2855 |
- # Reading with step is generally slow with NetCDF 4, but it is
|
|
2856 |
- # particularly so for the first dimension.
|
|
2857 |
- # Ref: http://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2013/msg00311.html
|
|
2858 |
- h_str[0] = 1
|
|
2859 |
- nc4remedy = true
|
|
2860 |
- else
|
|
2861 |
- nc4remedy = false
|
|
2862 |
- end
|
|
2863 |
- if t_var == "char"
|
|
2864 |
- v = get_vars_char(h_sta,h_end,h_str)
|
|
2865 |
- elsif t_var == "byte"
|
|
2866 |
- v = get_vars_byte(h_sta,h_end,h_str)
|
|
2867 |
- elsif t_var == "sint"
|
|
2868 |
- v = get_vars_sint(h_sta,h_end,h_str)
|
|
2869 |
- elsif t_var == "int"
|
|
2870 |
- v = get_vars_int(h_sta,h_end,h_str)
|
|
2871 |
- elsif t_var == "sfloat"
|
|
2872 |
- v = get_vars_sfloat(h_sta,h_end,h_str)
|
|
2873 |
- elsif t_var == "float"
|
|
2874 |
- v = get_vars_float(h_sta,h_end,h_str)
|
|
2875 |
- else
|
|
2876 |
- raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
|
2877 |
- end
|
|
2878 |
- if nc4remedy
|
|
2879 |
- idx = []
|
|
2880 |
- (0...v.shape[0]).step(xstr){|k| idx.push(k)}
|
|
2881 |
- v = v[idx,false]
|
|
2882 |
- end
|
|
2883 |
- v
|
|
2884 |
- else
|
|
2885 |
- raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
|
|
2886 |
- end
|
|
2887 |
- end
|
|
2888 |
-
|
|
2889 |
- alias get simple_get
|
|
2890 |
-
|
|
2891 |
- def __rubber_expansion( args )
|
|
2892 |
- if (id = args.index(false)) # substitution into id
|
|
2893 |
- # false is incuded
|
|
2894 |
- alen = args.length
|
|
2895 |
- if args.rindex(false) != id
|
|
2896 |
- raise ArguemntError,"only one rubber dimension is permitted"
|
|
2897 |
- elsif alen > rank+1
|
|
2898 |
- raise ArgumentError, "too many args"
|
|
2899 |
- end
|
|
2900 |
- ar = ( id!=0 ? args[0..id-1] : [] )
|
|
2901 |
- args = ar + [true]*(rank-alen+1) + args[id+1..-1]
|
|
2902 |
- elsif args.length == 0 # to support empty [], []=
|
|
2903 |
- args = [true]*rank
|
|
2904 |
- end
|
|
2905 |
- args
|
|
2906 |
- end
|
|
2907 |
- private :__rubber_expansion
|
|
2908 |
-
|
|
2909 |
- def [](*a)
|
|
2910 |
- if a.length == 0
|
|
2911 |
- return self.get
|
|
2912 |
- end
|
|
2913 |
- a = __rubber_expansion(a)
|
|
2914 |
- first = Array.new
|
|
2915 |
- last = Array.new
|
|
2916 |
- stride = Array.new
|
|
2917 |
- set_stride = false
|
|
2918 |
- a.each{|i|
|
|
2919 |
- if(i.is_a?(Fixnum))
|
|
2920 |
- first.push(i)
|
|
2921 |
- last.push(i)
|
|
2922 |
- stride.push(1)
|
|
2923 |
- elsif(i.is_a?(Range))
|
|
2924 |
- first.push(i.first)
|
|
2925 |
- last.push(i.exclude_end? ? i.last-1 : i.last)
|
|
2926 |
- stride.push(1)
|
|
2927 |
- elsif(i.is_a?(Hash))
|
|
2928 |
- r = (i.to_a[0])[0]
|
|
2929 |
- s = (i.to_a[0])[1]
|
|
2930 |
- if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
|
|
2931 |
- raise TypeError, "Hash argument must be {a_Range, step}"
|
|
2932 |
- end
|
|
2933 |
- first.push(r.first)
|
|
2934 |
- last.push(r.exclude_end? ? r.last-1 : r.last)
|
|
2935 |
- stride.push(s)
|
|
2936 |
- set_stride = true
|
|
2937 |
- elsif(i.is_a?(TrueClass))
|
|
2938 |
- first.push(0)
|
|
2939 |
- last.push(-1)
|
|
2940 |
- stride.push(1)
|
|
2941 |
- elsif( i.is_a?(Array) || i.is_a?(NArray))
|
|
2942 |
- a_new = a.dup
|
|
2943 |
- at = a.index(i)
|
|
2944 |
- i = NArray.to_na(i) if i.is_a?(Array)
|
|
2945 |
- for n in 0..i.length-1
|
|
2946 |
- a_new[at] = i[n]..i[n]
|
|
2947 |
- na_tmp = self[*a_new]
|
|
2948 |
- if n==0 then
|
|
2949 |
- k = at
|
|
2950 |
- if at > 0
|
|
2951 |
- a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
|
|
2952 |
- end
|
|
2953 |
- shape_tmp = na_tmp.shape
|
|
2954 |
- shape_tmp[k] = i.length
|
|
2955 |
- na = na_tmp.class.new(na_tmp.typecode,*shape_tmp)
|
|
2956 |
- index_tmp = Array.new(shape_tmp.length,true)
|
|
2957 |
- end
|
|
2958 |
- index_tmp[k] = n..n
|
|
2959 |
- na[*index_tmp] = na_tmp
|
|
2960 |
- end
|
|
2961 |
- return na
|
|
2962 |
- else
|
|
2963 |
- raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
|
|
2964 |
- end
|
|
2965 |
- }
|
|
2966 |
-
|
|
2967 |
- if(set_stride)
|
|
2968 |
- na = self.get({"start"=>first, "end"=>last, "stride"=>stride})
|
|
2969 |
- else
|
|
2970 |
- na = self.get({"start"=>first, "end"=>last})
|
|
2971 |
- end
|
|
2972 |
- shape = na.shape
|
|
2973 |
- (a.length-1).downto(0){ |i|
|
|
2974 |
- shape.delete_at(i) if a[i].is_a?(Fixnum)
|
|
2975 |
+ end
|
|
2976 |
+
|
|
2977 |
+ # The put and get methods in the NetCDFVar class
|
|
2978 |
+
|
|
2979 |
+ def pack(na)
|
|
2980 |
+ sf = att('scale_factor')
|
|
2981 |
+ ao = att('add_offset')
|
|
2982 |
+ if ( sf == nil && ao == nil ) then
|
|
2983 |
+ na
|
|
2984 |
+ else
|
|
2985 |
+ na = NArray.to_na(na) if na.is_a?(Array)
|
|
2986 |
+ if sf
|
|
2987 |
+ csf = sf.get
|
|
2988 |
+ raise NetcdfError,"scale_factor is not a numeric" if csf.is_a?(String)
|
|
2989 |
+ raise NetcdfError, "scale_factor is not unique" if csf.length != 1
|
|
2990 |
+ raise NetcdfError, "zero scale_factor" if csf[0] == 0
|
|
2991 |
+ else
|
|
2992 |
+ csf = nil
|
|
2993 |
+ end
|
|
2994 |
+ if ao
|
|
2995 |
+ cao = ao.get
|
|
2996 |
+ raise NetcdfError, "add_offset is not a numeric" if cao.is_a?(String)
|
|
2997 |
+ raise NetcdfError, "add_offset is not unique" if cao.length != 1
|
|
2998 |
+ else
|
|
2999 |
+ cao = nil
|
|
3000 |
+ end
|
|
3001 |
+ if csf and cao
|
|
3002 |
+ packed = (na - cao) / csf
|
|
3003 |
+ elsif csf
|
|
3004 |
+ packed = na / csf
|
|
3005 |
+ elsif cao
|
|
3006 |
+ packed = na - cao
|
|
3007 |
+ end
|
|
3008 |
+ if self.typecode <= NArray::LINT
|
|
3009 |
+ packed = packed.round
|
|
3010 |
+ end
|
|
3011 |
+ packed
|
|
3012 |
+ end
|
|
3013 |
+ end
|
|
3014 |
+
|
|
3015 |
+ def scaled_put(var,hash=nil)
|
|
3016 |
+ simple_put( pack(var), hash)
|
|
3017 |
+ end
|
|
3018 |
+
|
|
3019 |
+ @@unpack_type = nil
|
|
3020 |
+ class << NetCDFVar
|
|
3021 |
+ def unpack_type
|
|
3022 |
+ @@unpack_type
|
|
3023 |
+ end
|
|
3024 |
+ def unpack_type=(na_type)
|
|
3025 |
+ if [NArray::BYTE, NArray::SINT, NArray::INT,
|
|
3026 |
+ NArray::SFLOAT, NArray::FLOAT, nil].include?(na_type)
|
|
3027 |
+ @@unpack_type = na_type
|
|
3028 |
+ else
|
|
3029 |
+ raise ArgumentError, "Arg must be one of NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, NArray::FLOAT"
|
|
3030 |
+ end
|
|
3031 |
+ end
|
|
3032 |
+
|
|
3033 |
+ end
|
|
3034 |
+
|
|
3035 |
+ def unpack(na)
|
|
3036 |
+ sf = att('scale_factor')
|
|
3037 |
+ ao = att('add_offset')
|
|
3038 |
+ if ( sf == nil && ao == nil ) then
|
|
3039 |
+ na
|
|
3040 |
+ else
|
|
3041 |
+ if sf
|
|
3042 |
+ csf = sf.get
|
|
3043 |
+ raise NetcdfError,"scale_factor is not a numeric" if csf.is_a?(String)
|
|
3044 |
+ raise NetcdfError, "scale_factor is not unique" if csf.length != 1
|
|
3045 |
+ raise NetcdfError, "zero scale_factor" if csf[0] == 0
|
|
3046 |
+ else
|
|
3047 |
+ csf =nil
|
|
3048 |
+ end
|
|
3049 |
+ if ao
|
|
3050 |
+ cao = ao.get
|
|
3051 |
+ raise NetcdfError, "add_offset is not a numeric" if cao.is_a?(String)
|
|
3052 |
+ raise NetcdfError, "add_offset is not unique" if cao.length != 1
|
|
3053 |
+ else
|
|
3054 |
+ cao = nil
|
|
3055 |
+ end
|
|
3056 |
+ if csf and cao
|
|
3057 |
+ una = na * csf + cao # csf & cao are NArray -> coerced to their types
|
|
3058 |
+ elsif csf
|
|
3059 |
+ una = na * csf
|
|
3060 |
+ elsif cao
|
|
3061 |
+ una = na + cao
|
|
3062 |
+ end
|
|
3063 |
+ una = una.to_type(@@unpack_type) if @@unpack_type
|
|
3064 |
+ una
|
|
3065 |
+ end
|
|
3066 |
+ end
|
|
3067 |
+
|
|
3068 |
+ def scaled_get(hash=nil)
|
|
3069 |
+ unpack( simple_get(hash) )
|
|
3070 |
+ end
|
|
3071 |
+
|
|
3072 |
+ def simple_put(var,hash=nil)
|
|
3073 |
+ if hash==nil
|
|
3074 |
+ if self.vartype == "char"
|
|
3075 |
+ put_var_char(var)
|
|
3076 |
+ elsif self.vartype == "byte"
|
|
3077 |
+ put_var_byte(var)
|
|
3078 |
+ elsif self.vartype == "sint"
|
|
3079 |
+ put_var_sint(var)
|
|
3080 |
+ elsif self.vartype == "int"
|
|
3081 |
+ put_var_int(var)
|
|
3082 |
+ elsif self.vartype == "sfloat"
|
|
3083 |
+ put_var_sfloat(var)
|
|
3084 |
+ elsif self.vartype == "float"
|
|
3085 |
+ put_var_float(var)
|
|
3086 |
+ else
|
|
3087 |
+ raise NetcdfError,"variable type isn't supported in netCDF"
|
|
3088 |
+ end
|
|
3089 |
+ elsif hash.key?("index")==true
|
|
3090 |
+ if self.vartype == "char"
|
|
3091 |
+ put_var1_char(var,hash["index"])
|
|
3092 |
+ elsif self.vartype=="byte"
|
|
3093 |
+ put_var1_byte(var,hash["index"])
|
|
3094 |
+ elsif self.vartype=="sint"
|
|
3095 |
+ put_var1_sint(var,hash["index"])
|
|
3096 |
+ elsif self.vartype == "int"
|
|
3097 |
+ put_var1_int(var,hash["index"])
|
|
3098 |
+ elsif self.vartype == "sfloat"
|
|
3099 |
+ put_var1_sfloat(var,hash["index"])
|
|
3100 |
+ elsif self.vartype == "float"
|
|
3101 |
+ put_var1_float(var,hash["index"])
|
|
3102 |
+ else
|
|
3103 |
+ raise NetcdfError,"variable type isn't supported in netCDF"
|
|
3104 |
+ end
|
|
3105 |
+ elsif hash.key?("start")==true
|
|
3106 |
+ if hash.key?("end")==false && hash.key?("stride")==false
|
|
3107 |
+ if self.vartype == "char"
|
|
3108 |
+ put_vars_char(var,hash["start"],nil,nil)
|
|
3109 |
+ elsif self.vartype=="byte"
|
|
3110 |
+ put_vars_byte(var,hash["start"],nil,nil)
|
|
3111 |
+ elsif self.vartype=="sint"
|
|
3112 |
+ put_vars_sint(var,hash["start"],nil,nil)
|
|
3113 |
+ elsif self.vartype=="int"
|
|
3114 |
+ put_vars_int(var,hash["start"],nil,nil)
|
|
3115 |
+ elsif self.vartype=="sfloat"
|
|
3116 |
+ put_vars_sfloat(var,hash["start"],nil,nil)
|
|
3117 |
+ elsif self.vartype=="float"
|
|
3118 |
+ put_vars_float(var,hash["start"],nil,nil)
|
|
3119 |
+ else
|
|
3120 |
+ raise NetcdfError, "variable type isn't supported in netCDF"
|
|
3121 |
+ end
|
|
3122 |
+ elsif hash.key?("end")==true && hash.key?("stride") == false
|
|
3123 |
+ if self.vartype == "char"
|
|
3124 |
+ put_vars_char(var,hash["start"],hash["end"],nil)
|
|
3125 |
+ elsif self.vartype=="byte"
|
|
3126 |
+ put_vars_byte(var,hash["start"],hash["end"],nil)
|
|
3127 |
+ elsif self.vartype=="sint"
|
|
3128 |
+ put_vars_sint(var,hash["start"],hash["end"],nil)
|
|
3129 |
+ elsif self.vartype=="int"
|
|
3130 |
+ put_vars_int(var,hash["start"],hash["end"],nil)
|
|
3131 |
+ elsif self.vartype == "sfloat"
|
|
3132 |
+ put_vars_sfloat(var,hash["start"],hash["end"],nil)
|
|
3133 |
+ elsif self.vartype =="float"
|
|
3134 |
+ put_vars_float(var,hash["start"],hash["end"],nil)
|
|
3135 |
+ else
|
|
3136 |
+ raise NetcdfError, "variable type isn't supported in netCDF"
|
|
3137 |
+ end
|
|
3138 |
+ elsif hash.key?("end")==false && hash.key?("stride")==true
|
|
3139 |
+ if self.vartype == "char"
|
|
3140 |
+ put_vars_char(var,hash["start"],nil,hash["stride"])
|
|
3141 |
+ elsif self.vartype=="byte"
|
|
3142 |
+ put_vars_byte(var,hash["start"],nil,hash["stride"])
|
|
3143 |
+ elsif self.vartype=="sint"
|
|
3144 |
+ put_vars_sint(var,hash["start"],nil,hash["stride"])
|
|
3145 |
+ elsif self.vartype=="int"
|
|
3146 |
+ put_vars_int(var,hash["start"],nil,hash["stride"])
|
|
3147 |
+ elsif self.vartype=="sfloat"
|
|
3148 |
+ put_vars_sfloat(var,hash["start"],nil,hash["stride"])
|
|
3149 |
+ elsif self.vartype=="float"
|
|
3150 |
+ put_vars_float(var,hash["start"],nil,hash["stride"])
|
|
3151 |
+ else
|
|
3152 |
+ raise NetcdfError, "variable type isn't supported in netCDF"
|
|
3153 |
+ end
|
|
3154 |
+ else hash.key?("end")==true && hash.key?("stride")==true
|
|
3155 |
+ if self.vartype == "char"
|
|
3156 |
+ put_vars_char(var,hash["start"],hash["end"],hash["stride"])
|
|
3157 |
+ elsif self.vartype=="byte"
|
|
3158 |
+ put_vars_byte(var,hash["start"],hash["end"],hash["stride"])
|
|
3159 |
+ elsif self.vartype=="sint"
|
|
3160 |
+ put_vars_sint(var,hash["start"],hash["end"],hash["stride"])
|
|
3161 |
+ elsif self.vartype=="int"
|
|
3162 |
+ put_vars_int(var,hash["start"],hash["end"],hash["stride"])
|
|
3163 |
+ elsif self.vartype=="sfloat"
|
|
3164 |
+ put_vars_sfloat(var,hash["start"],hash["end"],hash["stride"])
|
|
3165 |
+ elsif self.vartype=="float"
|
|
3166 |
+ put_vars_float(var,hash["start"],hash["end"],hash["stride"])
|
|
3167 |
+ else
|
|
3168 |
+ raise NetcdfError, "variable type isn't supported in netCDF"
|
|
3169 |
+ end
|
|
3170 |
+ end
|
|
3171 |
+ else
|
|
3172 |
+ raise ArgumentError,"{'start'}=>[ARRAY] or {'index'}=>[ARRAY] is needed"
|
|
3173 |
+ end
|
|
3174 |
+ end
|
|
3175 |
+
|
|
3176 |
+ alias put simple_put
|
|
3177 |
+
|
|
3178 |
+ def simple_get(hash=nil)
|
|
3179 |
+ t_var = self.vartype
|
|
3180 |
+ if hash == nil
|
|
3181 |
+ if t_var == "char"
|
|
3182 |
+ get_var_char
|
|
3183 |
+ elsif t_var == "byte"
|
|
3184 |
+ get_var_byte
|
|
3185 |
+ elsif t_var == "sint"
|
|
3186 |
+ get_var_sint
|
|
3187 |
+ elsif t_var == "int"
|
|
3188 |
+ get_var_int
|
|
3189 |
+ elsif t_var == "sfloat"
|
|
3190 |
+ get_var_sfloat
|
|
3191 |
+ elsif t_var == "float"
|
|
3192 |
+ get_var_float
|
|
3193 |
+ else
|
|
3194 |
+ raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
|
3195 |
+ end
|
|
3196 |
+ elsif hash.key?("index")==true
|
|
3197 |
+ ind = hash["index"]
|
|
3198 |
+ if t_var == "char"
|
|
3199 |
+ get_var1_char(ind)
|
|
3200 |
+ elsif t_var == "byte"
|
|
3201 |
+ get_var1_byte(ind)
|
|
3202 |
+ elsif t_var == "sint"
|
|
3203 |
+ get_var1_sint(ind)
|
|
3204 |
+ elsif t_var == "int"
|
|
3205 |
+ get_var1_int(ind)
|
|
3206 |
+ elsif t_var == "sfloat"
|
|
3207 |
+ get_var1_sfloat(ind)
|
|
3208 |
+ elsif t_var == "float"
|
|
3209 |
+ get_var1_float(ind)
|
|
3210 |
+ else
|
|
3211 |
+ raise NetcdfError,"variable type #{t_var} isn't supported in netCDF"
|
|
3212 |
+ end
|
|
3213 |
+ elsif hash.key?("start")==true
|
|
3214 |
+ h_sta = hash["start"]
|
|
3215 |
+ h_end = hash["end"] # can be nill
|
|
3216 |
+ h_str = hash["stride"] # can be nill
|
|
3217 |
+ if NetCDF.nc4? && h_str && ((xstr=h_str[0]) != 1)
|
|
3218 |
+ # Tentative treatment for the very slow netcdf-4 reading with step.
|
|
3219 |
+ # Reading with step is generally slow with NetCDF 4, but it is
|
|
3220 |
+ # particularly so for the first dimension.
|
|
3221 |
+ # Ref: http://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2013/msg00311.html
|
|
3222 |
+ h_str[0] = 1
|
|
3223 |
+ nc4remedy = true
|
|
3224 |
+ else
|
|
3225 |
+ nc4remedy = false
|
|
3226 |
+ end
|
|
3227 |
+ if t_var == "char"
|
|
3228 |
+ v = get_vars_char(h_sta,h_end,h_str)
|
|
3229 |
+ elsif t_var == "byte"
|
|
3230 |
+ v = get_vars_byte(h_sta,h_end,h_str)
|
|
3231 |
+ elsif t_var == "sint"
|
|
3232 |
+ v = get_vars_sint(h_sta,h_end,h_str)
|
|
3233 |
+ elsif t_var == "int"
|
|
3234 |
+ v = get_vars_int(h_sta,h_end,h_str)
|
|
3235 |
+ elsif t_var == "sfloat"
|
|
3236 |
+ v = get_vars_sfloat(h_sta,h_end,h_str)
|
|
3237 |
+ elsif t_var == "float"
|
|
3238 |
+ v = get_vars_float(h_sta,h_end,h_str)
|
|
3239 |
+ else
|
|
3240 |
+ raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
|
3241 |
+ end
|
|
3242 |
+ if nc4remedy
|
|
3243 |
+ idx = []
|
|
3244 |
+ (0...v.shape[0]).step(xstr){|k| idx.push(k)}
|
|
3245 |
+ v = v[idx,false]
|
|
3246 |
+ end
|
|
3247 |
+ v
|
|
3248 |
+ else
|
|
3249 |
+ raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
|
|
3250 |
+ end
|
|
3251 |
+ end
|
|
3252 |
+
|
|
3253 |
+ alias get simple_get
|
|
3254 |
+
|
|
3255 |
+ def __rubber_expansion( args )
|
|
3256 |
+ if (id = args.index(false)) # substitution into id
|
|
3257 |
+ # false is incuded
|
|
3258 |
+ alen = args.length
|
|
3259 |
+ if args.rindex(false) != id
|
|
3260 |
+ raise ArguemntError,"only one rubber dimension is permitted"
|
|
3261 |
+ elsif alen > rank+1
|
|
3262 |
+ raise ArgumentError, "too many args"
|
|
3263 |
+ end
|
|
3264 |
+ ar = ( id!=0 ? args[0..id-1] : [] )
|
|
3265 |
+ args = ar + [true]*(rank-alen+1) + args[id+1..-1]
|
|
3266 |
+ elsif args.length == 0 # to support empty [], []=
|
|
3267 |
+ args = [true]*rank
|
|
3268 |
+ end
|
|
3269 |
+ args
|
|
3270 |
+ end
|
|
3271 |
+ private :__rubber_expansion
|
|
3272 |
+
|
|
3273 |
+ def [](*a)
|
|
3274 |
+ if a.length == 0
|
|
3275 |
+ return self.get
|
|
3276 |
+ end
|
|
3277 |
+ a = __rubber_expansion(a)
|
|
3278 |
+ first = Array.new
|
|
3279 |
+ last = Array.new
|
|
3280 |
+ stride = Array.new
|
|
3281 |
+ set_stride = false
|
|
3282 |
+ a.each{|i|
|
|
3283 |
+ if(i.is_a?(Integer))
|
|
3284 |
+ first.push(i)
|
|
3285 |
+ last.push(i)
|
|
3286 |
+ stride.push(1)
|
|
3287 |
+ elsif(i.is_a?(Range))
|
|
3288 |
+ first.push(i.first)
|
|
3289 |
+ last.push(i.exclude_end? ? i.last-1 : i.last)
|
|
3290 |
+ stride.push(1)
|
|
3291 |
+ elsif(i.is_a?(Hash))
|
|
3292 |
+ r = (i.to_a[0])[0]
|
|
3293 |
+ s = (i.to_a[0])[1]
|
|
3294 |
+ if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
|
|
3295 |
+ raise TypeError, "Hash argument must be {a_Range, step}"
|
|
3296 |
+ end
|
|
3297 |
+ first.push(r.first)
|
|
3298 |
+ last.push(r.exclude_end? ? r.last-1 : r.last)
|
|
3299 |
+ stride.push(s)
|
|
3300 |
+ set_stride = true
|
|
3301 |
+ elsif(i.is_a?(TrueClass))
|
|
3302 |
+ first.push(0)
|
|
3303 |
+ last.push(-1)
|
|
3304 |
+ stride.push(1)
|
|
3305 |
+ elsif( i.is_a?(Array) || i.is_a?(NArray))
|
|
3306 |
+ a_new = a.dup
|
|
3307 |
+ at = a.index(i)
|
|
3308 |
+ i = NArray.to_na(i) if i.is_a?(Array)
|
|
3309 |
+ for n in 0..i.length-1
|
|
3310 |
+ a_new[at] = i[n]..i[n]
|
|
3311 |
+ na_tmp = self[*a_new]
|
|
3312 |
+ if n==0 then
|
|
3313 |
+ k = at
|
|
3314 |
+ if at > 0
|
|
3315 |
+ a[0..at-1].each{|x| if x.is_a?(Integer) then k -= 1 end}
|
|
3316 |
+ end
|
|
3317 |
+ shape_tmp = na_tmp.shape
|
|
3318 |
+ shape_tmp[k] = i.length
|
|
3319 |
+ na = na_tmp.class.new(na_tmp.typecode,*shape_tmp)
|
|
3320 |
+ index_tmp = Array.new(shape_tmp.length,true)
|
|
3321 |
+ end
|
|
3322 |
+ index_tmp[k] = n..n
|
|
3323 |
+ na[*index_tmp] = na_tmp
|
|
3324 |
+ end
|
|
3325 |
+ return na
|
|
3326 |
+ else
|
|
3327 |
+ raise TypeError, "argument must be Integer, Range, Hash, TrueClass, Array, or NArray"
|
|
3328 |
+ end
|
|
3329 |
+ }
|
|
3330 |
+
|
|
3331 |
+ if(set_stride)
|
|
3332 |
+ na = self.get({"start"=>first, "end"=>last, "stride"=>stride})
|
|
3333 |
+ else
|
|
3334 |
+ na = self.get({"start"=>first, "end"=>last})
|
|
3335 |
+ end
|
|
3336 |
+ shape = na.shape
|
|
3337 |
+ (a.length-1).downto(0){ |i|
|
|
3338 |
+ shape.delete_at(i) if a[i].is_a?(Integer)
|
|
3339 |
}
|
|
3340 |
na.reshape!( *shape )
|
|
3341 |
- na
|
|
3342 |
- end
|
|
3343 |
-
|
|
3344 |
- def []=(*a)
|
|
3345 |
- val = a.pop
|
|
3346 |
- a = __rubber_expansion(a)
|
|
3347 |
- first = Array.new
|
|
3348 |
- last = Array.new
|
|
3349 |
- stride = Array.new
|
|
3350 |
- set_stride = false
|
|
3351 |
- a.each{|i|
|
|
3352 |
- if(i.is_a?(Fixnum))
|
|
3353 |
- first.push(i)
|
|
3354 |
- last.push(i)
|
|
3355 |
- stride.push(1)
|
|
3356 |
- elsif(i.is_a?(Range))
|
|
3357 |
- first.push(i.first)
|
|
3358 |
- last.push(i.exclude_end? ? i.last-1 : i.last)
|
|
3359 |
- stride.push(1)
|
|
3360 |
- elsif(i.is_a?(Hash))
|
|
3361 |
- r = (i.to_a[0])[0]
|
|
3362 |
- s = (i.to_a[0])[1]
|
|
3363 |
- if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
|
|
3364 |
- raise ArgumentError, "Hash argument must be {first..last, step}"
|
|
3365 |
- end
|
|
3366 |
- first.push(r.first)
|
|
3367 |
- last.push(r.exclude_end? ? r.last-1 : r.last)
|
|
3368 |
- stride.push(s)
|
|
3369 |
- set_stride = true
|
|
3370 |
- elsif(i.is_a?(TrueClass))
|
|
3371 |
- first.push(0)
|
|
3372 |
- last.push(-1)
|
|
3373 |
- stride.push(1)
|
|
3374 |
- elsif(i.is_a?(Array) || i.is_a?(NArray))
|
|
3375 |
- a_new = a.dup
|
|
3376 |
- at = a.index(i)
|
|
3377 |
- i = NArray.to_na(i) if i.is_a?(Array)
|
|
3378 |
- val = NArray.to_na(val) if val.is_a?(Array)
|
|
3379 |
- rank_of_subset = a.dup.delete_if{|v| v.is_a?(Fixnum)}.length
|
|
3380 |
- if val.rank != rank_of_subset
|
|
3381 |
- raise "rank of the rhs (#{val.rank}) is not equal to the rank "+
|
|
3382 |
- "of the subset specified by #{a.inspect} (#{rank_of_subset})"
|
|
3383 |
- end
|
|
3384 |
- k = at
|
|
3385 |
- a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
|
|
3386 |
- if i.length != val.shape[k]
|
|
3387 |
- raise "length of the #{k+1}-th dim of rhs is incorrect "+
|
|
3388 |
- "(#{i.length} for #{val.shape[k]})"
|
|
3389 |
- end
|
|
3390 |
- index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like
|
|
3391 |
- for n in 0..i.length-1
|
|
3392 |
- a_new[at] = i[n]..i[n]
|
|
3393 |
- if !val.is_a?(Numeric) then
|
|
3394 |
- index_tmp[k] = n..n
|
|
3395 |
- self[*a_new] = val[*index_tmp]
|
|
3396 |
- else
|
|
3397 |
- self[*a_new] = val
|
|
3398 |
- end
|
|
3399 |
- end
|
|
3400 |
- return self
|
|
3401 |
- else
|
|
3402 |
- raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
|
|
3403 |
- end
|
|
3404 |
- }
|
|
3405 |
-
|
|
3406 |
- if(set_stride)
|
|
3407 |
- self.put(val, {"start"=>first, "end"=>last, "stride"=>stride})
|
|
3408 |
- else
|
|
3409 |
- self.put(val, {"start"=>first, "end"=>last})
|
|
3410 |
- end
|
|
3411 |
- end
|
|
3412 |
-
|
|
3413 |
- def inspect
|
|
3414 |
- 'NetCDFVar:'+file.path+'?var='+name
|
|
3415 |
- end
|
|
3416 |
-
|
|
3417 |
- end
|
|
3418 |
-
|
|
3419 |
- class NetCDFAtt
|
|
3420 |
-
|
|
3421 |
- def put(val,atttype=nil)
|
|
3422 |
+ na
|
|
3423 |
+ end
|
|
3424 |
+
|
|
3425 |
+ def []=(*a)
|
|
3426 |
+ val = a.pop
|
|
3427 |
+ a = __rubber_expansion(a)
|
|
3428 |
+ first = Array.new
|
|
3429 |
+ last = Array.new
|
|
3430 |
+ stride = Array.new
|
|
3431 |
+ set_stride = false
|
|
3432 |
+ a.each{|i|
|
|
3433 |
+ if(i.is_a?(Integer))
|
|
3434 |
+ first.push(i)
|
|
3435 |
+ last.push(i)
|
|
3436 |
+ stride.push(1)
|
|
3437 |
+ elsif(i.is_a?(Range))
|
|
3438 |
+ first.push(i.first)
|
|
3439 |
+ last.push(i.exclude_end? ? i.last-1 : i.last)
|
|
3440 |
+ stride.push(1)
|
|
3441 |
+ elsif(i.is_a?(Hash))
|
|
3442 |
+ r = (i.to_a[0])[0]
|
|
3443 |
+ s = (i.to_a[0])[1]
|
|
3444 |
+ if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
|
|
3445 |
+ raise ArgumentError, "Hash argument must be {first..last, step}"
|
|
3446 |
+ end
|
|
3447 |
+ first.push(r.first)
|
|
3448 |
+ last.push(r.exclude_end? ? r.last-1 : r.last)
|
|
3449 |
+ stride.push(s)
|
|
3450 |
+ set_stride = true
|
|
3451 |
+ elsif(i.is_a?(TrueClass))
|
|
3452 |
+ first.push(0)
|
|
3453 |
+ last.push(-1)
|
|
3454 |
+ stride.push(1)
|
|
3455 |
+ elsif(i.is_a?(Array) || i.is_a?(NArray))
|
|
3456 |
+ a_new = a.dup
|
|
3457 |
+ at = a.index(i)
|
|
3458 |
+ i = NArray.to_na(i) if i.is_a?(Array)
|
|
3459 |
+ val = NArray.to_na(val) if val.is_a?(Array)
|
|
3460 |
+ rank_of_subset = a.dup.delete_if{|v| v.is_a?(Integer)}.length
|
|
3461 |
+ if val.rank != rank_of_subset
|
|
3462 |
+ raise "rank of the rhs (#{val.rank}) is not equal to the rank "+
|
|
3463 |
+ "of the subset specified by #{a.inspect} (#{rank_of_subset})"
|
|
3464 |
+ end
|
|
3465 |
+ k = at
|
|
3466 |
+ a[0..at-1].each{|x| if x.is_a?(Integer) then k -= 1 end}
|
|
3467 |
+ if i.length != val.shape[k]
|
|
3468 |
+ raise "length of the #{k+1}-th dim of rhs is incorrect "+
|
|
3469 |
+ "(#{i.length} for #{val.shape[k]})"
|
|
3470 |
+ end
|
|
3471 |
+ index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like
|
|
3472 |
+ for n in 0..i.length-1
|
|
3473 |
+ a_new[at] = i[n]..i[n]
|
|
3474 |
+ if !val.is_a?(Numeric) then
|
|
3475 |
+ index_tmp[k] = n..n
|
|
3476 |
+ self[*a_new] = val[*index_tmp]
|
|
3477 |
+ else
|
|
3478 |
+ self[*a_new] = val
|
|
3479 |
+ end
|
|
3480 |
+ end
|
|
3481 |
+ return self
|
|
3482 |
+ else
|
|
3483 |
+ raise TypeError, "argument must be Integer, Range, Hash, TrueClass, Array, or NArray"
|
|
3484 |
+ end
|
|
3485 |
+ }
|
|
3486 |
+
|
|
3487 |
+ if(set_stride)
|
|
3488 |
+ self.put(val, {"start"=>first, "end"=>last, "stride"=>stride})
|
|
3489 |
+ else
|
|
3490 |
+ self.put(val, {"start"=>first, "end"=>last})
|
|
3491 |
+ end
|
|
3492 |
+ end
|
|
3493 |
+
|
|
3494 |
+ def inspect
|
|
3495 |
+ 'NetCDFVar:'+file.path+'?var='+name
|
|
3496 |
+ end
|
|
3497 |
+
|
|
3498 |
+ end
|
|
3499 |
+
|
|
3500 |
+ class NetCDFAtt
|
|
3501 |
+
|
|
3502 |
+ def put(val,atttype=nil)
|
|
3503 |
putraw(val,atttype)
|
|
3504 |
- end
|
|
3505 |
-
|
|
3506 |
- def inspect
|
|
3507 |
- 'NetCDFAtt:'+name
|
|
3508 |
- end
|
|
3509 |
- end
|
|
3510 |
-
|
|
3511 |
- class NetCDFDim
|
|
3512 |
- def inspect
|
|
3513 |
- 'NetCDFDim:'+name
|
|
3514 |
- end
|
|
3515 |
-
|
|
3516 |
- def length_ul0
|
|
3517 |
+ end
|
|
3518 |
+
|
|
3519 |
+ def inspect
|
|
3520 |
+ 'NetCDFAtt:'+name
|
|
3521 |
+ end
|
|
3522 |
+ end
|
|
3523 |
+
|
|
3524 |
+ class NetCDFDim
|
|
3525 |
+ def inspect
|
|
3526 |
+ 'NetCDFDim:'+name
|
|
3527 |
+ end
|
|
3528 |
+
|
|
3529 |
+ def length_ul0
|
|
3530 |
if unlimited?
|
|
3531 |
- 0
|
|
3532 |
+ 0
|
|
3533 |
else
|
|
3534 |
- length
|
|
3535 |
+ length
|
|
3536 |
end
|
|
3537 |
- end
|
|
3538 |
+ end
|
|
3539 |
|
|
3540 |
- end
|
|
3541 |
+ end
|
|
3542 |
end
|