Quick Demo: Cut and paste this in Ferret
repeat/k=8:11 list/nohead substring("`k+10^3`",2,3)
--------------------------------------------------
Hello All,
A situation that comes up fairly often for me is creating, within Ferret,
a set of filenames for I/O, for example "image_001.gif" ... "image_121.gif"
in creating the frames of an animation.
In this case a "clunky" solution would be
repeat/k=1:9 ( go ptest ; frame/file="image_00"`k`".gif ")
repeat/k=10:99 ( go ptest ; frame/file="image_0"`k`".gif" )
repeat/k=100:121 ( go ptest ; frame/file="image_"`k`".gif" )
where "go ptest" just generates a sample plot on the screen.
While it's not rocket science, and has probably been used by others, it just
struck me that the "substring" function is well-suited to this task (there
may be other simple(r) methods for which the appropriate 2x4 has not yet
impinged on my cranium).
The 3-digit "001" ... "121" can be generated by adding 1000=10^3 and lopping
off the leading "1", as in
repeat/k=1:121 list/nohead substring("`k+10^3`",2,3)
Here the 2 never changes - it just says "start with the 2nd character". The
3's specify the number of characters in the strings produced.
So to achieve the same result as the "clunky" three step frame naming above,
one could write
repeat/k=1:121 ( let id="image_"+substring("`k+10^3`",2,3)+".gif" ; go
ptest ; frame/file=`id` )
Hope this is of use to others, (and is not already in the user group
archives)
Mick