[Thread Prev][Thread Next][Index]

Re: [ferret_users] reusing information from variable definitions



Hello—

On 11 Feb 03:09 Fiedler, Russell (O&A, Hobart) wrote:
> It looks like the /LIKE qualifier could be what you're after.
> 
> https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/commands-reference/DEFINE#_VPINDEXENTRY_1348
> 
> All attributes are inherited (apart from missing_value, scaling and offset). You can override some if you want.
> 
> e.g. (From the examples)
> 
> 
> 
> yes? let/like=temperature/title="Surface Temperature" sst = temperature[z=0:5@MAX]
> 
> so
> 
> let/like=aa bb=aa+666
> let/like=bb/title="`bb,return=original_definition`" cc = bb
> 
> which should be the same as
> 
> let/like=aa/title="`bb,return=original_definition`" cc = bb

Yes, this would be the solution to the problem that I stated.  The
/LIKE functionality is very useful.  But I forgot to mention something
that complicates the issue.  I will try to state the issue correctly
now.

Several datasets are loaded.  It is known that AA is in one of the
datasets but not in which one.  First, Tr is set as a function of AA:

    let Tr = AA + 123.

If I were to do

    let/like=AA Tr = AA + 123.

this would often result in failure as the current dataset may not be
containing AA.  This 'Tr' is a general variable that I refer to in
later scripts, but AA's name is only known at the stage of this command.

The next thing I do is check in which dataset Tr is available, so

    repeat/i=1:`ndsets` ( if `Tr,return=isReady` then ;\
        let ndset = `i` ;\
        exit/loop \
    )
    set data `ndset`

Note that I cannot determine 'ndsets' before defining Tr.  Only after
ndsets is determined, I can set attributes, e.g. like

    def attr Tr.units = "`AA.units`"

or, if not depending on current default dataset,

    def symb Ndset = `ndset`  ! avoid embedded ````
    def attr Tr.units = "`AA.units[d=($Ndset)]`"

or by redefining

    set data `ndset`
    let/like=AA Tr = AA + 123.

or, again not depending on current dataset (apparently both in the
/LIKE and the expression I must say what the right dataset is, which is
somewhat inconsistent as let Tr=AA; set data `ndset` works fine, i.e.,
without specifying the dataset in the expression):

    let/like=AA[d=`ndset`] Tr = AA[d=`ndset`] + 123.

But none of this would work, because I need to know the name of AA
(whether I set an attribute of Tr or redefine Tr with /LIKE).


I think the above is a MWE equivalent to what I try to accomplish in a
more complicated setting.  For further rationale of my challenge, I
explain it below concretely (see http://complot.nongnu.org/ for full
context).

One may ask why I want to refer to AA only once (let Tr = AA + 123.).
This is not just an issue of inelegant code duplication.  My main user
script is called with a tracer name argument, so in short this happens:

    def symb Tr = ($1)  ! user may have given "GbSi" as an argument
    
    let GbSi = GSi ! variable expected in one of the datasets
    let SbSi = BSi
    let TPoC = POC
    ...
    ! Here we determine where ($Tr) is in (ndset).
    ! And then we do the proper initialisation:
    set data `ndset`
    let/like=GSi Tr = ($Tr)
    !        ^^^
    !        this we don't know

Am I overlooking something obvious?

—Marco


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

Privacy Policy | Disclaimer | Accessibility Statement