[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 980223: problem with nc_redef
- Subject: Re: 980223: problem with nc_redef
- Date: Mon, 23 Feb 1998 14:50:24 -0700
>To: address@hidden
>From: Hartmut Freihofer <address@hidden>
>Subject: problem with nc_redef
>Organization: Forschungsinstitut fuer Kerntechnik und Energiewandlung e.V.,
>Abt. Wissensverarbeitung und Numerik
>Keywords: 199802231650.JAA06505
Hi Hartmut,
> i have a problem defining a new variable in an existing netCDF file
> which already contains data.
>
> I use the netCDF version 3.4a and the Visual C++ Compiler 5.0.
>
> I tried to make a short example showing my problem:
>
> //BOF
> #include "netcdf.h"
>
> int main(void){
>
> int ncstatus;
> int ncid;
>
> ncstatus = nc_create("test.cdf", NC_CLOBBER , &ncid);
>
>
> int ncidDim_Time;
> ncstatus += nc_def_dim( ncid, "Timesteps", NC_UNLIMITED,
> &ncidDim_Time);
>
> int time_dimids[1];
> int ncid_Time;
> time_dimids[0]=ncidDim_Time;
> ncstatus +=nc_def_var( ncid, "Time", NC_INT, 1, time_dimids,
> &ncid_Time);
>
> int ncid_First_Var;
> ncstatus += nc_def_var( ncid, "First_Var", NC_FLOAT,1,time_dimids,
> &ncid_First_Var);
>
> //put some data in it:
> nc_enddef(ncid);
>
> size_t beg[1];
> nc_inq_dimlen( ncid, ncid_Time, &beg[0]);
>
> size_t count[1];
> count[0]=3;
> long times[3]={1,2,3};
> ncstatus += nc_put_vara_long(ncid, ncid_Time, beg, count, times);
>
> float data[3]={4.5,5.5,6.5};
> ncstatus += nc_put_vara_float(ncid, ncid_First_Var, beg, count, data);
>
>
> //append another var:
> nc_redef(ncid);
>
> int ncid_Second_Var; // <<<<<<<<<<<<<<<< cdf file corrupts here!
> >>>>>>>>>>>>>>>>>>
> ncstatus += nc_def_var( ncid, "Second_Var", NC_FLOAT, 1,
> time_dimids,
> &ncid_Second_Var);
>
> nc_close(ncid);
>
> return ncstatus;
> }
> //EOF
>
> Is this a problem of mine (what mistake did i make)?
> Is it possible at all?
I was able to compile and run this program with the Sun C++ compiler,
and it worked fine, with the expected result from "ncdump test.cdf".
So this may be a platform-specific bug. We will try to reproduce the
problem on an NT platform with Visual C++ 5.0, so we can determine the
cause.
Thanks for reporting the problem.
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu