stdlib_lsame Function

public pure function stdlib_lsame(ca, cb)

LSAME returns .TRUE. if CA is the same letter as CB regardless of case.

Arguments

Type IntentOptional Attributes Name
character(len=1), intent(in) :: ca
character(len=1), intent(in) :: cb

Return Value logical(kind=lk)


Source Code

     pure logical(lk) function stdlib_lsame(ca,cb)
     !! LSAME returns .TRUE. if CA is the same letter as CB regardless of
     !! case.
        ! -- reference blas level1 routine --
        ! -- reference blas is a software package provided by univ. of tennessee,    --
        ! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
           ! Scalar Arguments 
           character, intent(in) :: ca, cb
       ! =====================================================================
           ! Intrinsic Functions 
           intrinsic :: ichar
           ! Local Scalars 
           integer(ilp) :: inta, intb, zcode
           ! test if the characters are equal
           stdlib_lsame = ca == cb
           if (stdlib_lsame) return
           ! now test for equivalence if both characters are alphabetic.
           zcode = ichar('Z')
           ! use 'z' rather than 'a' so that ascii can be detected on prime
           ! machines, on which ichar returns a value with bit 8 set.
           ! ichar('a') on prime machines returns 193 which is the same as
           ! ichar('a') on an ebcdic machine.
           inta = ichar(ca)
           intb = ichar(cb)
           if (zcode==90 .or. zcode==122) then
              ! ascii is assumed - zcode is the ascii code of either lower or
              ! upper case 'z'.
               if (inta>=97 .and. inta<=122) inta = inta - 32
               if (intb>=97 .and. intb<=122) intb = intb - 32
           else if (zcode==233 .or. zcode==169) then
              ! ebcdic is assumed - zcode is the ebcdic code of either lower or
              ! upper case 'z'.
               if (inta>=129 .and. inta<=137 .or.inta>=145 .and. inta<=153 .or.inta>=162 .and. &
                         inta<=169) inta = inta + 64
               if (intb>=129 .and. intb<=137 .or.intb>=145 .and. intb<=153 .or.intb>=162 .and. &
                         intb<=169) intb = intb + 64
           else if (zcode==218 .or. zcode==250) then
              ! ascii is assumed, on prime machines - zcode is the ascii code
              ! plus 128 of either lower or upper case 'z'.
               if (inta>=225 .and. inta<=250) inta = inta - 32
               if (intb>=225 .and. intb<=250) intb = intb - 32
           end if
           stdlib_lsame = inta == intb
           ! return
     end function stdlib_lsame