Mercurial > forge
annotate main/netcdf/src/__netcdf__.cc @ 12707:543825a41fd6 octave-forge
fix bug #46798; bad delete
author | abarth93 |
---|---|
date | Wed, 27 Jan 2016 08:19:59 +0000 |
parents | 78807393548d |
children |
rev | line source |
---|---|
11984 | 1 // Copyright (C) 2013 Alexander Barth <barth.alexander@gmail.com> |
2 // | |
3 // This program is free software; you can redistribute it and/or modify it under | |
4 // the terms of the GNU General Public License as published by the Free Software | |
5 // Foundation; either version 2 of the License, or (at your option) any later | |
6 // version. | |
7 // | |
8 // This program is distributed in the hope that it will be useful, but WITHOUT | |
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
11 // details. | |
12 // | |
13 // You should have received a copy of the GNU General Public License along with | |
14 // this program; if not, see <http://www.gnu.org/licenses/>. | |
15 | |
16 | |
17 #include <octave/oct.h> | |
18 #include <octave/ov-cell.h> | |
19 | |
20 #include <netcdf.h> | |
21 | |
22 #include <string> | |
23 #include <map> | |
24 #include <iostream> | |
25 #include <algorithm> | |
26 #include <vector> | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
27 #include <inttypes.h> |
11984 | 28 |
29 std::map<std::string, octave_value> netcdf_constants; | |
30 | |
31 void init() { | |
32 #include "netcdf_constants.h" | |
33 } | |
34 | |
35 void check_err(int status) | |
36 { | |
37 if (status != NC_NOERR) error("%s",nc_strerror(status)); | |
38 } | |
39 | |
40 // convert name to upper-case and add "NC_" prefix if it is missing | |
41 std::string normalize_ncname(std::string name) { | |
42 std::string prefix = "NC_"; | |
43 std::string ncname = name; | |
44 // to upper case | |
45 std::transform(ncname.begin(), ncname.end(),ncname.begin(), ::toupper); | |
46 | |
47 // add prefix if it is missing | |
48 if (ncname.substr(0, prefix.size()) != prefix) { | |
49 ncname = prefix + ncname; | |
50 } | |
51 return ncname; | |
52 } | |
53 | |
54 octave_value netcdf_get_constant(octave_value ov) | |
55 { | |
56 if (netcdf_constants.empty()) | |
57 { | |
58 init(); | |
59 } | |
60 | |
61 if (ov.is_scalar_type()) | |
62 { | |
63 return ov.scalar_value(); | |
64 } | |
65 | |
66 std::string name = ov.string_value(); | |
67 name = normalize_ncname(name); | |
68 std::map<std::string, octave_value>::const_iterator cst = netcdf_constants.find(name); | |
69 | |
70 if (cst != netcdf_constants.end ()) | |
71 { | |
72 return cst->second; | |
73 } | |
74 else | |
75 { | |
76 error("unknown netcdf constant: %s",name.c_str()); | |
11990 | 77 return octave_value(); |
11984 | 78 } |
79 } | |
80 | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
81 size_t to_size_t(octave_value ov) { |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
82 size_t sz; |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
83 sz = static_cast<uint64_t>(ov.uint64_scalar_value()); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
84 return sz; |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
85 } |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
86 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
87 void to_size_t_vector(octave_value ov, int len, size_t *vec) { |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
88 uint64NDArray tmp = ov.uint64_array_value(); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
89 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
90 for (int i=0; i<len; i++) |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
91 { |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
92 vec[i] = static_cast<uint64_t>(tmp(len-i-1)); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
93 } |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
94 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
95 } |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
96 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
97 void to_ptrdiff_t_vector(octave_value ov, int len, ptrdiff_t *vec) { |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
98 int64NDArray tmp = ov.int64_array_value(); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
99 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
100 for (int i=0; i<len; i++) |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
101 { |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
102 vec[i] = static_cast<int64_t>(tmp(len-i-1)); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
103 } |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
104 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
105 } |
11984 | 106 |
11994 | 107 void start_count_stride(int ncid, int varid, octave_value_list args,int len, |
108 int ndims, size_t* start,size_t* count,ptrdiff_t* stride) | |
11984 | 109 { |
11994 | 110 OCTAVE_LOCAL_BUFFER (int, dimids, ndims); |
11984 | 111 check_err(nc_inq_vardimid (ncid, varid, dimids)); |
112 | |
113 // default values for start, count and stride | |
114 // i.e. all variable is loaded | |
115 | |
116 for (int i=0; i<ndims; i++) { | |
117 check_err(nc_inq_dimlen(ncid,dimids[i],&(count[i]))); | |
118 start[i] = 0; | |
119 //cout << "count def " << count[i] << " " << i << endl; | |
120 stride[i] = 1; | |
121 } | |
122 | |
123 // start argument | |
124 | |
125 if (len > 2) | |
126 { | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
127 if (args(2).numel() != ndims) |
11984 | 128 { |
129 error("number of elements of argument %s should match the number " | |
130 "of dimension of the netCDF variable", | |
131 "start"); | |
132 } | |
133 | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
134 to_size_t_vector(args(2),ndims,start); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
135 |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
136 // if start is specified, the default for count is 1 (how odd!) |
11984 | 137 for (int i=0; i<ndims; i++) |
138 { | |
139 count[i] = 1; | |
140 } | |
141 } | |
142 | |
143 // count argument | |
144 | |
145 if (len > 3) | |
146 { | |
147 | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
148 if (args(3).numel() != ndims) |
11984 | 149 { |
150 error("number of elements of argument %s should match the number " | |
151 "of dimension of the netCDF variable", | |
152 "count"); | |
153 } | |
154 | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
155 to_size_t_vector(args(3),ndims,count); |
11984 | 156 } |
157 | |
158 // stride argument | |
159 | |
160 if (len > 4) | |
161 { | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
162 if (args(4).numel() != ndims) |
11984 | 163 { |
164 error("number of elements of argument %s should match the number " | |
165 "of dimension of the netCDF variable", | |
166 "stride"); | |
167 } | |
168 | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
169 to_ptrdiff_t_vector(args(4),ndims,stride); |
11984 | 170 } |
171 } | |
172 | |
173 | |
174 DEFUN_DLD(netcdf_getConstant, args,, | |
175 "-*- texinfo -*-\n\ | |
176 @deftypefn {Loadable Function} {@var{value} =} netcdf_getConstant(@var{name}) \n\ | |
177 Returns the value of a NetCDF constant called @var{name}.\n\ | |
178 @seealso{netcdf_getConstantNames}\n\ | |
179 @end deftypefn") | |
180 { | |
181 if (args.length() != 1) { | |
182 print_usage (); | |
183 return octave_value(); | |
184 } | |
185 | |
186 return netcdf_get_constant(args(0)); | |
187 } | |
188 | |
189 | |
190 DEFUN_DLD(netcdf_getConstantNames, args,, | |
191 "-*- texinfo -*-\n\ | |
192 @deftypefn {Loadable Function} {@var{value} =} netcdf_getConstantNames() \n\ | |
193 Returns a list of all constant names.\n\ | |
194 @end deftypefn\n\ | |
195 @seealso{netcdf_getConstant}\n") | |
196 { | |
197 | |
11993 | 198 if (args.length() != 0) |
199 { | |
11984 | 200 print_usage (); |
201 return octave_value(); | |
202 } | |
203 | |
11989 | 204 if (netcdf_constants.empty()) |
205 { | |
206 init(); | |
207 } | |
208 | |
11984 | 209 Cell c = Cell (dim_vector(1,netcdf_constants.size())); |
210 | |
211 int i = 0; | |
212 for (std::map<std::string, octave_value>::const_iterator p = netcdf_constants.begin (); | |
213 p != netcdf_constants.end (); p++) { | |
214 c(i++) = octave_value(p->first); | |
215 } | |
216 | |
217 return octave_value(c); | |
218 | |
219 } | |
220 | |
221 | |
222 DEFUN_DLD(netcdf_inqLibVers, args,, | |
223 "-*- texinfo -*-\n\ | |
224 @deftypefn {Loadable Function} {@var{vers} =} netcdf_inqLibVers() \n\ | |
225 Returns the version of the NetCDF library.\n\ | |
226 @end deftypefn\n\ | |
227 @seealso{netcdf_open}\n") | |
228 { | |
11993 | 229 if (args.length() != 0) |
230 { | |
11984 | 231 print_usage (); |
232 return octave_value (); | |
233 } | |
234 | |
235 return octave_value(std::string(nc_inq_libvers())); | |
236 } | |
237 | |
238 DEFUN_DLD(netcdf_setDefaultFormat, args,, | |
239 "-*- texinfo -*-\n\ | |
240 @deftypefn {Loadable Function} {@var{old_format} =} netcdf_setDefaultFormat(@var{format}) \n\ | |
241 Sets the default format of the NetCDF library and returns the previous default format (as a numeric value). @var{format} can be \n\ | |
242 \"format_classic\", \"format_64bit\", \"format_netcdf4\" or \"format_netcdf4_classic\". \n\ | |
243 @end deftypefn\n\ | |
244 @seealso{netcdf_open}\n") | |
245 { | |
246 if (args.length() != 1) | |
247 { | |
248 print_usage (); | |
249 return octave_value (); | |
250 } | |
251 | |
252 int format = netcdf_get_constant(args(0)).int_value(); | |
253 int old_format; | |
254 | |
11993 | 255 if (error_state) |
256 { | |
257 print_usage (); | |
258 return octave_value(); | |
259 } | |
260 | |
11984 | 261 check_err(nc_set_default_format(format, &old_format)); |
262 | |
263 return octave_value(old_format); | |
264 } | |
265 | |
266 | |
267 // int nc_set_chunk_cache(size_t size, size_t nelems, float preemption); | |
268 | |
269 DEFUN_DLD(netcdf_setChunkCache, args,, | |
270 "-*- texinfo -*-\n\ | |
271 @deftypefn {Loadable Function} {} netcdf_setChunkCache(@var{size}, @var{nelems}, @var{preemption}) \n\ | |
272 Sets the default chunk cache settins in the HDF5 library. The settings applies to all files which are subsequently opened or created.\n\ | |
273 @end deftypefn\n\ | |
274 @seealso{netcdf_getChunkCache}\n") | |
275 { | |
276 if (args.length() != 3) | |
277 { | |
278 print_usage (); | |
279 return octave_value(); | |
280 } | |
281 | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
282 size_t size = to_size_t(args(0)); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
283 size_t nelems = to_size_t(args(1)); |
11984 | 284 float preemption = args(2).scalar_value(); |
285 | |
286 if (error_state) | |
287 { | |
288 print_usage (); | |
289 return octave_value(); | |
290 } | |
291 | |
292 check_err(nc_set_chunk_cache(size, nelems, preemption)); | |
293 | |
294 return octave_value(); | |
295 } | |
296 | |
297 | |
298 // int nc_get_chunk_cache(size_t *sizep, size_t *nelemsp, float *preemptionp); | |
299 | |
300 DEFUN_DLD(netcdf_getChunkCache, args,, | |
301 "-*- texinfo -*-\n\ | |
302 @deftypefn {Loadable Function} {[@var{size}, @var{nelems}, @var{preemption}] =} netcdf_getChunkCache() \n\ | |
303 Gets the default chunk cache settins in the HDF5 library. \n\ | |
304 @end deftypefn\n\ | |
305 @seealso{netcdf_setChunkCache}\n") | |
306 { | |
307 if (args.length() != 0) | |
308 { | |
309 print_usage (); | |
310 return octave_value (); | |
311 } | |
312 | |
313 size_t size; | |
314 size_t nelems; | |
315 float preemption; | |
316 | |
317 if (error_state) | |
318 { | |
319 print_usage (); | |
320 return octave_value(); | |
321 } | |
322 | |
323 check_err(nc_get_chunk_cache(&size, &nelems, &preemption)); | |
324 octave_value_list retval; | |
325 retval(0) = octave_value(size); | |
326 retval(1) = octave_value(nelems); | |
327 retval(2) = octave_value(preemption); | |
328 | |
329 return retval; | |
330 } | |
331 | |
332 | |
333 | |
334 DEFUN_DLD(netcdf_create, args,, | |
335 "-*- texinfo -*-\n\ | |
336 @deftypefn {Loadable Function} {@var{ncid} =} netcdf_create(@var{filename},@var{mode}) \n\ | |
337 Creates the file named @var{filename} in the mode @var{mode} which can have the \n\ | |
338 following values: \n\ | |
339 \"clobber\" (overwrite existing files), \n\ | |
340 \"noclobber\" (prevent to overwrite existing files) \n\ | |
341 \"64bit_offset\" (use the 64bit-offset format), \n\ | |
342 \"netcdf4\" (use the NetCDF4, i.e. HDF5 format) or \n\ | |
343 \"share\" (concurrent reading of the dataset). \n\ | |
344 @var{mode} can also be the numeric value return by netcdf_getConstant. In the later-case it can be combined with a bitwise-or. \n\ | |
345 @end deftypefn\n\ | |
346 Example: \n\ | |
347 @example \n\ | |
348 mode = bitor(netcdf.getConstant(\"classic_model\"), ...\n\ | |
349 netcdf.getConstant(\"netcdf4\")); \n\ | |
350 ncid = netcdf.create(\"test.nc\",mode); \n\ | |
351 @end example \n\ | |
352 @seealso{netcdf_close}\n") | |
353 { | |
354 | |
355 if (args.length() != 2) | |
356 { | |
357 print_usage (); | |
358 return octave_value (); | |
359 } | |
360 | |
361 std::string filename = args(0).string_value(); | |
362 int mode = netcdf_get_constant(args(1)).int_value(); | |
363 int ncid; | |
364 | |
11993 | 365 if (error_state) |
366 { | |
367 print_usage (); | |
368 return octave_value(); | |
369 } | |
370 | |
11984 | 371 check_err(nc_create(filename.c_str(), mode, &ncid)); |
372 | |
373 return octave_value(ncid); | |
374 } | |
375 | |
376 DEFUN_DLD(netcdf_open, args,, | |
377 "-*- texinfo -*-\n\ | |
378 @deftypefn {Loadable Function} {@var{ncid} =} netcdf_open(@var{filename},@var{mode}) \n\ | |
379 Opens the file named @var{filename} in the mode @var{mode}.\n\ | |
380 @end deftypefn\n\ | |
381 @seealso{netcdf_close}\n") | |
382 { | |
383 | |
11993 | 384 if (args.length() != 2) |
385 { | |
11984 | 386 print_usage (); |
387 return octave_value(); | |
388 } | |
389 | |
390 std::string filename = args(0).string_value(); | |
391 int mode = netcdf_get_constant(args(1)).int_value(); | |
392 int ncid; | |
393 | |
11993 | 394 if (error_state) |
395 { | |
396 print_usage (); | |
397 return octave_value(); | |
398 } | |
399 | |
11984 | 400 check_err(nc_open(filename.c_str(), mode, &ncid)); |
401 | |
402 return octave_value(ncid); | |
403 } | |
404 | |
405 | |
406 | |
407 DEFUN_DLD(netcdf_abort, args,, | |
408 "-*- texinfo -*-\n\ | |
409 @deftypefn {Loadable Function} {} netcdf_abort(@var{ncid}) \n\ | |
410 Aborts all changes since the last time the dataset entered in define mode.\n\ | |
411 @end deftypefn\n\ | |
412 @seealso{netcdf_reDef}\n") | |
413 { | |
414 | |
415 if (args.length() != 1) | |
416 { | |
417 print_usage (); | |
418 return octave_value(); | |
419 } | |
420 | |
421 int ncid = args(0).scalar_value(); | |
422 | |
423 if (error_state) | |
424 { | |
425 print_usage (); | |
426 return octave_value(); | |
427 } | |
428 | |
429 check_err(nc_abort(ncid)); | |
430 | |
431 return octave_value(); | |
432 } | |
433 | |
434 | |
435 DEFUN_DLD(netcdf_sync, args,, | |
436 "-*- texinfo -*-\n\ | |
437 @deftypefn {Loadable Function} {} netcdf_sync(@var{ncid}) \n\ | |
438 Writes all changes to the disk and leaves the file open.\n\ | |
439 @end deftypefn\n\ | |
440 @seealso{netcdf_close}\n") | |
441 { | |
442 | |
443 if (args.length() != 1) | |
444 { | |
445 print_usage (); | |
446 return octave_value(); | |
447 } | |
448 | |
449 int ncid = args(0).scalar_value(); | |
450 | |
451 if (error_state) | |
452 { | |
453 print_usage (); | |
454 return octave_value(); | |
455 } | |
456 | |
457 check_err(nc_sync(ncid)); | |
458 | |
459 return octave_value(); | |
460 } | |
461 | |
462 DEFUN_DLD(netcdf_setFill, args,, | |
463 "-*- texinfo -*-\n\ | |
464 @deftypefn {Loadable Function} {@var{old_mode} =} netcdf_setFill(@var{ncid},@var{fillmode}) \n\ | |
465 Change the fill mode (@var{fillmode}) of the data set @var{ncid}. The previous value of the fill mode is returned. @var{fillmode} can be either \"fill\" or \"nofill\".\n\ | |
466 @end deftypefn\n\ | |
467 @seealso{netcdf_open}\n") | |
468 { | |
469 | |
470 if (args.length() != 2) | |
471 { | |
472 print_usage (); | |
473 return octave_value(); | |
474 } | |
475 | |
476 int ncid = args(0).scalar_value(); | |
477 int fillmode = netcdf_get_constant(args(1)).int_value(); | |
478 int old_mode; | |
479 | |
480 if (error_state) | |
481 { | |
482 print_usage (); | |
483 return octave_value(); | |
484 } | |
485 | |
486 check_err (nc_set_fill (ncid, fillmode, &old_mode)); | |
487 | |
488 return octave_value(old_mode); | |
489 } | |
490 | |
491 | |
492 //int nc_inq (int ncid, int *ndimsp, int *nvarsp, int *ngattsp, | |
493 // int *unlimdimidp); | |
494 DEFUN_DLD(netcdf_inq, args,, | |
495 "-*- texinfo -*-\n\ | |
496 @deftypefn {Loadable Function} {[@var{ndims},@var{nvars},@var{ngatts},@var{unlimdimid}] =} netcdf_inq(@var{ncid}) \n\ | |
497 Return the number of dimension (@var{ndims}), the number of variables (@var{nvars}), the number of global attributes (@var{ngatts}) and the id of the unlimited dimension (@var{unlimdimid}). \n\ | |
498 If no unlimited dimension is declared -1 is returned. For NetCDF4 files, one should use \n\ | |
499 the function netcdf_inqUnlimDims as multiple unlimite dimension exists. \n\ | |
500 @end deftypefn\n\ | |
501 @seealso{netcdf_inqUnlimDims}\n") | |
502 { | |
11993 | 503 if (args.length() != 1) |
504 { | |
11984 | 505 print_usage (); |
506 return octave_value(); | |
507 } | |
508 | |
509 int ncid = args(0).scalar_value(); | |
510 int ndims, nvars, ngatts, unlimdimid; | |
511 octave_value_list retval; | |
512 | |
11993 | 513 if (error_state) |
514 { | |
515 print_usage (); | |
516 return octave_value(); | |
517 } | |
518 | |
11984 | 519 check_err(nc_inq(ncid,&ndims,&nvars,&ngatts,&unlimdimid)); |
520 | |
521 retval(0) = octave_value(ndims); | |
522 retval(1) = octave_value(nvars); | |
523 retval(2) = octave_value(ngatts); | |
524 retval(3) = octave_value(unlimdimid); | |
525 return retval; | |
526 } | |
527 | |
528 // int nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp); | |
529 DEFUN_DLD(netcdf_inqUnlimDims, args,, | |
530 "-*- texinfo -*-\n\ | |
531 @deftypefn {Loadable Function} {@var{unlimdimids} =} netcdf_inqUnlimDims(@var{ncid}) \n\ | |
532 Return the id of all unlimited dimensions of the NetCDF file @var{ncid}.\n\ | |
533 @end deftypefn\n\ | |
534 @seealso{netcdf_inq}\n") | |
535 { | |
11993 | 536 if (args.length() != 1) |
537 { | |
11984 | 538 print_usage (); |
539 return octave_value(); | |
540 } | |
541 | |
542 int ncid = args(0).scalar_value(); | |
543 int nunlimdims; | |
544 | |
11993 | 545 if (error_state) |
546 { | |
547 print_usage (); | |
548 return octave_value(); | |
549 } | |
550 | |
11984 | 551 check_err(nc_inq_unlimdims(ncid, &nunlimdims, NULL)); |
552 Array<int> unlimdimids = Array<int>(dim_vector(1,nunlimdims)); | |
553 check_err(nc_inq_unlimdims(ncid, &nunlimdims, unlimdimids.fortran_vec())); | |
554 | |
555 return octave_value(unlimdimids); | |
556 } | |
557 | |
558 | |
559 // int nc_inq_format (int ncid, int *formatp); | |
560 DEFUN_DLD(netcdf_inqFormat, args,, | |
561 "-*- texinfo -*-\n\ | |
562 @deftypefn {Loadable Function} {@var{format} =} netcdf_inqFormat(@var{ncid}) \n\ | |
563 Return the NetCDF format of the dataset @var{ncid}.\n\ | |
564 Format might be one of the following \n\ | |
565 \"FORMAT_CLASSIC\", \"FORMAT_64BIT\", \"FORMAT_NETCDF4\" or \"FORMAT_NETCDF4_CLASSIC\" \n\ | |
566 @end deftypefn\n\ | |
567 @seealso{netcdf_inq}\n") | |
568 { | |
569 | |
11993 | 570 if (args.length() != 1) |
571 { | |
11984 | 572 print_usage (); |
573 return octave_value(); | |
574 } | |
575 | |
576 int ncid = args(0).scalar_value(); | |
577 int format; | |
11993 | 578 |
579 if (error_state) | |
580 { | |
581 print_usage (); | |
582 return octave_value(); | |
583 } | |
584 | |
11984 | 585 check_err(nc_inq_format(ncid, &format)); |
586 | |
587 if (format == NC_FORMAT_CLASSIC) { | |
588 return octave_value("FORMAT_CLASSIC"); | |
589 } | |
590 if (format == NC_FORMAT_64BIT) { | |
591 return octave_value("FORMAT_64BIT"); | |
592 } | |
593 if (format == NC_FORMAT_NETCDF4) { | |
594 return octave_value("FORMAT_NETCDF4"); | |
595 } | |
596 | |
597 return octave_value("FORMAT_NETCDF4_CLASSIC"); | |
598 } | |
599 | |
600 // int nc_def_dim (int ncid, const char *name, size_t len, int *dimidp); | |
601 | |
602 DEFUN_DLD(netcdf_defDim, args,, | |
603 "-*- texinfo -*-\n\ | |
604 @deftypefn {Loadable Function} {@var{dimid} =} netcdf_defDim(@var{ncid},@var{name},@var{len}) \n\ | |
605 Define the dimension with the name @var{name} and the length @var{len} in the dataset @var{ncid}. The id of the dimension is returned.\n\ | |
606 @end deftypefn\n\ | |
607 @seealso{netcdf_defVar}\n") | |
608 { | |
609 | |
11993 | 610 if (args.length() != 3) |
611 { | |
11984 | 612 print_usage (); |
613 return octave_value(); | |
614 } | |
615 | |
616 int ncid = args(0).scalar_value(); | |
617 std::string name = args(1).string_value(); | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
618 size_t len = to_size_t(args(2)); |
11984 | 619 int dimid; |
620 | |
11993 | 621 if (error_state) |
622 { | |
623 print_usage (); | |
624 return octave_value(); | |
625 } | |
626 | |
11984 | 627 check_err(nc_def_dim (ncid, name.c_str(), len, &dimid)); |
628 | |
629 return octave_value(dimid); | |
630 } | |
631 | |
632 | |
633 // int nc_rename_dim(int ncid, int dimid, const char* name); | |
634 | |
635 | |
636 DEFUN_DLD(netcdf_renameDim, args,, | |
637 "-*- texinfo -*-\n\ | |
638 @deftypefn {Loadable Function} {} netcdf_renameDim(@var{ncid},@var{dimid},@var{name}) \n\ | |
639 Renames the dimension with the id @var{dimid} in the data set @var{ncid}. @var{name} is the new name of the dimension.\n\ | |
640 @end deftypefn\n\ | |
641 @seealso{netcdf_defDim}\n") | |
642 { | |
643 | |
644 if (args.length() != 3) | |
645 { | |
646 print_usage (); | |
647 return octave_value(); | |
648 } | |
649 | |
650 int ncid = args(0).scalar_value(); | |
651 int dimid = args(1).scalar_value(); | |
652 std::string name = args(2).string_value(); | |
653 | |
654 if (error_state) | |
655 { | |
656 print_usage (); | |
657 return octave_value(); | |
658 } | |
659 | |
660 check_err(nc_rename_dim (ncid, dimid, name.c_str())); | |
661 | |
662 return octave_value(); | |
663 } | |
664 | |
665 // int nc_def_var (int ncid, const char *name, nc_type xtype, | |
666 // int ndims, const int dimids[], int *varidp); | |
667 | |
668 DEFUN_DLD(netcdf_defVar, args,, | |
669 "-*- texinfo -*-\n\ | |
670 @deftypefn {Loadable Function} {@var{varid} = } netcdf_defVar(@var{ncid},@var{name},@var{xtype},@var{dimids}) \n\ | |
671 Defines a variable with the name @var{name} in the dataset @var{ncid}. @var{xtype} can be \"byte\", \"ubyte\", \"short\", \"ushort\", \"int\", \"uint\", \"int64\", \"uint64\", \"float\", \"double\", \"char\" or the corresponding number as returned by netcdf_getConstant. The parameter @var{dimids} define the ids of the dimension. For scalar this parameter is the empty array ([]). The variable id is returned. \n\ | |
672 @end deftypefn\n\ | |
673 @seealso{netcdf_open,netcdf_defDim}\n") | |
674 { | |
675 | |
11993 | 676 if (args.length() != 4) |
677 { | |
11984 | 678 print_usage (); |
679 return octave_value(); | |
680 } | |
681 | |
682 int ncid = args(0).scalar_value(); | |
683 std::string name = args(1).string_value (); | |
684 int xtype = netcdf_get_constant(args(2)).int_value();; | |
11993 | 685 |
686 if (error_state) | |
687 { | |
688 print_usage (); | |
689 return octave_value(); | |
690 } | |
691 | |
11984 | 692 Array<double> tmp; |
693 | |
694 if (!args(3).is_empty()) { | |
695 tmp = args(3).vector_value (); | |
696 } | |
697 | |
698 OCTAVE_LOCAL_BUFFER (int, dimids, tmp.numel()); | |
699 | |
700 for (int i = 0; i < tmp.numel(); i++) | |
701 { | |
702 dimids[i] = tmp(tmp.numel()-i-1); | |
703 } | |
704 | |
705 int varid; | |
706 | |
707 check_err(nc_def_var (ncid, name.c_str(), xtype, tmp.numel(), dimids, &varid)); | |
708 | |
709 return octave_value(varid); | |
710 } | |
711 | |
712 | |
713 // int nc_rename_var(int ncid, int varid, const char* name); | |
714 | |
715 | |
716 DEFUN_DLD(netcdf_renameVar, args,, | |
717 "-*- texinfo -*-\n\ | |
718 @deftypefn {Loadable Function} {} netcdf_renameVar(@var{ncid},@var{varid},@var{name}) \n\ | |
719 Renames the variable with the id @var{varid} in the data set @var{ncid}. @var{name} is the new name of the variable.\n\ | |
720 @end deftypefn\n\ | |
721 @seealso{netcdf_defVar}\n") | |
722 { | |
723 | |
724 if (args.length() != 3) | |
725 { | |
726 print_usage (); | |
727 return octave_value(); | |
728 } | |
729 | |
730 int ncid = args(0).scalar_value(); | |
731 int varid = args(1).scalar_value(); | |
732 std::string name = args(2).string_value(); | |
733 | |
734 if (error_state) | |
735 { | |
736 print_usage (); | |
737 return octave_value(); | |
738 } | |
739 | |
740 check_err(nc_rename_var (ncid, varid, name.c_str())); | |
741 | |
742 return octave_value(); | |
743 } | |
744 | |
745 | |
746 // int nc_def_var_fill(int ncid, int varid, int no_fill, void *fill_value); | |
747 DEFUN_DLD(netcdf_defVarFill, args,, | |
748 "-*- texinfo -*-\n\ | |
749 @deftypefn {Loadable Function} {} netcdf_defVarFill(@var{ncid},@var{varid},@var{no_fill},@var{fillvalue}) \n\ | |
750 Define the fill-value settings of the NetCDF variable @var{varid}.\n\ | |
751 If @var{no_fill} is false, then the values between no-contiguous writes are filled with the value @var{fill_value}. This is disabled by setting @var{no_fill} to true.\n\ | |
752 @end deftypefn\n\ | |
753 @seealso{netcdf_inqVarFill}\n") | |
754 { | |
755 | |
11993 | 756 if (args.length() != 4) |
757 { | |
11984 | 758 print_usage (); |
759 return octave_value(); | |
760 } | |
761 | |
762 int ncid = args(0).scalar_value(); | |
763 int varid = args(1).scalar_value(); | |
764 int no_fill = args(2).scalar_value(); // boolean | |
765 octave_value fill_value = args(3); | |
766 nc_type xtype; | |
11993 | 767 |
768 if (error_state) | |
769 { | |
770 print_usage (); | |
771 return octave_value(); | |
772 } | |
773 | |
11984 | 774 check_err(nc_inq_vartype (ncid, varid, &xtype)); |
775 | |
776 switch (xtype) | |
777 { | |
778 #define OV_NETCDF_DEF_VAR_FILL(netcdf_type,c_type,method) \ | |
779 case netcdf_type: \ | |
780 { \ | |
781 check_err(nc_def_var_fill(ncid, varid, no_fill, fill_value.method().fortran_vec())); \ | |
782 break; \ | |
783 } | |
784 | |
785 OV_NETCDF_DEF_VAR_FILL(NC_BYTE, signed char, int8_array_value) | |
786 OV_NETCDF_DEF_VAR_FILL(NC_UBYTE, unsigned char, uint8_array_value) | |
787 OV_NETCDF_DEF_VAR_FILL(NC_SHORT, short, int16_array_value) | |
788 OV_NETCDF_DEF_VAR_FILL(NC_USHORT, unsigned short, uint16_array_value) | |
789 OV_NETCDF_DEF_VAR_FILL(NC_INT, int, int32_array_value) | |
790 OV_NETCDF_DEF_VAR_FILL(NC_UINT, unsigned int, uint32_array_value) | |
791 OV_NETCDF_DEF_VAR_FILL(NC_INT64, long long, int64_array_value) | |
792 OV_NETCDF_DEF_VAR_FILL(NC_UINT64, unsigned long long, uint64_array_value) | |
793 | |
794 OV_NETCDF_DEF_VAR_FILL(NC_FLOAT, float, float_array_value) | |
795 OV_NETCDF_DEF_VAR_FILL(NC_DOUBLE,double,array_value) | |
796 | |
797 OV_NETCDF_DEF_VAR_FILL(NC_CHAR, char, char_array_value) | |
798 } | |
799 | |
800 return octave_value(); | |
801 } | |
802 | |
803 | |
804 | |
805 // int nc_def_var_fill(int ncid, int varid, int no_fill, void *fill_value); | |
806 DEFUN_DLD(netcdf_inqVarFill, args,, | |
807 "-*- texinfo -*-\n\ | |
808 @deftypefn {Loadable Function} {[@var{no_fill},@var{fillvalue}] = } netcdf_inqVarFill(@var{ncid},@var{varid}) \n\ | |
809 Determines the fill-value settings of the NetCDF variable @var{varid}.\n\ | |
810 If @var{no_fill} is false, then the values between no-contiguous writes are filled with the value @var{fill_value}. This is disabled by setting @var{no_fill} to true.\n\ | |
811 @end deftypefn\n\ | |
812 @seealso{netcdf_defVarFill}\n") | |
813 { | |
814 | |
11993 | 815 if (args.length() != 2) |
816 { | |
11984 | 817 print_usage (); |
818 return octave_value(); | |
819 } | |
820 | |
821 int ncid = args(0).scalar_value(); | |
822 int varid = args(1).scalar_value(); | |
823 int no_fill; | |
824 nc_type xtype; | |
825 octave_value_list retval; | |
826 octave_value data; | |
11993 | 827 |
828 if (error_state) | |
829 { | |
830 print_usage (); | |
831 return octave_value(); | |
832 } | |
833 | |
11984 | 834 check_err(nc_inq_vartype (ncid, varid, &xtype)); |
835 | |
11993 | 836 if (error_state) |
837 { | |
838 return octave_value(); | |
839 } | |
840 | |
11984 | 841 switch (xtype) |
842 { | |
843 #define OV_NETCDF_INQ_VAR_FILL(netcdf_type,c_type) \ | |
844 case netcdf_type: \ | |
845 { \ | |
846 Array< c_type > fill_value = Array< c_type >(dim_vector(1,1)); \ | |
847 check_err(nc_inq_var_fill(ncid, varid, &no_fill, \ | |
848 fill_value.fortran_vec())); \ | |
849 data = octave_value(fill_value); \ | |
850 break; \ | |
851 } | |
852 | |
853 OV_NETCDF_INQ_VAR_FILL(NC_BYTE,octave_int8) | |
854 OV_NETCDF_INQ_VAR_FILL(NC_UBYTE,octave_uint8) | |
855 OV_NETCDF_INQ_VAR_FILL(NC_SHORT,octave_int16) | |
856 OV_NETCDF_INQ_VAR_FILL(NC_USHORT,octave_uint16) | |
857 OV_NETCDF_INQ_VAR_FILL(NC_INT,octave_int32) | |
858 OV_NETCDF_INQ_VAR_FILL(NC_UINT,octave_uint32) | |
859 OV_NETCDF_INQ_VAR_FILL(NC_INT64,octave_int64) | |
860 OV_NETCDF_INQ_VAR_FILL(NC_UINT64,octave_uint64) | |
861 | |
862 OV_NETCDF_INQ_VAR_FILL(NC_FLOAT,float) | |
863 OV_NETCDF_INQ_VAR_FILL(NC_DOUBLE,double) | |
864 | |
865 OV_NETCDF_INQ_VAR_FILL(NC_CHAR,char) | |
866 } | |
867 | |
868 //cout << "xtype3 " << xtype << " " << NC_DOUBLE << std::endl; | |
869 retval(0) = octave_value(no_fill); | |
870 retval(1) = data; | |
871 return retval; | |
872 } | |
873 | |
874 | |
875 | |
876 | |
877 //nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, | |
878 // int deflate_level); | |
879 DEFUN_DLD(netcdf_defVarDeflate, args,, | |
880 "-*- texinfo -*-\n\ | |
881 @deftypefn {Loadable Function} {} netcdf_defVarDeflate (@var{ncid},@var{varid},@var{shuffle},@var{deflate},@var{deflate_level}) \n\ | |
882 Define the compression settings NetCDF variable @var{varid}.\n\ | |
883 If @var{deflate} is true, then the variable is compressed. The compression level @var{deflate_level} is an integer between 0 (no compression) and 9 (maximum compression).\n\ | |
884 @end deftypefn\n\ | |
885 @seealso{netcdf_inqVarDeflate}\n") | |
886 { | |
887 | |
11993 | 888 if (args.length() != 5) |
889 { | |
11984 | 890 print_usage (); |
891 return octave_value(); | |
892 } | |
893 | |
894 int ncid = args(0).scalar_value(); | |
895 int varid = args(1).scalar_value(); | |
896 int shuffle = args(2).scalar_value(); // boolean | |
897 int deflate = args(3).scalar_value(); // boolean | |
898 int deflate_level = args(4).scalar_value(); | |
899 | |
11993 | 900 if (error_state) |
901 { | |
902 print_usage (); | |
903 return octave_value(); | |
904 } | |
905 | |
11984 | 906 check_err(nc_def_var_deflate (ncid, varid, shuffle, deflate, deflate_level)); |
907 return octave_value(); | |
908 } | |
909 | |
910 | |
911 //nc_inq_var_deflate(int ncid, int varid, int *shufflep, | |
912 // int *deflatep, int *deflate_levelp); | |
913 DEFUN_DLD(netcdf_inqVarDeflate, args,, | |
914 "-*- texinfo -*-\n\ | |
915 @deftypefn {Loadable Function} {[@var{shuffle},@var{deflate},@var{deflate_level}] = } netcdf_inqVarDeflate (@var{ncid},@var{varid}) \n\ | |
916 Determines the compression settings NetCDF variable @var{varid}.\n\ | |
917 If @var{deflate} is true, then the variable is compressed. The compression level @var{deflate_level} is an integer between 0 (no compression) and 9 (maximum compression).\n\ | |
918 @end deftypefn\n\ | |
919 @seealso{netcdf_defVarDeflate}\n") | |
920 { | |
921 | |
11993 | 922 if (args.length() != 2) |
923 { | |
11984 | 924 print_usage (); |
925 return octave_value(); | |
926 } | |
927 | |
928 int ncid = args(0).scalar_value(); | |
929 int varid = args(1).scalar_value(); | |
930 int shuffle, deflate, deflate_level; | |
931 octave_value_list retval; | |
932 | |
933 if (! error_state) { | |
934 int format; | |
935 check_err(nc_inq_format(ncid, &format)); | |
936 | |
937 // nc_inq_var_deflate returns garbage for classic or 64bit files | |
938 if (format == NC_FORMAT_CLASSIC || format == NC_FORMAT_64BIT) { | |
939 shuffle = 0; | |
940 deflate = 0; | |
941 deflate_level = 0; | |
942 } | |
943 else { | |
944 check_err(nc_inq_var_deflate(ncid, varid, | |
945 &shuffle,&deflate,&deflate_level)); | |
946 } | |
947 | |
948 retval(0) = octave_value(shuffle); | |
949 retval(1) = octave_value(deflate); | |
950 retval(2) = octave_value(deflate_level); | |
951 } | |
952 | |
953 return retval; | |
954 } | |
955 | |
956 //int nc_def_var_chunking(int ncid, int varid, int storage, size_t *chunksizesp); | |
957 //chunksizes can be ommited if storage is \"CONTIGUOUS\" | |
958 DEFUN_DLD(netcdf_defVarChunking, args,, | |
959 "-*- texinfo -*-\n\ | |
960 @deftypefn {Loadable Function} {} netcdf_defVarChunking (@var{ncid},@var{varid},@var{storage},@var{chunkSizes}) \n\ | |
961 Define the chunking settings of NetCDF variable @var{varid}.\n\ | |
962 If @var{storage} is the string \"chunked\", the variable is stored by chunk of the size @var{chunkSizes}.\n\ | |
963 If @var{storage} is the string \"contiguous\", the variable is stored in a contiguous way.\n\ | |
964 @end deftypefn\n\ | |
965 @seealso{netcdf_inqVarChunking}\n") | |
966 { | |
967 | |
11993 | 968 if (args.length() != 3 && args.length() != 4) |
969 { | |
11984 | 970 print_usage (); |
971 return octave_value(); | |
972 } | |
973 | |
974 int ncid = args(0).scalar_value(); | |
975 int varid = args(1).scalar_value(); | |
976 std::string storagestr = args(2).string_value(); | |
977 int storage; | |
978 | |
979 if (! error_state) { | |
980 std::transform(storagestr.begin(), storagestr.end(),storagestr.begin(), ::toupper); | |
981 | |
982 if (storagestr == "CHUNKED") { | |
983 storage = NC_CHUNKED; | |
984 } | |
985 else if (storagestr == "CONTIGUOUS") { | |
986 storage = NC_CONTIGUOUS; | |
987 } | |
988 else { | |
989 error("unknown storage %s",storagestr.c_str()); | |
990 return octave_value(); | |
991 } | |
992 | |
993 if (args.length() == 4) { | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
994 OCTAVE_LOCAL_BUFFER (size_t, chunksizes, args(3).numel()); |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
995 to_size_t_vector(args(3), args(3).numel(),chunksizes); |
11984 | 996 |
997 check_err(nc_def_var_chunking(ncid, varid, storage, chunksizes)); | |
998 } | |
999 else { | |
1000 check_err(nc_def_var_chunking(ncid, varid, storage, NULL)); | |
1001 } | |
1002 } | |
1003 | |
1004 return octave_value(); | |
1005 } | |
1006 | |
1007 //int nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp); | |
1008 DEFUN_DLD(netcdf_inqVarChunking, args,, | |
1009 "-*- texinfo -*-\n\ | |
1010 @deftypefn {Loadable Function} {[@var{storage},@var{chunkSizes}] = } netcdf_inqVarChunking (@var{ncid},@var{varid}) \n\ | |
1011 Determines the chunking settings of NetCDF variable @var{varid}.\n\ | |
1012 If @var{storage} is the string \"chunked\", the variable is stored by chunk of the size @var{chunkSizes}.\n\ | |
1013 If @var{storage} is the string \"contiguous\", the variable is stored in a contiguous way.\n\ | |
1014 @end deftypefn\n\ | |
1015 @seealso{netcdf_defVarChunking}\n") | |
1016 { | |
1017 | |
11993 | 1018 if (args.length() != 2) |
1019 { | |
11984 | 1020 print_usage (); |
1021 return octave_value(); | |
1022 } | |
1023 | |
1024 int ncid = args(0).scalar_value(); | |
1025 int varid = args(1).scalar_value(); | |
1026 int storage; | |
1027 int ndims; | |
1028 octave_value_list retval; | |
1029 | |
1030 check_err(nc_inq_varndims (ncid, varid, &ndims)); | |
1031 OCTAVE_LOCAL_BUFFER (size_t, chunksizes, ndims); | |
1032 | |
1033 if (! error_state) { | |
1034 check_err(nc_inq_var_chunking(ncid, varid, &storage, chunksizes)); | |
1035 | |
1036 if (storage == NC_CHUNKED) { | |
1037 retval(0) = octave_value("chunked"); | |
12029
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
1038 // should use uint32NDArray on 32-bit? |
21b530fbeee2
make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents:
11994
diff
changeset
|
1039 uint64NDArray chunkSizes = uint64NDArray(dim_vector(1,ndims)); |
11984 | 1040 |
1041 for (int i = 0; i < ndims; i++) | |
1042 { | |
1043 chunkSizes(ndims-i-1) = chunksizes[i]; | |
1044 } | |
1045 retval(1) = octave_value(chunkSizes); | |
1046 } | |
1047 else { | |
1048 retval(0) = octave_value("contiguous"); | |
1049 retval(1) = octave_value(Array<double>()); | |
1050 } | |
1051 | |
1052 } | |
1053 | |
1054 return retval; | |
1055 } | |
1056 | |
1057 // nc_def_var_fletcher32(int ncid, int varid, int checksum); | |
1058 DEFUN_DLD(netcdf_defVarFletcher32, args,, | |
1059 "-*- texinfo -*-\n\ | |
1060 @deftypefn {Loadable Function} {} netcdf_defVarFletcher32(@var{ncid},@var{varid},@var{checksum}) \n\ | |
11990 | 1061 Defines the checksum settings of the variable with the id @var{varid} in the data set @var{ncid}. If @var{checksum} is the string \"FLETCHER32\", then fletcher32 checksums will be turned on for this variable. If @var{checksum} is \"NOCHECKSUM\", then checksums will be disabled. \n\ |
11984 | 1062 @end deftypefn\n\ |
1063 @seealso{netcdf_defVar,netcdf_inqVarFletcher32}\n") | |
1064 { | |
1065 | |
1066 if (args.length() != 3) | |
1067 { | |
1068 print_usage (); | |
1069 return octave_value(); | |
1070 } | |
1071 | |
1072 int ncid = args(0).scalar_value(); | |
1073 int varid = args(1).scalar_value(); | |
1074 int checksum = netcdf_get_constant(args(2)).int_value(); | |
1075 | |
1076 if (error_state) | |
1077 { | |
1078 print_usage (); | |
1079 return octave_value(); | |
1080 } | |
1081 | |
1082 check_err(nc_def_var_fletcher32(ncid, varid, checksum)); | |
1083 | |
1084 return octave_value(); | |
1085 } | |
1086 | |
1087 | |
1088 | |
1089 DEFUN_DLD(netcdf_inqVarFletcher32, args,, | |
1090 "-*- texinfo -*-\n\ | |
1091 @deftypefn {Loadable Function} {@var{checksum} =} netcdf_inqVarFletcher32(@var{ncid},@var{varid}) \n\ | |
11990 | 1092 Determines the checksum settings of the variable with the id @var{varid} in the data set @var{ncid}. If fletcher32 checksums is turned on for this variable, then @var{checksum} is the string \"FLETCHER32\". Otherwise it is the string \"NOCHECKSUM\". \n\ |
11984 | 1093 @end deftypefn\n\ |
1094 @seealso{netcdf_defVar,netcdf_inqVarFletcher32}\n") | |
1095 { | |
1096 | |
1097 if (args.length() != 2) | |
1098 { | |
1099 print_usage (); | |
1100 return octave_value(); | |
1101 } | |
1102 | |
1103 int ncid = args(0).scalar_value(); | |
1104 int varid = args(1).scalar_value(); | |
1105 int checksum; | |
1106 | |
1107 if (error_state) | |
1108 { | |
1109 print_usage (); | |
1110 return octave_value(); | |
1111 } | |
1112 | |
1113 check_err(nc_inq_var_fletcher32(ncid, varid, &checksum)); | |
1114 | |
1115 if (checksum == NC_FLETCHER32) | |
1116 { | |
11990 | 1117 return octave_value("FLETCHER32"); |
11984 | 1118 } |
1119 else | |
1120 { | |
11990 | 1121 return octave_value("NOCHECKSUM"); |
11984 | 1122 } |
1123 } | |
1124 | |
1125 | |
1126 | |
1127 DEFUN_DLD(netcdf_endDef, args,, | |
1128 "-*- texinfo -*-\n\ | |
1129 @deftypefn {Loadable Function} {} netcdf_endDef (@var{ncid}) \n\ | |
1130 Leaves define-mode of NetCDF file @var{ncid}.\n\ | |
1131 @end deftypefn\n\ | |
1132 @seealso{netcdf_reDef}\n") | |
1133 { | |
1134 if (args.length() != 1) | |
1135 { | |
1136 print_usage (); | |
1137 return octave_value(); | |
1138 } | |
1139 | |
1140 int ncid = args(0).scalar_value(); | |
11993 | 1141 |
1142 if (error_state) | |
1143 { | |
1144 print_usage (); | |
1145 return octave_value(); | |
1146 } | |
1147 | |
11984 | 1148 check_err(nc_enddef (ncid)); |
1149 | |
1150 return octave_value(); | |
1151 } | |
1152 | |
1153 DEFUN_DLD(netcdf_reDef, args,, | |
1154 "-*- texinfo -*-\n\ | |
1155 @deftypefn {Loadable Function} {} netcdf_reDef (@var{ncid}) \n\ | |
1156 Enter define-mode of NetCDF file @var{ncid}.\n\ | |
1157 @end deftypefn\n\ | |
1158 @seealso{netcdf_endDef}\n") | |
1159 { | |
1160 if (args.length() != 1) | |
1161 { | |
1162 print_usage (); | |
1163 return octave_value(); | |
1164 } | |
1165 | |
1166 int ncid = args(0).scalar_value(); | |
11993 | 1167 |
1168 if (error_state) | |
1169 { | |
1170 print_usage (); | |
1171 return octave_value(); | |
1172 } | |
1173 | |
11984 | 1174 check_err(nc_redef (ncid)); |
1175 | |
1176 return octave_value(); | |
1177 } | |
1178 | |
1179 // http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-c/nc_005fput_005fvar_005f-type.html#nc_005fput_005fvar_005f-type | |
1180 | |
1181 DEFUN_DLD(netcdf_putVar, args,, | |
1182 "-*- texinfo -*-\n\ | |
1183 @deftypefn {Loadable Function} {} netcdf_putVar (@var{ncid},@var{varid},@var{data}) \n\ | |
1184 @deftypefnx {Loadable Function} {} netcdf_putVar (@var{ncid},@var{varid},@var{start},@var{data}) \n\ | |
1185 @deftypefnx {Loadable Function} {} netcdf_putVar (@var{ncid},@var{varid},@var{start},@var{count},@var{data}) \n\ | |
1186 @deftypefnx {Loadable Function} {} netcdf_putVar (@var{ncid},@var{varid},@var{start},@var{count},@var{stride},@var{data}) \n\ | |
1187 Put data in a NetCDF variable.\n\ | |
1188 The data @var{data} is stored in the variable @var{varid} of the NetCDF file @var{ncid}. \n\ | |
1189 @var{start} is the start index of each dimension (0-based and defaults to a vector of zeros), \n\ | |
1190 @var{count} is the number of elements of to be written along each dimension (default all elements)\n\ | |
1191 and @var{stride} is the sampling interval.\n\ | |
1192 @end deftypefn\n\ | |
1193 @seealso{netcdf_endDef}\n") | |
1194 { | |
1195 if (args.length() < 3 || args.length() > 6) | |
1196 { | |
1197 print_usage (); | |
1198 return octave_value(); | |
1199 } | |
1200 | |
1201 int ncid = args(0).scalar_value(); | |
1202 int varid = args(1).scalar_value (); | |
1203 octave_value data = args(args.length()-1); | |
1204 | |
11993 | 1205 if (error_state) |
1206 { | |
1207 print_usage (); | |
1208 return octave_value(); | |
1209 } | |
1210 | |
11994 | 1211 int ndims; |
1212 check_err(nc_inq_varndims (ncid, varid, &ndims)); | |
1213 | |
1214 OCTAVE_LOCAL_BUFFER (size_t, start, ndims); | |
1215 OCTAVE_LOCAL_BUFFER (size_t, count, ndims); | |
1216 OCTAVE_LOCAL_BUFFER (ptrdiff_t, stride, ndims); | |
1217 | |
1218 nc_type xtype; | |
1219 | |
1220 | |
11984 | 1221 check_err(nc_inq_vartype (ncid, varid, &xtype)); |
1222 //int sliced_numel = tmp.numel(); | |
1223 | |
11993 | 1224 if (error_state) |
1225 { | |
1226 return octave_value(); | |
1227 } | |
1228 | |
11994 | 1229 start_count_stride(ncid, varid, args, args.length()-1, ndims, start, count, stride); |
11984 | 1230 |
1231 // check if count matched size(data) | |
1232 | |
1233 switch (xtype) | |
1234 { | |
1235 #define OV_NETCDF_PUT_VAR(netcdf_type,c_type,method) \ | |
1236 case netcdf_type: \ | |
1237 { \ | |
1238 check_err(nc_put_vars (ncid, varid, start, count, stride, (c_type*)data.method().fortran_vec())); \ | |
1239 break; \ | |
1240 } | |
1241 | |
1242 OV_NETCDF_PUT_VAR(NC_BYTE, signed char, int8_array_value) | |
1243 OV_NETCDF_PUT_VAR(NC_UBYTE, unsigned char, uint8_array_value) | |
1244 OV_NETCDF_PUT_VAR(NC_SHORT, short, int16_array_value) | |
1245 OV_NETCDF_PUT_VAR(NC_USHORT, unsigned short, uint16_array_value) | |
1246 OV_NETCDF_PUT_VAR(NC_INT, int, int32_array_value) | |
1247 OV_NETCDF_PUT_VAR(NC_UINT, unsigned int, uint32_array_value) | |
1248 OV_NETCDF_PUT_VAR(NC_INT64, long long, int64_array_value) | |
1249 OV_NETCDF_PUT_VAR(NC_UINT64, unsigned long long, uint64_array_value) | |
1250 | |
1251 OV_NETCDF_PUT_VAR(NC_FLOAT, float, float_array_value) | |
1252 OV_NETCDF_PUT_VAR(NC_DOUBLE,double,array_value) | |
1253 | |
1254 OV_NETCDF_PUT_VAR(NC_CHAR, char, char_array_value) | |
1255 default: | |
1256 { | |
1257 error("unknown type %d" ,xtype); | |
1258 } | |
1259 } | |
1260 return octave_value(); | |
1261 } | |
1262 | |
1263 | |
1264 | |
1265 DEFUN_DLD(netcdf_getVar, args,, | |
1266 "-*- texinfo -*-\n\ | |
1267 @deftypefn {Loadable Function} {@var{data} =} netcdf_getVar (@var{ncid},@var{varid}) \n\ | |
1268 @deftypefnx {Loadable Function} {@var{data} =} netcdf_getVar (@var{ncid},@var{varid},@var{start}) \n\ | |
1269 @deftypefnx {Loadable Function} {@var{data} =} netcdf_getVar (@var{ncid},@var{varid},@var{start},@var{count}) \n\ | |
1270 @deftypefnx {Loadable Function} {@var{data} =} netcdf_getVar (@var{ncid},@var{varid},@var{start},@var{count},@var{stride}) \n\ | |
1271 Get the data from a NetCDF variable.\n\ | |
1272 The data @var{data} is loaded from the variable @var{varid} of the NetCDF file @var{ncid}. \n\ | |
1273 @var{start} is the start index of each dimension (0-based and defaults to a vector of zeros), \n\ | |
1274 @var{count} is the number of elements of to be written along each dimension (default all elements)\n\ | |
1275 and @var{stride} is the sampling interval.\n\ | |
1276 @end deftypefn\n\ | |
1277 @seealso{netcdf_putVar}\n") | |
1278 { | |
1279 if (args.length() < 2 || args.length() > 5) | |
1280 { | |
1281 print_usage (); | |
1282 return octave_value(); | |
1283 } | |
1284 | |
1285 int ncid = args(0).scalar_value(); | |
1286 int varid = args(1).scalar_value (); | |
1287 std::list<Range> ranges; | |
1288 int ndims; | |
1289 octave_value data; | |
1290 nc_type xtype; | |
1291 | |
11993 | 1292 if (error_state) |
1293 { | |
1294 print_usage (); | |
1295 return octave_value(); | |
1296 } | |
1297 | |
11984 | 1298 check_err(nc_inq_vartype (ncid, varid, &xtype)); |
11993 | 1299 |
1300 if (error_state) | |
1301 { | |
1302 return octave_value(); | |
1303 } | |
1304 | |
11984 | 1305 check_err(nc_inq_varndims (ncid, varid, &ndims)); |
11993 | 1306 |
12498 | 1307 //std::cout << "ndims " << ndims << std::endl; |
1308 | |
11993 | 1309 if (error_state) |
1310 { | |
1311 return octave_value(); | |
1312 } | |
1313 | |
11994 | 1314 OCTAVE_LOCAL_BUFFER (size_t, start, ndims); |
1315 OCTAVE_LOCAL_BUFFER (size_t, count, ndims); | |
1316 OCTAVE_LOCAL_BUFFER (ptrdiff_t, stride, ndims); | |
1317 | |
11984 | 1318 int sz = 1; |
1319 | |
1320 dim_vector sliced_dim_vector; | |
1321 | |
1322 if (ndims < 2) | |
1323 { | |
1324 sliced_dim_vector.resize(2); | |
1325 sliced_dim_vector(0) = 1; | |
1326 sliced_dim_vector(1) = 1; | |
1327 } | |
1328 else | |
1329 { | |
1330 sliced_dim_vector.resize(ndims); | |
1331 } | |
1332 | |
11994 | 1333 start_count_stride(ncid, varid, args, args.length(), ndims, start, count, stride); |
12498 | 1334 // std::cout << "count " << count[0] << std::endl; |
1335 // std::cout << "start " << start[0] << std::endl; | |
1336 // std::cout << "stide " << stride[0] << std::endl; | |
11984 | 1337 |
1338 if (error_state) | |
1339 { | |
1340 print_usage (); | |
1341 return octave_value(); | |
1342 } | |
1343 | |
1344 | |
1345 // total size sz | |
1346 for (int i=0; i<ndims; i++) { | |
1347 sz = sz * count[i]; | |
1348 sliced_dim_vector(i) = count[ndims-i-1]; | |
1349 //sliced_dim_vector(i) = count[i]; | |
1350 } | |
1351 | |
12498 | 1352 // std::cout << "sz " << sz << std::endl; |
1353 // std::cout << "sliced_dim_vector " << sliced_dim_vector(0) << " x " << sliced_dim_vector(1) << std::endl; | |
11984 | 1354 |
12498 | 1355 // Array < float > arr = Array < float >(sliced_dim_vector); |
1356 // float* time; | |
1357 // time = (float*)malloc(10 * sizeof(float)); | |
1358 // check_err(nc_get_vars(ncid, varid, start, count, stride, time)); | |
1359 // data = octave_value(arr); | |
1360 // return data; | |
1361 | |
11984 | 1362 switch (xtype) |
1363 { | |
12498 | 1364 #define OV_NETCDF_GET_VAR_CASE(netcdf_type,c_type) \ |
1365 case netcdf_type: \ | |
1366 { \ | |
1367 Array < c_type > arr = Array < c_type >(sliced_dim_vector); \ | |
1368 /* necessary for netcdf 4.1.3 */ \ | |
1369 if (sz > 0) { \ | |
1370 check_err(nc_get_vars(ncid, varid, start, count, stride, arr.fortran_vec())); \ | |
1371 } \ | |
1372 data = octave_value(arr); \ | |
1373 break; \ | |
11984 | 1374 } |
1375 | |
1376 OV_NETCDF_GET_VAR_CASE(NC_BYTE,octave_int8) | |
1377 OV_NETCDF_GET_VAR_CASE(NC_UBYTE,octave_uint8) | |
1378 OV_NETCDF_GET_VAR_CASE(NC_SHORT,octave_int16) | |
1379 OV_NETCDF_GET_VAR_CASE(NC_USHORT,octave_uint16) | |
1380 OV_NETCDF_GET_VAR_CASE(NC_INT,octave_int32) | |
1381 OV_NETCDF_GET_VAR_CASE(NC_UINT,octave_uint32) | |
1382 OV_NETCDF_GET_VAR_CASE(NC_INT64,octave_int64) | |
1383 OV_NETCDF_GET_VAR_CASE(NC_UINT64,octave_uint64) | |
1384 | |
1385 OV_NETCDF_GET_VAR_CASE(NC_FLOAT,float) | |
1386 OV_NETCDF_GET_VAR_CASE(NC_DOUBLE,double) | |
1387 | |
1388 OV_NETCDF_GET_VAR_CASE(NC_CHAR, char) | |
1389 | |
1390 default: | |
1391 { | |
1392 error("unknown type %d" ,xtype); | |
1393 } | |
1394 | |
1395 } | |
1396 | |
1397 return data; | |
1398 } | |
1399 | |
1400 DEFUN_DLD(netcdf_close, args,, | |
1401 "-*- texinfo -*-\n\ | |
1402 @deftypefn {Loadable Function} {} netcdf_close(@var{ncid}) \n\ | |
1403 Close the NetCDF file with the id @var{ncid}.\n\ | |
1404 @end deftypefn\n\ | |
1405 @seealso{netcdf_open}\n") | |
1406 { | |
1407 | |
11993 | 1408 if (args.length() != 1) |
1409 { | |
11984 | 1410 print_usage (); |
1411 return octave_value(); | |
1412 } | |
1413 | |
1414 int ncid = args(0).scalar_value(); | |
11993 | 1415 |
1416 if (error_state) | |
1417 { | |
1418 print_usage (); | |
1419 return octave_value(); | |
1420 } | |
1421 | |
11984 | 1422 check_err(nc_close(ncid)); |
1423 return octave_value (); | |
1424 } | |
1425 | |
1426 | |
1427 | |
1428 // int nc_inq_attname(int ncid, int varid, int attnum, char *name); | |
1429 | |
1430 DEFUN_DLD(netcdf_inqAttName, args,, | |
1431 "-*- texinfo -*-\n\ | |
1432 @deftypefn {Loadable Function} {@var{name} =} netcdf_inqAttName (@var{ncid},@var{varid},@var{attnum}) \n\ | |
1433 Get the name of a NetCDF attribute.\n\ | |
1434 This function returns the name of the attribute with the id @var{attnum} of the variable \n\ | |
1435 @var{varid} in the NetCDF file @var{ncid}. For global attributes @var{varid} can be \n\ | |
1436 netcdf_getConstant(\"global\").\n\ | |
1437 @seealso{netcdf_inqAttName}\n\ | |
1438 @end deftypefn") | |
1439 { | |
1440 if (args.length() != 3) { | |
1441 print_usage (); | |
1442 return octave_value(); | |
1443 } | |
1444 | |
1445 int ncid = args(0).scalar_value(); | |
1446 int varid = args(1).scalar_value(); | |
1447 int attnum = args(2).scalar_value(); | |
1448 char name[NC_MAX_NAME+1]; | |
1449 | |
11993 | 1450 if (error_state) |
1451 { | |
1452 print_usage (); | |
1453 return octave_value(); | |
1454 } | |
1455 | |
11984 | 1456 check_err(nc_inq_attname(ncid, varid, attnum, name)); |
1457 | |
1458 return octave_value(std::string(name)); | |
1459 } | |
1460 | |
1461 | |
1462 DEFUN_DLD(netcdf_inqAttID, args,, | |
1463 "-*- texinfo -*-\n\ | |
1464 @deftypefn {Loadable Function} {@var{attnum} =} netcdf_inqAttID(@var{ncid},@var{varid},@var{attname}) \n\ | |
1465 Return the attribute id @var{attnum} of the attribute named @var{attname} of the variable @var{varid} in the dataset @var{ncid}. \n\ | |
1466 For global attributes @var{varid} can be \n\ | |
1467 netcdf_getConstant(\"global\").\n\ | |
1468 @seealso{netcdf_inqAttName}\n\ | |
1469 @end deftypefn") | |
1470 { | |
1471 if (args.length() != 3) | |
1472 { | |
1473 print_usage (); | |
1474 return octave_value (); | |
1475 } | |
1476 int ncid = args(0).scalar_value(); | |
1477 int varid = args(1).scalar_value(); | |
1478 std::string attname = args(2).string_value(); | |
1479 int attnum; | |
1480 | |
1481 if (error_state) | |
1482 { | |
1483 print_usage (); | |
1484 return octave_value (); | |
1485 } | |
1486 | |
1487 check_err (nc_inq_attid (ncid, varid, attname.c_str(), &attnum)); | |
1488 | |
1489 return octave_value(attnum); | |
1490 } | |
1491 | |
1492 | |
1493 //int nc_inq_att (int ncid, int varid, const char *name, | |
1494 // nc_type *xtypep, size_t *lenp); | |
1495 | |
1496 DEFUN_DLD(netcdf_inqAtt, args,, | |
1497 "-*- texinfo -*-\n\ | |
1498 @deftypefn {Loadable Function} {[@var{xtype},@var{len}] = } netcdf_inqAtt(@var{ncid},@var{varid},@var{name}) \n\ | |
1499 Get attribute type and length.\n\ | |
1500 @seealso{netcdf_inqAttName}\n\ | |
1501 @end deftypefn") | |
1502 { | |
11993 | 1503 if (args.length() != 3) |
1504 { | |
1505 print_usage (); | |
1506 return octave_value(); | |
1507 } | |
11984 | 1508 |
1509 int ncid = args(0).scalar_value(); | |
1510 int varid = args(1).scalar_value(); | |
1511 std::string name = args(2).string_value(); | |
1512 int xtype; | |
1513 size_t len; | |
1514 octave_value_list retval; | |
11993 | 1515 |
1516 if (error_state) | |
1517 { | |
1518 print_usage (); | |
1519 return octave_value(); | |
1520 } | |
11984 | 1521 |
1522 check_err(nc_inq_att(ncid, varid, name.c_str(), &xtype, &len)); | |
1523 | |
1524 retval(0) = octave_value(xtype); | |
1525 retval(1) = octave_value(len); | |
1526 return retval; | |
1527 } | |
1528 | |
1529 | |
1530 DEFUN_DLD(netcdf_getAtt, args,, | |
1531 "-*- texinfo -*-\n\ | |
1532 @deftypefn {Loadable Function} {@var{data} =} netcdf_getAtt (@var{ncid},@var{varid},@var{name}) \n\ | |
1533 Get the value of a NetCDF attribute.\n\ | |
1534 This function returns the value of the attribute called @var{name} of the variable \n\ | |
1535 @var{varid} in the NetCDF file @var{ncid}. For global attributes @var{varid} can be \n\ | |
1536 netcdf_getConstant(\"global\").\n\ | |
1537 @seealso{netcdf_putAtt}\n\ | |
1538 @end deftypefn") | |
1539 { | |
11993 | 1540 if (args.length() != 3) |
1541 { | |
1542 print_usage (); | |
1543 return octave_value(); | |
1544 } | |
11984 | 1545 |
1546 int ncid = args(0).scalar_value(); | |
1547 int varid = args(1).scalar_value(); | |
1548 std::string attname = args(2).string_value(); | |
1549 nc_type xtype; | |
1550 size_t len; | |
1551 octave_value data; | |
1552 | |
11993 | 1553 if (error_state) |
1554 { | |
1555 print_usage (); | |
1556 return octave_value(); | |
1557 } | |
1558 | |
11984 | 1559 check_err(nc_inq_att(ncid, varid, attname.c_str(), &xtype, &len)); |
1560 | |
11993 | 1561 if (error_state) |
1562 { | |
1563 return octave_value(); | |
1564 } | |
1565 | |
11984 | 1566 #define OV_NETCDF_GET_ATT_CASE(netcdf_type,c_type) \ |
1567 if (xtype == netcdf_type) \ | |
1568 { \ | |
1569 Array< c_type > arr = Array< c_type >(dim_vector(1,len)); \ | |
1570 check_err(nc_get_att(ncid, varid, attname.c_str(), arr.fortran_vec())); \ | |
1571 data = octave_value(arr); \ | |
1572 } | |
1573 OV_NETCDF_GET_ATT_CASE(NC_BYTE,octave_int8) | |
1574 OV_NETCDF_GET_ATT_CASE(NC_UBYTE,octave_uint8) | |
1575 OV_NETCDF_GET_ATT_CASE(NC_SHORT,octave_int16) | |
1576 OV_NETCDF_GET_ATT_CASE(NC_USHORT,octave_uint16) | |
1577 OV_NETCDF_GET_ATT_CASE(NC_INT,octave_int32) | |
1578 OV_NETCDF_GET_ATT_CASE(NC_UINT,octave_uint32) | |
1579 OV_NETCDF_GET_ATT_CASE(NC_INT64,octave_int64) | |
1580 OV_NETCDF_GET_ATT_CASE(NC_UINT64,octave_uint64) | |
1581 | |
1582 OV_NETCDF_GET_ATT_CASE(NC_FLOAT,float) | |
1583 OV_NETCDF_GET_ATT_CASE(NC_DOUBLE,double) | |
1584 | |
1585 OV_NETCDF_GET_ATT_CASE(NC_CHAR, char) | |
1586 | |
1587 | |
1588 return data; | |
1589 } | |
1590 | |
1591 | |
1592 DEFUN_DLD(netcdf_putAtt, args,, | |
1593 "-*- texinfo -*-\n\ | |
1594 @deftypefn {Loadable Function} {} netcdf_putAtt (@var{ncid},@var{varid},@var{name},@var{data}) \n\ | |
1595 Defines a NetCDF attribute.\n\ | |
1596 This function defines the attribute called @var{name} of the variable \n\ | |
1597 @var{varid} in the NetCDF file @var{ncid}. The value of the attribute will be @var{data}. \n\ | |
1598 For global attributes @var{varid} can be \n\ | |
1599 netcdf_getConstant(\"global\").\n\ | |
1600 @seealso{netcdf_getAtt}\n\ | |
1601 @end deftypefn") | |
1602 { | |
11993 | 1603 if (args.length() != 4) |
1604 { | |
1605 print_usage (); | |
1606 return octave_value(); | |
1607 } | |
11984 | 1608 |
1609 int ncid = args(0).scalar_value(); | |
1610 int varid = args(1).scalar_value(); | |
1611 std::string attname = args(2).string_value(); | |
1612 octave_value data = args(3); | |
1613 | |
1614 nc_type xtype; | |
11993 | 1615 |
1616 if (error_state) | |
1617 { | |
1618 print_usage (); | |
1619 return octave_value(); | |
1620 } | |
11984 | 1621 |
1622 // get matching netcdf type | |
1623 | |
1624 if (data.is_string()) | |
1625 xtype = NC_CHAR; | |
1626 else if (data.is_int8_type()) | |
1627 xtype = NC_BYTE; | |
1628 else if (data.is_uint8_type()) | |
1629 xtype = NC_UBYTE; | |
1630 else if (data.is_int16_type()) | |
1631 xtype = NC_SHORT; | |
1632 else if (data.is_uint16_type()) | |
1633 xtype = NC_USHORT; | |
1634 else if (data.is_int32_type()) | |
1635 xtype = NC_INT; | |
1636 else if (data.is_uint32_type()) | |
1637 xtype = NC_UINT; | |
1638 else if (data.is_int64_type()) | |
1639 xtype = NC_INT64; | |
1640 else if (data.is_uint64_type()) | |
1641 xtype = NC_UINT64; | |
1642 else if (data.is_single_type()) | |
1643 xtype = NC_FLOAT; | |
1644 else | |
1645 xtype = NC_DOUBLE; | |
1646 | |
1647 //cout << "xtype " << xtype << endl; | |
1648 size_t len = data.numel(); | |
1649 | |
1650 switch (xtype) | |
1651 { | |
1652 #define OV_NETCDF_PUT_ATT(netcdf_type,c_type,method) \ | |
1653 case netcdf_type: \ | |
1654 { \ | |
1655 check_err(nc_put_att (ncid, varid, attname.c_str(), xtype, len, data.method().fortran_vec())); \ | |
1656 break; \ | |
1657 } | |
1658 | |
1659 OV_NETCDF_PUT_ATT(NC_BYTE, signed char, int8_array_value) | |
1660 OV_NETCDF_PUT_ATT(NC_UBYTE, unsigned char, uint8_array_value) | |
1661 OV_NETCDF_PUT_ATT(NC_SHORT, short, int16_array_value) | |
1662 OV_NETCDF_PUT_ATT(NC_USHORT, unsigned short, uint16_array_value) | |
1663 OV_NETCDF_PUT_ATT(NC_INT, int, int32_array_value) | |
1664 OV_NETCDF_PUT_ATT(NC_UINT, unsigned int, uint32_array_value) | |
1665 OV_NETCDF_PUT_ATT(NC_INT64, long long, int64_array_value) | |
1666 OV_NETCDF_PUT_ATT(NC_UINT64, unsigned long long, uint64_array_value) | |
1667 | |
1668 OV_NETCDF_PUT_ATT(NC_FLOAT, float, float_array_value) | |
1669 OV_NETCDF_PUT_ATT(NC_DOUBLE,double,array_value) | |
1670 | |
1671 OV_NETCDF_PUT_ATT(NC_CHAR, char, char_array_value) | |
1672 } | |
1673 | |
1674 /* check_err(nc_put_att (int ncid, int varid, const char *name, nc_type xtype, | |
1675 size_t len, const void *op));*/ | |
1676 | |
1677 return octave_value(); | |
1678 | |
1679 } | |
1680 | |
1681 | |
1682 DEFUN_DLD(netcdf_copyAtt, args,, | |
1683 "-*- texinfo -*-\n\ | |
1684 @deftypefn {Loadable Function} {} netcdf_copyAtt (@var{ncid},@var{varid},@var{name},@var{ncid_out},@var{varid_out}) \n\ | |
1685 Copies the attribute named @var{old_name} of the variable @var{varid} in the data set @var{ncid} \n\ | |
1686 to the variable @var{varid_out} in the data set @var{ncid_out}. \n\ | |
1687 To copy a global attribute use netcdf_getConstant(\"global\") for @var{varid} or @var{varid_out}.\n\ | |
1688 @seealso{netcdf_getAtt,netcdf_getConstant}\n\ | |
1689 @end deftypefn") | |
1690 { | |
1691 | |
1692 if (args.length() != 5) | |
1693 { | |
1694 print_usage (); | |
1695 return octave_value (); | |
1696 } | |
1697 | |
1698 int ncid = args(0).scalar_value(); | |
1699 int varid = args(1).scalar_value(); | |
1700 std::string name = args(2).string_value(); | |
1701 int ncid_out = args(3).scalar_value(); | |
1702 int varid_out = args(4).scalar_value(); | |
1703 | |
1704 if (error_state) | |
1705 { | |
1706 print_usage (); | |
1707 return octave_value (); | |
1708 } | |
1709 | |
1710 check_err (nc_copy_att (ncid, varid, name.c_str(), | |
1711 ncid_out, varid_out)); | |
1712 | |
1713 return octave_value (); | |
1714 } | |
1715 | |
1716 | |
1717 DEFUN_DLD(netcdf_renameAtt, args,, | |
1718 "-*- texinfo -*-\n\ | |
1719 @deftypefn {Loadable Function} {} netcdf_renameAtt(@var{ncid},@var{varid},@var{old_name},@var{new_name}) \n\ | |
1720 Renames the attribute named @var{old_name} of the variable @var{varid} in the data set @var{ncid}. @var{new_name} is the new name of the attribute.\n\ | |
1721 To rename a global attribute use netcdf_getConstant(\"global\") for @var{varid}.\n\ | |
1722 @seealso{netcdf_copyAtt,netcdf_getConstant}\n\ | |
1723 @end deftypefn") | |
1724 { | |
1725 | |
1726 if (args.length() != 4) | |
1727 { | |
1728 print_usage (); | |
1729 return octave_value (); | |
1730 } | |
1731 | |
1732 int ncid = args(0).scalar_value(); | |
1733 int varid = args(1).scalar_value(); | |
1734 std::string old_name = args(2).string_value(); | |
1735 std::string new_name = args(3).string_value(); | |
1736 | |
1737 if (error_state) | |
1738 { | |
1739 print_usage (); | |
1740 return octave_value (); | |
1741 } | |
1742 | |
1743 check_err(nc_rename_att (ncid, varid, old_name.c_str(), new_name.c_str())); | |
1744 | |
1745 return octave_value (); | |
1746 } | |
1747 | |
1748 | |
1749 DEFUN_DLD(netcdf_delAtt, args,, | |
1750 "-*- texinfo -*-\n\ | |
1751 @deftypefn {Loadable Function} {} netcdf_delAtt(@var{ncid},@var{varid},@var{name}) \n\ | |
1752 Deletes the attribute named @var{name} of the variable @var{varid} in the data set @var{ncid}. \n\ | |
1753 To delete a global attribute use netcdf_getConstant(\"global\") for @var{varid}.\n\ | |
1754 @seealso{netcdf_defAtt,netcdf_getConstant}\n\ | |
1755 @end deftypefn") | |
1756 { | |
1757 | |
1758 if (args.length() != 3) | |
1759 { | |
1760 print_usage (); | |
1761 return octave_value (); | |
1762 } | |
1763 | |
1764 int ncid = args(0).scalar_value(); | |
1765 int varid = args(1).scalar_value(); | |
1766 std::string name = args(2).string_value(); | |
1767 | |
1768 if (error_state) | |
1769 { | |
1770 print_usage (); | |
1771 return octave_value (); | |
1772 } | |
1773 | |
1774 check_err(nc_del_att (ncid, varid, name.c_str())); | |
1775 | |
1776 return octave_value (); | |
1777 } | |
1778 | |
1779 | |
1780 DEFUN_DLD(netcdf_inqVarID, args,, | |
1781 "-*- texinfo -*-\n\ | |
1782 @deftypefn {Loadable Function} {@var{varid} = } netcdf_inqVarID (@var{ncid},@var{name}) \n\ | |
1783 Return the id of a variable based on its name.\n\ | |
1784 @seealso{netcdf_defVar,netcdf_inqVarIDs}\n\ | |
1785 @end deftypefn") | |
1786 { | |
1787 | |
11993 | 1788 if (args.length() != 2) |
1789 { | |
11984 | 1790 print_usage (); |
1791 return octave_value(); | |
1792 } | |
1793 | |
1794 int ncid = args(0).scalar_value(); | |
1795 std::string varname = args(1).string_value(); | |
1796 int varid; | |
1797 | |
11993 | 1798 if (error_state) |
1799 { | |
1800 print_usage (); | |
1801 return octave_value(); | |
1802 } | |
1803 | |
11984 | 1804 check_err(nc_inq_varid(ncid,varname.c_str(), &varid)); |
1805 | |
1806 return octave_value(varid); | |
1807 } | |
1808 | |
1809 DEFUN_DLD(netcdf_inqVarIDs, args,, | |
1810 "-*- texinfo -*-\n\ | |
1811 @deftypefn {Loadable Function} {@var{varids} = } netcdf_inqVarID (@var{ncid}) \n\ | |
1812 Return all variable ids.\n\ | |
1813 This functions returns all variable ids in a NetCDF file or NetCDF group.\n\ | |
1814 @seealso{netcdf_inqVarID}\n\ | |
1815 @end deftypefn") | |
1816 { | |
1817 | |
11993 | 1818 if (args.length() != 1) |
1819 { | |
11984 | 1820 print_usage (); |
1821 return octave_value (); | |
1822 } | |
1823 | |
1824 int ncid = args(0).scalar_value(); | |
1825 int nvars; | |
1826 | |
11993 | 1827 if (error_state) |
1828 { | |
1829 print_usage (); | |
1830 return octave_value(); | |
1831 } | |
1832 | |
11984 | 1833 check_err(nc_inq_varids(ncid, &nvars, NULL)); |
11993 | 1834 |
1835 if (error_state) | |
1836 { | |
1837 return octave_value(); | |
1838 } | |
1839 | |
11984 | 1840 Array<int> varids = Array<int>(dim_vector(1,nvars)); |
1841 check_err(nc_inq_varids(ncid, &nvars, varids.fortran_vec())); | |
1842 | |
1843 return octave_value(varids); | |
1844 } | |
1845 | |
1846 DEFUN_DLD(netcdf_inqVar, args,, | |
1847 "-*- texinfo -*-\n\ | |
1848 @deftypefn {Loadable Function} {[@var{name},@var{nctype},@var{dimids},@var{nattr}] = } netcdf_inqVarID (@var{ncid},@var{varid}) \n\ | |
1849 Inquires information about a NetCDF variable.\n\ | |
1850 This functions returns the @var{name}, the NetCDF type @var{nctype}, an array of dimension ids \n\ | |
1851 @var{dimids} and the number of attributes @var{nattr} of the NetCDF variable. @var{nctype} in an \n\ | |
1852 integer corresponding NetCDF constants.\n\ | |
1853 @seealso{netcdf_inqVarID,netcdf_getConstant}\n\ | |
1854 @end deftypefn") | |
1855 { | |
1856 | |
1857 if (args.length() != 2) | |
1858 { | |
1859 print_usage (); | |
1860 return octave_value(); | |
1861 } | |
1862 | |
1863 int ncid = args(0).scalar_value(); | |
1864 int varid = args(1).scalar_value(); | |
1865 char name[NC_MAX_NAME+1]; | |
11994 | 1866 int ndims, natts; |
11984 | 1867 nc_type xtype; |
1868 octave_value_list retval; | |
1869 | |
1870 if (error_state) | |
1871 { | |
1872 print_usage (); | |
1873 return octave_value(); | |
1874 } | |
1875 | |
1876 check_err(nc_inq_varndims(ncid, varid, &ndims)); | |
11994 | 1877 OCTAVE_LOCAL_BUFFER (int, dimids, ndims); |
11984 | 1878 |
1879 if (error_state) | |
1880 { | |
1881 return octave_value(); | |
1882 } | |
1883 | |
1884 check_err(nc_inq_var(ncid, varid, name, &xtype, | |
1885 &ndims, dimids, &natts)); | |
1886 | |
1887 retval(0) = octave_value(std::string(name)); | |
1888 retval(1) = octave_value(xtype); | |
1889 | |
1890 // copy output arguments | |
1891 Array<double> dimids_ = Array<double>(dim_vector(1,ndims)); | |
1892 for (int i = 0; i < ndims; i++) | |
1893 { | |
1894 dimids_(i) = dimids[ndims-i-1]; | |
1895 } | |
1896 | |
1897 retval(2) = octave_value(dimids_); | |
1898 retval(3) = octave_value(natts); | |
1899 | |
1900 return retval; | |
1901 } | |
1902 | |
1903 | |
1904 | |
1905 DEFUN_DLD(netcdf_inqDim, args,, | |
1906 "-*- texinfo -*-\n\ | |
1907 @deftypefn {Loadable Function} {[@var{name},@var{length}] =} netcdf_inqDim(@var{ncid},@var{dimid}) \n\ | |
1908 Returns the name and length of a NetCDF dimension.\n\ | |
1909 @seealso{netcdf_inqDimID}\n\ | |
1910 @end deftypefn") | |
1911 { | |
1912 | |
11993 | 1913 if (args.length() != 2) |
1914 { | |
11984 | 1915 print_usage (); |
1916 return octave_value(); | |
1917 } | |
1918 | |
1919 int ncid = args(0).scalar_value(); | |
1920 int dimid = args(1).scalar_value(); | |
1921 octave_value_list retval; | |
1922 | |
11993 | 1923 if (! error_state) |
1924 { | |
1925 char name[NC_MAX_NAME+1]; | |
1926 size_t length; | |
1927 check_err(nc_inq_dim(ncid, dimid, name, &length)); | |
1928 | |
1929 retval(0) = octave_value(std::string(name)); | |
1930 retval(1) = octave_value(length); | |
1931 } | |
11984 | 1932 |
1933 return retval; | |
1934 } | |
1935 | |
1936 | |
1937 DEFUN_DLD(netcdf_inqDimID, args,, | |
1938 "-*- texinfo -*-\n\ | |
1939 @deftypefn {Loadable Function} {@var{dimid} =} netcdf_inqDimID(@var{ncid},@var{dimname}) \n\ | |
1940 Return the id of a NetCDF dimension.\n\ | |
1941 @seealso{netcdf_inqDim}\n\ | |
1942 @end deftypefn") | |
1943 { | |
1944 | |
11993 | 1945 if (args.length() != 2) |
1946 { | |
11984 | 1947 print_usage (); |
1948 return octave_value(); | |
1949 } | |
1950 | |
1951 int ncid = args(0).scalar_value(); | |
1952 std::string dimname = args(1).string_value(); | |
1953 int id; | |
1954 octave_value_list retval; | |
1955 | |
11993 | 1956 if (! error_state) |
1957 { | |
1958 check_err(nc_inq_dimid(ncid, dimname.c_str(), &id)); | |
1959 retval(0) = octave_value(id); | |
1960 } | |
11984 | 1961 |
1962 return retval; | |
1963 } | |
1964 | |
1965 // int nc_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents); | |
1966 DEFUN_DLD(netcdf_inqDimIDs, args,, | |
1967 "-*- texinfo -*-\n\ | |
1968 @deftypefn {Loadable Function} {@var{dimids} =} netcdf_inqDimID(@var{ncid}) \n\ | |
1969 @deftypefnx {Loadable Function} {@var{dimids} =} netcdf_inqDimID(@var{ncid},@var{include_parents}) \n\ | |
1970 Return the dimension ids defined in a NetCDF file.\n\ | |
1971 If @var{include_parents} is 1, the dimension ids of the parent group are also returned.\n\ | |
1972 Per default this is not the case (@var{include_parents} is 0).\n\ | |
1973 @seealso{netcdf_inqDim}\n\ | |
1974 @end deftypefn") | |
1975 { | |
11993 | 1976 if (args.length() != 1 && args.length() != 2) |
1977 { | |
11984 | 1978 print_usage (); |
1979 return octave_value(); | |
1980 } | |
1981 | |
1982 int ncid = args(0).scalar_value(); | |
1983 int include_parents = 0; | |
11993 | 1984 if (args.length() == 2) |
1985 { | |
1986 include_parents = args(0).scalar_value(); | |
1987 } | |
1988 | |
1989 if (error_state) | |
1990 { | |
1991 print_usage (); | |
1992 return octave_value(); | |
1993 } | |
11984 | 1994 |
1995 int ndims; | |
1996 check_err(nc_inq_ndims(ncid, &ndims)); | |
1997 Array<int> dimids = Array<int>(dim_vector(1,ndims)); | |
1998 check_err(nc_inq_dimids(ncid, &ndims, dimids.fortran_vec(),include_parents)); | |
1999 | |
2000 return octave_value(dimids); | |
2001 } | |
2002 | |
2003 | |
2004 | |
2005 // groups | |
2006 | |
2007 //int nc_def_grp(int parent_ncid, const char *name, int *new_ncid); | |
2008 | |
2009 DEFUN_DLD(netcdf_defGrp, args,, | |
2010 "-*- texinfo -*-\n\ | |
2011 @deftypefn {Loadable Function} {@var{new_ncid} =} netcdf_defGrp(@var{ncid},@var{name}) \n\ | |
2012 Define a group in a NetCDF file.\n\ | |
2013 @seealso{netcdf_inqGrps}\n\ | |
2014 @end deftypefn") | |
2015 { | |
2016 | |
11993 | 2017 if (args.length() != 2) |
2018 { | |
11984 | 2019 print_usage (); |
2020 return octave_value(); | |
2021 } | |
2022 | |
2023 int parent_ncid = args(0).scalar_value(); | |
2024 std::string name = args(1).string_value(); | |
2025 int new_ncid; | |
2026 | |
11993 | 2027 if (error_state) |
2028 { | |
2029 print_usage (); | |
2030 return octave_value(); | |
2031 } | |
2032 | |
11984 | 2033 check_err(nc_def_grp(parent_ncid, name.c_str(), &new_ncid)); |
2034 return octave_value(new_ncid); | |
2035 } | |
2036 | |
2037 | |
2038 // int nc_inq_grps(int ncid, int *numgrps, int *ncids); | |
2039 DEFUN_DLD(netcdf_inqGrps, args,, | |
2040 "-*- texinfo -*-\n\ | |
2041 @deftypefn {Loadable Function} {@var{ncids} =} netcdf_inqGrps(@var{ncid}) \n\ | |
2042 Return all groups ids in a NetCDF file.\n\ | |
2043 @seealso{netcdf_inqGrps}\n\ | |
2044 @end deftypefn") | |
2045 { | |
11993 | 2046 if (args.length() != 1) |
2047 { | |
11984 | 2048 print_usage (); |
2049 return octave_value(); | |
2050 } | |
2051 | |
2052 int ncid = args(0).scalar_value(); | |
2053 int numgrps; | |
2054 | |
11993 | 2055 if (error_state) |
2056 { | |
2057 print_usage (); | |
2058 return octave_value(); | |
2059 } | |
2060 | |
11984 | 2061 check_err(nc_inq_grps(ncid, &numgrps, NULL)); |
11993 | 2062 |
2063 if (error_state) | |
2064 { | |
2065 return octave_value(); | |
2066 } | |
2067 | |
11984 | 2068 Array<int> ncids = Array<int>(dim_vector(1,numgrps)); |
2069 check_err(nc_inq_grps(ncid, NULL, ncids.fortran_vec())); | |
2070 | |
2071 return octave_value(ncids); | |
2072 } | |
2073 | |
2074 //int nc_inq_grpname(int ncid, char *name); | |
2075 DEFUN_DLD(netcdf_inqGrpName, args,, | |
2076 "-*- texinfo -*-\n\ | |
2077 @deftypefn {Loadable Function} {@var{name} =} netcdf_inqGrpName(@var{ncid}) \n\ | |
2078 Return group name in a NetCDF file.\n\ | |
2079 @seealso{netcdf_inqGrps}\n\ | |
2080 @end deftypefn") | |
2081 { | |
11993 | 2082 if (args.length() != 1) |
2083 { | |
11984 | 2084 print_usage (); |
2085 return octave_value(); | |
2086 } | |
2087 | |
2088 int ncid = args(0).scalar_value(); | |
2089 char name[NC_MAX_NAME+1]; | |
2090 | |
11993 | 2091 if (error_state) |
2092 { | |
2093 print_usage (); | |
2094 return octave_value(); | |
2095 } | |
2096 | |
11984 | 2097 check_err(nc_inq_grpname(ncid, name)); |
11993 | 2098 |
2099 if (error_state) | |
2100 { | |
2101 return octave_value(); | |
2102 } | |
2103 | |
11984 | 2104 return octave_value(std::string(name)); |
2105 } | |
2106 | |
2107 //int nc_inq_grpname_full(int ncid, size_t *lenp, char *full_name); | |
2108 DEFUN_DLD(netcdf_inqGrpNameFull, args,, | |
2109 "-*- texinfo -*-\n\ | |
2110 @deftypefn {Loadable Function} {@var{name} =} netcdf_inqGrpNameFull(@var{ncid}) \n\ | |
2111 Return full name of group in NetCDF file.\n\ | |
2112 @seealso{netcdf_inqGrpName}\n\ | |
2113 @end deftypefn") | |
2114 { | |
11993 | 2115 if (args.length() != 1) |
2116 { | |
11984 | 2117 print_usage (); |
2118 return octave_value(); | |
2119 } | |
2120 | |
2121 int ncid = args(0).scalar_value(); | |
2122 size_t len; | |
11993 | 2123 |
2124 if (error_state) | |
2125 { | |
2126 print_usage (); | |
2127 return octave_value(); | |
2128 } | |
2129 | |
11984 | 2130 check_err(nc_inq_grpname_len(ncid,&len)); |
11993 | 2131 |
2132 if (error_state) | |
2133 { | |
2134 return octave_value(); | |
2135 } | |
2136 | |
11984 | 2137 char* name = new char[len+1]; |
2138 octave_value retval; | |
11993 | 2139 check_err(nc_inq_grpname_full(ncid, &len, name)); |
11984 | 2140 |
11993 | 2141 if (error_state) |
2142 { | |
12707 | 2143 delete[] name; |
11993 | 2144 return octave_value(); |
2145 } | |
2146 | |
11984 | 2147 retval = octave_value(std::string(name)); |
12707 | 2148 delete[] name; |
11984 | 2149 return retval; |
2150 } | |
2151 | |
2152 // int nc_inq_grp_parent(int ncid, int *parent_ncid); | |
2153 DEFUN_DLD(netcdf_inqGrpParent, args,, | |
2154 "-*- texinfo -*-\n\ | |
2155 @deftypefn {Loadable Function} {@var{parent_ncid} =} netcdf_inqGrpParent(@var{ncid}) \n\ | |
2156 Return id of the parent group\n\ | |
2157 @seealso{netcdf_inqGrpName}\n\ | |
2158 @end deftypefn") | |
2159 { | |
11993 | 2160 if (args.length() != 1) |
2161 { | |
11984 | 2162 print_usage (); |
2163 return octave_value(); | |
2164 } | |
2165 | |
2166 int ncid = args(0).scalar_value(); | |
2167 int parent_ncid; | |
2168 | |
11993 | 2169 if (error_state) |
2170 { | |
2171 print_usage (); | |
2172 return octave_value(); | |
2173 } | |
2174 | |
11984 | 2175 check_err(nc_inq_grp_parent(ncid, &parent_ncid)); |
2176 return octave_value(parent_ncid); | |
2177 } | |
2178 | |
2179 // int nc_inq_grp_full_ncid(int ncid, char *full_name, int *grp_ncid); | |
2180 DEFUN_DLD(netcdf_inqGrpFullNcid, args,, | |
2181 "-*- texinfo -*-\n\ | |
2182 @deftypefn {Loadable Function} {@var{grp_ncid} =} netcdf_inqGrpFullNcid(@var{ncid},@var{name}) \n\ | |
2183 Return the group id based on the full group name.\n\ | |
2184 @seealso{netcdf_inqGrpName}\n\ | |
2185 @end deftypefn") | |
2186 { | |
11993 | 2187 if (args.length() != 2) |
2188 { | |
11984 | 2189 print_usage (); |
2190 return octave_value(); | |
2191 } | |
2192 | |
2193 int ncid = args(0).scalar_value(); | |
2194 std::string name = args(1).string_value(); | |
2195 int grp_ncid; | |
2196 | |
11993 | 2197 if (error_state) |
2198 { | |
2199 print_usage (); | |
2200 return octave_value(); | |
2201 } | |
2202 | |
11984 | 2203 int format; |
2204 check_err(nc_inq_format(ncid, &format)); | |
2205 | |
2206 if (error_state) | |
2207 { | |
2208 return octave_value(); | |
2209 } | |
2210 | |
2211 if (format == NC_FORMAT_CLASSIC || format == NC_FORMAT_64BIT) | |
2212 { | |
2213 if (name == "/") | |
2214 { | |
2215 return octave_value(ncid); | |
2216 } | |
2217 else | |
2218 { | |
2219 error("groups are not supported in this format"); | |
2220 return octave_value(); | |
2221 } | |
2222 } | |
2223 | |
2224 // nc_inq_grp_full_ncid makes a segmentation fault if | |
2225 // file is in non-HDF5 format | |
2226 check_err(nc_inq_grp_full_ncid(ncid, name.c_str(),&grp_ncid)); | |
2227 return octave_value(grp_ncid); | |
2228 } | |
2229 | |
2230 | |
2231 | |
2232 // int nc_inq_ncid(int ncid, const char *name, int *grp_ncid); | |
2233 DEFUN_DLD(netcdf_inqNcid, args,, | |
2234 "-*- texinfo -*-\n\ | |
2235 @deftypefn {Loadable Function} {@var{grp_ncid} =} netcdf_inqNcid(@var{ncid},@var{name}) \n\ | |
2236 Return group id based on its name\n\ | |
2237 @seealso{netcdf_inqGrpFullNcid}\n\ | |
2238 @end deftypefn") | |
2239 { | |
11993 | 2240 if (args.length() != 2) |
2241 { | |
11984 | 2242 print_usage (); |
2243 return octave_value(); | |
2244 } | |
2245 | |
2246 int ncid = args(0).scalar_value(); | |
2247 std::string name = args(1).string_value(); | |
2248 int grp_ncid; | |
2249 | |
11993 | 2250 if (error_state) |
2251 { | |
2252 print_usage (); | |
2253 return octave_value(); | |
2254 } | |
2255 | |
11984 | 2256 check_err(nc_inq_ncid(ncid, name.c_str(), &grp_ncid)); |
2257 return octave_value(grp_ncid); | |
2258 } |