1 | /********************************************************************* |
---|
2 | Copyright 2010, UCAR/Unidata See netcdf/COPYRIGHT file for |
---|
3 | copying and redistribution conditions. |
---|
4 | |
---|
5 | $Id: nc3dispatch.c,v 2.8 2010/05/26 11:11:26 ed Exp $ |
---|
6 | *********************************************************************/ |
---|
7 | |
---|
8 | #include "config.h" |
---|
9 | #include <stdlib.h> |
---|
10 | #include <string.h> |
---|
11 | |
---|
12 | #include "netcdf.h" |
---|
13 | #include "nc.h" |
---|
14 | #include "nc3dispatch.h" |
---|
15 | |
---|
16 | #ifndef NC_CONTIGUOUS |
---|
17 | #define NC_CONTIGUOUS 1 |
---|
18 | #endif |
---|
19 | |
---|
20 | #ifndef NC_ENOTNC4 |
---|
21 | #define NC_ENOTNC4 (-111) |
---|
22 | #endif |
---|
23 | |
---|
24 | #ifndef NC_ENOGRP |
---|
25 | #define NC_ENOGRP (-125) |
---|
26 | #endif |
---|
27 | |
---|
28 | #ifndef NC_STRING |
---|
29 | #define NC_STRING (12) |
---|
30 | #endif |
---|
31 | |
---|
32 | |
---|
33 | static int NC3_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, |
---|
34 | int *ndimsp, int *dimidsp, int *nattsp, |
---|
35 | int *shufflep, int *deflatep, int *deflate_levelp, |
---|
36 | int *fletcher32p, int *contiguousp, size_t *chunksizesp, |
---|
37 | int *no_fill, void *fill_valuep, int *endiannessp, |
---|
38 | int *options_maskp, int *pixels_per_blockp); |
---|
39 | |
---|
40 | #ifdef USE_NETCDF4 |
---|
41 | static int NC3_show_metadata(int); |
---|
42 | static int NC3_inq_unlimdims(int,int*,int*); |
---|
43 | static int NC3_var_par_access(int,int,int); |
---|
44 | static int NC3_inq_ncid(int,const char*,int*); |
---|
45 | static int NC3_inq_grps(int,int*,int*); |
---|
46 | static int NC3_inq_grpname(int,char*); |
---|
47 | static int NC3_inq_grpname_full(int,size_t*,char*); |
---|
48 | static int NC3_inq_grp_parent(int,int*); |
---|
49 | static int NC3_inq_grp_full_ncid(int,const char*,int*); |
---|
50 | static int NC3_inq_varids(int,int* nvars,int*); |
---|
51 | static int NC3_inq_dimids(int,int* ndims,int*,int); |
---|
52 | static int NC3_inq_typeids(int,int* ntypes,int*); |
---|
53 | static int NC3_inq_type_equal(int,nc_type,int,nc_type,int*); |
---|
54 | static int NC3_def_grp(int,const char*,int*); |
---|
55 | static int NC3_inq_user_type(int,nc_type,char*,size_t*,nc_type*,size_t*,int*); |
---|
56 | static int NC3_inq_typeid(int,const char*,nc_type*); |
---|
57 | static int NC3_def_compound(int,size_t,const char*,nc_type*); |
---|
58 | static int NC3_insert_compound(int,nc_type,const char*,size_t,nc_type); |
---|
59 | static int NC3_insert_array_compound(int,nc_type,const char*,size_t,nc_type,int,const int*); |
---|
60 | static int NC3_inq_compound_field(int,nc_type,int,char*,size_t*,nc_type*,int*,int*); |
---|
61 | static int NC3_inq_compound_fieldindex(int,nc_type,const char*,int*); |
---|
62 | static int NC3_def_vlen(int,const char*,nc_type base_typeid,nc_type*); |
---|
63 | static int NC3_put_vlen_element(int,int,void*,size_t,const void*); |
---|
64 | static int NC3_get_vlen_element(int,int,const void*,size_t*,void*); |
---|
65 | static int NC3_def_enum(int,nc_type,const char*,nc_type*); |
---|
66 | static int NC3_insert_enum(int,nc_type,const char*,const void*); |
---|
67 | static int NC3_inq_enum_member(int,nc_type,int,char*,void*); |
---|
68 | static int NC3_inq_enum_ident(int,nc_type,long long,char*); |
---|
69 | static int NC3_def_opaque(int,size_t,const char*,nc_type*); |
---|
70 | static int NC3_def_var_deflate(int,int,int,int,int); |
---|
71 | static int NC3_def_var_fletcher32(int,int,int); |
---|
72 | static int NC3_def_var_chunking(int,int,int,const size_t*); |
---|
73 | static int NC3_def_var_fill(int,int,int,const void*); |
---|
74 | static int NC3_def_var_endian(int,int,int); |
---|
75 | static int NC3_set_var_chunk_cache(int,int,size_t,size_t,float); |
---|
76 | static int NC3_get_var_chunk_cache(int,int,size_t*,size_t*,float*); |
---|
77 | #endif /*USE_NETCDF4*/ |
---|
78 | |
---|
79 | NC_Dispatch NC3_dispatcher = { |
---|
80 | |
---|
81 | NC_DISPATCH_NC3, |
---|
82 | |
---|
83 | NC3_new_nc, |
---|
84 | |
---|
85 | NC3_create, |
---|
86 | NC3_open, |
---|
87 | |
---|
88 | NC3_redef, |
---|
89 | NC3__enddef, |
---|
90 | NC3_sync, |
---|
91 | NC3_abort, |
---|
92 | NC3_close, |
---|
93 | NC3_set_fill, |
---|
94 | NC3_inq_base_pe, |
---|
95 | NC3_set_base_pe, |
---|
96 | NC3_inq_format, |
---|
97 | |
---|
98 | NC3_inq, |
---|
99 | NC3_inq_type, |
---|
100 | |
---|
101 | NC3_def_dim, |
---|
102 | NC3_inq_dimid, |
---|
103 | NC3_inq_dim, |
---|
104 | NC3_inq_unlimdim, |
---|
105 | NC3_rename_dim, |
---|
106 | |
---|
107 | NC3_inq_att, |
---|
108 | NC3_inq_attid, |
---|
109 | NC3_inq_attname, |
---|
110 | NC3_rename_att, |
---|
111 | NC3_del_att, |
---|
112 | NC3_get_att, |
---|
113 | NC3_put_att, |
---|
114 | |
---|
115 | NC3_def_var, |
---|
116 | NC3_inq_varid, |
---|
117 | NC3_rename_var, |
---|
118 | NC3_get_vara, |
---|
119 | NC3_put_vara, |
---|
120 | NCDEFAULT_get_vars, |
---|
121 | NCDEFAULT_put_vars, |
---|
122 | NCDEFAULT_get_varm, |
---|
123 | NCDEFAULT_put_varm, |
---|
124 | |
---|
125 | NC3_inq_var_all, |
---|
126 | |
---|
127 | #ifdef USE_NETCDF4 |
---|
128 | NC3_show_metadata, |
---|
129 | NC3_inq_unlimdims, |
---|
130 | NC3_var_par_access, |
---|
131 | NC3_inq_ncid, |
---|
132 | NC3_inq_grps, |
---|
133 | NC3_inq_grpname, |
---|
134 | NC3_inq_grpname_full, |
---|
135 | NC3_inq_grp_parent, |
---|
136 | NC3_inq_grp_full_ncid, |
---|
137 | NC3_inq_varids, |
---|
138 | NC3_inq_dimids, |
---|
139 | NC3_inq_typeids, |
---|
140 | NC3_inq_type_equal, |
---|
141 | NC3_def_grp, |
---|
142 | NC3_inq_user_type, |
---|
143 | NC3_inq_typeid, |
---|
144 | |
---|
145 | NC3_def_compound, |
---|
146 | NC3_insert_compound, |
---|
147 | NC3_insert_array_compound, |
---|
148 | NC3_inq_compound_field, |
---|
149 | NC3_inq_compound_fieldindex, |
---|
150 | NC3_def_vlen, |
---|
151 | NC3_put_vlen_element, |
---|
152 | NC3_get_vlen_element, |
---|
153 | NC3_def_enum, |
---|
154 | NC3_insert_enum, |
---|
155 | NC3_inq_enum_member, |
---|
156 | NC3_inq_enum_ident, |
---|
157 | NC3_def_opaque, |
---|
158 | NC3_def_var_deflate, |
---|
159 | NC3_def_var_fletcher32, |
---|
160 | NC3_def_var_chunking, |
---|
161 | NC3_def_var_fill, |
---|
162 | NC3_def_var_endian, |
---|
163 | NC3_set_var_chunk_cache, |
---|
164 | NC3_get_var_chunk_cache, |
---|
165 | |
---|
166 | #endif /*_NC4DISPATCH_H*/ |
---|
167 | |
---|
168 | }; |
---|
169 | |
---|
170 | NC_Dispatch* NC3_dispatch_table = NULL; /* moved here from ddispatch.c */ |
---|
171 | |
---|
172 | int |
---|
173 | NC3_initialize(void) |
---|
174 | { |
---|
175 | NC3_dispatch_table = &NC3_dispatcher; |
---|
176 | return NC_NOERR; |
---|
177 | } |
---|
178 | |
---|
179 | static int |
---|
180 | NC3_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, |
---|
181 | int *ndimsp, int *dimidsp, int *nattsp, |
---|
182 | int *shufflep, int *deflatep, int *deflate_levelp, |
---|
183 | int *fletcher32p, int *contiguousp, size_t *chunksizesp, |
---|
184 | int *no_fill, void *fill_valuep, int *endiannessp, |
---|
185 | int *options_maskp, int *pixels_per_blockp) |
---|
186 | { |
---|
187 | int stat = NC3_inq_var(ncid,varid,name,xtypep,ndimsp,dimidsp,nattsp); |
---|
188 | if(stat) return stat; |
---|
189 | if(shufflep) *shufflep = 0; |
---|
190 | if(deflatep) *deflatep = 0; |
---|
191 | if(fletcher32p) *fletcher32p = 0; |
---|
192 | if(contiguousp) *contiguousp = NC_CONTIGUOUS; |
---|
193 | if(no_fill) *no_fill = 1; |
---|
194 | if(endiannessp) return NC_ENOTNC4; |
---|
195 | if(options_maskp) return NC_ENOTNC4; |
---|
196 | return NC_NOERR; |
---|
197 | } |
---|
198 | |
---|
199 | #ifdef USE_NETCDF4 |
---|
200 | |
---|
201 | static int |
---|
202 | NC3_inq_unlimdims(int ncid, int *ndimsp, int *unlimdimidsp) |
---|
203 | { |
---|
204 | int retval; |
---|
205 | int unlimid; |
---|
206 | |
---|
207 | if ((retval = nc_inq_unlimdim(ncid, &unlimid))) |
---|
208 | return retval; |
---|
209 | if (unlimid != -1) { |
---|
210 | if(ndimsp) *ndimsp = 1; |
---|
211 | if (unlimdimidsp) |
---|
212 | unlimdimidsp[0] = unlimid; |
---|
213 | } else |
---|
214 | if(ndimsp) *ndimsp = 0; |
---|
215 | return NC_NOERR; |
---|
216 | } |
---|
217 | |
---|
218 | static int |
---|
219 | NC3_def_grp(int parent_ncid, const char *name, int *new_ncid) |
---|
220 | { |
---|
221 | return NC_ENOTNC4; |
---|
222 | } |
---|
223 | |
---|
224 | static int |
---|
225 | NC3_inq_ncid(int ncid, const char *name, int *grp_ncid) |
---|
226 | { |
---|
227 | if(grp_ncid) *grp_ncid = ncid; |
---|
228 | return NC_NOERR; |
---|
229 | } |
---|
230 | |
---|
231 | static int |
---|
232 | NC3_inq_grps(int ncid, int *numgrps, int *ncids) |
---|
233 | { |
---|
234 | if (numgrps) |
---|
235 | *numgrps = 0; |
---|
236 | return NC_NOERR; |
---|
237 | } |
---|
238 | |
---|
239 | static int |
---|
240 | NC3_inq_grpname(int ncid, char *name) |
---|
241 | { |
---|
242 | if (name) |
---|
243 | strcpy(name, "/"); |
---|
244 | return NC_NOERR; |
---|
245 | } |
---|
246 | |
---|
247 | static int |
---|
248 | NC3_inq_grpname_full(int ncid, size_t *lenp, char *full_name) |
---|
249 | { |
---|
250 | if (full_name) |
---|
251 | strcpy(full_name, "/"); |
---|
252 | if(lenp) *lenp = 1; |
---|
253 | return NC_NOERR; |
---|
254 | } |
---|
255 | |
---|
256 | static int |
---|
257 | NC3_inq_grp_parent(int ncid, int *parent_ncid) |
---|
258 | { |
---|
259 | return NC_ENOGRP; |
---|
260 | } |
---|
261 | |
---|
262 | static int |
---|
263 | NC3_inq_grp_full_ncid(int ncid, const char *full_name, int *grp_ncid) |
---|
264 | { |
---|
265 | return NC_ENOGRP; |
---|
266 | } |
---|
267 | |
---|
268 | static int |
---|
269 | NC3_inq_varids(int ncid, int *nvarsp, int *varids) |
---|
270 | { |
---|
271 | int retval,v,nvars; |
---|
272 | /* If this is a netcdf-3 file, there is only one group, the root |
---|
273 | group, and its vars have ids 0 thru nvars - 1. */ |
---|
274 | if ((retval = nc_inq(ncid, NULL, &nvars, NULL, NULL))) |
---|
275 | return retval; |
---|
276 | if(nvarsp) *nvarsp = nvars; |
---|
277 | if (varids) |
---|
278 | for (v = 0; v < nvars; v++) |
---|
279 | varids[v] = v; |
---|
280 | return NC_NOERR; |
---|
281 | } |
---|
282 | |
---|
283 | static int |
---|
284 | NC3_inq_dimids(int ncid, int *ndimsp, int *dimids, int include_parents) |
---|
285 | { |
---|
286 | int retval,d,ndims; |
---|
287 | /* If this is a netcdf-3 file, then the dimids are going to be 0 |
---|
288 | thru ndims-1, so just provide them. */ |
---|
289 | if ((retval = nc_inq(ncid, &ndims, NULL, NULL, NULL))) |
---|
290 | return retval; |
---|
291 | if(ndimsp) *ndimsp = ndims; |
---|
292 | if (dimids) |
---|
293 | for (d = 0; d < ndims; d++) |
---|
294 | dimids[d] = d; |
---|
295 | return NC_NOERR; |
---|
296 | } |
---|
297 | |
---|
298 | static int |
---|
299 | NC3_show_metadata(int ncid) |
---|
300 | { |
---|
301 | return NC_NOERR; |
---|
302 | } |
---|
303 | |
---|
304 | static int |
---|
305 | NC3_inq_type_equal(int ncid1, nc_type typeid1, int ncid2, nc_type typeid2, int* equalp) |
---|
306 | { |
---|
307 | /* Check input. */ |
---|
308 | if(equalp == NULL) return NC_NOERR; |
---|
309 | |
---|
310 | if (typeid1 <= NC_NAT || typeid2 <= NC_NAT) |
---|
311 | return NC_EINVAL; |
---|
312 | |
---|
313 | *equalp = 0; /* assume */ |
---|
314 | |
---|
315 | /* If one is atomic, and the other user-defined, the types are not equal */ |
---|
316 | if ((typeid1 <= NC_STRING && typeid2 > NC_STRING) || |
---|
317 | (typeid2 <= NC_STRING && typeid1 > NC_STRING)) { |
---|
318 | if (equalp) *equalp = 0; |
---|
319 | return NC_NOERR; |
---|
320 | } |
---|
321 | |
---|
322 | /* If both are atomic types, the answer is easy. */ |
---|
323 | if (typeid1 <= ATOMICTYPEMAX) { |
---|
324 | if (equalp) { |
---|
325 | if (typeid1 == typeid2) |
---|
326 | *equalp = 1; |
---|
327 | else |
---|
328 | *equalp = 0; |
---|
329 | } |
---|
330 | return NC_NOERR; |
---|
331 | } |
---|
332 | return NC_NOERR; |
---|
333 | } |
---|
334 | |
---|
335 | static int |
---|
336 | NC3_inq_typeid(int ncid, const char *name, nc_type *typeidp) |
---|
337 | { |
---|
338 | int i; |
---|
339 | for (i = 0; i <= ATOMICTYPEMAX; i++) |
---|
340 | if (!strcmp(name, NC_atomictypename(i))) { |
---|
341 | if (typeidp) *typeidp = i; |
---|
342 | return NC_NOERR; |
---|
343 | } |
---|
344 | return NC_ENOTNC4; |
---|
345 | } |
---|
346 | |
---|
347 | static int |
---|
348 | NC3_inq_typeids(int ncid, int *ntypes, int *typeids) |
---|
349 | { |
---|
350 | if(ntypes) *ntypes = 0; |
---|
351 | return NC_NOERR; |
---|
352 | } |
---|
353 | |
---|
354 | static int |
---|
355 | NC3_inq_user_type(int ncid, nc_type typeid, char *name, size_t *size, |
---|
356 | nc_type *base_nc_typep, size_t *nfieldsp, int *classp) |
---|
357 | { |
---|
358 | return NC_ENOTNC4; |
---|
359 | } |
---|
360 | |
---|
361 | static int |
---|
362 | NC3_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp) |
---|
363 | { |
---|
364 | return NC_ENOTNC4; |
---|
365 | } |
---|
366 | |
---|
367 | static int |
---|
368 | NC3_insert_compound(int ncid, nc_type typeid, const char *name, size_t offset, |
---|
369 | nc_type field_typeid) |
---|
370 | { |
---|
371 | return NC_ENOTNC4; |
---|
372 | } |
---|
373 | |
---|
374 | static int |
---|
375 | NC3_insert_array_compound(int ncid, nc_type typeid, const char *name, |
---|
376 | size_t offset, nc_type field_typeid, |
---|
377 | int ndims, const int *dim_sizes) |
---|
378 | { |
---|
379 | return NC_ENOTNC4; |
---|
380 | } |
---|
381 | |
---|
382 | |
---|
383 | static int |
---|
384 | NC3_inq_compound_field(int ncid, nc_type typeid, int fieldid, char *name, |
---|
385 | size_t *offsetp, nc_type *field_typeidp, int *ndimsp, |
---|
386 | int *dim_sizesp) |
---|
387 | { |
---|
388 | return NC_ENOTNC4; |
---|
389 | } |
---|
390 | |
---|
391 | static int |
---|
392 | NC3_inq_compound_fieldindex(int ncid, nc_type typeid, const char *name, int *fieldidp) |
---|
393 | { |
---|
394 | return NC_ENOTNC4; |
---|
395 | } |
---|
396 | |
---|
397 | static int |
---|
398 | NC3_def_opaque(int ncid, size_t datum_size, const char *name, nc_type* xtypep) |
---|
399 | { |
---|
400 | return NC_ENOTNC4; |
---|
401 | } |
---|
402 | |
---|
403 | static int |
---|
404 | NC3_def_vlen(int ncid, const char *name, nc_type base_typeid, nc_type* xtypep) |
---|
405 | { |
---|
406 | return NC_ENOTNC4; |
---|
407 | } |
---|
408 | |
---|
409 | static int |
---|
410 | NC3_def_enum(int ncid, nc_type base_typeid, const char *name, |
---|
411 | nc_type *typeidp) |
---|
412 | { |
---|
413 | return NC_ENOTNC4; |
---|
414 | } |
---|
415 | |
---|
416 | static int |
---|
417 | NC3_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier) |
---|
418 | { |
---|
419 | return NC_ENOTNC4; |
---|
420 | } |
---|
421 | |
---|
422 | static int |
---|
423 | NC3_inq_enum_member(int ncid, nc_type typeid, int idx, char *identifier, |
---|
424 | void *value) |
---|
425 | { |
---|
426 | return NC_ENOTNC4; |
---|
427 | } |
---|
428 | |
---|
429 | static int |
---|
430 | NC3_insert_enum(int ncid, nc_type typeid, const char *identifier, |
---|
431 | const void *value) |
---|
432 | { |
---|
433 | return NC_ENOTNC4; |
---|
434 | } |
---|
435 | |
---|
436 | static int |
---|
437 | NC3_put_vlen_element(int ncid, int typeid, void *vlen_element, |
---|
438 | size_t len, const void *data) |
---|
439 | { |
---|
440 | return NC_ENOTNC4; |
---|
441 | } |
---|
442 | |
---|
443 | static int |
---|
444 | NC3_get_vlen_element(int ncid, int typeid, const void *vlen_element, |
---|
445 | size_t *len, void *data) |
---|
446 | { |
---|
447 | return NC_ENOTNC4; |
---|
448 | } |
---|
449 | |
---|
450 | static int |
---|
451 | NC3_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption) |
---|
452 | { |
---|
453 | return NC_ENOTNC4; |
---|
454 | } |
---|
455 | |
---|
456 | static int |
---|
457 | NC3_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp) |
---|
458 | { |
---|
459 | return NC_ENOTNC4; |
---|
460 | } |
---|
461 | |
---|
462 | static int |
---|
463 | NC3_def_var_deflate(int ncid, int varid, int shuffle, int deflate, |
---|
464 | int deflate_level) |
---|
465 | { |
---|
466 | return NC_ENOTNC4; |
---|
467 | } |
---|
468 | |
---|
469 | static int |
---|
470 | NC3_def_var_fletcher32(int ncid, int varid, int fletcher32) |
---|
471 | { |
---|
472 | return NC_ENOTNC4; |
---|
473 | } |
---|
474 | |
---|
475 | static int |
---|
476 | NC3_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp) |
---|
477 | { |
---|
478 | return NC_ENOTNC4; |
---|
479 | } |
---|
480 | |
---|
481 | static int |
---|
482 | NC3_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value) |
---|
483 | { |
---|
484 | return NC_ENOTNC4; |
---|
485 | } |
---|
486 | |
---|
487 | static int |
---|
488 | NC3_def_var_endian(int ncid, int varid, int endianness) |
---|
489 | { |
---|
490 | return NC_ENOTNC4; |
---|
491 | } |
---|
492 | |
---|
493 | static int |
---|
494 | NC3_var_par_access(int ncid, int varid, int par_access) |
---|
495 | { |
---|
496 | return NC_ENOTNC4; |
---|
497 | } |
---|
498 | |
---|
499 | #endif /*USE_NETCDF4*/ |
---|
500 | |
---|