NetCDF  4.8.1
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 
551 int
552 nc_inq_var_endian(int ncid, int varid, int *endianp)
553 {
554  NC* ncp;
555  int stat = NC_check_id(ncid,&ncp);
556  if(stat != NC_NOERR) return stat;
557  TRACE(nc_inq_var_endian);
558  return ncp->dispatch->inq_var_all(
559  ncid, varid,
560  NULL, /*name*/
561  NULL, /*xtypep*/
562  NULL, /*ndimsp*/
563  NULL, /*dimidsp*/
564  NULL, /*nattsp*/
565  NULL, /*shufflep*/
566  NULL, /*deflatep*/
567  NULL, /*deflatelevelp*/
568  NULL, /*fletcher32p*/
569  NULL, /*contiguousp*/
570  NULL, /*chunksizep*/
571  NULL, /*nofillp*/
572  NULL, /*fillvaluep*/
573  endianp, /*endianp*/
574  NULL, NULL, NULL);
575 }
576 
641 int
642 nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
643 {
644 #ifndef USE_NETCDF4
645  return NC_ENOTNC4;
646 #else
647  NC* ncp;
648  int stat = NC_check_id(ncid,&ncp);
649  if(stat != NC_NOERR) return stat;
650  TRACE(nc_inq_unlimdims);
651  return ncp->dispatch->inq_unlimdims(ncid, nunlimdimsp,
652  unlimdimidsp);
653 #endif
654 }
655 
701 int
702 nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp)
703 {
704  NC* ncp;
705  size_t nparams;
706  unsigned int params[4];
707 
708  int stat = NC_check_id(ncid,&ncp);
709  if(stat != NC_NOERR) return stat;
710  TRACE(nc_inq_var_szip);
711 
712  /* Verify id and nparams */
713  stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_SZIP,&nparams,params);
714  switch (stat) {
715  case NC_NOERR:
716  if(nparams != 2)
717  return NC_EFILTER; /* bad # params */
718  break;
719  case NC_ENOFILTER:
720  case NC_ENOTNC4:
721  /* If the szip filter is not in use, or if this is not a HDF5
722  * file, return 0 for both parameters. */
723  params[0] = 0;
724  params[1] = 0;
725  stat = NC_NOERR;
726  break;
727  default:
728  return stat;
729  }
730 
731  /* Param[0] should be options_mask
732  Param[1] should be pixels_per_block */
733  if(options_maskp) *options_maskp = (int)params[0];
734  if(pixels_per_blockp) *pixels_per_blockp = (int)params[1];
735  return stat;
736 }
737  /* End of named group ...*/
NC_NOERR
#define NC_NOERR
No Error.
Definition: netcdf.h:333
nc_inq_varname
int nc_inq_varname(int ncid, int varid, char *name)
Definition: dvarinq.c:156
nc_inq_varnatts
int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
Definition: dvarinq.c:249
nc_inq_varndims
int nc_inq_varndims(int ncid, int varid, int *ndimsp)
Learn how many dimensions are associated with a variable.
Definition: dvarinq.c:202
NC_ENOFILTER
#define NC_ENOFILTER
Filter not defined on variable.
Definition: netcdf.h:482
NC_EFILTER
#define NC_EFILTER
Filter operation failed.
Definition: netcdf.h:478
nc_inq_unlimdims
int nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
Return number and list of unlimited dimensions.
Definition: dvarinq.c:642
nc_inq_natts
EXTERNL int nc_inq_natts(int ncid, int *nattsp)
Definition: dattinq.c:299
NC_ENOTNC4
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
Definition: netcdf.h:456
nc_inq_var_endian
int nc_inq_var_endian(int ncid, int varid, int *endianp)
Definition: dvarinq.c:552
NC_GLOBAL
#define NC_GLOBAL
Attribute id to put/get a global attribute.
Definition: netcdf.h:249
nc_inq_var_deflate
int nc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, int *deflate_levelp)
Definition: dvarinq.c:295
nc_inq_var_fletcher32
int nc_inq_var_fletcher32(int ncid, int varid, int *fletcher32p)
Definition: dvarinq.c:378
netcdf.h
nc_inq_varid
int nc_inq_varid(int ncid, const char *name, int *varidp)
Definition: dvarinq.c:60
nc_inq_var_szip
int nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp)
Definition: dvarinq.c:702
nc_type
int nc_type
The nc_type type is just an int.
Definition: netcdf.h:25
nc_inq_vartype
int nc_inq_vartype(int ncid, int varid, nc_type *typep)
Learn the type of a variable.
Definition: dvarinq.c:178
nc_inq_var_fill
int nc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep)
Definition: dvarinq.c:502
nc_inq_var_chunking
int nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp)
Definition: dvarinq.c:466
nc_inq_var
int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
Definition: dvarinq.c:124
nc_inq_vardimid
int nc_inq_vardimid(int ncid, int varid, int *dimidsp)
Learn the dimension IDs associated with a variable.
Definition: dvarinq.c:225