David Fanning wrote:
> 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. :-(
I think it's related to the _FillValue global attribute. I can't remember the details, but
I posted here about exactly the same thing a few months ago. Searching the web....
Paul van Delst wrote:
> Hello,
>
> I've encountered a strange problem with some netCDF output using IDL.
>
> I define a character string array variable in my output netCDF file like so:
> VarId = NCDF_VARDEF( fid, 'Absorber_Units_Name', [32,n_Absorbers_DimId], /CHAR)
> where the "32" is the maximum string length.
>
> Now if I try to set a fill value attribute for that variable, like so
> NCDF_ATTPUT, fid, VarId, '_FillValue', ' '
> or
> NCDF_ATTPUT, fid, VarId, '_FillValue', 0B
>
> when I run the code I get the following error when I take the file out of define mode:
>
> % NCDF_CONTROL: Attempt to take the file out of define mode (ENDEF) failed. (NC_ERROR=-45)
>
> If I simply comment out the call to NCDF_ATTPUT for these character variables, there's no
> problem.
>
> I do this sort of thing (i.e. _FillValue of " " for character string variables) all the
> time using the Fortran90 API to netCDF so I assume an empty space is a valid fill value.
>
> Has anyone else encountered this behaviour in IDL? I.e. is this a known bug in the IDL
> netCDF interface, or do I need to do something special with character fill values?
>
> Thanks for any info.
>
> cheers,
>
> paulv
F�LDY Lajos came up with a solution,
> I have found the solution: _FillValue needs to be the same type as the
> variable. ' ' is an IDL string, which is converted to something, probably
> BYTE. So let's add an explicite /CHAR to ncdf_attput:
>
> ncid=ncdf_create('test.nc', /clobber)
> dim32=ncdf_dimdef(ncid, 'dim1', 32)
> n_absorbers_dimid=ncdf_dimdef(ncid, 'dim2', 9)
> varid = ncdf_vardef( ncid, 'absorber_units_name', [dim32,n_absorbers_dimid], /char)
> ncdf_attput, ncid, varid, '_FillValue', ' ', /CHAR
> ncdf_control, ncid, /endef
> ncdf_close, ncid
>
> It works now! :-)
>
> regards,
> lajos
Does that help?
cheers,
paulv
|