Re: Netcdf output with non-numeric datatyep

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Fri May 02 2014 - 10:41:42 MDT

Liang,

I have re-checked the code I sent to ncl-talk.
It can write out a nc4 file, and ncdump works fine on this file
(see out put below).

The reason your ncdump did not work, is probably you do not have
netcdf4 enabled on your machine's netcdf installation.

It is true that ncl could not read this file.

The issue here is that ncl could use strings as coordinate variable to do anything
(and it crashed at this instance, which I did not think careful enough).

Here is an alternative script. Certainly this may not be what you want,
but that is what I can think of for now.

Regards,

Wei

--------

 fout = "out.nc"
 system("/bin/rm -f "+fout)
 setfileoption( "nc", "format", "netcdf4" )
 ncdf = addfile(fout,"c")

 mode = (/"Original value","Component 1","Component 2","Component 3","Component 4"/)
 time = (/0, 1, 2/)
 modenumber = ispan(0, dimsizes(mode) - 1, 1)

;print(modenumber)

 mode@long_name = "mode"
 mode@units = "M"

 modenumber@long_name = "mode number"
 modenumber@units = "None"

 mode!0 = "modenumber"
 mode&modenumber = modenumber

 time!0 = "time"
 time&time = time

 time@long_name = "time"
 time@units = "day"

 print("mode=" + mode)
 print("time=" + time)

 allmode = new((/dimsizes(modenumber), dimsizes(time)/), float)
 allmode = 9.9

 allmode(1,1) = 1.0
 allmode(1, 2) = 2.0

 allmode@long_name = "allmode"
 allmode@units = "mode/day"

 allmode!0 = "modenumber"
 allmode!1 = "time"
 allmode&modenumber = modenumber
 allmode&time = time

 ncdf->mode = mode
 ncdf->allmode = allmode

 delete(ncdf)

------------

cisl-huelva:/Users/huangwei/test/ncltest/ncl_liang 574 > ncl liang.ncl
 Copyright (C) 1995-2014 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.2.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
(0) mode=Original value
(1) mode=Component 1
(2) mode=Component 2
(3) mode=Component 3
(4) mode=Component 4
(0) time=0
(1) time=1
(2) time=2
cisl-huelva:/Users/huangwei/test/ncltest/ncl_liang 575 > ncdump out.nc
netcdf out {
dimensions:
        mode = 5 ;
        time = 3 ;
variables:
        string mode(mode) ;
                string mode:long_name = "mode" ;
                string mode:units = "M" ;
        int time(time) ;
                string time:long_name = "time" ;
                string time:units = "day" ;
        float allmode(mode, time) ;
                string allmode:units = "mode/day" ;
                string allmode:long_name = "allmode" ;
                allmode:_FillValue = 9.96921e+36f ;
data:

 mode = "Original value", "Component 1", "Component 2", "Component 3",
    "Component 4" ;

 time = 0, 1, 2 ;

 allmode =
  9.9, 9.9, 9.9,
  9.9, 9.9, 9.9,
  9.9, 9.9, 9.9,
  9.9, 9.9, 9.9,
  9.9, 9.9, 9.9 ;
}

On May 2, 2014, at 5:28 AM, "Liang Guo (Gmail)" <liang.guo.81@gmail.com> wrote:

> Hi Wei,
>
> This is very interesting idea, but unfortunately, there is something wrong with it.
>
> First of all, the code you shown me can be ran errorlessly. However, the output "out.nc" cannot be recognised, i.g., when I try *ncdump out.nc*, the error message is:
> ncdump: out.nc: NetCDF: Unknown file format
>
> And, when I try to read *out.nc* in NCL using code like:
> fi = addfile ("out.nc","r")
> allmode = fi->allmode
>
> The error is *Memory fault*.
>
> This is bizarre as NCL can create the file, but the file cannot be recognised by itself.
>
> Any idea about it?
>
> Regards,
> Liang
>
>
> On 14 Apr 2014, at 21:00, Wei Huang <huangwei@ucar.edu> wrote:
>
>> Liang,
>>
>> You may try something like:
>>
>> fout = "out.nc"
>> system("/bin/rm -f "+fout)
>> setfileoption( "nc", "format", "netcdf4" )
>> ncdf = addfile(fout,"c")
>>
>> mode = (/"Original value","Component 1","Component 2","Component 3","Component 4"/)
>> time = (/0, 1, 2/)
>>
>> mode@long_name = "mode"
>> mode@units = "M"
>>
>> mode!0 = "mode"
>> mode&mode = mode
>>
>> time!0 = "time"
>> time&time = time
>>
>> time@long_name = "time"
>> time@units = "day"
>>
>> print("mode=" + mode)
>> print("time=" + time)
>>
>> allmode = new((/dimsizes(mode), dimsizes(time)/), float)
>> allmode = 9.9
>>
>> allmode@long_name = "allmode"
>> allmode@units = "mode/day"
>>
>> allmode!0 = "mode"
>> allmode!1 = "time"
>> allmode&mode = mode
>> allmode&time = time
>>
>> ncdf->allmode = allmode
>>
>> delete(ncdf)
>>
>>
>> Wei
>>
>>
>> On Apr 7, 2014, at 8:18 AM, Liang Guo (Gmail) <liang.guo.81@gmail.com> wrote:
>>
>>> Dear NCL,
>>>
>>> I have a variable named *allmode(mode,time)*. For the dimension *mode*, I'd like to assign string value (/"Original value","Component 1","Component 2","Component 3","Component 4"/) instead of numeric value (/0,1,2,3,4/). Then, I try to write this variable into a Netcdf file. I wrote:
>>> > fout = "out.nc"
>>> > system("/bin/rm -f "+fout)
>>> > setfileoption( "nc", "format", "netcdf4" )
>>> > ncdf = addfile(fout,"c")
>>> > ncdf->mode = allmode
>>>
>>> However, file can not be created successfully, with error information as:
>>> warning:FileReadVarAtt: _FillValue attribute type differs from variable (mode) type in file (out), forcing type conversion; may result in overflow and/or loss of precision
>>> ncclose: ncid 393216: NetCDF: Can't open HDF5 attribute
>>>
>>> Does any has ideas how to write this file out?
>>>
>>> Regards,
>>> Liang
>>>
>>> _______________________________________________
>>> 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 Fri May 02 10:42:28 2014

This archive was generated by hypermail 2.1.8 : Sun May 04 2014 - 12:38:56 MDT