NetCDF 4.9.2
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
17static int searchgroup(int ncid1, int tid1, int grp, int* tid2);
18static int searchgrouptree(int ncid1, int tid1, int grp, int* tid2);
19
34static int
35NC_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
177static int
178NC_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
202done:
203 return ret;
204}
205
218static int
219NC_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
272int
273nc_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
507static int
508NC_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#ifdef SEPDATA
524 if (xtype < NC_STRING)
525 {
526 /* Handle non-string atomic types. */
527 if (len)
528 {
529 size_t size = NC_atomictypelen(xtype);
530
531 assert(size > 0);
532 if (!(data = malloc(len * size)))
533 return NC_ENOMEM;
534 }
535
536 res = nc_get_att(ncid_in, varid_in, name, data);
537 if (!res)
538 res = nc_put_att(ncid_out, varid_out, name, xtype,
539 len, data);
540 if (len)
541 free(data);
542 }
543#ifdef USE_NETCDF4
544 else if (xtype == NC_STRING)
545 {
546 /* Copy string attributes. */
547 char **str_data;
548 if (!(str_data = malloc(sizeof(char *) * len)))
549 return NC_ENOMEM;
550 res = nc_get_att_string(ncid_in, varid_in, name, str_data);
551 if (!res)
552 res = nc_put_att_string(ncid_out, varid_out, name, len,
553 (const char **)str_data);
554 nc_free_string(len, str_data);
555 free(str_data);
556 }
557 else
558 {
559 /* Copy user-defined type attributes. */
560 int class;
561 size_t size;
562 void *data;
563 nc_type xtype_out = NC_NAT;
564
565 /* Find out if there is an equal type in the output file. */
566 /* Note: original code used a libsrc4 specific internal function
567 which we had to "duplicate" here */
568 if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
569 return res;
570 if (xtype_out)
571 {
572 /* We found an equal type! */
573 if ((res = nc_inq_user_type(ncid_in, xtype, NULL, &size,
574 NULL, NULL, &class)))
575 return res;
576 if (class == NC_VLEN) /* VLENs are different... */
577 {
578 nc_vlen_t *vldata;
579 int i;
580 if (!(vldata = malloc(sizeof(nc_vlen_t) * len)))
581 return NC_ENOMEM;
582 if ((res = nc_get_att(ncid_in, varid_in, name, vldata)))
583 return res;
584 if ((res = nc_put_att(ncid_out, varid_out, name, xtype_out,
585 len, vldata)))
586 return res;
587 for (i = 0; i < len; i++)
588 if((res = nc_free_vlen(&vldata[i])))
589 return res;
590 free(vldata);
591 }
592 else /* not VLEN */
593 {
594 if (!(data = malloc(size * len)))
595 return NC_ENOMEM;
596 res = nc_get_att(ncid_in, varid_in, name, data);
597 if (!res)
598 res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
599 free(data);
600 }
601 }
602 }
603#endif
604#else
605 {
606 /* Copy arbitrary attributes. */
607 int class;
608 size_t size;
609 nc_type xtype_out = NC_NAT;
610
611 if(xtype <= NC_MAX_ATOMIC_TYPE) {
612 xtype_out = xtype;
613 if((res = nc_inq_type(ncid_out,xtype_out,NULL,&size))) return res;
614 } else { /* User defined type */
615 /* Find out if there is an equal type in the output file. */
616 /* Note: original code used a libsrc4 specific internal function
617 which we had to "duplicate" here */
618 if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
619 return res;
620 if (xtype_out) {
621 /* We found an equal type! */
622 if ((res = nc_inq_user_type(ncid_in, xtype, NULL, &size, NULL, NULL, &class)))
623 return res;
624 }
625 }
626 if((data = malloc(size * len))==NULL) {return NC_ENOMEM;}
627 res = nc_get_att(ncid_in, varid_in, name, data);
628 if(!res)
629 res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
630 (void)nc_reclaim_data_all(ncid_out,xtype_out,data,len);
631 }
632#endif /*SEPDATA*/
633
634 return res;
635}
636
658int
659nc_copy_att(int ncid_in, int varid_in, const char *name,
660 int ncid_out, int varid_out)
661{
662 int format, target_natts, target_attid;
663 char att_name[NC_MAX_NAME + 1];
664 int a, retval;
665
666 /* What is the destination format? */
667 if ((retval = nc_inq_format(ncid_out, &format)))
668 return retval;
669
670 /* Can't copy to same var in same file. */
671 if (ncid_in == ncid_out && varid_in == varid_out)
672 return NC_NOERR;
673
674 /* For classic model netCDF-4 files, order of attributes must be
675 * maintained during copies. We MUST MAINTAIN ORDER! */
676 if (format == NC_FORMAT_NETCDF4_CLASSIC)
677 {
678 /* Does this attribute already exist in the target file? */
679 retval = nc_inq_attid(ncid_out, varid_out, name, &target_attid);
680 if (retval == NC_ENOTATT)
681 {
682 /* Attribute does not exist. No order to be preserved. */
683 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
684 }
685 else if (retval == NC_NOERR)
686 {
687 /* How many atts for this var? */
688 if ((retval = nc_inq_varnatts(ncid_out, varid_out, &target_natts)))
689 return retval;
690
691 /* If this is the last attribute in the target file, we are
692 * off the hook. */
693 if (target_attid == target_natts - 1)
694 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
695
696 /* Order MUST BE MAINTAINED! Copy all existing atts in the target
697 * file, stopping at our target att. */
698 for (a = 0; a < target_natts; a++)
699 {
700 if (a == target_attid)
701 {
702 if ((retval = NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out)))
703 return retval;
704 }
705 else
706 {
707 if ((retval = nc_inq_attname(ncid_out, varid_out, a, att_name)))
708 return retval;
709 if ((retval = NC_copy_att(ncid_out, varid_out, att_name,
710 ncid_out, varid_out)))
711 return retval;
712 }
713 }
714 }
715 else
716 return retval; /* Some other error occurred. */
717 }
718 else
719 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
720
721 return NC_NOERR;
722}
723
724#ifdef USE_NETCDF4
725
726/* Helper function for NC_rec_find_nc_type();
727 search a specified group for matching type.
728*/
729static int
730searchgroup(int ncid1, int tid1, int grp, int* tid2)
731{
732 int i,ret = NC_NOERR;
733 int nids;
734 int* ids = NULL;
735
736 /* Get all types in grp */
737 if(tid2)
738 *tid2 = 0;
739 if ((ret = nc_inq_typeids(grp, &nids, NULL)))
740 goto done;
741 if (nids)
742 {
743 if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
744 {ret = NC_ENOMEM; goto done;}
745 if ((ret = nc_inq_typeids(grp, &nids, ids)))
746 goto done;
747 for(i = 0; i < nids; i++)
748 {
749 int equal = 0;
750 if ((ret = NC_compare_nc_types(ncid1, tid1, grp, ids[i], &equal)))
751 goto done;
752 if(equal)
753 {
754 if(tid2)
755 *tid2 = ids[i];
756 goto done;
757 }
758 }
759 }
760
761done:
762 nullfree(ids);
763 return ret;
764}
765
766/* Helper function for NC_rec_find_nc_type();
767 search a tree of groups for a matching type
768 using a breadth first queue
769*/
770static int
771searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
772{
773 int i,ret = NC_NOERR;
774 int nids;
775 int* ids = NULL;
776 NClist* queue = nclistnew();
777 int gid;
778 uintptr_t id;
779
780 id = grp;
781 nclistpush(queue,(void*)id); /* prime the queue */
782 while(nclistlength(queue) > 0) {
783 id = (uintptr_t)nclistremove(queue,0);
784 gid = (int)id;
785 if((ret = searchgroup(ncid1,tid1,gid,tid2)))
786 goto done;
787 if(*tid2 != 0)
788 goto done; /*we found it*/
789 /* Get subgroups of gid and push onto front of the queue (for breadth first) */
790 if((ret = nc_inq_grps(gid,&nids,NULL)))
791 goto done;
792 if (!(ids = (int *)malloc((size_t)nids * sizeof(int))))
793 {ret = NC_ENOMEM; goto done;}
794 if ((ret = nc_inq_grps(gid, &nids, ids)))
795 goto done;
796 /* push onto the end of the queue */
797 for(i=0;i<nids;i++) {
798 id = ids[i];
799 nclistpush(queue,(void*)id);
800 }
801 free(ids); ids = NULL;
802 }
803 /* Not found */
804 ret = NC_EBADTYPE;
805
806done:
807 nclistfree(queue);
808 nullfree(ids);
809 return ret;
810}
811
812#endif
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
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:659
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
EXTERNL int nc_get_att_string(int ncid, int varid, const char *name, char **ip)
Get an attribute array of type string.
Definition: dattget.c:711
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_get_att(int ncid, int varid, const char *name, void *ip)
Get an attribute of any type.
Definition: dattget.c:133
EXTERNL int nc_inq_attid(int ncid, int varid, const char *name, int *idp)
Find an attribute ID.
Definition: dattinq.c:164
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:75
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_attname(int ncid, int varid, int attnum, char *name)
Find the name of an attribute.
Definition: dattinq.c:255
EXTERNL int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
Definition: dfile.c:1730
EXTERNL int nc_enddef(int ncid)
Leave define mode.
Definition: dfile.c:1029
EXTERNL int nc_redef(int ncid)
Put open netcdf dataset into define mode.
Definition: dfile.c:965
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:1549
EXTERNL int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
Definition: dfile.c:1197
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_dimname(int ncid, int dimid, char *name)
Find out the name of a dimension.
Definition: ddim.c:409
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
EXTERNL int nc_inq_typeids(int ncid, int *ntypes, int *typeids)
Retrieve a list of types associated with a group.
Definition: dgroup.c:223
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_grp_parent(int ncid, int *parent_ncid)
Get the ID of the parent based on a group ID.
Definition: dgroup.c:136
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
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
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Free memory in a VLEN object.
Definition: dvlen.c:43
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
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:652
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:796
EXTERNL int nc_free_string(size_t len, char **data)
Free string space allocated by the library.
Definition: dvar.c:1316
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:740
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:692
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:754
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:803
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:676
EXTERNL int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
Definition: dvarinq.c:249
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:768
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:817
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:761
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
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:782
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:716
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:732
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:775
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:700
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_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:644
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:824
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:724
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:831
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:668
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:838
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:660
#define NC_FORMAT_64BIT_OFFSET
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:184
#define NC_FORMAT_NETCDF4_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:187
#define NC_EBADTYPE
Not a netcdf data type.
Definition: netcdf.h:410
#define NC_UINT
unsigned 4-byte int
Definition: netcdf.h:44
#define NC_INT
signed 4 byte integer
Definition: netcdf.h:38
#define NC_MAX_VAR_DIMS
max per variable dimensions
Definition: netcdf.h:282
#define NC_BYTE
signed 1 byte integer
Definition: netcdf.h:35
#define NC_VLEN
vlen (variable-length) types
Definition: netcdf.h:53
#define NC_ENOGRP
No group found.
Definition: netcdf.h:505
#define NC_NAT
Not A Type.
Definition: netcdf.h:34
#define NC_DOUBLE
double precision floating point number
Definition: netcdf.h:41
#define NC_UBYTE
unsigned 1 byte int
Definition: netcdf.h:42
#define NC_FLOAT
single precision floating point number
Definition: netcdf.h:40
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
Definition: netcdf.h:491
#define NC_ENOMEM
Memory allocation (malloc) failure.
Definition: netcdf.h:448
#define NC_COMPOUND
compound types
Definition: netcdf.h:56
#define NC_EINDEFINE
Operation not allowed in define mode.
Definition: netcdf.h:393
#define NC_SHORT
signed 2 byte integer
Definition: netcdf.h:37
#define NC_ENUM
enum types
Definition: netcdf.h:55
#define NC_INT64
signed 8-byte int
Definition: netcdf.h:45
#define NC_FORMAT_NETCDF4
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:186
#define NC_UINT64
unsigned 8-byte int
Definition: netcdf.h:46
#define NC_ENOTATT
Attribute not found.
Definition: netcdf.h:408
#define NC_FORMAT_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:178
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:378
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:281
#define NC_NOERR
No Error.
Definition: netcdf.h:368
#define NC_USHORT
unsigned 2-byte int
Definition: netcdf.h:43
#define NC_OPAQUE
opaque types
Definition: netcdf.h:54
#define NC_STRING
string
Definition: netcdf.h:47
#define NC_CHAR
ISO/ASCII character.
Definition: netcdf.h:36
#define NC_FORMAT_64BIT_DATA
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:188
int nc_type
The nc_type type is just an int.
Definition: netcdf.h:25
This is the type of arrays of vlens.
Definition: netcdf.h:746