Skip to content

Commit d8931a6

Browse files
author
Damian Rouson
committed
feat(intrinsic_array_m): add 2D array support
1 parent d98f8a4 commit d8931a6

3 files changed

Lines changed: 91 additions & 59 deletions

File tree

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ 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(:,:)
1419
contains
1520
procedure :: as_character
1621
end type

src/intrinsic_array_s.F90

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
rank default
39+
error stop "intrinsic_array_t construct: unsupported rank"
40+
end select
41+
#endif
42+
43+
end procedure
44+
45+
module procedure as_character
46+
integer, parameter :: single_number_width=32
47+
48+
if (1 /= count( &
49+
[ allocated(self%complex_1D), allocated(self%integer_1D), allocated(self%logical_1D), allocated(self%real_1D) &
50+
,allocated(self%complex_2D), allocated(self%integer_2D), allocated(self%logical_2D), allocated(self%real_2D) &
51+
])) error stop "intrinsic_array_t as_character: ambiguous component allocation status."
52+
53+
if (allocated(self%complex_1D)) then
54+
character_self = repeat(" ", ncopies = single_number_width*size(self%complex_1D))
55+
write(character_self, *) self%complex_1D
56+
else if (allocated(self%integer_1D)) then
57+
character_self = repeat(" ", ncopies = single_number_width*size(self%integer_1D))
58+
write(character_self, *) self%integer_1D
59+
else if (allocated(self%logical_1D)) then
60+
character_self = repeat(" ", ncopies = single_number_width*size(self%logical_1D))
61+
write(character_self, *) self%logical_1D
62+
else if (allocated(self%real_1D)) then
63+
character_self = repeat(" ", ncopies = single_number_width*size(self%real_1D))
64+
write(character_self, *) self%real_1D
65+
else if (allocated(self%complex_2D)) then
66+
character_self = repeat(" ", ncopies = single_number_width*size(self%complex_2D))
67+
write(character_self, *) self%complex_2D
68+
else if (allocated(self%integer_2D)) then
69+
character_self = repeat(" ", ncopies = single_number_width*size(self%integer_2D))
70+
write(character_self, *) self%integer_2D
71+
else if (allocated(self%logical_2D)) then
72+
character_self = repeat(" ", ncopies = single_number_width*size(self%logical_1D))
73+
write(character_self, *) self%logical_2D
74+
else if (allocated(self%real_2D)) then
75+
character_self = repeat(" ", ncopies = single_number_width*size(self%real_2D))
76+
write(character_self, *) self%real_2D
77+
end if
78+
79+
character_self = trim(adjustl(character_self))
80+
end procedure
81+
82+
end submodule intrinsic_array_s

src/intrinsic_array_s.f90

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

0 commit comments

Comments
 (0)