File: arrays_30.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 (50 lines) | stat: -rw-r--r-- 1,969 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
program arrays_30
implicit none
   integer    :: i1(64) = [  479,  735, -870,  410, 446, -627,  879,  -72, &
                            -948,  693,  133, -672, 897, -227,  965,    9, &
                               0,  997,  721, -240, 765, -426,  361,  751, &
                             669,  -94,  534,  806, -23,  844,  246, -114, &
                             673, -445,  654, -274, -53,  505, -414,  269, &
                            -345,  268, -544,  629, 353, -808,  199,  322, &
                             995, -697,  290, -514, 350, -777,  664,  195, &
                            -401,  348,   86, -620, 153,  144,   65, -431  ]
   integer    :: i2(4, 16)
   integer    :: i3(2, 4, 8)
   integer    :: i4(2, 4, 2, 4)
   integer    :: res_01(1), res_02(2), res_03(3), res_04(4)
   integer    :: max = 997

   i2 = reshape(i1, [4, 16])
   i3 = reshape(i1, [2, 4, 8])
   i4 = reshape(i1, [2, 4, 2, 4])

   res_01 = maxloc(i1)
   res_02 = maxloc(i2)
   res_03 = maxloc(i3)
   res_04 = maxloc(i4)

   if (maxloc(i1, 1) /= 18) error stop
   if (i1(res_01(1)) /= max) error stop
   if (i2(res_02(1), res_02(2)) /= i1(res_01(1))) error stop
   if (i3(res_03(1), res_03(2), res_03(3)) /= max) error stop
   if (i4(res_04(1), res_04(2), res_04(3), res_04(4)) /= max) error stop

   res_01 = shape(maxloc(i1))
   if (res_01(1) /= 1) error stop
   res_01 = shape(maxloc(i2, 1))
   if (res_01(1) /= 16) error stop
   res_02 = shape(maxloc(i3, 2))
   if (res_02(1) /= 2 .or. res_02(2) /= 8) error stop
   res_03 = shape(maxloc(i4, 3))
   if (res_03(1) /= 2 .or. res_03(2) /= 4 .or. res_03(3) /= 4) error stop

   if (size(maxloc(i2, 2)) /= 4) error stop
   if (size(maxloc(i3, 3)) /= 8) error stop
   if (size(maxloc(i4, 4)) /= 16) error stop

   res_04 = maxloc(i2, 2)
   if (i2(1, res_04(1)) /= 995) error stop
   if (i2(2, res_04(2)) /= max) error stop
   if (i2(3, res_04(3)) /= 965) error stop
   if (i2(4, res_04(4)) /= 806) error stop
end program arrays_30