File: optional_01.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (38 lines) | stat: -rw-r--r-- 802 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
program optional_01
implicit none

character(len=1) :: response = "Y"
if (lower(response) /= 'y') error stop
print *, lower(response)

contains

elemental pure function lower(str, begin, end) result (string)
    character(*), intent(in) :: str
    character(len(str)) :: string
    integer, intent(in), optional :: begin, end
    integer :: i
    integer :: ibegin, iend

    string = str
    ibegin = 1
    if (present(begin)) then
        ibegin = max(ibegin, begin)
    end if

    iend = len_trim(str)
    if (present(end)) then
        iend = min(iend,end)
    end if

    do i = ibegin, iend
        select case (str(i:i))
            case ('A':'Z')
                string(i:i) = char(iachar(str(i:i)) + 32)
            case default
        end select
    end do

end function lower

end program