NetCDF  4.8.1
nc4var.c
Go to the documentation of this file.
1 /* Copyright 2003-2018, University Corporation for Atmospheric
2  * Research. See COPYRIGHT file for copying and redistribution
3  * conditions.*/
13 #include "config.h"
14 #include "nc4internal.h"
15 #include "nc4dispatch.h"
16 #ifdef USE_HDF5
17 #include "hdf5internal.h"
18 #endif
19 #include <math.h>
20 
22 #define DEFAULT_1D_UNLIM_SIZE (4096)
23 
40 int
41 NC4_get_var_chunk_cache(int ncid, int varid, size_t *sizep,
42  size_t *nelemsp, float *preemptionp)
43 {
44  NC *nc;
45  NC_GRP_INFO_T *grp;
46  NC_FILE_INFO_T *h5;
47  NC_VAR_INFO_T *var;
48  int retval;
49 
50  /* Find info for this file and group, and set pointer to each. */
51  if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
52  return retval;
53  assert(nc && grp && h5);
54 
55  /* Find the var. */
56  var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
57  if(!var)
58  return NC_ENOTVAR;
59  assert(var && var->hdr.id == varid);
60 
61  /* Give the user what they want. */
62  if (sizep)
63  *sizep = var->chunk_cache_size;
64  if (nelemsp)
65  *nelemsp = var->chunk_cache_nelems;
66  if (preemptionp)
67  *preemptionp = var->chunk_cache_preemption;
68 
69  return NC_NOERR;
70 }
71 
88 int
89 nc_get_var_chunk_cache_ints(int ncid, int varid, int *sizep,
90  int *nelemsp, int *preemptionp)
91 {
92  size_t real_size, real_nelems;
93  float real_preemption;
94  int ret;
95 
96  if ((ret = NC4_get_var_chunk_cache(ncid, varid, &real_size,
97  &real_nelems, &real_preemption)))
98  return ret;
99 
100  if (sizep)
101  *sizep = real_size / MEGABYTE;
102  if (nelemsp)
103  *nelemsp = (int)real_nelems;
104  if(preemptionp)
105  *preemptionp = (int)(real_preemption * 100);
106 
107  return NC_NOERR;
108 }
109 
147 int
148 NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
149  int *ndimsp, int *dimidsp, int *nattsp,
150  int *shufflep, int *deflatep, int *deflate_levelp,
151  int *fletcher32p, int *storagep, size_t *chunksizesp,
152  int *no_fill, void *fill_valuep, int *endiannessp,
153  unsigned int *idp, size_t *nparamsp, unsigned int *params)
154 {
155  NC_GRP_INFO_T *grp;
156  NC_FILE_INFO_T *h5;
157  NC_VAR_INFO_T *var;
158  int d;
159  int retval;
160 
161  LOG((2, "%s: ncid 0x%x varid %d", __func__, ncid, varid));
162 
163  /* Find info for this file and group, and set pointer to each. */
164  if ((retval = nc4_find_nc_grp_h5(ncid, NULL, &grp, &h5)))
165  return retval;
166  assert(grp && h5);
167 
168  /* If the varid is -1, find the global atts and call it a day. */
169  if (varid == NC_GLOBAL && nattsp)
170  {
171  *nattsp = ncindexcount(grp->att);
172  return NC_NOERR;
173  }
174 
175  /* Find the var. */
176  if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
177  return NC_ENOTVAR;
178  assert(var && var->hdr.id == varid);
179 
180  /* Copy the data to the user's data buffers. */
181  if (name)
182  strcpy(name, var->hdr.name);
183  if (xtypep)
184  *xtypep = var->type_info->hdr.id;
185  if (ndimsp)
186  *ndimsp = var->ndims;
187  if (dimidsp)
188  for (d = 0; d < var->ndims; d++)
189  dimidsp[d] = var->dimids[d];
190  if (nattsp)
191  *nattsp = ncindexcount(var->att);
192 
193  /* Did the user want the chunksizes? */
194  if (var->storage == NC_CHUNKED && chunksizesp)
195  {
196  for (d = 0; d < var->ndims; d++)
197  {
198  chunksizesp[d] = var->chunksizes[d];
199  LOG((4, "chunksizesp[%d]=%d", d, chunksizesp[d]));
200  }
201  }
202 
203  /* Did the user inquire about the storage? */
204  if (storagep)
205  *storagep = var->storage;
206 
207  /* Filter stuff. */
208  if (shufflep)
209  *shufflep = (int)var->shuffle;
210  if (fletcher32p)
211  *fletcher32p = (int)var->fletcher32;
212 
213  if (deflatep)
214  return NC_EFILTER;
215 
216  if (idp) {
217  return NC_EFILTER;
218  }
219 
220  /* Fill value stuff. */
221  if (no_fill)
222  *no_fill = (int)var->no_fill;
223 
224  /* Don't do a thing with fill_valuep if no_fill mode is set for
225  * this var, or if fill_valuep is NULL. */
226  if (!var->no_fill && fill_valuep)
227  {
228  /* Do we have a fill value for this var? */
229  if (var->fill_value)
230  {
231  if (var->type_info->nc_type_class == NC_STRING)
232  {
233  assert(*(char **)var->fill_value);
234  /* This will allocate memory and copy the string. */
235  if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value)))
236  {
237  free(*(char **)fill_valuep);
238  return NC_ENOMEM;
239  }
240  }
241  else
242  {
243  assert(var->type_info->size);
244  memcpy(fill_valuep, var->fill_value, var->type_info->size);
245  }
246  }
247  else
248  {
249  if (var->type_info->nc_type_class == NC_STRING)
250  {
251  if (!(*(char **)fill_valuep = calloc(1, sizeof(char *))))
252  return NC_ENOMEM;
253 
254  if ((retval = nc4_get_default_fill_value(var->type_info->hdr.id, (char **)fill_valuep)))
255  {
256  free(*(char **)fill_valuep);
257  return retval;
258  }
259  }
260  else
261  {
262  if ((retval = nc4_get_default_fill_value(var->type_info->hdr.id, fill_valuep)))
263  return retval;
264  }
265  }
266  }
267 
268  /* Does the user want the endianness of this variable? */
269  if (endiannessp)
270  *endiannessp = var->endianness;
271 
272  return NC_NOERR;
273 }
274 
291 int
292 nc_inq_var_chunking_ints(int ncid, int varid, int *storagep, int *chunksizesp)
293 {
294  NC_VAR_INFO_T *var;
295  size_t *cs = NULL;
296  int i, retval;
297 
298  /* Get pointer to the var. */
299  if ((retval = nc4_find_grp_h5_var(ncid, varid, NULL, NULL, &var)))
300  return retval;
301  assert(var);
302 
303  /* Allocate space for the size_t copy of the chunksizes array. */
304  if (var->ndims)
305  if (!(cs = malloc(var->ndims * sizeof(size_t))))
306  return NC_ENOMEM;
307 
308  /* Call the netcdf-4 version directly. */
309  retval = NC4_inq_var_all(ncid, varid, NULL, NULL, NULL, NULL, NULL,
310  NULL, NULL, NULL, NULL, storagep, cs, NULL,
311  NULL, NULL, NULL, NULL, NULL);
312 
313  /* Copy from size_t array. */
314  if (!retval && chunksizesp && var->storage == NC_CHUNKED)
315  {
316  for (i = 0; i < var->ndims; i++)
317  {
318  chunksizesp[i] = (int)cs[i];
319  if (cs[i] > NC_MAX_INT)
320  retval = NC_ERANGE;
321  }
322  }
323 
324  if (var->ndims)
325  free(cs);
326  return retval;
327 }
328 
341 int
342 NC4_inq_varid(int ncid, const char *name, int *varidp)
343 {
344  NC *nc;
345  NC_GRP_INFO_T *grp;
346  NC_VAR_INFO_T *var;
347  char norm_name[NC_MAX_NAME + 1];
348  int retval;
349 
350  if (!name)
351  return NC_EINVAL;
352  if (!varidp)
353  return NC_NOERR;
354 
355  LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));
356 
357  /* Find info for this file and group, and set pointer to each. */
358  if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, NULL)))
359  return retval;
360 
361  /* Normalize name. */
362  if ((retval = nc4_normalize_name(name, norm_name)))
363  return retval;
364 
365  /* Find var of this name. */
366  var = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,norm_name);
367  if(var)
368  {
369  *varidp = var->hdr.id;
370  return NC_NOERR;
371  }
372  return NC_ENOTVAR;
373 }
374 
393 int
394 NC4_var_par_access(int ncid, int varid, int par_access)
395 {
396 #ifndef USE_PARALLEL4
397  NC_UNUSED(ncid);
398  NC_UNUSED(varid);
399  NC_UNUSED(par_access);
400  return NC_ENOPAR;
401 #else
402  NC *nc;
403  NC_GRP_INFO_T *grp;
404  NC_FILE_INFO_T *h5;
405  NC_VAR_INFO_T *var;
406  int retval;
407 
408  LOG((1, "%s: ncid 0x%x varid %d par_access %d", __func__, ncid,
409  varid, par_access));
410 
411  if (par_access != NC_INDEPENDENT && par_access != NC_COLLECTIVE)
412  return NC_EINVAL;
413 
414  /* Find info for this file and group, and set pointer to each. */
415  if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
416  return retval;
417 
418  /* This function only for files opened with nc_open_par or nc_create_par. */
419  if (!h5->parallel)
420  return NC_ENOPAR;
421 
422  /* Find the var, and set its preference. */
423  var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
424  if (!var) return NC_ENOTVAR;
425  assert(var->hdr.id == varid);
426 
427  /* If zlib, shuffle, or fletcher32 filters are in use, then access
428  * must be collective. Fail an attempt to set such a variable to
429  * independent access. */
430  if ((nclistlength((NClist*)var->filters) > 0 || var->shuffle || var->fletcher32) &&
431  par_access == NC_INDEPENDENT)
432  return NC_EINVAL;
433 
434  if (par_access)
435  var->parallel_access = NC_COLLECTIVE;
436  else
437  var->parallel_access = NC_INDEPENDENT;
438  return NC_NOERR;
439 #endif /* USE_PARALLEL4 */
440 }
441 
464 int
465 nc4_convert_type(const void *src, void *dest, const nc_type src_type,
466  const nc_type dest_type, const size_t len, int *range_error,
467  const void *fill_value, int strict_nc3)
468 {
469  char *cp, *cp1;
470  float *fp, *fp1;
471  double *dp, *dp1;
472  int *ip, *ip1;
473  short *sp, *sp1;
474  signed char *bp, *bp1;
475  unsigned char *ubp, *ubp1;
476  unsigned short *usp, *usp1;
477  unsigned int *uip, *uip1;
478  long long *lip, *lip1;
479  unsigned long long *ulip, *ulip1;
480  size_t count = 0;
481 
482  *range_error = 0;
483  LOG((3, "%s: len %d src_type %d dest_type %d", __func__, len, src_type,
484  dest_type));
485 
486  /* OK, this is ugly. If you can think of anything better, I'm open
487  to suggestions!
488 
489  Note that we don't use a default fill value for type
490  NC_BYTE. This is because Lord Voldemort cast a nofilleramous spell
491  at Harry Potter, but it bounced off his scar and hit the netcdf-4
492  code.
493  */
494  switch (src_type)
495  {
496  case NC_CHAR:
497  switch (dest_type)
498  {
499  case NC_CHAR:
500  for (cp = (char *)src, cp1 = dest; count < len; count++)
501  *cp1++ = *cp++;
502  break;
503  default:
504  LOG((0, "%s: Unknown destination type.", __func__));
505  }
506  break;
507 
508  case NC_BYTE:
509  switch (dest_type)
510  {
511  case NC_BYTE:
512  for (bp = (signed char *)src, bp1 = dest; count < len; count++)
513  *bp1++ = *bp++;
514  break;
515  case NC_UBYTE:
516  for (bp = (signed char *)src, ubp = dest; count < len; count++)
517  {
518  if (*bp < 0)
519  (*range_error)++;
520  *ubp++ = *bp++;
521  }
522  break;
523  case NC_SHORT:
524  for (bp = (signed char *)src, sp = dest; count < len; count++)
525  *sp++ = *bp++;
526  break;
527  case NC_USHORT:
528  for (bp = (signed char *)src, usp = dest; count < len; count++)
529  {
530  if (*bp < 0)
531  (*range_error)++;
532  *usp++ = *bp++;
533  }
534  break;
535  case NC_INT:
536  for (bp = (signed char *)src, ip = dest; count < len; count++)
537  *ip++ = *bp++;
538  break;
539  case NC_UINT:
540  for (bp = (signed char *)src, uip = dest; count < len; count++)
541  {
542  if (*bp < 0)
543  (*range_error)++;
544  *uip++ = *bp++;
545  }
546  break;
547  case NC_INT64:
548  for (bp = (signed char *)src, lip = dest; count < len; count++)
549  *lip++ = *bp++;
550  break;
551  case NC_UINT64:
552  for (bp = (signed char *)src, ulip = dest; count < len; count++)
553  {
554  if (*bp < 0)
555  (*range_error)++;
556  *ulip++ = *bp++;
557  }
558  break;
559  case NC_FLOAT:
560  for (bp = (signed char *)src, fp = dest; count < len; count++)
561  *fp++ = *bp++;
562  break;
563  case NC_DOUBLE:
564  for (bp = (signed char *)src, dp = dest; count < len; count++)
565  *dp++ = *bp++;
566  break;
567  default:
568  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
569  __func__, src_type, dest_type));
570  return NC_EBADTYPE;
571  }
572  break;
573 
574  case NC_UBYTE:
575  switch (dest_type)
576  {
577  case NC_BYTE:
578  for (ubp = (unsigned char *)src, bp = dest; count < len; count++)
579  {
580  if (!strict_nc3 && *ubp > X_SCHAR_MAX)
581  (*range_error)++;
582  *bp++ = *ubp++;
583  }
584  break;
585  case NC_SHORT:
586  for (ubp = (unsigned char *)src, sp = dest; count < len; count++)
587  *sp++ = *ubp++;
588  break;
589  case NC_UBYTE:
590  for (ubp = (unsigned char *)src, ubp1 = dest; count < len; count++)
591  *ubp1++ = *ubp++;
592  break;
593  case NC_USHORT:
594  for (ubp = (unsigned char *)src, usp = dest; count < len; count++)
595  *usp++ = *ubp++;
596  break;
597  case NC_INT:
598  for (ubp = (unsigned char *)src, ip = dest; count < len; count++)
599  *ip++ = *ubp++;
600  break;
601  case NC_UINT:
602  for (ubp = (unsigned char *)src, uip = dest; count < len; count++)
603  *uip++ = *ubp++;
604  break;
605  case NC_INT64:
606  for (ubp = (unsigned char *)src, lip = dest; count < len; count++)
607  *lip++ = *ubp++;
608  break;
609  case NC_UINT64:
610  for (ubp = (unsigned char *)src, ulip = dest; count < len; count++)
611  *ulip++ = *ubp++;
612  break;
613  case NC_FLOAT:
614  for (ubp = (unsigned char *)src, fp = dest; count < len; count++)
615  *fp++ = *ubp++;
616  break;
617  case NC_DOUBLE:
618  for (ubp = (unsigned char *)src, dp = dest; count < len; count++)
619  *dp++ = *ubp++;
620  break;
621  default:
622  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
623  __func__, src_type, dest_type));
624  return NC_EBADTYPE;
625  }
626  break;
627 
628  case NC_SHORT:
629  switch (dest_type)
630  {
631  case NC_UBYTE:
632  for (sp = (short *)src, ubp = dest; count < len; count++)
633  {
634  if (*sp > X_UCHAR_MAX || *sp < 0)
635  (*range_error)++;
636  *ubp++ = *sp++;
637  }
638  break;
639  case NC_BYTE:
640  for (sp = (short *)src, bp = dest; count < len; count++)
641  {
642  if (*sp > X_SCHAR_MAX || *sp < X_SCHAR_MIN)
643  (*range_error)++;
644  *bp++ = *sp++;
645  }
646  break;
647  case NC_SHORT:
648  for (sp = (short *)src, sp1 = dest; count < len; count++)
649  *sp1++ = *sp++;
650  break;
651  case NC_USHORT:
652  for (sp = (short *)src, usp = dest; count < len; count++)
653  {
654  if (*sp < 0)
655  (*range_error)++;
656  *usp++ = *sp++;
657  }
658  break;
659  case NC_INT:
660  for (sp = (short *)src, ip = dest; count < len; count++)
661  *ip++ = *sp++;
662  break;
663  case NC_UINT:
664  for (sp = (short *)src, uip = dest; count < len; count++)
665  {
666  if (*sp < 0)
667  (*range_error)++;
668  *uip++ = *sp++;
669  }
670  break;
671  case NC_INT64:
672  for (sp = (short *)src, lip = dest; count < len; count++)
673  *lip++ = *sp++;
674  break;
675  case NC_UINT64:
676  for (sp = (short *)src, ulip = dest; count < len; count++)
677  {
678  if (*sp < 0)
679  (*range_error)++;
680  *ulip++ = *sp++;
681  }
682  break;
683  case NC_FLOAT:
684  for (sp = (short *)src, fp = dest; count < len; count++)
685  *fp++ = *sp++;
686  break;
687  case NC_DOUBLE:
688  for (sp = (short *)src, dp = dest; count < len; count++)
689  *dp++ = *sp++;
690  break;
691  default:
692  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
693  __func__, src_type, dest_type));
694  return NC_EBADTYPE;
695  }
696  break;
697 
698  case NC_USHORT:
699  switch (dest_type)
700  {
701  case NC_UBYTE:
702  for (usp = (unsigned short *)src, ubp = dest; count < len; count++)
703  {
704  if (*usp > X_UCHAR_MAX)
705  (*range_error)++;
706  *ubp++ = *usp++;
707  }
708  break;
709  case NC_BYTE:
710  for (usp = (unsigned short *)src, bp = dest; count < len; count++)
711  {
712  if (*usp > X_SCHAR_MAX)
713  (*range_error)++;
714  *bp++ = *usp++;
715  }
716  break;
717  case NC_SHORT:
718  for (usp = (unsigned short *)src, sp = dest; count < len; count++)
719  {
720  if (*usp > X_SHORT_MAX)
721  (*range_error)++;
722  *sp++ = *usp++;
723  }
724  break;
725  case NC_USHORT:
726  for (usp = (unsigned short *)src, usp1 = dest; count < len; count++)
727  *usp1++ = *usp++;
728  break;
729  case NC_INT:
730  for (usp = (unsigned short *)src, ip = dest; count < len; count++)
731  *ip++ = *usp++;
732  break;
733  case NC_UINT:
734  for (usp = (unsigned short *)src, uip = dest; count < len; count++)
735  *uip++ = *usp++;
736  break;
737  case NC_INT64:
738  for (usp = (unsigned short *)src, lip = dest; count < len; count++)
739  *lip++ = *usp++;
740  break;
741  case NC_UINT64:
742  for (usp = (unsigned short *)src, ulip = dest; count < len; count++)
743  *ulip++ = *usp++;
744  break;
745  case NC_FLOAT:
746  for (usp = (unsigned short *)src, fp = dest; count < len; count++)
747  *fp++ = *usp++;
748  break;
749  case NC_DOUBLE:
750  for (usp = (unsigned short *)src, dp = dest; count < len; count++)
751  *dp++ = *usp++;
752  break;
753  default:
754  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
755  __func__, src_type, dest_type));
756  return NC_EBADTYPE;
757  }
758  break;
759 
760  case NC_INT:
761  switch (dest_type)
762  {
763  case NC_UBYTE:
764  for (ip = (int *)src, ubp = dest; count < len; count++)
765  {
766  if (*ip > X_UCHAR_MAX || *ip < 0)
767  (*range_error)++;
768  *ubp++ = *ip++;
769  }
770  break;
771  case NC_BYTE:
772  for (ip = (int *)src, bp = dest; count < len; count++)
773  {
774  if (*ip > X_SCHAR_MAX || *ip < X_SCHAR_MIN)
775  (*range_error)++;
776  *bp++ = *ip++;
777  }
778  break;
779  case NC_SHORT:
780  for (ip = (int *)src, sp = dest; count < len; count++)
781  {
782  if (*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
783  (*range_error)++;
784  *sp++ = *ip++;
785  }
786  break;
787  case NC_USHORT:
788  for (ip = (int *)src, usp = dest; count < len; count++)
789  {
790  if (*ip > X_USHORT_MAX || *ip < 0)
791  (*range_error)++;
792  *usp++ = *ip++;
793  }
794  break;
795  case NC_INT: /* src is int */
796  for (ip = (int *)src, ip1 = dest; count < len; count++)
797  {
798  if (*ip > X_INT_MAX || *ip < X_INT_MIN)
799  (*range_error)++;
800  *ip1++ = *ip++;
801  }
802  break;
803  case NC_UINT:
804  for (ip = (int *)src, uip = dest; count < len; count++)
805  {
806  if (*ip > X_UINT_MAX || *ip < 0)
807  (*range_error)++;
808  *uip++ = *ip++;
809  }
810  break;
811  case NC_INT64:
812  for (ip = (int *)src, lip = dest; count < len; count++)
813  *lip++ = *ip++;
814  break;
815  case NC_UINT64:
816  for (ip = (int *)src, ulip = dest; count < len; count++)
817  {
818  if (*ip < 0)
819  (*range_error)++;
820  *ulip++ = *ip++;
821  }
822  break;
823  case NC_FLOAT:
824  for (ip = (int *)src, fp = dest; count < len; count++)
825  *fp++ = *ip++;
826  break;
827  case NC_DOUBLE:
828  for (ip = (int *)src, dp = dest; count < len; count++)
829  *dp++ = *ip++;
830  break;
831  default:
832  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
833  __func__, src_type, dest_type));
834  return NC_EBADTYPE;
835  }
836  break;
837 
838  case NC_UINT:
839  switch (dest_type)
840  {
841  case NC_UBYTE:
842  for (uip = (unsigned int *)src, ubp = dest; count < len; count++)
843  {
844  if (*uip > X_UCHAR_MAX)
845  (*range_error)++;
846  *ubp++ = *uip++;
847  }
848  break;
849  case NC_BYTE:
850  for (uip = (unsigned int *)src, bp = dest; count < len; count++)
851  {
852  if (*uip > X_SCHAR_MAX)
853  (*range_error)++;
854  *bp++ = *uip++;
855  }
856  break;
857  case NC_SHORT:
858  for (uip = (unsigned int *)src, sp = dest; count < len; count++)
859  {
860  if (*uip > X_SHORT_MAX)
861  (*range_error)++;
862  *sp++ = *uip++;
863  }
864  break;
865  case NC_USHORT:
866  for (uip = (unsigned int *)src, usp = dest; count < len; count++)
867  {
868  if (*uip > X_USHORT_MAX)
869  (*range_error)++;
870  *usp++ = *uip++;
871  }
872  break;
873  case NC_INT:
874  for (uip = (unsigned int *)src, ip = dest; count < len; count++)
875  {
876  if (*uip > X_INT_MAX)
877  (*range_error)++;
878  *ip++ = *uip++;
879  }
880  break;
881  case NC_UINT:
882  for (uip = (unsigned int *)src, uip1 = dest; count < len; count++)
883  {
884  if (*uip > X_UINT_MAX)
885  (*range_error)++;
886  *uip1++ = *uip++;
887  }
888  break;
889  case NC_INT64:
890  for (uip = (unsigned int *)src, lip = dest; count < len; count++)
891  *lip++ = *uip++;
892  break;
893  case NC_UINT64:
894  for (uip = (unsigned int *)src, ulip = dest; count < len; count++)
895  *ulip++ = *uip++;
896  break;
897  case NC_FLOAT:
898  for (uip = (unsigned int *)src, fp = dest; count < len; count++)
899  *fp++ = *uip++;
900  break;
901  case NC_DOUBLE:
902  for (uip = (unsigned int *)src, dp = dest; count < len; count++)
903  *dp++ = *uip++;
904  break;
905  default:
906  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
907  __func__, src_type, dest_type));
908  return NC_EBADTYPE;
909  }
910  break;
911 
912  case NC_INT64:
913  switch (dest_type)
914  {
915  case NC_UBYTE:
916  for (lip = (long long *)src, ubp = dest; count < len; count++)
917  {
918  if (*lip > X_UCHAR_MAX || *lip < 0)
919  (*range_error)++;
920  *ubp++ = *lip++;
921  }
922  break;
923  case NC_BYTE:
924  for (lip = (long long *)src, bp = dest; count < len; count++)
925  {
926  if (*lip > X_SCHAR_MAX || *lip < X_SCHAR_MIN)
927  (*range_error)++;
928  *bp++ = *lip++;
929  }
930  break;
931  case NC_SHORT:
932  for (lip = (long long *)src, sp = dest; count < len; count++)
933  {
934  if (*lip > X_SHORT_MAX || *lip < X_SHORT_MIN)
935  (*range_error)++;
936  *sp++ = *lip++;
937  }
938  break;
939  case NC_USHORT:
940  for (lip = (long long *)src, usp = dest; count < len; count++)
941  {
942  if (*lip > X_USHORT_MAX || *lip < 0)
943  (*range_error)++;
944  *usp++ = *lip++;
945  }
946  break;
947  case NC_UINT:
948  for (lip = (long long *)src, uip = dest; count < len; count++)
949  {
950  if (*lip > X_UINT_MAX || *lip < 0)
951  (*range_error)++;
952  *uip++ = *lip++;
953  }
954  break;
955  case NC_INT:
956  for (lip = (long long *)src, ip = dest; count < len; count++)
957  {
958  if (*lip > X_INT_MAX || *lip < X_INT_MIN)
959  (*range_error)++;
960  *ip++ = *lip++;
961  }
962  break;
963  case NC_INT64:
964  for (lip = (long long *)src, lip1 = dest; count < len; count++)
965  *lip1++ = *lip++;
966  break;
967  case NC_UINT64:
968  for (lip = (long long *)src, ulip = dest; count < len; count++)
969  {
970  if (*lip < 0)
971  (*range_error)++;
972  *ulip++ = *lip++;
973  }
974  break;
975  case NC_FLOAT:
976  for (lip = (long long *)src, fp = dest; count < len; count++)
977  *fp++ = *lip++;
978  break;
979  case NC_DOUBLE:
980  for (lip = (long long *)src, dp = dest; count < len; count++)
981  *dp++ = *lip++;
982  break;
983  default:
984  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
985  __func__, src_type, dest_type));
986  return NC_EBADTYPE;
987  }
988  break;
989 
990  case NC_UINT64:
991  switch (dest_type)
992  {
993  case NC_UBYTE:
994  for (ulip = (unsigned long long *)src, ubp = dest; count < len; count++)
995  {
996  if (*ulip > X_UCHAR_MAX)
997  (*range_error)++;
998  *ubp++ = *ulip++;
999  }
1000  break;
1001  case NC_BYTE:
1002  for (ulip = (unsigned long long *)src, bp = dest; count < len; count++)
1003  {
1004  if (*ulip > X_SCHAR_MAX)
1005  (*range_error)++;
1006  *bp++ = *ulip++;
1007  }
1008  break;
1009  case NC_SHORT:
1010  for (ulip = (unsigned long long *)src, sp = dest; count < len; count++)
1011  {
1012  if (*ulip > X_SHORT_MAX)
1013  (*range_error)++;
1014  *sp++ = *ulip++;
1015  }
1016  break;
1017  case NC_USHORT:
1018  for (ulip = (unsigned long long *)src, usp = dest; count < len; count++)
1019  {
1020  if (*ulip > X_USHORT_MAX)
1021  (*range_error)++;
1022  *usp++ = *ulip++;
1023  }
1024  break;
1025  case NC_UINT:
1026  for (ulip = (unsigned long long *)src, uip = dest; count < len; count++)
1027  {
1028  if (*ulip > X_UINT_MAX)
1029  (*range_error)++;
1030  *uip++ = *ulip++;
1031  }
1032  break;
1033  case NC_INT:
1034  for (ulip = (unsigned long long *)src, ip = dest; count < len; count++)
1035  {
1036  if (*ulip > X_INT_MAX)
1037  (*range_error)++;
1038  *ip++ = *ulip++;
1039  }
1040  break;
1041  case NC_INT64:
1042  for (ulip = (unsigned long long *)src, lip = dest; count < len; count++)
1043  {
1044  if (*ulip > X_INT64_MAX)
1045  (*range_error)++;
1046  *lip++ = *ulip++;
1047  }
1048  break;
1049  case NC_UINT64:
1050  for (ulip = (unsigned long long *)src, ulip1 = dest; count < len; count++)
1051  *ulip1++ = *ulip++;
1052  break;
1053  case NC_FLOAT:
1054  for (ulip = (unsigned long long *)src, fp = dest; count < len; count++)
1055  *fp++ = *ulip++;
1056  break;
1057  case NC_DOUBLE:
1058  for (ulip = (unsigned long long *)src, dp = dest; count < len; count++)
1059  *dp++ = *ulip++;
1060  break;
1061  default:
1062  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
1063  __func__, src_type, dest_type));
1064  return NC_EBADTYPE;
1065  }
1066  break;
1067 
1068  case NC_FLOAT:
1069  switch (dest_type)
1070  {
1071  case NC_UBYTE:
1072  for (fp = (float *)src, ubp = dest; count < len; count++)
1073  {
1074  if (*fp > X_UCHAR_MAX || *fp < 0)
1075  (*range_error)++;
1076  *ubp++ = *fp++;
1077  }
1078  break;
1079  case NC_BYTE:
1080  for (fp = (float *)src, bp = dest; count < len; count++)
1081  {
1082  if (*fp > (double)X_SCHAR_MAX || *fp < (double)X_SCHAR_MIN)
1083  (*range_error)++;
1084  *bp++ = *fp++;
1085  }
1086  break;
1087  case NC_SHORT:
1088  for (fp = (float *)src, sp = dest; count < len; count++)
1089  {
1090  if (*fp > (double)X_SHORT_MAX || *fp < (double)X_SHORT_MIN)
1091  (*range_error)++;
1092  *sp++ = *fp++;
1093  }
1094  break;
1095  case NC_USHORT:
1096  for (fp = (float *)src, usp = dest; count < len; count++)
1097  {
1098  if (*fp > X_USHORT_MAX || *fp < 0)
1099  (*range_error)++;
1100  *usp++ = *fp++;
1101  }
1102  break;
1103  case NC_UINT:
1104  for (fp = (float *)src, uip = dest; count < len; count++)
1105  {
1106  if (*fp > X_UINT_MAX || *fp < 0)
1107  (*range_error)++;
1108  *uip++ = *fp++;
1109  }
1110  break;
1111  case NC_INT:
1112  for (fp = (float *)src, ip = dest; count < len; count++)
1113  {
1114  if (*fp > (double)X_INT_MAX || *fp < (double)X_INT_MIN)
1115  (*range_error)++;
1116  *ip++ = *fp++;
1117  }
1118  break;
1119  case NC_INT64:
1120  for (fp = (float *)src, lip = dest; count < len; count++)
1121  {
1122  if (*fp > X_INT64_MAX || *fp <X_INT64_MIN)
1123  (*range_error)++;
1124  *lip++ = *fp++;
1125  }
1126  break;
1127  case NC_UINT64:
1128  for (fp = (float *)src, lip = dest; count < len; count++)
1129  {
1130  if (*fp > X_UINT64_MAX || *fp < 0)
1131  (*range_error)++;
1132  *lip++ = *fp++;
1133  }
1134  break;
1135  case NC_FLOAT:
1136  for (fp = (float *)src, fp1 = dest; count < len; count++)
1137  {
1138  /* if (*fp > X_FLOAT_MAX || *fp < X_FLOAT_MIN)
1139  (*range_error)++;*/
1140  *fp1++ = *fp++;
1141  }
1142  break;
1143  case NC_DOUBLE:
1144  for (fp = (float *)src, dp = dest; count < len; count++)
1145  *dp++ = *fp++;
1146  break;
1147  default:
1148  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
1149  __func__, src_type, dest_type));
1150  return NC_EBADTYPE;
1151  }
1152  break;
1153 
1154  case NC_DOUBLE:
1155  switch (dest_type)
1156  {
1157  case NC_UBYTE:
1158  for (dp = (double *)src, ubp = dest; count < len; count++)
1159  {
1160  if (*dp > X_UCHAR_MAX || *dp < 0)
1161  (*range_error)++;
1162  *ubp++ = *dp++;
1163  }
1164  break;
1165  case NC_BYTE:
1166  for (dp = (double *)src, bp = dest; count < len; count++)
1167  {
1168  if (*dp > X_SCHAR_MAX || *dp < X_SCHAR_MIN)
1169  (*range_error)++;
1170  *bp++ = *dp++;
1171  }
1172  break;
1173  case NC_SHORT:
1174  for (dp = (double *)src, sp = dest; count < len; count++)
1175  {
1176  if (*dp > X_SHORT_MAX || *dp < X_SHORT_MIN)
1177  (*range_error)++;
1178  *sp++ = *dp++;
1179  }
1180  break;
1181  case NC_USHORT:
1182  for (dp = (double *)src, usp = dest; count < len; count++)
1183  {
1184  if (*dp > X_USHORT_MAX || *dp < 0)
1185  (*range_error)++;
1186  *usp++ = *dp++;
1187  }
1188  break;
1189  case NC_UINT:
1190  for (dp = (double *)src, uip = dest; count < len; count++)
1191  {
1192  if (*dp > X_UINT_MAX || *dp < 0)
1193  (*range_error)++;
1194  *uip++ = *dp++;
1195  }
1196  break;
1197  case NC_INT:
1198  for (dp = (double *)src, ip = dest; count < len; count++)
1199  {
1200  if (*dp > X_INT_MAX || *dp < X_INT_MIN)
1201  (*range_error)++;
1202  *ip++ = *dp++;
1203  }
1204  break;
1205  case NC_INT64:
1206  for (dp = (double *)src, lip = dest; count < len; count++)
1207  {
1208  if (*dp > X_INT64_MAX || *dp < X_INT64_MIN)
1209  (*range_error)++;
1210  *lip++ = *dp++;
1211  }
1212  break;
1213  case NC_UINT64:
1214  for (dp = (double *)src, lip = dest; count < len; count++)
1215  {
1216  if (*dp > X_UINT64_MAX || *dp < 0)
1217  (*range_error)++;
1218  *lip++ = *dp++;
1219  }
1220  break;
1221  case NC_FLOAT:
1222  for (dp = (double *)src, fp = dest; count < len; count++)
1223  {
1224  if (isgreater(*dp, X_FLOAT_MAX) || isless(*dp, X_FLOAT_MIN))
1225  (*range_error)++;
1226  *fp++ = *dp++;
1227  }
1228  break;
1229  case NC_DOUBLE:
1230  for (dp = (double *)src, dp1 = dest; count < len; count++)
1231  {
1232  /* if (*dp > X_DOUBLE_MAX || *dp < X_DOUBLE_MIN) */
1233  /* (*range_error)++; */
1234  *dp1++ = *dp++;
1235  }
1236  break;
1237  default:
1238  LOG((0, "%s: unexpected dest type. src_type %d, dest_type %d",
1239  __func__, src_type, dest_type));
1240  return NC_EBADTYPE;
1241  }
1242  break;
1243 
1244  default:
1245  LOG((0, "%s: unexpected src type. src_type %d, dest_type %d",
1246  __func__, src_type, dest_type));
1247  return NC_EBADTYPE;
1248  }
1249  return NC_NOERR;
1250 }
1251 
1263 int
1264 nc4_get_fill_value(NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var, void **fillp)
1265 {
1266  size_t size;
1267  int retval;
1268 
1269  /* Find out how much space we need for this type's fill value. */
1270  if (var->type_info->nc_type_class == NC_VLEN)
1271  size = sizeof(nc_vlen_t);
1272  else if (var->type_info->nc_type_class == NC_STRING)
1273  size = sizeof(char *);
1274  else
1275  {
1276  if ((retval = nc4_get_typelen_mem(h5, var->type_info->hdr.id, &size)))
1277  return retval;
1278  }
1279  assert(size);
1280 
1281  /* Allocate the space. */
1282  if (!((*fillp) = calloc(1, size)))
1283  return NC_ENOMEM;
1284 
1285  /* If the user has set a fill_value for this var, use, otherwise
1286  * find the default fill value. */
1287  if (var->fill_value)
1288  {
1289  LOG((4, "Found a fill value for var %s", var->hdr.name));
1290  if (var->type_info->nc_type_class == NC_VLEN)
1291  {
1292  nc_vlen_t *in_vlen = (nc_vlen_t *)(var->fill_value), *fv_vlen = (nc_vlen_t *)(*fillp);
1293  size_t basetypesize = 0;
1294 
1295  if((retval=nc4_get_typelen_mem(h5, var->type_info->u.v.base_nc_typeid, &basetypesize)))
1296  return retval;
1297 
1298  fv_vlen->len = in_vlen->len;
1299  if (!(fv_vlen->p = malloc(basetypesize * in_vlen->len)))
1300  {
1301  free(*fillp);
1302  *fillp = NULL;
1303  return NC_ENOMEM;
1304  }
1305  memcpy(fv_vlen->p, in_vlen->p, in_vlen->len * basetypesize);
1306  }
1307  else if (var->type_info->nc_type_class == NC_STRING)
1308  {
1309  if (*(char **)var->fill_value)
1310  if (!(**(char ***)fillp = strdup(*(char **)var->fill_value)))
1311  {
1312  free(*fillp);
1313  *fillp = NULL;
1314  return NC_ENOMEM;
1315  }
1316  }
1317  else
1318  memcpy((*fillp), var->fill_value, size);
1319  }
1320  else
1321  {
1322  if (nc4_get_default_fill_value(var->type_info->hdr.id, *fillp))
1323  {
1324  /* Note: release memory, but don't return error on failure */
1325  free(*fillp);
1326  *fillp = NULL;
1327  }
1328  }
1329 
1330  return NC_NOERR;
1331 }
1332 
1344 int
1345 nc4_get_default_fill_value(nc_type typecode, void *fill_value)
1346 {
1347  switch (typecode)
1348  {
1349  case NC_CHAR:
1350  *(char *)fill_value = NC_FILL_CHAR;
1351  break;
1352 
1353  case NC_STRING:
1354  *(char **)fill_value = strdup(NC_FILL_STRING);
1355  break;
1356 
1357  case NC_BYTE:
1358  *(signed char *)fill_value = NC_FILL_BYTE;
1359  break;
1360 
1361  case NC_SHORT:
1362  *(short *)fill_value = NC_FILL_SHORT;
1363  break;
1364 
1365  case NC_INT:
1366  *(int *)fill_value = NC_FILL_INT;
1367  break;
1368 
1369  case NC_UBYTE:
1370  *(unsigned char *)fill_value = NC_FILL_UBYTE;
1371  break;
1372 
1373  case NC_USHORT:
1374  *(unsigned short *)fill_value = NC_FILL_USHORT;
1375  break;
1376 
1377  case NC_UINT:
1378  *(unsigned int *)fill_value = NC_FILL_UINT;
1379  break;
1380 
1381  case NC_INT64:
1382  *(long long *)fill_value = NC_FILL_INT64;
1383  break;
1384 
1385  case NC_UINT64:
1386  *(unsigned long long *)fill_value = NC_FILL_UINT64;
1387  break;
1388 
1389  case NC_FLOAT:
1390  *(float *)fill_value = NC_FILL_FLOAT;
1391  break;
1392 
1393  case NC_DOUBLE:
1394  *(double *)fill_value = NC_FILL_DOUBLE;
1395  break;
1396 
1397  default:
1398  return NC_EINVAL;
1399  }
1400 
1401  return NC_NOERR;
1402 }
1403 
1416 int
1417 nc4_get_typelen_mem(NC_FILE_INFO_T *h5, nc_type xtype, size_t *len)
1418 {
1419  NC_TYPE_INFO_T *type;
1420  int retval;
1421 
1422  LOG((4, "%s xtype: %d", __func__, xtype));
1423  assert(len);
1424 
1425  /* If this is an atomic type, the answer is easy. */
1426  switch (xtype)
1427  {
1428  case NC_BYTE:
1429  case NC_CHAR:
1430  case NC_UBYTE:
1431  *len = sizeof(char);
1432  return NC_NOERR;
1433  case NC_SHORT:
1434  case NC_USHORT:
1435  *len = sizeof(short);
1436  return NC_NOERR;
1437  case NC_INT:
1438  case NC_UINT:
1439  *len = sizeof(int);
1440  return NC_NOERR;
1441  case NC_FLOAT:
1442  *len = sizeof(float);
1443  return NC_NOERR;
1444  case NC_DOUBLE:
1445  *len = sizeof(double);
1446  return NC_NOERR;
1447  case NC_INT64:
1448  case NC_UINT64:
1449  *len = sizeof(long long);
1450  return NC_NOERR;
1451  case NC_STRING:
1452  *len = sizeof(char *);
1453  return NC_NOERR;
1454  }
1455 
1456  /* See if var is compound type. */
1457  if ((retval = nc4_find_type(h5, xtype, &type)))
1458  return retval;
1459 
1460  if (!type)
1461  return NC_EBADTYPE;
1462 
1463  *len = type->size;
1464 
1465  LOG((5, "type->size: %d", type->size));
1466 
1467  return NC_NOERR;
1468 }
1469 
1470 
1484 int
1485 nc4_check_chunksizes(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, const size_t *chunksizes)
1486 {
1487  double dprod;
1488  size_t type_len;
1489  int d;
1490  int retval;
1491 
1492  if ((retval = nc4_get_typelen_mem(grp->nc4_info, var->type_info->hdr.id, &type_len)))
1493  return retval;
1494  if (var->type_info->nc_type_class == NC_VLEN)
1495  dprod = (double)sizeof(nc_vlen_t);
1496  else
1497  dprod = (double)type_len;
1498  for (d = 0; d < var->ndims; d++)
1499  dprod *= (double)chunksizes[d];
1500 
1501  if (dprod > (double) NC_MAX_UINT)
1502  return NC_EBADCHUNK;
1503 
1504  return NC_NOERR;
1505 }
1506 
1518 int
1519 nc4_find_default_chunksizes2(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
1520 {
1521  int d;
1522  size_t type_size;
1523  float num_values = 1, num_unlim = 0;
1524  int retval;
1525  size_t suggested_size;
1526 #ifdef LOGGING
1527  double total_chunk_size;
1528 #endif
1529 
1530  if (var->type_info->nc_type_class == NC_STRING)
1531  type_size = sizeof(char *);
1532  else
1533  type_size = var->type_info->size;
1534 
1535 #ifdef LOGGING
1536  /* Later this will become the total number of bytes in the default
1537  * chunk. */
1538  total_chunk_size = (double) type_size;
1539 #endif
1540 
1541  if(var->chunksizes == NULL) {
1542  if((var->chunksizes = calloc(1,sizeof(size_t)*var->ndims)) == NULL)
1543  return NC_ENOMEM;
1544  }
1545 
1546  /* How many values in the variable (or one record, if there are
1547  * unlimited dimensions). */
1548  for (d = 0; d < var->ndims; d++)
1549  {
1550  assert(var->dim[d]);
1551  if (! var->dim[d]->unlimited)
1552  num_values *= (float)var->dim[d]->len;
1553  else {
1554  num_unlim++;
1555  var->chunksizes[d] = 1; /* overwritten below, if all dims are unlimited */
1556  }
1557  }
1558  /* Special case to avoid 1D vars with unlim dim taking huge amount
1559  of space (DEFAULT_CHUNK_SIZE bytes). Instead we limit to about
1560  4KB */
1561  if (var->ndims == 1 && num_unlim == 1) {
1562  if (DEFAULT_CHUNK_SIZE / type_size <= 0)
1563  suggested_size = 1;
1564  else if (DEFAULT_CHUNK_SIZE / type_size > DEFAULT_1D_UNLIM_SIZE)
1565  suggested_size = DEFAULT_1D_UNLIM_SIZE;
1566  else
1567  suggested_size = DEFAULT_CHUNK_SIZE / type_size;
1568  var->chunksizes[0] = suggested_size / type_size;
1569  LOG((4, "%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
1570  "chunksize %ld", __func__, var->hdr.name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[0]));
1571  }
1572  if (var->ndims > 1 && var->ndims == num_unlim) { /* all dims unlimited */
1573  suggested_size = pow((double)DEFAULT_CHUNK_SIZE/type_size, 1.0/(double)(var->ndims));
1574  for (d = 0; d < var->ndims; d++)
1575  {
1576  var->chunksizes[d] = suggested_size ? suggested_size : 1;
1577  LOG((4, "%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
1578  "chunksize %ld", __func__, var->hdr.name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
1579  }
1580  }
1581 
1582  /* Pick a chunk length for each dimension, if one has not already
1583  * been picked above. */
1584  for (d = 0; d < var->ndims; d++)
1585  if (!var->chunksizes[d])
1586  {
1587  suggested_size = (pow((double)DEFAULT_CHUNK_SIZE/(num_values * type_size),
1588  1.0/(double)(var->ndims - num_unlim)) * var->dim[d]->len - .5);
1589  if (suggested_size > var->dim[d]->len)
1590  suggested_size = var->dim[d]->len;
1591  var->chunksizes[d] = suggested_size ? suggested_size : 1;
1592  LOG((4, "%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
1593  "chunksize %ld", __func__, var->hdr.name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
1594  }
1595 
1596 #ifdef LOGGING
1597  /* Find total chunk size. */
1598  for (d = 0; d < var->ndims; d++)
1599  total_chunk_size *= (double) var->chunksizes[d];
1600  LOG((4, "total_chunk_size %f", total_chunk_size));
1601 #endif
1602 
1603  /* But did this result in a chunk that is too big? */
1604  retval = nc4_check_chunksizes(grp, var, var->chunksizes);
1605  if (retval)
1606  {
1607  /* Other error? */
1608  if (retval != NC_EBADCHUNK)
1609  return retval;
1610 
1611  /* Chunk is too big! Reduce each dimension by half and try again. */
1612  for ( ; retval == NC_EBADCHUNK; retval = nc4_check_chunksizes(grp, var, var->chunksizes))
1613  for (d = 0; d < var->ndims; d++)
1614  var->chunksizes[d] = var->chunksizes[d]/2 ? var->chunksizes[d]/2 : 1;
1615  }
1616 
1617  /* Do we have any big data overhangs? They can be dangerous to
1618  * babies, the elderly, or confused campers who have had too much
1619  * beer. */
1620  for (d = 0; d < var->ndims; d++)
1621  {
1622  size_t num_chunks;
1623  size_t overhang;
1624  assert(var->chunksizes[d] > 0);
1625  num_chunks = (var->dim[d]->len + var->chunksizes[d] - 1) / var->chunksizes[d];
1626  if(num_chunks > 0) {
1627  overhang = (num_chunks * var->chunksizes[d]) - var->dim[d]->len;
1628  var->chunksizes[d] -= overhang / num_chunks;
1629  }
1630  }
1631 
1632 
1633  return NC_NOERR;
1634 }
NC_USHORT
#define NC_USHORT
unsigned 2-byte int
Definition: netcdf.h:43
NC_NOERR
#define NC_NOERR
No Error.
Definition: netcdf.h:333
NC_EINVAL
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:343
NC_FILL_DOUBLE
#define NC_FILL_DOUBLE
Default fill value.
Definition: netcdf.h:72
NC_FILL_USHORT
#define NC_FILL_USHORT
Default fill value.
Definition: netcdf.h:74
nc_vlen_t
This is the type of arrays of vlens.
Definition: netcdf.h:703
NC_FLOAT
#define NC_FLOAT
single precision floating point number
Definition: netcdf.h:40
NC_DOUBLE
#define NC_DOUBLE
double precision floating point number
Definition: netcdf.h:41
NC_FILL_FLOAT
#define NC_FILL_FLOAT
Default fill value.
Definition: netcdf.h:71
NC_FILL_BYTE
#define NC_FILL_BYTE
Default fill value.
Definition: netcdf.h:67
NC_BYTE
#define NC_BYTE
signed 1 byte integer
Definition: netcdf.h:35
NC_VLEN
#define NC_VLEN
vlen (variable-length) types
Definition: netcdf.h:53
NC_FILL_CHAR
#define NC_FILL_CHAR
Default fill value.
Definition: netcdf.h:68
NC_EFILTER
#define NC_EFILTER
Filter operation failed.
Definition: netcdf.h:478
NC_CHUNKED
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
Definition: netcdf.h:299
NC_COLLECTIVE
#define NC_COLLECTIVE
Use with nc_var_par_access() to set parallel access to collective.
Definition: netcdf_par.h:28
NC_INT
#define NC_INT
signed 4 byte integer
Definition: netcdf.h:38
NC_MAX_NAME
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:276
NC_UBYTE
#define NC_UBYTE
unsigned 1 byte int
Definition: netcdf.h:42
NC_ENOPAR
#define NC_ENOPAR
Parallel operation on file opened for non-parallel access.
Definition: netcdf.h:459
NC_ERANGE
#define NC_ERANGE
Math result not representable.
Definition: netcdf.h:412
NC_GLOBAL
#define NC_GLOBAL
Attribute id to put/get a global attribute.
Definition: netcdf.h:249
nc_vlen_t::p
void * p
Pointer to VL data.
Definition: netcdf.h:705
NC_EBADCHUNK
#define NC_EBADCHUNK
Bad chunksize.
Definition: netcdf.h:472
NC_FILL_UINT
#define NC_FILL_UINT
Default fill value.
Definition: netcdf.h:75
NC_MAX_INT
#define NC_MAX_INT
Max or min values for a type.
Definition: netcdf.h:94
NC_FILL_INT64
#define NC_FILL_INT64
Default fill value.
Definition: netcdf.h:76
NC_FILL_SHORT
#define NC_FILL_SHORT
Default fill value.
Definition: netcdf.h:69
NC_MAX_UINT
#define NC_MAX_UINT
Max or min values for a type.
Definition: netcdf.h:102
NC_FILL_INT
#define NC_FILL_INT
Default fill value.
Definition: netcdf.h:70
NC_SHORT
#define NC_SHORT
signed 2 byte integer
Definition: netcdf.h:37
nc_vlen_t::len
size_t len
Length of VL data (in base type units)
Definition: netcdf.h:704
nc_type
int nc_type
The nc_type type is just an int.
Definition: netcdf.h:25
NC_EBADTYPE
#define NC_EBADTYPE
Not a netcdf data type.
Definition: netcdf.h:375
NC_FILL_UBYTE
#define NC_FILL_UBYTE
Default fill value.
Definition: netcdf.h:73
NC_ENOMEM
#define NC_ENOMEM
Memory allocation (malloc) failure.
Definition: netcdf.h:413
NC_UINT64
#define NC_UINT64
unsigned 8-byte int
Definition: netcdf.h:46
NC_UINT
#define NC_UINT
unsigned 4-byte int
Definition: netcdf.h:44
NC_STRING
#define NC_STRING
string
Definition: netcdf.h:47
NC_FILL_STRING
#define NC_FILL_STRING
Default fill value.
Definition: netcdf.h:78
NC_INDEPENDENT
#define NC_INDEPENDENT
Use with nc_var_par_access() to set parallel access to independent.
Definition: netcdf_par.h:26
NC_CHAR
#define NC_CHAR
ISO/ASCII character.
Definition: netcdf.h:36
NC_FILL_UINT64
#define NC_FILL_UINT64
Default fill value.
Definition: netcdf.h:77
NC_ENOTVAR
#define NC_ENOTVAR
Variable not found.
Definition: netcdf.h:387
NC_INT64
#define NC_INT64
signed 8-byte int
Definition: netcdf.h:45