2011-08-17 05:04:33 +08:00
|
|
|
/** \file
|
2010-07-01 05:05:11 +08:00
|
|
|
This header file contains the definitions of structs used to hold
|
|
|
|
netCDF file metadata in memory.
|
|
|
|
|
2011-08-17 05:04:33 +08:00
|
|
|
Copyright 2005-2011 University Corporation for Atmospheric
|
|
|
|
Research/Unidata.
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#ifndef _NC4INTERNAL_
|
|
|
|
#define _NC4INTERNAL_
|
|
|
|
|
2016-05-04 11:17:06 +08:00
|
|
|
#include "config.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <hdf5.h>
|
2016-06-09 01:26:37 +08:00
|
|
|
|
|
|
|
|
2016-05-04 11:17:06 +08:00
|
|
|
#include "ncdimscale.h"
|
|
|
|
#include "nc_logging.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#ifdef USE_PARALLEL
|
2016-05-04 11:17:06 +08:00
|
|
|
#include "netcdf_par.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif /* USE_PARALLEL */
|
2016-05-04 11:17:06 +08:00
|
|
|
#include "netcdf.h"
|
|
|
|
#include "netcdf_f.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
/* Always needed */
|
|
|
|
#include "nc.h"
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef USE_HDF4
|
|
|
|
#include <mfhdf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define FILE_ID_MASK (0xffff0000)
|
|
|
|
#define GRP_ID_MASK (0x0000ffff)
|
|
|
|
#define ID_SHIFT (16)
|
|
|
|
|
|
|
|
typedef enum {GET, PUT} NC_PG_T;
|
|
|
|
typedef enum {VAR, DIM, ATT} NC_OBJ_T;
|
|
|
|
|
|
|
|
#define NC_MAX_HDF5_NAME (NC_MAX_NAME + 10)
|
|
|
|
#define NC_V2_ERR (-1)
|
|
|
|
|
|
|
|
/* The name of the root group. */
|
|
|
|
#define NC_GROUP_NAME "/"
|
|
|
|
|
|
|
|
#define MEGABYTE 1048576
|
|
|
|
|
|
|
|
/*
|
|
|
|
* limits of the external representation
|
|
|
|
*/
|
|
|
|
#define X_SCHAR_MIN (-128)
|
|
|
|
#define X_SCHAR_MAX 127
|
|
|
|
#define X_UCHAR_MAX 255U
|
|
|
|
#define X_SHORT_MIN (-32768)
|
|
|
|
#define X_SHRT_MIN X_SHORT_MIN /* alias compatible with limits.h */
|
|
|
|
#define X_SHORT_MAX 32767
|
|
|
|
#define X_SHRT_MAX X_SHORT_MAX /* alias compatible with limits.h */
|
|
|
|
#define X_USHORT_MAX 65535U
|
|
|
|
#define X_USHRT_MAX X_USHORT_MAX /* alias compatible with limits.h */
|
|
|
|
#define X_INT_MIN (-2147483647-1)
|
|
|
|
#define X_INT_MAX 2147483647
|
|
|
|
#define X_LONG_MIN X_INT_MIN
|
|
|
|
#define X_LONG_MAX X_INT_MAX
|
|
|
|
#define X_UINT_MAX 4294967295U
|
|
|
|
#ifdef WIN32 /* Windows, of course, has to be a *little* different. */
|
|
|
|
#define X_FLOAT_MAX 3.402823466e+38f
|
|
|
|
#else
|
|
|
|
#define X_FLOAT_MAX 3.40282347e+38f
|
|
|
|
#endif /* WIN32 */
|
|
|
|
#define X_FLOAT_MIN (-X_FLOAT_MAX)
|
2016-02-20 06:05:39 +08:00
|
|
|
#define X_DOUBLE_MAX 1.7976931348623157e+308
|
2010-06-03 21:24:43 +08:00
|
|
|
#define X_DOUBLE_MIN (-X_DOUBLE_MAX)
|
|
|
|
|
|
|
|
/* These have to do with creating chuncked datasets in HDF5. */
|
|
|
|
#define NC_HDF5_UNLIMITED_DIMSIZE (0)
|
|
|
|
#define NC_HDF5_CHUNKSIZE_FACTOR (10)
|
|
|
|
#define NC_HDF5_MIN_CHUNK_SIZE (2)
|
|
|
|
|
|
|
|
#define NC_EMPTY_SCALE "NC_EMPTY_SCALE"
|
|
|
|
|
|
|
|
/* This is an attribute I had to add to handle multidimensional
|
|
|
|
* coordinate variables. */
|
|
|
|
#define COORDINATES "_Netcdf4Coordinates"
|
|
|
|
#define COORDINATES_LEN (NC_MAX_NAME * 5)
|
|
|
|
|
|
|
|
/* This is used when the user defines a non-coordinate variable with
|
|
|
|
* same name as a dimension. */
|
|
|
|
#define NON_COORD_PREPEND "_nc4_non_coord_"
|
|
|
|
|
|
|
|
/* An attribute in the HDF5 root group of this name means that the
|
|
|
|
* file must follow strict netCDF classic format rules. */
|
|
|
|
#define NC3_STRICT_ATT_NAME "_nc3_strict"
|
|
|
|
|
|
|
|
/* If this attribute is present on a dimscale variable, use the value
|
|
|
|
* as the netCDF dimid. */
|
|
|
|
#define NC_DIMID_ATT_NAME "_Netcdf4Dimid"
|
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Boolean type, to make the code easier to read */
|
|
|
|
typedef enum {NC_FALSE = 0, NC_TRUE = 1} nc_bool_t;
|
|
|
|
|
2016-05-04 11:17:06 +08:00
|
|
|
/*Forward*/
|
|
|
|
struct NCFILEINFO;
|
|
|
|
|
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
|
|
|
/* Generic doubly-linked list node */
|
|
|
|
typedef struct NC_LIST_NODE
|
|
|
|
{
|
|
|
|
void *next;
|
|
|
|
void *prev;
|
|
|
|
} NC_LIST_NODE_T;
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* This is a struct to handle the dim metadata. */
|
|
|
|
typedef struct NC_DIM_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2010-07-01 21:36:41 +08:00
|
|
|
char *name;
|
2010-06-03 21:24:43 +08:00
|
|
|
size_t len;
|
2016-03-04 04:18:31 +08:00
|
|
|
uint32_t hash;
|
2010-06-03 21:24:43 +08:00
|
|
|
int dimid;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t unlimited; /* True if the dimension is unlimited */
|
|
|
|
nc_bool_t extended; /* True if the dimension needs to be extended */
|
|
|
|
nc_bool_t too_long; /* True if len is too big to fit in local size_t. */
|
2010-06-03 21:24:43 +08:00
|
|
|
hid_t hdf_dimscaleid;
|
2013-12-01 13:20:28 +08:00
|
|
|
HDF5_OBJID_T hdf5_objid;
|
2010-06-03 21:24:43 +08:00
|
|
|
struct NC_VAR_INFO *coord_var; /* The coord var, if it exists. */
|
|
|
|
} NC_DIM_INFO_T;
|
|
|
|
|
|
|
|
typedef struct NC_ATT_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2010-07-01 21:08:28 +08:00
|
|
|
char *name;
|
2014-02-12 07:12:08 +08:00
|
|
|
int len;
|
|
|
|
nc_bool_t dirty; /* True if attribute modified */
|
|
|
|
nc_bool_t created; /* True if attribute already created */
|
|
|
|
nc_type nc_typeid; /* netCDF type of attribute's data */
|
|
|
|
hid_t native_hdf_typeid; /* Native HDF5 datatype for attribute's data */
|
2010-06-03 21:24:43 +08:00
|
|
|
int attnum;
|
|
|
|
void *data;
|
|
|
|
nc_vlen_t *vldata; /* only used for vlen */
|
|
|
|
char **stdata; /* only for string type. */
|
|
|
|
} NC_ATT_INFO_T;
|
|
|
|
|
|
|
|
/* This is a struct to handle the var metadata. */
|
|
|
|
typedef struct NC_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2010-07-01 19:39:34 +08:00
|
|
|
char *name;
|
2010-07-01 05:16:50 +08:00
|
|
|
char *hdf5_name; /* used if different from name */
|
2010-06-03 21:24:43 +08:00
|
|
|
int ndims;
|
2010-07-01 20:52:44 +08:00
|
|
|
int *dimids;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_DIM_INFO_T **dim;
|
|
|
|
int varid;
|
|
|
|
int natts;
|
2016-03-04 04:18:31 +08:00
|
|
|
uint32_t hash;
|
2014-11-24 23:36:58 +08:00
|
|
|
nc_bool_t is_new_var; /* True if variable is newly created */
|
|
|
|
nc_bool_t was_coord_var; /* True if variable was a coordinate var, but either the dim or var has been renamed */
|
|
|
|
nc_bool_t became_coord_var; /* True if variable _became_ a coordinate var, because either the dim or var has been renamed */
|
2014-12-01 22:52:53 +08:00
|
|
|
nc_bool_t fill_val_changed; /* True if variable's fill value changes after it has been created */
|
2014-11-24 23:36:58 +08:00
|
|
|
nc_bool_t attr_dirty; /* True if variable's attributes are dirty and should be rewritten */
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t created; /* Variable has already been created (_not_ that it was just created) */
|
|
|
|
nc_bool_t written_to; /* True if variable has data written to it */
|
2010-06-03 21:24:43 +08:00
|
|
|
struct NC_TYPE_INFO *type_info;
|
|
|
|
hid_t hdf_datasetid;
|
|
|
|
NC_ATT_INFO_T *att;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t no_fill; /* True if no fill value is defined for var */
|
2010-06-03 21:24:43 +08:00
|
|
|
void *fill_value;
|
2010-07-01 05:05:11 +08:00
|
|
|
size_t *chunksizes;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t contiguous; /* True if variable is stored contiguously in HDF5 file */
|
|
|
|
int parallel_access; /* Type of parallel access for I/O on variable (collective or independent) */
|
|
|
|
nc_bool_t dimscale; /* True if var is a dimscale */
|
|
|
|
nc_bool_t *dimscale_attached; /* Array of flags that are true if dimscale is attached for that dim index */
|
2010-06-03 21:24:43 +08:00
|
|
|
HDF5_OBJID_T *dimscale_hdf5_objids;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t deflate; /* True if var has deflate filter applied */
|
2010-06-03 21:24:43 +08:00
|
|
|
int deflate_level;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t shuffle; /* True if var has shuffle filter applied */
|
|
|
|
nc_bool_t fletcher32; /* True if var has fletcher32 filter applied */
|
|
|
|
nc_bool_t szip; /* True if var has szip filter applied */
|
2010-06-03 21:24:43 +08:00
|
|
|
int options_mask;
|
|
|
|
int pixels_per_block;
|
|
|
|
size_t chunk_cache_size, chunk_cache_nelems;
|
|
|
|
float chunk_cache_preemption;
|
2014-02-12 07:12:08 +08:00
|
|
|
#ifdef USE_HDF4
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Stuff below is for hdf4 files. */
|
|
|
|
int sdsid;
|
|
|
|
int hdf4_data_type;
|
2014-02-12 07:12:08 +08:00
|
|
|
#endif /* USE_HDF4 */
|
2011-08-17 05:04:33 +08:00
|
|
|
/* Stuff below for diskless data files. */
|
|
|
|
void *diskless_data;
|
2010-06-03 21:24:43 +08:00
|
|
|
} NC_VAR_INFO_T;
|
|
|
|
|
|
|
|
typedef struct NC_FIELD_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_type nc_typeid;
|
2010-06-03 21:24:43 +08:00
|
|
|
hid_t hdf_typeid;
|
2014-02-12 07:12:08 +08:00
|
|
|
hid_t native_hdf_typeid;
|
2010-06-03 21:24:43 +08:00
|
|
|
size_t offset;
|
2010-07-01 23:51:19 +08:00
|
|
|
char *name;
|
2014-02-12 07:12:08 +08:00
|
|
|
int fieldid; /* ID (index?) of field */
|
2010-06-03 21:24:43 +08:00
|
|
|
int ndims;
|
2010-07-02 00:02:10 +08:00
|
|
|
int *dim_size;
|
2010-06-03 21:24:43 +08:00
|
|
|
} NC_FIELD_INFO_T;
|
|
|
|
|
|
|
|
typedef struct NC_ENUM_MEMBER_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2010-07-01 23:51:19 +08:00
|
|
|
char *name;
|
2010-06-03 21:24:43 +08:00
|
|
|
void *value;
|
|
|
|
} NC_ENUM_MEMBER_INFO_T;
|
|
|
|
|
|
|
|
typedef struct NC_TYPE_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2010-07-01 21:17:54 +08:00
|
|
|
char *name;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_type nc_typeid; /* netCDF type ID, equivalent to a pre-defined type
|
|
|
|
* for atomic types, but a dynamically
|
|
|
|
* defined value for user-defined types (stored
|
|
|
|
* as named datatypes in the HDF5 file).
|
|
|
|
*/
|
|
|
|
unsigned rc; /* Ref. count of objects using this type */
|
|
|
|
hid_t hdf_typeid; /* HDF5 type ID, in the file */
|
|
|
|
hid_t native_hdf_typeid; /* HDF5 type ID, in memory */
|
|
|
|
int endianness; /* What endianness for the type? */
|
|
|
|
/* (Set for integer types as well as "complex"
|
|
|
|
* types, like compound/enum/vlen, used for the
|
|
|
|
* endianness of the fields and/or base type)
|
|
|
|
*/
|
|
|
|
size_t size; /* Size of the type in memory, in bytes */
|
|
|
|
nc_bool_t committed; /* True when datatype is committed in the file */
|
|
|
|
nc_type nc_type_class; /* NC_VLEN, NC_COMPOUND, NC_OPAQUE, or NC_ENUM
|
|
|
|
* NOTE: NC_INT is used for all integer types,
|
|
|
|
* NC_FLOAT is used for all floating-point
|
|
|
|
* types, and NC_STRING is also used for
|
|
|
|
* fixed- and variable-length strings.
|
|
|
|
* (NC_CHAR is used for characters though)
|
|
|
|
*
|
|
|
|
* This is somewhat redundant with the
|
|
|
|
* nc_type field, but allows the code to
|
|
|
|
* have a single location to look at for
|
|
|
|
* the "kind" of a type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Information for each type or class */
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int num_members;
|
|
|
|
NC_ENUM_MEMBER_INFO_T *enum_member;
|
|
|
|
nc_type base_nc_typeid;
|
|
|
|
hid_t base_hdf_typeid;
|
|
|
|
} e; /* Enum */
|
|
|
|
struct {
|
|
|
|
int num_fields;
|
|
|
|
NC_FIELD_INFO_T *field;
|
|
|
|
} c; /* Compound */
|
|
|
|
struct {
|
|
|
|
nc_type base_nc_typeid;
|
|
|
|
hid_t base_hdf_typeid;
|
|
|
|
} v; /* Variable-length */
|
|
|
|
} u; /* Union of structs, for each type/class */
|
2010-06-03 21:24:43 +08:00
|
|
|
} NC_TYPE_INFO_T;
|
|
|
|
|
2016-07-07 22:28:24 +08:00
|
|
|
typedef struct NC_VAR_ARRAY_T {
|
|
|
|
size_t nalloc; /* number allocated >= nelems */
|
|
|
|
size_t nelems; /* length of the array */
|
|
|
|
NC_VAR_INFO_T **value;
|
|
|
|
} NC_VAR_ARRAY_T;
|
|
|
|
|
|
|
|
extern void
|
|
|
|
free_NC_VAR_ARRAY_V0(NC_VAR_ARRAY_T *ncap);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
free_NC_VAR_ARRAY_V(NC_VAR_ARRAY_T *ncap);
|
|
|
|
|
|
|
|
extern int
|
|
|
|
dup_NC_VAR_ARRAY_V(NC_VAR_ARRAY_T *ncap, const NC_VAR_ARRAY_T *ref);
|
|
|
|
|
|
|
|
extern NC_VAR_INFO_T *
|
|
|
|
elem_NC_VAR_ARRAY(const NC_VAR_ARRAY_T *ncap, size_t elem);
|
|
|
|
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* This holds information for one group. Groups reproduce with
|
|
|
|
* parthenogenesis. */
|
|
|
|
typedef struct NC_GRP_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
|
|
|
NC_LIST_NODE_T l; /* Use generic doubly-linked list (must be first) */
|
2014-02-12 07:12:08 +08:00
|
|
|
char *name;
|
|
|
|
hid_t hdf_grpid;
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc_grpid;
|
2014-02-12 07:12:08 +08:00
|
|
|
struct NC_HDF5_FILE_INFO *nc4_info;
|
2010-06-03 21:24:43 +08:00
|
|
|
struct NC_GRP_INFO *parent;
|
|
|
|
struct NC_GRP_INFO *children;
|
2016-07-07 22:28:24 +08:00
|
|
|
NC_VAR_ARRAY_T vars;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
NC_DIM_INFO_T *dim;
|
|
|
|
NC_ATT_INFO_T *att;
|
2014-02-12 07:12:08 +08:00
|
|
|
NC_TYPE_INFO_T *type;
|
2010-06-03 21:24:43 +08:00
|
|
|
int nvars;
|
|
|
|
int ndims;
|
|
|
|
int natts;
|
|
|
|
} NC_GRP_INFO_T;
|
|
|
|
|
|
|
|
/* These constants apply to the cmode parameter in the
|
|
|
|
* HDF5_FILE_INFO_T defined below. */
|
|
|
|
#define NC_CREAT 2 /* in create phase, cleared by ncendef */
|
|
|
|
#define NC_INDEF 8 /* in define mode, cleared by ncendef */
|
|
|
|
#define NC_NSYNC 0x10 /* synchronise numrecs on change */
|
|
|
|
#define NC_HSYNC 0x20 /* synchronise whole header on change */
|
|
|
|
#define NC_NDIRTY 0x40 /* numrecs has changed */
|
|
|
|
#define NC_HDIRTY 0x80 /* header info has changed */
|
|
|
|
|
2016-05-04 11:17:06 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* This is the metadata we need to keep track of for each
|
|
|
|
netcdf-4/HDF5 file. */
|
2012-09-07 03:44:03 +08:00
|
|
|
typedef struct NC_HDF5_FILE_INFO
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC* controller;
|
2010-06-03 21:24:43 +08:00
|
|
|
hid_t hdfid;
|
2015-08-16 06:26:35 +08:00
|
|
|
#ifdef USE_PARALLEL4
|
2013-08-19 09:45:17 +08:00
|
|
|
MPI_Comm comm; /* Copy of MPI Communicator used to open the file */
|
|
|
|
MPI_Info info; /* Copy of MPI Information Object used to open the file */
|
|
|
|
#endif
|
2010-06-03 21:24:43 +08:00
|
|
|
int flags;
|
|
|
|
int cmode;
|
|
|
|
int nvars;
|
|
|
|
int ndims;
|
|
|
|
int natts;
|
2014-02-12 07:12:08 +08:00
|
|
|
nc_bool_t parallel; /* True if file is open for parallel access */
|
|
|
|
nc_bool_t redef; /* True if redefining an existing file */
|
|
|
|
int fill_mode; /* Fill mode for vars - Unused internally currently */
|
|
|
|
nc_bool_t no_write; /* true if nc_open has mode NC_NOWRITE. */
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_GRP_INFO_T *root_grp;
|
|
|
|
short next_nc_grpid;
|
|
|
|
NC_TYPE_INFO_T *type;
|
|
|
|
int next_typeid;
|
|
|
|
int next_dimid;
|
2014-02-12 07:12:08 +08:00
|
|
|
#ifdef USE_HDF4
|
|
|
|
nc_bool_t hdf4; /* True for HDF4 file */
|
2010-06-03 21:24:43 +08:00
|
|
|
int sdid;
|
2014-02-12 07:12:08 +08:00
|
|
|
#endif /* USE_HDF4 */
|
2016-05-04 11:17:06 +08:00
|
|
|
struct NCFILEINFO* fileinfo;
|
2012-09-07 03:44:03 +08:00
|
|
|
} NC_HDF5_FILE_INFO_T;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
|
2016-03-09 00:41:24 +08:00
|
|
|
/* Defined in lookup3.c */
|
|
|
|
extern uint32_t hash_fast(const void *key, size_t length);
|
|
|
|
|
2015-08-20 17:42:05 +08:00
|
|
|
/* These functions convert between netcdf and HDF5 types. */
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_get_typelen_mem(NC_HDF5_FILE_INFO_T *h5, nc_type xtype,
|
2010-06-03 21:24:43 +08:00
|
|
|
int is_long, size_t *len);
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_convert_type(const void *src, void *dest,
|
|
|
|
const nc_type src_type, const nc_type dest_type,
|
|
|
|
const size_t len, int *range_error,
|
2010-06-03 21:24:43 +08:00
|
|
|
const void *fill_value, int strict_nc3, int src_long,
|
|
|
|
int dest_long);
|
|
|
|
|
|
|
|
/* These functions do HDF5 things. */
|
2013-12-01 13:20:28 +08:00
|
|
|
int rec_detach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid);
|
2014-11-24 23:36:58 +08:00
|
|
|
int rec_reattach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_open_var_grp2(NC_GRP_INFO_T *grp, int varid, hid_t *dataset);
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_put_vara(NC *nc, int ncid, int varid, const size_t *startp,
|
2010-06-03 21:24:43 +08:00
|
|
|
const size_t *countp, nc_type xtype, int is_long, void *op);
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_get_vara(NC *nc, int ncid, int varid, const size_t *startp,
|
2010-06-03 21:24:43 +08:00
|
|
|
const size_t *countp, nc_type xtype, int is_long, void *op);
|
|
|
|
int nc4_rec_match_dimscales(NC_GRP_INFO_T *grp);
|
2014-11-24 23:36:58 +08:00
|
|
|
int nc4_rec_detect_need_to_preserve_dimids(NC_GRP_INFO_T *grp, nc_bool_t *bad_coord_orderp);
|
|
|
|
int nc4_rec_write_metadata(NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order);
|
2013-12-01 13:20:28 +08:00
|
|
|
int nc4_rec_write_groups_types(NC_GRP_INFO_T *grp);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_enddef_netcdf4_file(NC_HDF5_FILE_INFO_T *h5);
|
|
|
|
int nc4_reopen_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var);
|
|
|
|
int nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T * var);
|
|
|
|
|
|
|
|
/* The following functions manipulate the in-memory linked list of
|
|
|
|
metadata, without using HDF calls. */
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grp,
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_HDF5_FILE_INFO_T **h5);
|
|
|
|
int nc4_find_grp_h5(int ncid, NC_GRP_INFO_T **grp, NC_HDF5_FILE_INFO_T **h5);
|
|
|
|
int nc4_find_nc4_grp(int ncid, NC_GRP_INFO_T **grp);
|
|
|
|
NC_GRP_INFO_T *nc4_find_nc_grp(int ncid);
|
|
|
|
NC_GRP_INFO_T *nc4_rec_find_grp(NC_GRP_INFO_T *start_grp, int target_nc_grpid);
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc4_find_nc_file(int ncid, NC_HDF5_FILE_INFO_T**);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim, NC_GRP_INFO_T **dim_grp);
|
2013-12-01 13:20:28 +08:00
|
|
|
int nc4_find_var(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len);
|
2014-02-12 07:12:08 +08:00
|
|
|
int nc4_find_type(const NC_HDF5_FILE_INFO_T *h5, int typeid1, NC_TYPE_INFO_T **type);
|
2015-02-06 08:05:10 +08:00
|
|
|
NC_TYPE_INFO_T *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
|
|
|
NC_TYPE_INFO_T *nc4_rec_find_hdf_type(NC_GRP_INFO_T *start_grp, hid_t target_hdf_typeid);
|
|
|
|
NC_TYPE_INFO_T *nc4_rec_find_named_type(NC_GRP_INFO_T *start_grp, char *name);
|
|
|
|
NC_TYPE_INFO_T *nc4_rec_find_equal_type(NC_GRP_INFO_T *start_grp, int ncid1, NC_TYPE_INFO_T *type);
|
|
|
|
int nc4_find_nc_att(int ncid, int varid, const char *name, int attnum,
|
|
|
|
NC_ATT_INFO_T **att);
|
2016-02-20 06:05:39 +08:00
|
|
|
int 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);
|
|
|
|
int nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum,
|
|
|
|
NC_ATT_INFO_T **att);
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_get_hdf_typeid(NC_HDF5_FILE_INFO_T *h5, nc_type xtype,
|
2010-06-03 21:24:43 +08:00
|
|
|
hid_t *hdf_typeid, int endianness);
|
2014-02-12 07:12:08 +08:00
|
|
|
int nc4_get_typeclass(const NC_HDF5_FILE_INFO_T *h5, nc_type xtype,
|
|
|
|
int *type_class);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* Free various types */
|
|
|
|
int nc4_type_free(NC_TYPE_INFO_T *type);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
/* These list functions add and delete vars, atts. */
|
2012-09-07 03:44:03 +08:00
|
|
|
int nc4_nc4f_list_add(NC *nc, const char *path, int mode);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_var_list_add(NC_VAR_INFO_T **list, NC_VAR_INFO_T **var);
|
2013-03-01 16:10:28 +08:00
|
|
|
int nc4_var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *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
|
|
|
int nc4_dim_list_add(NC_DIM_INFO_T **list, NC_DIM_INFO_T **dim);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_dim_list_del(NC_DIM_INFO_T **list, NC_DIM_INFO_T *dim);
|
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 nc4_att_list_add(NC_ATT_INFO_T **list, NC_ATT_INFO_T **att);
|
2014-02-12 07:12:08 +08:00
|
|
|
int 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
|
|
|
int nc4_field_list_add(NC_FIELD_INFO_T **list, int fieldid, const char *name,
|
2016-02-20 06:05:39 +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);
|
2012-09-07 03:44:03 +08:00
|
|
|
void nc4_file_list_del(NC *nc);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_att_list_del(NC_ATT_INFO_T **list, NC_ATT_INFO_T *att);
|
2016-02-20 06:05:39 +08:00
|
|
|
int nc4_grp_list_add(NC_GRP_INFO_T **list, int new_nc_grpid, NC_GRP_INFO_T *parent_grp,
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc, char *name, NC_GRP_INFO_T **grp);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp);
|
|
|
|
int nc4_enum_member_add(NC_ENUM_MEMBER_INFO_T **list, size_t size,
|
|
|
|
const char *name, const void *value);
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
/* Break & reform coordinate variables */
|
|
|
|
int nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim);
|
|
|
|
int nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Check and normalize names. */
|
2014-02-12 07:12:08 +08:00
|
|
|
int NC_check_name(const char *name);
|
2010-06-03 21:24:43 +08:00
|
|
|
int nc4_check_name(const char *name, char *norm_name);
|
|
|
|
int nc4_normalize_name(const char *name, char *norm_name);
|
|
|
|
int nc4_check_dup_name(NC_GRP_INFO_T *grp, char *norm_name);
|
|
|
|
|
2016-01-29 06:03:40 +08:00
|
|
|
/* HDF5 initialization */
|
2016-05-04 11:17:06 +08:00
|
|
|
extern int nc4_hdf5_initialized;
|
|
|
|
extern void nc4_hdf5_initialize(void);
|
2016-01-29 06:03:40 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* This is only included if --enable-logging is used for configure; it
|
|
|
|
prints info about the metadata to stderr. */
|
|
|
|
#ifdef LOGGING
|
2012-09-07 03:44:03 +08:00
|
|
|
int log_metadata_nc(NC *nc);
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
|
|
|
|
2012-09-07 03:44:03 +08:00
|
|
|
/* Define accessors for the dispatchdata */
|
|
|
|
#define NC4_DATA(nc) ((NC_HDF5_FILE_INFO_T*)(nc)->dispatchdata)
|
|
|
|
#define NC4_DATA_SET(nc,data) ((nc)->dispatchdata = (void*)(data))
|
|
|
|
|
2016-05-04 11:17:06 +08:00
|
|
|
/* Reserved Attributes */
|
|
|
|
extern const char* NC_RESERVED_VARATT_LIST[];
|
|
|
|
extern const char* NC_RESERVED_ATT_LIST[];
|
|
|
|
extern const char* NC_RESERVED_SPECIAL_LIST[];
|
|
|
|
#define NC_ATT_REFERENCE_LIST "REFERENCE_LIST"
|
|
|
|
#define NC_ATT_CLASS "CLASS"
|
|
|
|
#define NC_ATT_DIMENSION_LIST "DIMENSION_LIST"
|
|
|
|
#define NC_ATT_NAME "NAME"
|
|
|
|
#define NC_ATT_COORDINATES COORDINATES /*defined above*/
|
|
|
|
#define NC_ATT_FORMAT "_Format"
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/**
|
|
|
|
For netcdf4 files, capture state information about the following:
|
|
|
|
1. Global: netcdf library version
|
|
|
|
2. Global: hdf5 library version
|
|
|
|
3. Per file: superblock version
|
|
|
|
4. Per File: was it created by netcdf-4?
|
|
|
|
5. Per file: _NCProperties attribute
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NCPROPS "_NCProperties"
|
|
|
|
#define NCPROPS_VERSION (1)
|
|
|
|
#define NCPROPSSEP '|'
|
|
|
|
|
|
|
|
/* Currently used properties */
|
|
|
|
#define NCPVERSION "version" /* Of the properties format */
|
|
|
|
#define NCPHDF5LIBVERSION "hdf5libversion"
|
|
|
|
#define NCPNCLIBVERSION "netcdflibversion"
|
|
|
|
|
|
|
|
/* Other hidden attributes */
|
|
|
|
#define ISNETCDF4ATT "_IsNetcdf4"
|
|
|
|
#define SUPERBLOCKATT "_SuperblockVersion"
|
|
|
|
|
|
|
|
struct NCFILEINFO {
|
|
|
|
int superblockversion;
|
|
|
|
/* Following is filled from NCPROPS attribute or from global version */
|
|
|
|
struct NCPROPINFO {
|
|
|
|
int version; /* 0 => not defined */
|
|
|
|
char hdf5ver[NC_MAX_NAME+1];
|
|
|
|
char netcdfver[NC_MAX_NAME+1];
|
|
|
|
} propattr;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct NCPROPINFO globalpropinfo;
|
|
|
|
|
|
|
|
extern int NC4_fileinfo_init(void); /*libsrc4/ncinfo.c*/
|
|
|
|
extern int NC4_get_fileinfo(struct NC_HDF5_FILE_INFO* info, struct NCPROPINFO*); /*libsrc4/ncinfo.c*/
|
|
|
|
extern int NC4_put_propattr(struct NC_HDF5_FILE_INFO* info); /*libsrc4/ncinfo.c*/
|
2016-08-08 23:24:19 +08:00
|
|
|
extern int NC4_buildpropinfo(struct NCPROPINFO* info,char** propdatap);
|
2016-05-04 11:17:06 +08:00
|
|
|
|
|
|
|
extern int NC4_hdf5get_libversion(unsigned*,unsigned*,unsigned*);/*libsrc4/nc4hdf.c*/
|
|
|
|
extern int NC4_hdf5get_superblock(struct NC_HDF5_FILE_INFO*, int*);/*libsrc4/nc4hdf.c*/
|
|
|
|
extern int NC4_isnetcdf4(struct NC_HDF5_FILE_INFO*); /*libsrc4/nc4hdf.c*/
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif /* _NETCDF4_ */
|