File: functions_15.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 (56 lines) | stat: -rw-r--r-- 1,278 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module functions_15_module_1
implicit none

contains

    subroutine sub_1(a, b, c, d, e, f)
        integer, intent(inout) :: a
        real, intent(inout) :: b
        logical, intent(in) :: c
        real, intent(in), optional :: d
        integer, intent(in), optional :: e
        real, intent(in) :: f
        if (present(d)) then
            a = b ** 2 + d
            if (present(e)) then
                b = b * f + e
            else
                b = b * f
            end if
        else
            a = b ** 2
            if (present(e)) then
                b = b * f + e
            else
                b = b * f
            end if
        end if
    end subroutine sub_1
end module

program functions_15
use functions_15_module_1, only: sub_1
implicit none

    integer :: a
    real :: b
    a = 1
    b = 2
    call sub_1(a, b, .true., d=12.0, e=5, f=6.0)
    call sub_1(a, b, .false., f=6.0)
    call sub_1(a, b, .true., e=78, f=117.0)
    call sub_1(a, b, .false., d=58.0, f=123.0)
    print *, a, b
    if (a /= 144288208) error stop
    if (b /= 1477476.00) error stop

    print *, f(), f(42)      ! "f t"

contains

    logical function f(x)
        integer, intent(in), optional :: x
        f = present(x)
    end function

end program functions_15