Re: writing and reading character arrays to netCDF

From: Jonathan Vigh <vigh_at_nyahnyahspammersnyahnyah>
Date: Thu, 05 Mar 2009 22:28:24 +0000

Hi again,

Interestingly, the el's don't appear if I don't predefine the _FillValue
attribute before writing out the data to the netCDF file. To make the
error go away when I read it in, I just have to delete the incorrect
_FillValue attribute and set it to the correct value (nullChar).

On the other front, it seems that logical variables are indeed converted
to integer type upon output to netCDF, but when they are read back in
from netCDF, NCL still sees them as integer type. (see below). I guess I
could write a simple function to transition this back to logical at the
reading stage.

Anyway, thanks for the help.

Jonathan

ncl 0> bb = new(4,logical)
ncl 1> bb(0) = True
ncl 2> bb(1) = False
ncl 3> bb(2) = True
ncl 4> print(bb)

Variable: bb
Type: logical
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes: [4]
Coordinates:
Number Of Attributes: 1
  _FillValue : -1
(0) True
(1) False
(2) True
(3) -1
ncl 5> fout = addfile("foo.nc","c")
fatal:Could not create (foo.nc)
ncl 6> fout = addfile("foos.nc","c")
ncl 7> fout->bb = bb
ncl 8> exit
[vigh_at_andrew ~]$ ncdump foos.nc
netcdf foos {
dimensions:
        ncl0 = 4 ;
variables:
        int bb(ncl0) ;
                bb:_FillValue = -1 ;
data:

 bb = 1, 0, 1, _ ;
}
[vigh_at_andrew ~]$ ncl
 Copyright (C) 1995-2008 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 5.0.1-beta
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
ncl 0> fin = addfile("foos.nc","r")
ncl 1> bb = fin->bb
ncl 2> print(bb)

Variable: bb
Type: integer
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes: [ncl0 | 4]
Coordinates:
Number Of Attributes: 1
  _FillValue : -1
(0) 1
(1) 0
(2) 1
(3) -1
ncl 3>

David Brown wrote:
>
> On Mar 5, 2009, at 1:16 PM, Jonathan Vigh wrote:
>
>>
>> Hi Dave,
>> Okay, thanks for letting me know. By the way, do logical values
>> automatically get transmorgified into 1's and 0's when NCL writes them
>> out to netCDF? I noticed that as well and was a bit mystified as to the
>> best way to write out logical arrays to netCDF files.
>>
>
> Since NetCDF does not have a logical type, NCL writes out logical data as
> integers. When read back into NCL, there is, unfortunately, no way to
> tell that these
> data were logical to begin with.
> However, if you read the data into a pre-defined logical array of the
> correct dimensions,
> I think it will be converted correctly.
> -dave
>
>
>> Jonathan
>>
>>
>> David Brown wrote:
>>>
>>> Hi Jonathan,
>>>
>>> I have reproduced your problem of have the _FillValue show up as lower
>>> case 'l'
>>> when reading the file into NCL, while ncdump shows it as a null
>>> character.
>>>
>>> This is a bug somewhere, probably in NCL. I will investigate.
>>> -dave
>>>
>>>
>>> On Mar 5, 2009, at 12:39 PM, Jonathan Vigh wrote:
>>>
>>>>
>>>> Greetings,
>>>> I'm using NCL to write out a character array to a netCDF flie and
>>>> then read it back in for processing using a different NCL script.
>>>> Some
>>>> of the time my arrays are all just _FillValue, which I have set to the
>>>> null character. However, if I dump the resulting netCDF file after
>>>> it is
>>>> written, these show up as lower case Ls (e.g. "l"). When I read the
>>>> netCDF file back in using my other script, the _FillValue attribute is
>>>> "l". This causes a warning message because I am trying to assign the
>>>> read data to a multidimensional array which already has a _FillValue
>>>> set to the null character. So I get the warning:
>>>>
>>>> fatal:Attribute assignment type mismatch
>>>>
>>>> Does anyone know about why this is happening? Does netCDF represent
>>>> the
>>>> null character as an "l"?
>>>>
>>>> Thanks,
>>>> Jonathan
>>>>
>>>> _______________________________________________
>>>> 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
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 05 2009 - 15:28:24 MST

This archive was generated by hypermail 2.2.0 : Thu Mar 05 2009 - 15:48:48 MST