source: XIOS/dev/dev_cmip6_omp/extern/src_netcdf4/nc3dispatch.c @ 1606

Last change on this file since 1606 was 409, checked in by ymipsl, 11 years ago

Add improved nectdf internal library src

YM

  • Property svn:eol-style set to native
File size: 11.5 KB
Line 
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
33static 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
41static int NC3_show_metadata(int);
42static int NC3_inq_unlimdims(int,int*,int*);
43static int NC3_var_par_access(int,int,int);
44static int NC3_inq_ncid(int,const char*,int*);
45static int NC3_inq_grps(int,int*,int*);
46static int NC3_inq_grpname(int,char*);
47static int NC3_inq_grpname_full(int,size_t*,char*);
48static int NC3_inq_grp_parent(int,int*);
49static int NC3_inq_grp_full_ncid(int,const char*,int*);
50static int NC3_inq_varids(int,int* nvars,int*);
51static int NC3_inq_dimids(int,int* ndims,int*,int);
52static int NC3_inq_typeids(int,int* ntypes,int*);
53static int NC3_inq_type_equal(int,nc_type,int,nc_type,int*);
54static int NC3_def_grp(int,const char*,int*);
55static int NC3_inq_user_type(int,nc_type,char*,size_t*,nc_type*,size_t*,int*);
56static int NC3_inq_typeid(int,const char*,nc_type*);
57static int NC3_def_compound(int,size_t,const char*,nc_type*);
58static int NC3_insert_compound(int,nc_type,const char*,size_t,nc_type);
59static int NC3_insert_array_compound(int,nc_type,const char*,size_t,nc_type,int,const int*);
60static int NC3_inq_compound_field(int,nc_type,int,char*,size_t*,nc_type*,int*,int*);
61static int NC3_inq_compound_fieldindex(int,nc_type,const char*,int*);
62static int NC3_def_vlen(int,const char*,nc_type base_typeid,nc_type*);
63static int NC3_put_vlen_element(int,int,void*,size_t,const void*);
64static int NC3_get_vlen_element(int,int,const void*,size_t*,void*);
65static int NC3_def_enum(int,nc_type,const char*,nc_type*);
66static int NC3_insert_enum(int,nc_type,const char*,const void*);
67static int NC3_inq_enum_member(int,nc_type,int,char*,void*);
68static int NC3_inq_enum_ident(int,nc_type,long long,char*);
69static int NC3_def_opaque(int,size_t,const char*,nc_type*);
70static int NC3_def_var_deflate(int,int,int,int,int);
71static int NC3_def_var_fletcher32(int,int,int);
72static int NC3_def_var_chunking(int,int,int,const size_t*);
73static int NC3_def_var_fill(int,int,int,const void*);
74static int NC3_def_var_endian(int,int,int);
75static int NC3_set_var_chunk_cache(int,int,size_t,size_t,float);
76static int NC3_get_var_chunk_cache(int,int,size_t*,size_t*,float*);
77#endif /*USE_NETCDF4*/
78
79NC_Dispatch NC3_dispatcher = {
80
81NC_DISPATCH_NC3,
82
83NC3_new_nc,
84
85NC3_create,
86NC3_open,
87
88NC3_redef,
89NC3__enddef,
90NC3_sync,
91NC3_abort,
92NC3_close,
93NC3_set_fill,
94NC3_inq_base_pe,
95NC3_set_base_pe,
96NC3_inq_format,
97
98NC3_inq,
99NC3_inq_type,
100
101NC3_def_dim,
102NC3_inq_dimid,
103NC3_inq_dim,
104NC3_inq_unlimdim,
105NC3_rename_dim,
106
107NC3_inq_att,
108NC3_inq_attid,
109NC3_inq_attname,
110NC3_rename_att,
111NC3_del_att,
112NC3_get_att,
113NC3_put_att,
114
115NC3_def_var,
116NC3_inq_varid,
117NC3_rename_var,
118NC3_get_vara,
119NC3_put_vara,
120NCDEFAULT_get_vars,
121NCDEFAULT_put_vars,
122NCDEFAULT_get_varm,
123NCDEFAULT_put_varm,
124
125NC3_inq_var_all,
126
127#ifdef USE_NETCDF4
128NC3_show_metadata,
129NC3_inq_unlimdims,
130NC3_var_par_access,
131NC3_inq_ncid,
132NC3_inq_grps,
133NC3_inq_grpname,
134NC3_inq_grpname_full,
135NC3_inq_grp_parent,
136NC3_inq_grp_full_ncid,
137NC3_inq_varids,
138NC3_inq_dimids,
139NC3_inq_typeids,
140NC3_inq_type_equal,
141NC3_def_grp,
142NC3_inq_user_type,
143NC3_inq_typeid,
144
145NC3_def_compound,
146NC3_insert_compound,
147NC3_insert_array_compound,
148NC3_inq_compound_field,
149NC3_inq_compound_fieldindex,
150NC3_def_vlen,
151NC3_put_vlen_element,
152NC3_get_vlen_element,
153NC3_def_enum,
154NC3_insert_enum,
155NC3_inq_enum_member,
156NC3_inq_enum_ident,
157NC3_def_opaque,
158NC3_def_var_deflate,
159NC3_def_var_fletcher32,
160NC3_def_var_chunking,
161NC3_def_var_fill,
162NC3_def_var_endian,
163NC3_set_var_chunk_cache,
164NC3_get_var_chunk_cache,
165
166#endif /*_NC4DISPATCH_H*/
167
168};
169
170NC_Dispatch* NC3_dispatch_table = NULL; /* moved here from ddispatch.c */
171
172int
173NC3_initialize(void)
174{
175    NC3_dispatch_table = &NC3_dispatcher;
176    return NC_NOERR;
177}
178
179static int
180NC3_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
201static int
202NC3_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
218static int
219NC3_def_grp(int parent_ncid, const char *name, int *new_ncid)
220{
221    return NC_ENOTNC4;
222}
223
224static int
225NC3_inq_ncid(int ncid, const char *name, int *grp_ncid)
226{
227    if(grp_ncid) *grp_ncid = ncid;
228    return NC_NOERR;
229}
230
231static int
232NC3_inq_grps(int ncid, int *numgrps, int *ncids)
233{
234    if (numgrps)
235       *numgrps = 0;
236    return NC_NOERR;
237}
238
239static int
240NC3_inq_grpname(int ncid, char *name)
241{
242    if (name)
243        strcpy(name, "/");
244    return NC_NOERR;
245}
246
247static int
248NC3_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
256static int
257NC3_inq_grp_parent(int ncid, int *parent_ncid)
258{
259    return NC_ENOGRP;
260}
261
262static int
263NC3_inq_grp_full_ncid(int ncid, const char *full_name, int *grp_ncid)
264{
265    return NC_ENOGRP;
266}
267
268static int
269NC3_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
283static int
284NC3_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
298static int
299NC3_show_metadata(int ncid)
300{
301    return NC_NOERR;
302}
303
304static int
305NC3_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
335static int
336NC3_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
347static int
348NC3_inq_typeids(int ncid, int *ntypes, int *typeids)
349{
350    if(ntypes) *ntypes = 0;
351    return NC_NOERR;
352}
353
354static int
355NC3_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
361static int
362NC3_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp)
363{
364    return NC_ENOTNC4;
365}
366
367static int
368NC3_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
374static int
375NC3_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
383static int
384NC3_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
391static int
392NC3_inq_compound_fieldindex(int ncid, nc_type typeid, const char *name, int *fieldidp)
393{
394    return NC_ENOTNC4;
395}
396
397static int
398NC3_def_opaque(int ncid, size_t datum_size, const char *name, nc_type* xtypep)
399{
400    return NC_ENOTNC4;
401}
402
403static int
404NC3_def_vlen(int ncid, const char *name, nc_type base_typeid, nc_type* xtypep)
405{
406    return NC_ENOTNC4;
407}
408
409static int
410NC3_def_enum(int ncid, nc_type base_typeid, const char *name,
411            nc_type *typeidp)
412{
413    return NC_ENOTNC4;
414}
415
416static int
417NC3_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
418{
419    return NC_ENOTNC4;
420}
421
422static int
423NC3_inq_enum_member(int ncid, nc_type typeid, int idx, char *identifier,
424                   void *value)
425{
426    return NC_ENOTNC4;
427}
428
429static int
430NC3_insert_enum(int ncid, nc_type typeid, const char *identifier,
431               const void *value)
432{
433    return NC_ENOTNC4;
434}
435
436static int
437NC3_put_vlen_element(int ncid, int typeid, void *vlen_element,
438                    size_t len, const void *data)
439{
440    return NC_ENOTNC4;
441}
442
443static int
444NC3_get_vlen_element(int ncid, int typeid, const void *vlen_element,
445                    size_t *len, void *data)
446{
447    return NC_ENOTNC4;
448}
449
450static int
451NC3_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption)
452{
453    return NC_ENOTNC4;
454}
455
456static int
457NC3_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp)
458{
459    return NC_ENOTNC4;
460}
461
462static int
463NC3_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
464                   int deflate_level)
465{
466    return NC_ENOTNC4;
467}
468
469static int
470NC3_def_var_fletcher32(int ncid, int varid, int fletcher32)
471{
472    return NC_ENOTNC4;
473}
474
475static int
476NC3_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp)
477{
478    return NC_ENOTNC4;
479}
480
481static int
482NC3_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
483{
484    return NC_ENOTNC4;
485}
486
487static int
488NC3_def_var_endian(int ncid, int varid, int endianness)
489{
490    return NC_ENOTNC4;
491}
492
493static int
494NC3_var_par_access(int ncid, int varid, int par_access)
495{
496    return NC_ENOTNC4;
497}
498   
499#endif /*USE_NETCDF4*/
500   
Note: See TracBrowser for help on using the repository browser.