NetCDF  4.9.2
dvarinq.c
Go to the documentation of this file.
1 /* Copyright 2018 University Corporation for Atmospheric
2  Research/Unidata. See COPYRIGHT file for more info. */
8 #include "config.h"
9 #include "netcdf.h"
10 #include "netcdf_filter.h"
11 #include "ncdispatch.h"
12 #include "nc4internal.h"
13 #ifdef USE_HDF5
14 #include <hdf5.h>
15 #endif /* USE_HDF5 */
16  /* All these functions are part of this named group... */
21 
59 int
60 nc_inq_varid(int ncid, const char *name, int *varidp)
61 {
62  NC* ncp;
63  int stat = NC_check_id(ncid, &ncp);
64  if(stat != NC_NOERR) return stat;
65  return ncp->dispatch->inq_varid(ncid, name, varidp);
66 }
67 
123 int
124 nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep,
125  int *ndimsp, int *dimidsp, int *nattsp)
126 {
127  NC* ncp;
128  int stat = NC_check_id(ncid, &ncp);
129  if(stat != NC_NOERR) return stat;
130  TRACE(nc_inq_var);
131  return ncp->dispatch->inq_var_all(ncid, varid, name, xtypep, ndimsp,
132  dimidsp, nattsp, NULL, NULL, NULL,
133  NULL, NULL, NULL, NULL, NULL, NULL,
134  NULL,NULL,NULL);
135 }
136 
155 int
156 nc_inq_varname(int ncid, int varid, char *name)
157 {
158  return nc_inq_var(ncid, varid, name, NULL, NULL,
159  NULL, NULL);
160 }
161 
177 int
178 nc_inq_vartype(int ncid, int varid, nc_type *typep)
179 {
180  return nc_inq_var(ncid, varid, NULL, typep, NULL,
181  NULL, NULL);
182 }
183 
201 int
202 nc_inq_varndims(int ncid, int varid, int *ndimsp)
203 {
204  return nc_inq_var(ncid, varid, NULL, NULL, ndimsp, NULL, NULL);
205 }
206 
224 int
225 nc_inq_vardimid(int ncid, int varid, int *dimidsp)
226 {
227  return nc_inq_var(ncid, varid, NULL, NULL, NULL,
228  dimidsp, NULL);
229 }
230 
248 int
249 nc_inq_varnatts(int ncid, int varid, int *nattsp)
250 {
251  if (varid == NC_GLOBAL)
252  return nc_inq_natts(ncid,nattsp);
253  /*else*/
254  return nc_inq_var(ncid, varid, NULL, NULL, NULL, NULL,
255  nattsp);
256 }
257 
294 int
295 nc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, int *deflate_levelp)
296 {
297  NC* ncp;
298  size_t nparams;
299  unsigned int params[4];
300  int deflating = 0;
301  int stat;
302 
303  stat = NC_check_id(ncid,&ncp);
304  if(stat != NC_NOERR) return stat;
305  TRACE(nc_inq_var_deflate);
306 
307  /* Verify id and nparams */
308  stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_DEFLATE,&nparams,params);
309  switch (stat) {
310  case NC_ENOFILTER: deflating = 0; stat = NC_NOERR; break;
311  case NC_NOERR: deflating = 1; break;
312  case NC_ENOTNC4:
313  /* As a special case, to support behavior already coded into user
314  * applications, handle classic format files by reporting no
315  * deflation. */
316  if (shufflep)
317  *shufflep = 0;
318  if (deflatep)
319  *deflatep = 0;
320  if (deflate_levelp)
321  *deflate_levelp = 0;
322  return NC_NOERR;
323  break;
324  default: return stat;
325  }
326  if(deflatep) *deflatep = deflating;
327  if(deflating) {
328  if(nparams != 1)
329  return NC_EFILTER; /* bad # params */
330  /* Param[0] should be level */
331  if(deflate_levelp) *deflate_levelp = (int)params[0];
332  } else if (deflate_levelp)
333  *deflate_levelp = 0;
334  /* also get the shuffle state */
335  if(!shufflep)
336  return NC_NOERR;
337  return ncp->dispatch->inq_var_all(
338  ncid, varid,
339  NULL, /*name*/
340  NULL, /*xtypep*/
341  NULL, /*ndimsp*/
342  NULL, /*dimidsp*/
343  NULL, /*nattsp*/
344  shufflep, /*shufflep*/
345  NULL, /*deflatep*/
346  NULL, /*deflatelevelp*/
347  NULL, /*fletcher32p*/
348  NULL, /*contiguousp*/
349  NULL, /*chunksizep*/
350  NULL, /*nofillp*/
351  NULL, /*fillvaluep*/
352  NULL, /*endianp*/
353  NULL, NULL, NULL
354  );
355 }
356 
377 int
378 nc_inq_var_fletcher32(int ncid, int varid, int *fletcher32p)
379 {
380  NC* ncp;
381  int stat = NC_check_id(ncid,&ncp);
382  if(stat != NC_NOERR) return stat;
383  TRACE(nc_inq_var_fletcher32);
384  return ncp->dispatch->inq_var_all(
385  ncid, varid,
386  NULL, /*name*/
387  NULL, /*xtypep*/
388  NULL, /*ndimsp*/
389  NULL, /*dimidsp*/
390  NULL, /*nattsp*/
391  NULL, /*shufflep*/
392  NULL, /*deflatep*/
393  NULL, /*deflatelevelp*/
394  fletcher32p, /*fletcher32p*/
395  NULL, /*contiguousp*/
396  NULL, /*chunksizep*/
397  NULL, /*nofillp*/
398  NULL, /*fillvaluep*/
399  NULL, /*endianp*/
400  NULL, NULL, NULL
401  );
402 }
403 
465 int
466 nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp)
467 {
468  NC *ncp;
469  int stat = NC_check_id(ncid, &ncp);
470  if(stat != NC_NOERR) return stat;
471  TRACE(nc_inq_var_chunking);
472  return ncp->dispatch->inq_var_all(ncid, varid, NULL, NULL, NULL, NULL,
473  NULL, NULL, NULL, NULL, NULL, storagep,
474  chunksizesp, NULL, NULL, NULL,
475  NULL, NULL, NULL);
476 }
477 
501 int
502 nc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep)
503 {
504  NC* ncp;
505  int stat = NC_check_id(ncid,&ncp);
506 
507  if(stat != NC_NOERR) return stat;
508  TRACE(nc_inq_var_fill);
509 
510  return ncp->dispatch->inq_var_all(
511  ncid,varid,
512  NULL, /*name*/
513  NULL, /*xtypep*/
514  NULL, /*ndimsp*/
515  NULL, /*dimidsp*/
516  NULL, /*nattsp*/
517  NULL, /*shufflep*/
518  NULL, /*deflatep*/
519  NULL, /*deflatelevelp*/
520  NULL, /*fletcher32p*/
521  NULL, /*contiguousp*/
522  NULL, /*chunksizep*/
523  no_fill, /*nofillp*/
524  fill_valuep, /*fillvaluep*/
525  NULL, /*endianp*/
526  NULL, NULL, NULL
527  );
528 }
529 
544 int
545 nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp)
546 {
547  NC* ncp;
548  int stat = NC_check_id(ncid,&ncp);
549 
550  if(stat != NC_NOERR) return stat;
551  TRACE(nc_inq_var_quantize);
552 
553  /* Using NC_GLOBAL is illegal. */
554  if (varid == NC_GLOBAL) return NC_EGLOBAL;
555 
556  return ncp->dispatch->inq_var_quantize(ncid, varid,
557  quantize_modep, nsdp);
558 }
559 
581 int
582 nc_inq_var_endian(int ncid, int varid, int *endianp)
583 {
584  NC* ncp;
585  int stat = NC_check_id(ncid,&ncp);
586  if(stat != NC_NOERR) return stat;
587  TRACE(nc_inq_var_endian);
588  return ncp->dispatch->inq_var_all(
589  ncid, varid,
590  NULL, /*name*/
591  NULL, /*xtypep*/
592  NULL, /*ndimsp*/
593  NULL, /*dimidsp*/
594  NULL, /*nattsp*/
595  NULL, /*shufflep*/
596  NULL, /*deflatep*/
597  NULL, /*deflatelevelp*/
598  NULL, /*fletcher32p*/
599  NULL, /*contiguousp*/
600  NULL, /*chunksizep*/
601  NULL, /*nofillp*/
602  NULL, /*fillvaluep*/
603  endianp, /*endianp*/
604  NULL, NULL, NULL);
605 }
606 
671 int
672 nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
673 {
674 #ifndef USE_NETCDF4
675  return NC_ENOTNC4;
676 #else
677  NC* ncp;
678  int stat = NC_check_id(ncid,&ncp);
679  if(stat != NC_NOERR) return stat;
680  TRACE(nc_inq_unlimdims);
681  return ncp->dispatch->inq_unlimdims(ncid, nunlimdimsp,
682  unlimdimidsp);
683 #endif
684 }
685 
731 int
732 nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp)
733 {
734  NC* ncp;
735  size_t nparams;
736  unsigned int params[4];
737 
738  int stat = NC_check_id(ncid,&ncp);
739  if(stat != NC_NOERR) return stat;
740  TRACE(nc_inq_var_szip);
741 
742  /* Verify id and nparams */
743  stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_SZIP,&nparams,params);
744  switch (stat) {
745  case NC_NOERR:
746  if(nparams < 2)
747  return NC_EFILTER; /* bad # params */
748  if(nparams > 2)
749  nparams = 2; /* for compatibility, only return 2 params */
750  break;
751  case NC_ENOFILTER:
752  case NC_ENOTNC4:
753  /* If the szip filter is not in use, or if this is not a HDF5
754  * file, return 0 for both parameters. */
755  params[0] = 0;
756  params[1] = 0;
757  stat = NC_NOERR;
758  break;
759  default:
760  return stat;
761  }
762 
763  /* Param[0] should be options_mask
764  Param[1] should be pixels_per_block */
765  if(options_maskp) *options_maskp = (int)params[0];
766  if(pixels_per_blockp) *pixels_per_blockp = (int)params[1];
767  return stat;
768 }
769  /* End of named group ...*/
EXTERNL int nc_inq_natts(int ncid, int *nattsp)
Find number of global or group attributes.
Definition: dattinq.c:300
int nc_inq_var_endian(int ncid, int varid, int *endianp)
Find the endianness of a variable.
Definition: dvarinq.c:582
int nc_inq_varndims(int ncid, int varid, int *ndimsp)
Learn how many dimensions are associated with a variable.
Definition: dvarinq.c:202
int nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
Return number and list of unlimited dimensions.
Definition: dvarinq.c:672
int nc_inq_varname(int ncid, int varid, char *name)
Learn the name of a variable.
Definition: dvarinq.c:156
int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp)
Learn whether quantization is on for a variable, and, if so, the NSD setting.
Definition: dvarinq.c:545
int nc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, int *deflate_levelp)
Learn the shuffle and deflate settings for a variable.
Definition: dvarinq.c:295
int nc_inq_vartype(int ncid, int varid, nc_type *typep)
Learn the type of a variable.
Definition: dvarinq.c:178
int nc_inq_var_fletcher32(int ncid, int varid, int *fletcher32p)
Learn the checksum settings for a variable.
Definition: dvarinq.c:378
int nc_inq_varid(int ncid, const char *name, int *varidp)
Find the ID of a variable, from the name.
Definition: dvarinq.c:60
int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
Definition: dvarinq.c:249
EXTERNL int nc_inq_var_filter_info(int ncid, int varid, unsigned int id, size_t *nparams, unsigned int *params)
Find the the param info about filter (if any) associated with a variable and with specified id.
Definition: dfilter.c:94
int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
Learn about a variable.
Definition: dvarinq.c:124
int nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp)
Learn the szip settings of a variable.
Definition: dvarinq.c:732
int nc_inq_vardimid(int ncid, int varid, int *dimidsp)
Learn the dimension IDs associated with a variable.
Definition: dvarinq.c:225
int nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp)
Get the storage and (for chunked variables) the chunksizes of a variable.
Definition: dvarinq.c:466
int nc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep)
Learn the fill mode of a variable.
Definition: dvarinq.c:502
Main header file for the C API.
#define NC_EFILTER
Filter operation failed.
Definition: netcdf.h:513
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
Definition: netcdf.h:491
#define NC_GLOBAL
Attribute id to put/get a global attribute.
Definition: netcdf.h:254
#define NC_NOERR
No Error.
Definition: netcdf.h:368
#define NC_EGLOBAL
Action prohibited on NC_GLOBAL varid.
Definition: netcdf.h:423
#define NC_ENOFILTER
Filter not defined on variable.
Definition: netcdf.h:517
int nc_type
The nc_type type is just an int.
Definition: netcdf.h:25