[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with C++ set_cur function
- Subject: Re: Problem with C++ set_cur function
- Date: Fri, 13 Jan 1995 16:14:33 -0700
> Organization: .
> Keywords: 199501132100.AA20965
Hi Phil,
> In the set_cur C++ function in netcdf.cc, I have made the following
> modification. This change seems necessary to be able to extend a variable
> with an unlimited dimension. For instance, in the nctst.cc file, the entire
> unlimited dimension frtime is written first. Then the P variable can be
> written in pieces.
> line 665 of netcdf.cc
>
> if ( (t[i] >= get_dim(i)->size()) &&
> ( i > 1 || !get_dim(i)->is_unlimited()) )
> return FALSE; // too big for dimension
I don't see the reason for the "i>1" condition, but you are correct in
excluding the unlimited dimension. Here is what my fix looks like:
if ((t[i] >= get_dim(i)->size()) &&
!get_dim(i)->is_unlimited())
return FALSE; // too big for dimension
and the same fix is needed a little further down, in the other version of
set_cur()
if ((cur[i] >= get_dim(i)->size()) &&
!get_dim(i)->is_unlimited())
return FALSE;
I've been meaning to put together another patch with this and additional
fixes to the C++ interface, but I haven't found the necessary time yet. I
assume you've already applied the set of C++ patches in
ftp://ftp.unidata.ucar.edu/pub/netcdf/2.3.2-patch3
to the current distribution. I've appended the current diffs between that
and what bug fixes I have accumulated, but I'm afraid I can't gaurantee much
except that this passes the simple test I constructed with "make test" in
the C++ directory.
______________________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden P.O. Box 3000
http://www.unidata.ucar.edu/ Boulder, CO 80307-3000
______________________________________________________________________________
diff -c /home/russ/build/netcdf-232pl3/c++/netcdf.cc ./netcdf.cc
*** /home/russ/build/netcdf-232pl3/c++/netcdf.cc Fri Jan 13 16:08:03 1995
--- ./netcdf.cc Fri Jan 13 15:41:36 1995
***************
*** 4,10 ****
*
* Purpose: Implements class interface for netCDF over C interface
*
! * $Header: /upc/new/CVS/netcdf/c++/netcdf.cc,v 1.46 1994/02/22 18:09:42
russ Exp $
*********************************************************************/
#include <string.h>
--- 4,10 ----
*
* Purpose: Implements class interface for netCDF over C interface
*
! * $Header: /upc/new/CVS/netcdf/c++/netcdf.cc,v 1.48 1994/10/10 21:39:50
russ Exp $
*********************************************************************/
#include <string.h>
***************
*** 160,172 ****
// For variables with more than 5 dimensions, use n-dimensional interface
// with vector of dimensions.
! NcVar* NcFile::add_var(NcToken name, NcType type, int ndims, const NcDim*
dims)
{
if (!is_valid() || !define_mode())
return 0;
int *dimids = new int[ndims];
for (int i=0; i < ndims; i++)
! dimids[i] = dims[i].id();
int n = num_vars();
NcVar* varp =
new NcVar(this, ncvardef(the_id, name, (nc_type) type, ndims, dimids));
--- 160,172 ----
// For variables with more than 5 dimensions, use n-dimensional interface
// with vector of dimensions.
! NcVar* NcFile::add_var(NcToken name, NcType type, int ndims, const NcDim**
dims)
{
if (!is_valid() || !define_mode())
return 0;
int *dimids = new int[ndims];
for (int i=0; i < ndims; i++)
! dimids[i] = dims[i]->id();
int n = num_vars();
NcVar* varp =
new NcVar(this, ncvardef(the_id, name, (nc_type) type, ndims, dimids));
***************
*** 220,225 ****
--- 220,227 ----
NcBool NcFile::sync( void )
{
+ if (!data_mode())
+ return 0;
if (ncsync(the_id) == ncBad)
return 0;
for (int i = 0; i < num_dims(); i++)
***************
*** 469,475 ****
return the_file->get_dim(dims[i]);
}
! const long* NcVar::edges( void ) const // edge lengths (dimension
sizes)
{
long* evec = new long[num_dims()];
for(int i=0; i < num_dims(); i++)
--- 471,477 ----
return the_file->get_dim(dims[i]);
}
! long* NcVar::edges( void ) const // edge lengths (dimension sizes)
{
long* evec = new long[num_dims()];
for(int i=0; i < num_dims(); i++)
***************
*** 573,579 ****
NcVar_put_array(double)
#define NcVar_put_nd_array(TYPE) \
! NcBool NcVar::put( const TYPE* vals, const long* count )
\
{ \
if (type() != NcTypeEnum(TYPE)) \
return FALSE; \
--- 575,581 ----
NcVar_put_array(double)
#define NcVar_put_nd_array(TYPE) \
! NcBool NcVar::put( const TYPE* vals, const long* count ) \
{ \
if (type() != NcTypeEnum(TYPE)) \
return FALSE; \
***************
*** 634,640 ****
NcVar_get_array(double)
#define NcVar_get_nd_array(TYPE) \
! NcBool NcVar::get( TYPE* vals, const long* count ) const
\
{ \
if (type() != NcTypeEnum(TYPE)) \
return FALSE; \
--- 636,642 ----
NcVar_get_array(double)
#define NcVar_get_nd_array(TYPE) \
! NcBool NcVar::get( TYPE* vals, const long* count ) const \
{ \
if (type() != NcTypeEnum(TYPE)) \
return FALSE; \
***************
*** 669,675 ****
if (num_dims() < j)
return FALSE; // too many for variable's dimensionality
for (int i = 0; i < j; i++) {
! if (t[i] >= get_dim(i)->size())
return FALSE; // too big for dimension
the_cur[i] = t[i];
}
--- 671,678 ----
if (num_dims() < j)
return FALSE; // too many for variable's dimensionality
for (int i = 0; i < j; i++) {
! if ((t[i] >= get_dim(i)->size()) &&
! !get_dim(i)->is_unlimited())
return FALSE; // too big for dimension
the_cur[i] = t[i];
}
***************
*** 684,690 ****
NcBool NcVar::set_cur(long *cur)
{
for(int i = 0; i < num_dims(); i++) {
! if (cur[i] >= get_dim(i)->size())
return FALSE;
the_cur[i] = cur[i];
}
--- 687,694 ----
NcBool NcVar::set_cur(long *cur)
{
for(int i = 0; i < num_dims(); i++) {
! if ((cur[i] >= get_dim(i)->size()) &&
! !get_dim(i)->is_unlimited())
return FALSE;
the_cur[i] = cur[i];
}
diff -c /home/russ/build/netcdf-232pl3/c++/netcdf.hh ./netcdf.hh
*** /home/russ/build/netcdf-232pl3/c++/netcdf.hh Fri Jan 13 16:08:03 1995
--- ./netcdf.hh Wed Nov 2 16:56:52 1994
***************
*** 4,10 ****
*
* Purpose: C++ class interface for netCDF
*
! * $Header: /upc/new/CVS/netcdf/c++/netcdf.hh,v 1.40 1993/12/07 16:17:48
russ Exp $
*********************************************************************/
#ifndef NETCDF_HH
--- 4,10 ----
*
* Purpose: C++ class interface for netCDF
*
! * $Header: /upc/new/CVS/netcdf/c++/netcdf.hh,v 1.41 1994/10/10 21:39:52
russ Exp $
*********************************************************************/
#ifndef NETCDF_HH
***************
*** 61,67 ****
const NcDim* dim3=0, // 4-dim
const NcDim* dim4=0 ); // 5-dim
NcVar* add_var( NcToken varname, NcType type, // n-dim
! int ndims, const NcDim* dims );
NcBool add_att( NcToken attname, char ); // scalar attributes
NcBool add_att( NcToken attname, short );
--- 61,67 ----
const NcDim* dim3=0, // 4-dim
const NcDim* dim4=0 ); // 5-dim
NcVar* add_var( NcToken varname, NcType type, // n-dim
! int ndims, const NcDim** dims );
NcBool add_att( NcToken attname, char ); // scalar attributes
NcBool add_att( NcToken attname, short );
***************
*** 229,235 ****
NcBool is_valid( void ) const;
int num_dims( void ) const; // dimensionality of variable
NcDim* get_dim( int ) const; // n-th dimension
! const long* edges( void ) const; // dimension sizes
int num_atts( void ) const; // number of attributes
NcAtt* get_att( NcToken ) const; // attribute by name
NcAtt* get_att( int ) const; // n-th attribute
--- 229,235 ----
NcBool is_valid( void ) const;
int num_dims( void ) const; // dimensionality of variable
NcDim* get_dim( int ) const; // n-th dimension
! long* edges( void ) const; // dimension sizes
int num_atts( void ) const; // number of attributes
NcAtt* get_att( NcToken ) const; // attribute by name
NcAtt* get_att( int ) const; // n-th attribute
***************
*** 342,348 ****
const NcDim*,
const NcDim*);
friend NcVar* NcFile::add_var( NcToken, NcType, int,
! const NcDim* );
};
--- 342,348 ----
const NcDim*,
const NcDim*);
friend NcVar* NcFile::add_var( NcToken, NcType, int,
! const NcDim** );
};