/* Get the format (i.e. classic, 64-bit-offset, or netcdf-4) of an * open file. */ int NC4_inq_format(int ncid, int *formatp) { NC *nc; NC_HDF5_FILE_INFO_T* nc4_info; LOG((2, "nc_inq_format: ncid 0x%x", ncid)); if (!formatp) return NC_NOERR; /* Find the file metadata. */ if (!(nc = nc4_find_nc_file(ncid,&nc4_info))) return NC_EBADID; #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (nc4_info->pnetcdf_file) return ncmpi_inq_format(nc->int_ncid, formatp); #endif /* USE_PNETCDF */ /* Otherwise, this is a netcdf-4 file. Check if classic NC3 rules * are in effect for this file. */ if (nc4_info->cmode & NC_CLASSIC_MODEL) *formatp = NC_FORMAT_NETCDF4_CLASSIC; else *formatp = NC_FORMAT_NETCDF4; return NC_NOERR; }
/* Given an attnum, find the att's name. */ int NC4_inq_attname(int ncid, int varid, int attnum, char *name) { NC *nc; NC_ATT_INFO_T *att; NC_HDF5_FILE_INFO_T *h5; int retval = NC_NOERR; LOG((2, "nc_inq_attname: ncid 0x%x varid %d attnum %d", ncid, varid, attnum)); /* Find metadata. */ if (!(nc = nc4_find_nc_file(ncid,NULL))) return NC_EBADID; /* get netcdf-4 metadata */ h5 = NC4_DATA(nc); assert(h5); #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (h5->pnetcdf_file) return ncmpi_inq_attname(nc->int_ncid, varid, attnum, name); #endif /* USE_PNETCDF */ /* Handle netcdf-4 files. */ if ((retval = nc4_find_nc_att(ncid, varid, NULL, attnum, &att))) return retval; /* Get the name. */ if (name) strcpy(name, att->name); return NC_NOERR; }
/* Get the format (i.e. classic, 64-bit-offset, or netcdf-4) of an * open file. */ int NC4_inq_format(int ncid, int *formatp) { NC_FILE_INFO_T *nc; LOG((2, "nc_inq_format: ncid 0x%x", ncid)); if (!formatp) return NC_NOERR; /* Find the file metadata. */ if (!(nc = nc4_find_nc_file(ncid))) return NC_EBADID; /* If this isn't a netcdf-4 file, pass this call on to the netcdf-3 * library. */ if (!nc->nc4_info) return NC3_inq_format(nc->int_ncid, formatp); /* Otherwise, this is a netcdf-4 file. Check if classic NC3 rules * are in effect for this file. */ if (nc->nc4_info->cmode & NC_CLASSIC_MODEL) *formatp = NC_FORMAT_NETCDF4_CLASSIC; else *formatp = NC_FORMAT_NETCDF4; return NC_NOERR; }
/* Learn an attnum, given a name. */ int NC4_inq_attid(int ncid, int varid, const char *name, int *attnump) { NC *nc; NC_HDF5_FILE_INFO_T *h5; LOG((2, "nc_inq_attid: ncid 0x%x varid %d name %s", ncid, varid, name)); /* Find metadata. */ if (!(nc = nc4_find_nc_file(ncid,NULL))) return NC_EBADID; /* get netcdf-4 metadata */ h5 = NC4_DATA(nc); assert(h5); #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (h5->pnetcdf_file) return ncmpi_inq_attid(nc->int_ncid, varid, name, attnump); #endif /* USE_PNETCDF */ /* Handle netcdf-4 files. */ return nc4_get_att(ncid, nc, varid, name, NULL, NC_UBYTE, NULL, attnump, 0, NULL); }
/* Learn about an att. All the nc4 nc_inq_ functions just call * add_meta_get to get the metadata on an attribute. */ int NC4_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp) { NC *nc; NC_HDF5_FILE_INFO_T *h5; LOG((2, "nc_inq_att: ncid 0x%x varid %d name %s", ncid, varid, name)); /* Find metadata. */ if (!(nc = nc4_find_nc_file(ncid,NULL))) return NC_EBADID; /* get netcdf-4 metadata */ h5 = NC4_DATA(nc); assert(h5); #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (h5->pnetcdf_file) { MPI_Offset mpi_len; int ret = ncmpi_inq_att(nc->int_ncid, varid, name, xtypep, &mpi_len); if (ret != NC_NOERR) return ret; if (lenp) *lenp = mpi_len; } #endif /* USE_PNETCDF */ /* Handle netcdf-4 files. */ return nc4_get_att(ncid, nc, varid, name, xtypep, NC_UBYTE, lenp, NULL, 0, NULL); }
/* This function only does anything for netcdf-3 files. */ int NC4_inq_base_pe(int ncid, int *pe) { NC_FILE_INFO_T *nc; if (!(nc = nc4_find_nc_file(ncid))) return NC_EBADID; if (nc->nc4_info) return NC_ENOTNC3; return NC3_inq_base_pe(nc->int_ncid, pe); }
/* Read an attribute of any type, with type conversion. This may be * called by any of the nc_get_att_* functions. */ int nc4_get_att_tc(int ncid, int varid, const char *name, nc_type mem_type, int mem_type_is_long, void *ip) { NC *nc; NC_HDF5_FILE_INFO_T *h5; LOG((3, "nc4_get_att_tc: ncid 0x%x varid %d name %s mem_type %d", ncid, varid, name, mem_type)); /* Find metadata. */ if (!(nc = nc4_find_nc_file(ncid,NULL))) return NC_EBADID; /* get netcdf-4 metadata */ h5 = NC4_DATA(nc); assert(h5); #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (h5->pnetcdf_file) { if (mem_type == NC_UBYTE) mem_type = NC_BYTE; switch(mem_type) { case NC_BYTE: return ncmpi_get_att_schar(nc->int_ncid, varid, name, ip); case NC_CHAR: return ncmpi_get_att_text(nc->int_ncid, varid, name, ip); case NC_SHORT: return ncmpi_get_att_short(nc->int_ncid, varid, name, ip); case NC_INT: if (mem_type_is_long) return ncmpi_get_att_long(nc->int_ncid, varid, name, ip); else return ncmpi_get_att_int(nc->int_ncid, varid, name, ip); case NC_FLOAT: return ncmpi_get_att_float(nc->int_ncid, varid, name, ip); case NC_DOUBLE: return ncmpi_get_att_double(nc->int_ncid, varid, name, ip); case NC_NAT: default: return NC_EBADTYPE; } } #endif /* USE_PNETCDF */ return nc4_get_att(ncid, nc, varid, name, NULL, mem_type, NULL, NULL, mem_type_is_long, ip); }
/* Given an ncid, find the relevant group and return a pointer to it, * also set a pointer to the nc4_info struct of the related file. For * netcdf-3 files, *h5 will be set to NULL. */ int nc4_find_grp_h5(int ncid, NC_GRP_INFO_T **grp, NC_HDF5_FILE_INFO_T **h5) { NC_FILE_INFO_T *f = nc4_find_nc_file(ncid); if(f == NULL) return NC_EBADID; if (f->nc4_info) { assert(f->nc4_info->root_grp); /* If we can't find it, the grp id part of ncid is bad. */ if (!(*grp = nc4_rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK)))) return NC_EBADID; *h5 = (*grp)->file->nc4_info; assert(*h5); } else { *h5 = NULL; *grp = NULL; } return NC_NOERR; }
int nc4_find_nc4_grp(int ncid, NC_GRP_INFO_T **grp) { NC_FILE_INFO_T *f = nc4_find_nc_file(ncid); if(f == NULL) return NC_EBADID; /* No netcdf-3 files allowed! */ if (!f->nc4_info) return NC_ENOTNC4; assert(f->nc4_info->root_grp); /* This function demands netcdf-4 files without strict nc3 * rules.*/ if (f->nc4_info->cmode & NC_CLASSIC_MODEL) return NC_ESTRICTNC3; /* If we can't find it, the grp id part of ncid is bad. */ if (!(*grp = nc4_rec_find_grp(f->nc4_info->root_grp, (ncid & GRP_ID_MASK)))) return NC_EBADID; return NC_NOERR; }
/* Given an ncid, find the relevant group and return a pointer to it, * also set a pointer to the nc4_info struct of the related file. For * netcdf-3 files, *h5 will be set to NULL. */ int nc4_find_grp_h5(int ncid, NC_GRP_INFO_T **grpp, NC_HDF5_FILE_INFO_T **h5p) { NC_HDF5_FILE_INFO_T *h5; NC_GRP_INFO_T *grp; NC *f = nc4_find_nc_file(ncid,&h5); if(f == NULL) return NC_EBADID; if (h5) { assert(h5->root_grp); /* If we can't find it, the grp id part of ncid is bad. */ if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK)))) return NC_EBADID; h5 = (grp)->nc4_info; assert(h5); } else { h5 = NULL; grp = NULL; } if(h5p) *h5p = h5; if(grpp) *grpp = grp; return NC_NOERR; }
int nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grpp, NC_HDF5_FILE_INFO_T **h5p) { NC_GRP_INFO_T *grp; NC_HDF5_FILE_INFO_T* h5; NC *f = nc4_find_nc_file(ncid,&h5); if(f == NULL) return NC_EBADID; *nc = f; #if 0 /* I do not understand this code at all */ #if 0 /*def USE_PNETCDF*/ if (h5->pnetcdf_file) { *h5p = NULL; *grpp = NULL; return NC_NOERR; } #endif #endif if (h5) { assert(h5->root_grp); /* If we can't find it, the grp id part of ncid is bad. */ if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK)))) return NC_EBADID; h5 = (grp)->nc4_info; assert(h5); } else { h5 = NULL; grp = NULL; } if(h5p) *h5p = h5; if(grpp) *grpp = grp; return NC_NOERR; }
/* Get the extended format of an open file. */ int NC4_inq_format_extended(int ncid, int *formatp, int *modep) { NC *nc; NC_HDF5_FILE_INFO_T* h5; LOG((2, "nc_inq_format_extended: ncid 0x%x", ncid)); /* Find the file metadata. */ if (!(nc = nc4_find_nc_file(ncid,&h5))) return NC_EBADID; if(modep) *modep = (nc->mode|NC_NETCDF4); if(formatp) { #ifdef USE_HDF4 /* Distinguish HDF5 from HDF4 */ *formatp = (h5->hdf4 ? NC_FORMATX_NC_HDF4 : NC_FORMATX_NC_HDF5); #else /* USE_HDF4 */ *formatp = NC_FORMATX_NC_HDF5; #endif /* USE_HDF4 */ } return NC_NOERR; }
/* Write an attribute with type conversion. */ static int nc4_put_att_tc(int ncid, int varid, const char *name, nc_type file_type, nc_type mem_type, int mem_type_is_long, size_t len, const void *op) { NC *nc; NC_HDF5_FILE_INFO_T *h5; if (!name || strlen(name) > NC_MAX_NAME) return NC_EBADNAME; LOG((3, "nc4_put_att_tc: ncid 0x%x varid %d name %s file_type %d " "mem_type %d len %d", ncid, varid, name, file_type, mem_type, len)); /* The length needs to be positive (cast needed for braindead systems with signed size_t). */ if((unsigned long) len > X_INT_MAX) return NC_EINVAL; /* Find metadata. */ if (!(nc = nc4_find_nc_file(ncid,NULL))) return NC_EBADID; /* get netcdf-4 metadata */ h5 = NC4_DATA(nc); assert(h5); #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (h5->pnetcdf_file) { if (mem_type == NC_UBYTE) mem_type = NC_BYTE; switch(mem_type) { case NC_BYTE: return ncmpi_put_att_schar(nc->int_ncid, varid, name, file_type, len, op); case NC_CHAR: return ncmpi_put_att_text(nc->int_ncid, varid, name, len, op); case NC_SHORT: return ncmpi_put_att_short(nc->int_ncid, varid, name, file_type, len, op); case NC_INT: if (mem_type_is_long) return ncmpi_put_att_long(nc->int_ncid, varid, name, file_type, len, op); else return ncmpi_put_att_int(nc->int_ncid, varid, name, file_type, len, op); case NC_FLOAT: return ncmpi_put_att_float(nc->int_ncid, varid, name, file_type, len, op); case NC_DOUBLE: return ncmpi_put_att_double(nc->int_ncid, varid, name, file_type, len, op); case NC_NAT: default: return NC_EBADTYPE; } } #endif /* USE_PNETCDF */ /* Otherwise, handle things the netcdf-4 way. */ return nc4_put_att(ncid, nc, varid, name, file_type, mem_type, len, mem_type_is_long, op); }