[Thread Prev][Thread Next][Index]

Re: PPL $element() within a repeat loop



Hi Arindam,
Thank you for the simple example in your question.  I don't
know of a way to use the ppl $element function inside the loop;
there may be a way, but you can do the same things using the
newer functions for string variables.  It takes a few more steps,
but this works:

! strr.jnl.
! Example:
!  Make a simple plot, then use the strr.jnl to put labels on it.
!     yes? plot/i=1:12 i
!     yes? go strr.jnl "1,1,First" "2,2,Second"
! string functions within a repeat loop
!
 def sym nplt = 2

 repeat/i=1:($nplt) ( \
  let tit = "$`i`"; \
  let it = strindex(tit,",");\
  let st1 = substring(tit,1,`it-1`);\
  let t1 = strfloat(st1);\
  let slen = strlen(tit);\
  let trem = substring(tit,`it+1`,slen);\
  let it = strindex(trem,",");\
  let st2 = substring(trem,1,`it-1`);\
  let t2 = strfloat(st2);\
  let t3 = substring(trem,`it+1`,slen);\
  list t1; \
  list t2; \
  list t3; \
  label/nouser 2,`t2`,0,0,0.2,"@P`t1``t3`"; \
)
! end of file strr.jnl


Arindam Chakraborty wrote:

> Hello Ferreters,
>         I'm facing a problem while trying to get a substring using
> ppl $element() within a repeat loop. To illustrate it, I'm showing a
> simple journal file here:
>
> yes? sp cat pplrep.jnl
> ! ppl $element within a repeat loop
>  can sym/all
>
>  def sym nplt = 2
>
> ! def sym tit = 1,2,My Title
> ! ppl set t3 $element(3,",",tit);
>
>  repeat/i=1:($nplt) ( \
>   def sym tit = $`i`; \
>   ppl set t1 $element(1,",",tit); \
>   ppl set t2 $element(2,",",tit); \
>   ppl set t3 $element(3,",",tit); \
>   label/nouser 2,2,0,0,0.2,@P($t1)($t3); \
>   say ($t1); \
>   say ($t2); \
>   say ($t3); \
>  )
> ! end of file pplrep.jnl
>
> Now,
>
> yes? go pplrep.jnl "1,1,First" "2,2,Second"
>
> does not put the text ("First" or "Second"). It is clear that all the
> three t1, t2 and t3 are null strings, whereas tit contains the correct
> string. I'm using Ferret 5.51 in RH Linux 8.0. The same file works very
> well with Ferret 5.33 for Linux 6.2 (as well in 8.0).
>
> If I break the repeat loop into $nplt number of grouped
> statements (those are within the loop), it works fine again with
> Ferret 5.51 (and 5.33). But for my application the value of nplt is
> supposed to change (mostly will be an input argument) and it is very
> clean to use the loop instead a bunch of repeating statements of the
> same kind.
>
> Any workaround is much appreciated. Many thanks in advance.
>
> Arindam
> ------------------------------------------
>  ARINDAM CHAKRABORTY
>  Centre for Atmospheric & Oceanic Sciences
>  Indian Institute of Science
>  Bangalore 560 012; INDIA
>  Tel: +91-80-3942505, +91-80-3600450
>  Fax: +91-80-3600865
> __________________________________________

--
Ansley Manke  Pacific Marine Environmental Laboratory  Seattle WA  (206)526-6246




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement