NetCDF  4.9.3
dcopy.c
Go to the documentation of this file.
1 
10 #include "config.h"
11 #include "ncdispatch.h"
12 #include "nc_logging.h"
13 #include "nclist.h"
14 
15 static int NC_find_equal_type(int ncid1, nc_type xtype1, int ncid2, nc_type *xtype2);
16 
17 #ifdef USE_NETCDF4
18 
19 static int searchgroup(int ncid1, int tid1, int grp, int* tid2);
20 static int searchgrouptree(int ncid1, int tid1, int grp, int* tid2);
21 
22 #endif /*USE_NETCDF4*/
23 
24 
25 #ifdef USE_NETCDF4
26 
40 static int
41 NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2, int *equalp)
42 {
43  int ret = NC_NOERR;
44 
45  /* If you don't care about the answer, neither do I! */
46  if(equalp == NULL)
47  return NC_NOERR;
48 
49  /* Assume the types are not equal. If we find any inequality, then
50  exit with NC_NOERR and we're done. */
51  *equalp = 0;
52 
53  /* Atomic types are so easy! */
54  if (typeid1 <= NC_MAX_ATOMIC_TYPE)
55  {
56  if (typeid2 != typeid1)
57  return NC_NOERR;
58  *equalp = 1;
59  }
60  else
61  {
62  size_t i;
63  int ret, equal1;
64  char name1[NC_MAX_NAME];
65  char name2[NC_MAX_NAME];
66  size_t size1, size2;
67  nc_type base1, base2;
68  size_t nelems1, nelems2;
69  int class1, class2;
70  void* value1 = NULL;
71  void* value2 = NULL;
72  size_t offset1, offset2;
73  nc_type ftype1, ftype2;
74  int ndims1, ndims2;
75  int dimsizes1[NC_MAX_VAR_DIMS];
76  int dimsizes2[NC_MAX_VAR_DIMS];
77 
78  /* Find out about the two types. */
79  if ((ret = nc_inq_user_type(ncid1, typeid1, name1, &size1,
80  &base1, &nelems1, &class1)))
81  return ret;
82  if ((ret = nc_inq_user_type(ncid2, typeid2, name2, &size2,
83  &base2, &nelems2, &class2)))
84  return ret;
85 
86  /* Check the obvious. */
87  if(size1 != size2 || class1 != class2 || strcmp(name1,name2) != 0)
88  return NC_NOERR;
89 
90  /* Check user-defined types in detail. */
91  switch(class1)
92  {
93  case NC_VLEN:
94  if((ret = NC_compare_nc_types(ncid1, base1, ncid2,
95  base1, &equal1)))
96  return ret;
97  if(!equal1)
98  return NC_NOERR;
99  break;
100  case NC_OPAQUE:
101  /* Already checked size above. */
102  break;
103  case NC_ENUM:
104  if(base1 != base2 || nelems1 != nelems2) return NC_NOERR;
105 
106  if (!(value1 = malloc(size1)))
107  return NC_ENOMEM;
108  if (!(value2 = malloc(size2))) {
109  free(value1);
110  return NC_ENOMEM;
111  }
112 
113  for(i = 0; i < nelems1; i++)
114  {
115  if ((ret = nc_inq_enum_member(ncid1, typeid1, i, name1,
116  value1)) ||
117  (ret = nc_inq_enum_member(ncid2, typeid2, i, name2,
118  value2)) ||
119  strcmp(name1, name2) != 0 || memcmp(value1, value2, size1) != 0)
120  {
121  free(value1);
122  free(value2);
123  return ret;
124  }
125  }
126  free(value1);
127  free(value2);
128  break;
129  case NC_COMPOUND:
130  if(nelems1 != nelems2)
131  return NC_NOERR;
132 
133  /* Compare each field. Each must be equal! */
134  for(i = 0; i < nelems1; i++)
135  {
136  int j;
137  if ((ret = nc_inq_compound_field(ncid1, typeid1, i, name1, &offset1,
138  &ftype1, &ndims1, dimsizes1)))
139  return ret;
140  if ((ret = nc_inq_compound_field(ncid2, typeid2, i, name2, &offset2,
141  &ftype2, &ndims2, dimsizes2)))
142  return ret;
143  if(ndims1 != ndims2)
144  return NC_NOERR;
145  for(j = 0; j < ndims1;j++)
146  if(dimsizes1[j] != dimsizes2[j])
147  return NC_NOERR;
148 
149  /* Compare user-defined field types. */
150  if((ret = NC_compare_nc_types(ncid1, ftype1, ncid2, ftype2,
151  &equal1)))
152  return ret;
153  if(!equal1)
154  return NC_NOERR;
155  }
156  break;
157  default:
158  return NC_EINVAL;
159  }
160  *equalp = 1;
161  }
162  return ret;
163 }
164 
184 static int
185 NC_rec_find_nc_type(int ncid1, nc_type tid1, int ncid2, nc_type* tid2)
186 {
187  int ret = NC_NOERR;
188  int parent;
189 
190  if((ret = searchgroup(ncid1,tid1,ncid2,tid2)))
191  goto done;
192  if(*tid2 != 0)
193  goto done; /* found */
194 
195  /* Look in the parents of ncid2 upto the root */
196  switch (ret = nc_inq_grp_parent(ncid2,&parent)) {
197  case NC_NOERR:
198  /* Recurse up using parent grp */
199  ret = NC_rec_find_nc_type(ncid1, tid1, parent, tid2);
200  break;
201  case NC_ENOGRP:
202  /* do the breadth-first pre-order search of the whole tree */
203  /* ncid2 should be root group */
204  ret = searchgrouptree(ncid1,tid1,ncid2,tid2);
205  break;
206  default: break;
207  }
208 
209 done:
210  return ret;
211 }
212 
213 #endif /* USE_NETCDF4 */
214 
227 static int
228 NC_find_equal_type(int ncid1, nc_type xtype1, int ncid2, nc_type *xtype2)
229 {
230  int ret = NC_NOERR;
231 
232  /* Check input */
233  if(xtype1 <= NC_NAT)
234  return NC_EINVAL;
235 
236  /* Handle atomic types. */
237  if (xtype1 <= NC_MAX_ATOMIC_TYPE)
238  {
239  if(xtype2)
240  *xtype2 = xtype1;
241  return NC_NOERR;
242  }
243 
244 #ifdef USE_NETCDF4
245  /* Recursively search group ncid2 and its children
246  to find a type that is equal (using compare_type)
247  to xtype1. */
248  ret = NC_rec_find_nc_type(ncid1, xtype1 , ncid2, xtype2);
249 #endif /* USE_NETCDF4 */
250  return ret;
251 }
252 
281 int
282 nc_copy_var(int ncid_in, int varid_in, int ncid_out)
283 {
284  char name[NC_MAX_NAME + 1];
285  char att_name[NC_MAX_NAME + 1];
286  nc_type xtype;
287  int ndims;
288  int dimids_in[NC_MAX_VAR_DIMS], dimids_out[NC_MAX_VAR_DIMS];
289  int natts, real_ndims;
290  int varid_out;
291  int a, d;
292  void *data = NULL;
293  size_t *count = NULL, *start = NULL;
294  size_t reclen = 1;
295  size_t *dimlen = NULL;
296  int retval = NC_NOERR;
297  size_t type_size;
298  int src_format, dest_format;
299  char type_name[NC_MAX_NAME+1];
300  char dimname_in[NC_MAX_NAME + 1];
301  size_t i;
302 
303  /* Learn about this var. */
304  if ((retval = nc_inq_var(ncid_in, varid_in, name, &xtype,
305  &ndims, dimids_in, &natts)))
306  return retval;
307  /* find corresponding dimids in the output file */
308  for(i = 0; i < (size_t)ndims; i++) {
309  dimids_out[i] = dimids_in[i];
310  if ((retval = nc_inq_dimname(ncid_in, dimids_in[i], dimname_in)))
311  return retval;
312  if ((retval = nc_inq_dimid(ncid_out, dimname_in, &dimids_out[i])))
313  return retval;
314  }
315 
316  LOG((2, "nc_copy_var: ncid_in 0x%x varid_in %d ncid_out 0x%x",
317  ncid_in, varid_in, ncid_out));
318 
319  /* Make sure we are not trying to write into a netcdf-3 file
320  * anything that won't fit in netcdf-3. */
321  if ((retval = nc_inq_format(ncid_in, &src_format)))
322  return retval;
323  if ((retval = nc_inq_format(ncid_out, &dest_format)))
324  return retval;
325  if ((dest_format == NC_FORMAT_CLASSIC
326  || dest_format == NC_FORMAT_64BIT_DATA
327  || dest_format == NC_FORMAT_64BIT_OFFSET) &&
328  src_format == NC_FORMAT_NETCDF4 && xtype > NC_DOUBLE)
329  return NC_ENOTNC4;
330 
331  /* Later on, we will need to know the size of this type. */
332  if ((retval = nc_inq_type(ncid_in, xtype, type_name, &type_size)))
333  return retval;
334  LOG((3, "type %s has size %d", type_name, type_size));
335 
336  /* Switch back to define mode, and create the output var. */
337  retval = nc_redef(ncid_out);
338  if (retval && retval != NC_EINDEFINE)
339  BAIL(retval);
340  if ((retval = nc_def_var(ncid_out, name, xtype,
341  ndims, dimids_out, &varid_out)))
342  BAIL(retval);
343 
344  /* Copy the attributes. */
345  for (a=0; a<natts; a++)
346  {
347  if ((retval = nc_inq_attname(ncid_in, varid_in, a, att_name)))
348  BAIL(retval);
349  if ((retval = nc_copy_att(ncid_in, varid_in, att_name,
350  ncid_out, varid_out)))
351  BAIL(retval);
352  }
353 
354  /* End define mode, to write metadata and create file. */
355  nc_enddef(ncid_out);
356  nc_sync(ncid_out);
357 
358  /* Allocate memory for our start and count arrays. If ndims = 0
359  this is a scalar, which I will treat as a 1-D array with one
360  element. */
361  real_ndims = ndims ? ndims : 1;
362  if (!(start = malloc((size_t)real_ndims * sizeof(size_t))))
363  BAIL(NC_ENOMEM);
364  if (!(count = malloc((size_t)real_ndims * sizeof(size_t))))
365  BAIL(NC_ENOMEM);
366 
367  /* The start array will be all zeros, except the first element,
368  which will be the record number. Count will be the dimension
369  size, except for the first element, which will be one, because
370  we will copy one record at a time. For this we need the var
371  shape. */
372  if (!(dimlen = malloc((size_t)real_ndims * sizeof(size_t))))
373  BAIL(NC_ENOMEM);
374 
375  /* Set to 0, to correct for an unlikely dereference
376  error reported by clang/llvm. */
377  dimlen[0] = 0;
378 
379  /* Find out how much data. */
380  for (d=0; d<ndims; d++)
381  {
382  if ((retval = nc_inq_dimlen(ncid_in, dimids_in[d], &dimlen[d])))
383  BAIL(retval);
384  LOG((4, "nc_copy_var: there are %d data", dimlen[d]));
385  }
386 
387  /* If this is really a scalar, then set the dimlen to 1. */
388  if (ndims == 0)
389  dimlen[0] = 1;
390 
391  for (d=0; d<real_ndims; d++)
392  {
393  start[d] = 0;
394  count[d] = d ? dimlen[d] : 1;
395  if (d) reclen *= dimlen[d];
396  }
397 
398  /* If there are no records, we're done. */
399  if (!dimlen[0])
400  goto exit;
401 
402  /* Allocate memory for one record. */
403  if (!(data = malloc(reclen * type_size))) {
404  if(count) free(count);
405  if(dimlen) free(dimlen);
406  if(start) free(start);
407  return NC_ENOMEM;
408  }
409 
410  /* Copy the var data one record at a time. */
411  for (start[0]=0; !retval && start[0]<(size_t)dimlen[0]; start[0]++)
412  {
413  switch (xtype)
414  {
415  case NC_BYTE:
416  retval = nc_get_vara_schar(ncid_in, varid_in, start, count,
417  (signed char *)data);
418  if (!retval)
419  retval = nc_put_vara_schar(ncid_out, varid_out, start, count,
420  (const signed char *)data);
421  break;
422  case NC_CHAR:
423  retval = nc_get_vara_text(ncid_in, varid_in, start, count,
424  (char *)data);
425  if (!retval)
426  retval = nc_put_vara_text(ncid_out, varid_out, start, count,
427  (char *)data);
428  break;
429  case NC_SHORT:
430  retval = nc_get_vara_short(ncid_in, varid_in, start, count,
431  (short *)data);
432  if (!retval)
433  retval = nc_put_vara_short(ncid_out, varid_out, start, count,
434  (short *)data);
435  break;
436  case NC_INT:
437  retval = nc_get_vara_int(ncid_in, varid_in, start, count,
438  (int *)data);
439  if (!retval)
440  retval = nc_put_vara_int(ncid_out, varid_out, start, count,
441  (int *)data);
442  break;
443  case NC_FLOAT:
444  retval = nc_get_vara_float(ncid_in, varid_in, start, count,
445  (float *)data);
446  if (!retval)
447  retval = nc_put_vara_float(ncid_out, varid_out, start, count,
448  (float *)data);
449  break;
450  case NC_DOUBLE:
451  retval = nc_get_vara_double(ncid_in, varid_in, start, count,
452  (double *)data);
453  if (!retval)
454  retval = nc_put_vara_double(ncid_out, varid_out, start, count,
455  (double *)data);
456  break;
457  case NC_UBYTE:
458  retval = nc_get_vara_uchar(ncid_in, varid_in, start, count,
459  (unsigned char *)data);
460  if (!retval)
461  retval = nc_put_vara_uchar(ncid_out, varid_out, start, count,
462  (unsigned char *)data);
463  break;
464  case NC_USHORT:
465  retval = nc_get_vara_ushort(ncid_in, varid_in, start, count,
466  (unsigned short *)data);
467  if (!retval)
468  retval = nc_put_vara_ushort(ncid_out, varid_out, start, count,
469  (unsigned short *)data);
470  break;
471  case NC_UINT:
472  retval = nc_get_vara_uint(ncid_in, varid_in, start, count,
473  (unsigned int *)data);
474  if (!retval)
475  retval = nc_put_vara_uint(ncid_out, varid_out, start, count,
476  (unsigned int *)data);
477  break;
478  case NC_INT64:
479  retval = nc_get_vara_longlong(ncid_in, varid_in, start, count,
480  (long long *)data);
481  if (!retval)
482  retval = nc_put_vara_longlong(ncid_out, varid_out, start, count,
483  (long long *)data);
484  break;
485  case NC_UINT64:
486  retval = nc_get_vara_ulonglong(ncid_in, varid_in, start, count,
487  (unsigned long long *)data);
488  if (!retval)
489  retval = nc_put_vara_ulonglong(ncid_out, varid_out, start, count,
490  (unsigned long long *)data);
491  break;
492  default:
493  retval = NC_EBADTYPE;
494  }
495  }
496 
497  exit:
498  if (data) free(data);
499  if (dimlen) free(dimlen);
500  if (start) free(start);
501  if (count) free(count);
502  return retval;
503 }
504 
518 static int
519 NC_copy_att(int ncid_in, int varid_in, const char *name,
520  int ncid_out, int varid_out)
521 {
522  nc_type xtype;
523  size_t len;
524  void *data=NULL;
525  int res;
526 
527  LOG((2, "nc_copy_att: ncid_in 0x%x varid_in %d name %s",
528  ncid_in, varid_in, name));
529 
530  /* Find out about the attribute to be copied. */
531  if ((res = nc_inq_att(ncid_in, varid_in, name, &xtype, &len)))
532  return res;
533 
534  {
535  /* Copy arbitrary attributes. */
536  int class;
537  size_t size = 0;
538  nc_type xtype_out = NC_NAT;
539 
540  if(xtype <= NC_MAX_ATOMIC_TYPE) {
541  xtype_out = xtype;
542  if((res = nc_inq_type(ncid_out,xtype_out,NULL,&size))) return res;
543  } else { /* User defined type */
544  /* Find out if there is an equal type in the output file. */
545  /* Note: original code used a libsrc4 specific internal function
546  which we had to "duplicate" here */
547  if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
548  return res;
549  if (xtype_out) {
550  /* We found an equal type! */
551  if ((res = nc_inq_user_type(ncid_in, xtype, NULL, &size, NULL, NULL, &class)))
552  return res;
553  }
554  }
555  if((data = malloc(size * len))==NULL) {return NC_ENOMEM;}
556  res = nc_get_att(ncid_in, varid_in, name, data);
557  if(!res)
558  res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
559  (void)nc_reclaim_data_all(ncid_out,xtype_out,data,len);
560  }
561 
562  return res;
563 }
564 
586 int
587 nc_copy_att(int ncid_in, int varid_in, const char *name,
588  int ncid_out, int varid_out)
589 {
590  int format, target_natts, target_attid;
591  char att_name[NC_MAX_NAME + 1];
592  int a, retval;
593 
594  /* What is the destination format? */
595  if ((retval = nc_inq_format(ncid_out, &format)))
596  return retval;
597 
598  /* Can't copy to same var in same file. */
599  if (ncid_in == ncid_out && varid_in == varid_out)
600  return NC_NOERR;
601 
602  /* For classic model netCDF-4 files, order of attributes must be
603  * maintained during copies. We MUST MAINTAIN ORDER! */
604  if (format == NC_FORMAT_NETCDF4_CLASSIC)
605  {
606  /* Does this attribute already exist in the target file? */
607  retval = nc_inq_attid(ncid_out, varid_out, name, &target_attid);
608  if (retval == NC_ENOTATT)
609  {
610  /* Attribute does not exist. No order to be preserved. */
611  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
612  }
613  else if (retval == NC_NOERR)
614  {
615  /* How many atts for this var? */
616  if ((retval = nc_inq_varnatts(ncid_out, varid_out, &target_natts)))
617  return retval;
618 
619  /* If this is the last attribute in the target file, we are
620  * off the hook. */
621  if (target_attid == target_natts - 1)
622  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
623 
624  /* Order MUST BE MAINTAINED! Copy all existing atts in the target
625  * file, stopping at our target att. */
626  for (a = 0; a < target_natts; a++)
627  {
628  if (a == target_attid)
629  {
630  if ((retval = NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out)))
631  return retval;
632  }
633  else
634  {
635  if ((retval = nc_inq_attname(ncid_out, varid_out, a, att_name)))
636  return retval;
637  if ((retval = NC_copy_att(ncid_out, varid_out, att_name,
638  ncid_out, varid_out)))
639  return retval;
640  }
641  }
642  }
643  else
644  return retval; /* Some other error occurred. */
645  }
646  else
647  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
648 
649  return NC_NOERR;
650 }
651 
652 #ifdef USE_NETCDF4
653 
654 /* Helper function for NC_rec_find_nc_type();
655  search a specified group for matching type.
656 */
657 static int
658 searchgroup(int ncid1, int tid1, int grp, int* tid2)
659 {
660  int i,ret = NC_NOERR;
661  int nids;
662  int* ids = NULL;
663 
664  /* Get all types in grp */
665  if(tid2)
666  *tid2 = 0;
667  if ((ret = nc_inq_typeids(grp, &nids, NULL)))
668  goto done;
669  if (nids)
670  {
671  if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
672  {ret = NC_ENOMEM; goto done;}
673  if ((ret = nc_inq_typeids(grp, &nids, ids)))
674  goto done;
675  for(i = 0; i < nids; i++)
676  {
677  int equal = 0;
678  if ((ret = NC_compare_nc_types(ncid1, tid1, grp, ids[i], &equal)))
679  goto done;
680  if(equal)
681  {
682  if(tid2)
683  *tid2 = ids[i];
684  goto done;
685  }
686  }
687  }
688 
689 done:
690  nullfree(ids);
691  return ret;
692 }
693 
694 /* Helper function for NC_rec_find_nc_type();
695  search a tree of groups for a matching type
696  using a breadth first queue
697 */
698 static int
699 searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
700 {
701  int i,ret = NC_NOERR;
702  int nids;
703  int* ids = NULL;
704  NClist* queue = nclistnew();
705  int gid;
706  uintptr_t id;
707 
708  id = (uintptr_t)grp;
709  nclistpush(queue,(void*)id); /* prime the queue */
710  while(nclistlength(queue) > 0) {
711  id = (uintptr_t)nclistremove(queue,0);
712  gid = (int)id;
713  if((ret = searchgroup(ncid1,tid1,gid,tid2)))
714  goto done;
715  if(*tid2 != 0)
716  goto done; /*we found it*/
717  /* Get subgroups of gid and push onto front of the queue (for breadth first) */
718  if((ret = nc_inq_grps(gid,&nids,NULL)))
719  goto done;
720  if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
721  {ret = NC_ENOMEM; goto done;}
722  if ((ret = nc_inq_grps(gid, &nids, ids)))
723  goto done;
724  /* push onto the end of the queue */
725  for(i=0;i<nids;i++) {
726  id = (uintptr_t)ids[i];
727  nclistpush(queue,(void*)id);
728  }
729  free(ids); ids = NULL;
730  }
731  /* Not found */
732  ret = NC_EBADTYPE;
733 
734 done:
735  nclistfree(queue);
736  nullfree(ids);
737  return ret;
738 }
739 
740 #endif /* USE_NETCDF4 */
741 
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:829
#define NC_ENOMEM
Memory allocation (malloc) failure.
Definition: netcdf.h:458
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
Definition: netcdf.h:501
#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:654
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:86
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:214
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:808
#define NC_UBYTE
unsigned 1 byte int
Definition: netcdf.h:42
#define NC_MAX_VAR_DIMS
max per variable dimensions
Definition: netcdf.h:292
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:662
EXTERNL int nc_redef(int ncid)
Put open netcdf dataset into define mode.
Definition: dfile.c:963
#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:734
#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:519
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:702
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:694
#define NC_INT64
signed 8-byte int
Definition: netcdf.h:45
#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:1547
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:670
#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:726
#define NC_EINDEFINE
Operation not allowed in define mode.
Definition: netcdf.h:403
#define NC_ENOGRP
No group found.
Definition: netcdf.h:515
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:646
#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_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:822
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
Get an attribute of any type.
Definition: dattget.c:133
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:780
EXTERNL int nc_inq_grp_parent(int ncid, int *parent_ncid)
Get the ID of the parent based on a group ID.
Definition: dgroup.c:136
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:801
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:718
#define NC_EBADTYPE
Not a netcdf data type.
Definition: netcdf.h:420
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:787
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:388
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:836
#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:843
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:291
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:759
#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:766
EXTERNL int nc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op)
Write an attribute of any type.
Definition: dattput.c:222
EXTERNL int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
Definition: dfile.c:1728
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:678
#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:587
#define NC_FORMAT_NETCDF4_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:196
#define NC_FORMAT_NETCDF4
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:195
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:282
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:773
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
#define NC_FORMAT_64BIT_DATA
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:197
#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:742
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:124
#define NC_NOERR
No Error.
Definition: netcdf.h:378
#define NC_ENUM
enum types
Definition: netcdf.h:55
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:249
EXTERNL int nc_enddef(int ncid)
Leave define mode.
Definition: dfile.c:1027
#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:193
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:164
#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:187
#define NC_ENOTATT
Attribute not found.
Definition: netcdf.h:418
EXTERNL int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
Definition: dfile.c:1195
#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:255
EXTERNL int nc_inq_typeids(int ncid, int *ntypes, int *typeids)
Retrieve a list of types associated with a group.
Definition: dgroup.c:223