Manual Reference Pages  - iachar (3fortran)

NAME

IACHAR(3) - [CHARACTER:CONVERSION] Return integer ASCII code of a character

SYNOPSIS

result = iachar(c [,kind])

         elemental integer(kind=KIND) function iachar(c,kind)

character(len=1),intent(in) :: c integer(kind=**),intent(in),optional :: KIND

CHARACTERISTICS

o C is a single character
o The return value is of type integer and of kind KIND. If KIND is absent, the return value is of default integer kind.
NOTE: : a kind designated as ** may be any supported kind for the type

DESCRIPTION

IACHAR(3) returns the code for the ASCII character in the first character position of C.

OPTIONS

o C : A character to determine the ASCII code of. A common extension is to allow strings but all but the first character is then ignored.
o KIND : A constant initialization expression indicating the kind parameter of the result.

RESULT

the result is the position of the character C in the ASCII collating sequence. It is nonnegative and less than or equal to 127.

By ASCII, it is meant that C is in the collating sequence defined by the codes specified in ISO/IEC 646:1991 (International Reference Version).

The value of the result is processor dependent if C is not in the ASCII collating sequence.

The results are consistent with the LGE(3), LGT(3), LLE(3), and LLT(3) comparison functions. For example, if LLE(C, D) is true, IACHAR(C) <= IACHAR (D) is true where C and D are any two characters representable by the processor.

EXAMPLES

Sample program:

    program demo_iachar
    implicit none
       ! basic usage
        ! just does a string one character long
        write(*,*)iachar(’A’)
        ! elemental: can do an array of letters
        write(*,*)iachar([’A’,’Z’,’a’,’z’])

! convert all characters to lowercase write(*,’(a)’)lower(’abcdefg ABCDEFG’) contains ! pure elemental function lower(str) result (string) ! Changes a string to lowercase character(*), intent(In) :: str character(len(str)) :: string integer :: i string = str ! step thru each letter in the string in specified range do i = 1, len(str) select case (str(i:i)) case (’A’:’Z’) ! change letter to miniscule string(i:i) = char(iachar(str(i:i))+32) case default end select end do end function lower ! end program demo_iachar

Results:

     > 65
     > 65          90          97         122
     > abcdefg abcdefg

STANDARD

Fortran 95 , with KIND argument - Fortran 2003

SEE ALSO

ACHAR(3), CHAR(3), ICHAR(3)

See ICHAR(3) in particular for a discussion of converting between numerical values and formatted string representations.

Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), SCAN(3), VERIFY(3)
o NONELEMENTAL: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 iachar (3fortran) November 02, 2024
Generated by manServer 1.08 from bc968e0b-c89d-44a3-a2c2-bfdef1816f58 using man macros.