! TITLE:  ifany.mac (MANAGEMENT)
!
!   - Add error checking
!   - Add message report of result, last arg to match, # to match, and if
!     any bad matches.  Slows down for stats because doesn't exit once find
!     first comparison.
!   - Do not print notes if /nopr was active prior to command.
!
! OBJECTIVE:
!
!   Compares string or number with list via logic symbol
!   Compares ARG1 to ARG3 thru ARG9 and if any compare per ARG2 logic then
!   the variable ifany = 1 otherwise ifany = 0.
!
! COMMAND SYNTAX:      
!
!   ifany,ARG1,ARG2,ARG3,....   
!
! ARGUMENTS:
!
!   ARG1 is normally a number or string variable.   
!   ARG3 thru ARG? can be either a number or string.  Strings must be in single
!   quotes and are limited to 8 characters with the usual ANSYS string restrictions.
!
!   ARG2 can be any of the following logical abbreviations
!      'EQ' = equal
!      'NE' = not equal
!      'LT' = less than
!      'GT' = greater than
!      'LE' = less than or equal
!      'GE' = greater than or equal
!      'ABLT' = absolute values less than (numbers only)
!      'ABGT' = absolute values greater (numbers only)
!     
! DESCRIPTION:
!
!   Compares ARG1 to ARG3 thru ARG9 and if any compare per ARG2 logic then
!   the variable ifany = 1 otherwise ifany = 0.  
!
! WARNING:
!
!   - The command line must be less than 64? characters long or it will be cut off.
!
! EXAMPLES:
!
!   see below
!
! TO BE DONE:
!
!  - Warn if cut off because command line too long.
!  - Create another similar macro to search arrrays.  Items in list can be scalars or arrays.  
!    If an array name is the same as a character scalar, the argument will be assumed to refer 
!    to the array and not the scalar? 
!
*GET,AR91,CMD,0,NARGS      !Field number of last non-blank field on the previous command.
!                          !for macros includes macroname as field
!
*GET,AR67,ACTIVE,,PRKEY
/NOPR

skip=1
*IF,skip,EQ,0,THEN
   ifany,'zebra','EQ','cat','dog','elephant','hippopatomous','zebra'
   ! will set ifany = 1 because 'zebra' is equal to at least one of the ARG3 thru ARG9 inputs.

   animal='hippo'
   ifany,animal,'EQ','cat','dog','hippopatomous'
   ! will set ifany = 0 because 'hippo' is not equal to at any of the ARG3 thru ARG9 inputs.

   animal='hippo' $match=animal
   ifany,animal,'EQ','cat','dog','hippo',match
   ! will set ifany = 1 because 'hippo'='hippo' and match='hippo'

   ifany,'zebra','EQ',1,'dog','elephant','hippopatomous','zebra'
   ! will set ifany = 1 but will report a bad match due to ARG3 = scalar

*ENDIF
*set,skip
ifany=0

!- ARG1 parameter type
*GET,AR80,PARM,ARG1,TYPE
!  Parameter type: 0=scalar, 1=array, 2=table, 3=character scalar, 
!                  4=character array, -1=undefined Parameter

!- Check if comparison argument valid and if not abort
*IF,ARG2,EQ,'EQ',OR,ARG2,EQ,'NE',THEN
*ELSEIF,ARG2,EQ,'LT',OR,ARG2,EQ,'GT',THEN
*ELSEIF,ARG2,EQ,'LE',OR,ARG2,EQ,'GE',THEN
*ELSEIF,ARG2,EQ,'ABLT',OR,ARG2,EQ,'ABGT',THEN
   *IF,AR80,EQ,0,THEN
   *ELSE
      AR99=1   !'abort'
      *MSG,WARN,ARG2
      Argument 1 is not a scalar, therefore cannot use %C.
   *ENDIF
*ELSE
   AR99=1      !'abort'
   *MSG,WARN
   The logical operator provided in argument 2 is not valid. %/&
   Hint: must put single quotes around operator abbreviation. %/&
   (e.g. 'EQ','NE','LT','GT','LE','GE','ABLT','ABGT')
*ENDIF

*IF,AR99,NE,1,THEN    !don't abort
   !- Compare ARG1 to ARG3 thru ...
   !- Check each argument before compare to make sure that it is a valid comparison
   !    (e.g. character to character, scalar to scalar)
   *DO,AR50,3,AR91-1
     *IF,AR50,GE,10,THEN
        *GET,AR81,PARM,AR%AR50%,TYPE
        *IF,AR81,EQ,AR80,THEN
           *IF,ARG1,%ARG2%,AR%AR50%,THEN
               ifany=1
               AR97=AR50  !an argument # which matched
               AR96=AR96+1  !count of how many matched
           *ENDIF
        *ELSE
           AR98=AR98+1   !'badmatch'
           *MSG,WARN,AR50
           The parameter type of argument %I does not match the %/&
           the parameter type of argument 1.  These arguments were %/&
           not compared.  Please review and correct.
        *ENDIF
     *ELSEIF,AR50,LT,10,THEN
        *GET,AR81,PARM,ARG%AR50%,TYPE
        *IF,AR81,EQ,AR80,THEN
           *IF,ARG1,%ARG2%,ARG%AR50%,THEN
               ifany=1
               AR97=AR50      !an argument # which matched
               AR96=AR96+1    !count of how many matched
           *ENDIF
        *ELSE
           AR98=AR98+1    !'badmatch'
           *MSG,WARN,AR50
           The parameter type of argument %I does not match the %/&
           the parameter type of argument 1.  These arguments were %/&
           not compared.  Please review and correct.
        *ENDIF
     *ENDIF
   *ENDDO
   !- Report findings and whether any badmatches
      *IF,ifany,EQ,1,THEN
         *MSG,NOTE,ifany,AR96,AR97,AR98
         ifany = %I. %/&
         There was %I match(es) with the last match being argument %I.%/&
         There was %I argument(s) whose parameter type did not match ARG1%/&
         See Warnings above.
      *ELSE
         *MSG,NOTE,ifany,AR96,AR97,AR98
         ifany = %I. %/&
         There were no matches. %/&
         There was %I argument(s) whose parameter type did not match ARG1%/&
         See Warnings above.
      *ENDIF
      *IF,ifany,EQ,1,THEN
         *MSG,NOTE,ifany,AR96,AR97
         ifany = %I. %/&
         There was %I match(es) with the last match being argument %I.
      *ELSE
         *MSG,NOTE,ifany,AR96,AR97
         ifany = %I. %/&
         There were no matches.
      *ENDIF
   *ENDIF
*ENDIF  !(AR99=abort)

*IF,AR67,EQ,1,THEN
  /GOPR
*ENDIF