/I/J/K/L/M/N /X/Y/Z/T/E/F /RANGE= /NAME= /ANIMATE/LOOP=
Repeats a command or group of commands over a range of values along an axis.
yes? REPEAT/q=lo:hi[:increment] COMMAND yes? REPEAT/RANGE=lo:hi[:increment][/NAME=] COMMAND
A word of caution about REPEAT/RANGE. If you find yourself trying touse REPEAT to do regridding, or compute integrals or averages, or ifyou are doing some operation to every element of a variable along anaxis, you might want to rethink whether you are unnecessarilycomplicating your scripts by duplicating Ferret's capability to operateon entire grids or axes in a single command. Please read theintroductory sections including Thinking Like a Ferret, to review the way Ferret commands operate on entire variables over all or a portion of the grid on which they are defined.
The units of lo, hi, and increment are the units of the underlying grid axis if the qualifier is X, Y, Z, or T. The qualifiers I, J, K, or L advance the repeat loop by incrementing the indicated index (the default index increment is 1). Use SHOW GRID to examine the axis units (if the units are not displayed try CANCEL MODE LATITUDE, LONGITUDE, or CALENDAR as appropriate). To use an arbitrary loop counter use /RANGE=lo:hi:inc and optionally /NAME=string to name the loop counter. To run the loop from the highest value decreasing towards the lowest value, specify increment to be less than zero. Any command or group of commands that can be specified at the command line can also be given as an argument to REPEAT. If MODE VERIFY is SET, the current loop index is displayed at the console as REPEAT executes. The value of any symbols e.g. "($symbol)") that are used inside of REPEAT loops are re-translated at each repetition of the loop.
We can exit early from a REPEAT loop with the command EXIT/LOOP, stop execution of that loop and return to the level in Ferret which executed the loop. We can skip the remaining commands in a loop and return to the next iteration with the command EXIT/CYCLE. See the documentation on EXIT.
1) yes? REPEAT/L=1:240 CONTOUR/Y=30S:50N/X=130E:70W/LEV/FRAME sst
Produces a 240-frame movie of sea surface temperature. (note movies are discontinued with Ferret v6.6)
2) yes? REPEAT/Z=300:0:-30 GO compz
Executes the command file compz.jnl at Z=300, Z=270, ..., Z=0.
3) yes? REPEAT/L=1:250:5 (GO set_up; CONTOUR sst; FRAME/file=sst`l`.gif)
Repeats three commands‚Äîexecution of a GO script, CONTOUR, and FRAME‚Äîfor each timestep specified.
4) yes? CANCEL MODE verify
yes? REPEAT/RANGE=1:100:5/NAME=m \
(USE wind_`m`.nc; \
LIST/NOHEAD wspd[X=@AVE,Y=@AVE,Z=@AVE,T=@AVE]; \
CANCEL DATA wind_`m`)
Uses REPEAT/RANGE to open a set of data files, and do computations in all four dimensions. (Note that the m here is just a variable, not the pseudo-variable for the E axis which is _M.)
5) yes? LET num_ens = `var,return=msize`
For each member of an ensemble, make an XY plot of its time-average.
6) See also the examples in the section on "Animations"
Command qualifiers for REPEAT:
Repeats the requested command(s) for the specified range of axis subscripts (I, J, K, L, M, or N) or axis coordinates (X, Y, Z, T, E or F). Note that when T or F axis limits are specified as dates, the units of increment are hours.
The /ANIMATE qualifier creates an animation on the fly. In a Ferret session, display an animation with the command,
to start an animation sequence. Given LOOP=n, the animation sequence will repeat n times.
yes? USE coads_climatology yes? REPEAT/L=1:12/ANIMATE/LOOP=5 (SHADE sst; GO fland)
For a general discussion of animations, see the chapter "Animations and GIF Images"
NOTE: In order to properly display on SGI's, it is necessary to have backing store enabled for the Xserver.
(Introduced in Ferret version 5.6) Repeats a command or group of commands over an arbitrary range of values. /RANGE= may be used with /NAME= to give a name to the repeat counter. The syntax is:
yes? REPEAT/RANGE=LO:HI[:INC] ! for an unnamed loop counter yes? REPEAT/RANGE=LO:HI[:INC]/NAME=string ! for a named loop counter
If INC is not specified the increment is 1. If LO is larger than HI and INC is negative, then the loop is executed on decreasing values of the counter. If LO is larger than HI and INC is positive, the loop is not executed (or if LO is less than HI and INC is negative, the loop is not executed). The syntax can be used to create nested loops, including nesting with REPEAT /I/J/K/L/M/N or /X/Y/Z/T/E/F commands.
REPEAT/RANGE=LO:HI[:INC]/NAME=var assigns the name "var" to the repeat counter so it may be used within the commands to be executed. when /NAME is used, the values of LO:HI:[INC[ must be integers (analogous to REPEAT/I= or /J= etc). After the REPEAT terminates, this variable is undefined.
Example 1) Factorial calculation with REPEAT/RANGE
yes? ! Factorial yes? CANCEL MODE verify yes? LET a = 0; LET f = 1 yes? REPEAT/RANGE=1:8 ( LET a = `a+1`;LET f = `f*a`;\ LIST/NOHEAD/FORMAT=(F3.0," factorial", F7.0) a, f ) 1. factorial 1. 2. factorial 2. 3. factorial 6. 4. factorial 24. 5. factorial 120. 6. factorial 720. 7. factorial 5040. 8. factorial 40320.
Example 2) REPEAT/RANGE=/NAME= with a nested repeat. The first two commands are not executed, their LO:HI:INC ranges indicate that no repeat is to be done.
yes? rep/range=3:7:-1/name=s (list s) yes? rep/range=3:-3:3/name=s (list s) yes? rep/range=3:-3:-3/name=s (rep/range=1:2/name=tt list s + sin(tt)) !-> REPEAT: S:3 !-> REPEAT: TT:1 VARIABLE : S + SIN(TT) 3.841 !-> REPEAT: TT:2 VARIABLE : S + SIN(TT) 3.909 !-> REPEAT: S:0 !-> REPEAT: TT:1 VARIABLE : S + SIN(TT) 0.8415 !-> REPEAT: TT:2 VARIABLE : S + SIN(TT) 0.9093 !-> REPEAT: S:-3 !-> REPEAT: TT:1 VARIABLE : S + SIN(TT) -2.159 !-> REPEAT: TT:2 VARIABLE : S + SIN(TT) -2.091
Example 3) The REPEAT/RANGE counter is unaffected by whether a dataset is open, or a region has been set. Here we use the @MIN and @MAX transformations and the INT function to set the minimum and maximum for the range counter, and plot the MAX function computed using the range counter variable.
yes? USE levitus_climatology yes? SET REGION/x=100:300/Y=0/Z=10 yes? PLOT temp yes? LET r1 = INT( temp[X=@MIN]) + 1 yes? LET r2 = INT( temp[X=@MAX]) - 1
yes? REPEAT/RANGE=`r1`:`r2`:3/NAME=tt (PLOT/OVER MAX(temp,`tt`) ) !-> rep/range=18:28:3/name=tt (plot/over max(var,`tt`) ) !-> REPEAT: TT:18 !-> plot/over max(var,18) !-> REPEAT: TT:21 !-> plot/over max(var,21) !-> REPEAT: TT:24 !-> plot/over max(var,24) !-> REPEAT: TT:27 !-> plot/over max(var,27)