Coverage Report

Created: 2025-06-09 07:42

/src/gdal/netcdf-c-4.7.4/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_NOTNC4_filter_actions,
168
};
169
170
const NC_Dispatch* NC3_dispatch_table = NULL; /*!< NC3 Dispatch table, moved here from ddispatch.c */
171
172
int
173
NC3_initialize(void)
174
1
{
175
1
    NC3_dispatch_table = &NC3_dispatcher;
176
1
    return NC_NOERR;
177
1
}
178
179
int
180
NC3_finalize(void)
181
0
{
182
0
    return NC_NOERR;
183
0
}
184
185
static int
186
NC3_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, 
187
               int *ndimsp, int *dimidsp, int *nattsp, 
188
               int *shufflep, int *deflatep, int *deflate_levelp,
189
               int *fletcher32p, int *contiguousp, size_t *chunksizesp, 
190
               int *no_fill, void *fill_valuep, int *endiannessp, 
191
         unsigned int* idp, size_t* nparamsp, unsigned int* params
192
         )
193
11.6k
{
194
11.6k
    int stat = NC3_inq_var(ncid,varid,name,xtypep,ndimsp,dimidsp,nattsp,no_fill,fill_valuep);
195
11.6k
    if(stat) return stat;
196
11.6k
    if(shufflep) *shufflep = 0;
197
11.6k
    if(deflatep) *deflatep = 0;
198
11.6k
    if(fletcher32p) *fletcher32p = 0;
199
11.6k
    if(contiguousp) *contiguousp = NC_CONTIGUOUS;
200
11.6k
    if(endiannessp) return NC_ENOTNC4;
201
11.6k
    if(idp) return NC_ENOTNC4;
202
11.6k
    if(nparamsp) return NC_ENOTNC4;
203
11.6k
    if(params) return NC_ENOTNC4;
204
11.6k
    return NC_NOERR;
205
11.6k
}
206
207
static int
208
NC3_var_par_access(int ncid, int varid, int par_access)
209
0
{
210
0
    return NC_NOERR; /* no-op for netcdf classic */
211
0
}
212
213
static int
214
NC3_inq_unlimdims(int ncid, int *ndimsp, int *unlimdimidsp)
215
0
{
216
0
    int retval;
217
0
    int unlimid;
218
219
0
    if ((retval = NC3_inq_unlimdim(ncid, &unlimid)))
220
0
        return retval;
221
0
    if (unlimid != -1) {
222
0
        if(ndimsp) *ndimsp = 1;
223
0
        if (unlimdimidsp)
224
0
            unlimdimidsp[0] = unlimid;
225
0
    } else
226
0
        if(ndimsp) *ndimsp = 0;
227
0
    return NC_NOERR;
228
0
}
229
230
static int
231
NC3_def_grp(int parent_ncid, const char *name, int *new_ncid)
232
0
{
233
0
    return NC_ENOTNC4;
234
0
}
235
236
static int
237
NC3_rename_grp(int grpid, const char *name)
238
0
{
239
0
    return NC_ENOTNC4;
240
0
}
241
242
static int
243
NC3_inq_ncid(int ncid, const char *name, int *grp_ncid)
244
0
{
245
0
  if(grp_ncid) *grp_ncid = ncid;
246
0
    return NC_NOERR;
247
0
}
248
249
static int
250
NC3_inq_grps(int ncid, int *numgrps, int *ncids)
251
168k
{
252
168k
  if (numgrps)
253
84.2k
       *numgrps = 0;
254
168k
    return NC_NOERR;
255
168k
}
256
257
static int
258
NC3_inq_grpname(int ncid, char *name)
259
0
{
260
0
    if (name)
261
0
        strcpy(name, "/");
262
0
    return NC_NOERR;
263
0
}
264
265
static int
266
NC3_inq_grpname_full(int ncid, size_t *lenp, char *full_name)
267
8.97k
{
268
8.97k
    if (full_name)
269
4.48k
        strcpy(full_name, "/");
270
8.97k
    if(lenp) *lenp = 1;
271
8.97k
    return NC_NOERR;
272
8.97k
}
273
274
static int
275
NC3_inq_grp_parent(int ncid, int *parent_ncid)
276
87.3k
{
277
87.3k
    return NC_ENOGRP;
278
87.3k
}
279
280
static int
281
NC3_inq_grp_full_ncid(int ncid, const char *full_name, int *grp_ncid)
282
1.14k
{
283
1.14k
    return NC_ENOGRP;
284
1.14k
}
285
286
static int
287
NC3_inq_varids(int ncid, int *nvarsp, int *varids)
288
0
{
289
0
    int retval,v,nvars;
290
    /* This is a netcdf-3 file, there is only one group, the root
291
        group, and its vars have ids 0 thru nvars - 1. */
292
0
    if ((retval = NC3_inq(ncid, NULL, &nvars, NULL, NULL)))
293
0
        return retval;
294
0
    if(nvarsp) *nvarsp = nvars;
295
0
    if (varids)
296
0
        for (v = 0; v < nvars; v++)
297
0
            varids[v] = v;
298
0
    return NC_NOERR;
299
0
}
300
301
static int
302
NC3_inq_dimids(int ncid, int *ndimsp, int *dimids, int include_parents)
303
0
{
304
0
    int retval,d,ndims;
305
    /* If this is a netcdf-3 file, then the dimids are going to be 0
306
       thru ndims-1, so just provide them. */
307
0
    if ((retval = NC3_inq(ncid, &ndims,  NULL, NULL, NULL)))
308
0
        return retval;
309
0
    if(ndimsp) *ndimsp = ndims;
310
0
    if (dimids)
311
0
        for (d = 0; d < ndims; d++)
312
0
            dimids[d] = d;
313
0
    return NC_NOERR;
314
0
}
315
316
static int
317
NC3_show_metadata(int ncid)
318
0
{
319
0
    return NC_NOERR;
320
0
}
321
322
static int
323
NC3_inq_type_equal(int ncid1, nc_type typeid1, int ncid2, nc_type typeid2, int* equalp)
324
0
{
325
    /* Check input. */
326
0
    if(equalp == NULL) return NC_NOERR;
327
    
328
0
    if (typeid1 <= NC_NAT || typeid2 <= NC_NAT)
329
0
       return NC_EINVAL;
330
    
331
0
    *equalp = 0; /* assume */
332
    
333
    /* If one is atomic, and the other user-defined, the types are not equal */
334
0
    if ((typeid1 <= NC_STRING && typeid2 > NC_STRING) ||
335
0
        (typeid2 <= NC_STRING && typeid1 > NC_STRING)) {
336
0
        if (equalp) *equalp = 0;
337
0
        return NC_NOERR;
338
0
    }
339
    
340
    /* If both are atomic types, the answer is easy. */
341
0
    if (typeid1 <= ATOMICTYPEMAX3) {
342
0
        if (equalp) {
343
0
            if (typeid1 == typeid2)
344
0
                *equalp = 1;
345
0
            else
346
0
                *equalp = 0;
347
0
        }
348
0
        return NC_NOERR;
349
0
    }
350
0
    return NC_NOERR;
351
0
}
352
353
static int
354
NC3_inq_typeid(int ncid, const char *name, nc_type *typeidp)
355
0
{
356
0
    int i;
357
0
    for (i = 0; i <= ATOMICTYPEMAX3; i++)
358
0
        if (!strcmp(name, NC_atomictypename(i))) {
359
0
            if (typeidp) *typeidp = i;
360
0
                return NC_NOERR;
361
0
        }
362
0
    return NC_ENOTNC4;
363
0
}
364
365
static int
366
NC3_inq_typeids(int ncid, int *ntypes, int *typeids)
367
0
{
368
0
    if(ntypes) *ntypes = 0;
369
0
    return NC_NOERR;
370
0
}
371
372
static int
373
NC3_inq_user_type(int ncid, nc_type typeid, char *name, size_t *size,
374
     nc_type *base_nc_typep, size_t *nfieldsp, int *classp)
375
0
{
376
0
    return NC_ENOTNC4;
377
0
}
378
379
static int
380
NC3_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp)
381
0
{
382
0
    return NC_ENOTNC4;
383
0
}
384
385
static int
386
NC3_insert_compound(int ncid, nc_type typeid, const char *name, size_t offset,
387
                    nc_type field_typeid)
388
0
{
389
0
    return NC_ENOTNC4;
390
0
}
391
392
static int
393
NC3_insert_array_compound(int ncid, nc_type typeid, const char *name,
394
       size_t offset, nc_type field_typeid,
395
       int ndims, const int *dim_sizes)
396
0
{
397
0
    return NC_ENOTNC4;
398
0
}
399
400
401
static int
402
NC3_inq_compound_field(int ncid, nc_type typeid, int fieldid, char *name,
403
          size_t *offsetp, nc_type *field_typeidp, int *ndimsp, 
404
          int *dim_sizesp)
405
0
{
406
0
    return NC_ENOTNC4;
407
0
}
408
409
static int
410
NC3_inq_compound_fieldindex(int ncid, nc_type typeid, const char *name, int *fieldidp)
411
0
{
412
0
    return NC_ENOTNC4;
413
0
}
414
415
static int
416
NC3_def_opaque(int ncid, size_t datum_size, const char *name, nc_type* xtypep)
417
0
{
418
0
    return NC_ENOTNC4;
419
0
}
420
421
static int
422
NC3_def_vlen(int ncid, const char *name, nc_type base_typeid, nc_type* xtypep)
423
0
{
424
0
    return NC_ENOTNC4;
425
0
}
426
427
static int
428
NC3_def_enum(int ncid, nc_type base_typeid, const char *name,
429
      nc_type *typeidp)
430
0
{
431
0
    return NC_ENOTNC4;
432
0
}
433
434
static int
435
NC3_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
436
0
{
437
0
    return NC_ENOTNC4;
438
0
}
439
440
static int
441
NC3_inq_enum_member(int ncid, nc_type typeid, int idx, char *identifier,
442
       void *value)
443
0
{
444
0
    return NC_ENOTNC4;
445
0
}
446
447
static int
448
NC3_insert_enum(int ncid, nc_type typeid, const char *identifier,
449
         const void *value)
450
0
{
451
0
    return NC_ENOTNC4;
452
0
}
453
454
static int
455
NC3_put_vlen_element(int ncid, int typeid, void *vlen_element,
456
        size_t len, const void *data)
457
0
{
458
0
    return NC_ENOTNC4;
459
0
}
460
461
static int
462
NC3_get_vlen_element(int ncid, int typeid, const void *vlen_element,
463
        size_t *len, void *data)
464
0
{
465
0
    return NC_ENOTNC4;
466
0
}
467
468
static int
469
NC3_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption)
470
0
{
471
0
    return NC_ENOTNC4;
472
0
}
473
474
static int
475
NC3_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp)
476
0
{
477
0
    return NC_ENOTNC4;
478
0
}
479
480
static int
481
NC3_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
482
       int deflate_level)
483
0
{
484
0
    return NC_ENOTNC4;
485
0
}
486
487
static int
488
NC3_def_var_fletcher32(int ncid, int varid, int fletcher32)
489
0
{
490
0
    return NC_ENOTNC4;
491
0
}
492
493
static int
494
NC3_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp)
495
0
{
496
0
    return NC_ENOTNC4;
497
0
}
498
499
static int
500
NC3_def_var_endian(int ncid, int varid, int endianness)
501
0
{
502
0
    return NC_ENOTNC4;
503
0
}
504
505
static int
506
NC3_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams, const unsigned int* parms)
507
0
{
508
0
    return NC_ENOTNC4;
509
0
}
510