Merge branch 'master' into ejh_cleanup

This commit is contained in:
Ward Fisher 2018-04-16 16:05:49 -06:00 committed by GitHub
commit af36e53d21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1674 additions and 1320 deletions

View File

@ -10,6 +10,7 @@ IF(USE_HDF4_FILE_TESTS AND NOT MSVC)
build_bin_test_no_prefix(tst_interops3)
add_bin_test(hdf4_test tst_chunk_hdf4)
add_bin_test(hdf4_test tst_h4_lendian)
add_bin_test(hdf4_test tst_hdf4_extra)
add_sh_test(hdf4_test run_get_hdf4_files)
add_sh_test(hdf4_test run_formatx_hdf4)
ENDIF()

View File

@ -14,8 +14,8 @@ include $(top_srcdir)/lib_flags.am
AM_LDFLAGS += ${top_builddir}/liblib/libnetcdf.la
# These are the C tests for HDF4.
check_PROGRAMS = tst_chunk_hdf4 tst_h4_lendian
TESTS = tst_chunk_hdf4 tst_h4_lendian
check_PROGRAMS = tst_chunk_hdf4 tst_h4_lendian tst_hdf4_extra
TESTS = tst_chunk_hdf4 tst_h4_lendian tst_hdf4_extra
# This test script depends on ncdump and tst_interops2.c.
if BUILD_UTILITIES

View File

@ -95,7 +95,7 @@ main(int argc, char **argv)
if (nc_open(CONTIGFILE, 0, &ncid)) ERR;
if (nc_inq_varid(ncid, CONTIGVAR, &varid)) ERR;
if (nc_def_var_deflate(ncid, varid, 0, 1, 4) != NC_EPERM) ERR;
if (nc_def_var_deflate(ncid, varid, 0, 1, 4) != NC_ENOTNC4) ERR;
if (nc_close(ncid)) ERR;
}

179
hdf4_test/tst_hdf4_extra.c Normal file
View File

