[Thread Prev][Thread Next][Index]

Re: [ferret_users] records

Hi Marco,
The idea of using Python (perhaps via PyFerret) may be the most natural way to do these sorts of things.

CF doesn't have an explicit concept of a "structure", but of course there is a partial analog through the use of shared dimensions (in netCDF) or coordinate axes (in Ferret and CF).  String arrays and numeric arrays that share the same coordinate axes, or even multidimensional grids, will share the same coordinate-aware index space.

If we think of his variable "B" below as a named axis then, say,
define axis/x B={0.1, 0.2, 0.3}
let B_myy = I[gx=B]
let B_myx = RESHAPE({"first", "second", "third"}, B_myy)
So then, "second" is directly connected to "2"  through index x=0.2 of axis B, so that
LIST/X=0.2 B-myx, B_myy
will pick out the associated "structure" elements "second" and 2.  

Use of families of variable names helps with readability, and Ferret scripts might be used to abstract the definitions and then  define various versions of your structure.
let vstrings = {"first", "second", "third"}
let zlocations = {0.1, 0.2, 0.3}

go define_structure B vstrings, zlocations
where a script, define_structure.jnl takes the arguments and defines a set of variables.
! define_structure.jnl
! Arguments
!  1 name prefix
!  2 list of strings
!  3 locations

define axis/x ($1) = ($3)

let ($1)_myy = I[gx=($1)]
let ($1)_mxy = RESHAPE(($2), ($1)_myy)
show var ($1)*
would show,
 !-> sh var B*
 B_MYY = I[GX=B]

On 11/12/2015 3:07 AM, Marco van Hulten wrote:
Hi all,

Is it possible to define data structures that are more complex than
scalars and arrays?  I am talking about records [1], so e.g.

    let A.x = "some name"
    let A.y = 10
    let A.z = 3.14

Ultimately I'd like to define an array consisting of records:

    let B.x = {"first name", "second name", "third name"}
    let B.y = {1, 2, 3}
    let B.z = {0.1, 0.2, 0.3}

or the other way around starting with records and putting them in an

    let C = { A, A2, ... }

Note that none of the above command don't work in Ferret, but I hope it
is clear what I would like to do :-)


[1]: https://en.wikipedia.org/wiki/Record_(computer_science)#Examples

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement