File: functions_21.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 (42 lines) | stat: -rw-r--r-- 940 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
pure integer function my_merge(val1, val2, mask) result(merged_value)
  integer, intent(in) :: val1, val2
  logical, intent(in) :: mask

  if (mask) then
    merged_value = val1
  else
    merged_value = val2
  end if

end function my_merge


program functions_21
complex, dimension(3, 3) :: y
complex :: res(3)

res = mean_2_cdp_cdp(y, 1, mask=.true.)
print *, res
print *, abs(sum(res))
if (abs(abs(sum(res)) - 526.008179) > 1e-8) error stop 

contains
function mean_2_cdp_cdp(x, dim, mask) result(res)
  complex, intent(in) :: x(:,:)
  integer, intent(in) :: dim
  logical, intent(in), optional :: mask
  complex :: res(my_merge(size(x, 1), size(x, 2), mask=1<dim))

  interface
    pure integer function my_merge(val1, val2, mask)
      implicit none
      integer, intent(in) :: val1, val2
      logical, intent(in) :: mask
    end function my_merge
  end interface

  res = (123.41, -124.55)

end function mean_2_cdp_cdp
end program