/* Copyright 2010 University Corporation for Atmospheric Research/Unidata. See COPYRIGHT file for more info. This file has the var and att copy functions. "$Id: copy.c,v 1.1 2010/06/01 15:46:49 ed Exp $" */ #include "ncdispatch.h" #include #ifdef USE_NETCDF4 /* Compare two netcdf types for equality. Must have the ncids as well, to find user-defined types. */ static int NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2, int *equalp) { int ret = NC_NOERR; if(equalp == NULL) return NC_NOERR; /* Assume the types are not equal. If we find any inequality, then exit with NC_NOERR and we're done. */ *equalp = 0; /* Atomic types are so easy! */ if (typeid1 <= ATOMICTYPEMAX) { if (typeid2 != typeid1) return NC_NOERR; *equalp = 1; } else { int i, ret, equal1; char name1[NC_MAX_NAME]; char name2[NC_MAX_NAME]; size_t size1, size2; nc_type base1, base2; size_t nelems1, nelems2; int class1, class2; void* value1 = NULL; void* value2 = NULL; size_t offset1, offset2; nc_type ftype1, ftype2; int ndims1, ndims2; int dimsizes1[NC_MAX_VAR_DIMS]; int dimsizes2[NC_MAX_VAR_DIMS]; ret = nc_inq_user_type(ncid1,typeid1,name1,&size1,&base1,&nelems1,&class1); if(ret) return ret; ret = nc_inq_user_type(ncid2,typeid2,name2,&size2,&base2,&nelems2,&class2); if(ret) return ret; /* Check the obvious. */ if(size1 != size2 || class1 != class2 || strcmp(name1,name2)) return NC_NOERR; /* Check user-defined types in detail. */ switch(class1) { case NC_VLEN: if(base1 <= NC_STRING) { if(base1 != base2) return NC_NOERR; } else { /* User defined type in VLEN! */ if((ret = NC_compare_nc_types(ncid1,base1,ncid2,base1,&equal1))) return ret; if(!equal1) return NC_NOERR; } break; case NC_OPAQUE: /* Already checked size above. */ break; case NC_ENUM: if(base1 != base2 || nelems1 != nelems2) return NC_NOERR; value1 = malloc(size1); value2 = malloc(size2); for(i=0;i NC_DOUBLE) return NC_ENOTNC4; /* Later on, we will need to know the size of this type. */ if ((retval = nc_inq_type(ncid_in, xtype, type_name, &type_size))) return retval; #ifdef USE_NETCDF4 LOG((3, "type %s has size %d", type_name, type_size)); #endif /* Switch back to define mode, and create the output var. */ retval = nc_redef(ncid_out); if (retval && retval != NC_EINDEFINE) BAIL(retval); if ((retval = nc_def_var(ncid_out, name, xtype, ndims, dimids, &varid_out))) BAIL(retval); /* Copy the attributes. */ for (a=0; a