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.
Linda, > To: address@hidden > cc: address@hidden, > cc: address@hidden > From: Linda Wharton <address@hidden> > Subject: Help needed with _FillValue attribute in NetCDFPerl > Organization: NOAA/FSL > Keywords: 200006282031.e5SKVxT26774 In the above message, you wrote: > I am trying to set the _FillValue of an unlimited character array to "NONE" > using NetCDFPerl and receive the following error: > > ncvarput: ncid 3: Not a netCDF data type > > Here is the code: > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > use NetCDF; > > my $flname = ""; > my $Num_Pireps = "UNLIMITED"; > my $Str3 = 1; > my $Str4 = 256; > > $flname = "xyz.ncf"; > $ncid = NetCDF::create($flname , NetCDF::CLOBBER); > NetCDF::setfill($ncid, NetCDF::FILL); > > # Define diminsions. > > $numpirID = NetCDF::dimdef($ncid, "Num_Pireps", $Num_Pireps); > die "Couldn't define numPireps diminsion\n" if $numpirID < 0; > > $str3ID = NetCDF::dimdef($ncid, "Str3_Lngth", $Str3); > die "Couldn't define third diminsion\n" if $str3ID < 0; > > $str4ID = NetCDF::dimdef($ncid, "Str4_Lngth", $Str4); > die "Couldn't define forth diminsion\n" if $str4ID < 0; > > # Define variables and attributes. > > $pitypeID = NetCDF::vardef($ncid, "pirep_type", NetCDF::CHAR, [$numpirID, > $str3ID]); > $N = "N"; > $attid = NetCDF::attput($ncid, $pitypeID, "_FillValue", NetCDF::CHAR, \$N); > > $rawID = NetCDF::vardef($ncid, "raw_pirep", NetCDF::CHAR, [$numpirID, > $str4ID]); > $attid = NetCDF::attput($ncid, $rawID, "long_name", NetCDF::CHAR, "Raw > Pirep"); > > $attid = NetCDF::attput($ncid, $rawID, "_FillValue", NetCDF::CHAR, "NONE"); > > NetCDF::endef($ncid); > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > I have tried: > > $nn = "NONE\0"; > $attid = NetCDF::attput($ncid, $rawID, "_FillValue", NetCDF::CHAR, \$nn); > > and > > $nn = "NONE\0"; > $attid = NetCDF::attput($ncid, $rawID, "_FillValue", NetCDF::CHAR, $nn); > > and > > $nn = 'NONE'; > $attid = NetCDF::attput($ncid, $rawID, "_FillValue", NetCDF::CHAR, \$nn); > > and > > $attid = NetCDF::attput($ncid, $rawID, "_FillValue", NetCDF::CHAR, 'NONE'); > > They all give the same error, which occurs as soon as the UNLIMITED dimension > expands to the first slot and tries to do the fill value. If I comment out > the _FillValue line, the code works. Attached is the output file after the > error occurs. > > > > I successfully executed the following $ptypeID code, with a one character > _FillValue, but it doesn't work with trying to _FillValue with a longer > string: > > $N = "N"; > $attid = NetCDF::attput($ncid, $pitypeID, "_FillValue", NetCDF::CHAR, \$N); > > > Can you please tell me what I'm missing, and perhaps where it's covered in > the > documentation? > > Thanks, > > Linda Wharton > Forecast Systems Lab, Boulder > address@hidden > 303-497-7239 The fill-value for a netCDF character variable is, necessarily, a single character value: multi-character strings won't work. If you want a fill-value that is other than the default fill-value for characters, then I suggest that you pass-in the integer value of the character you want for the fill-value. Regards, Steve Emmerson <http://www.unidata.ucar.edu>