Re: How to write string to netcdf output

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed, 12 Jul 2006 08:12:41 -0600 (MDT)

Yes, Kyle is correct.

Current versions of netCDF [3.x] do not support strings.
The next release of netCDF [netCDF4; 4.0] will.
     http://www.unidata.ucar.edu/software/netcdf/netcdf-4/

You will have to use "stringtochar" to write to netCDF.

Say you have a string variable "city" of length N.
Then the character equivalent will be 2D:

ncl 0> city = new(2,"string")
ncl 1> city(0)="Boston"
ncl 2> city(1)="San Diego"
ncl 3> CITY = stringtochar( city )
ncl 4> print(CITY)

Variable: CITY
Type: character
Total Size: 20 bytes
             20 values
Number of Dimensions: 2
Dimensions and sizes: [2] x [10]

Note that NCL [ for some reason :-( ] adds a 'end-of-line' character
at the end.

     CITY = stringtochar( city )
     CITY!0 = "city"
     CITY!1 = "maxLength"

     fnc = addfile ("FOO.nc", "c")
     fnc->city = CITY

good luck

On Wed, 12 Jul 2006, Kyle Wilcox wrote:

> Please someone correct me if I am wrong because I am no expert, but I
> don't believe strings are a data type supported by netCDF files. This
> dates back to FORTRAN not accepting variable-length character strings.
>
> What you need to do is translate the string into an array of character
> values and then output that array to the netCDF file.
>
> Hope this helps,
>
> Kyle Wilcox
> kyle.wilcox_at_noaa.gov
>
> Jax (Guangxia) Cao wrote:
>> Hi,
>>
>> I have used the following to write numerical arrays to netcdf and was
>> successful,
>> ......
>> a=addfile(fname, "c")
>> a->lwu10m = w10
>> a->lwulow = wlw
>> ....
>>
>> I tried similiar to write string arrays to the netcdf output
>> but failed and I approached other ways but not successful. I would
>> appreciate any suggestion.
>>
>> Thanks.
>>
>> Jax
>>
>> _______________________________________________
>> 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 Wed Jul 12 2006 - 08:12:41 MDT

This archive was generated by hypermail 2.2.0 : Thu Jul 13 2006 - 09:59:49 MDT