Re: Writing non-string variable attributes to netcdf files

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu Jan 20 2011 - 18:26:28 MST

Andrew,

Somehow in NCL you are assigning strings to these attributes, rather
than numeric values. This is where the quotes in the Netcdf file
are coming from.

Attributes in NCL have data types just like variables, e.g. string,
float, integer, etc. These are determined by the original
assignment statement such as:

   f->Lambert_Conformal@longitude_of_central_meridian = "297."

Try examining your source program carefully to find out why these
attributes are being created as string rather than numeric. This is
unusual, as Dennis's message implies. They may be "inherited" from
some other Netcdf file, in which case they should probably be
converted to numeric.

There is a workaround with functions like stringtofloat, but that
does not seem as good as fixing the problem at the source. But you
may be required to use the workaround if you have "inherited"
attributes. In this case you can not simply change the attribute
type in place, you must delete it first, then rewrite. Something
like the following should work for either a memory variable or a
file variable:

   temp = stringtofloat (var@longitude_of_central_meridian)
   delete ("var@longitude_of_central_meridian") ; remove string
attribute
   var@longitude_of_central_meridian = temp ; replace with float

--Dave

On 1/20/2011 5:35 PM, Andrew Monaghan wrote:
> Hello,
>
> I'm creating a netcdf file in which some of the variable attributes are
> real numbers (as opposed to strings), but when they are written to the
> netcdf output file with ncl, they have quotes around them. For example:
>
> Lambert_Conformal:longitude_of_central_meridian = "297." ;
>
> But what I want is (no quotes around 297):
>
> Lambert_Conformal:longitude_of_central_meridian = 297. ;
>
>
> I assume that most software can probably distinguish whether an
> attribute should be a real or a string value based on the attribute
> name, as long as its a standard cf-compliant attribute name. Therefore,
> having quotes around a real numbered attribute likely isn't an issue
> when reading the netcdf file into another piece of software. However,
> this isn't the case when reading netcdf files into ArcGIS -- it appears
> that ArcGIS requires that real-numbered attribute values not have
> quotes; otherwise any attribute with quotes is assumed to be a string
> and the data arrays are subsequently geo-located in the wrong place.
>
> Is there any way, in ncl, to write out certain attributes in netcdf
> files so that they do not have quotes around them?
>
> Thanks in advance for any insight you can provide.
>
> Sincerely,
> Andy Monaghan
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jan 20 18:26:34 2011

This archive was generated by hypermail 2.1.8 : Tue Jan 25 2011 - 14:22:15 MST