[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 970203: Problem with ncendef



> >To: address@hidden
> >From: address@hidden (Hank Fisher)
> >Subject: Problem with ncendef
> >Organization: .
> >Keywords: 199702021956.MAA17474

Hi Hank,

First, apologies for not replying to your question earlier.  We were all
out of town at a meeting last week and came back to a large backlog of
support questions ...

>       Hi, I am having a problem using ncendef.  Specifically when
> I use ncredef to enter define mode in order to define a new variable I
> then exit using ncenedef.  The program then crashes and gives me the
> following error message
> 
> ncendef: rename failed: Cross-device link

This is a symptom of a bug in an old (2.02) version of netCDF.  The
current version (2.4.3) which is available from

   ftp://ftp.unidata.ucar.edu/pub/netcdf/

as the file netcdf.tar.Z should not have this problem.  

The problem occurred when an attempt was made to change the schema of a
netCDF file (by adding new dimensions, for example), causing the library
to try to create a new file, copy the schema and data to the new file,
and rename it to the old file's name.  If you were doing this in a
directory that was on a different file system than the original file,
the bug would occur.  So another possible workaround (if you must use
the old version of netCDF) would be to make sure you are on the same
file system as the original file to which you are adding dimensions.

>       Below is the piece of my code that deals with the netcdf commands.
> I believe I have followed all of the instructions according to the manual,
> but I am at a loss as to what I am doing wrong.  Can you help?
> 
> Hank
> 
> ncopts = NC_VERBOSE;
> 
>           ncfileid = ncopen(write_name,NC_WRITE);     /* Open          */
> 
>           if(ncfileid == -1)
>           {
>             ncfileid = nccreate(write_name,NC_NOCLOBBER);/*Create file */
>             cellid = ncdimdef(ncfileid,"cell",259200);  /* Create cell dimens 
> */
>             timid = ncdimdef(ncfileid,"month",12);      /* Create month dimen 
> */
>             dimhold[0] = timid;
>             dimhold[1] = cellid;
>             ncendef(ncfileid);                           /* leave define mode 
> */
>           }
>           else
>           {
>             dimhold[0] = 0;
>             dimhold[1] = 1;
>           }
>           if (month == 0)
>           {
>             ncredef(ncfileid);
>             ncvardef(ncfileid,argv[4],NC_FLOAT,2,dimhold);/* Create variable*/
>           }
>           varid = ncvarid(ncfileid,argv[4]);            /* Get variable id    
> */
>           printf("%d\n",varid);
>           ncendef(ncfileid);                     /* leave define mode */
> 
> 
>           -----------other program stuff deleted--------------------
> 
> 
>             ncvarput1(ncfileid,varid,index, (void *)&value);
> 
> 
>           -----------other program stuff deleted--------------------
> 
> 
>           ncclose(ncfileid);                           /* close the ncdf file 
> */

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu