[ncl-talk] using attributes to define 2D arrays
Dennis Shea
shea at ucar.edu
Sun Aug 19 15:33:55 MDT 2018
A strength of NCL is that, the variable data structure adheres to the
classic netCDF variable data structure. ie: NCL variables 'look like'
netCDF variables. This includes following the variable rules established by
netCDF. One netCDF variable 'rule' is that a variable attribute can not
have an attribute. In short, there *can not* be an *'attribute cascade'*
[ie: attributes having attributes that have attributes .... etc)
*By default*, when the NCL *new*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/new.shtml> statement
is used as follows:
xxx = *new*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/new.shtml>((/nest,ndays/),"string")
*; no _FillValue specified *
it will *automatically create *a _FillValue appropriate to the variable
type.
To avoid this, as documented, you can specify *"No_FillValue" *and no
attribute will be created.
ncl 0> DATE = 0
ncl 1> nest = 2
ncl 2> ndays =3
ncl 3> DATE*@date* = new((/nest,ndays/),"string"*,"No_FillValue"*)
This *works *because the attribute '*date*' will *not itself have any
attribute*. ie: no attribute cascade.
-----
netCDF does **NOT* *support multi-dimensional attributes
*NCL allows the creation of multi-dimensional attributes within a script.*
Again .. no attributes can be associated with an attribute.
However, NCL does *NOT support directly accessing the multi-dimensional
attribute*.
The script must explicitly extract the attribute and make it a distinct
variable..
ncl 4> *date_att* = DATE at date ; extract the multidimensional
attribute to a variable
ncl 5> printVarSummary(date_att) ; two-dimensions
Variable: *date_att*
Type: string
Total Size: 48 bytes
6 values
Number of Dimensions: 2
Dimensions and sizes: *[2] x [3]*
Coordinates:
ncl 6> qqq = date_att(1,2) ; access an element of the
variable
ncl 7> QQQ = DATE at date(1,2) ; NCL does *not *support direct access
to an element
; within a
multidimensional attribute
*fatal:*Attributes only have one dimension, 2 subscripts used
*fatal:*["Execute.c":8638]:Execute: Error occurred at or near line 7
=============
A bit more:
As noted: Attributes can not have other attributes associated with them.
Also, attributes can not have named dimensions or coordinate variables.
=============
Hope this helps!
Cheers
D
On Sun, Aug 19, 2018 at 11:19 AM, Francesco Trotta <
francesco.trotta4 at unibo.it> wrote:
> Dear ncl-support,
>
> I'm using attributes to define 2D array but I get this error:
>
>
> fatal:Attributes only have one dimension, 2 subscripts used
> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 416 in
> file ./procPREPRO_surf.ncl
>
>
> Usually I define 1d array with attribute and it is all right but with 2d
> array the program stop.
>
> Here some lines of the code where the program stop:
>
>
> DATE at date = new((/nnest,ndays_max+15/),string,"")
> DATE at year = new((/nnest,ndays_max+15/),string,"")
> DATE at mounth = new((/nnest,ndays_max+15/),string,"")
> DATE at day = new((/nnest,ndays_max+15/),string,"")
>
> do inest=0,nnest-1
>
> ;compute date yyyymmdd of the simulation
> iday = 0
> DATE at date(inest,iday) = runMan_date000(inest)
>
> .......
>
>
>
> Can I define 2d array via attribute in ncl?
>
> If not, is there a way to define a data structure with heterogeneous
> multiple arrays 2d, 1d or scalar?
>
>
> Thanks
>
> Francesco
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180819/b2af2b17/attachment.html>
More information about the ncl-talk
mailing list