2011-08-17 05:04:33 +08:00
|
|
|
/** \file \internal
|
|
|
|
Internal netcdf-4 functions.
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
This file contains functions internal to the netcdf4 library. None of
|
|
|
|
the functions in this file are exposed in the exetnal API. These
|
|
|
|
functions all relate to the manipulation of netcdf-4's in-memory
|
2012-09-07 03:44:03 +08:00
|
|
|
buffer of metadata information, i.e. the linked list of NC
|
2010-06-03 21:24:43 +08:00
|
|
|
structs.
|
|
|
|
|
2011-08-17 05:04:33 +08:00
|
|
|
Copyright 2003-2011, University Corporation for Atmospheric
|
2010-06-03 21:24:43 +08:00
|
|
|
Research. See the COPYRIGHT file for copying and redistribution
|
|
|
|
conditions.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include "nc4internal.h"
|
|
|
|
#include "nc.h" /* from libsrc */
|
2010-11-10 06:53:03 +08:00
|
|
|
#include "ncdispatch.h" /* from libdispatch */
|
2013-12-01 13:20:28 +08:00
|
|
|
#include "H5DSpublic.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
#include <utf8proc.h>
|
|
|
|
|
2013-03-16 04:31:07 +08:00
|
|
|
#if 0 /*def USE_PNETCDF*/
|
2013-01-15 11:46:46 +08:00
|
|
|
#include <pnetcdf.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#define MEGABYTE 1048576
|
|
|
|
|
|
|
|
/* These are the default chunk cache sizes for HDF5 files created or
|
|
|
|
* opened with netCDF-4. */
|
|
|
|
extern size_t nc4_chunk_cache_size;
|
|
|
|
extern size_t nc4_chunk_cache_nelems;
|
|
|
|
extern float nc4_chunk_cache_preemption;
|
|
|
|
|
|
|
|
/* This is to track opened HDF5 objects to make sure they are
|
|
|
|
* closed. */
|
|
|
|
#ifdef EXTRA_TESTS
|
|
|
|
extern int num_spaces;
|
|
|
|
#endif /* EXTRA_TESTS */
|
|
|
|
|
|
|
|
#ifdef LOGGING
|
|
|
|
/* This is the severity level of messages which will be logged. Use
|
|
|
|
severity 0 for errors, 1 for important log messages, 2 for less
|
|
|
|
important, etc. */
|
|
|
|
int nc_log_level = -1;
|
|
|
|
|
|
|
|
#endif /* LOGGING */
|
|
|
|
|
|
|
|
/* Check and normalize and name. */
|
|
|
|
int
|
|
|
|
nc4_check_name(const char *name, char *norm_name)
|
|
|
|
{
|
|
|
|
char *temp;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Check the length. */
|
|
|
|
if (strlen(name) > NC_MAX_NAME)
|
|
|
|
return NC_EMAXNAME;
|
|
|
|
|
|
|
|
/* Make sure this is a valid netcdf name. This should be done
|
|
|
|
* before the name is normalized, because it gives better error
|
|
|
|
* codes for bad utf8 strings. */
|
|
|
|
if ((retval = NC_check_name(name)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* Normalize the name. */
|
|
|
|
if (!(temp = (char *)utf8proc_NFC((const unsigned char *)name)))
|
|
|
|
return NC_EINVAL;
|
|
|
|
strcpy(norm_name, temp);
|
|
|
|
free(temp);
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2013-06-26 01:04:10 +08:00
|
|
|
/* Given a varid, return the maximum length of a dimension using dimid */
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
static int
|
2013-06-26 01:04:10 +08:00
|
|
|
find_var_dim_max_length(NC_GRP_INFO_T *grp, int varid, int dimid, size_t *maxlen)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
hid_t datasetid = 0, spaceid = 0;
|
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
hsize_t *h5dimlen = NULL, *h5dimlenmax = NULL;
|
|
|
|
int d, dataset_ndims = 0;
|
|
|
|
int retval = NC_NOERR;
|
|
|
|
|
2013-06-26 01:04:10 +08:00
|
|
|
*maxlen = 0;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Find this var. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (var = grp->var; var; var = var->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if (var->varid == varid)
|
|
|
|
break;
|
|
|
|
if (!var)
|
|
|
|
return NC_ENOTVAR;
|
|
|
|
|
2013-06-26 01:04:10 +08:00
|
|
|
/* If the var hasn't been created yet, its size is 0. */
|
|
|
|
if (!var->created)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2013-06-26 01:04:10 +08:00
|
|
|
*maxlen = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the number of records in the dataset. */
|
|
|
|
if ((retval = nc4_open_var_grp2(grp, var->varid, &datasetid)))
|
|
|
|
BAIL(retval);
|
|
|
|
if ((spaceid = H5Dget_space(datasetid)) < 0)
|
|
|
|
BAIL(NC_EHDFERR);
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef EXTRA_TESTS
|
2013-06-26 01:04:10 +08:00
|
|
|
num_spaces++;
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
2013-06-26 01:04:10 +08:00
|
|
|
/* If it's a scalar dataset, it has length one. */
|
|
|
|
if (H5Sget_simple_extent_type(spaceid) == H5S_SCALAR)
|
|
|
|
{
|
|
|
|
*maxlen = (var->dimids && var->dimids[0] == dimid) ? 1 : 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check to make sure ndims is right, then get the len of each
|
|
|
|
dim in the space. */
|
|
|
|
if ((dataset_ndims = H5Sget_simple_extent_ndims(spaceid)) < 0)
|
|
|
|
BAIL(NC_EHDFERR);
|
|
|
|
if (dataset_ndims != var->ndims)
|
|
|
|
BAIL(NC_EHDFERR);
|
|
|
|
if (!(h5dimlen = malloc(dataset_ndims * sizeof(hsize_t))))
|
|
|
|
BAIL(NC_ENOMEM);
|
|
|
|
if (!(h5dimlenmax = malloc(dataset_ndims * sizeof(hsize_t))))
|
|
|
|
BAIL(NC_ENOMEM);
|
2014-12-29 13:04:48 +08:00
|
|
|
if ((dataset_ndims = H5Sget_simple_extent_dims(spaceid,
|
2013-06-26 01:04:10 +08:00
|
|
|
h5dimlen, h5dimlenmax)) < 0)
|
|
|
|
BAIL(NC_EHDFERR);
|
2014-12-29 13:04:48 +08:00
|
|
|
LOG((5, "find_var_dim_max_length: varid %d len %d max: %d",
|
2013-06-26 01:04:10 +08:00
|
|
|
varid, (int)h5dimlen[0], (int)h5dimlenmax[0]));
|
|
|
|
for (d=0; d<dataset_ndims; d++) {
|
|
|
|
if (var->dimids[d] == dimid) {
|
|
|
|
*maxlen = *maxlen > h5dimlen[d] ? *maxlen : h5dimlen[d];
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2013-06-26 01:04:10 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
if (spaceid > 0 && H5Sclose(spaceid) < 0)
|
|
|
|
BAIL2(NC_EHDFERR);
|
|
|
|
#ifdef EXTRA_TESTS
|
|
|
|
num_spaces--;
|
|
|
|
#endif
|
|
|
|
if (h5dimlen) free(h5dimlen);
|
|
|
|
if (h5dimlenmax) free(h5dimlenmax);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
/* Given an NC pointer, add the necessary stuff for a
|
2010-06-03 21:24:43 +08:00
|
|
|
* netcdf-4 file. */
|
|
|
|
int
|
2012-09-07 03:44:03 +08:00
|
|
|
nc4_nc4f_list_add(NC *nc, const char *path, int mode)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
NC_HDF5_FILE_INFO_T *h5;
|
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
assert(nc && !NC4_DATA(nc) && path);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
/* We need to malloc and
|
2010-06-03 21:24:43 +08:00
|
|
|
initialize the substructure NC_HDF_FILE_INFO_T. */
|
2012-09-07 03:44:03 +08:00
|
|
|
if (!(h5 = calloc(1, sizeof(NC_HDF5_FILE_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
2012-09-07 03:44:03 +08:00
|
|
|
NC4_DATA_SET(nc,h5);
|
|
|
|
h5->controller = nc;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Hang on to cmode, and note that we're in define mode. */
|
|
|
|
h5->cmode = mode | NC_INDEF;
|
|
|
|
|
|
|
|
/* The next_typeid needs to be set beyond the end of our atomic
|
|
|
|
* types. */
|
|
|
|
h5->next_typeid = NC_FIRSTUSERTYPEID;
|
|
|
|
|
|
|
|
/* There's always at least one open group - the root
|
|
|
|
* group. Allocate space for one group's worth of information. Set
|
|
|
|
* its hdf id, name, and a pointer to it's file structure. */
|
2014-12-29 13:04:48 +08:00
|
|
|
return nc4_grp_list_add(&(h5->root_grp), h5->next_nc_grpid++,
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NULL, nc, NC_GROUP_NAME, NULL);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Given an ncid, find the relevant group and return a pointer to it,
|
|
|
|
* return an error of this is not a netcdf-4 file (or if strict nc3 is
|
|
|
|
* turned on for this file.) */
|
|
|
|
int
|
|
|
|
nc4_find_nc4_grp(int ncid, NC_GRP_INFO_T **grp)
|
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC_HDF5_FILE_INFO_T* h5;
|
|
|
|
NC *f = nc4_find_nc_file(ncid,&h5);
|
2010-06-03 21:24:43 +08:00
|
|
|
if(f == NULL) return NC_EBADID;
|
|
|
|
|
|
|
|
/* No netcdf-3 files allowed! */
|
2012-09-07 03:44:03 +08:00
|
|
|
if (!h5) return NC_ENOTNC4;
|
|
|
|
assert(h5->root_grp);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* This function demands netcdf-4 files without strict nc3
|
|
|
|
* rules.*/
|
2012-09-07 03:44:03 +08:00
|
|
|
if (h5->cmode & NC_CLASSIC_MODEL) return NC_ESTRICTNC3;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* If we can't find it, the grp id part of ncid is bad. */
|
2012-09-07 03:44:03 +08:00
|
|
|
if (!(*grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK))))
|
2010-09-24 23:55:54 +08:00
|
|
|
return NC_EBADID;
|
2010-06-03 21:24:43 +08:00
|
|
|
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
|
2012-09-07 03:44:03 +08:00
|
|
|
nc4_find_grp_h5(int ncid, NC_GRP_INFO_T **grpp, NC_HDF5_FILE_INFO_T **h5p)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC_HDF5_FILE_INFO_T *h5;
|
|
|
|
NC_GRP_INFO_T *grp;
|
|
|
|
NC *f = nc4_find_nc_file(ncid,&h5);
|
2010-06-03 21:24:43 +08:00
|
|
|
if(f == NULL) return NC_EBADID;
|
2012-09-07 03:44:03 +08:00
|
|
|
if (h5) {
|
|
|
|
assert(h5->root_grp);
|
2010-06-03 21:24:43 +08:00
|
|
|
/* If we can't find it, the grp id part of ncid is bad. */
|
2012-09-07 03:44:03 +08:00
|
|
|
if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK))))
|
2010-09-24 23:55:54 +08:00
|
|
|
return NC_EBADID;
|
2012-09-07 03:44:03 +08:00
|
|
|
h5 = (grp)->nc4_info;
|
|
|
|
assert(h5);
|
2010-06-03 21:24:43 +08:00
|
|
|
} else {
|
2012-09-07 03:44:03 +08:00
|
|
|
h5 = NULL;
|
|
|
|
grp = NULL;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2012-09-07 03:44:03 +08:00
|
|
|
if(h5p) *h5p = h5;
|
|
|
|
if(grpp) *grpp = grp;
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-09-07 03:44:03 +08:00
|
|
|
nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grpp,
|
|
|
|
NC_HDF5_FILE_INFO_T **h5p)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC_GRP_INFO_T *grp;
|
|
|
|
NC_HDF5_FILE_INFO_T* h5;
|
|
|
|
NC *f = nc4_find_nc_file(ncid,&h5);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
if(f == NULL) return NC_EBADID;
|
|
|
|
*nc = f;
|
2013-01-15 11:46:46 +08:00
|
|
|
|
2013-01-18 10:25:12 +08:00
|
|
|
#if 0 /* I do not understand this code at all */
|
2013-03-16 04:31:07 +08:00
|
|
|
#if 0 /*def USE_PNETCDF*/
|
2013-01-18 10:25:12 +08:00
|
|
|
if (h5->pnetcdf_file) {
|
|
|
|
*h5p = NULL;
|
|
|
|
*grpp = NULL;
|
2013-01-15 11:46:46 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
2013-01-18 10:25:12 +08:00
|
|
|
#endif
|
2013-01-15 11:46:46 +08:00
|
|
|
#endif
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
if (h5) {
|
|
|
|
assert(h5->root_grp);
|
2010-06-03 21:24:43 +08:00
|
|
|
/* If we can't find it, the grp id part of ncid is bad. */
|
2012-09-07 03:44:03 +08:00
|
|
|
if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK))))
|
2010-09-24 23:55:54 +08:00
|
|
|
return NC_EBADID;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
h5 = (grp)->nc4_info;
|
|
|
|
assert(h5);
|
2010-06-03 21:24:43 +08:00
|
|
|
} else {
|
2012-09-07 03:44:03 +08:00
|
|
|
h5 = NULL;
|
|
|
|
grp = NULL;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2012-09-07 03:44:03 +08:00
|
|
|
if(h5p) *h5p = h5;
|
|
|
|
if(grpp) *grpp = grp;
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recursively hunt for a group id. */
|
|
|
|
NC_GRP_INFO_T *
|
|
|
|
nc4_rec_find_grp(NC_GRP_INFO_T *start_grp, int target_nc_grpid)
|
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g, *res;
|
|
|
|
|
|
|
|
assert(start_grp);
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Is this the group we are searching for? */
|
|
|
|
if (start_grp->nc_grpid == target_nc_grpid)
|
|
|
|
return start_grp;
|
|
|
|
|
|
|
|
/* Shake down the kids. */
|
|
|
|
if (start_grp->children)
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = start_grp->children; g; g = g->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((res = nc4_rec_find_grp(g, target_nc_grpid)))
|
|
|
|
return res;
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Can't find it. Fate, why do you mock me? */
|
2010-06-03 21:24:43 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given an ncid and varid, get pointers to the group and var
|
|
|
|
* metadata. */
|
|
|
|
int
|
2014-12-29 13:04:48 +08:00
|
|
|
nc4_find_g_var_nc(NC *nc, int ncid, int varid,
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var)
|
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC_HDF5_FILE_INFO_T* h5 = NC4_DATA(nc);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Find the group info. */
|
2012-09-07 03:44:03 +08:00
|
|
|
assert(grp && var && h5 && h5->root_grp);
|
|
|
|
*grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK));
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2013-04-17 07:02:54 +08:00
|
|
|
/* It is possible for *grp to be NULL. If it is,
|
|
|
|
return an error. */
|
2014-12-29 13:04:48 +08:00
|
|
|
if(*grp == NULL)
|
2013-04-17 07:02:54 +08:00
|
|
|
return NC_ENOTVAR;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Find the var info. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for ((*var) = (*grp)->var; (*var); (*var) = (*var)->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((*var)->varid == varid)
|
|
|
|
break;
|
|
|
|
if (!(*var))
|
|
|
|
return NC_ENOTVAR;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a dim in a grp (or parents). */
|
|
|
|
int
|
|
|
|
nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim,
|
|
|
|
NC_GRP_INFO_T **dim_grp)
|
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g, *dg = NULL;
|
2014-12-29 13:04:48 +08:00
|
|
|
int finished = 0;
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
assert(grp && dim);
|
|
|
|
|
|
|
|
/* Find the dim info. */
|
|
|
|
for (g = grp; g && !finished; g = g->parent)
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for ((*dim) = g->dim; (*dim); (*dim) = (*dim)->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((*dim)->dimid == dimid)
|
|
|
|
{
|
|
|
|
dg = g;
|
|
|
|
finished++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we didn't find it, return an error. */
|
|
|
|
if (!(*dim))
|
|
|
|
return NC_EBADDIM;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Give the caller the group the dimension is in. */
|
|
|
|
if (dim_grp)
|
|
|
|
*dim_grp = dg;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
/* Find a var (by name) in a grp. */
|
|
|
|
int
|
|
|
|
nc4_find_var(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var)
|
|
|
|
{
|
|
|
|
assert(grp && var && name);
|
|
|
|
|
|
|
|
/* Find the var info. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for ((*var) = grp->var; (*var); (*var) = (*var)->l.next)
|
2013-12-01 13:20:28 +08:00
|
|
|
if (0 == strcmp(name, (*var)->name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Recursively hunt for a HDF type id. */
|
|
|
|
NC_TYPE_INFO_T *
|
|
|
|
nc4_rec_find_hdf_type(NC_GRP_INFO_T *start_grp, hid_t target_hdf_typeid)
|
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g;
|
|
|
|
NC_TYPE_INFO_T *type, *res;
|
|
|
|
htri_t equal;
|
|
|
|
|
|
|
|
assert(start_grp);
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Does this group have the type we are searching for? */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (type = start_grp->type; type; type = type->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
if ((equal = H5Tequal(type->native_hdf_typeid ? type->native_hdf_typeid : type->hdf_typeid, target_hdf_typeid)) < 0)
|
2010-06-03 21:24:43 +08:00
|
|
|
return NULL;
|
|
|
|
if (equal)
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shake down the kids. */
|
|
|
|
if (start_grp->children)
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = start_grp->children; g; g = g->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((res = nc4_rec_find_hdf_type(g, target_hdf_typeid)))
|
|
|
|
return res;
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Can't find it. Fate, why do you mock me? */
|
2010-06-03 21:24:43 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Recursively hunt for a netCDF type by name. */
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_TYPE_INFO_T *
|
2014-02-12 07:12:08 +08:00
|
|
|
nc4_rec_find_named_type(NC_GRP_INFO_T *start_grp, char *name)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g;
|
|
|
|
NC_TYPE_INFO_T *type, *res;
|
|
|
|
|
|
|
|
assert(start_grp);
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Does this group have the type we are searching for? */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (type = start_grp->type; type; type = type->l.next)
|
2014-02-12 07:12:08 +08:00
|
|
|
if (!strcmp(type->name, name))
|
2010-06-03 21:24:43 +08:00
|
|
|
return type;
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Search subgroups. */
|
2010-06-03 21:24:43 +08:00
|
|
|
if (start_grp->children)
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = start_grp->children; g; g = g->l.next)
|
2014-02-12 07:12:08 +08:00
|
|
|
if ((res = nc4_rec_find_named_type(g, name)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return res;
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Can't find it. Oh, woe is me! */
|
2010-06-03 21:24:43 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Recursively hunt for a netCDF type id. */
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_TYPE_INFO_T *
|
2014-02-12 07:12:08 +08:00
|
|
|
nc4_rec_find_nc_type(const NC_GRP_INFO_T *start_grp, nc_type target_nc_typeid)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
NC_TYPE_INFO_T *type;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
assert(start_grp);
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Does this group have the type we are searching for? */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (type = start_grp->type; type; type = type->l.next)
|
2014-02-12 07:12:08 +08:00
|
|
|
if (type->nc_typeid == target_nc_typeid)
|
2010-06-03 21:24:43 +08:00
|
|
|
return type;
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Shake down the kids. */
|
2010-06-03 21:24:43 +08:00
|
|
|
if (start_grp->children)
|
2014-02-12 07:12:08 +08:00
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g;
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = start_grp->children; g; g = g->l.next)
|
2014-02-12 07:12:08 +08:00
|
|
|
{
|
|
|
|
NC_TYPE_INFO_T *res;
|
|
|
|
|
|
|
|
if ((res = nc4_rec_find_nc_type(g, target_nc_typeid)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return res;
|
2014-02-12 07:12:08 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Can't find it. Fate, why do you mock me? */
|
2010-06-03 21:24:43 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use a netCDF typeid to find a type in a type_list. */
|
|
|
|
int
|
2014-02-12 07:12:08 +08:00
|
|
|
nc4_find_type(const NC_HDF5_FILE_INFO_T *h5, nc_type typeid, NC_TYPE_INFO_T **type)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
if (typeid < 0 || !type)
|
|
|
|
return NC_EINVAL;
|
|
|
|
*type = NULL;
|
|
|
|
|
|
|
|
/* Atomic types don't have associated NC_TYPE_INFO_T struct, just
|
|
|
|
* return NOERR. */
|
|
|
|
if (typeid <= NC_STRING)
|
|
|
|
return NC_NOERR;
|
|
|
|
|
|
|
|
/* Find the type. */
|
|
|
|
if(!(*type = nc4_rec_find_nc_type(h5->root_grp, typeid)))
|
|
|
|
return NC_EBADTYPID;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the actual length of a dim by checking the length of that dim
|
2015-02-06 07:33:42 +08:00
|
|
|
* in all variables that use it, in grp or children. **len must be
|
2010-06-03 21:24:43 +08:00
|
|
|
* initialized to zero before this function is called. */
|
|
|
|
int
|
|
|
|
nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len)
|
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g;
|
|
|
|
NC_VAR_INFO_T *var;
|
2014-12-29 13:04:48 +08:00
|
|
|
int retval;
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
assert(grp && len);
|
|
|
|
LOG((3, "nc4_find_dim_len: grp->name %s dimid %d", grp->name, dimid));
|
|
|
|
|
|
|
|
/* If there are any groups, call this function recursively on
|
|
|
|
* them. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = grp->children; g; g = g->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((retval = nc4_find_dim_len(g, dimid, len)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* For all variables in this group, find the ones that use this
|
|
|
|
* dimension, and remember the max length. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (var = grp->var; var; var = var->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
size_t mylen;
|
|
|
|
|
2013-06-26 01:04:10 +08:00
|
|
|
/* Find max length of dim in this variable... */
|
|
|
|
if ((retval = find_var_dim_max_length(grp, var->varid, dimid, &mylen)))
|
2013-01-29 02:31:02 +08:00
|
|
|
return retval;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2013-06-26 01:04:10 +08:00
|
|
|
**len = **len > mylen ? **len : mylen;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a group, find an att. */
|
|
|
|
int
|
|
|
|
nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum,
|
|
|
|
NC_ATT_INFO_T **att)
|
|
|
|
{
|
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
NC_ATT_INFO_T *attlist = NULL;
|
|
|
|
|
|
|
|
assert(grp && grp->name);
|
2014-12-29 13:04:48 +08:00
|
|
|
LOG((4, "nc4_find_grp_att: grp->name %s varid %d name %s attnum %d",
|
2010-06-03 21:24:43 +08:00
|
|
|
grp->name, varid, name, attnum));
|
|
|
|
|
|
|
|
/* Get either the global or a variable attribute list. */
|
|
|
|
if (varid == NC_GLOBAL)
|
|
|
|
attlist = grp->att;
|
|
|
|
else
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for(var = grp->var; var; var = var->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
if (var->varid == varid)
|
|
|
|
{
|
|
|
|
attlist = var->att;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!var)
|
|
|
|
return NC_ENOTVAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now find the attribute by name or number. If a name is provided,
|
|
|
|
* ignore the attnum. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (*att = attlist; *att; *att = (*att)->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((name && !strcmp((*att)->name, name)) ||
|
|
|
|
(!name && (*att)->attnum == attnum))
|
|
|
|
return NC_NOERR;
|
|
|
|
|
|
|
|
/* If we get here, we couldn't find the attribute. */
|
|
|
|
return NC_ENOTATT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given an ncid, varid, and name or attnum, find and return pointer
|
|
|
|
to NC_ATT_INFO_T metadata. */
|
|
|
|
int
|
|
|
|
nc4_find_nc_att(int ncid, int varid, const char *name, int attnum,
|
|
|
|
NC_ATT_INFO_T **att)
|
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *grp;
|
|
|
|
NC_HDF5_FILE_INFO_T *h5;
|
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
NC_ATT_INFO_T *attlist = NULL;
|
|
|
|
int retval;
|
|
|
|
|
2014-12-29 13:04:48 +08:00
|
|
|
LOG((4, "nc4_find_nc_att: ncid 0x%x varid %d name %s attnum %d",
|
2010-06-03 21:24:43 +08:00
|
|
|
ncid, varid, name, attnum));
|
|
|
|
|
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
|
|
|
if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
assert(grp && h5);
|
|
|
|
|
|
|
|
/* Get either the global or a variable attribute list. */
|
|
|
|
if (varid == NC_GLOBAL)
|
|
|
|
attlist = grp->att;
|
|
|
|
else
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for(var = grp->var; var; var = var->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
if (var->varid == varid)
|
|
|
|
{
|
|
|
|
attlist = var->att;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!var)
|
|
|
|
return NC_ENOTVAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now find the attribute by name or number. If a name is provided, ignore the attnum. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (*att = attlist; *att; *att = (*att)->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((name && !strcmp((*att)->name, name)) ||
|
|
|
|
(!name && (*att)->attnum == attnum))
|
|
|
|
return NC_NOERR;
|
|
|
|
|
|
|
|
/* If we get here, we couldn't find the attribute. */
|
|
|
|
return NC_ENOTATT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Given an id, walk the list and find the appropriate
|
2012-09-07 03:44:03 +08:00
|
|
|
NC. */
|
|
|
|
NC*
|
|
|
|
nc4_find_nc_file(int ext_ncid, NC_HDF5_FILE_INFO_T** h5p)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC* nc;
|
|
|
|
int stat;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
stat = NC_check_id(ext_ncid,&nc);
|
|
|
|
if(stat != NC_NOERR)
|
|
|
|
nc = NULL;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2013-08-06 04:36:33 +08:00
|
|
|
if(nc)
|
|
|
|
if(h5p) *h5p = (NC_HDF5_FILE_INFO_T*)nc->dispatchdata;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
return nc;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add object to the end of a list. */
|
|
|
|
static void
|
|
|
|
obj_list_add(NC_LIST_NODE_T **list, NC_LIST_NODE_T *obj)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Go to the end of the list and set the last one to point at object,
|
|
|
|
* or, if the list is empty, our new object becomes the list. */
|
2010-06-03 21:24:43 +08:00
|
|
|
if(*list)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_LIST_NODE_T *o;
|
|
|
|
|
|
|
|
for (o = *list; o; o = o->next)
|
|
|
|
if (!o->next)
|
2010-06-03 21:24:43 +08:00
|
|
|
break;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
o->next = obj;
|
|
|
|
obj->prev = o;
|
2014-12-29 13:04:48 +08:00
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
else
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
*list = obj;
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Remove object from a list. */
|
|
|
|
static void
|
|
|
|
obj_list_del(NC_LIST_NODE_T **list, NC_LIST_NODE_T *obj)
|
|
|
|
{
|
|
|
|
/* Remove the var from the linked list. */
|
|
|
|
if(*list == obj)
|
|
|
|
*list = obj->next;
|
|
|
|
else
|
|
|
|
((NC_LIST_NODE_T *)obj->prev)->next = obj->next;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if(obj->next)
|
|
|
|
((NC_LIST_NODE_T *)obj->next)->prev = obj->prev;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add to the end of a var list. Return a pointer to the newly
|
|
|
|
* added var. */
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
nc4_var_list_add(NC_VAR_INFO_T **list, NC_VAR_INFO_T **var)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_VAR_INFO_T *new_var;
|
|
|
|
|
|
|
|
/* Allocate storage for new variable. */
|
|
|
|
if (!(new_var = calloc(1, sizeof(NC_VAR_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
|
|
|
|
/* These are the HDF5-1.8.4 defaults. */
|
|
|
|
new_var->chunk_cache_size = nc4_chunk_cache_size;
|
|
|
|
new_var->chunk_cache_nelems = nc4_chunk_cache_nelems;
|
|
|
|
new_var->chunk_cache_preemption = nc4_chunk_cache_preemption;
|
|
|
|
|
|
|
|
/* Add object to list */
|
|
|
|
obj_list_add((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)new_var);
|
|
|
|
|
|
|
|
/* Set the var pointer, if one was given */
|
|
|
|
if (var)
|
|
|
|
*var = new_var;
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the beginning of a dim list. */
|
|
|
|
int
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
nc4_dim_list_add(NC_DIM_INFO_T **list, NC_DIM_INFO_T **dim)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_DIM_INFO_T *new_dim;
|
|
|
|
|
|
|
|
if (!(new_dim = calloc(1, sizeof(NC_DIM_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add object to list */
|
|
|
|
obj_list_add((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)new_dim);
|
|
|
|
|
|
|
|
/* Set the dim pointer, if one was given */
|
|
|
|
if (dim)
|
|
|
|
*dim = new_dim;
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the end of an att list. */
|
|
|
|
int
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
nc4_att_list_add(NC_ATT_INFO_T **list, NC_ATT_INFO_T **att)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_ATT_INFO_T *new_att;
|
|
|
|
|
|
|
|
if (!(new_att = calloc(1, sizeof(NC_ATT_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
|
|
|
|
/* Add object to list */
|
|
|
|
obj_list_add((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)new_att);
|
|
|
|
|
|
|
|
/* Set the attribute pointer, if one was given */
|
|
|
|
if (att)
|
|
|
|
*att = new_att;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the end of a group list. Can't use 0 as a new_nc_grpid -
|
|
|
|
* it's reserverd for the root group. */
|
|
|
|
int
|
2014-12-29 13:04:48 +08:00
|
|
|
nc4_grp_list_add(NC_GRP_INFO_T **list, int new_nc_grpid,
|
|
|
|
NC_GRP_INFO_T *parent_grp, NC *nc,
|
2010-06-03 21:24:43 +08:00
|
|
|
char *name, NC_GRP_INFO_T **grp)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_GRP_INFO_T *new_grp;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((3, "%s: new_nc_grpid %d name %s ", __func__, new_nc_grpid, name));
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Get the memory to store this groups info. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if (!(new_grp = calloc(1, sizeof(NC_GRP_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Fill in this group's information. */
|
|
|
|
new_grp->nc_grpid = new_nc_grpid;
|
|
|
|
new_grp->parent = parent_grp;
|
|
|
|
if (!(new_grp->name = strdup(name)))
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
free(new_grp);
|
|
|
|
return NC_ENOMEM;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
new_grp->nc4_info = NC4_DATA(nc);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add object to list */
|
|
|
|
obj_list_add((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)new_grp);
|
|
|
|
|
|
|
|
/* Set the group pointer, if one was given */
|
|
|
|
if (grp)
|
|
|
|
*grp = new_grp;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Names for groups, variables, and types must not be the same. This
|
|
|
|
* function checks that a proposed name is not already in
|
|
|
|
* use. Normalzation of UTF8 strings should happen before this
|
|
|
|
* function is called. */
|
|
|
|
int
|
|
|
|
nc4_check_dup_name(NC_GRP_INFO_T *grp, char *name)
|
|
|
|
{
|
|
|
|
NC_TYPE_INFO_T *type;
|
|
|
|
NC_GRP_INFO_T *g;
|
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
|
|
|
|
/* Any types of this name? */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (type = grp->type; type; type = type->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if (!strcmp(type->name, name))
|
|
|
|
return NC_ENAMEINUSE;
|
|
|
|
|
|
|
|
/* Any child groups of this name? */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = grp->children; g; g = g->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if (!strcmp(g->name, name))
|
|
|
|
return NC_ENAMEINUSE;
|
|
|
|
|
|
|
|
/* Any variables of this name? */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (var = grp->var; var; var = var->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
if (!strcmp(var->name, name))
|
|
|
|
return NC_ENAMEINUSE;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the end of a type list. */
|
|
|
|
int
|
2014-02-12 07:12:08 +08:00
|
|
|
nc4_type_list_add(NC_GRP_INFO_T *grp, size_t size, const char *name,
|
|
|
|
NC_TYPE_INFO_T **type)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_TYPE_INFO_T *new_type;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Allocate memory for the type */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if (!(new_type = calloc(1, sizeof(NC_TYPE_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add object to list */
|
2014-02-12 07:12:08 +08:00
|
|
|
obj_list_add((NC_LIST_NODE_T **)(&grp->type), (NC_LIST_NODE_T *)new_type);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Remember info about this type. */
|
|
|
|
new_type->nc_typeid = grp->nc4_info->next_typeid++;
|
|
|
|
new_type->size = size;
|
|
|
|
if (!(new_type->name = strdup(name)))
|
|
|
|
return NC_ENOMEM;
|
|
|
|
|
|
|
|
/* Increment the ref. count on the type */
|
|
|
|
new_type->rc++;
|
|
|
|
|
|
|
|
/* Return a pointer to the new type, if requested */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if (type)
|
|
|
|
*type = new_type;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the end of a compound field list. */
|
|
|
|
int
|
|
|
|
nc4_field_list_add(NC_FIELD_INFO_T **list, int fieldid, const char *name,
|
2014-12-29 13:04:48 +08:00
|
|
|
size_t offset, hid_t field_hdf_typeid, hid_t native_typeid,
|
2010-06-03 21:24:43 +08:00
|
|
|
nc_type xtype, int ndims, const int *dim_sizesp)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_FIELD_INFO_T *field;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Name has already been checked and UTF8 normalized. */
|
|
|
|
if (!name)
|
|
|
|
return NC_EINVAL;
|
|
|
|
|
|
|
|
/* Allocate storage for this field information. */
|
|
|
|
if (!(field = calloc(1, sizeof(NC_FIELD_INFO_T))))
|
|
|
|
return NC_ENOMEM;
|
|
|
|
|
|
|
|
/* Store the information about this field. */
|
|
|
|
field->fieldid = fieldid;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if (!(field->name = strdup(name)))
|
|
|
|
{
|
|
|
|
free(field);
|
2010-07-01 23:51:19 +08:00
|
|
|
return NC_ENOMEM;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
field->hdf_typeid = field_hdf_typeid;
|
2014-02-12 07:12:08 +08:00
|
|
|
field->native_hdf_typeid = native_typeid;
|
|
|
|
field->nc_typeid = xtype;
|
2010-06-03 21:24:43 +08:00
|
|
|
field->offset = offset;
|
|
|
|
field->ndims = ndims;
|
2010-07-02 00:02:10 +08:00
|
|
|
if (ndims)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
int i;
|
|
|
|
|
2010-07-02 00:02:10 +08:00
|
|
|
if (!(field->dim_size = malloc(ndims * sizeof(int))))
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
{
|
|
|
|
free(field->name);
|
|
|
|
free(field);
|
2010-07-02 00:02:10 +08:00
|
|
|
return NC_ENOMEM;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
}
|
2010-07-02 00:02:10 +08:00
|
|
|
for (i = 0; i < ndims; i++)
|
|
|
|
field->dim_size[i] = dim_sizesp[i];
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add object to list */
|
|
|
|
obj_list_add((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)field);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a member to an enum type. */
|
|
|
|
int
|
2014-12-29 13:04:48 +08:00
|
|
|
nc4_enum_member_add(NC_ENUM_MEMBER_INFO_T **list, size_t size,
|
2010-06-03 21:24:43 +08:00
|
|
|
const char *name, const void *value)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
NC_ENUM_MEMBER_INFO_T *member;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Name has already been checked. */
|
|
|
|
assert(name && size > 0 && value);
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
LOG((4, "%s: size %d name %s", __func__, size, name));
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Allocate storage for this field information. */
|
2013-08-18 01:53:29 +08:00
|
|
|
if (!(member = calloc(1, sizeof(NC_ENUM_MEMBER_INFO_T))))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOMEM;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if (!(member->value = malloc(size))) {
|
2013-08-18 01:53:29 +08:00
|
|
|
free(member);
|
|
|
|
return NC_ENOMEM;
|
|
|
|
}
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if (!(member->name = strdup(name))) {
|
2013-08-18 01:53:29 +08:00
|
|
|
free(member->value);
|
|
|
|
free(member);
|
|
|
|
return NC_ENOMEM;
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Store the value for this member. */
|
2010-06-03 21:24:43 +08:00
|
|
|
memcpy(member->value, value, size);
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Add object to list */
|
|
|
|
obj_list_add((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)member);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Delete a field from a field list, and nc_free the memory. */
|
|
|
|
static void
|
|
|
|
field_list_del(NC_FIELD_INFO_T **list, NC_FIELD_INFO_T *field)
|
|
|
|
{
|
|
|
|
/* Take this field out of the list. */
|
|
|
|
obj_list_del((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)field);
|
|
|
|
|
|
|
|
/* Free some stuff. */
|
|
|
|
if (field->name)
|
|
|
|
free(field->name);
|
|
|
|
if (field->dim_size)
|
|
|
|
free(field->dim_size);
|
|
|
|
|
|
|
|
/* Nc_Free the memory. */
|
|
|
|
free(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free allocated space for type information. */
|
|
|
|
int
|
|
|
|
nc4_type_free(NC_TYPE_INFO_T *type)
|
|
|
|
{
|
|
|
|
/* Decrement the ref. count on the type */
|
|
|
|
assert(type->rc);
|
|
|
|
type->rc--;
|
|
|
|
|
|
|
|
/* Release the type, if the ref. count drops to zero */
|
|
|
|
if (0 == type->rc)
|
|
|
|
{
|
|
|
|
/* Close any open user-defined HDF5 typeids. */
|
|
|
|
if (type->hdf_typeid && H5Tclose(type->hdf_typeid) < 0)
|
|
|
|
return NC_EHDFERR;
|
|
|
|
if (type->native_hdf_typeid && H5Tclose(type->native_hdf_typeid) < 0)
|
|
|
|
return NC_EHDFERR;
|
|
|
|
|
|
|
|
/* Free the name. */
|
|
|
|
if (type->name)
|
|
|
|
free(type->name);
|
|
|
|
|
|
|
|
/* Class-specific cleanup */
|
|
|
|
switch (type->nc_type_class)
|
|
|
|
{
|
|
|
|
case NC_COMPOUND:
|
|
|
|
{
|
|
|
|
NC_FIELD_INFO_T *field;
|
|
|
|
|
|
|
|
/* Delete all the fields in this type (there will be some if its a
|
|
|
|
* compound). */
|
|
|
|
field = type->u.c.field;
|
|
|
|
while (field)
|
|
|
|
{
|
|
|
|
NC_FIELD_INFO_T *f = field->l.next;
|
|
|
|
|
|
|
|
field_list_del(&type->u.c.field, field);
|
|
|
|
field = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NC_ENUM:
|
|
|
|
{
|
|
|
|
NC_ENUM_MEMBER_INFO_T *enum_member;
|
|
|
|
|
|
|
|
/* Delete all the enum_members, if any. */
|
|
|
|
enum_member = type->u.e.enum_member;
|
|
|
|
while (enum_member)
|
|
|
|
{
|
|
|
|
NC_ENUM_MEMBER_INFO_T *em = enum_member->l.next;
|
|
|
|
|
|
|
|
free(enum_member->value);
|
|
|
|
free(enum_member->name);
|
|
|
|
free(enum_member);
|
|
|
|
enum_member = em;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (H5Tclose(type->u.e.base_hdf_typeid) < 0)
|
|
|
|
return NC_EHDFERR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NC_VLEN:
|
|
|
|
if (H5Tclose(type->u.v.base_hdf_typeid) < 0)
|
|
|
|
return NC_EHDFERR;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the memory. */
|
|
|
|
free(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Delete a var from a var list, and free the memory. */
|
2013-03-01 16:10:28 +08:00
|
|
|
int
|
|
|
|
nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
NC_ATT_INFO_T *a, *att;
|
|
|
|
int ret;
|
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
if(var == NULL)
|
2013-04-03 06:09:31 +08:00
|
|
|
return NC_NOERR;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
|
|
|
|
/* Remove the var from the linked list. */
|
|
|
|
obj_list_del((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)var);
|
2013-04-03 06:09:31 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* First delete all the attributes attached to this var. */
|
2013-03-01 16:10:28 +08:00
|
|
|
att = var->att;
|
2010-06-03 21:24:43 +08:00
|
|
|
while (att)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
a = att->l.next;
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((ret = nc4_att_list_del(&var->att, att)))
|
|
|
|
return ret;
|
|
|
|
att = a;
|
|
|
|
}
|
|
|
|
|
2010-07-01 05:16:50 +08:00
|
|
|
/* Free some things that may be allocated. */
|
2014-12-29 13:04:48 +08:00
|
|
|
if (var->chunksizes)
|
2013-04-03 06:09:31 +08:00
|
|
|
{free(var->chunksizes);var->chunksizes = NULL;}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-07-01 05:16:50 +08:00
|
|
|
if (var->hdf5_name)
|
2013-04-03 06:09:31 +08:00
|
|
|
{free(var->hdf5_name); var->hdf5_name = NULL;}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-07-01 19:39:34 +08:00
|
|
|
if (var->name)
|
2013-04-03 06:09:31 +08:00
|
|
|
{free(var->name); var->name = NULL;}
|
|
|
|
|
2010-07-01 20:52:44 +08:00
|
|
|
if (var->dimids)
|
2013-04-03 06:09:31 +08:00
|
|
|
{free(var->dimids); var->dimids = NULL;}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-07-01 20:52:44 +08:00
|
|
|
if (var->dim)
|
2013-04-03 06:09:31 +08:00
|
|
|
{free(var->dim); var->dim = NULL;}
|
2010-07-01 05:05:11 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Delete any fill value allocation. This must be done before the
|
|
|
|
* type_info is freed. */
|
|
|
|
if (var->fill_value)
|
|
|
|
{
|
2010-11-30 06:23:16 +08:00
|
|
|
if (var->hdf_datasetid)
|
|
|
|
{
|
2013-03-01 16:10:28 +08:00
|
|
|
if (var->type_info)
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
if (var->type_info->nc_type_class == NC_VLEN)
|
2013-03-01 16:10:28 +08:00
|
|
|
nc_free_vlen((nc_vlen_t *)var->fill_value);
|
2014-02-12 07:12:08 +08:00
|
|
|
else if (var->type_info->nc_type_class == NC_STRING && *(char **)var->fill_value)
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
free(*(char **)var->fill_value);
|
|
|
|
}
|
2010-11-30 06:23:16 +08:00
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
free(var->fill_value);
|
2013-04-03 06:09:31 +08:00
|
|
|
var->fill_value = NULL;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Release type information */
|
|
|
|
if (var->type_info)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
int retval;
|
2010-08-20 01:37:29 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
if ((retval = nc4_type_free(var->type_info)))
|
|
|
|
return retval;
|
2013-04-03 06:09:31 +08:00
|
|
|
var->type_info = NULL;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Delete any HDF5 dimscale objid information. */
|
|
|
|
if (var->dimscale_hdf5_objids)
|
|
|
|
free(var->dimscale_hdf5_objids);
|
|
|
|
|
|
|
|
/* Delete information about the attachment status of dimscales. */
|
|
|
|
if (var->dimscale_attached)
|
|
|
|
free(var->dimscale_attached);
|
|
|
|
|
|
|
|
/* Delete the var. */
|
|
|
|
free(var);
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a type from a type list, and nc_free the memory. */
|
2013-03-25 01:33:17 +08:00
|
|
|
static int
|
2010-06-03 21:24:43 +08:00
|
|
|
type_list_del(NC_TYPE_INFO_T **list, NC_TYPE_INFO_T *type)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Take this type out of the list. */
|
|
|
|
obj_list_del((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)type);
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Free the type, and its components */
|
|
|
|
return nc4_type_free(type);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a del from a var list, and nc_free the memory. */
|
|
|
|
int
|
|
|
|
nc4_dim_list_del(NC_DIM_INFO_T **list, NC_DIM_INFO_T *dim)
|
|
|
|
{
|
|
|
|
/* Take this dimension out of the list. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
obj_list_del((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)dim);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2010-07-01 21:36:41 +08:00
|
|
|
/* Free memory allocated for names. */
|
|
|
|
if (dim->name)
|
|
|
|
free(dim->name);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
free(dim);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a NC_GRP_INFO_T from the linked list. This will nc_free the
|
|
|
|
memory too. */
|
|
|
|
static void
|
|
|
|
grp_list_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
/* Take this group out of the list. */
|
|
|
|
obj_list_del((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)grp);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
free(grp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recursively delete the data for a group (and everything it
|
|
|
|
* contains) in our internal metadata store. */
|
2014-12-29 13:04:48 +08:00
|
|
|
int
|
|
|
|
nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g, *c;
|
|
|
|
NC_VAR_INFO_T *v, *var;
|
|
|
|
NC_ATT_INFO_T *a, *att;
|
|
|
|
NC_DIM_INFO_T *d, *dim;
|
|
|
|
NC_TYPE_INFO_T *type, *t;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
assert(grp);
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((3, "%s: grp->name %s", __func__, grp->name));
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Recursively call this function for each child, if any, stopping
|
|
|
|
* if there is an error. */
|
|
|
|
g = grp->children;
|
|
|
|
while(g)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
c = g->l.next;
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((retval = nc4_rec_grp_del(&(grp->children), g)))
|
|
|
|
return retval;
|
|
|
|
g = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete all the list contents for vars, dims, and atts, in each
|
|
|
|
* group. */
|
|
|
|
att = grp->att;
|
|
|
|
while (att)
|
|
|
|
{
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((4, "%s: deleting att %s", __func__, att->name));
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
a = att->l.next;
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((retval = nc4_att_list_del(&grp->att, att)))
|
|
|
|
return retval;
|
|
|
|
att = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete all vars. */
|
|
|
|
var = grp->var;
|
|
|
|
while (var)
|
|
|
|
{
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((4, "%s: deleting var %s", __func__, var->name));
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Close HDF5 dataset associated with this var, unless it's a
|
|
|
|
* scale. */
|
2013-12-01 13:20:28 +08:00
|
|
|
if (var->hdf_datasetid && H5Dclose(var->hdf_datasetid) < 0)
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_EHDFERR;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
v = var->l.next;
|
2013-03-01 16:10:28 +08:00
|
|
|
if ((retval = nc4_var_list_del(&grp->var, var)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return retval;
|
|
|
|
var = v;
|
|
|
|
}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Delete all dims. */
|
|
|
|
dim = grp->dim;
|
|
|
|
while (dim)
|
|
|
|
{
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((4, "%s: deleting dim %s", __func__, dim->name));
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Close HDF5 dataset associated with this dim. */
|
|
|
|
if (dim->hdf_dimscaleid && H5Dclose(dim->hdf_dimscaleid) < 0)
|
|
|
|
return NC_EHDFERR;
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
d = dim->l.next;
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((retval = nc4_dim_list_del(&grp->dim, dim)))
|
|
|
|
return retval;
|
|
|
|
dim = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete all types. */
|
2014-12-29 13:04:48 +08:00
|
|
|
type = grp->type;
|
2010-06-03 21:24:43 +08:00
|
|
|
while (type)
|
|
|
|
{
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((4, "%s: deleting type %s", __func__, type->name));
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
t = type->l.next;
|
2010-06-03 21:24:43 +08:00
|
|
|
if ((retval = type_list_del(&grp->type, type)))
|
|
|
|
return retval;
|
|
|
|
type = t;
|
|
|
|
}
|
|
|
|
|
2014-12-29 13:04:48 +08:00
|
|
|
/* Tell HDF5 we're closing this group. */
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((4, "%s: closing group %s", __func__, grp->name));
|
2014-12-29 13:04:48 +08:00
|
|
|
if (grp->hdf_grpid && H5Gclose(grp->hdf_grpid) < 0)
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_EHDFERR;
|
|
|
|
|
2010-07-02 00:02:10 +08:00
|
|
|
/* Free the name. */
|
|
|
|
free(grp->name);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Finally, redirect pointers around this entry in the list, and
|
|
|
|
* nc_free its memory. */
|
|
|
|
grp_list_del(list, grp);
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a NC_ATT_INFO_T from the linked list. This will nc_free the
|
|
|
|
memory too.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nc4_att_list_del(NC_ATT_INFO_T **list, NC_ATT_INFO_T *att)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Take this att out of the list. */
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
obj_list_del((NC_LIST_NODE_T **)list, (NC_LIST_NODE_T *)att);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Free memory that was malloced to hold data for this
|
|
|
|
* attribute. */
|
|
|
|
if (att->data)
|
|
|
|
free(att->data);
|
|
|
|
|
2010-07-01 21:08:28 +08:00
|
|
|
/* Free the name. */
|
|
|
|
if (att->name)
|
|
|
|
free(att->name);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Close the HDF5 typeid. */
|
2014-02-12 07:12:08 +08:00
|
|
|
if (att->native_hdf_typeid && H5Tclose(att->native_hdf_typeid) < 0)
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_EHDFERR;
|
|
|
|
|
|
|
|
/* If this is a string array attribute, delete all members of the
|
|
|
|
* string array, then delete the array of pointers to strings. (The
|
|
|
|
* array was filled with pointers by HDF5 when the att was read,
|
|
|
|
* and memory for each string was allocated by HDF5. That's why I
|
|
|
|
* use free and not nc_free, because the netCDF library didn't
|
|
|
|
* allocate the memory that is being freed.) */
|
|
|
|
if (att->stdata)
|
|
|
|
{
|
|
|
|
for (i = 0; i < att->len; i++)
|
2013-07-11 04:09:31 +08:00
|
|
|
if(att->stdata[i])
|
|
|
|
free(att->stdata[i]);
|
2010-06-03 21:24:43 +08:00
|
|
|
free(att->stdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this att has vlen data, release it. */
|
|
|
|
if (att->vldata)
|
|
|
|
{
|
|
|
|
for (i = 0; i < att->len; i++)
|
|
|
|
nc_free_vlen(&att->vldata[i]);
|
|
|
|
free(att->vldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(att);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
/* Break a coordinate variable to separate the dimension and the variable */
|
|
|
|
int
|
|
|
|
nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim)
|
|
|
|
{
|
|
|
|
int retval = NC_NOERR;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
assert(dim->coord_var == coord_var);
|
|
|
|
assert(coord_var->dim[0] == dim);
|
|
|
|
assert(coord_var->dimids[0] == dim->dimid);
|
|
|
|
assert(0 == dim->hdf_dimscaleid);
|
|
|
|
|
|
|
|
/* If we're replacing an existing dimscale dataset, go to
|
|
|
|
* every var in the file and detach this dimension scale. */
|
2014-12-29 13:04:48 +08:00
|
|
|
if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
|
2013-12-01 13:20:28 +08:00
|
|
|
dim->dimid, coord_var->hdf_datasetid)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* Allow attached dimscales to be tracked on the [former] coordinate variable */
|
|
|
|
if (coord_var->ndims)
|
|
|
|
{
|
|
|
|
/* Coordinate variables shouldn't have dimscales attached */
|
|
|
|
assert(NULL == coord_var->dimscale_attached);
|
|
|
|
|
|
|
|
/* Allocate space for tracking them */
|
2014-02-12 07:12:08 +08:00
|
|
|
if (NULL == (coord_var->dimscale_attached = calloc(coord_var->ndims, sizeof(nc_bool_t))))
|
2013-12-01 13:20:28 +08:00
|
|
|
return NC_ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detach dimension from variable */
|
2014-02-12 07:12:08 +08:00
|
|
|
coord_var->dimscale = NC_FALSE;
|
2013-12-01 13:20:28 +08:00
|
|
|
dim->coord_var = NULL;
|
|
|
|
|
2014-11-24 23:36:58 +08:00
|
|
|
/* Set state transition indicators */
|
|
|
|
coord_var->was_coord_var = NC_TRUE;
|
|
|
|
coord_var->became_coord_var = NC_FALSE;
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reform a coordinate variable from a dimension and a variable */
|
|
|
|
int
|
|
|
|
nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
|
|
|
{
|
|
|
|
int retval = NC_NOERR;
|
|
|
|
|
|
|
|
/* Detach dimscales from the [new] coordinate variable */
|
|
|
|
if(var->dimscale_attached)
|
|
|
|
{
|
|
|
|
int dims_detached = 0;
|
|
|
|
int finished = 0;
|
|
|
|
int d;
|
|
|
|
|
|
|
|
/* Loop over all dimensions for variable */
|
|
|
|
for (d = 0; d < var->ndims && !finished; d++)
|
|
|
|
/* Is there a dimscale attached to this axis? */
|
|
|
|
if(var->dimscale_attached[d])
|
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
for (g = grp; g && !finished; g = g->parent)
|
|
|
|
{
|
|
|
|
NC_DIM_INFO_T *dim1;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (dim1 = g->dim; dim1 && !finished; dim1 = dim1->l.next)
|
2013-12-01 13:20:28 +08:00
|
|
|
if (var->dimids[d] == dim1->dimid)
|
|
|
|
{
|
|
|
|
hid_t dim_datasetid; /* Dataset ID for dimension */
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
/* Find dataset ID for dimension */
|
|
|
|
if (dim1->coord_var)
|
|
|
|
dim_datasetid = dim1->coord_var->hdf_datasetid;
|
|
|
|
else
|
|
|
|
dim_datasetid = dim1->hdf_dimscaleid;
|
|
|
|
assert(dim_datasetid > 0);
|
|
|
|
if (H5DSdetach_scale(var->hdf_datasetid, dim_datasetid, d) < 0)
|
|
|
|
BAIL(NC_EHDFERR);
|
2014-02-12 07:12:08 +08:00
|
|
|
var->dimscale_attached[d] = NC_FALSE;
|
2013-12-01 13:20:28 +08:00
|
|
|
if (dims_detached++ == var->ndims)
|
|
|
|
finished++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release & reset the array tracking attached dimscales */
|
|
|
|
free(var->dimscale_attached);
|
|
|
|
var->dimscale_attached = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use variable's dataset ID for the dimscale ID */
|
2014-12-29 13:04:48 +08:00
|
|
|
if (dim->hdf_dimscaleid && grp != NULL)
|
2013-12-01 13:20:28 +08:00
|
|
|
{
|
|
|
|
if (H5Dclose(dim->hdf_dimscaleid) < 0)
|
|
|
|
BAIL(NC_EHDFERR);
|
|
|
|
dim->hdf_dimscaleid = 0;
|
|
|
|
|
2014-12-29 13:04:48 +08:00
|
|
|
/* Now delete the dimscale's dataset
|
|
|
|
(it will be recreated later, if necessary) */
|
2013-12-01 13:20:28 +08:00
|
|
|
if (H5Gunlink(grp->hdf_grpid, dim->name) < 0)
|
2014-12-29 13:04:48 +08:00
|
|
|
return NC_EDIMMETA;
|
2013-12-01 13:20:28 +08:00
|
|
|
}
|
|
|
|
|
2014-11-24 23:36:58 +08:00
|
|
|
/* Attach variable to dimension */
|
|
|
|
var->dimscale = NC_TRUE;
|
|
|
|
dim->coord_var = var;
|
|
|
|
|
|
|
|
/* Check if this variable used to be a coord. var */
|
2015-02-12 04:13:39 +08:00
|
|
|
if (var->was_coord_var && grp != NULL)
|
2014-11-24 23:36:58 +08:00
|
|
|
{
|
|
|
|
/* Reattach the scale everywhere it is used. */
|
|
|
|
/* (Recall that netCDF dimscales are always 1-D) */
|
2014-12-29 13:04:48 +08:00
|
|
|
if ((retval = rec_reattach_scales(grp->nc4_info->root_grp,
|
2014-11-24 23:36:58 +08:00
|
|
|
var->dimids[0], var->hdf_datasetid)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* Set state transition indicator (cancels earlier transition) */
|
|
|
|
var->was_coord_var = NC_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Set state transition indicator */
|
|
|
|
var->became_coord_var = NC_TRUE;
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
exit:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Normalize a UTF8 name. Put the result in norm_name, which can be
|
|
|
|
* NC_MAX_NAME + 1 in size. This function makes sure the free() gets
|
|
|
|
* called on the return from utf8proc_NFC, and also ensures that the
|
|
|
|
* name is not too long. */
|
|
|
|
int
|
|
|
|
nc4_normalize_name(const char *name, char *norm_name)
|
|
|
|
{
|
|
|
|
char *temp_name;
|
|
|
|
if (!(temp_name = (char *)utf8proc_NFC((const unsigned char *)name)))
|
|
|
|
return NC_EINVAL;
|
|
|
|
if (strlen(temp_name) > NC_MAX_NAME)
|
|
|
|
{
|
|
|
|
free(temp_name);
|
|
|
|
return NC_EMAXNAME;
|
|
|
|
}
|
|
|
|
strcpy(norm_name, temp_name);
|
|
|
|
free(temp_name);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out a bunch of info to stderr about the metadata for
|
|
|
|
debugging purposes. */
|
|
|
|
#ifdef LOGGING
|
|
|
|
/* Use this to set the global log level. Set it to NC_TURN_OFF_LOGGING
|
|
|
|
(-1) to turn off all logging. Set it to 0 to show only errors, and
|
|
|
|
to higher numbers to show more and more logging details. */
|
2014-12-29 13:04:48 +08:00
|
|
|
int
|
2010-06-03 21:24:43 +08:00
|
|
|
nc_set_log_level(int new_level)
|
|
|
|
{
|
|
|
|
/* If the user wants to completely turn off logging, turn off HDF5
|
|
|
|
logging too. Now I truely can't think of what to do if this
|
|
|
|
fails, so just ignore the return code. */
|
|
|
|
if (new_level == NC_TURN_OFF_LOGGING)
|
|
|
|
{
|
|
|
|
H5Eset_auto(NULL, NULL);
|
|
|
|
LOG((1, "HDF5 error messages turned off!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do we need to turn HDF5 logging back on? */
|
2014-12-29 13:04:48 +08:00
|
|
|
if (new_level > NC_TURN_OFF_LOGGING &&
|
2010-06-03 21:24:43 +08:00
|
|
|
nc_log_level <= NC_TURN_OFF_LOGGING)
|
|
|
|
{
|
|
|
|
if (H5Eset_auto((H5E_auto_t)&H5Eprint, stderr) < 0)
|
|
|
|
LOG((0, "H5Eset_auto failed!"));
|
|
|
|
LOG((1, "HDF5 error messages turned on."));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now remember the new level. */
|
|
|
|
nc_log_level = new_level;
|
|
|
|
LOG((4, "log_level changed to %d", nc_log_level));
|
|
|
|
return 0;
|
2014-12-29 13:04:48 +08:00
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Recursively print the metadata of a group. */
|
|
|
|
#define MAX_NESTS 10
|
|
|
|
static int
|
2014-02-12 07:12:08 +08:00
|
|
|
rec_print_metadata(NC_GRP_INFO_T *grp, int tab_count)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
NC_GRP_INFO_T *g;
|
|
|
|
NC_ATT_INFO_T *att;
|
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
NC_DIM_INFO_T *dim;
|
|
|
|
NC_TYPE_INFO_T *type;
|
|
|
|
NC_FIELD_INFO_T *field;
|
|
|
|
char tabs[MAX_NESTS] = "";
|
2013-01-29 02:31:02 +08:00
|
|
|
char *dims_string = NULL;
|
2010-06-03 21:24:43 +08:00
|
|
|
char temp_string[10];
|
|
|
|
int t, retval, d;
|
|
|
|
|
|
|
|
/* Come up with a number of tabs relative to the group. */
|
2014-02-12 07:12:08 +08:00
|
|
|
for (t = 0; t < tab_count && t < MAX_NESTS; t++)
|
2010-06-03 21:24:43 +08:00
|
|
|
strcat(tabs, "\t");
|
|
|
|
|
|
|
|
LOG((2, "%s GROUP - %s nc_grpid: %d nvars: %d natts: %d",
|
|
|
|
tabs, grp->name, grp->nc_grpid, grp->nvars, grp->natts));
|
2014-12-29 13:04:48 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for(att = grp->att; att; att = att->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
LOG((2, "%s GROUP ATTRIBUTE - attnum: %d name: %s type: %d len: %d",
|
2014-02-12 07:12:08 +08:00
|
|
|
tabs, att->attnum, att->name, att->nc_typeid, att->len));
|
2010-06-03 21:24:43 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for(dim = grp->dim; dim; dim = dim->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
LOG((2, "%s DIMENSION - dimid: %d name: %s len: %d unlimited: %d",
|
|
|
|
tabs, dim->dimid, dim->name, dim->len, dim->unlimited));
|
2014-12-29 13:04:48 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for(var = grp->var; var; var = var->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2013-07-11 04:09:31 +08:00
|
|
|
if(var->ndims > 0)
|
|
|
|
{
|
|
|
|
dims_string = (char*)malloc(sizeof(char)*(var->ndims*4));
|
|
|
|
strcpy(dims_string, "");
|
|
|
|
for (d = 0; d < var->ndims; d++)
|
|
|
|
{
|
|
|
|
sprintf(temp_string, " %d", var->dimids[d]);
|
|
|
|
strcat(dims_string, temp_string);
|
|
|
|
}
|
|
|
|
}
|
2015-05-15 07:22:07 +08:00
|
|
|
LOG((2, "%s VARIABLE - varid: %d name: %s type: %d ndims: %d dimscale: %d dimids:%s endianness: %d, hdf_typeid: %d",
|
2014-12-29 13:04:48 +08:00
|
|
|
tabs, var->varid, var->name, var->type_info->nc_typeid, var->ndims, (int)var->dimscale,
|
2015-05-15 07:22:07 +08:00
|
|
|
(dims_string ? dims_string : " -"),var->type_info->endianness, var->type_info->native_hdf_typeid));
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for(att = var->att; att; att = att->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
LOG((2, "%s VAR ATTRIBUTE - attnum: %d name: %s type: %d len: %d",
|
2014-02-12 07:12:08 +08:00
|
|
|
tabs, att->attnum, att->name, att->nc_typeid, att->len));
|
2013-07-11 04:09:31 +08:00
|
|
|
if(dims_string)
|
|
|
|
{
|
|
|
|
free(dims_string);
|
|
|
|
dims_string = NULL;
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (type = grp->type; type; type = type->l.next)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
LOG((2, "%s TYPE - nc_typeid: %d hdf_typeid: 0x%x size: %d committed: %d "
|
2014-12-29 13:04:48 +08:00
|
|
|
"name: %s num_fields: %d", tabs, type->nc_typeid,
|
|
|
|
type->hdf_typeid, type->size, (int)type->committed, type->name,
|
2014-02-12 07:12:08 +08:00
|
|
|
type->u.c.num_fields));
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Is this a compound type? */
|
2014-02-12 07:12:08 +08:00
|
|
|
if (type->nc_type_class == NC_COMPOUND)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
LOG((3, "compound type"));
|
2014-02-12 07:12:08 +08:00
|
|
|
for (field = type->u.c.field; field; field = field->l.next)
|
2014-12-29 13:04:48 +08:00
|
|
|
LOG((4, "field %s offset %d nctype %d ndims %d", field->name,
|
2014-02-12 07:12:08 +08:00
|
|
|
field->offset, field->nc_typeid, field->ndims));
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2014-02-12 07:12:08 +08:00
|
|
|
else if (type->nc_type_class == NC_VLEN)
|
|
|
|
{
|
2010-06-03 21:24:43 +08:00
|
|
|
LOG((3, "VLEN type"));
|
2014-02-12 07:12:08 +08:00
|
|
|
LOG((4, "base_nc_type: %d", type->u.v.base_nc_typeid));
|
|
|
|
}
|
|
|
|
else if (type->nc_type_class == NC_OPAQUE)
|
2010-06-03 21:24:43 +08:00
|
|
|
LOG((3, "Opaque type"));
|
2014-02-12 07:12:08 +08:00
|
|
|
else if (type->nc_type_class == NC_ENUM)
|
|
|
|
{
|
2010-06-03 21:24:43 +08:00
|
|
|
LOG((3, "Enum type"));
|
2014-02-12 07:12:08 +08:00
|
|
|
LOG((4, "base_nc_type: %d", type->u.e.base_nc_typeid));
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
else
|
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
LOG((0, "Unknown class: %d", type->nc_type_class));
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_EBADTYPE;
|
|
|
|
}
|
|
|
|
}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Call self for each child of this group. */
|
|
|
|
if (grp->children)
|
|
|
|
{
|
Refactored read_scale(), memio_new(), var_create_dataset() and makespecial()
to clean up resources properly on failure.
Refactored doubly-linked list code for objects in the libsrc4 directory,
cleaning up the add/del routines, breaking out the common next/prev
pointers into a struct and extracting the add/del operations on them,
changed the list of dims to add new dims in the same order as the other
types, made all add routines able to optionally return a pointer to the
newly created object.
Removed some dead code (pg_var(), nc4_pg_var1(), nc4_pg_varm(), misc. small
routines, etc)
Fixed fill value handling for string types in nc4_get_vara().
Changed many malloc()+strcpy() pairs into calls to strdup().
Cleaned up misc. other minor Coverity issues.
2013-12-08 17:29:26 +08:00
|
|
|
for (g = grp->children; g; g = g->l.next)
|
2014-02-12 07:12:08 +08:00
|
|
|
if ((retval = rec_print_metadata(g, tab_count + 1)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out the internal metadata for a file. This is useful to check
|
|
|
|
* that netCDF is working! Nonetheless, this function will print
|
|
|
|
* nothing if logging is not set to at least two. */
|
|
|
|
int
|
2012-09-07 03:44:03 +08:00
|
|
|
log_metadata_nc(NC *nc)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC_HDF5_FILE_INFO_T *h5 = NC4_DATA(nc);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-12-29 13:04:48 +08:00
|
|
|
LOG((2, "*** NetCDF-4 Internal Metadata: int_ncid 0x%x ext_ncid 0x%x",
|
2010-06-03 21:24:43 +08:00
|
|
|
nc->int_ncid, nc->ext_ncid));
|
|
|
|
if (!h5)
|
|
|
|
{
|
|
|
|
LOG((2, "This is a netCDF-3 file."));
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
LOG((2, "FILE - hdfid: 0x%x path: %s cmode: 0x%x parallel: %d redef: %d "
|
2014-12-29 13:04:48 +08:00
|
|
|
"fill_mode: %d no_write: %d next_nc_grpid: %d", h5->hdfid, nc->path,
|
|
|
|
h5->cmode, (int)h5->parallel, (int)h5->redef, h5->fill_mode, (int)h5->no_write,
|
2010-06-03 21:24:43 +08:00
|
|
|
h5->next_nc_grpid));
|
2014-02-12 07:12:08 +08:00
|
|
|
return rec_print_metadata(h5->root_grp, 0);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*LOGGING */
|
|
|
|
|
|
|
|
/* Show the in-memory metadata for a netcdf file. */
|
|
|
|
int
|
|
|
|
NC4_show_metadata(int ncid)
|
|
|
|
{
|
|
|
|
int retval = NC_NOERR;
|
|
|
|
#ifdef LOGGING
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc;
|
2010-06-03 21:24:43 +08:00
|
|
|
int old_log_level = nc_log_level;
|
2014-12-29 13:04:48 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Find file metadata. */
|
2012-09-07 03:44:03 +08:00
|
|
|
if (!(nc = nc4_find_nc_file(ncid,NULL)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_EBADID;
|
|
|
|
|
|
|
|
/* Log level must be 2 to see metadata. */
|
|
|
|
nc_log_level = 2;
|
|
|
|
retval = log_metadata_nc(nc);
|
|
|
|
nc_log_level = old_log_level;
|
|
|
|
#endif /*LOGGING*/
|
|
|
|
return retval;
|
|
|
|
}
|