Coverage Report

Created: 2023-05-28 06:42

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