File: arrayelements1.f90

package info (click to toggle)
lfortran 0.58.0-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 54,508 kB
  • sloc: cpp: 162,179; f90: 68,251; python: 17,476; ansic: 6,278; yacc: 2,334; sh: 1,317; fortran: 892; makefile: 34; javascript: 15
file content (50 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (4)
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
module my_subs
implicit none
interface my_sum
  module procedure sum_real, sum_int
end interface my_sum
contains
    subroutine sum_real (array, tot)
       real, dimension(:), intent (in) :: array
       real, intent (out) :: tot
       integer :: i
       tot = 1.0
       do i=1, size (array)
          tot = tot * array (i)
       end do
    end subroutine sum_real

    subroutine sum_int (array, tot)
       integer, dimension(:), intent (in) :: array
       integer, intent (out) :: tot
       integer :: i
       tot = 0
       do i=1, size (array)
          tot = tot + array (i)
       end do
    end subroutine sum_int

end module my_subs

program test_dt
use my_subs
implicit none
    type my_type
       integer weight
       real length
    end type my_type
    type (my_type), dimension (:), allocatable :: people
    type (my_type) :: answer
    allocate (people (2))

    people (1) % weight = 1
    people (1) % length = 1.0
    people (2) % weight = 2
    people (2) % length = 2.0

    call my_sum ( people (:) % weight, answer % weight )
    write (*, *)  answer % weight

    call my_sum ( people (:) % length, answer % length )
    write (*, *)  answer % length
end program test_dt