NetCDF  4.6.3
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
dcopy.c
Go to the documentation of this file.
1 
10 #include "ncdispatch.h"
11 #include "nc_logging.h"
12 
13 #ifdef USE_NETCDF4
14 
28 static int
29 NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2,
30  int *equalp)
31 {
32  int ret = NC_NOERR;
33 
34  /* If you don't care about the answer, neither do I! */
35  if(equalp == NULL)
36  return NC_NOERR;
37 
38  /* Assume the types are not equal. If we find any inequality, then
39  exit with NC_NOERR and we're done. */
40  *equalp = 0;
41 
42  /* Atomic types are so easy! */
43  if (typeid1 <= NC_MAX_ATOMIC_TYPE)
44  {
45  if (typeid2 != typeid1)
46  return NC_NOERR;
47  *equalp = 1;
48  }
49  else
50  {
51  int i, ret, equal1;
52  char name1[NC_MAX_NAME];
53  char name2[NC_MAX_NAME];
54  size_t size1, size2;
55  nc_type base1, base2;
56  size_t nelems1, nelems2;
57  int class1, class2;
58  void* value1 = NULL;
59  void* value2 = NULL;
60  size_t offset1, offset2;
61  nc_type ftype1, ftype2;
62  int ndims1, ndims2;
63  int dimsizes1[NC_MAX_VAR_DIMS];
64  int dimsizes2[NC_MAX_VAR_DIMS];
65 
66  /* Find out about the two types. */
67  if ((ret = nc_inq_user_type(ncid1, typeid1, name1, &size1,
68  &base1, &nelems1, &class1)))
69  return ret;
70  if ((ret = nc_inq_user_type(ncid2, typeid2, name2, &size2,
71  &base2, &nelems2, &class2)))
72  return ret;
73 
74  /* Check the obvious. */
75  if(size1 != size2 || class1 != class2 || strcmp(name1,name2))
76  return NC_NOERR;
77 
78  /* Check user-defined types in detail. */
79  switch(class1)
80  {
81  case NC_VLEN:
82  if((ret = NC_compare_nc_types(ncid1, base1, ncid2,
83  base1, &equal1)))
84  return ret;
85  if(!equal1)
86  return NC_NOERR;
87  break;
88  case NC_OPAQUE:
89  /* Already checked size above. */
90  break;
91  case NC_ENUM:
92  if(base1 != base2 || nelems1 != nelems2) return NC_NOERR;
93 
94  if (!(value1 = malloc(size1)))
95  return NC_ENOMEM;
96  if (!(value2 = malloc(size2))) {
97  free(value1);
98  return NC_ENOMEM;
99  }
100 
101  for(i = 0; i < nelems1; i++)
102  {
103  if ((ret = nc_inq_enum_member(ncid1, typeid1, i, name1,
104  value1)) ||
105  (ret = nc_inq_enum_member(ncid2, typeid2, i, name2,
106  value2)) ||
107  strcmp(name1, name2) || memcmp(value1, value2, size1))
108  {
109  free(value1);
110  free(value2);
111  return ret;
112  }
113  }
114  free(value1);
115  free(value2);
116  break;
117  case NC_COMPOUND:
118  if(nelems1 != nelems2)
119  return NC_NOERR;
120 
121  /* Compare each field. Each must be equal! */
122  for(i = 0; i < nelems1; i++)
123  {
124  int j;
125  if ((ret = nc_inq_compound_field(ncid1, typeid1, i, name1, &offset1,
126  &ftype1, &ndims1, dimsizes1)))
127  return ret;
128  if ((ret = nc_inq_compound_field(ncid2, typeid2, i, name2, &offset2,
129  &ftype2, &ndims2, dimsizes2)))
130  return ret;
131  if(ndims1 != ndims2)
132  return NC_NOERR;
133  for(j = 0; j < ndims1;j++)
134  if(dimsizes1[j] != dimsizes2[j])
135  return NC_NOERR;
136 
137  /* Compare user-defined field types. */
138  if((ret = NC_compare_nc_types(ncid1, ftype1, ncid2, ftype2,
139  &equal1)))
140  return ret;
141  if(!equal1)
142  return NC_NOERR;
143  }
144  break;
145  default:
146  return NC_EINVAL;
147  }
148  *equalp = 1;
149  }
150  return ret;
151 }
152 
165 static int
166 NC_rec_find_nc_type(int ncid1, nc_type tid1, int ncid2, nc_type* tid2)
167 {
168  int i,ret = NC_NOERR;
169  int nids;
170  int* ids = NULL;
171 
172  /* Get all types in grp ncid2 */
173  if(tid2)
174  *tid2 = 0;
175  if ((ret = nc_inq_typeids(ncid2, &nids, NULL)))
176  return ret;
177  if (nids)
178  {
179  if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
180  return NC_ENOMEM;
181  if ((ret = nc_inq_typeids(ncid2, &nids, ids)))
182  return ret;
183  for(i = 0; i < nids; i++)
184  {
185  int equal = 0;
186  if ((ret = NC_compare_nc_types(ncid1, tid1, ncid2, ids[i], &equal)))
187  return ret;
188  if(equal)
189  {
190  if(tid2)
191  *tid2 = ids[i];
192  free(ids);
193  return NC_NOERR;
194  }
195  }
196  free(ids);
197  }
198 
199  /* recurse */
200  if ((ret = nc_inq_grps(ncid1, &nids, NULL)))
201  return ret;
202  if (nids)
203  {
204  if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
205  return NC_ENOMEM;
206  if ((ret = nc_inq_grps(ncid1, &nids, ids)))
207  {
208  free(ids);
209  return ret;
210  }
211  for (i = 0; i < nids; i++)
212  {
213  ret = NC_rec_find_nc_type(ncid1, tid1, ids[i], tid2);
214  if (ret && ret != NC_EBADTYPE)
215  break;
216  if (tid2 && *tid2 != 0) /* found */
217  {
218  free(ids);
219  return NC_NOERR;
220  }
221  }
222  free(ids);
223  }
224  return NC_EBADTYPE; /* not found */
225 }
226 
239 static int
240 NC_find_equal_type(int ncid1, nc_type xtype1, int ncid2, nc_type *xtype2)
241 {
242  int ret = NC_NOERR;
243 
244  /* Check input */
245  if(xtype1 <= NC_NAT)
246  return NC_EINVAL;
247 
248  /* Handle atomic types. */
249  if (xtype1 <= NC_MAX_ATOMIC_TYPE)
250  {
251  if(xtype2)
252  *xtype2 = xtype1;
253  return NC_NOERR;
254  }
255 
256  /* Recursively search group ncid2 and its children
257  to find a type that is equal (using compare_type)
258  to xtype1. */
259  ret = NC_rec_find_nc_type(ncid1, xtype1 , ncid2, xtype2);
260  return ret;
261 }
262 
263 #endif /* USE_NETCDF4 */
264 
293 int
294 nc_copy_var(int ncid_in, int varid_in, int ncid_out)
295 {
296  char name[NC_MAX_NAME + 1];
297  char att_name[NC_MAX_NAME + 1];
298  nc_type xtype;
299  int ndims, dimids_in[NC_MAX_VAR_DIMS], dimids_out[NC_MAX_VAR_DIMS], natts, real_ndims;
300  int varid_out;
301  int a, d;
302  void *data = NULL;
303  size_t *count = NULL, *start = NULL;
304  size_t reclen = 1;
305  size_t *dimlen = NULL;
306  int retval = NC_NOERR;
307  size_t type_size;
308  int src_format, dest_format;
309  char type_name[NC_MAX_NAME+1];
310  char dimname_in[NC_MAX_NAME + 1];
311  int i;
312 
313  /* Learn about this var. */
314  if ((retval = nc_inq_var(ncid_in, varid_in, name, &xtype,
315  &ndims, dimids_in, &natts)))
316  return retval;
317  /* find corresponding dimids in the output file */
318  for(i = 0; i < ndims; i++) {
319  dimids_out[i] = dimids_in[i];
320  if ((retval = nc_inq_dimname(ncid_in, dimids_in[i], dimname_in)))
321  return retval;
322  if ((retval = nc_inq_dimid(ncid_out, dimname_in, &dimids_out[i])))
323  return retval;
324  }
325 
326 #ifdef USE_NETCDF4
327  LOG((2, "nc_copy_var: ncid_in 0x%x varid_in %d ncid_out 0x%x",
328  ncid_in, varid_in, ncid_out));
329 #endif
330 
331  /* Make sure we are not trying to write into a netcdf-3 file
332  * anything that won't fit in netcdf-3. */
333  if ((retval = nc_inq_format(ncid_in, &src_format)))
334  return retval;
335  if ((retval = nc_inq_format(ncid_out, &dest_format)))
336  return retval;
337  if ((dest_format == NC_FORMAT_CLASSIC
338  || dest_format == NC_FORMAT_64BIT_DATA
339  || dest_format == NC_FORMAT_64BIT_OFFSET) &&
340  src_format == NC_FORMAT_NETCDF4 && xtype > NC_DOUBLE)
341  return NC_ENOTNC4;
342 
343  /* Later on, we will need to know the size of this type. */
344  if ((retval = nc_inq_type(ncid_in, xtype, type_name, &type_size)))
345  return retval;
346 #ifdef USE_NETCDF4
347  LOG((3, "type %s has size %d", type_name, type_size));
348 #endif
349 
350  /* Switch back to define mode, and create the output var. */
351  retval = nc_redef(ncid_out);
352  if (retval && retval != NC_EINDEFINE)
353  BAIL(retval);
354  if ((retval = nc_def_var(ncid_out, name, xtype,
355  ndims, dimids_out, &varid_out)))
356  BAIL(retval);
357 
358  /* Copy the attributes. */
359  for (a=0; a<natts; a++)
360  {
361  if ((retval = nc_inq_attname(ncid_in, varid_in, a, att_name)))
362  BAIL(retval);
363  if ((retval = nc_copy_att(ncid_in, varid_in, att_name,
364  ncid_out, varid_out)))
365  BAIL(retval);
366  }
367 
368  /* End define mode, to write metadata and create file. */
369  nc_enddef(ncid_out);
370  nc_sync(ncid_out);
371 
372  /* Allocate memory for our start and count arrays. If ndims = 0
373  this is a scalar, which I will treat as a 1-D array with one
374  element. */
375  real_ndims = ndims ? ndims : 1;
376  if (!(start = malloc((size_t)real_ndims * sizeof(size_t))))
377  BAIL(NC_ENOMEM);
378  if (!(count = malloc((size_t)real_ndims * sizeof(size_t))))
379  BAIL(NC_ENOMEM);
380 
381  /* The start array will be all zeros, except the first element,
382  which will be the record number. Count will be the dimension
383  size, except for the first element, which will be one, because
384  we will copy one record at a time. For this we need the var
385  shape. */
386  if (!(dimlen = malloc((size_t)real_ndims * sizeof(size_t))))
387  BAIL(NC_ENOMEM);
388 
389  /* Set to 0, to correct for an unlikely dereference
390  error reported by clang/llvm. */
391  dimlen[0] = 0;
392 
393  /* Find out how much data. */
394  for (d=0; d<ndims; d++)
395  {
396  if ((retval = nc_inq_dimlen(ncid_in, dimids_in[d], &dimlen[d])))
397  BAIL(retval);
398 #ifdef USE_NETCDF4
399  LOG((4, "nc_copy_var: there are %d data", dimlen[d]));
400 #endif
401  }
402 
403  /* If this is really a scalar, then set the dimlen to 1. */
404  if (ndims == 0)
405  dimlen[0] = 1;
406 
407  for (d=0; d<real_ndims; d++)
408  {
409  start[d] = 0;
410  count[d] = d ? dimlen[d] : 1;
411  if (d) reclen *= dimlen[d];
412  }
413 
414  /* If there are no records, we're done. */
415  if (!dimlen[0])
416  goto exit;
417 
418  /* Allocate memory for one record. */
419  if (!(data = malloc(reclen * type_size))) {
420  if(count) free(count);
421  if(dimlen) free(dimlen);
422  if(start) free(start);
423  return NC_ENOMEM;
424  }
425 
426  /* Copy the var data one record at a time. */
427  for (start[0]=0; !retval && start[0]<(size_t)dimlen[0]; start[0]++)
428  {
429  switch (xtype)
430  {
431  case NC_BYTE:
432  retval = nc_get_vara_schar(ncid_in, varid_in, start, count,
433  (signed char *)data);
434  if (!retval)
435  retval = nc_put_vara_schar(ncid_out, varid_out, start, count,
436  (const signed char *)data);
437  break;
438  case NC_CHAR:
439  retval = nc_get_vara_text(ncid_in, varid_in, start, count,
440  (char *)data);
441  if (!retval)
442  retval = nc_put_vara_text(ncid_out, varid_out, start, count,
443  (char *)data);
444  break;
445  case NC_SHORT:
446  retval = nc_get_vara_short(ncid_in, varid_in, start, count,
447  (short *)data);
448  if (!retval)
449  retval = nc_put_vara_short(ncid_out, varid_out, start, count,
450  (short *)data);
451  break;
452  case NC_INT:
453  retval = nc_get_vara_int(ncid_in, varid_in, start, count,
454  (int *)data);
455  if (!retval)
456  retval = nc_put_vara_int(ncid_out, varid_out, start, count,
457  (int *)data);
458  break;
459  case NC_FLOAT:
460  retval = nc_get_vara_float(ncid_in, varid_in, start, count,
461  (float *)data);
462  if (!retval)
463  retval = nc_put_vara_float(ncid_out, varid_out, start, count,
464  (float *)data);
465  break;
466  case NC_DOUBLE:
467  retval = nc_get_vara_double(ncid_in, varid_in, start, count,
468  (double *)data);
469  if (!retval)
470  retval = nc_put_vara_double(ncid_out, varid_out, start, count,
471  (double *)data);
472  break;
473  case NC_UBYTE:
474  retval = nc_get_vara_uchar(ncid_in, varid_in, start, count,
475  (unsigned char *)data);
476  if (!retval)
477  retval = nc_put_vara_uchar(ncid_out, varid_out, start, count,
478  (unsigned char *)data);
479  break;
480  case NC_USHORT:
481  retval = nc_get_vara_ushort(ncid_in, varid_in, start, count,
482  (unsigned short *)data);
483  if (!retval)
484  retval = nc_put_vara_ushort(ncid_out, varid_out, start, count,
485  (unsigned short *)data);
486  break;
487  case NC_UINT:
488  retval = nc_get_vara_uint(ncid_in, varid_in, start, count,
489  (unsigned int *)data);
490  if (!retval)
491  retval = nc_put_vara_uint(ncid_out, varid_out, start, count,
492  (unsigned int *)data);
493  break;
494  case NC_INT64:
495  retval = nc_get_vara_longlong(ncid_in, varid_in, start, count,
496  (long long *)data);
497  if (!retval)
498  retval = nc_put_vara_longlong(ncid_out, varid_out, start, count,
499  (long long *)data);
500  break;
501  case NC_UINT64:
502  retval = nc_get_vara_ulonglong(ncid_in, varid_in, start, count,
503  (unsigned long long *)data);
504  if (!retval)
505  retval = nc_put_vara_ulonglong(ncid_out, varid_out, start, count,
506  (unsigned long long *)data);
507  break;
508  default:
509  retval = NC_EBADTYPE;
510  }
511  }
512 
513  exit:
514  if (data) free(data);
515  if (dimlen) free(dimlen);
516  if (start) free(start);
517  if (count) free(count);
518  return retval;
519 }
520 
534 static int
535 NC_copy_att(int ncid_in, int varid_in, const char *name,
536  int ncid_out, int varid_out)
537 {
538  nc_type xtype;
539  size_t len;
540  void *data=NULL;
541  int res;
542 
543  LOG((2, "nc_copy_att: ncid_in 0x%x varid_in %d name %s",
544  ncid_in, varid_in, name));
545 
546  /* Find out about the attribute to be copied. */
547  if ((res = nc_inq_att(ncid_in, varid_in, name, &xtype, &len)))
548  return res;
549 
550  if (xtype < NC_STRING)
551  {
552  /* Handle non-string atomic types. */
553  if (len)
554  {
555  size_t size = NC_atomictypelen(xtype);
556 
557  assert(size > 0);
558  if (!(data = malloc(len * size)))
559  return NC_ENOMEM;
560  }
561 
562  res = nc_get_att(ncid_in, varid_in, name, data);
563  if (!res)
564  res = nc_put_att(ncid_out, varid_out, name, xtype,
565  len, data);
566  if (len)
567  free(data);
568  }
569 #ifdef USE_NETCDF4
570  else if (xtype == NC_STRING)
571  {
572  /* Copy string attributes. */
573  char **str_data;
574  if (!(str_data = malloc(sizeof(char *) * len)))
575  return NC_ENOMEM;
576  res = nc_get_att_string(ncid_in, varid_in, name, str_data);
577  if (!res)
578  res = nc_put_att_string(ncid_out, varid_out, name, len,
579  (const char **)str_data);
580  nc_free_string(len, str_data);
581  free(str_data);
582  }
583  else
584  {
585  /* Copy user-defined type attributes. */
586  int class;
587  size_t size;
588  void *data;
589  nc_type xtype_out = NC_NAT;
590 
591  /* Find out if there is an equal type in the output file. */
592  /* Note: original code used a libsrc4 specific internal function
593  which we had to "duplicate" here */
594  if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
595  return res;
596  if (xtype_out)
597  {
598  /* We found an equal type! */
599  if ((res = nc_inq_user_type(ncid_in, xtype, NULL, &size,
600  NULL, NULL, &class)))
601  return res;
602  if (class == NC_VLEN) /* VLENs are different... */
603  {
604  nc_vlen_t *vldata;
605  int i;
606  if (!(vldata = malloc(sizeof(nc_vlen_t) * len)))
607  return NC_ENOMEM;
608  if ((res = nc_get_att(ncid_in, varid_in, name, vldata)))
609  return res;
610  if ((res = nc_put_att(ncid_out, varid_out, name, xtype_out,
611  len, vldata)))
612  return res;
613  for (i = 0; i < len; i++)
614  if((res = nc_free_vlen(&vldata[i])))
615  return res;
616  free(vldata);
617  }
618  else /* not VLEN */
619  {
620  if (!(data = malloc(size * len)))
621  return NC_ENOMEM;
622  res = nc_get_att(ncid_in, varid_in, name, data);
623  if (!res)
624  res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
625  free(data);
626  }
627  }
628  }
629 #endif
630  return res;
631 }
632 
654 int
655 nc_copy_att(int ncid_in, int varid_in, const char *name,
656  int ncid_out, int varid_out)
657 {
658  int format, target_natts, target_attid;
659  char att_name[NC_MAX_NAME + 1];
660  int a, retval;
661 
662  /* What is the destination format? */
663  if ((retval = nc_inq_format(ncid_out, &format)))
664  return retval;
665 
666  /* Can't copy to same var in same file. */
667  if (ncid_in == ncid_out && varid_in == varid_out)
668  return NC_NOERR;
669 
670  /* For classic model netCDF-4 files, order of attributes must be
671  * maintained during copies. We MUST MAINTAIN ORDER! */
672  if (format == NC_FORMAT_NETCDF4_CLASSIC)
673  {
674  /* Does this attribute already exist in the target file? */
675  retval = nc_inq_attid(ncid_out, varid_out, name, &target_attid);
676  if (retval == NC_ENOTATT)
677  {
678  /* Attribute does not exist. No order to be preserved. */
679  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
680  }
681  else if (retval == NC_NOERR)
682  {
683  /* How many atts for this var? */
684  if ((retval = nc_inq_varnatts(ncid_out, varid_out, &target_natts)))
685  return retval;
686 
687  /* If this is the last attribute in the target file, we are
688  * off the hook. */
689  if (target_attid == target_natts - 1)
690  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
691 
692  /* Order MUST BE MAINTAINED! Copy all existing atts in the target
693  * file, stopping at our target att. */
694  for (a = 0; a < target_natts; a++)
695  {
696  if (a == target_attid)
697  {
698  if ((retval = NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out)))
699  return retval;
700  }
701  else
702  {
703  if ((retval = nc_inq_attname(ncid_out, varid_out, a, att_name)))
704  return retval;
705  if ((retval = NC_copy_att(ncid_out, varid_out, att_name,
706  ncid_out, varid_out)))
707  return retval;
708  }
709  }
710  }
711  else
712  return retval; /* Some other error occurred. */
713  }
714  else
715  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
716 
717  return NC_NOERR;
718 }
int nc_get_vara_uint(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned int *ip)
Read an array of values from a variable.
Definition: dvarget.c:833
#define NC_ENOMEM
Memory allocation (malloc) failure.
Definition: netcdf.h:403
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
Definition: netcdf.h:446
#define NC_CHAR
ISO/ASCII character.
Definition: netcdf.h:36
int nc_put_vara_schar(int ncid, int varid, const size_t *startp, const size_t *countp, const signed char *op)
Write an array of values to a variable.
Definition: dvarput.c:660
EXTERNL int nc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
Return information about a netCDF attribute.
Definition: dattinq.c:83
EXTERNL int nc_inq_dimname(int ncid, int dimid, char *name)
Find out the name of a dimension.
Definition: ddim.c:409
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
Definition: dvar.c:207
int nc_get_vara_double(int ncid, int varid, const size_t *startp, const size_t *countp, double *ip)
Read an array of values from a variable.
Definition: dvarget.c:812
#define NC_UBYTE
unsigned 1 byte int
Definition: netcdf.h:42
#define NC_MAX_VAR_DIMS
max per variable dimensions
Definition: netcdf.h:274
int nc_put_vara_uchar(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned char *op)
Write an array of values to a variable.
Definition: dvarput.c:668
EXTERNL int nc_redef(int ncid)
Put open netcdf dataset into define mode.
Definition: dfile.c:1127
#define NC_UINT
unsigned 4-byte int
Definition: netcdf.h:44
int nc_put_vara_longlong(int ncid, int varid, const size_t *startp, const size_t *countp, const long long *op)
Write an array of values to a variable.
Definition: dvarput.c:740
#define NC_OPAQUE
opaque types
Definition: netcdf.h:54
static int NC_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
Copy an attribute from one open file to another.
Definition: dcopy.c:535
int nc_put_vara_double(int ncid, int varid, const size_t *startp, const size_t *countp, const double *op)
Write an array of values to a variable.
Definition: dvarput.c:708
int nc_put_vara_float(int ncid, int varid, const size_t *startp, const size_t *countp, const float *op)
Write an array of values to a variable.
Definition: dvarput.c:700
#define NC_INT64
signed 8-byte int
Definition: netcdf.h:45
#define NC_STRING
string
Definition: netcdf.h:47
#define NC_DOUBLE
double precision floating point number
Definition: netcdf.h:41
EXTERNL int nc_inq_format(int ncid, int *formatp)
Inquire about the binary format of a netCDF file as presented by the API.
Definition: dfile.c:1729
int nc_type
The nc_type type is just an int.
Definition: netcdf.h:25
int nc_put_vara_short(int ncid, int varid, const size_t *startp, const size_t *countp, const short *op)
Write an array of values to a variable.
Definition: dvarput.c:676
#define NC_BYTE
signed 1 byte integer
Definition: netcdf.h:35
int nc_put_vara_uint(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned int *op)
Write an array of values to a variable.
Definition: dvarput.c:732
#define NC_EINDEFINE
Operation not allowed in define mode.
Definition: netcdf.h:348
int nc_put_vara_text(int ncid, int varid, const size_t *startp, const size_t *countp, const char *op)
Write an array of values to a variable.
Definition: dvarput.c:652
#define NC_VLEN
vlen (variable-length) types
Definition: netcdf.h:53
EXTERNL int nc_inq_dimlen(int ncid, int dimid, size_t *lenp)
Find the length of a dimension.
Definition: ddim.c:467
EXTERNL int nc_get_att_string(int ncid, int varid, const char *name, char **ip)
Get a variable-length string attribute.
Definition: dattget.c:408
EXTERNL int nc_inq_compound_field(int ncid, nc_type xtype, int fieldid, char *name, size_t *offsetp, nc_type *field_typeidp, int *ndimsp, int *dim_sizesp)
Get information about one of the fields of a compound type.
Definition: dcompound.c:287
int nc_get_vara_ushort(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned short *ip)
Read an array of values from a variable.
Definition: dvarget.c:826
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
Get an attribute of any type.
Definition: dattget.c:83
int nc_get_vara_short(int ncid, int varid, const size_t *startp, const size_t *countp, short *ip)
Read an array of values from a variable.
Definition: dvarget.c:784
int nc_get_vara_float(int ncid, int varid, const size_t *startp, const size_t *countp, float *ip)
Read an array of values from a variable.
Definition: dvarget.c:805
int nc_put_vara_ushort(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned short *op)
Write an array of values to a variable.
Definition: dvarput.c:724
#define NC_EBADTYPE
Not a netcdf data type.
Definition: netcdf.h:365
int nc_get_vara_int(int ncid, int varid, const size_t *startp, const size_t *countp, int *ip)
Read an array of values from a variable.
Definition: dvarget.c:791
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:333
int nc_get_vara_longlong(int ncid, int varid, const size_t *startp, const size_t *countp, long long *ip)
Read an array of values from a variable.
Definition: dvarget.c:840
#define NC_INT
signed 4 byte integer
Definition: netcdf.h:38
int nc_get_vara_ulonglong(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned long long *ip)
Read an array of values from a variable.
Definition: dvarget.c:847
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:273
int nc_get_vara_text(int ncid, int varid, const size_t *startp, const size_t *countp, char *ip)
Read an array of values from a variable.
Definition: dvarget.c:763
#define NC_NAT
Not A Type.
Definition: netcdf.h:34
int nc_get_vara_schar(int ncid, int varid, const size_t *startp, const size_t *countp, signed char *ip)
Read an array of values from a variable.
Definition: dvarget.c:770
EXTERNL int nc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op)
Write an attribute.
Definition: dattput.c:231
EXTERNL int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
Definition: dfile.c:1910
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Free memory in a VLEN object.
Definition: dvlen.c:41
int nc_put_vara_int(int ncid, int varid, const size_t *startp, const size_t *countp, const int *op)
Write an array of values to a variable.
Definition: dvarput.c:684
EXTERNL int nc_free_string(size_t len, char **data)
Free string space allocated by the library.
Definition: dvar.c:1090
#define NC_USHORT
unsigned 2-byte int
Definition: netcdf.h:43
int nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
Copy an attribute from one open file to another.
Definition: dcopy.c:655
#define NC_FORMAT_NETCDF4_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:183
#define NC_FORMAT_NETCDF4
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:182
int nc_copy_var(int ncid_in, int varid_in, int ncid_out)
This will copy a variable that is an array of primitive type and its attributes from one file to anot...
Definition: dcopy.c:294
EXTERNL int nc_inq_dimid(int ncid, const char *name, int *idp)
Find the ID of a dimension from the name.
Definition: ddim.c:152
int nc_get_vara_uchar(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned char *ip)
Read an array of values from a variable.
Definition: dvarget.c:777
EXTERNL int nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name, void *value)
Learn about a about a member of an enum type.
Definition: denum.c:140
This is the type of arrays of vlens.
Definition: netcdf.h:685
#define NC_FORMAT_64BIT_DATA
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:184
#define NC_SHORT
signed 2 byte integer
Definition: netcdf.h:37
int nc_put_vara_ulonglong(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned long long *op)
Write an array of values to a variable.
Definition: dvarput.c:748
EXTERNL 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:126
#define NC_NOERR
No Error.
Definition: netcdf.h:323
#define NC_ENUM
enum types
Definition: netcdf.h:55
EXTERNL int nc_put_att_string(int ncid, int varid, const char *name, size_t len, const char **op)
Write a string attribute.
Definition: dattput.c:50
EXTERNL int nc_inq_grps(int ncid, int *numgrps, int *ncids)
Get a list of groups or subgroups from a file or groupID.
Definition: dgroup.c:73
EXTERNL int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
Definition: dvarinq.c:251
EXTERNL int nc_enddef(int ncid)
Leave define mode.
Definition: dfile.c:1191
#define NC_COMPOUND
compound types
Definition: netcdf.h:56
#define NC_FORMAT_64BIT_OFFSET
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:180
EXTERNL int nc_inq_user_type(int ncid, nc_type xtype, char *name, size_t *size, nc_type *base_nc_typep, size_t *nfieldsp, int *classp)
Learn about a user defined type.
Definition: dtype.c:146
EXTERNL int nc_inq_attid(int ncid, int varid, const char *name, int *idp)
Find an attribute ID.
Definition: dattinq.c:161
#define NC_FLOAT
single precision floating point number
Definition: netcdf.h:40
#define NC_FORMAT_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:174
#define NC_ENOTATT
Attribute not found.
Definition: netcdf.h:363
EXTERNL int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
Definition: dfile.c:1359
#define NC_UINT64
unsigned 8-byte int
Definition: netcdf.h:46
EXTERNL int nc_inq_attname(int ncid, int varid, int attnum, char *name)
Find the name of an attribute.
Definition: dattinq.c:253
EXTERNL int nc_inq_typeids(int ncid, int *ntypes, int *typeids)
Retrieve a list of types associated with a group.
Definition: dgroup.c:223

Return to the Main Unidata NetCDF page.
Generated on Sat Apr 6 2019 08:19:00 for NetCDF. NetCDF is a Unidata library.