Re: filevarattdef - IO/API

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Fri, 16 Nov 2007 14:21:40 -0700

Neil,
Just to clarify this a bit:

You can write attributes to a NetCDF file without a NULL byte at the
end as long as you do
what Dennis suggests, which is first to create local NCL character
variables that do
not contain a NULL byte, using a technique such as Dennis
demonstrates below, then assign
all attributes using these character variables. You cannot use
literal strings in filevarattdef or
you will get the NULL byte.

I was not sure this actually worked so I just tested it and it does,
either by direct assignment
or by using fileattdef/filevarattdef.

A possible source of confusion is that if you read the file back in
using NCL the
attributes will appear to be of string type, but that is a conversion
that NCL does. In the
actual file the attributes will be character arrays.

  -dave

On Nov 15, 2007, at 5:44 PM, Dennis Shea wrote:

>
> Sorry, there is not enough information.
>
> Are you writing character variables to the netCDF file?
>
> Just FYI
>
> ncl 1> s = "test"
> ncl 2> c = stringtochar(s)
> ncl 3> print(c)
>
>
> Variable: c
> Type: character
> Total Size: 5 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> (0) t
> (1) e
> (2) s
> (3) t
> (4) 0x00 ; NCL adds the NULL to char variables
>
>
> ncl 4> nc = dimsizes( c )
> ncl 5> cNew = c(0:nc-2)
> ncl 6> print(cNew)
>
> Variable: cNew
> Type: character
> Total Size: 4 bytes
> 4 values
> Number of Dimensions: 1
> Dimensions and sizes: [4]
> Coordinates:
> (0) t
> (1) e
> (2) s
> (3) t
>
>
> Neil Davis wrote:
>> I am using NCL to manipulate some files which I then want to write
>> out in the IO/API netCDF format. This format has strict rules
>> about the size of the attributes associated with netCDF
>> variables. When I try to use the filevarattdef command to copy
>> the files over there is an extra "NULL" character which gets
>> included on the file variable's attribute even if I first trim it
>> from the NCL variable's attribute. Is there a way which I can
>> write a file variable's attribute that will not include this
>> "NULL" character, as currently I have to trim one of the
>> characters from the attribute to allow space for the "NULL"
>> Thanks,
>> Neil Davis
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 16 2007 - 14:21:40 MST

This archive was generated by hypermail 2.2.0 : Sun Nov 25 2007 - 07:21:25 MST