@ -0,0 +1,179 @@
/* This is part of the netCDF package. Copyright 2005-2011,
University Corporation for Atmospheric Research/Unidata. See
COPYRIGHT file for conditions of use.
Test that NetCDF-4 can read HDF4 files.
Ed Hartnett
*/
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <mfhdf.h>
#include <netcdf_f.h>
#define FILE_NAME "tst_hdf4_extra.h4"
#define PRES_NAME "pres"
#define LAT_LEN 3
#define LON_LEN 2
#define NDIMS2 2
#define ATT_NAME "Caesar"
#define NAME_DUMB "Bozo"
int
create_hdf4_file()
{
int32 sd_id, sds_id;
int32 dim_size[NDIMS2] = {LAT_LEN, LON_LEN};
int32 start[NDIMS2] = {0, 0}, edge[NDIMS2] = {LAT_LEN, LON_LEN};
int data_out[LAT_LEN][LON_LEN];
int test_val = 42;
int i, j;
int count = 0;
/* Create some data. */
for (i = 0; i < LAT_LEN; i++)
for (j = 0; j < LON_LEN; j++)
data_out[i][j] = count++;
/* Create a file with one SDS, containing our phony data. */
sd_id = SDstart(FILE_NAME, DFACC_CREATE);
sds_id = SDcreate(sd_id, PRES_NAME, DFNT_INT32, NDIMS2, dim_size);
if (SDwritedata(sds_id, start, NULL, edge, (void *)data_out)) ERR;
/* Add a global attribute. */
if (SDsetattr(sd_id, ATT_NAME, DFNT_INT32, 1, &test_val)) ERR;
/* Shut down. */
if (SDendaccess(sds_id)) ERR;
if (SDend(sd_id)) ERR;
return 0;
}
int
main(int argc, char **argv)
{
printf("\n*** Testing HDF4/NetCDF-4 interoperability extra stuff...\n");
/* Create our test file. */
if (create_hdf4_file()) ERR;
printf("*** testing data conversion...");
{
int ncid;
size_t start[NDIMS2] = {0, 0}, count[NDIMS2] = {LAT_LEN, LON_LEN};
int data_int[LAT_LEN * LON_LEN];
short data_short[LAT_LEN * LON_LEN];
int data_int2[LAT_LEN * LON_LEN];
float data_float[LAT_LEN * LON_LEN];
double data_double[LAT_LEN * LON_LEN];
/* Open HDF4 file with netCDF. */
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
/* These won't work. */
if (nc_get_vara_int(ncid, 0, NULL, count, data_int) != NC_EINVAL) ERR;
if (nc_get_vara_int(ncid, 0, start, count, NULL) != NC_EINVAL) ERR;
if (nc_get_vara_int(ncid + TEST_VAL_42, 0, start, count, data_int) != NC_EBADID) ERR;
/* Read data as short. */
if (nc_get_vara_short(ncid, 0, start, count, data_short)) ERR;
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
if (data_short[i] != (short)i) ERR;
/* Read data as int. */
if (nc_get_vara_int(ncid, 0, start, count, data_int)) ERR;
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
if (data_int[i] != i) ERR;
/* NULL count is treated as meaing entire variable. */
if (nc_get_vara_int(ncid, 0, start, NULL, data_int2)) ERR;
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
if (data_int2[i] != i) ERR;
/* Read data as float. */
if (nc_get_vara_float(ncid, 0, start, count, data_float)) ERR;
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
if (data_float[i] != (float)i) ERR;
/* Read data as double. */
if (nc_get_vara_double(ncid, 0, start, count, data_double)) ERR;
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
if (data_double[i] != (double)i) ERR;
/* Close the file. */
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing bad parameters, read-only writes, and abort...");
{
int ncid;
int ndims, nvars, ngatts, unlimdimid;
size_t start[NDIMS2] = {0, 0}, count[NDIMS2] = {1, 1};
int test_val;
/* These will not work. */
if (nc_open(FILE_NAME, NC_MMAP, &ncid) != NC_EINVAL) ERR;
if (nc_open(FILE_NAME, NC_64BIT_OFFSET, &ncid) != NC_EINVAL) ERR;
if (nc_open(FILE_NAME, NC_MPIIO, &ncid) != NC_EINVAL) ERR;
if (nc_open(FILE_NAME, NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
if (nc_open(FILE_NAME, NC_DISKLESS, &ncid) != NC_EINVAL) ERR;
/* Now open with netCDF. */
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
/* Check it out. */
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
if (ndims != 2 || nvars != 1 || ngatts != 1 || unlimdimid != -1) ERR;
if (nc_inq(ncid, NULL, NULL, NULL, NULL)) ERR;
if (nc_inq(ncid + TEST_VAL_42, NULL, NULL, NULL, NULL) != NC_EBADID) ERR;
/* These only work for netCDF-3 files. */
if (nc_set_base_pe(ncid, 0) != NC_ENOTNC3) ERR;
if (nc_inq_base_pe(ncid, NULL) != NC_ENOTNC3) ERR;
/* Attempt to write. */
if (nc_rename_att(ncid, NC_GLOBAL, ATT_NAME, NAME_DUMB) != NC_EPERM) ERR;
if (nc_del_att(ncid, NC_GLOBAL, ATT_NAME) != NC_EPERM) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, NAME_DUMB, NC_INT, 0, NULL) != NC_EPERM) ERR;
if (nc_def_dim(ncid, NAME_DUMB, 1, NULL) != NC_EPERM) ERR;
if (nc_def_var(ncid, "hh", NC_INT, 0, NULL, NULL) != NC_EPERM) ERR;
if (nc_def_var_fill(ncid, 0, 0, &test_val) != NC_EPERM) ERR;
if (nc_rename_var(ncid, 0, NAME_DUMB) != NC_EPERM) ERR;
if (nc_put_vara_int(ncid, 0, start, count, &test_val) != NC_EPERM) ERR;
if (nc_set_fill(ncid, 0, NULL) != NC_EPERM) ERR;
if (nc_rename_dim(ncid, 0, NULL) != NC_EPERM) ERR;
/* These succeed but do nothing. */
if (nc_enddef(ncid)) ERR;
if (nc_sync(ncid)) ERR;
/* These netcdf-4 operations are not supported. */
if (nc_def_var_filter(ncid, 0, 0, 0, NULL) != NC_ENOTNC4) ERR;
if (nc_def_var_fletcher32(ncid, 0, 0) != NC_ENOTNC4) ERR;
if (nc_def_var_endian(ncid, 0, 0) != NC_ENOTNC4) ERR;
if (nc_def_grp(ncid, NAME_DUMB, NULL) != NC_ENOTNC4) ERR;
if (nc_rename_grp(ncid, NAME_DUMB) != NC_ENOTNC4) ERR;
if (nc_def_compound(ncid, 1, NAME_DUMB, NULL) != NC_ENOTNC4) ERR;
if (nc_insert_compound(ncid, 1, NAME_DUMB, 1, 1) != NC_ENOTNC4) ERR;
if (nc_insert_array_compound(ncid, 1, NAME_DUMB, 1, 1, 1, NULL) != NC_ENOTNC4) ERR;
if (nc_inq_compound_field(ncid, 1, 1, NULL, NULL, NULL, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_inq_compound_fieldindex(ncid, 1, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_def_opaque(ncid, 1, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_def_vlen(ncid, NULL, 1, NULL) != NC_ENOTNC4) ERR;
if (nc_def_enum(ncid, 1, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_inq_enum_ident(ncid, 1, 1, NULL) != NC_ENOTNC4) ERR;
if (nc_inq_enum_member(ncid, 1, 1, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_insert_enum(ncid, 1, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_put_vlen_element(ncid, 1, NULL, 1, NULL) != NC_ENOTNC4) ERR;
if (nc_get_vlen_element(ncid, 1, NULL, NULL, NULL) != NC_ENOTNC4) ERR;
if (nc_set_var_chunk_cache(ncid, 1, 1, 1, 1.0) != NC_ENOTNC4) ERR;
if (nc_get_var_chunk_cache(ncid, 1, NULL, NULL, NULL) != NC_ENOTNC4) ERR;
/* Abort is the same as nc_close, since HDF4 is read-only.) */
if (nc_abort(ncid)) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -1,9 +1,10 @@
/* Copyright 2018, UCAR/Unidata. See netcdf/COPYRIGHT file for copying
* and redistribution conditions. */
/**
* @file
* This header file contains the prototypes for the HDF4 versions
* of the netCDF functions.
* @file @internal This header file contains the prototypes for the
* HDF4 versions of the netCDF functions. This is part of the HDF4
* dispatch layer and this header should not be included by any file
* outside the libhdf4 directory.
*
* Ed Hartnett
*/
@ -11,263 +12,48 @@
#define _HDF4DISPATCH_H
#include "config.h"
#include <stddef.h> /* size_t, ptrdiff_t */
#include <errno.h> /* netcdf functions sometimes return system errors */
#include "ncdispatch.h"
/** This is the max size of an SD dataset name in HDF4 (from HDF4
* documentation).*/
#define NC_MAX_HDF4_NAME 64
/** This is the max number of dimensions for a HDF4 SD dataset (from
* HDF4 documentation). */
#define NC_MAX_HDF4_DIMS 32
/* Stuff below is for hdf4 files. */
typedef struct NC_VAR_HDF4_INFO
{
int sdsid;
int hdf4_data_type;
} NC_VAR_HDF4_INFO_T;
typedef struct NC_HDF4_FILE_INFO
{
int sdid;
} NC_HDF4_FILE_INFO_T;
#if defined(__cplusplus)
extern "C" {
#endif
extern int
HDF4_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
int useparallel, void* parameters,
NC_Dispatch*, NC*);
extern int
NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp,
int use_parallel, void* parameters, NC_Dispatch*, NC*);
extern int
HDF4_open(const char *path, int mode,
int basepe, size_t *chunksizehintp,
int use_parallel, void* parameters,
NC_Dispatch*, NC*);
extern int
NC_HDF4_close(int ncid);
extern int
HDF4_redef(int ncid);
extern int
NC_HDF4_inq_format(int ncid, int *formatp);
extern int
HDF4__enddef(int ncid, size_t h_minfree, size_t v_align,
size_t v_minfree, size_t r_align);
extern int
NC_HDF4_inq_format_extended(int ncid, int *formatp, int *modep);
extern int
HDF4_sync(int ncid);
extern int
HDF4_abort(int ncid);
extern int
HDF4_close(int ncid);
extern int
HDF4_set_fill(int ncid, int fillmode, int *old_modep);
extern int
HDF4_set_base_pe(int ncid, int pe);
extern int
HDF4_inq_base_pe(int ncid, int *pe);
extern int
HDF4_inq_format(int ncid, int *formatp);
extern int
HDF4_inq_format_extended(int ncid, int *formatp, int *modep);
extern int
HDF4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp);
extern int
HDF4_inq_type(int, nc_type, char *, size_t *);
/* Begin _dim */
extern int
HDF4_def_dim(int ncid, const char *name, size_t len, int *idp);
extern int
HDF4_inq_dimid(int ncid, const char *name, int *idp);
extern int
HDF4_inq_dim(int ncid, int dimid, char *name, size_t *lenp);
extern int
HDF4_inq_unlimdim(int ncid, int *unlimdimidp);
extern int
HDF4_rename_dim(int ncid, int dimid, const char *name);
/* End _dim */
/* Begin _att */
extern int
HDF4_inq_att(int ncid, int varid, const char *name,
nc_type *xtypep, size_t *lenp);
extern int
HDF4_inq_attid(int ncid, int varid, const char *name, int *idp);
extern int
HDF4_inq_attname(int ncid, int varid, int attnum, char *name);
extern int
HDF4_rename_att(int ncid, int varid, const char *name, const char *newname);
extern int
HDF4_del_att(int ncid, int varid, const char*);
/* End _att */
/* Begin {put,get}_att */
extern int
HDF4_get_att(int ncid, int varid, const char *name, void *value, nc_type);
extern int
HDF4_put_att(int ncid, int varid, const char *name, nc_type datatype,
size_t len, const void *value, nc_type);
/* End {put,get}_att */
/* Begin _var */
extern int
HDF4_def_var(int ncid, const char *name,
nc_type xtype, int ndims, const int *dimidsp, int *varidp);
extern int
HDF4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
int *ndimsp, int *dimidsp, int *nattsp,
int *shufflep, int *deflatep, int *deflate_levelp,
int *fletcher32p, int *contiguousp, size_t *chunksizesp,
int *no_fill, void *fill_valuep, int *endiannessp,
unsigned int* idp, size_t* nparamsp, unsigned int* params
);
extern int
HDF4_inq_varid(int ncid, const char *name, int *varidp);
extern int
HDF4_rename_var(int ncid, int varid, const char *name);
extern int
HDF4_put_vara(int ncid, int varid,
const size_t *start, const size_t *count,
const void *value, nc_type);
extern int
HDF4_get_vara(int ncid, int varid,
const size_t *start, const size_t *count,
void *value, nc_type);
/* End _var */
/* netCDF4 API only */
extern int
HDF4_var_par_access(int, int, int);
extern int
HDF4_inq_ncid(int, const char *, int *);
extern int
HDF4_inq_grps(int, int *, int *);
extern int
HDF4_inq_grpname(int, char *);
extern int
HDF4_inq_grpname_full(int, size_t *, char *);
extern int
HDF4_inq_grp_parent(int, int *);
extern int
HDF4_inq_grp_full_ncid(int, const char *, int *);
extern int
HDF4_inq_varids(int, int * nvars, int *);
extern int
HDF4_inq_dimids(int, int * ndims, int *, int);
extern int
HDF4_inq_typeids(int, int * ntypes, int *);
extern int
HDF4_inq_type_equal(int, nc_type, int, nc_type, int *);
extern int
HDF4_def_grp(int, const char *, int *);
extern int
HDF4_rename_grp(int, const char *);
extern int
HDF4_inq_user_type(int, nc_type, char *, size_t *, nc_type *,
size_t *, int *);
extern int
HDF4_def_compound(int, size_t, const char *, nc_type *);
extern int
HDF4_insert_compound(int, nc_type, const char *, size_t, nc_type);
extern int
HDF4_insert_array_compound(int, nc_type, const char *, size_t,
nc_type, int, const int *);
extern int
HDF4_inq_typeid(int, const char *, nc_type *);
extern int
HDF4_inq_compound_field(int, nc_type, int, char *, size_t *,
nc_type *, int *, int *);
extern int
HDF4_inq_compound_fieldindex(int, nc_type, const char *, int *);
extern int
HDF4_def_vlen(int, const char *, nc_type base_typeid, nc_type *);
extern int
HDF4_put_vlen_element(int, int, void *, size_t, const void *);
extern int
HDF4_get_vlen_element(int, int, const void *, size_t *, void *);
extern int
HDF4_def_enum(int, nc_type, const char *, nc_type *);
extern int
HDF4_insert_enum(int, nc_type, const char *, const void *);
extern int
HDF4_inq_enum_member(int, nc_type, int, char *, void *);
extern int
HDF4_inq_enum_ident(int, nc_type, long long, char *);
extern int
HDF4_def_opaque(int, size_t, const char *, nc_type *);
extern int
HDF4_def_var_deflate(int, int, int, int, int);
extern int
HDF4_def_var_fletcher32(int, int, int);
extern int
HDF4_def_var_chunking(int, int, int, const size_t *);
extern int
HDF4_def_var_fill(int, int, int, const void *);
extern int
HDF4_def_var_endian(int, int, int);
extern int
HDF4_def_var_filter(int, int, unsigned int, size_t, const unsigned int*);
extern int
HDF4_set_var_chunk_cache(int, int, size_t, size_t, float);
extern int
HDF4_get_var_chunk_cache(int, int, size_t *, size_t *, float *);
extern int
HDF4_inq_unlimdims(int, int *, int *);
extern int
HDF4_show_metadata(int);
extern int
HDF4_initialize(void);
extern int
NC_HDF4_get_vara(int ncid, int varid, const size_t *start, const size_t *count,
void *value, nc_type);
#if defined(__cplusplus)
}

View File

@ -1,9 +1,8 @@
/** \file
This header file contains the definitions of structs used to hold
netCDF file metadata in memory.
Copyright 2005-2011 University Corporation for Atmospheric
Research/Unidata.
/* Copyright 2005-2018 University Corporation for Atmospheric
Research/Unidata. */
/**
* @file This header file contains the definitions of structs used to
* hold netCDF file metadata in memory.
*/
#ifndef _NC4INTERNAL_
@ -30,10 +29,6 @@
/* Always needed */
#include "nc.h"
#ifdef USE_HDF4
#include <mfhdf.h>
#endif
#define FILE_ID_MASK (0xffff0000)
#define GRP_ID_MASK (0x0000ffff)
#define ID_SHIFT (16)
@ -200,9 +195,7 @@ typedef struct NC_VAR_INFO
size_t chunk_cache_size, chunk_cache_nelems;
float chunk_cache_preemption;
#ifdef USE_HDF4
/* Stuff below is for hdf4 files. */
int sdsid;
int hdf4_data_type;
void *format_var_info; /* Pointer to any binary format info. */
#endif /* USE_HDF4 */
/* Stuff for arbitrary filters */
unsigned int filterid;
@ -330,8 +323,7 @@ typedef struct NC_HDF5_FILE_INFO
NClist* alltypes;
NClist* allgroups; /* including root group */
#ifdef USE_HDF4
nc_bool_t hdf4; /* True for HDF4 file */
int sdid;
void *format_file_info;
#endif /* USE_HDF4 */
struct NCFILEINFO* fileinfo;
} NC_HDF5_FILE_INFO_T;

View File

@ -413,4 +413,65 @@ NCDISPATCH_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
extern int
NCDISPATCH_get_att(int ncid, int varid, const char* name, void* value, nc_type t);
/* Read-only dispatch layers can use these functions to return
* NC_EPERM to all attempts to modify a file. */
int NC_RO_create(const char *path, int cmode, size_t initialsz, int basepe,
size_t *chunksizehintp, int useparallel, void* parameters,
NC_Dispatch*, NC*);
int NC_RO_redef(int ncid);
int NC_RO__enddef(int ncid, size_t h_minfree, size_t v_align, size_t v_minfree,
size_t r_align);
int NC_RO_sync(int ncid);
int NC_RO_def_var_fill(int, int, int, const void *);
int NC_RO_rename_att(int ncid, int varid, const char *name,
const char *newname);
int NC_RO_del_att(int ncid, int varid, const char*);
int NC_RO_put_att(int ncid, int varid, const char *name, nc_type datatype,
size_t len, const void *value, nc_type);
int NC_RO_def_var(int ncid, const char *name,
nc_type xtype, int ndims, const int *dimidsp, int *varidp);
int NC_RO_rename_var(int ncid, int varid, const char *name);
int NC_RO_put_vara(int ncid, int varid,
const size_t *start, const size_t *count,
const void *value, nc_type);
int NC_RO_def_dim(int ncid, const char *name, size_t len, int *idp);
int NC_RO_rename_dim(int ncid, int dimid, const char *name);
int NC_RO_set_fill(int ncid, int fillmode, int *old_modep);
/* These functions are for dispatch layers that don't implement these
* legacy functions. They return NC_ENOTNC3. */
int NC_NOTNC3_set_base_pe(int ncid, int pe);
int NC_NOTNC3_inq_base_pe(int ncid, int *pe);
/* These functions are for dispatch layers that don't implement the
* enhanced model. They return NC_ENOTNC4. */
int NC_NOTNC4_def_var_filter(int, int, unsigned int, size_t,
const unsigned int*);
int NC_NOTNC4_def_grp(int, const char *, int *);
int NC_NOTNC4_rename_grp(int, const char *);
int NC_NOTNC4_def_compound(int, size_t, const char *, nc_type *);
int NC_NOTNC4_insert_compound(int, nc_type, const char *, size_t, nc_type);
int NC_NOTNC4_insert_array_compound(int, nc_type, const char *, size_t,
nc_type, int, const int *);
int NC_NOTNC4_inq_typeid(int, const char *, nc_type *);
int NC_NOTNC4_inq_compound_field(int, nc_type, int, char *, size_t *,
nc_type *, int *, int *);
int NC_NOTNC4_inq_compound_fieldindex(int, nc_type, const char *, int *);
int NC_NOTNC4_def_vlen(int, const char *, nc_type base_typeid, nc_type *);
int NC_NOTNC4_put_vlen_element(int, int, void *, size_t, const void *);
int NC_NOTNC4_get_vlen_element(int, int, const void *, size_t *, void *);
int NC_NOTNC4_def_enum(int, nc_type, const char *, nc_type *);
int NC_NOTNC4_insert_enum(int, nc_type, const char *, const void *);
int NC_NOTNC4_inq_enum_member(int, nc_type, int, char *, void *);
int NC_NOTNC4_inq_enum_ident(int, nc_type, long long, char *);
int NC_NOTNC4_def_opaque(int, size_t, const char *, nc_type *);
int NC_NOTNC4_def_var_deflate(int, int, int, int, int);
int NC_NOTNC4_def_var_fletcher32(int, int, int);
int NC_NOTNC4_def_var_chunking(int, int, int, const size_t *);
int NC_NOTNC4_def_var_endian(int, int, int);
int NC_NOTNC4_set_var_chunk_cache(int, int, size_t, size_t, float);
int NC_NOTNC4_get_var_chunk_cache(int, int, size_t *, size_t *, float *);
int NC_NOTNC4_var_par_access(int, int, int);
#endif /* _DISPATCH_H */

View File

@ -1,4 +1,4 @@
SET(libdispatch_SOURCES dparallel.c dcopy.c dfile.c ddim.c datt.c dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c dvarinq.c ddispatch.c nclog.c dstring.c dutf8.c dinternal.c doffsets.c ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c utf8proc.h utf8proc.c dwinpath.c dutil.c drc.c dauth.c crc32.c)
SET(libdispatch_SOURCES dparallel.c dcopy.c dfile.c ddim.c datt.c dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c dvarinq.c ddispatch.c nclog.c dstring.c dutf8.c dinternal.c doffsets.c ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c utf8proc.h utf8proc.c dwinpath.c dutil.c drc.c dauth.c dreadonly.c dnotnc4.c dnotnc3.c crc32.c)
IF(USE_NETCDF4)
SET(libdispatch_SOURCES ${libdispatch_SOURCES} dgroup.c dvlen.c dcompound.c dtype.c denum.c dopaque.c ncaux.c dfilter.c)

View File

@ -17,10 +17,9 @@ libdispatch_la_CPPFLAGS = ${AM_CPPFLAGS}
# The source files.
libdispatch_la_SOURCES = dparallel.c dcopy.c dfile.c ddim.c datt.c \
dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c \
dvarinq.c dinternal.c ddispatch.c dutf8.c \
nclog.c dstring.c \
ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c \
nc.c nclistmgr.c drc.c dauth.c doffsets.c dwinpath.c dutil.c \
dvarinq.c dinternal.c ddispatch.c dutf8.c nclog.c dstring.c ncuri.c \
nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c drc.c \
dauth.c doffsets.c dwinpath.c dutil.c dreadonly.c dnotnc4.c dnotnc3.c \
crc32.c crc32.h
# Add the utf8 codebase

41
libdispatch/dnotnc3.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file @internal This file handles the *_base_pe()
* functions for dispatch layers that need to return ::NC_ENOTNC3.
*
* @author Ed Hartnett
*/
#include "nc4dispatch.h"
/**
* @internal This function only does anything for netcdf-3 files.
*
* @param ncid Ignored.
* @param pe Ignored.
*
* @return ::NC_ENOTNC3 Not a netCDF classic format file.
* @author Ed Hartnett
*/
int
NC_NOTNC3_set_base_pe(int ncid, int pe)
{
return NC_ENOTNC3;
}
/**
* @internal This function only does anything for netcdf-3 files.
*
* @param ncid Ignored.
* @param pe Ignored.
*
* @return ::NC_ENOTNC3 Not a netCDF classic format file.
* @author Ed Hartnett
*/
int
NC_NOTNC3_inq_base_pe(int ncid, int *pe)
{
return NC_ENOTNC3;
}

432
libdispatch/dnotnc4.c Normal file
View File

@ -0,0 +1,432 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file
* @internal This file contains functions that return NC_ENOTNC4, for
* dispatch layers that only implement the classic model.
*
* @author Ed Hartnett
*/
#include "ncdispatch.h"
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param id Ignored.
* @param nparams Ignored.
* @param parms Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams,
const unsigned int* parms)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param parent_ncid Ignored.
* @param name Ignored.
* @param new_ncid Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_grp(int parent_ncid, const char *name, int *new_ncid)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param grpid Ignored.
* @param name Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_rename_grp(int grpid, const char *name)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param size Ignored.
* @param name Ignored.
* @param typeidp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param name Ignored.
* @param offset Ignored.
* @param field Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_insert_compound(int ncid, nc_type typeid1, const char *name, size_t offset,
nc_type field_typeid)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param name Ignored.
* @param offset Ignored.
* @param field Ignored.
* @param ndims Ignored.
* @param dim Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
extern int
NC_NOTNC4_insert_array_compound(int ncid, int typeid1, const char *name,
size_t offset, nc_type field_typeid,
int ndims, const int *dim_sizesp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param fieldid Ignored.
* @param name Ignored.
* @param offsetp Ignored.
* @param field Ignored.
* @param ndimsp Ignored.
* @param dim Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_inq_compound_field(int ncid, nc_type typeid1, int fieldid, char *name,
size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
int *dim_sizesp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param name Ignored.
* @param fieldidp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_inq_compound_fieldindex(int ncid, nc_type typeid1, const char *name, int *fieldidp)
{
return NC_ENOTNC4;
}
/* Opaque type. */
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param datum Ignored.
* @param name Ignored.
* @param typeidp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_opaque(int ncid, size_t datum_size, const char *name,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param name Ignored.
* @param base_typeid Ignored.
* @param typeidp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_vlen(int ncid, const char *name, nc_type base_typeid,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param base_typeid Ignored.
* @param name Ignored.
* @param typeidp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_enum(int ncid, nc_type base_typeid, const char *name,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param xtype Ignored.
* @param value Ignored.
* @param identifier Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param idx Ignored.
* @param identifier Ignored.
* @param value Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_inq_enum_member(int ncid, nc_type typeid1, int idx, char *identifier,
void *value)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param identifier Ignored.
* @param value Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_insert_enum(int ncid, nc_type typeid1, const char *identifier,
const void *value)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param vlen_element Ignored.
* @param len Ignored.
* @param data Ignored.
*
* @return ::NC_NOERR No error.
* @author Ed Hartnett
*/
int
NC_NOTNC4_put_vlen_element(int ncid, int typeid1, void *vlen_element,
size_t len, const void *data)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param typeid1 Ignored.
* @param vlen_element Ignored.
* @param len Ignored.
* @param data Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_get_vlen_element(int ncid, int typeid1, const void *vlen_element,
size_t *len, void *data)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param size Ignored.
* @param nelems Ignored.
* @param preemption Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems,
float preemption)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param sizep Ignored.
* @param nelemsp Ignored.
* @param preemptionp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_get_var_chunk_cache(int ncid, int varid, size_t *sizep,
size_t *nelemsp, float *preemptionp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param shuffle Ignored.
* @param deflate Ignored.
* @param deflate_level Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett, Dennis Heimbigner
*/
int
NC_NOTNC4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
int deflate_level)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param fletcher32 Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett, Dennis Heimbigner
*/
int
NC_NOTNC4_def_var_fletcher32(int ncid, int varid, int fletcher32)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param contiguous Ignored.
* @param chunksizesp Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett, Dennis Heimbigner
*/
int
NC_NOTNC4_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp)
{
return NC_EPERM;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param endianness Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett
*/
int
NC_NOTNC4_def_var_endian(int ncid, int varid, int endianness)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for classic model.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param par_access Ignored.
*
* @return ::NC_ENOTNC4 Not allowed for classic model.
* @author Ed Hartnett, Dennis Heimbigner
*/
int
NC_NOTNC4_var_par_access(int ncid, int varid, int par_access)
{
return NC_ENOTNC4;
}

261
libdispatch/dreadonly.c Normal file
View File

@ -0,0 +1,261 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file
* @internal This file contains functions that return NC_EPERM, for
* read-only dispatch layers.
*
* @author Ed Hartnett
*/
#include "nc.h"
#include "ncdispatch.h"
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param name Ignored.
* @param newname Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_rename_att(int ncid, int varid, const char *name, const char *newname)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param name Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_del_att(int ncid, int varid, const char *name)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param name Ignored.
* @param file_type Ignored.
* @param len Ignored.
* @param data Ignored.
* @param memtype Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_put_att(int ncid, int varid, const char *name, nc_type file_type,
size_t len, const void *data, nc_type mem_type)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param name Ignored.
* @param len Ignored.
* @param idp Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_def_dim(int ncid, const char *name, size_t len, int *idp)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param dimid Ignored.
* @param name Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_rename_dim(int ncid, int dimid, const char *name)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param name Ignored.
* @param xtype Ignored.
* @param ndims Ignored.
* @param dimidsp Ignored.
* @param varidp Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_def_var(int ncid, const char *name, nc_type xtype,
int ndims, const int *dimidsp, int *varidp)
{
return NC_EPERM;
}
/**
* @internal Not allowed for classic model access.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param no_fill Ignored.
* @param fill_value Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid File ID.
* @param varid Variable ID
* @param name New name of the variable.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_rename_var(int ncid, int varid, const char *name)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param startp Array of start indicies.
* @param countp Array of counts.
* @param op pointer that gets the data.
* @param memtype The type of these data in memory.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_put_vara(int ncid, int varid, const size_t *startp,
const size_t *countp, const void *op, int memtype)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid File and group ID.
* @param fillmode File mode.
* @param old_modep Pointer that gets old mode. Ignored if NULL.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_set_fill(int ncid, int fillmode, int *old_modep)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_redef(int ncid)
{
return NC_EPERM;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
* @param h_minfree Ignored.
* @param v_align Ignored.
* @param v_minfree Ignored.
* @param r_align Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO__enddef(int ncid, size_t h_minfree, size_t v_align,
size_t v_minfree, size_t r_align)
{
return NC_NOERR;
}
/**
* @internal Not allowed for read-only access.
*
* @param ncid Ignored.
*
* @return ::NC_EPERM Not allowed.
* @author Ed Hartnett
*/
int
NC_RO_sync(int ncid)
{
return NC_NOERR;
}
/**
* @internal Not allowed for read-only access.
*
* @param path Ignored.
* @param cmode Ignored.
* @param initialsz Ignored.
* @param basepe Ignored.
* @param chunksizehintp Ignored.
* @param use_parallel Ignored.
* @param parameters Ignored.
* @param dispatch Ignored.
* @param nc_file Ignored.
*
* @return ::NC_EPERM Cannot create files.
* @author Ed Hartnett
*/
int
NC_RO_create(const char* path, int cmode, size_t initialsz, int basepe,
size_t *chunksizehintp, int use_parallel, void *parameters,
NC_Dispatch *dispatch, NC* nc_file)
{
return NC_EPERM;
}

View File

@ -11,7 +11,6 @@
#include <stdlib.h>
#include "hdf4dispatch.h"
#include "nc4dispatch.h"
#include "nc.h"
/* This is the dispatch object that holds pointers to all the
* functions that make up the HDF4 dispatch interface. */
@ -19,42 +18,42 @@ static NC_Dispatch HDF4_dispatcher = {
NC_FORMATX_NC_HDF4,
HDF4_create,
HDF4_open,
NC_RO_create,
NC_HDF4_open,
HDF4_redef,
HDF4__enddef,
HDF4_sync,
HDF4_abort,
HDF4_close,
HDF4_set_fill,
HDF4_inq_base_pe,
HDF4_set_base_pe,
HDF4_inq_format,
HDF4_inq_format_extended,
NC_RO_redef,
NC_RO__enddef,
NC_RO_sync,
NC_HDF4_close,
NC_HDF4_close,
NC_RO_set_fill,
NC_NOTNC3_inq_base_pe,
NC_NOTNC3_set_base_pe,
NC_HDF4_inq_format,
NC_HDF4_inq_format_extended,
NC4_inq,
NC4_inq_type,
HDF4_def_dim,
NC_RO_def_dim,
NC4_inq_dimid,
NC4_inq_dim,
NC4_inq_unlimdim,
HDF4_rename_dim,
NC_RO_rename_dim,
NC4_inq_att,
NC4_inq_attid,
NC4_inq_attname,
HDF4_rename_att,
HDF4_del_att,
NC_RO_rename_att,
NC_RO_del_att,
NC4_get_att,
HDF4_put_att,
NC_RO_put_att,
HDF4_def_var,
NC_RO_def_var,
NC4_inq_varid,
HDF4_rename_var,
HDF4_get_vara,
HDF4_put_vara,
NC_RO_rename_var,
NC_HDF4_get_vara,
NC_RO_put_vara,
NCDEFAULT_get_vars,
NCDEFAULT_put_vars,
NCDEFAULT_get_varm,
@ -62,8 +61,8 @@ NCDEFAULT_put_varm,
NC4_inq_var_all,
HDF4_var_par_access,
HDF4_def_var_fill,
NC_NOTNC4_var_par_access,
NC_RO_def_var_fill,
NC4_show_metadata,
NC4_inq_unlimdims,
@ -78,32 +77,31 @@ NC4_inq_varids,
NC4_inq_dimids,
NC4_inq_typeids,
NC4_inq_type_equal,
HDF4_def_grp,
HDF4_rename_grp,
NC_NOTNC4_def_grp,
NC_NOTNC4_rename_grp,
NC4_inq_user_type,
NC4_inq_typeid,
HDF4_def_compound,
HDF4_insert_compound,
HDF4_insert_array_compound,
HDF4_inq_compound_field,
HDF4_inq_compound_fieldindex,
HDF4_def_vlen,
HDF4_put_vlen_element,
HDF4_get_vlen_element,
HDF4_def_enum,
HDF4_insert_enum,
HDF4_inq_enum_member,
HDF4_inq_enum_ident,
HDF4_def_opaque,
HDF4_def_var_deflate,
HDF4_def_var_fletcher32,
HDF4_def_var_chunking,
HDF4_def_var_endian,
HDF4_def_var_filter,
HDF4_set_var_chunk_cache,
HDF4_get_var_chunk_cache,
NC_NOTNC4_def_compound,
NC_NOTNC4_insert_compound,
NC_NOTNC4_insert_array_compound,
NC_NOTNC4_inq_compound_field,
NC_NOTNC4_inq_compound_fieldindex,
NC_NOTNC4_def_vlen,
NC_NOTNC4_put_vlen_element,
NC_NOTNC4_get_vlen_element,
NC_NOTNC4_def_enum,
NC_NOTNC4_insert_enum,
NC_NOTNC4_inq_enum_member,
NC_NOTNC4_inq_enum_ident,
NC_NOTNC4_def_opaque,
NC_NOTNC4_def_var_deflate,
NC_NOTNC4_def_var_fletcher32,
NC_NOTNC4_def_var_chunking,
NC_NOTNC4_def_var_endian,
NC_NOTNC4_def_var_filter,
NC_NOTNC4_set_var_chunk_cache,
NC_NOTNC4_get_var_chunk_cache
};
NC_Dispatch* HDF4_dispatch_table = NULL;
@ -115,7 +113,7 @@ NC_Dispatch* HDF4_dispatch_table = NULL;
* @author Ed Hartnett
*/
int
HDF4_initialize(void)
NC_HDF4_initialize(void)
{
HDF4_dispatch_table = &HDF4_dispatcher;
return NC_NOERR;
@ -128,7 +126,7 @@ HDF4_initialize(void)
* @author Ed Hartnett
*/
int
HDF4_finalize(void)
NC_HDF4_finalize(void)
{
return NC_NOERR;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +1,15 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file @internal This file handles the (useless) *_base_pe()
* functions, and the inq_format functions for the HDF4 dispatch
* layer.
* @file @internal HDF4 functions.
*
* @author Ed Hartnett
*/
*/
#include "config.h"
#include "nc4internal.h"
#include "nc4dispatch.h"
/**
* @internal This function only does anything for netcdf-3 files.
*
* @param ncid File ID (ignored).
* @param pe Processor element (ignored).
*
* @return ::NC_ENOTNC3 Not a netCDF classic format file.
* @author Ed Hartnett
*/
int
HDF4_set_base_pe(int ncid, int pe)
{
return NC_ENOTNC3;
}
/**
* @internal This function only does anything for netcdf-3 files.
*
* @param ncid File ID (ignored).
* @param pe Pointer to processor element. Ignored if NULL. Gets a 0
* if present.
*
* @return ::NC_ENOTNC3 Not a netCDF classic format file.
* @author Ed Hartnett
*/
int
HDF4_inq_base_pe(int ncid, int *pe)
{
return NC_ENOTNC3;
}
#include "hdf4dispatch.h"
#include <mfhdf.h>
/**
* @internal Get the format (i.e. NC_FORMAT_NC_HDF4) of an open HDF4
@ -54,22 +23,11 @@ HDF4_inq_base_pe(int ncid, int *pe)
* @author Ed Hartnett
*/
int
HDF4_inq_format(int ncid, int *formatp)
NC_HDF4_inq_format(int ncid, int *formatp)
{
NC *nc;
NC_HDF5_FILE_INFO_T* nc4_info;
LOG((2, "nc_inq_format: ncid 0x%x", ncid));
if (!formatp)
return NC_NOERR;
/* Find the file metadata. */
if (!(nc = nc4_find_nc_file(ncid, &nc4_info)))
return NC_EBADID;
/* HDF4 is the format. */
*formatp = NC_FORMATX_NC_HDF4;
if (formatp)
*formatp = NC_FORMATX_NC_HDF4;
return NC_NOERR;
}
@ -78,10 +36,8 @@ HDF4_inq_format(int ncid, int *formatp)
* @internal Return the extended format (i.e. the dispatch model),
* plus the mode associated with an open file.
*
* @param ncid File ID (ignored).
* @param formatp a pointer that gets the extended format. Note that
* this is not the same as the format provided by nc_inq_format(). The
* extended foramt indicates the dispatch layer model. HDF4 files
* @param ncid File ID.
* @param formatp a pointer that gets the extended format. HDF4 files
* will always get NC_FORMATX_NC_HDF4.
* @param modep a pointer that gets the open/create mode associated with
* this file. Ignored if NULL.
@ -91,15 +47,14 @@ HDF4_inq_format(int ncid, int *formatp)
* @author Ed Hartnett
*/
int
HDF4_inq_format_extended(int ncid, int *formatp, int *modep)
NC_HDF4_inq_format_extended(int ncid, int *formatp, int *modep)
{
NC *nc;
NC_HDF5_FILE_INFO_T* h5;
LOG((2, "%s: ncid 0x%x", __func__, ncid));
/* Find the file metadata. */
if (!(nc = nc4_find_nc_file(ncid,&h5)))
if (!(nc = nc4_find_nc_file(ncid, &h5)))
return NC_EBADID;
if (modep)

View File

@ -7,343 +7,11 @@
* @author Ed Hartnett
*/
#include "config.h"
#include <nc4internal.h>
#include "hdf4dispatch.h"
#include "nc4dispatch.h"
/**
* @internal Set chunk cache size for a variable. This is the internal
* function called by nc_set_var_chunk_cache().
*
* @param ncid File ID.
* @param varid Variable ID.
* @param size Size in bytes to set cache.
* @param nelems Number of elements in cache.
* @param preemption Controls cache swapping.
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ESTRICTNC3 Attempting netcdf-4 operation on strict nc3 netcdf-4 file.
* @returns ::NC_EINVAL Invalid input.
* @returns ::NC_EHDFERR HDF5 error.
* @author Ed Hartnett
*/
int
HDF4_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems,
float preemption)
{
return NC_ENOTNC4;
}
/**
* @internal This is called by nc_get_var_chunk_cache(). Get chunk
* cache size for a variable.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param sizep Gets size in bytes of cache.
* @param nelemsp Gets number of element slots in cache.
* @param preemptionp Gets cache swapping setting.
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Not a netCDF-4 file.
* @author Ed Hartnett
*/
int
HDF4_get_var_chunk_cache(int ncid, int varid, size_t *sizep,
size_t *nelemsp, float *preemptionp)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for HDF4.
*
* @param ncid File ID.
* @param name Name.
* @param xtype Type.
* @param ndims Number of dims.
* @param dimidsp Array of dim IDs.
* @param varidp Gets the var ID.
*
* @returns ::NC_EPERM Not allowed for HDF4.
* @author Ed Hartnett
*/
int
HDF4_def_var(int ncid, const char *name, nc_type xtype,
int ndims, const int *dimidsp, int *varidp)
{
return NC_EPERM;
}
/**
* @internal Set compression settings on a variable. This is called by
* nc_def_var_deflate().
*
* @param ncid File ID.
* @param varid Variable ID.
* @param shuffle True to turn on the shuffle filter.
* @param deflate True to turn on deflation.
* @param deflate_level A number between 0 (no compression) and 9
* (maximum compression).
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Attempting netcdf-4 operation on file that is
* not netCDF-4/HDF5.
* @returns ::NC_ELATEDEF Too late to change settings for this variable.
* @returns ::NC_ENOTINDEFINE Not in define mode.
* @returns ::NC_EINVAL Invalid input
* @author Ed Hartnett, Dennis Heimbigner
*/
int
HDF4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
int deflate_level)
{
return NC_EPERM;
}
/**
* @internal Set checksum on a variable. This is called by
* nc_def_var_fletcher32().
*
* @param ncid File ID.
* @param varid Variable ID.
* @param fletcher32 Pointer to fletcher32 setting.
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Attempting netcdf-4 operation on file that is
* not netCDF-4/HDF5.
* @returns ::NC_ELATEDEF Too late to change settings for this variable.
* @returns ::NC_ENOTINDEFINE Not in define mode.
* @returns ::NC_EINVAL Invalid input
* @author Ed Hartnett, Dennis Heimbigner
*/
int
HDF4_def_var_fletcher32(int ncid, int varid, int fletcher32)
{
return NC_ENOTNC4;
}
/**
* @internal Define chunking stuff for a var. This is called by
* nc_def_var_chunking(). Chunking is required in any dataset with one
* or more unlimited dimensions in HDF5, or any dataset using a
* filter.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param contiguous Pointer to contiguous setting.
* @param chunksizesp Array of chunksizes.
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Attempting netcdf-4 operation on file that is
* not netCDF-4/HDF5.
* @returns ::NC_ELATEDEF Too late to change settings for this variable.
* @returns ::NC_ENOTINDEFINE Not in define mode.
* @returns ::NC_EINVAL Invalid input
* @returns ::NC_EBADCHUNK Bad chunksize.
* @author Ed Hartnett, Dennis Heimbigner
*/
int
HDF4_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp)
{
return NC_EPERM;
}
/**
* @internal This functions sets fill value and no_fill mode for a
* netCDF-4 variable. It is called by nc_def_var_fill().
*
* @note All pointer parameters may be NULL, in which case they are ignored.
* @param ncid File ID.
* @param varid Variable ID.
* @param no_fill No_fill setting.
* @param fill_value Pointer to fill value.
*
* @returns ::NC_NOERR for success
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Attempting netcdf-4 operation on file that is
* not netCDF-4/HDF5.
* @returns ::NC_ESTRICTNC3 Attempting netcdf-4 operation on strict nc3
* netcdf-4 file.
* @returns ::NC_ELATEDEF Too late to change settings for this variable.
* @returns ::NC_ENOTINDEFINE Not in define mode.
* @returns ::NC_EPERM File is read only.
* @returns ::NC_EINVAL Invalid input
* @author Ed Hartnett
*/
int
HDF4_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
{
return NC_ENOTNC4;
}
/**
* @internal This functions sets endianness for a netCDF-4
* variable. Called by nc_def_var_endian().
*
* @note All pointer parameters may be NULL, in which case they are ignored.
* @param ncid File ID.
* @param varid Variable ID.
* @param endianness Endianness setting.
*
* @returns ::NC_NOERR for success
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Attempting netcdf-4 operation on file that is
* not netCDF-4/HDF5.
* @returns ::NC_ESTRICTNC3 Attempting netcdf-4 operation on strict nc3
* netcdf-4 file.
* @returns ::NC_ELATEDEF Too late to change settings for this variable.
* @returns ::NC_ENOTINDEFINE Not in define mode.
* @returns ::NC_EPERM File is read only.
* @returns ::NC_EINVAL Invalid input
* @author Ed Hartnett
*/
int
HDF4_def_var_endian(int ncid, int varid, int endianness)
{
return NC_ENOTNC4;
}
/**
* @internal Define filter settings. Called by nc_def_var_filter().
*
* @param ncid File ID.
* @param varid Variable ID.
* @param id Filter ID
* @param nparams Number of parameters for filter.
* @param parms Filter parameters.
*
* @returns ::NC_NOERR for success
* @returns ::NC_EBADID Bad ncid.
* @returns ::NC_ENOTVAR Invalid variable ID.
* @returns ::NC_ENOTNC4 Attempting netcdf-4 operation on file that is
* not netCDF-4/HDF5.
* @returns ::NC_ELATEDEF Too late to change settings for this variable.
* @returns ::NC_EFILTER Filter error.
* @returns ::NC_EINVAL Invalid input
* @author Dennis Heimbigner
*/
int
HDF4_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams,
const unsigned int* parms)
{
return NC_ENOTNC4;
}
/**
* @internal Not allowed for HDF4.
*
* @param ncid File ID.
* @param varid Variable ID
* @param name New name of the variable.
*
* @returns ::NC_EPERM Not allowed for HDF4.
* @author Ed Hartnett
*/
int
HDF4_rename_var(int ncid, int varid, const char *name)
{
return NC_EPERM;
}
/**
* @internal
*
* This function will change the parallel access of a variable from
* independent to collective.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param par_access NC_COLLECTIVE or NC_INDEPENDENT.
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Invalid ncid passed.
* @returns ::NC_ENOTVAR Invalid varid passed.
* @returns ::NC_ENOPAR LFile was not opened with nc_open_par/nc_create_var.
* @returns ::NC_EINVAL Invalid par_access specified.
* @returns ::NC_NOERR for success
* @author Ed Hartnett, Dennis Heimbigner
*/
int
HDF4_var_par_access(int ncid, int varid, int par_access)
{
return NC_ENOTNC4;
}
/**
* @internal Get data from an HDF4 SD dataset.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param startp Array of start indicies.
* @param countp Array of counts.
* @param mem_nc_type The type of these data after it is read into memory.
* @param is_long Ignored for HDF4.
* @param data pointer that gets the data.
* @returns ::NC_NOERR for success
* @author Ed Hartnett
*/
static int
nc4_get_hdf4_vara(NC *nc, int ncid, int varid, const size_t *startp,
const size_t *countp, nc_type mem_nc_type, int is_long, void *data)
{
NC_GRP_INFO_T *grp;
NC_HDF5_FILE_INFO_T *h5;
NC_VAR_INFO_T *var;
int32 start32[NC_MAX_VAR_DIMS], edge32[NC_MAX_VAR_DIMS];
int retval, d;
/* Find our metadata for this file, group, and var. */
assert(nc);
if ((retval = nc4_find_g_var_nc(nc, ncid, varid, &grp, &var)))
return retval;
h5 = NC4_DATA(nc);
assert(grp && h5 && var && var->hdr.name);
for (d = 0; d < var->ndims; d++)
{
start32[d] = startp[d];
edge32[d] = countp[d];
}
if (SDreaddata(var->sdsid, start32, NULL, edge32, data))
return NC_EHDFERR;
return NC_NOERR;
}
/**
* @internal Write an array of data to a variable. This is called by
* nc_put_vara() and other nc_put_vara_* functions, for netCDF-4
* files.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param startp Array of start indicies.
* @param countp Array of counts.
* @param op pointer that gets the data.
* @param memtype The type of these data in memory.
*
* @returns ::NC_NOERR for success
* @author Ed Hartnett, Dennis Heimbigner
*/
int
HDF4_put_vara(int ncid, int varid, const size_t *startp,
const size_t *countp, const void *op, int memtype)
{
return NC_EPERM;
}
#include <mfhdf.h>
/**
* Read an array of values. This is called by nc_get_vara() for
@ -357,23 +25,83 @@ HDF4_put_vara(int ncid, int varid, const size_t *startp,
* @param ip pointer that gets the data.
* @param memtype The type of these data after it is read into memory.
* @returns ::NC_NOERR for success
* @return ::NC_NOERR for success.
* @return ::NC_EBADID Bad ncid.
* @author Ed Hartnett, Dennis Heimbigner
*/
int
HDF4_get_vara(int ncid, int varid, const size_t *startp,
const size_t *countp, void *ip, int memtype)
NC_HDF4_get_vara(int ncid, int varid, const size_t *startp,
const size_t *countp, void *ip, int memtype)
{
NC *nc;
NC_HDF5_FILE_INFO_T* h5;
NC_GRP_INFO_T *grp;
NC_VAR_HDF4_INFO_T *hdf4_var;
NC_VAR_INFO_T *var;
int32 start32[NC_MAX_VAR_DIMS], edge32[NC_MAX_VAR_DIMS];
size_t nelem = 1;
void *data;
int retval, d;
int range_error;
LOG((2, "%s: ncid 0x%x varid %d memtype %d", __func__, ncid, varid,
memtype));
/* No scalars in HDF4 SD API. Caller must also provide place to put
* data. */
if (!startp || !countp || !ip)
return NC_EINVAL;
/* Find file info. */
if (!(nc = nc4_find_nc_file(ncid, &h5)))
return NC_EBADID;
/* Find our metadata for this file, group, and var. */
if ((retval = nc4_find_g_var_nc(nc, ncid, varid, &grp, &var)))
return retval;
/* Handle HDF4 cases. */
return nc4_get_hdf4_vara(nc, ncid, varid, startp, countp, memtype,
0, (void *)ip);
assert(grp && var && var->hdr.name && var->format_var_info);
/* Get the HDF4 specific var metadata. */
hdf4_var = (NC_VAR_HDF4_INFO_T *)var->format_var_info;
h5 = NC4_DATA(nc);
assert(h5);
/* Convert starts/edges to the int32 type HDF4 wants. Also learn
* how many elements of data are being read. */
for (d = 0; d < var->ndims; d++)
{
start32[d] = startp[d];
edge32[d] = countp[d];
nelem *= countp[d];
}
/* If memtype was not give, use variable type. */
if (memtype == NC_NAT)
memtype = var->type_info->hdr.id;
/* If we need to convert data, allocate temp storage. */
if (var->type_info->hdr.id == memtype)
data = ip;
else
if (!(data = malloc(var->type_info->size * nelem)))
return NC_ENOMEM;
/* Read the data with HDF4. */
if (SDreaddata(hdf4_var->sdsid, start32, NULL, edge32, data))
return NC_EHDFERR;
/* Do we need to convert data? */
if (var->type_info->hdr.id != memtype)
{
if ((retval = nc4_convert_type(data, ip, var->type_info->hdr.id, memtype, nelem,
&range_error, NULL, 0, 0, 0)))
return retval;
free(data);
if (range_error)
return range_error;
}
return NC_NOERR;
}

View File

@ -36,8 +36,8 @@ extern int NCP_finalize(void);
#endif
#ifdef USE_HDF4
extern int HDF4_initialize(void);
extern int HDF4_finalize(void);
extern int NC_HDF4_initialize(void);
extern int NC_HDF4_finalize(void);
#endif
#ifdef _MSC_VER
@ -89,7 +89,7 @@ nc_initialize()
if((stat = NCP_initialize())) goto done;
#endif
#ifdef USE_HDF4
if((stat = HDF4_initialize())) goto done;
if((stat = NC_HDF4_initialize())) goto done;
#endif
#ifdef USE_NETCDF4
if((stat = NC4_initialize())) goto done;
@ -131,6 +131,10 @@ nc_finalize(void)
if((stat = NCP_finalize())) return stat;
#endif
#ifdef USE_HDF4
if((stat = NC_HDF4_finalize())) return stat;
#endif /* USE_HDF4 */
#ifdef USE_NETCDF4
if((stat = NC4_finalize())) return stat;
#endif /* USE_NETCDF4 */

View File

@ -1381,138 +1381,6 @@ NCP_inq_user_type(int ncid, nc_type typeid, char *name, size_t *size,
return NC_ENOTNC4;
}
static int
NCP_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp)
{
return NC_ENOTNC4;
}
static int
NCP_insert_compound(int ncid, nc_type typeid, const char *name, size_t offset,
nc_type field_typeid)
{
return NC_ENOTNC4;
}
static int
NCP_insert_array_compound(int ncid, nc_type typeid, const char *name,
size_t offset, nc_type field_typeid,
int ndims, const int *dim_sizes)
{
return NC_ENOTNC4;
}
static int
NCP_inq_compound_field(int ncid, nc_type typeid, int fieldid, char *name,
size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
int *dim_sizesp)
{
return NC_ENOTNC4;
}
static int
NCP_inq_compound_fieldindex(int ncid, nc_type typeid, const char *name, int *fieldidp)
{
return NC_ENOTNC4;
}
static int
NCP_def_opaque(int ncid, size_t datum_size, const char *name, nc_type* xtypep)
{
return NC_ENOTNC4;
}
static int
NCP_def_vlen(int ncid, const char *name, nc_type base_typeid, nc_type* xtypep)
{
return NC_ENOTNC4;
}
static int
NCP_def_enum(int ncid, nc_type base_typeid, const char *name,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
static int
NCP_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
{
return NC_ENOTNC4;
}
static int
NCP_inq_enum_member(int ncid, nc_type typeid, int idx, char *identifier,
void *value)
{
return NC_ENOTNC4;
}
static int
NCP_insert_enum(int ncid, nc_type typeid, const char *identifier,
const void *value)
{
return NC_ENOTNC4;
}
static int
NCP_put_vlen_element(int ncid, int typeid, void *vlen_element,
size_t len, const void *data)
{
return NC_ENOTNC4;
}
static int
NCP_get_vlen_element(int ncid, int typeid, const void *vlen_element,
size_t *len, void *data)
{
return NC_ENOTNC4;
}
static int
NCP_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption)
{
return NC_ENOTNC4;
}
static int
NCP_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp)
{
return NC_ENOTNC4;
}
static int
NCP_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
int deflate_level)
{
return NC_ENOTNC4;
}
static int
NCP_def_var_fletcher32(int ncid, int varid, int fletcher32)
{
return NC_ENOTNC4;
}
static int
NCP_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp)
{
return NC_ENOTNC4;
}
static int
NCP_def_var_endian(int ncid, int varid, int endianness)
{
return NC_ENOTNC4;
}
static int
NCP_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams, const unsigned int* parms)
{
return NC_ENOTNC4;
}
#endif /*USE_NETCDF4*/
/**************************************************/
@ -1587,26 +1455,26 @@ NCP_rename_grp,
NCP_inq_user_type,
NCP_inq_typeid,
NCP_def_compound,
NCP_insert_compound,
NCP_insert_array_compound,
NCP_inq_compound_field,
NCP_inq_compound_fieldindex,
NCP_def_vlen,
NCP_put_vlen_element,
NCP_get_vlen_element,
NCP_def_enum,
NCP_insert_enum,
NCP_inq_enum_member,
NCP_inq_enum_ident,
NCP_def_opaque,
NCP_def_var_deflate,
NCP_def_var_fletcher32,
NCP_def_var_chunking,
NCP_def_var_endian,
NCP_def_var_filter,
NCP_set_var_chunk_cache,
NCP_get_var_chunk_cache,
NC_NOTNC4_def_compound,
NC_NOTNC4_insert_compound,
NC_NOTNC4_insert_array_compound,
NC_NOTNC4_inq_compound_field,
NC_NOTNC4_inq_compound_fieldindex,
NC_NOTNC4_def_vlen,
NC_NOTNC4_put_vlen_element,
NC_NOTNC4_get_vlen_element,
NC_NOTNC4_def_enum,
NC_NOTNC4_insert_enum,
NC_NOTNC4_inq_enum_member,
NC_NOTNC4_inq_enum_ident,
NC_NOTNC4_def_opaque,
NC_NOTNC4_def_var_deflate,
NC_NOTNC4_def_var_fletcher32,
NC_NOTNC4_def_var_chunking,
NC_NOTNC4_def_var_endian,
NC_NOTNC4_def_var_filter,
NC_NOTNC4_set_var_chunk_cache,
NC_NOTNC4_get_var_chunk_cache,
#endif /*USE_NETCDF4*/
};