NetCDF 4.8.0
Loading...
Searching...
No Matches
nc4hdf.c File Reference
#include "config.h"
#include "netcdf.h"
#include "nc4internal.h"
#include "ncdispatch.h"
#include "hdf5internal.h"
#include "hdf5err.h"
#include "hdf5debug.h"
#include <math.h>

Go to the source code of this file.

Macros

#define NC_HDF5_MAX_NAME   1024
 

Functions

static int attach_dimscales (NC_GRP_INFO_T *grp)
 
static int commit_type (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 
static int create_group (NC_GRP_INFO_T *grp)
 
static int flag_atts_dirty (NCindex *attlist)
 
int nc4_adjust_var_cache (NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
 
int nc4_create_dim_wo_var (NC_DIM_INFO_T *dim)
 
int nc4_get_hdf_typeid (NC_FILE_INFO_T *h5, nc_type xtype, hid_t *hdf_typeid, int endianness)
 
int NC4_hdf5get_libversion (unsigned *major, unsigned *minor, unsigned *release)
 
int NC4_hdf5get_superblock (struct NC_FILE_INFO *h5, int *idp)
 
int NC4_isnetcdf4 (struct NC_FILE_INFO *h5)
 
int nc4_open_var_grp2 (NC_GRP_INFO_T *grp, int varid, hid_t *dataset)
 
int nc4_rec_match_dimscales (NC_GRP_INFO_T *grp)
 
int nc4_rec_write_groups_types (NC_GRP_INFO_T *grp)
 
int nc4_rec_write_metadata (NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order)
 
static int NC4_strict_att_exists (NC_FILE_INFO_T *)
 
static int NC4_walk (hid_t, int *)
 
static int put_att_grpa (NC_GRP_INFO_T *grp, int varid, NC_ATT_INFO_T *att)
 
int rec_detach_scales (NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid)
 
int rec_reattach_scales (NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid)
 
static int remove_coord_atts (hid_t hdf_datasetid)
 
void reportobject (int uselog, hid_t id, unsigned int type)
 
void reportopenobjects (int uselog, hid_t fid)
 
static void reportopenobjectsT (int uselog, hid_t fid, int ntypes, unsigned int *otypes)
 
void showopenobjects (int ncid)
 
void showopenobjects5 (NC_FILE_INFO_T *h5)
 
static int var_create_dataset (NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid)
 
static int var_exists (hid_t grpid, char *name, nc_bool_t *exists)
 
static int write_attlist (NCindex *attlist, int varid, NC_GRP_INFO_T *grp)
 
static int write_coord_dimids (NC_VAR_INFO_T *var)
 
static int write_dim (NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
 
static int write_nc3_strict_att (hid_t hdf_grpid)
 
static int write_netcdf4_dimid (hid_t datasetid, int dimid)
 
static int write_var (NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
 

Detailed Description

This file is part of netcdf-4, a netCDF-like interface for HDF5, or a HDF5 backend for netCDF, depending on your point of view.

This file contains functions internal to the netcdf4 library. None of the functions in this file are exposed in the exetnal API. These functions handle the HDF interface.

Author
Ed Hartnett, Dennis Heimbigner, Ward Fisher

Definition in file nc4hdf.c.

Macro Definition Documentation

◆ NC_HDF5_MAX_NAME

#define NC_HDF5_MAX_NAME   1024

Max size of HDF5 name.

Definition at line 31 of file nc4hdf.c.

Function Documentation

◆ attach_dimscales()

static int attach_dimscales ( NC_GRP_INFO_T * grp)
static

After all the datasets of the file have been read, it's time to sort the wheat from the chaff. Which of the datasets are netCDF dimensions, and which are coordinate variables, and which are non-coordinate variables.

Parameters
grpPointer to group info struct.
Returns
NC_NOERR No error.
Author
Ed Hartnett

Definition at line 1359 of file nc4hdf.c.

◆ commit_type()

static int commit_type ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type )
static

Create a HDF5 defined type from a NC_TYPE_INFO_T struct, and commit it to the file.

Parameters
grpPointer to group info struct.
typePointer to type info struct.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 error.
NC_ECHAR Conversions of NC_CHAR forbidden.
NC_EVARMETA HDF5 returning error creating datatype.
NC_EHDFERR HDF5 returning error.
NC_EBADTYE Type not found.
Author
Ed Hartnett

Definition at line 1116 of file nc4hdf.c.

◆ create_group()

static int create_group ( NC_GRP_INFO_T * grp)
static

Create a HDF5 group that is not the root group. HDF5 properties are set in the group to ensure that objects and attributes are kept in creation order, instead of alphebetical order (the HDF5 default).

Parameters
grpPointer to group info struct.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 error.
Author
Ed Hartnett

Definition at line 1302 of file nc4hdf.c.

◆ flag_atts_dirty()

static int flag_atts_dirty ( NCindex * attlist)
static

Flag attributes in a linked list as dirty.

Parameters
attlistList of attributes, may be NULL.
Returns
NC_NOERR No error.
Author
Dennis Heimbigner

Definition at line 42 of file nc4hdf.c.

◆ nc4_adjust_var_cache()

int nc4_adjust_var_cache ( NC_GRP_INFO_T * grp,
NC_VAR_INFO_T * var )

Adjust the chunk cache of a var for better performance.

Note
For contiguous and compact storage vars, or when parallel I/O is in use, this function will do nothing and return NC_NOERR;
Parameters
grpPointer to group info struct.
varPointer to var info struct.
Returns
NC_NOERR No error.
Author
Ed Hartnett

Definition at line 1060 of file nc4hdf.c.

◆ nc4_create_dim_wo_var()

int nc4_create_dim_wo_var ( NC_DIM_INFO_T * dim)

Write a HDF5 dataset which is a dimension without a coordinate variable. This is a special 1-D dataset.

Parameters
dimPointer to dim info struct.
grpPointer to group info struct.
write_dimid
Returns
NC_NOERR No error.
NC_EPERM Read-only file.
NC_EHDFERR HDF5 returned error.
Author
Ed Hartnett

Definition at line 1711 of file nc4hdf.c.

◆ nc4_get_hdf_typeid()

int nc4_get_hdf_typeid ( NC_FILE_INFO_T * h5,
nc_type xtype,
hid_t * hdf_typeid,
int endianness )

Given a netcdf type, return appropriate HDF typeid. (All hdf_typeid's returned from this routine must be H5Tclosed by the caller).

Parameters
h5Pointer to HDF5 file info struct.
xtypeNetCDF type ID.
hdf_typeidPointer that gets the HDF5 type ID.
endiannessDesired endianness in HDF5 type.
Returns
NC_NOERR No error.
NC_ECHAR Conversions of NC_CHAR forbidden.
NC_EVARMETA HDF5 returning error creating datatype.
NC_EHDFERR HDF5 returning error.
NC_EBADTYE Type not found.
Author
Ed Hartnett

Definition at line 250 of file nc4hdf.c.

◆ NC4_hdf5get_libversion()

int NC4_hdf5get_libversion ( unsigned * major,
unsigned * minor,
unsigned * release )

Get HDF5 library version.

Parameters
majorPointer that gets major version number.
minorPointer that gets minor version number.
releasePointer that gets release version number.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned error.
Author
Dennis Heimbigner

Definition at line 2387 of file nc4hdf.c.

◆ NC4_hdf5get_superblock()

int NC4_hdf5get_superblock ( struct NC_FILE_INFO * h5,
int * idp )

Get HDF5 superblock version.

Parameters
h5Pointer to HDF5 file info struct.
idpPointer that gets superblock version.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned error.
Author
Dennis Heimbigner

Definition at line 2405 of file nc4hdf.c.

◆ NC4_isnetcdf4()

int NC4_isnetcdf4 ( struct NC_FILE_INFO * h5)

Determine whether file is netCDF-4.

We define a file as being from netcdf-4 if any of the following are true:

  1. NCPROPS attribute exists in root group
  2. NC3_STRICT_ATT_NAME exists in root group
  3. any of NC_ATT_REFERENCE_LIST, NC_ATT_CLASS, NC_ATT_DIMENSION_LIST, NC_ATT_NAME, NC_ATT_COORDINATES, NC_DIMID_ATT_NAME exist anywhere in the file; note that this requires walking the file.
Note
WARNINGS:
  1. False negatives are possible for a small subset of netcdf-4 created files; especially if the file looks like a simple netcdf classic file.
  2. Deliberate falsification in the file can be used to cause a false positive.
Parameters
h5Pointer to HDF5 file info struct.
Returns
NC_NOERR No error.
Author
Dennis Heimbigner.

Definition at line 2454 of file nc4hdf.c.

◆ nc4_open_var_grp2()

int nc4_open_var_grp2 ( NC_GRP_INFO_T * grp,
int varid,
hid_t * dataset )

Open a HDF5 dataset and leave it open.

Parameters
grpPointer to group info struct.
varidVariable ID.
datasetPointer that gets the HDF5 dataset ID.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 203 of file nc4hdf.c.

◆ nc4_rec_match_dimscales()

int nc4_rec_match_dimscales ( NC_GRP_INFO_T * grp)

In our first pass through the data, we may have encountered variables before encountering their dimscales, so go through the vars in this file and make sure we've got a dimid for each.

Parameters
grpPointer to group info struct.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
NC_ENOMEM Out of memory.
Author
Ed Hartnett

Definition at line 2021 of file nc4hdf.c.

◆ nc4_rec_write_groups_types()

int nc4_rec_write_groups_types ( NC_GRP_INFO_T * grp)

Recursively write all groups and types.

Parameters
grpPointer to group info struct.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 1965 of file nc4hdf.c.

◆ nc4_rec_write_metadata()

int nc4_rec_write_metadata ( NC_GRP_INFO_T * grp,
nc_bool_t bad_coord_order )

Recursively write all the metadata in a group. Groups and types have all already been written. Propagate bad cooordinate order to subgroups, if detected.

Parameters
grpPointer to group info struct.
bad_coord_order1 if there is a bad coordinate order.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 1879 of file nc4hdf.c.

◆ NC4_strict_att_exists()

static int NC4_strict_att_exists ( NC_FILE_INFO_T * h5)
static

See if the NC3 strict attribute exists.

Parameters
h5Pointer to HDF5 file info struct.
Returns
1 if error || exists; 0 otherwise
Author
Dennis Heimbigner.

Definition at line 2488 of file nc4hdf.c.

◆ NC4_walk()

static int NC4_walk ( hid_t gid,
int * countp )
static

Walk group struct.

Parameters
gidHDF5 ID of starting group.
countpPointer that gets count.
Returns
NC_NOERR No error.
Author
Dennis Heimbigner

Definition at line 2512 of file nc4hdf.c.

◆ put_att_grpa()

static int put_att_grpa ( NC_GRP_INFO_T * grp,
int varid,
NC_ATT_INFO_T * att )
static

Write an attribute.

Parameters
grpPointer to group info struct.
varidVariable ID or NC_GLOBAL.
attPointer to attribute info struct.
Returns
NC_NOERR No error.
NC_ENOTVAR Variable not found.
NC_EPERM Read-only file.
NC_EHDFERR HDF5 returned error.
NC_EATTMETA HDF5 returned error with attribute calls.
Author
Ed Hartnett

Definition at line 428 of file nc4hdf.c.

◆ rec_detach_scales()

int rec_detach_scales ( NC_GRP_INFO_T * grp,
int dimid,
hid_t dimscaleid )

This function is needed to handle one special case: what if the user defines a dim, writes metadata, then goes back into define mode and adds a coordinate var for the already existing dim. In that case, I need to recreate the dim's dimension scale dataset, and then I need to go to every var in the file which uses that dimension, and attach the new dimension scale.

Parameters
grpPointer to group info struct.
dimidDimension ID.
dimscaleidHDF5 dimension scale ID.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 143 of file nc4hdf.c.

◆ rec_reattach_scales()

int rec_reattach_scales ( NC_GRP_INFO_T * grp,
int dimid,
hid_t dimscaleid )

This function is needed to handle one special case: what if the user defines a dim, writes metadata, then goes back into define mode and adds a coordinate var for the already existing dim. In that case, I need to recreate the dim's dimension scale dataset, and then I need to go to every var in the file which uses that dimension, and attach the new dimension scale.

Parameters
grpPointer to group info struct.
dimidDimension ID.
dimscaleidHDF5 dimension scale ID.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 77 of file nc4hdf.c.

◆ remove_coord_atts()

static int remove_coord_atts ( hid_t hdf_datasetid)
static

Convert a coordinate variable HDF5 dataset into one that is not a coordinate variable. This happens during renaming of vars and dims. This function removes the HDF5 NAME and CLASS attributes associated with dimension scales, and also the NC_DIMID_ATT_NAME attribute which may be present, and, if it does, holds the dimid of the coordinate variable.

Parameters
hdf_datasetidThe HDF5 dataset ID of the coordinate variable dataset.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 error.
Author
Ed Hartnett

Definition at line 1464 of file nc4hdf.c.

◆ reportobject()

void reportobject ( int uselog,
hid_t id,
unsigned int type )

Report information about an open HDF5 object. This is called on any still-open objects when a HDF5 file close is attempted.

Parameters
uselogIf true, send output to LOG not stderr.
idHDF5 ID of open object.
typeType of HDF5 object, file, dataset, etc.
Author
Dennis Heimbigner

Definition at line 2242 of file nc4hdf.c.

◆ reportopenobjects()

void reportopenobjects ( int uselog,
hid_t fid )

Report open objects.

Parameters
uselog
fidHDF5 file ID.
Author
Dennit Heimbigner

Definition at line 2325 of file nc4hdf.c.

◆ reportopenobjectsT()

static void reportopenobjectsT ( int uselog,
hid_t fid,
int ntypes,
unsigned int * otypes )
static
Parameters
uselog
fidHDF5 ID.
ntypesNumber of types.
otypesPointer that gets number of open types.
Author
Dennis Heimbigner

Definition at line 2288 of file nc4hdf.c.

◆ showopenobjects()

void showopenobjects ( int ncid)

Report open objects given an ncid Defined to support user or gdb level call.

Parameters
ncidfile id
Author
Dennis Heimbigner

Definition at line 2363 of file nc4hdf.c.

◆ showopenobjects5()

void showopenobjects5 ( NC_FILE_INFO_T * h5)

Report open objects given a pointer to NC_FILE_INFO_T object

Parameters
h5file object
Author
Dennis Heimbigner

Definition at line 2341 of file nc4hdf.c.

◆ var_create_dataset()

static int var_create_dataset ( NC_GRP_INFO_T * grp,
NC_VAR_INFO_T * var,
nc_bool_t write_dimid )
static

This function creates the HDF5 dataset for a variable.

Parameters
grpPointer to group info struct.
varPointer to variable info struct.
write_dimidTrue to write dimid.
Returns
NC_NOERR
NC_ECHAR Conversions of NC_CHAR forbidden.
NC_EVARMETA HDF5 returning error creating datatype.
NC_EHDFERR HDF5 returning error.
NC_EBADTYE Type not found.
Author
Ed Hartnett

Definition at line 747 of file nc4hdf.c.

◆ var_exists()

static int var_exists ( hid_t grpid,
char * name,
nc_bool_t * exists )
static

Does a variable exist?

Parameters
grpidHDF5 group ID.
nameName of variable.
existsPointer that gets 1 of the variable exists, 0 otherwise.
Returns
NC_NOERR No error.
Author
Ed Hartnett

Definition at line 1423 of file nc4hdf.c.

◆ write_attlist()

static int write_attlist ( NCindex * attlist,
int varid,
NC_GRP_INFO_T * grp )
static

Write all the dirty atts in an attlist.

Parameters
attlistPointer to the list if attributes.
varidVariable ID.
grpPointer to group info struct.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 612 of file nc4hdf.c.

◆ write_coord_dimids()

static int write_coord_dimids ( NC_VAR_INFO_T * var)
static

HDF5 dimension scales cannot themselves have scales attached. This is a problem for multidimensional coordinate variables. So this function writes a special attribute for such a variable, which has the ids of all the dimensions for that coordinate variable.

Parameters
varPointer to var info struct.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 648 of file nc4hdf.c.

◆ write_dim()

static int write_dim ( NC_DIM_INFO_T * dim,
NC_GRP_INFO_T * grp,
nc_bool_t write_dimid )
static

Write a dimension.

Parameters
dimPointer to dim info struct.
grpPointer to group info struct.
write_dimid
Returns
NC_NOERR No error.
NC_EPERM Read-only file.
NC_EHDFERR HDF5 returned error.
Author
Ed Hartnett

Definition at line 1802 of file nc4hdf.c.

◆ write_nc3_strict_att()

static int write_nc3_strict_att ( hid_t hdf_grpid)
static

Write an attribute, with value 1, to indicate that strict NC3 rules apply to this file.

Parameters
hdf_grpidHDF5 group ID.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 1257 of file nc4hdf.c.

◆ write_netcdf4_dimid()

static int write_netcdf4_dimid ( hid_t datasetid,
int dimid )
static

Write a special attribute for the netCDF-4 dimension ID.

Parameters
datasetidHDF5 datasset ID.
dimidNetCDF dimension ID.
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett

Definition at line 693 of file nc4hdf.c.

◆ write_var()

static int write_var ( NC_VAR_INFO_T * var,
NC_GRP_INFO_T * grp,
nc_bool_t write_dimid )
static

This function writes a variable. The principle difficulty comes from the possibility that this is a coordinate variable, and was already written to the file as a dimension-only dimscale. If this occurs, then it must be deleted and recreated.

Parameters
varPointer to variable info struct.
grpPointer to group info struct.
write_dimid
Returns
NC_NOERR No error.
NC_EHDFERR HDF5 returned an error.
Author
Ed Hartnett, Quincey Koziol

Definition at line 1513 of file nc4hdf.c.