File: elemental_14.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 (45 lines) | stat: -rw-r--r-- 998 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
module elemental_14_mod
  implicit none

  type :: number_t
    real :: val
  contains
    procedure :: is_positive
  end type number_t

  type :: dec 
    type(number_t), allocatable :: nums(:)
  end type
contains

  elemental logical function is_positive(self)
    class(number_t), intent(in) :: self
    is_positive = self%val > 0.0
  end function is_positive

end module elemental_14_mod

program elemental_14
  use elemental_14_mod
  implicit none

  type(number_t), dimension(5) :: nums
  type(dec) :: ele
  logical :: result
  integer :: i
  nums(1)%val = -1.0
  nums(2)%val = -2.0
  nums(3)%val = -3.0
  nums(4)%val = -5.0
  nums(5)%val = -6.0
  result = any(nums%is_positive())
  if (result .neqv. .false.) error stop
  nums(1)%val = 1.0
  result = any(nums%is_positive())
  if (result .neqv. .true.) error stop
  allocate(ele%nums(2))
  ele%nums(2)%val = -1.0
  ele%nums(1)%val = -1.0
  result = any(ele%nums%is_positive())
  if (result .neqv. .false.) error stop
end program elemental_14