[Thread Prev][Thread Next][Index]

Re: [ferret_users] existence of elements in array



Hi,

The function IS_ELEMENT_OF_STR_N  does case-insensitive string matching:

yes? show function is_element*
IS_ELEMENT_OF(VAR,VALUES)
    Returns 1 if first argument contains any of the values in argument 2, else 0
    VAR: data to test
    VALUES: values to search for
IS_ELEMENT_OF_STR(VAR,VALUES)
    Returns 1 if first argument contains any of the values in 2nd argument (case sensitive), else 0
    VAR: string (STRING)
    VALUES: strings to search (STRING)
IS_ELEMENT_OF_STR_N(VAR,VALUES)
    Returns 1 if 1st arg contains any of the values in 2nd arg, 2 if case-insensitve match, else 0
    VAR: string (STRING)
    VALUES: strings to search (STRING)


yes? list/nohead IS_ELEMENT_OF_STR ({"friend"}, {"Hello", "Friend"})
          0.0000

yes? list/nohead IS_ELEMENT_OF_STR_N ({"friend"}, {"Hello", "Friend"})
          2.000
yes? list/nohead IS_ELEMENT_OF_STR_N ({"Friend"}, {"Hello", "Friend"})
          1.000


I am working on revising the documentation to include all of the functions in Ferret, and to make the documentation of functions easier to navigate. SHOW FUNCTION from the Ferret command line always shows valid and up-to-date information; it is querying the definitions in the code itself.


On 6/16/2017 5:44 AM, Akshay Hegde wrote:
And other thing which you asked, as far as I know there is no "CASE / SWITCH" statement in Ferret, you have to manage with IF-ELIF-ELSE clause only, if you have PyFerret then inside external function you can use switch statement.

Regards,
Akshay Hegde,
Data and Information,



On Fri, Jun 16, 2017 at 6:04 PM, Marco van Hulten <Marco.Hulten@xxxxxx> wrote:
Hello Akshay,

On 16 Jun 17:45 Akshay Hegde wrote:
> Make use of "IS_ELEMENT_OF" function
>
> [root@localhost tmp]# f
>      NOAA/PMEL TMAP
>      FERRET v6.96
>      Linux 2.6.32-573.7.1.el6.x86_64 64-bit - 12/02/15
>      16-Jun-17 17:42
>
> yes? let aa = {1, 2, 3};
> yes? list IS_ELEMENT_OF(aa, 3)
>              VARIABLE : IS_ELEMENT_OF(AA, 3)
>              X        : 1
>           1.000
> yes? list IS_ELEMENT_OF(aa, 35)
>              VARIABLE : IS_ELEMENT_OF(AA, 35)
>              X        : 1
>           0.0000
> yes? IF `IS_ELEMENT_OF(aa, 35) NE 0` THEN
>  !-> IF 0 THEN
> yes? say 'exists'
> yes? ELSE
> yes? say 'does not exists'
> 'does not exists'
> yes? ENDIF
> yes?

Thank you, this works for number arrays!

I want to do the same for arrays of strings.  This function doesn't
take strings, but I found a very similar function for that:

    yes? let ss = {"a", "b", "c"};
    yes? list IS_ELEMENT_OF_STR(ss, "c")
                 VARIABLE : IS_ELEMENT_OF_STR(SS, "c")
                 X        : 1
              1.000
    yes?

Fantastic.

 - Marco



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

Privacy Policy | Disclaimer | Accessibility Statement