NetCDF  4.8.1
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 #ifdef USE_NETCDF4
16 
17 static int searchgroup(int ncid1, int tid1, int grp, int* tid2);
18 static int searchgrouptree(int ncid1, int tid1, int grp, int* tid2);
19 
34 static int
35 NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2, int *equalp)
36 {
37  int ret = NC_NOERR;
38 
39  /* If you don't care about the answer, neither do I! */
40  if(equalp == NULL)
41  return NC_NOERR;
42 
43  /* Assume the types are not equal. If we find any inequality, then
44  exit with NC_NOERR and we're done. */
45  *equalp = 0;
46 
47  /* Atomic types are so easy! */
48  if (typeid1 <= NC_MAX_ATOMIC_TYPE)
49  {
50  if (typeid2 != typeid1)
51  return NC_NOERR;
52  *equalp = 1;
53  }
54  else
55  {
56  int i, ret, equal1;
57  char name1[NC_MAX_NAME];
58  char name2[NC_MAX_NAME];
59  size_t size1, size2;
60  nc_type base1, base2;
61  size_t nelems1, nelems2;
62  int class1, class2;
63  void* value1 = NULL;
64  void* value2 = NULL;
65  size_t offset1, offset2;
66  nc_type ftype1, ftype2;
67  int ndims1, ndims2;
68  int dimsizes1[NC_MAX_VAR_DIMS];
69  int dimsizes2[NC_MAX_VAR_DIMS];
70 
71  /* Find out about the two types. */
72  if ((ret = nc_inq_user_type(ncid1, typeid1, name1, &size1,
73  &base1, &nelems1, &class1)))
74  return ret;
75  if ((ret = nc_inq_user_type(ncid2, typeid2, name2, &size2,
76  &base2, &nelems2, &class2)))
77  return ret;
78 
79  /* Check the obvious. */
80  if(size1 != size2 || class1 != class2 || strcmp(name1,name2))
81  return NC_NOERR;
82 
83  /* Check user-defined types in detail. */
84  switch(class1)
85  {
86  case NC_VLEN:
87  if((ret = NC_compare_nc_types(ncid1, base1, ncid2,
88  base1, &equal1)))
89  return ret;
90  if(!equal1)
91  return NC_NOERR;
92  break;
93  case NC_OPAQUE:
94  /* Already checked size above. */
95  break;
96  case NC_ENUM:
97  if(base1 != base2 || nelems1 != nelems2) return NC_NOERR;
98 
99  if (!(value1 = malloc(size1)))
100  return NC_ENOMEM;
101  if (!(value2 = malloc(size2))) {
102  free(value1);
103  return NC_ENOMEM;
104  }
105 
106  for(i = 0; i < nelems1; i++)
107  {
108  if ((ret = nc_inq_enum_member(ncid1, typeid1, i, name1,
109  value1)) ||
110  (ret = nc_inq_enum_member(ncid2, typeid2, i, name2,
111  value2)) ||
112  strcmp(name1, name2) || memcmp(value1, value2, size1))
113  {
114  free(value1);
115  free(value2);
116  return ret;
117  }
118  }
119  free(value1);
120  free(value2);
121  break;
122  case NC_COMPOUND:
123  if(nelems1 != nelems2)
124  return NC_NOERR;
125 
126  /* Compare each field. Each must be equal! */
127  for(i = 0; i < nelems1; i++)
128  {
129  int j;
130  if ((ret = nc_inq_compound_field(ncid1, typeid1, i, name1, &offset1,
131  &ftype1, &ndims1, dimsizes1)))
132  return ret;
133  if ((ret = nc_inq_compound_field(ncid2, typeid2, i, name2, &offset2,
134  &ftype2, &ndims2, dimsizes2)))
135  return ret;
136  if(ndims1 != ndims2)
137  return NC_NOERR;
138  for(j = 0; j < ndims1;j++)
139  if(dimsizes1[j] != dimsizes2[j])
140  return NC_NOERR;
141 
142  /* Compare user-defined field types. */
143  if((ret = NC_compare_nc_types(ncid1, ftype1, ncid2, ftype2,
144  &equal1)))
145  return ret;
146  if(!equal1)
147  return NC_NOERR;
148  }
149  break;
150  default:
151  return NC_EINVAL;
152  }
153  *equalp = 1;
154  }
155  return ret;
156 }
157 
177 static int
178 NC_rec_find_nc_type(int ncid1, nc_type tid1, int ncid2, nc_type* tid2)
179 {
180  int ret = NC_NOERR;
181  int parent;
182 
183  if((ret = searchgroup(ncid1,tid1,ncid2,tid2)))
184  goto done;
185  if(*tid2 != 0)
186  goto done; /* found */
187 
188  /* Look in the parents of ncid2 upto the root */
189  switch (ret = nc_inq_grp_parent(ncid2,&parent)) {
190  case NC_NOERR:
191  /* Recurse up using parent grp */
192  ret = NC_rec_find_nc_type(ncid1, tid1, parent, tid2);
193  break;
194  case NC_ENOGRP:
195  /* do the breadth-first pre-order search of the whole tree */
196  /* ncid2 should be root group */
197  ret = searchgrouptree(ncid1,tid1,ncid2,tid2);
198  break;
199  default: break;
200  }
201 
202 done:
203  return ret;
204 }
205 
218 static int
219 NC_find_equal_type(int ncid1, nc_type xtype1, int ncid2, nc_type *xtype2)
220 {
221  int ret = NC_NOERR;
222 
223  /* Check input */
224  if(xtype1 <= NC_NAT)
225  return NC_EINVAL;
226 
227  /* Handle atomic types. */
228  if (xtype1 <= NC_MAX_ATOMIC_TYPE)
229  {
230  if(xtype2)
231  *xtype2 = xtype1;
232  return NC_NOERR;
233  }
234 
235  /* Recursively search group ncid2 and its children
236  to find a type that is equal (using compare_type)
237  to xtype1. */
238  ret = NC_rec_find_nc_type(ncid1, xtype1 , ncid2, xtype2);
239  return ret;
240 }
241 
242 #endif /* USE_NETCDF4 */
243 
272 int
273 nc_copy_var(int ncid_in, int varid_in, int ncid_out)
274 {
275  char name[NC_MAX_NAME + 1];
276  char att_name[NC_MAX_NAME + 1];
277  nc_type xtype;
278  int ndims, dimids_in[NC_MAX_VAR_DIMS], dimids_out[NC_MAX_VAR_DIMS], natts, real_ndims;
279  int varid_out;
280  int a, d;
281  void *data = NULL;
282  size_t *count = NULL, *start = NULL;
283  size_t reclen = 1;
284  size_t *dimlen = NULL;
285  int retval = NC_NOERR;
286  size_t type_size;
287  int src_format, dest_format;
288  char type_name[NC_MAX_NAME+1];
289  char dimname_in[NC_MAX_NAME + 1];
290  int i;
291 
292  /* Learn about this var. */
293  if ((retval = nc_inq_var(ncid_in, varid_in, name, &xtype,
294  &ndims, dimids_in, &natts)))
295  return retval;
296  /* find corresponding dimids in the output file */
297  for(i = 0; i < ndims; i++) {
298  dimids_out[i] = dimids_in[i];
299  if ((retval = nc_inq_dimname(ncid_in, dimids_in[i], dimname_in)))
300  return retval;
301  if ((retval = nc_inq_dimid(ncid_out, dimname_in, &dimids_out[i])))
302  return retval;
303  }
304 
305  LOG((2, "nc_copy_var: ncid_in 0x%x varid_in %d ncid_out 0x%x",
306  ncid_in, varid_in, ncid_out));
307 
308  /* Make sure we are not trying to write into a netcdf-3 file
309  * anything that won't fit in netcdf-3. */
310  if ((retval = nc_inq_format(ncid_in, &src_format)))
311  return retval;
312  if ((retval = nc_inq_format(ncid_out, &dest_format)))
313  return retval;
314  if ((dest_format == NC_FORMAT_CLASSIC
315  || dest_format == NC_FORMAT_64BIT_DATA
316  || dest_format == NC_FORMAT_64BIT_OFFSET) &&
317  src_format == NC_FORMAT_NETCDF4 && xtype > NC_DOUBLE)
318  return NC_ENOTNC4;
319 
320  /* Later on, we will need to know the size of this type. */
321  if ((retval = nc_inq_type(ncid_in, xtype, type_name, &type_size)))
322  return retval;
323  LOG((3, "type %s has size %d", type_name, type_size));
324 
325  /* Switch back to define mode, and create the output var. */
326  retval = nc_redef(ncid_out);
327  if (retval && retval != NC_EINDEFINE)
328  BAIL(retval);
329  if ((retval = nc_def_var(ncid_out, name, xtype,
330  ndims, dimids_out, &varid_out)))
331  BAIL(retval);
332 
333  /* Copy the attributes. */
334  for (a=0; a<natts; a++)
335  {
336  if ((retval = nc_inq_attname(ncid_in, varid_in, a, att_name)))
337  BAIL(retval);
338  if ((retval = nc_copy_att(ncid_in, varid_in, att_name,
339  ncid_out, varid_out)))
340  BAIL(retval);
341  }
342 
343  /* End define mode, to write metadata and create file. */
344  nc_enddef(ncid_out);
345  nc_sync(ncid_out);
346 
347  /* Allocate memory for our start and count arrays. If ndims = 0
348  this is a scalar, which I will treat as a 1-D array with one
349  element. */
350  real_ndims = ndims ? ndims : 1;
351  if (!(start = malloc((size_t)real_ndims * sizeof(size_t))))
352  BAIL(NC_ENOMEM);
353  if (!(count = malloc((size_t)real_ndims * sizeof(size_t))))
354  BAIL(NC_ENOMEM);
355 
356  /* The start array will be all zeros, except the first element,
357  which will be the record number. Count will be the dimension
358  size, except for the first element, which will be one, because
359  we will copy one record at a time. For this we need the var
360  shape. */
361  if (!(dimlen = malloc((size_t)real_ndims * sizeof(size_t))))
362  BAIL(NC_ENOMEM);
363 
364  /* Set to 0, to correct for an unlikely dereference
365  error reported by clang/llvm. */
366  dimlen[0] = 0;
367 
368  /* Find out how much data. */
369  for (d=0; d<ndims; d++)
370  {
371  if ((retval = nc_inq_dimlen(ncid_in, dimids_in[d], &dimlen[d])))
372  BAIL(retval);
373  LOG((4, "nc_copy_var: there are %d data", dimlen[d]));
374  }
375 
376  /* If this is really a scalar, then set the dimlen to 1. */
377  if (ndims == 0)
378  dimlen[0] = 1;
379 
380  for (d=0; d<real_ndims; d++)
381  {
382  start[d] = 0;
383  count[d] = d ? dimlen[d] : 1;
384  if (d) reclen *= dimlen[d];
385  }
386 
387  /* If there are no records, we're done. */
388  if (!dimlen[0])
389  goto exit;
390 
391  /* Allocate memory for one record. */
392  if (!(data = malloc(reclen * type_size))) {
393  if(count) free(count);
394  if(dimlen) free(dimlen);
395  if(start) free(start);
396  return NC_ENOMEM;
397  }
398 
399  /* Copy the var data one record at a time. */
400  for (start[0]=0; !retval && start[0]<(size_t)dimlen[0]; start[0]++)
401  {
402  switch (xtype)
403  {
404  case NC_BYTE:
405  retval = nc_get_vara_schar(ncid_in, varid_in, start, count,
406  (signed char *)data);
407  if (!retval)
408  retval = nc_put_vara_schar(ncid_out, varid_out, start, count,
409  (const signed char *)data);
410  break;
411  case NC_CHAR:
412  retval = nc_get_vara_text(ncid_in, varid_in, start, count,
413  (char *)data);
414  if (!retval)
415  retval = nc_put_vara_text(ncid_out, varid_out, start, count,
416  (char *)data);
417  break;
418  case NC_SHORT:
419  retval = nc_get_vara_short(ncid_in, varid_in, start, count,
420  (short *)data);
421  if (!retval)
422  retval = nc_put_vara_short(ncid_out, varid_out, start, count,
423  (short *)data);
424  break;
425  case NC_INT:
426  retval = nc_get_vara_int(ncid_in, varid_in, start, count,
427  (int *)data);
428  if (!retval)
429  retval = nc_put_vara_int(ncid_out, varid_out, start, count,
430  (int *)data);
431  break;
432  case NC_FLOAT:
433  retval = nc_get_vara_float(ncid_in, varid_in, start, count,
434  (float *)data);
435  if (!retval)
436  retval = nc_put_vara_float(ncid_out, varid_out, start, count,
437  (float *)data);
438  break;
439  case NC_DOUBLE:
440  retval = nc_get_vara_double(ncid_in, varid_in, start, count,
441  (double *)data);
442  if (!retval)
443  retval = nc_put_vara_double(ncid_out, varid_out, start, count,
444  (double *)data);
445  break;
446  case NC_UBYTE:
447  retval = nc_get_vara_uchar(ncid_in, varid_in, start, count,
448  (unsigned char *)data);
449  if (!retval)
450  retval = nc_put_vara_uchar(ncid_out, varid_out, start, count,
451  (unsigned char *)data);
452  break;
453  case NC_USHORT:
454  retval = nc_get_vara_ushort(ncid_in, varid_in, start, count,
455  (unsigned short *)data);
456  if (!retval)
457  retval = nc_put_vara_ushort(ncid_out, varid_out, start, count,
458  (unsigned short *)data);
459  break;
460  case NC_UINT:
461  retval = nc_get_vara_uint(ncid_in, varid_in, start, count,
462  (unsigned int *)data);
463  if (!retval)
464  retval = nc_put_vara_uint(ncid_out, varid_out, start, count,
465  (unsigned int *)data);
466  break;
467  case NC_INT64:
468  retval = nc_get_vara_longlong(ncid_in, varid_in, start, count,
469  (long long *)data);
470  if (!retval)
471  retval = nc_put_vara_longlong(ncid_out, varid_out, start, count,
472  (long long *)data);
473  break;
474  case NC_UINT64:
475  retval = nc_get_vara_ulonglong(ncid_in, varid_in, start, count,
476  (unsigned long long *)data);
477  if (!retval)
478  retval = nc_put_vara_ulonglong(ncid_out, varid_out, start, count,
479  (unsigned long long *)data);
480  break;
481  default:
482  retval = NC_EBADTYPE;
483  }
484  }
485 
486  exit:
487  if (data) free(data);
488  if (dimlen) free(dimlen);
489  if (start) free(start);
490  if (count) free(count);
491  return retval;
492 }
493 
507 static int
508 NC_copy_att(int ncid_in, int varid_in, const char *name,
509  int ncid_out, int varid_out)
510 {
511  nc_type xtype;
512  size_t len;
513  void *data=NULL;
514  int res;
515 
516  LOG((2, "nc_copy_att: ncid_in 0x%x varid_in %d name %s",
517  ncid_in, varid_in, name));
518 
519  /* Find out about the attribute to be copied. */
520  if ((res = nc_inq_att(ncid_in, varid_in, name, &xtype, &len)))
521  return res;
522 
523  if (xtype < NC_STRING)
524  {
525  /* Handle non-string atomic types. */
526  if (len)
527  {
528  size_t size = NC_atomictypelen(xtype);
529 
530  assert(size > 0);
531  if (!(data = malloc(len * size)))
532  return NC_ENOMEM;
533  }
534 
535  res = nc_get_att(ncid_in, varid_in, name, data);
536  if (!res)
537  res = nc_put_att(ncid_out, varid_out, name, xtype,
538  len, data);
539  if (len)
540  free(data);
541  }
542 #ifdef USE_NETCDF4
543  else if (xtype == NC_STRING)
544  {
545  /* Copy string attributes. */
546  char **str_data;
547  if (!(str_data = malloc(sizeof(char *) * len)))
548  return NC_ENOMEM;
549  res = nc_get_att_string(ncid_in, varid_in, name, str_data);
550  if (!res)
551  res = nc_put_att_string(ncid_out, varid_out, name, len,
552  (const char **)str_data);
553  nc_free_string(len, str_data);
554  free(str_data);
555  }
556  else
557  {
558  /* Copy user-defined type attributes. */
559  int class;
560  size_t size;
561  void *data;
562  nc_type xtype_out = NC_NAT;
563 
564  /* Find out if there is an equal type in the output file. */
565  /* Note: original code used a libsrc4 specific internal function
566  which we had to "duplicate" here */
567  if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
568  return res;
569  if (xtype_out)
570  {
571  /* We found an equal type! */
572  if ((res = nc_inq_user_type(ncid_in, xtype, NULL, &size,
573  NULL, NULL, &class)))
574  return res;
575  if (class == NC_VLEN) /* VLENs are different... */
576  {
577  nc_vlen_t *vldata;
578  int i;
579  if (!(vldata = malloc(sizeof(nc_vlen_t) * len)))
580  return NC_ENOMEM;
581  if ((res = nc_get_att(ncid_in, varid_in, name, vldata)))
582  return res;
583  if ((res = nc_put_att(ncid_out, varid_out, name, xtype_out,
584  len, vldata)))
585  return res;
586  for (i = 0; i < len; i++)
587  if((res = nc_free_vlen(&vldata[i])))
588  return res;
589  free(vldata);
590  }
591  else /* not VLEN */
592  {
593  if (!(data = malloc(size * len)))
594  return NC_ENOMEM;
595  res = nc_get_att(ncid_in, varid_in, name, data);
596  if (!res)
597  res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
598  free(data);
599  }
600  }
601  }
602 #endif
603  return res;
604 }
605 
627 int
628 nc_copy_att(int ncid_in, int varid_in, const char *name,
629  int ncid_out, int varid_out)
630 {
631  int format, target_natts, target_attid;
632  char att_name[NC_MAX_NAME + 1];
633  int a, retval;
634 
635  /* What is the destination format? */
636  if ((retval = nc_inq_format(ncid_out, &format)))
637  return retval;
638 
639  /* Can't copy to same var in same file. */
640  if (ncid_in == ncid_out && varid_in == varid_out)
641  return NC_NOERR;
642 
643  /* For classic model netCDF-4 files, order of attributes must be
644  * maintained during copies. We MUST MAINTAIN ORDER! */
645  if (format == NC_FORMAT_NETCDF4_CLASSIC)
646  {
647  /* Does this attribute already exist in the target file? */
648  retval = nc_inq_attid(ncid_out, varid_out, name, &target_attid);
649  if (retval == NC_ENOTATT)
650  {
651  /* Attribute does not exist. No order to be preserved. */
652  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
653  }
654  else if (retval == NC_NOERR)
655  {
656  /* How many atts for this var? */
657  if ((retval = nc_inq_varnatts(ncid_out, varid_out, &target_natts)))
658  return retval;
659 
660  /* If this is the last attribute in the target file, we are
661  * off the hook. */
662  if (target_attid == target_natts - 1)
663  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
664 
665  /* Order MUST BE MAINTAINED! Copy all existing atts in the target
666  * file, stopping at our target att. */
667  for (a = 0; a < target_natts; a++)
668  {
669  if (a == target_attid)
670  {
671  if ((retval = NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out)))
672  return retval;
673  }
674  else
675  {
676  if ((retval = nc_inq_attname(ncid_out, varid_out, a, att_name)))
677  return retval;
678  if ((retval = NC_copy_att(ncid_out, varid_out, att_name,
679  ncid_out, varid_out)))
680  return retval;
681  }
682  }
683  }
684  else
685  return retval; /* Some other error occurred. */
686  }
687  else
688  return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
689 
690  return NC_NOERR;
691 }
692 
693 #ifdef USE_NETCDF4
694 
695 /* Helper function for NC_rec_find_nc_type();
696  search a specified group for matching type.
697 */
698 static int
699 searchgroup(int ncid1, int tid1, int grp, int* tid2)
700 {
701  int i,ret = NC_NOERR;
702  int nids;
703  int* ids = NULL;
704 
705  /* Get all types in grp */
706  if(tid2)
707  *tid2 = 0;
708  if ((ret = nc_inq_typeids(grp, &nids, NULL)))
709  goto done;
710  if (nids)
711  {
712  if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
713  {ret = NC_ENOMEM; goto done;}
714  if ((ret = nc_inq_typeids(grp, &nids, ids)))
715  goto done;
716  for(i = 0; i < nids; i++)
717  {
718  int equal = 0;
719  if ((ret = NC_compare_nc_types(ncid1, tid1, grp, ids[i], &equal)))
720  goto done;
721  if(equal)
722  {
723  if(tid2)
724  *tid2 = ids[i];
725  goto done;
726  }
727  }
728  }
729 
730 done:
731  nullfree(ids);
732  return ret;
733 }
734 
735 /* Helper function for NC_rec_find_nc_type();
736  search a tree of groups for a matching type
737  using a breadth first queue
738 */
739 static int
740 searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
741 {
742  int i,ret = NC_NOERR;
743  int nids;
744  int* ids = NULL;
745  NClist* queue = nclistnew();
746  int gid;
747  uintptr_t id;
748 
749  id = grp;
750  nclistpush(queue,(void*)id); /* prime the queue */
751  while(nclistlength(queue) > 0) {
752  id = (uintptr_t)nclistremove(queue,0);
753  gid = (int)id;
754  if((ret = searchgroup(ncid1,tid1,gid,tid2)))
755  goto done;
756  if(*tid2 != 0)
757  goto done; /*we found it*/
758  /* Get subgroups of gid and push onto front of the queue (for breadth first) */
759  if((ret = nc_inq_grps(gid,&nids,NULL)))
760  goto done;
761  if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
762  {ret = NC_ENOMEM; goto done;}
763  if ((ret = nc_inq_grps(gid, &nids, ids)))
764  goto done;
765  /* push onto the end of the queue */
766  for(i=0;i<nids;i++) {
767  id = ids[i];
768  nclistpush(queue,(void*)id);
769  }
770  free(ids); ids = NULL;
771  }
772  /* Not found */
773  ret = NC_EBADTYPE;
774 
775 done:
776  nclistfree(queue);
777  nullfree(ids);
778  return ret;
779 }
780 
781 #endif
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_put_vara_uchar
int nc_put_vara_uchar(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned char *op)
Definition: dvarput.c:660
nc_get_vara_double
int nc_get_vara_double(int ncid, int varid, const size_t *startp, const size_t *countp, double *ip)
Definition: dvarget.c:803
nc_inq_attid
EXTERNL int nc_inq_attid(int ncid, int varid, const char *name, int *idp)
Definition: dattinq.c:163
NC_ENOGRP
#define NC_ENOGRP
No group found.
Definition: netcdf.h:470
nc_get_vara_uchar
int nc_get_vara_uchar(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned char *ip)
Definition: dvarget.c:768
nc_vlen_t
This is the type of arrays of vlens.
Definition: netcdf.h:703
nc_inq_varnatts
EXTERNL int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
Definition: dvarinq.c:249
nc_put_vara_short
int nc_put_vara_short(int ncid, int varid, const size_t *startp, const size_t *countp, const short *op)
Definition: dvarput.c:668
NC_FLOAT
#define NC_FLOAT
single precision floating point number
Definition: netcdf.h:40
nc_put_vara_uint
int nc_put_vara_uint(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned int *op)
Definition: dvarput.c:724
NC_DOUBLE
#define NC_DOUBLE
double precision floating point number
Definition: netcdf.h:41
nc_put_vara_schar
int nc_put_vara_schar(int ncid, int varid, const size_t *startp, const size_t *countp, const signed char *op)
Definition: dvarput.c:652
nc_get_vara_ushort
int nc_get_vara_ushort(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned short *ip)
Definition: dvarget.c:817
nc_inq_user_type
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)
Definition: dtype.c:146
NC_copy_att
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:508
nc_get_att_string
EXTERNL int nc_get_att_string(int ncid, int varid, const char *name, char **ip)
Definition: dattget.c:741
nc_redef
EXTERNL int nc_redef(int ncid)
Definition: dfile.c:954
nc_def_var
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:212
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_inq_format
EXTERNL int nc_inq_format(int ncid, int *formatp)
Definition: dfile.c:1538
nc_copy_var
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:273
NC_ENOTNC4
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
Definition: netcdf.h:456
NC_FORMAT_CLASSIC
#define NC_FORMAT_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:173
NC_INT
#define NC_INT
signed 4 byte integer
Definition: netcdf.h:38
NC_FORMAT_64BIT_DATA
#define NC_FORMAT_64BIT_DATA
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:183
NC_MAX_NAME
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:276
nc_inq_grps
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
NC_UBYTE
#define NC_UBYTE
unsigned 1 byte int
Definition: netcdf.h:42
nc_get_vara_uint
int nc_get_vara_uint(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned int *ip)
Definition: dvarget.c:824
nc_inq_compound_field
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)
Definition: dcompound.c:287
nc_get_vara_ulonglong
int nc_get_vara_ulonglong(int ncid, int varid, const size_t *startp, const size_t *countp, unsigned long long *ip)
Definition: dvarget.c:838
NC_FORMAT_NETCDF4
#define NC_FORMAT_NETCDF4
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:181
NC_MAX_VAR_DIMS
#define NC_MAX_VAR_DIMS
max per variable dimensions
Definition: netcdf.h:277
nc_inq_dimlen
EXTERNL int nc_inq_dimlen(int ncid, int dimid, size_t *lenp)
Find the length of a dimension.
Definition: ddim.c:467
nc_inq_typeids
EXTERNL int nc_inq_typeids(int ncid, int *ntypes, int *typeids)
Retrieve a list of types associated with a group.
Definition: dgroup.c:223
NC_FORMAT_NETCDF4_CLASSIC
#define NC_FORMAT_NETCDF4_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:182
nc_get_vara_float
int nc_get_vara_float(int ncid, int varid, const size_t *startp, const size_t *countp, float *ip)
Definition: dvarget.c:796
NC_FORMAT_64BIT_OFFSET
#define NC_FORMAT_64BIT_OFFSET
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:179
nc_inq_grp_parent
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
NC_ENOTATT
#define NC_ENOTATT
Attribute not found.
Definition: netcdf.h:373
nc_put_vara_text
int nc_put_vara_text(int ncid, int varid, const size_t *startp, const size_t *countp, const char *op)
Definition: dvarput.c:644
nc_put_vara_longlong
int nc_put_vara_longlong(int ncid, int varid, const size_t *startp, const size_t *countp, const long long *op)
Definition: dvarput.c:732
nc_inq_dimid
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
NC_COMPOUND
#define NC_COMPOUND
compound types
Definition: netcdf.h:56
nc_put_vara_ulonglong
int nc_put_vara_ulonglong(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned long long *op)
Definition: dvarput.c:740
nc_inq_att
EXTERNL int nc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
Definition: dattinq.c:85
nc_get_vara_schar
int nc_get_vara_schar(int ncid, int varid, const size_t *startp, const size_t *countp, signed char *ip)
Definition: dvarget.c:761
nc_inq_type
EXTERNL int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Definition: dfile.c:1719
nc_get_vara_text
int nc_get_vara_text(int ncid, int varid, const size_t *startp, const size_t *countp, char *ip)
Definition: dvarget.c:754
NC_SHORT
#define NC_SHORT
signed 2 byte integer
Definition: netcdf.h:37
nc_get_vara_int
int nc_get_vara_int(int ncid, int varid, const size_t *startp, const size_t *countp, int *ip)
Definition: dvarget.c:782
NC_OPAQUE
#define NC_OPAQUE
opaque types
Definition: netcdf.h:54
nc_put_att
EXTERNL int nc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op)
Definition: dattput.c:222
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_ENUM
#define NC_ENUM
enum types
Definition: netcdf.h:55
NC_EINDEFINE
#define NC_EINDEFINE
Operation not allowed in define mode.
Definition: netcdf.h:358
nc_get_vara_longlong
int nc_get_vara_longlong(int ncid, int varid, const size_t *startp, const size_t *countp, long long *ip)
Definition: dvarget.c:831
nc_free_vlen
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Definition: dvlen.c:41
nc_put_vara_int
int nc_put_vara_int(int ncid, int varid, const size_t *startp, const size_t *countp, const int *op)
Definition: dvarput.c:676
nc_get_vara_short
int nc_get_vara_short(int ncid, int varid, const size_t *startp, const size_t *countp, short *ip)
Definition: dvarget.c:775
NC_ENOMEM
#define NC_ENOMEM
Memory allocation (malloc) failure.
Definition: netcdf.h:413
NC_NAT
#define NC_NAT
Not A Type.
Definition: netcdf.h:34
nc_put_vara_ushort
int nc_put_vara_ushort(int ncid, int varid, const size_t *startp, const size_t *countp, const unsigned short *op)
Definition: dvarput.c:716
NC_UINT64
#define NC_UINT64
unsigned 8-byte int
Definition: netcdf.h:46
nc_copy_att
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:628
NC_UINT
#define NC_UINT
unsigned 4-byte int
Definition: netcdf.h:44
NC_STRING
#define NC_STRING
string
Definition: netcdf.h:47
nc_put_att_string
EXTERNL int nc_put_att_string(int ncid, int varid, const char *name, size_t len, const char **op)
Definition: dattput.c:75
nc_inq_attname
EXTERNL int nc_inq_attname(int ncid, int varid, int attnum, char *name)
Definition: dattinq.c:254
nc_enddef
EXTERNL int nc_enddef(int ncid)
Definition: dfile.c:1018
nc_put_vara_double
int nc_put_vara_double(int ncid, int varid, const size_t *startp, const size_t *countp, const double *op)
Definition: dvarput.c:700
NC_CHAR
#define NC_CHAR
ISO/ASCII character.
Definition: netcdf.h:36
nc_sync
EXTERNL int nc_sync(int ncid)
Definition: dfile.c:1186
nc_inq_var
EXTERNL int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
Definition: dvarinq.c:124
nc_put_vara_float
int nc_put_vara_float(int ncid, int varid, const size_t *startp, const size_t *countp, const float *op)
Definition: dvarput.c:692
nc_free_string
EXTERNL int nc_free_string(size_t len, char **data)
Free string space allocated by the library.
Definition: dvar.c:1206
nc_get_att
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
Definition: dattget.c:96
nc_inq_enum_member
EXTERNL int nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name, void *value)
Definition: denum.c:140
NC_INT64
#define NC_INT64
signed 8-byte int
Definition: netcdf.h:45
nc_inq_dimname
EXTERNL int nc_inq_dimname(int ncid, int dimid, char *name)
Find out the name of a dimension.
Definition: ddim.c:409