11#include "ncdispatch.h"
12#include "nc_logging.h"
46 if (typeid2 != typeid1)
57 size_t nelems1, nelems2;
61 size_t offset1, offset2;
69 &base1, &nelems1, &class1)))
72 &base2, &nelems2, &class2)))
76 if(size1 != size2 || class1 != class2 || strcmp(name1,name2))
93 if(base1 != base2 || nelems1 != nelems2)
return NC_NOERR;
95 if (!(value1 = malloc(size1)))
97 if (!(value2 = malloc(size2))) {
102 for(i = 0; i < nelems1; i++)
108 strcmp(name1, name2) || memcmp(value1, value2, size1))
119 if(nelems1 != nelems2)
123 for(i = 0; i < nelems1; i++)
127 &ftype1, &ndims1, dimsizes1)))
130 &ftype2, &ndims2, dimsizes2)))
134 for(j = 0; j < ndims1;j++)
135 if(dimsizes1[j] != dimsizes2[j])
180 if (!(ids = (
int *)malloc((
size_t)nids *
sizeof(
int))))
184 for(i = 0; i < nids; i++)
205 if (!(ids = (
int *)malloc((
size_t)nids *
sizeof(
int))))
212 for (i = 0; i < nids; i++)
217 if (tid2 && *tid2 != 0)
304 size_t *count = NULL, *start = NULL;
306 size_t *dimlen = NULL;
309 int src_format, dest_format;
315 if ((retval =
nc_inq_var(ncid_in, varid_in, name, &xtype,
316 &ndims, dimids_in, &natts)))
319 for(i = 0; i < ndims; i++) {
320 dimids_out[i] = dimids_in[i];
323 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));
343 if ((retval =
nc_inq_type(ncid_in, xtype, type_name, &type_size)))
345 LOG((3,
"type %s has size %d", type_name, type_size));
351 if ((retval =
nc_def_var(ncid_out, name, xtype,
352 ndims, dimids_out, &varid_out)))
356 for (a=0; a<natts; a++)
360 if ((retval =
nc_copy_att(ncid_in, varid_in, att_name,
361 ncid_out, varid_out)))
372 real_ndims = ndims ? ndims : 1;
373 if (!(start = malloc((
size_t)real_ndims *
sizeof(
size_t))))
375 if (!(count = malloc((
size_t)real_ndims *
sizeof(
size_t))))
383 if (!(dimlen = malloc((
size_t)real_ndims *
sizeof(
size_t))))
391 for (d=0; d<ndims; d++)
393 if ((retval =
nc_inq_dimlen(ncid_in, dimids_in[d], &dimlen[d])))
395 LOG((4,
"nc_copy_var: there are %d data", dimlen[d]));
402 for (d=0; d<real_ndims; d++)
405 count[d] = d ? dimlen[d] : 1;
406 if (d) reclen *= dimlen[d];
414 if (!(data = malloc(reclen * type_size))) {
415 if(count) free(count);
416 if(dimlen) free(dimlen);
417 if(start) free(start);
422 for (start[0]=0; !retval && start[0]<(size_t)dimlen[0]; start[0]++)
427 retval = nc_get_vara_schar(ncid_in, varid_in, start, count,
428 (
signed char *)data);
430 retval = nc_put_vara_schar(ncid_out, varid_out, start, count,
431 (
const signed char *)data);
434 retval = nc_get_vara_text(ncid_in, varid_in, start, count,
437 retval = nc_put_vara_text(ncid_out, varid_out, start, count,
441 retval = nc_get_vara_short(ncid_in, varid_in, start, count,
444 retval = nc_put_vara_short(ncid_out, varid_out, start, count,
448 retval = nc_get_vara_int(ncid_in, varid_in, start, count,
451 retval = nc_put_vara_int(ncid_out, varid_out, start, count,
455 retval = nc_get_vara_float(ncid_in, varid_in, start, count,
458 retval = nc_put_vara_float(ncid_out, varid_out, start, count,
462 retval = nc_get_vara_double(ncid_in, varid_in, start, count,
465 retval = nc_put_vara_double(ncid_out, varid_out, start, count,
469 retval = nc_get_vara_uchar(ncid_in, varid_in, start, count,
470 (
unsigned char *)data);
472 retval = nc_put_vara_uchar(ncid_out, varid_out, start, count,
473 (
unsigned char *)data);
476 retval = nc_get_vara_ushort(ncid_in, varid_in, start, count,
477 (
unsigned short *)data);
479 retval = nc_put_vara_ushort(ncid_out, varid_out, start, count,
480 (
unsigned short *)data);
483 retval = nc_get_vara_uint(ncid_in, varid_in, start, count,
484 (
unsigned int *)data);
486 retval = nc_put_vara_uint(ncid_out, varid_out, start, count,
487 (
unsigned int *)data);
490 retval = nc_get_vara_longlong(ncid_in, varid_in, start, count,
493 retval = nc_put_vara_longlong(ncid_out, varid_out, start, count,
497 retval = nc_get_vara_ulonglong(ncid_in, varid_in, start, count,
498 (
unsigned long long *)data);
500 retval = nc_put_vara_ulonglong(ncid_out, varid_out, start, count,
501 (
unsigned long long *)data);
509 if (data) free(data);
510 if (dimlen) free(dimlen);
511 if (start) free(start);
512 if (count) free(count);
531 int ncid_out,
int varid_out)
538 LOG((2,
"nc_copy_att: ncid_in 0x%x varid_in %d name %s",
539 ncid_in, varid_in, name));
542 if ((res =
nc_inq_att(ncid_in, varid_in, name, &xtype, &len)))
553 if (!(data = malloc(len * size)))
557 res =
nc_get_att(ncid_in, varid_in, name, data);
559 res =
nc_put_att(ncid_out, varid_out, name, xtype,
569 if (!(str_data = malloc(
sizeof(
char *) * len)))
574 (
const char **)str_data);
595 NULL, NULL, &
class)))
601 if (!(vldata = malloc(
sizeof(
nc_vlen_t) * len)))
603 if ((res =
nc_get_att(ncid_in, varid_in, name, vldata)))
605 if ((res =
nc_put_att(ncid_out, varid_out, name, xtype_out,
608 for (i = 0; i < len; i++)
615 if (!(data = malloc(size * len)))
617 res =
nc_get_att(ncid_in, varid_in, name, data);
619 res =
nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
651 int ncid_out,
int varid_out)
653 int format, target_natts, target_attid;
662 if (ncid_in == ncid_out && varid_in == varid_out)
670 retval =
nc_inq_attid(ncid_out, varid_out, name, &target_attid);
674 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
684 if (target_attid == target_natts - 1)
685 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
689 for (a = 0; a < target_natts; a++)
691 if (a == target_attid)
693 if ((retval =
NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out)))
700 if ((retval =
NC_copy_att(ncid_out, varid_out, att_name,
701 ncid_out, varid_out)))
710 return NC_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
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...
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.
static int NC_rec_find_nc_type(int ncid1, nc_type tid1, int ncid2, nc_type *tid2)
static int NC_find_equal_type(int ncid1, nc_type xtype1, int ncid2, nc_type *xtype2)
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.
static int NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2, int *equalp)
EXTERNL int nc_get_att_string(int ncid, int varid, const char *name, char **ip)
Get an attribute array of type string.
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.
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
Get an attribute of any type.
EXTERNL int nc_inq_attid(int ncid, int varid, const char *name, int *idp)
Find an attribute ID.
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_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
Return information about a netCDF attribute.
EXTERNL int nc_inq_attname(int ncid, int varid, int attnum, char *name)
Find the name of an attribute.
EXTERNL int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
EXTERNL int nc_enddef(int ncid)
Leave define mode.
EXTERNL int nc_redef(int ncid)
Put open netcdf dataset into define mode.
EXTERNL int nc_inq_format(int ncid, int *formatp)
Inquire about the binary format of a netCDF file as presented by the API.
EXTERNL int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
EXTERNL int nc_inq_dimlen(int ncid, int dimid, size_t *lenp)
Find the length of a dimension.
EXTERNL int nc_inq_dimname(int ncid, int dimid, char *name)
Find out the name of a dimension.
EXTERNL int nc_inq_dimid(int ncid, const char *name, int *idp)
Find the ID of a dimension from the name.
EXTERNL int nc_inq_typeids(int ncid, int *ntypes, int *typeids)
Retrieve a list of types associated with a group.
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_enum_member(int ncid, nc_type xtype, int idx, char *name, void *value)
Learn about a about a member of an enum type.
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.
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Free memory in a VLEN object.
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_free_string(size_t len, char **data)
Free string space allocated by the library.
EXTERNL int nc_inq_varnatts(int ncid, int varid, int *nattsp)
Learn how many attributes are associated with a variable.
size_t NC_atomictypelen(nc_type xtype)
EXTERNL int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
Learn about a variable.
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
#define NC_FORMAT_64BIT_OFFSET
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_FORMAT_NETCDF4_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_EBADTYPE
Not a netcdf data type.
#define NC_UINT
unsigned 4-byte int
#define NC_INT
signed 4 byte integer
#define NC_MAX_VAR_DIMS
max per variable dimensions
#define NC_BYTE
signed 1 byte integer
#define NC_VLEN
vlen (variable-length) types
#define NC_NAT
Not A Type.
#define NC_DOUBLE
double precision floating point number
#define NC_UBYTE
unsigned 1 byte int
#define NC_FLOAT
single precision floating point number
#define NC_MAX_ATOMIC_TYPE
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_COMPOUND
compound types
#define NC_EINDEFINE
Operation not allowed in define mode.
#define NC_SHORT
signed 2 byte integer
#define NC_ENUM
enum types
#define NC_INT64
signed 8-byte int
#define NC_FORMAT_NETCDF4
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_UINT64
unsigned 8-byte int
#define NC_ENOTATT
Attribute not found.
#define NC_FORMAT_CLASSIC
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.
#define NC_USHORT
unsigned 2-byte int
#define NC_OPAQUE
opaque types
#define NC_CHAR
ISO/ASCII character.
#define NC_FORMAT_64BIT_DATA
Format specifier for nc_set_default_format() and returned by nc_inq_format.
int nc_type
The nc_type type is just an int.
This is the type of arrays of vlens.