[Thread Prev][Thread Next][Index]

Re: string symbols



On Tue, 13 Mar 2001, Andrea Sardinha Taschetto wrote:
> My question is: 
> Is there any way to use recursive definitions and string symbols together? 
> Does anyone know how could I read and contour my data using something like:
> yes? REPEAT/l=1:5 (use data_($var`l`).cdf, contour ($var`l`)[l=1:12@ave])

Try placing the command inside a .jnl file:
-------------
! plot_it.jnl
use data_($var$1).cdf
contour ($var$1)[l=1:12@ave]
-------------
and then call it from inside the loop:

yes? REPEAT/l=1:5 (go plot_it `l`)

That should work.

Now the details... I think the problem here was that Ferret was looking
for a symbol named literally var`l`, not var1,var2,... as you intended.  
Ferret likes to evaluate string symbols right away, in this case before
the REPEAT even ran.  Since var`l` didn't exist, Ferret replaced it with a
blank.  Then the REPEAT command probably failed, since data_ .cdf didn't
exist.

If you run into this problem often and you don't want a lot of "plot_it"
scripts floating around, you might be interested in a simple tool called
"embed_sym.jnl" I wrote a while ago:

---------------
\can mode verify
! Usage: go embed_sym prefix symbol [suffix pre_space suf_space]
! Execute a command which is formed by embedding the symbol contents
! between a prefix string and a suffix string.  Useful in REPEAT commands,
! where immediate symbol evaluation sometimes causes problems.
!
! Ferret eats trailing spaces in string args, so the optional pre_space
! and suf_space arguments indicate whether a space should (1) or
! should not (0, default) be inserted after the prefix and before
! the suffix, respectively.

IF `$4"0"` THEN
   IF `$5"0"` THEN
      $1 ($$2) $3" "
   ELSE
      $1 ($$2)$3" "
   ENDIF
ELSE
   IF `$5"0"` THEN
      $1($$2) $3" "
   ELSE
      $1($$2)$3" "
   ENDIF
ENDIF

set mode/last verify
---------------

In your case I'd use this tool as follows:

yes? REPEAT/l=1:5 (go embed_sym "use data_" var`l` .cdf; 
       go embed_sym contour var`l` [l=1:12@ave] 1)

This may be overkill for your problem, but thought I'd pass it along!

Cheers,

Andrew

----------------------------------------------------------------------
Andrew Wittenberg          Program in Atmospheric and Oceanic Sciences
andyw@splash.princeton.edu                Sayre Hall, Forrestal Campus
                                                  Princeton University
                                              Princeton, NJ 08544-0710
----------------------------------------------------------------------



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement