Skip to content

Commit 7ca9c30

Browse files
author
Damian Rouson
authored
Merge pull request #8 from sourceryinstitute/nag-workaround
Add multidimensional array support and work around missing assumed-rank in NAG
2 parents 9d46eb8 + 2a633ff commit 7ca9c30

7 files changed

+153
-55
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ build
3434
*.exe
3535
*.out
3636
*.app
37+
38+
# FORD-generated documentation files
39+
doc/html

doc-generator.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
project: Assert library
3+
summary: A toolkit for checking runtime assertions.
4+
src_dir: src/
5+
exclude_dir: doc
6+
output_dir: doc/html
7+
preprocess: true
8+
macro: FORD
9+
preprocessor: gfortran -E
10+
display: public
11+
protected
12+
private
13+
source: true
14+
graph: true
15+
md_extensions: markdown.extensions.toc

src/assert_s.f90 renamed to src/assert_s.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656

5757
end if toggle_assertions
5858

59+
#ifndef FORD
5960
contains
61+
#else
62+
end procedure
63+
#endif
6064

6165
pure function string(numeric) result(number_as_string)
6266
!! Result is a string represention of the numeric argument
@@ -82,6 +86,8 @@ pure function string(numeric) result(number_as_string)
8286

8387
end function string
8488

89+
#ifndef FORD
8590
end procedure
91+
#endif
8692

8793
end submodule

src/intrinsic_array_m.f90 renamed to src/intrinsic_array_m.F90

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ module intrinsic_array_m
77
public :: intrinsic_array_t
88

99
type, extends(characterizable_t) :: intrinsic_array_t
10-
complex, allocatable :: c(:)
11-
integer, allocatable :: i(:)
12-
logical, allocatable :: l(:)
13-
real, allocatable :: r(:)
10+
complex, allocatable :: complex_1D(:)
11+
integer, allocatable :: integer_1D(:)
12+
logical, allocatable :: logical_1D(:)
13+
real, allocatable :: real_1D(:)
14+
15+
complex, allocatable :: complex_2D(:,:)
16+
integer, allocatable :: integer_2D(:,:)
17+
logical, allocatable :: logical_2D(:,:)
18+
real, allocatable :: real_2D(:,:)
19+
20+
complex, allocatable :: complex_3D(:,:,:)
21+
integer, allocatable :: integer_3D(:,:,:)
22+
logical, allocatable :: logical_3D(:,:,:)
23+
real, allocatable :: real_3D(:,:,:)
1424
contains
1525
procedure :: as_character
1626
end type
@@ -19,7 +29,11 @@ module intrinsic_array_m
1929

2030
pure module function construct(array) result(intrinsic_array)
2131
implicit none
32+
#ifndef NAGFOR
2233
class(*), intent(in) :: array(..)
34+
#else
35+
class(*), intent(in) :: array(:)
36+
#endif
2337
type(intrinsic_array_t) intrinsic_array
2438
end function
2539

src/intrinsic_array_s.F90

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
submodule(intrinsic_array_m) intrinsic_array_s
2+
implicit none
3+
4+
contains
5+
6+
module procedure construct
7+
8+
#ifndef NAGFOR
9+
select rank(array)
10+
rank(1)
11+
#endif
12+
select type(array)
13+
type is(complex)
14+
intrinsic_array%complex_1D = array
15+
type is(integer)
16+
intrinsic_array%integer_1D = array
17+
type is(logical)
18+
intrinsic_array%logical_1D = array
19+
type is(real)
20+
intrinsic_array%real_1D = array
21+
class default
22+
error stop "intrinsic_array_t construct: unsupported rank-2 type"
23+
end select
24+
#ifndef NAGFOR
25+
rank(2)
26+
select type(array)
27+
type is(complex)
28+
intrinsic_array%complex_2D = array
29+
type is(integer)
30+
intrinsic_array%integer_2D = array
31+
type is(logical)
32+
intrinsic_array%logical_2D = array
33+
type is(real)
34+
intrinsic_array%real_2D = array
35+
class default
36+
error stop "intrinsic_array_t construct: unsupported rank-2 type"
37+
end select
38+
39+
rank(3)
40+
select type(array)
41+
type is(complex)
42+
intrinsic_array%complex_3D = array
43+
type is(integer)
44+
intrinsic_array%integer_3D = array
45+
type is(logical)
46+
intrinsic_array%logical_3D = array
47+
type is(real)
48+
intrinsic_array%real_3D = array
49+
class default
50+
error stop "intrinsic_array_t construct: unsupported rank-3 type"
51+
end select
52+
53+
rank default
54+
error stop "intrinsic_array_t construct: unsupported rank"
55+
end select
56+
#endif
57+
58+
end procedure
59+
60+
module procedure as_character
61+
integer, parameter :: single_number_width=32
62+
63+
if (1 /= count( &
64+
[ allocated(self%complex_1D), allocated(self%integer_1D), allocated(self%logical_1D), allocated(self%real_1D) &
65+
,allocated(self%complex_2D), allocated(self%integer_2D), allocated(self%logical_2D), allocated(self%real_2D) &
66+
])) error stop "intrinsic_array_t as_character: ambiguous component allocation status."
67+
68+
if (allocated(self%complex_1D)) then
69+
character_self = repeat(" ", ncopies = single_number_width*size(self%complex_1D))
70+
write(character_self, *) self%complex_1D
71+
else if (allocated(self%integer_1D)) then
72+
character_self = repeat(" ", ncopies = single_number_width*size(self%integer_1D))
73+
write(character_self, *) self%integer_1D
74+
else if (allocated(self%logical_1D)) then
75+
character_self = repeat(" ", ncopies = single_number_width*size(self%logical_1D))
76+
write(character_self, *) self%logical_1D
77+
else if (allocated(self%real_1D)) then
78+
character_self = repeat(" ", ncopies = single_number_width*size(self%real_1D))
79+
write(character_self, *) self%real_1D
80+
else if (allocated(self%complex_2D)) then
81+
character_self = repeat(" ", ncopies = single_number_width*size(self%complex_2D))
82+
write(character_self, *) self%complex_2D
83+
else if (allocated(self%integer_2D)) then
84+
character_self = repeat(" ", ncopies = single_number_width*size(self%integer_2D))
85+
write(character_self, *) self%integer_2D
86+
else if (allocated(self%logical_2D)) then
87+
character_self = repeat(" ", ncopies = single_number_width*size(self%logical_1D))
88+
write(character_self, *) self%logical_2D
89+
else if (allocated(self%real_2D)) then
90+
character_self = repeat(" ", ncopies = single_number_width*size(self%real_2D))
91+
write(character_self, *) self%real_2D
92+
end if
93+
94+
character_self = trim(adjustl(character_self))
95+
end procedure
96+
97+
end submodule intrinsic_array_s

src/intrinsic_array_s.f90

Lines changed: 0 additions & 51 deletions
This file was deleted.

test/unit-tests/designed-to-error-terminate.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ pure function both(lhs,rhs) result(lhs_or_rhs)
4343
subroutine co_all(boolean)
4444
logical, intent(inout) :: boolean
4545

46+
#ifndef NAGFOR
4647
call co_reduce(boolean, both)
48+
#else
49+
! Because parallel NAG runs happen in shared memory and because this function is called only once in
50+
! one test, a simplistic, non-scalable reduction algorithm suffices until co_reduce is supported.
51+
block
52+
logical, save :: my_boolean[*]
53+
integer i
54+
55+
my_boolean = boolean
56+
do i=1,num_images()
57+
my_boolean = my_boolean .and. my_boolean[i]
58+
end do
59+
end block
60+
#endif
4761

4862
end subroutine
4963

0 commit comments

Comments
 (0)