File: procedure_19.f90

package info (click to toggle)
lfortran 0.60.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,416 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 38; javascript: 15
file content (37 lines) | stat: -rw-r--r-- 864 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
module mod1_procedure_19

   type :: my_type
    real :: value = 0.0
   contains
      procedure :: plus
      generic :: g_proc => plus
   end type my_type

contains

   subroutine plus(self, increment)
      class(my_type), intent(inout) :: self
      real, intent(in) :: increment
      self%value = self%value + increment
   end subroutine plus

end module mod1_procedure_19

module mod2_procedure_19
   use mod1_procedure_19
end module mod2_procedure_19

program procedure_19
    use mod2_procedure_19
    type(my_type) :: obj

    real :: test_increment = 5.0
   
    call obj%g_proc(test_increment)
    print *, 'After adding', test_increment, ':', obj%value
    if (abs(obj%value - 5.0) > 1.0e-6) error stop
   
    call obj%g_proc(3.0)
    print *, 'After adding 3.0:', obj%value
    if (abs(obj%value - 8.0) > 1.0e-6) error stop
end program procedure_19