Re: array of strings as an attribute

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 12 Nov 2007 09:17:22 -0700 (MST)

Hi Ozan,

You can't write strings to a netCDF file. This is a netCDF 3
limitation and not an NCL limitation. (With netCDF 4, you will be
allowed to write strings.)

For netCDF 3, strings have to be converted to characters first.

However, if you did this:

    names = (/"a","b","c","d"/)
    x_at_names_of_stations = stringtochar(names)

Then you would end up with a 2D array of character strings. I believe
an attribute of a variable cannot be anything bigger than a 1D array
in a netCDF 3 file (somebody correct me if I'm wrong).

So, perhaps this would work for you:

    names = "abcd"
    x_at_names_of_stations = stringtochar(names)

The problem here, though, is that if you read this back in with NCL,
"abcd" will be a single string, and not an array of strings
like you originally had it.

If you don't need to write "names" as an attribute of a variable, then
you can just write it as a variable directly. This way you *can* have
a 2D array of strings:

    names = (/"a","b","c","d"/)
    names_of_stations = stringtochar(names)

--Mary

On Mon, 12 Nov 2007, ozan mert gokturk wrote:

> Dear NCL Community,
>
> I would like to assign an array of strings to a
> variable as an attribute, and then output this
> variable as netCDF. The assignment of the attribute is
> successful, but when I output the variable as netCDF,
> only the first string in the array is written as the
> attribute!
>
> Here is my sample code:
>
> names = (/"a","b","c","d"/)
> x_at_names_of_stations = names
>
> When I print "x_at_names_of_stations" at this stage, it
> is fine. But when I write
>
> fout = addfile("mydata.nc","c")
> fout->data = x
>
> and then read this netCDF file, "mydata.nc", I see
> that only "a" is written as the "names_of_stations"
> attribute of "data".
>
> Do you have any idea to solve this problem?
>
> Thanks in advance
>
> Ozan
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> 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 Mon Nov 12 2007 - 09:17:22 MST

This archive was generated by hypermail 2.2.0 : Mon Nov 12 2007 - 09:17:56 MST