1 /* Copyright 2018 University Corporation for Atmospheric
2    Research/Unidata. See COPYRIGHT file for more info. */
3 /*! \file
4 Functions for inquiring about variables.
5 
6 */
7 
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 
17 /** \name Learning about Variables
18 
19 Functions to learn about the variables in a file. */
20 /*! \{ */ /* All these functions are part of this named group... */
21 
22 /**
23 \ingroup variables
24 Find the ID of a variable, from the name.
25 
26 The function nc_inq_varid returns the ID of a netCDF variable, given
27 its name.
28 
29 \param ncid NetCDF or group ID, from a previous call to nc_open(),
30 nc_create(), nc_def_grp(), or associated inquiry functions such as
31 nc_inq_ncid().
32 
33 \param name Name of the variable.
34 
35 \param varidp Pointer to location for returned variable ID.  \ref
36 ignored_if_null.
37 
38 \returns ::NC_NOERR No error.
39 \returns ::NC_EBADID Bad ncid.
40 \returns ::NC_ENOTVAR Invalid variable ID.
41 
42 \section nc_inq_varid_example4 Example
43 
44 Here is an example using nc_inq_varid to find out the ID of a variable
45 named rh in an existing netCDF dataset named foo.nc:
46 
47 \code
48      #include <netcdf.h>
49         ...
50      int  status, ncid, rh_id;
51         ...
52      status = nc_open("foo.nc", NC_NOWRITE, &ncid);
53      if (status != NC_NOERR) handle_error(status);
54         ...
55      status = nc_inq_varid (ncid, "rh", &rh_id);
56      if (status != NC_NOERR) handle_error(status);
57 \endcode
58  */
59 int
nc_inq_varid(int ncid,const char * name,int * varidp)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 
68 /**
69 \ingroup variables
70 Learn about a variable.
71 
72 \param ncid NetCDF or group ID, from a previous call to nc_open(),
73 nc_create(), nc_def_grp(), or associated inquiry functions such as
74 nc_inq_ncid().
75 
76 \param varid Variable ID
77 
78 \param name Returned \ref object_name of variable. \ref
79 ignored_if_null.
80 
81 \param xtypep Pointer where typeid will be stored. \ref ignored_if_null.
82 
83 \param ndimsp Pointer where number of dimensions will be
84 stored. \ref ignored_if_null.
85 
86 \param dimidsp Pointer where array of dimension IDs will be
87 stored. \ref ignored_if_null.
88 
89 \param nattsp Pointer where number of attributes will be
90 stored. \ref ignored_if_null.
91 
92 \returns ::NC_NOERR No error.
93 \returns ::NC_EBADID Bad ncid.
94 \returns ::NC_ENOTVAR Invalid variable ID.
95 
96 \section nc_inq_var_example5 Example
97 
98 Here is an example using nc_inq_var() to find out about a variable named
99 rh in an existing netCDF dataset named foo.nc:
100 
101 \code
102      #include <netcdf.h>
103         ...
104      int  status
105      int  ncid;
106      int  rh_id;
107      nc_type rh_type;
108      int rh_ndims;
109      int  rh_dimids[NC_MAX_VAR_DIMS];
110      int rh_natts
111         ...
112      status = nc_open ("foo.nc", NC_NOWRITE, &ncid);
113      if (status != NC_NOERR) handle_error(status);
114         ...
115      status = nc_inq_varid (ncid, "rh", &rh_id);
116      if (status != NC_NOERR) handle_error(status);
117      status = nc_inq_var (ncid, rh_id, 0, &rh_type, &rh_ndims, rh_dimids,
118                           &rh_natts);
119      if (status != NC_NOERR) handle_error(status);
120 \endcode
121 
122  */
123 int
nc_inq_var(int ncid,int varid,char * name,nc_type * xtypep,int * ndimsp,int * dimidsp,int * nattsp)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 
137 /**
138 \ingroup variables
139 Learn the name of a variable.
140 
141 \param ncid NetCDF or group ID, from a previous call to nc_open(),
142 nc_create(), nc_def_grp(), or associated inquiry functions such as
143 nc_inq_ncid().
144 
145 \param varid Variable ID
146 
147 \param name Returned variable name. The caller must allocate space for
148 the returned name. The maximum length is ::NC_MAX_NAME. Ignored if
149 NULL.
150 
151 \returns ::NC_NOERR No error.
152 \returns ::NC_EBADID Bad ncid.
153 \returns ::NC_ENOTVAR Invalid variable ID.
154  */
155 int
nc_inq_varname(int ncid,int varid,char * name)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 
162 /** Learn the type of a variable.
163 \ingroup variables
164 
165 \param ncid NetCDF or group ID, from a previous call to nc_open(),
166 nc_create(), nc_def_grp(), or associated inquiry functions such as
167 nc_inq_ncid().
168 
169 \param varid Variable ID
170 
171 \param typep Pointer where typeid will be stored. \ref ignored_if_null.
172 
173 \returns ::NC_NOERR No error.
174 \returns ::NC_EBADID Bad ncid.
175 \returns ::NC_ENOTVAR Invalid variable ID.
176  */
177 int
nc_inq_vartype(int ncid,int varid,nc_type * typep)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 
184 /**
185 Learn how many dimensions are associated with a variable.
186 \ingroup variables
187 
188 \param ncid NetCDF or group ID, from a previous call to nc_open(),
189 nc_create(), nc_def_grp(), or associated inquiry functions such as
190 nc_inq_ncid().
191 
192 \param varid Variable ID
193 
194 \param ndimsp Pointer where number of dimensions will be
195 stored. \ref ignored_if_null.
196 
197 \returns ::NC_NOERR No error.
198 \returns ::NC_EBADID Bad ncid.
199 \returns ::NC_ENOTVAR Invalid variable ID.
200  */
201 int
nc_inq_varndims(int ncid,int varid,int * ndimsp)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 
207 /**
208 Learn the dimension IDs associated with a variable.
209 \ingroup variables
210 
211 \param ncid NetCDF or group ID, from a previous call to nc_open(),
212 nc_create(), nc_def_grp(), or associated inquiry functions such as
213 nc_inq_ncid().
214 
215 \param varid Variable ID
216 
217 \param dimidsp Pointer where array of dimension IDs will be
218 stored. \ref ignored_if_null.
219 
220 \returns ::NC_NOERR No error.
221 \returns ::NC_EBADID Bad ncid.
222 \returns ::NC_ENOTVAR Invalid variable ID.
223  */
224 int
nc_inq_vardimid(int ncid,int varid,int * dimidsp)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 
231 /**
232 Learn how many attributes are associated with a variable.
233 \ingroup variables
234 
235 \param ncid NetCDF or group ID, from a previous call to nc_open(),
236 nc_create(), nc_def_grp(), or associated inquiry functions such as
237 nc_inq_ncid().
238 
239 \param varid Variable ID
240 
241 \param nattsp Pointer where number of attributes will be
242 stored. \ref ignored_if_null.
243 
244 \returns ::NC_NOERR No error.
245 \returns ::NC_EBADID Bad ncid.
246 \returns ::NC_ENOTVAR Invalid variable ID.
247  */
248 int
nc_inq_varnatts(int ncid,int varid,int * nattsp)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 
258 /** \ingroup variables
259 Learn the storage and deflate settings for a variable.
260 
261 \param ncid NetCDF or group ID, from a previous call to nc_open(),
262 nc_create(), nc_def_grp(), or associated inquiry functions such as
263 nc_inq_ncid().
264 
265 \param varid Variable ID
266 
267 \param shufflep A 1 will be written here if the shuffle filter is
268 turned on for this variable, and a 0 otherwise. \ref ignored_if_null.
269 
270 \param deflatep If this pointer is non-NULL, the nc_inq_var_deflate
271 function will write a 1 if the deflate filter is turned on for this
272 variable, and a 0 otherwise. \ref ignored_if_null.
273 
274 \param deflate_levelp If the deflate filter is in use for this
275 variable, the deflate_level will be written here. If deflate is not in
276 use, and deflate_levelp is provided, it will get a zero. (This
277 behavior is expected by the Fortran APIs). \ref ignored_if_null.
278 
279 \returns ::NC_NOERR No error.
280 \returns ::NC_ENOTNC4 Not a netCDF-4 file.
281 \returns ::NC_EBADID Bad ncid.
282 \returns ::NC_ENOTVAR Invalid variable ID.
283 \author Ed Hartnett, Dennis Heimbigner
284 */
285 int
nc_inq_var_deflate(int ncid,int varid,int * shufflep,int * deflatep,int * deflate_levelp)286 nc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, int *deflate_levelp)
287 {
288    NC* ncp;
289    size_t nparams;
290    unsigned int params[4];
291    int deflating = 0;
292 
293    int stat = NC_check_id(ncid,&ncp);
294    if(stat != NC_NOERR) return stat;
295    TRACE(nc_inq_var_deflate);
296 
297    /* Verify id and  nparams */
298    stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_DEFLATE,&nparams,params);
299    switch (stat) {
300    case NC_ENOFILTER: deflating = 0; stat = NC_NOERR; break;
301    case NC_NOERR: deflating = 1; break;
302    default: return stat;
303    }
304    if(deflatep) *deflatep = deflating;
305    if(deflating) {
306         if(nparams != 1)
307 	    return NC_EFILTER; /* bad # params */
308 	/* Param[0] should be level */
309 	if(deflate_levelp) *deflate_levelp = (int)params[0];
310    } else if (deflate_levelp)
311        *deflate_levelp = 0;
312    /* also get the shuffle state */
313    if(!shufflep)
314        return NC_NOERR;
315    return ncp->dispatch->inq_var_all(
316       ncid, varid,
317       NULL, /*name*/
318       NULL, /*xtypep*/
319       NULL, /*ndimsp*/
320       NULL, /*dimidsp*/
321       NULL, /*nattsp*/
322       shufflep, /*shufflep*/
323       NULL, /*deflatep*/
324       NULL, /*deflatelevelp*/
325       NULL, /*fletcher32p*/
326       NULL, /*contiguousp*/
327       NULL, /*chunksizep*/
328       NULL, /*nofillp*/
329       NULL, /*fillvaluep*/
330       NULL, /*endianp*/
331       NULL, NULL, NULL
332       );
333 }
334 
335 /** \ingroup variables
336 Learn the checksum settings for a variable.
337 
338 This is a wrapper for nc_inq_var_all().
339 
340 \param ncid NetCDF or group ID, from a previous call to nc_open(),
341 nc_create(), nc_def_grp(), or associated inquiry functions such as
342 nc_inq_ncid().
343 
344 \param varid Variable ID
345 
346 \param fletcher32p Will be set to ::NC_FLETCHER32 if the fletcher32
347 checksum filter is turned on for this variable, and ::NC_NOCHECKSUM if
348 it is not. \ref ignored_if_null.
349 
350 \returns ::NC_NOERR No error.
351 \returns ::NC_EBADID Bad ncid.
352 \returns ::NC_ENOTNC4 Not a netCDF-4 file.
353 \returns ::NC_ENOTVAR Invalid variable ID.
354 */
355 int
nc_inq_var_fletcher32(int ncid,int varid,int * fletcher32p)356 nc_inq_var_fletcher32(int ncid, int varid, int *fletcher32p)
357 {
358    NC* ncp;
359    int stat = NC_check_id(ncid,&ncp);
360    if(stat != NC_NOERR) return stat;
361    TRACE(nc_inq_var_fletcher32);
362    return ncp->dispatch->inq_var_all(
363       ncid, varid,
364       NULL, /*name*/
365       NULL, /*xtypep*/
366       NULL, /*ndimsp*/
367       NULL, /*dimidsp*/
368       NULL, /*nattsp*/
369       NULL, /*shufflep*/
370       NULL, /*deflatep*/
371       NULL, /*deflatelevelp*/
372       fletcher32p, /*fletcher32p*/
373       NULL, /*contiguousp*/
374       NULL, /*chunksizep*/
375       NULL, /*nofillp*/
376       NULL, /*fillvaluep*/
377       NULL, /*endianp*/
378       NULL, NULL, NULL
379       );
380 }
381 
382 /**
383  * @ingroup variables
384  *
385  * Get the storage and (for chunked variables) the chunksizes of a
386  * variable. See nc_def_var_chunking() for explanation of storage.
387  *
388  * @param ncid NetCDF or group ID, from a previous call to nc_open(),
389  * nc_create(), nc_def_grp(), or associated inquiry functions such as
390  * nc_inq_ncid().
391  * @param varid Variable ID
392  * @param storagep Address of returned storage property, returned as
393  * ::NC_CONTIGUOUS if this variable uses contiguous storage,
394  * ::NC_CHUNKED if it uses chunked storage, or ::NC_COMPACT for
395  * compact storage. \ref ignored_if_null.
396  * @param chunksizesp The chunksizes will be copied here. \ref
397  * ignored_if_null.
398  *
399  * @return ::NC_NOERR No error.
400  * @return ::NC_EBADID Bad ncid.
401  * @return ::NC_ENOTNC4 Not a netCDF-4 file.
402  * @return ::NC_ENOTVAR Invalid variable ID.
403  *
404  * @author Ed Hartnett
405  *
406  * @section nc_inq_var_chunking_example Example
407  *
408  * @code
409         printf("**** testing contiguous storage...");
410         {
411      #define NDIMS6 1
412      #define DIM6_NAME "D5"
413      #define VAR_NAME6 "V5"
414      #define DIM6_LEN 100
415 
416            int dimids[NDIMS6], dimids_in[NDIMS6];
417            int varid;
418            int ndims, nvars, natts, unlimdimid;
419            nc_type xtype_in;
420            char name_in[NC_MAX_NAME + 1];
421            int data[DIM6_LEN], data_in[DIM6_LEN];
422            size_t chunksize_in[NDIMS6];
423            int storage_in;
424            int i, d;
425 
426            for (i = 0; i < DIM6_LEN; i++)
427               data[i] = i;
428 
429 
430            if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
431            if (nc_def_dim(ncid, DIM6_NAME, DIM6_LEN, &dimids[0])) ERR;
432            if (dimids[0] != 0) ERR;
433            if (nc_def_var(ncid, VAR_NAME6, NC_INT, NDIMS6, dimids, &varid)) ERR;
434            if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL)) ERR;
435            if (nc_put_var_int(ncid, varid, data)) ERR;
436 
437 
438            if (nc_inq_var_chunking(ncid, 0, &storage_in, chunksize_in)) ERR;
439            if (storage_in != NC_CONTIGUOUS) ERR;
440 @endcode
441 *
442 */
443 int
nc_inq_var_chunking(int ncid,int varid,int * storagep,size_t * chunksizesp)444 nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp)
445 {
446    NC *ncp;
447    int stat = NC_check_id(ncid, &ncp);
448    if(stat != NC_NOERR) return stat;
449    TRACE(nc_inq_var_chunking);
450    return ncp->dispatch->inq_var_all(ncid, varid, NULL, NULL, NULL, NULL,
451 				     NULL, NULL, NULL, NULL, NULL, storagep,
452 				     chunksizesp, NULL, NULL, NULL,
453                                      NULL, NULL, NULL);
454 }
455 
456 /** \ingroup variables
457 Learn the fill mode of a variable.
458 
459 The fill mode of a variable is set by nc_def_var_fill().
460 
461 This is a wrapper for nc_inq_var_all().
462 
463 \param ncid NetCDF or group ID, from a previous call to nc_open(),
464 nc_create(), nc_def_grp(), or associated inquiry functions such as
465 nc_inq_ncid().
466 
467 \param varid Variable ID
468 
469 \param no_fill Pointer to an integer which will get a 1 if no_fill
470 mode is set for this variable. \ref ignored_if_null.
471 
472 \param fill_valuep A pointer which will get the fill value for this
473 variable. \ref ignored_if_null.
474 
475 \returns ::NC_NOERR No error.
476 \returns ::NC_EBADID Bad ncid.
477 \returns ::NC_ENOTVAR Invalid variable ID.
478 */
479 int
nc_inq_var_fill(int ncid,int varid,int * no_fill,void * fill_valuep)480 nc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep)
481 {
482    NC* ncp;
483    int stat = NC_check_id(ncid,&ncp);
484 
485    if(stat != NC_NOERR) return stat;
486    TRACE(nc_inq_var_fill);
487 
488    return ncp->dispatch->inq_var_all(
489       ncid,varid,
490       NULL, /*name*/
491       NULL, /*xtypep*/
492       NULL, /*ndimsp*/
493       NULL, /*dimidsp*/
494       NULL, /*nattsp*/
495       NULL, /*shufflep*/
496       NULL, /*deflatep*/
497       NULL, /*deflatelevelp*/
498       NULL, /*fletcher32p*/
499       NULL, /*contiguousp*/
500       NULL, /*chunksizep*/
501       no_fill, /*nofillp*/
502       fill_valuep, /*fillvaluep*/
503       NULL, /*endianp*/
504       NULL, NULL, NULL
505       );
506 }
507 
508 /** \ingroup variables
509 Find the endianness of a variable.
510 
511 This is a wrapper for nc_inq_var_all().
512 
513 \param ncid NetCDF or group ID, from a previous call to nc_open(),
514 nc_create(), nc_def_grp(), or associated inquiry functions such as
515 nc_inq_ncid().
516 
517 \param varid Variable ID
518 
519 \param endianp Storage which will get ::NC_ENDIAN_LITTLE if this
520 variable is stored in little-endian format, ::NC_ENDIAN_BIG if it is
521 stored in big-endian format, and ::NC_ENDIAN_NATIVE if the endianness
522 is not set, and the variable is not created yet.
523 
524 \returns ::NC_NOERR No error.
525 \returns ::NC_ENOTNC4 Not a netCDF-4 file.
526 \returns ::NC_EBADID Bad ncid.
527 \returns ::NC_ENOTVAR Invalid variable ID.
528 */
529 int
nc_inq_var_endian(int ncid,int varid,int * endianp)530 nc_inq_var_endian(int ncid, int varid, int *endianp)
531 {
532    NC* ncp;
533    int stat = NC_check_id(ncid,&ncp);
534    if(stat != NC_NOERR) return stat;
535    TRACE(nc_inq_var_endian);
536    return ncp->dispatch->inq_var_all(
537       ncid, varid,
538       NULL, /*name*/
539       NULL, /*xtypep*/
540       NULL, /*ndimsp*/
541       NULL, /*dimidsp*/
542       NULL, /*nattsp*/
543       NULL, /*shufflep*/
544       NULL, /*deflatep*/
545       NULL, /*deflatelevelp*/
546       NULL, /*fletcher32p*/
547       NULL, /*contiguousp*/
548       NULL, /*chunksizep*/
549       NULL, /*nofillp*/
550       NULL, /*fillvaluep*/
551       endianp, /*endianp*/
552       NULL, NULL, NULL);
553 }
554 
555 /**
556 Return number and list of unlimited dimensions.
557 
558 In netCDF-4 files, it's possible to have multiple unlimited
559 dimensions. This function returns a list of the unlimited dimension
560 ids visible in a group.
561 
562 Dimensions are visible in a group if they have been defined in that
563 group, or any ancestor group.
564 
565 \param ncid NetCDF file and group ID, from a previous call to nc_open(),
566 nc_create(), nc_def_grp(), etc.
567 
568 \param nunlimdimsp A pointer to an int which will get the number of
569 visible unlimited dimensions. Ignored if NULL.
570 
571 \param unlimdimidsp A pointer to an already allocated array of int
572 which will get the ids of all visible unlimited dimensions. Ignored if
573 NULL. To allocate the correct length for this array, call
574 nc_inq_unlimdims with a NULL for this parameter and use the
575 nunlimdimsp parameter to get the number of visible unlimited
576 dimensions.
577 
578 \section nc_inq_unlimdims_example Example
579 
580 Here is an example from nc_test4/tst_dims.c. In this example we create
581 a file with two unlimited dimensions, and then call nc_inq_unlimdims()
582 to check that there are 2 unlimited dimensions, and that they have
583 dimids 0 and 1.
584 
585 \code
586      #include <netcdf.h>
587         ...
588 #define ROMULUS "Romulus"
589 #define REMUS "Remus"
590 #define DIMS2 2
591    printf("*** Testing file with two unlimited dimensions...");
592    {
593       int ncid, dimid[DIMS2];
594       int unlimdimid_in[DIMS2];
595       int nunlimdims_in;
596 
597       if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
598       if (nc_def_dim(ncid, REMUS, NC_UNLIMITED, &dimid[0])) ERR;
599       if (nc_def_dim(ncid, ROMULUS, NC_UNLIMITED, &dimid[1])) ERR;
600 
601       ...
602       if (nc_inq_unlimdims(ncid, &nunlimdims_in, unlimdimid_in)) ERR;
603       if (nunlimdims_in != 2 || unlimdimid_in[0] != 0 || unlimdimid_in[1] != 1) ERR;
604 \endcode
605 
606 This function will return one of the following values.
607 
608 \returns ::NC_NOERR No error.
609 \returns ::NC_EBADID Bad group id.
610 \returns ::NC_ENOTNC4 Attempting a netCDF-4 operation on a netCDF-3
611 file. NetCDF-4 operations can only be performed on files defined with
612 a create mode which includes flag HDF5. (see nc_open).
613 \returns ::NC_ESTRICTNC3 This file was created with the strict
614 netcdf-3 flag, therefore netcdf-4 operations are not allowed. (see
615 nc_open).
616 \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
617 \author Ed Hartnett, Dennis Heimbigner
618  */
619 int
nc_inq_unlimdims(int ncid,int * nunlimdimsp,int * unlimdimidsp)620 nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
621 {
622 #ifndef USE_NETCDF4
623     return NC_ENOTNC4;
624 #else
625     NC* ncp;
626     int stat = NC_check_id(ncid,&ncp);
627     if(stat != NC_NOERR) return stat;
628     TRACE(nc_inq_unlimdims);
629     return ncp->dispatch->inq_unlimdims(ncid, nunlimdimsp,
630 					unlimdimidsp);
631 #endif
632 }
633 
634 /**
635 \ingroup variables
636 Learn the szip settings of a variable.
637 
638 This function returns the szip settings for a variable. To turn on
639 szip compression, use nc_def_var_szip(). Szip compression is only
640 available if HDF5 was built with szip support. The nc_def_var_filter
641 function may also be used to set szip compression.
642 
643 If a variable is not using szip, then a zero will be passed back
644 for both options_maskp and pixels_per_blockp.
645 
646 For more information on HDF5 and szip see
647 https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetSzip
648 and https://support.hdfgroup.org/doc_resource/SZIP/index.html.
649 
650 \param ncid NetCDF or group ID, from a previous call to nc_open(),
651 nc_create(), nc_def_grp(), or associated inquiry functions such as
652 nc_inq_ncid().
653 
654 \param varid Variable ID
655 
656 \param options_maskp The szip options mask will be copied to this
657 pointer. Note that the HDF5 layer adds to the options_mask, so this
658 value may be different from the value used when setting szip
659 compression, however the bit set when setting szip compression will
660 still be set in the options_maskp and can be checked for. If zero is
661 returned, szip is not in use for this variable.\ref ignored_if_null.
662 
663 \param pixels_per_blockp The szip pixels per block will be copied
664 here. The HDF5 layer may change this value, so this may not match the
665 value passed in when setting szip compression. If zero is returned,
666 szip is not in use for this variable. \ref ignored_if_null.
667 
668 \returns ::NC_NOERR No error.
669 \returns ::NC_EBADID Bad ncid.
670 \returns ::NC_ENOTNC4 Not a netCDF-4 file.
671 \returns ::NC_ENOTVAR Invalid variable ID.
672 \returns ::NC_EFILTER Filter error.
673 
674 \author Ed Hartnett, Dennis Heimbigner
675 
676 */
677 int
nc_inq_var_szip(int ncid,int varid,int * options_maskp,int * pixels_per_blockp)678 nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp)
679 {
680    NC* ncp;
681    size_t nparams;
682    unsigned int params[4];
683 
684    int stat = NC_check_id(ncid,&ncp);
685    if(stat != NC_NOERR) return stat;
686    TRACE(nc_inq_var_szip);
687 
688    /* Verify id and nparams */
689    stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_SZIP,&nparams,params);
690    switch (stat) {
691    case NC_NOERR:
692         if(nparams != 2)
693 	    return NC_EFILTER; /* bad # params */
694 	break;
695    case NC_ENOFILTER:
696        /* If the szip filter is not in use, return 0 for both  parameters. */
697        params[0] = 0;
698        params[1] = 0;
699        stat = NC_NOERR;
700        break;
701    default:
702    	return stat;
703    }
704 
705    /* Param[0] should be options_mask
706       Param[1] should be pixels_per_block */
707    if(options_maskp) *options_maskp = (int)params[0];
708    if(pixels_per_blockp) *pixels_per_blockp = (int)params[1];
709    return stat;
710 }
711 
712 /*!
713 Learn all about a variable.
714 
715 @param[in] ncid ncid for file.
716 @param[in] varid varid for variable in question.
717 @param[out] name Pointer to memory to contain the name of the
718 variable.
719 @param[out] xtypep Pointer to memory to contain the type of the
720 variable.
721 @param[out] ndimsp Pointer to memory to store the number of associated
722 dimensions for the variable.
723 @param[out] dimidsp Pointer to memory to store the dimids associated
724 with the variable.
725 @param[out] nattsp Pointer to memory to store the number of attributes
726 associated with the variable.
727 @param[out] shufflep Pointer to memory to store shuffle information
728 associated with the variable.
729 @param[out] deflatep Pointer to memory to store compression type
730 associated with the variable.
731 @param[out] deflate_levelp Pointer to memory to store compression
732 level associated with the variable.
733 @param[out] fletcher32p Pointer to memory to store compression
734 information associated with the variable.
735 @param[out] contiguousp Pointer to memory to store contiguous-data
736 information associated with the variable.
737 @param[out] chunksizesp Pointer to memory to store chunksize
738 information associated with the variable.
739 @param[out] no_fill Pointer to memory to store whether or not there is
740 a fill value associated with the variable.
741 @param[out] fill_valuep Pointer to memory to store the fill value (if
742 one exists) for the variable.
743 @param[out] endiannessp Pointer to memory to store endianness
744 value. One of ::NC_ENDIAN_BIG ::NC_ENDIAN_LITTLE ::NC_ENDIAN_NATIVE
745 @param[out] idp Pointer to memory to store filter id.
746 @param[out] nparamsp Pointer to memory to store filter parameter count.
747 @param[out] params Pointer to vector of unsigned integers into which
748 to store filter parameters.
749 \note Expose access to nc_inq_var_all().
750 
751 \returns ::NC_NOERR No error.
752 \returns ::NC_EBADID Bad ncid.
753 \returns ::NC_ENOTVAR Bad varid.
754 \returns ::NC_ENOMEM Out of memory.
755 \returns ::NC_EINVAL Invalid input.
756 \author Ed Hartnett, Dennis Heimbigner
757 \internal
758 \ingroup variables
759 */
760 #if 0
761 int
762 NC_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
763                int *ndimsp, int *dimidsp, int *nattsp,
764                int *shufflep, int *deflatep, int *deflate_levelp,
765                int *fletcher32p, int *contiguousp, size_t *chunksizesp,
766                int *no_fill, void *fill_valuep, int *endiannessp,
767 	       unsigned int* unused1, size_t* unused2, unsigned int* unused3
768                )
769 {
770    NC* ncp;
771    int stat = NC_check_id(ncid,&ncp);
772    if(stat != NC_NOERR) return stat;
773    return ncp->dispatch->inq_var_all(
774       ncid, varid, name, xtypep,
775       ndimsp, dimidsp, nattsp,
776       shufflep, deflatep, deflate_levelp, fletcher32p,
777       contiguousp, chunksizesp,
778       no_fill, fill_valuep,
779       endiannessp,
780       NULL, NULL, NULL);
781 }
782 #endif
783 
784 /*! \} */  /* End of named group ...*/
785