File: arrays_op_1.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 (58 lines) | stat: -rw-r--r-- 1,134 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
55
56
57
58
program array_op_1
implicit none

integer :: a(4), b(4)
real :: c(4), d(4)
integer :: i, j

i = 0

! TODO: Include i + 4 in the end
! Should be ignored. Fix to be made
! in implied_do_loops.cpp.
a = [i + 1, (i + j, j = 1, i + 3)]

b = [4*a(i + 1), 5*a(i + 2), 6*a(i + 3), 7*a(i + 4)]

! c = [i + 1, (i*j, j = 1, i + 3)]

c(1) = i + 1
c(2) = i*1
c(3) = i*2
c(4) = i*3

print *, a(1), a(2), a(3), a(4)

print *, b(1), b(2), b(3), b(4)

print *, c(1), c(2), c(3), c(4)

d = a + b + c
print *, d(1), d(2), d(3), d(4)
if( d(1) /= 6.0 ) error stop
if( d(2) /= 6.0 ) error stop
if( d(3) /= 14.0 ) error stop
if( d(4) /= 24.0 ) error stop

d = a - b*c
print *, d(1), d(2), d(3), d(4)
if( d(1) /= -3.0 ) error stop
if( d(2) /= 1.0 ) error stop
if( d(3) /= 2.0 ) error stop
if( d(4) /= 3.0 ) error stop

d = a*b*c
print *, d(1), d(2), d(3), d(4)
if( d(1) /= 4.0 ) error stop
if( d(2) /= 0.0 ) error stop
if( d(3) /= 0.0 ) error stop
if( d(4) /= 0.0 ) error stop

d = (a*b)/(c + 1)
print *, d(1), d(2), d(3), d(4)
if( d(1) /= 2.0 ) error stop
if( d(2) /= 5.0 ) error stop
if( d(3) /= 24.0 ) error stop
if( d(4) /= 63.0 ) error stop

end program