10 #include "ncdispatch.h"
11 #include "nc_logging.h"
29 NC_compare_nc_types(
int ncid1,
int typeid1,
int ncid2,
int typeid2,
43 if (typeid1 <= NC_MAX_ATOMIC_TYPE)
45 if (typeid2 != typeid1)
56 size_t nelems1, nelems2;
60 size_t offset1, offset2;
68 &base1, &nelems1, &class1)))
71 &base2, &nelems2, &class2)))
75 if(size1 != size2 || class1 != class2 || strcmp(name1,name2))
82 if((ret = NC_compare_nc_types(ncid1, base1, ncid2,
92 if(base1 != base2 || nelems1 != nelems2)
return NC_NOERR;
94 if (!(value1 = malloc(size1)))
96 if (!(value2 = malloc(size2))) {
101 for(i = 0; i < nelems1; i++)
107 strcmp(name1, name2) || memcmp(value1, value2, size1))
118 if(nelems1 != nelems2)
122 for(i = 0; i < nelems1; i++)
126 &ftype1, &ndims1, dimsizes1)))
129 &ftype2, &ndims2, dimsizes2)))
133 for(j = 0; j < ndims1;j++)
134 if(dimsizes1[j] != dimsizes2[j])
138 if((ret = NC_compare_nc_types(ncid1, ftype1, ncid2, ftype2,
166 NC_rec_find_nc_type(
int ncid1,
nc_type tid1,
int ncid2,
nc_type* tid2)
179 if (!(ids = (
int *)malloc((
size_t)nids *
sizeof(
int))))
183 for(i = 0; i < nids; i++)
186 if ((ret = NC_compare_nc_types(ncid1, tid1, ncid2, ids[i], &equal)))
204 if (!(ids = (
int *)malloc((
size_t)nids *
sizeof(
int))))
211 for (i = 0; i < nids; i++)
213 ret = NC_rec_find_nc_type(ncid1, tid1, ids[i], tid2);
216 if (tid2 && *tid2 != 0)
240 NC_find_equal_type(
int ncid1,
nc_type xtype1,
int ncid2,
nc_type *xtype2)
249 if (xtype1 <= NC_MAX_ATOMIC_TYPE)
259 ret = NC_rec_find_nc_type(ncid1, xtype1 , ncid2, xtype2);
303 size_t *count = NULL, *start = NULL;
305 size_t *dimlen = NULL;
308 int src_format, dest_format;
314 if ((retval =
nc_inq_var(ncid_in, varid_in, name, &xtype,
315 &ndims, dimids_in, &natts)))
318 for(i = 0; i < ndims; i++) {
319 dimids_out[i] = dimids_in[i];
322 if ((retval =
nc_inq_dimid(ncid_out, dimname_in, &dimids_out[i])))
327 LOG((2,
"nc_copy_var: ncid_in 0x%x varid_in %d ncid_out 0x%x",
328 ncid_in, varid_in, ncid_out));
344 if ((retval =
nc_inq_type(ncid_in, xtype, type_name, &type_size)))
347 LOG((3,
"type %s has size %d", type_name, type_size));
354 if ((retval =
nc_def_var(ncid_out, name, xtype,
355 ndims, dimids_out, &varid_out)))
359 for (a=0; a<natts; a++)
363 if ((retval =
nc_copy_att(ncid_in, varid_in, att_name,
364 ncid_out, varid_out)))
375 real_ndims = ndims ? ndims : 1;
376 if (!(start = malloc((
size_t)real_ndims *
sizeof(
size_t))))
378 if (!(count = malloc((
size_t)real_ndims *
sizeof(
size_t))))
386 if (!(dimlen = malloc((
size_t)real_ndims *
sizeof(
size_t))))
394 for (d=0; d<ndims; d++)
396 if ((retval =
nc_inq_dimlen(ncid_in, dimids_in[d], &dimlen[d])))
399 LOG((4,
"nc_copy_var: there are %d data", dimlen[d]));
407 for (d=0; d<real_ndims; d++)
410 count[d] = d ? dimlen[d] : 1;
411 if (d) reclen *= dimlen[d];
419 if (!(data = malloc(reclen * type_size))) {
420 if(count) free(count);
421 if(dimlen) free(dimlen);
422 if(start) free(start);
427 for (start[0]=0; !retval && start[0]<(size_t)dimlen[0]; start[0]++)
433 (
signed char *)data);
436 (
const signed char *)data);
475 (
unsigned char *)data);
478 (
unsigned char *)data);
482 (
unsigned short *)data);
485 (
unsigned short *)data);
489 (
unsigned int *)data);
492 (
unsigned int *)data);
503 (
unsigned long long *)data);
506 (
unsigned long long *)data);
514 if (data) free(data);
515 if (dimlen) free(dimlen);
516 if (start) free(start);
517 if (count) free(count);
536 int ncid_out,
int varid_out)
543 LOG((2,
"nc_copy_att: ncid_in 0x%x varid_in %d name %s",
544 ncid_in, varid_in, name));
547 if ((res =
nc_inq_att(ncid_in, varid_in, name, &xtype, &len)))
555 size_t size = NC_atomictypelen(xtype);
558 if (!(data = malloc(len * size)))
562 res =
nc_get_att(ncid_in, varid_in, name, data);
564 res =
nc_put_att(ncid_out, varid_out, name, xtype,
574 if (!(str_data = malloc(
sizeof(
char *) * len)))
579 (
const char **)str_data);
594 if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
600 NULL, NULL, &
class)))
606 if (!(vldata = malloc(
sizeof(
nc_vlen_t) * len)))
608 if ((res =
nc_get_att(ncid_in, varid_in, name, vldata)))
610 if ((res =
nc_put_att(ncid_out, varid_out, name, xtype_out,
613 for (i = 0; i < len; i++)
620 if (!(data = malloc(size * len)))
622 res =
nc_get_att(ncid_in, varid_in, name, data);
624 res =
nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
656 int ncid_out,
int varid_out)
658 int format, target_natts, target_attid;
667 if (ncid_in == ncid_out && varid_in == varid_out)
675 retval =
nc_inq_attid(ncid_out, varid_out, name, &target_attid);
679 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
689 if (target_attid == target_natts - 1)
690 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
694 for (a = 0; a < target_natts; a++)
696 if (a == target_attid)
698 if ((retval =
NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out)))
705 if ((retval =
NC_copy_att(ncid_out, varid_out, att_name,
706 ncid_out, varid_out)))
715 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
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.
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
#define NC_CHAR
ISO/ASCII character.
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.
EXTERNL int nc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
Return information about a netCDF attribute.
EXTERNL int nc_inq_dimname(int ncid, int dimid, char *name)
Find out the name of a dimension.
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
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.
#define NC_UBYTE
unsigned 1 byte int
#define NC_MAX_VAR_DIMS
max per variable dimensions
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.
EXTERNL int nc_redef(int ncid)
Put open netcdf dataset into define mode.
#define NC_UINT
unsigned 4-byte int
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.
#define NC_OPAQUE
opaque types
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.
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.
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.
#define NC_INT64
signed 8-byte int
#define NC_DOUBLE
double precision floating point number
EXTERNL int nc_inq_format(int ncid, int *formatp)
Inquire about the binary format of a netCDF file as presented by the API.
int nc_type
The nc_type type is just an int.
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.
#define NC_BYTE
signed 1 byte integer
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.
#define NC_EINDEFINE
Operation not allowed in define mode.
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.
#define NC_VLEN
vlen (variable-length) types
EXTERNL int nc_inq_dimlen(int ncid, int dimid, size_t *lenp)
Find the length of a dimension.
EXTERNL int nc_get_att_string(int ncid, int varid, const char *name, char **ip)
Get a variable-length string attribute.
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.
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.
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
Get an attribute of any type.
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.
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.
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.
#define NC_EBADTYPE
Not a netcdf data type.
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.
#define NC_EINVAL
Invalid Argument.
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.
#define NC_INT
signed 4 byte integer
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.
#define NC_MAX_NAME
Maximum for classic library.
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.
#define NC_NAT
Not A Type.
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.
EXTERNL int nc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op)
Write an attribute.
EXTERNL int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Free memory in a VLEN object.
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.
EXTERNL int nc_free_string(size_t len, char **data)
Free string space allocated by the library.
#define NC_USHORT
unsigned 2-byte int
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.
#define NC_FORMAT_NETCDF4_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_FORMAT_NETCDF4
Format specifier for nc_set_default_format() and returned by nc_inq_format.
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...
EXTERNL int nc_inq_dimid(int ncid, const char *name, int *idp)
Find the ID of a dimension from the name.
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.
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.
This is the type of arrays of vlens.
#define NC_FORMAT_64BIT_DATA
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_SHORT
signed 2 byte integer
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.
EXTERNL int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
Learn about a variable.
#define NC_NOERR
No Error.
#define NC_ENUM
enum types
EXTERNL int nc_put_att_string(int ncid, int varid, const char *name, size_t len, const char **op)
Write a string attribute.
EXTERNL int nc_inq_grps(int ncid, int *numgrps, int *ncids)
Get a list of groups or subgroups from a file or groupID.
EXTERNL int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
EXTERNL int nc_enddef(int ncid)
Leave define mode.
#define NC_COMPOUND
compound types
#define NC_FORMAT_64BIT_OFFSET
Format specifier for nc_set_default_format() and returned by nc_inq_format.
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.
EXTERNL int nc_inq_attid(int ncid, int varid, const char *name, int *idp)
Find an attribute ID.
#define NC_FLOAT
single precision floating point number
#define NC_FORMAT_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_ENOTATT
Attribute not found.
EXTERNL int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
#define NC_UINT64
unsigned 8-byte int
EXTERNL int nc_inq_attname(int ncid, int varid, int attnum, char *name)
Find the name of an attribute.
EXTERNL int nc_inq_typeids(int ncid, int *ntypes, int *typeids)
Retrieve a list of types associated with a group.