Printing multi-dimensional variables

From: Jan Ploski <Jan.Ploski_at_nyahnyahspammersnyahnyah>
Date: Thu, 26 Jun 2008 17:34:01 +0200

Hello,

I have a feature request or question concerning pretty-printing of
multi-dimensional variables. Consider the following NCL script:

names = (/ "first", "second" /)
hours = (/ 0, 6, 12, 18 /)

var = new((/ 2, 4 /), float, -999.0)
var!0 = "name"
var!1 = "hour"
var&name = names
var&hour = hours

var({"first"},{0}) = 1
var({"first"},{6}) = 2
var({"first"},{12}) = 3
var({"first"},{18}) = 4
var({"second"},{12}) = 7
var({"second"},{18}) = 8

print(var)

The NCL output is:

Variable: var
Type: float
Total Size: 32 bytes
            8 values
Number of Dimensions: 2
Dimensions and sizes: [name | 2] x [hour | 4]
Coordinates:
            name: [first..second]
            hour: [0..18]
Number Of Attributes: 1
  _FillValue : -999
(0,0) 1
(0,1) 2
(0,2) 3
(0,3) 4
(1,0) -999
(1,1) -999
(1,2) 7
(1,3) 8

In this trivial example it may be easy to translate in your head (1,2) to
a particular combination of dimension names and coordinate values, but
when the variables get higher dimensionality and the size of dimensions
increases, you quickly get lost. In fact, I have a user who considers
turning away from NCL in favor of Fortran because of this lack of
comfortable output formatting (his other major trouble is understanding
slicing/hyperslab operations, but that can be only cured by practice IMO).
Anyway, what he'd like to see in the output is:

Variable: var
Type: float
Total Size: 32 bytes
            8 values
Number of Dimensions: 2
Dimensions and sizes: [name | 2] x [hour | 4]
Coordinates:
            name: [first..second]
            hour: [0..18]
Number Of Attributes: 1
  _FillValue : -999
(name=first,hour=0) 1
(name=first,hour=6) 2
(name=first,hour=12) 3
(name=first,hour=18) 4
(name=second,hour=12) 7
(name=second,hour=18) 8

That is, (optional) dimension names, (optional) coordinates translated
using the subscript variable, and missing values optionally left out of
the output.

I guess this kind of output would be rather easy to support in a future
version of NCL?... In the meanwhile, I'd like to ask which solution you
think would be easiest:
1) a custom NCL routine to be used instead of print
2) a custom Fortran routine to be used instead of print
3) hacking the NCL source of the print routine directly
4) writing an NCL wrapper/post-processor in Perl (that would require the
values of coordinate variables to be available somewhere in the output)

Regards,
Jan Ploski
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jun 26 2008 - 09:34:01 MDT

This archive was generated by hypermail 2.2.0 : Thu Jun 26 2008 - 16:29:44 MDT