[Thread Prev][Thread Next][Index]

Re: [ferret_users] Re: assign value to array element [was: concatenating strings with integers]



To these ends it'd be really nice in in the future Ferret could:

1) Add a left-zero-fill capability to the FLOATSTR() function, e.g.
with a leading-zero format like "(f05.3)"; and

2) Add an INTSTR() function, also with optional left-zero-filling:
"(i05)".  Or just add this functionality to FLOATSTR().

Until then, depending on your application you may find it useful to
use a shell tool like "seq" to generate a sequence of numbers, with or
without zero-filling:

yes? let a = {"one","two","three"}
yes? let b = spawn("seq -f %02.0f 1 3")
yes? list a + "_" + b
             VARIABLE : A + "_" + B
             SUBSET   : 3 points (X)
 1   / 1:"one_01"
 2   / 2:"two_02"
 3   / 3:"three_03"

Andrew

PS: Paulo & Marco, please note that the immediate-mode option is
actually "zw" (zero width), not "zf":

http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/variables-xpressions/EMBEDDED-XPRESSIONS#_VPINDEXENTRY_563

Though apparently Ferret will accept either, since there's no other
option starting with "z".


On Tue, Sep 22, 2015 at 10:38 AM, Paulo B. Oliveira <pboliveira@xxxxxxx> wrote:
> Hi Marco,
>
> One (quite dirty) way to use the very nice "ZF" option is to create a
> variable definition using recursion, that is, to force ferret to do
> something that's against its nature... (you must be very careful with the
> use of single and double quotes)
>
>
> let First = xsequence({ "one", "two", "three" })
> let Second= xsequence({ 1, 2, 3 })
>
> let third_def =  "xsequence({"
>
> repeat/i=1:`First,ret=iend` ( let third_def =  "`third_def`
> '`First`_`Second,zf=2`', "  )
>
> let third_def =  "`third_def` 'last_not_used_item'})"
> let third = `third_def`
>
> list third
>
> ..... of course you can make it even dustier and use conditions to exclude
> or remove the last closing element.
>
> Regards,
>
> Paulo
>
>
>
>
> On Tue, 2015-09-22 at 15:34 +0200, Marco van Hulten wrote:
>
> Hi Ferret users,
>
> I wanted to apply Paulo's xsequence/repeat solution on string-integer
> concatenation (to another problem that I will report on in a different
> post), but I found a problem.
>
> Le 2015-09-18 Paulo a écrit:
>> let First = xsequence({ "one", "two", "three" })
>> let Second= xsequence({ 1, 2, 3 })
>>
>> repeat/i=1:`First,ret=iend` ( let Third = "`First`_`Second,zf=2`" )
>
> We want Third to be an array, but it will be a scalar here, having the
> value of the last iteration.  How can one force Third to be an array,
> and the assignment to be one to the i'th array element?
>
> Marco
>
>



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

Privacy Policy | Disclaimer | Accessibility Statement