if-statementidl-programming-language

IDL Check if number in array


I'm very new to IDL.

Effectively what i want to do is have an if statement that checks if the current index I is in an array.

In Python it would look something like the following:

if this_num in xartifact:
   print 'Is an x artifact'
elif this_num in yartifact:
   print 'Is a y artifact'
else:
   print 'Is neither'

I know that you can nest ifs in IDL:

IF P1 THEN S1 ELSE $

IF P2 THEN S2 ELSE $

IF PN THEN SN ELSE SX

I just can't find out if there is an in operator or sane way of doing this.

Cheers


Solution

  • I would use the count parameter in WHERE similar to the above example:

    a = 2
    b = [1, 2, 3, 5]
    ind = where(a eq b, count)
    print, count gt 0 ? 'a in b' : 'a not in b'