mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
fixed error value from nc4_find_g_var_nc() when ncid is bad
This commit is contained in:
parent
9e4c564656
commit
bf6dab14e0
@ -790,6 +790,8 @@ INPUT = \
|
||||
@abs_top_srcdir@/libdispatch/dv2i.c \
|
||||
@abs_top_srcdir@/libsrc4/nc4file.c \
|
||||
@abs_top_srcdir@/libsrc4/nc4var.c \
|
||||
@abs_top_srcdir@/libsrc4/nc4hdf.c \
|
||||
@abs_top_srcdir@/libsrc4/nc4internal.c \
|
||||
@abs_top_srcdir@/examples/C/simple_xy_wr.c \
|
||||
@abs_top_srcdir@/examples/C/simple_xy_rd.c \
|
||||
@abs_top_srcdir@/examples/C/sfc_pres_temp_wr.c \
|
||||
|
@ -1,16 +1,18 @@
|
||||
/*
|
||||
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.
|
||||
|
||||
Copyright 2003, University Corporation for Atmospheric
|
||||
Research. See the COPYRIGHT file for copying and redistribution
|
||||
conditions.
|
||||
|
||||
$Id: nc4hdf.c,v 1.273 2010/05/27 21:34:14 dmh Exp $
|
||||
/**
|
||||
*
|
||||
* @file
|
||||
* 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.
|
||||
*
|
||||
* Copyright 2003, University Corporation for Atmospheric
|
||||
* Research. See the COPYRIGHT file for copying and redistribution
|
||||
* conditions.
|
||||
*
|
||||
* @author Ed Hartnett, Dennis Heimbigner, Ward Fisher
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@ -535,11 +537,21 @@ set_par_access(NC_HDF5_FILE_INFO_T *h5, NC_VAR_INFO_T *var, hid_t xfer_plistid)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Write an array of data to a variable. When it comes right down to
|
||||
* it, this is what netCDF-4 is all about, this is *the* function, the
|
||||
* big enchilda, the grand poo-bah, the alpha dog, the head honcho,
|
||||
* the big cheese, the mighty kahuna, the top bananna, the high
|
||||
* muckity-muck, numero uno. Well, you get the idea. */
|
||||
/**
|
||||
* @internal Write an array of data to a variable.
|
||||
*
|
||||
* @param nc Pointer to the file NC struct.
|
||||
* @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 the data in memory.
|
||||
* @param is_long True only if NC_LONG is the memory type.
|
||||
* @param data The data to be written.
|
||||
*
|
||||
* @returns NC_NOERR No error.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
nc4_put_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)
|
||||
|
@ -1,16 +1,18 @@
|
||||
/** \file \internal
|
||||
Internal netcdf-4 functions.
|
||||
|
||||
This file contains functions internal to the netcdf4 library. None of
|
||||
the functions in this file are exposed in the exetnal API. These
|
||||
functions all relate to the manipulation of netcdf-4's in-memory
|
||||
buffer of metadata information, i.e. the linked list of NC
|
||||
structs.
|
||||
|
||||
Copyright 2003-2011, University Corporation for Atmospheric
|
||||
Research. See the COPYRIGHT file for copying and redistribution
|
||||
conditions.
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @internal
|
||||
* Internal netcdf-4 functions.
|
||||
*
|
||||
* This file contains functions internal to the netcdf4 library. None of
|
||||
* the functions in this file are exposed in the exetnal API. These
|
||||
* functions all relate to the manipulation of netcdf-4's in-memory
|
||||
* buffer of metadata information, i.e. the linked list of NC
|
||||
* structs.
|
||||
*
|
||||
* Copyright 2003-2011, University Corporation for Atmospheric
|
||||
* Research. See the COPYRIGHT file for copying and redistribution
|
||||
* conditions.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "nc4internal.h"
|
||||
@ -33,7 +35,6 @@ h5catch(void* ignored)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* These are the default chunk cache sizes for HDF5 files created or
|
||||
* opened with netCDF-4. */
|
||||
extern size_t nc4_chunk_cache_size;
|
||||
@ -259,6 +260,18 @@ nc4_find_grp_h5(int ncid, NC_GRP_INFO_T **grpp, NC_HDF5_FILE_INFO_T **h5p)
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Find info for this file and group, and set pointer to each.
|
||||
*
|
||||
* @param ncid File and group ID.
|
||||
* @param nc Pointer that gets a pointer to the file's NC struct.
|
||||
* @param grpp Pointer that gets a pointer to the group struct.
|
||||
* @param h5p Pointer that gets HDF5 file struct.
|
||||
*
|
||||
* @returns NC_NOERR No error.
|
||||
* @returns NC_EBADID Bad ncid.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grpp,
|
||||
NC_HDF5_FILE_INFO_T **h5p)
|
||||
@ -287,7 +300,15 @@ nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grpp,
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Recursively hunt for a group id. */
|
||||
/**
|
||||
* @internal Recursively hunt for a group id.
|
||||
*
|
||||
* @param start_grp Pointer to group where search should be started.
|
||||
* @param tartget_nc_grpid Group ID to be found.
|
||||
*
|
||||
* @returns Pointer to group info struct, or NULL if not found.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
NC_GRP_INFO_T *
|
||||
nc4_rec_find_grp(NC_GRP_INFO_T *start_grp, int target_nc_grpid)
|
||||
{
|
||||
@ -309,8 +330,18 @@ nc4_rec_find_grp(NC_GRP_INFO_T *start_grp, int target_nc_grpid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Given an ncid and varid, get pointers to the group and var
|
||||
* metadata. */
|
||||
/**
|
||||
* @internal Given an ncid and varid, get pointers to the group and var
|
||||
* metadata.
|
||||
*
|
||||
* @param nc Pointer to file's NC struct.
|
||||
* @param ncid File ID.
|
||||
* @param varid Variable ID.
|
||||
* @param grp Pointer that gets pointer to group info.
|
||||
* @param var Pointer that gets pointer to var info.
|
||||
*
|
||||
* @returns NC_NOERR No error.
|
||||
*/
|
||||
int
|
||||
nc4_find_g_var_nc(NC *nc, int ncid, int varid,
|
||||
NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var)
|
||||
@ -324,7 +355,7 @@ nc4_find_g_var_nc(NC *nc, int ncid, int varid,
|
||||
/* It is possible for *grp to be NULL. If it is,
|
||||
return an error. */
|
||||
if(*grp == NULL)
|
||||
return NC_ENOTVAR;
|
||||
return NC_EBADID;
|
||||
|
||||
/* Find the var info. */
|
||||
if (varid < 0 || varid >= (*grp)->vars.nelems)
|
||||
@ -334,7 +365,18 @@ nc4_find_g_var_nc(NC *nc, int ncid, int varid,
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Find a dim in a grp (or parents). */
|
||||
/**
|
||||
* @internal Find a dim in a grp (or its parents).
|
||||
*
|
||||
* @param grp Pointer to group info struct.
|
||||
* @param dimid Dimension ID to find.
|
||||
* @param dim Pointer that gets pointer to dim info if found.
|
||||
* @param dim_grp Pointer that gets pointer to group info of group that contians dimension.
|
||||
*
|
||||
* @returns ::NC_NOERR No error.
|
||||
* @returns ::NC_BADDIM Dimension not found.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim,
|
||||
NC_GRP_INFO_T **dim_grp)
|
||||
|
@ -398,8 +398,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* Try to write some data, but fail. */
|
||||
if (nc_put_vara_double(ncid + MILLION, 0, start, count, double_data) != NC_EBADID) ERR;
|
||||
/* This should return NC_EBADID, but returns NC_ENOTVAR. */
|
||||
if (nc_put_vara_double(ncid + TEST_VAL_42, 0, start, count, double_data) != NC_ENOTVAR) ERR;
|
||||
if (nc_put_vara_double(ncid + TEST_VAL_42, 0, start, count, double_data) != NC_EBADID) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user