File: arrays_72.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 (54 lines) | stat: -rw-r--r-- 945 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
program arrays_72
implicit none

real :: xpt(5, 10)

xpt = 2.0
xpt(1, :) = 3.0
xpt(2, :) = 4.0
xpt(3, :) = 5.0
xpt(:, 4) = 6.0
xpt(:, 5) = 7.0
xpt(:, 6) = 8.0
xpt(:, 7) = 9.0

call initq(xpt)

contains

function diag(A) result(D)
implicit none

real(4), intent(in) :: A(:, :)
real(4), allocatable :: D(:)
integer :: dlen, i

dlen = max(0_4, int(min(size(A, 1), size(A, 2)) - 0, 4))
allocate(D(dlen))
D = [(A(i, i), i=1, dlen)]

end function diag

subroutine initq(xpt)
real(4), intent(in), target :: xpt(:, :)
real(4) :: xa(min(size(xpt, 1), size(xpt, 2) - size(xpt, 1) - 1))
real(4) :: xb(size(xa))

integer :: ndiag, n, npt

n = int(size(xpt, 1), kind(n))
npt = int(size(xpt, 2), kind(npt))

ndiag = min(n, npt - n - 1)

xa = diag(xpt(:, 2:ndiag + 1))
xb = diag(xpt(:, n + 2:n + ndiag + 1))

print *, xa
print *, xb
if( any(xa /= [3.0, 4.0, 6.0, 7.0]) ) error stop
if( any(xb /= [9.0, 4.0, 5.0, 2.0]) ) error stop

end subroutine

end program