comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: NCDF_ATTPUT _FillValue problem for string arrays?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: NCDF_ATTPUT _FillValue problem for string arrays? [message #67144 is a reply to message #67140] Mon, 06 July 2009 13:41 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
F�LDY Lajos wrote:
>
>
> On Mon, 6 Jul 2009, 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
>>
>>
>
> NCDF_VARDEF needs dimension ID, not dimension size. The following code
> works for me:

Yeah, I fat-fingered my code when I typed the message. Cutting-and-pasting directly from
my script I have:

; ...Define dimensions
n_Levels_DimId = NCDF_DIMDEF(fid, LEVEL_DIMNAME , self.n_Levels)
n_Layers_DimId = NCDF_DIMDEF(fid, LAYER_DIMNAME , self.n_Layers)
n_Absorbers_DimId = NCDF_DIMDEF(fid, ABSORBER_DIMNAME , self.n_Absorbers)
pdsl_DimId = NCDF_DIMDEF(fid, DESCRIPTION_DIMNAME , PDSL)
aunsl_DimId = NCDF_DIMDEF(fid, ABSORBER_UNITS_DIMNAME, AUNSL)
n_Profiles_DimId = NCDF_DIMDEF(fid, PROFILE_DIMNAME , /UNLIMITED)


; Define variables
VarId = NCDF_VARDEF( fid, DESCRIPTION_VARNAME, [pdsl_DimId,n_Profiles_DimId], /CHAR)
NCDF_ATTPUT, fid, VarId, LONGNAME_ATTNAME , DESCRIPTION_LONGNAME
NCDF_ATTPUT, fid, VarId, DESCRIPTION_ATTNAME, DESCRIPTION_DESCRIPTION
NCDF_ATTPUT, fid, VarId, UNITS_ATTNAME , DESCRIPTION_UNITS
; NCDF_ATTPUT, fid, VarId, FILLVALUE_ATTNAME , DESCRIPTION_FILLVALUE

where I have a parameters include file containing:

LONGNAME_ATTNAME = 'long_name'
DESCRIPTION_ATTNAME = 'description'
UNITS_ATTNAME = 'units'
FILLVALUE_ATTNAME = '_FillValue'

DESCRIPTION_LONGNAME = 'Profile Description'
DESCRIPTION_DESCRIPTION = 'Description of atmospheric profile and modification'
DESCRIPTION_UNITS = 'N/A'
DESCRIPTION_FILLVALUE = ' '

....etc for other variables


Your example code works for me too. Hmmm....
>
> 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', ' '
> ncdf_control, ncid, /endef
> ncdf_close, ncid

AHA!!!

When I change your above test code to use the conventional fill value attribute name as
specified in the netCDF Interface Guide, "_FillValue", I get the following:

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', ' ' ; <---**** Note the attribute name
ncdf_control, ncid, /endef
ncdf_close, ncid

IDL> .run blah
% Compiled module: $MAIN$.
% NCDF_CONTROL: Attempt to take the file out of define mode (ENDEF) failed. (NC_ERROR=-45)
% Execution halted at: $MAIN$ 6 scratch/blah.pro


So:
- if I use "_fillvalue" for the attribute name, the code works fine.
- if I use "_FillValue" for the attribute name, the code crashes.

Given that netCDF attribute, dimension, and variable names are case-sensitive, this would
appear to be a bug....somehow.

Thanks for writing the little test case. I never would have figured it out otherwise.

cheers,

paulv

>
> and 'ncdump test.nc' produces:
>
> netcdf test {
> dimensions:
> dim1 = 32 ;
> dim2 = 9 ;
> variables:
> char absorber_units_name(dim2, dim1) ;
> absorber_units_name:_fillvalue = " " ;
> data:
>
> absorber_units_name =
> "",
> "",
> "",
> "",
> "",
> "",
> "",
> "",
> "" ;
> }
>
> NCDF_VARDEF does not print an error message, it returns -1 on failure :-(
>
> regards,
> lajos
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Are user-defined private methods possible?
Next Topic: IDL 7.1 dialog_pickfile segmentation fault

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:20:05 PDT 2025

Total time taken to generate the page: 0.00444 seconds