David Fanning writes:
>
> Folks,
>
> I am writing my first netCDF file in IDL and I am practically
> copying the code out of Ken Bowman's book. I open a file:
>
> fID = NCDF_CREATE(filename, /CLOBBER)
>
> Then, I define several global attributes, two dimensions,
> and two variables. I also define a couple of attributes
> of the variables. All in that order.
>
> Then, I attempt to get out of DEFINE mode and into DATA
> mode, so I can write the actual variables.
>
> NCDF_CONTROL, fID, /ENDEF
>
> But at this point I get the following error message:
>
> % NCDF_CONTROL: Attempt to take the file out of
> define mode (ENDEF) failed. (NC_ERROR=-45)
> % Execution halted at: TIMESERIES::CREATE_CLIMATOLOGY 2589
>
> Does anyone have ANY idea what this might be about?
The code is pretty simple:
; Create a netCDF file for storing the climatology.
fID = NCDF_Create(filename, /CLOBBER)
; Define dimensions.
xsizeID = NCDF_DIMDEF(fID, 'cols', xsize)
ysizeID = NCDF_DIMDEF(fID, 'rows', ysize)
timeID = NCDF_DIMDEF(fID, 'time', 2)
; Define variables.
vid = NCDF_VARDEF(fID, 'time', [timeID], /LONG)
vid = NCDF_VARDEF(fID, 'climatology', [xsizeID, ysizeID], /DOUBLE)
; Define variable attributes.
NCDF_ATTPUT, fID, 'time', 'units', 'Days since 1601-01-01 00:00:00'
NCDF_ATTPUT, fID, 'time', 'long_name', 'Start and end time. '
NCDF_ATTPUT, fID, 'climatology', '_FillValue', fillValue
NCDF_ATTPUT, fID, 'climatology', 'long_name', 'longish name'
; Exit DEFINE mode and into DATA mode.
NCDF_Control, fID, /ENDEF
; Write the variables.
NCDF_VarPut, fID, 'time', [time[0], time[timepts-1]]
NCDF_VarPut, fID, 'climatology', climatology
; Close the file.
NCDF_Close, fID
At one time I had global attributes in there, but I took them out
and the code worked! So I added them back one by one. Then, it
didn't work again, so I took them all back out. Now it *still*
doesn't work! Something really, really weird going on here, I think. :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|