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

Re: data vs define modes



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