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

Re: data vs define modes

This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.


  • Subject: Re: data vs define modes
  • Date: Sat, 04 Feb 2006 11:45:12 -0700

Hi Ben,

> Is there a way to determine if an open netcdf file is in data or
> define mode?  Maybe an inquiry function?  An inquiry function would
> let me know if I need to call nc_redef or nc_enddef prior to defining
> or writing. Thanks,

Sorry to take so long to answer this.  There is no inquiry function
for this (although there probably should be).  But you can do it by
checking the error return from a function that must be in define mode
to work.  For example, in the C interface, you can use something like

  /* For an open netCDF with id ncid, 
   * returns 0 if in data mode, 
   * returns 1 if in define mode 
   */
  int
  function nc_inq_mode(int ncid) {
     int status = nc_redef(ncid);
     if(status == NC_NOERR) {
        (void) nc_enddef(ncid);
        return 0;
     } elseif(status == NC_EINDEFINE) {
        return 1;
     }
     /* else */
     return(status);
  }

Note I haven't compiled above, but it looks right :-).

--Russ