11submodule(intrinsic_array_m) intrinsic_array_s
2+ use assert_m, only : assert
23 implicit none
34
45contains
1112 select type (array)
1213 type is (complex )
1314 allocate (intrinsic_array% complex_1D, source = array)
15+ type is (complex (kind (1.D0 )))
16+ allocate (intrinsic_array% complex_double_1D, source = array)
1417 type is (integer )
1518 allocate (intrinsic_array% integer_1D, source = array)
1619 type is (logical )
1720 allocate (intrinsic_array% logical_1D, source = array)
1821 type is (real )
1922 allocate (intrinsic_array% real_1D, source = array)
2023 type is (double precision )
21- allocate ( intrinsic_array% double_precision_1D, source = array)
24+ intrinsic_array% double_precision_1D = array
2225 class default
23- error stop " intrinsic_array_t construct: unsupported rank-1 type"
26+ error stop " intrinsic_array_s( construct) : unsupported rank-1 type"
2427 end select
2528 rank(2 )
2629 select type (array)
2730 type is (complex )
2831 allocate (intrinsic_array% complex_2D, source = array)
32+ type is (complex (kind (1.D0 )))
33+ allocate (intrinsic_array% complex_double_2D, source = array)
2934 type is (integer )
3035 allocate (intrinsic_array% integer_2D, source = array)
3136 type is (logical )
3540 type is (double precision )
3641 allocate (intrinsic_array% double_precision_2D, source = array)
3742 class default
38- error stop " intrinsic_array_t construct: unsupported rank-2 type"
43+ error stop " intrinsic_array_s( construct) : unsupported rank-2 type"
3944 end select
4045
4146 rank(3 )
4247 select type (array)
4348 type is (complex )
4449 allocate (intrinsic_array% complex_3D, source = array)
50+ type is (complex (kind (1.D0 )))
51+ allocate (intrinsic_array% complex_double_3D, source = array)
4552 type is (integer )
4653 allocate (intrinsic_array% integer_3D, source = array)
4754 type is (logical )
5158 type is (double precision )
5259 allocate (intrinsic_array% double_precision_3D, source = array)
5360 class default
54- error stop " intrinsic_array_t construct: unsupported rank-3 type"
61+ error stop " intrinsic_array_s( construct) : unsupported rank-3 type"
5562 end select
5663
5764 rank default
58- error stop " intrinsic_array_t construct: unsupported rank"
65+ error stop " intrinsic_array_s( construct) : unsupported rank"
5966 end select
6067
6168 end procedure
7178 rank(3 )
7279 allocate (intrinsic_array% complex_3D, source = array)
7380 rank default
74- error stop " intrinsic_array_t complex_array: unsupported rank"
81+ error stop " intrinsic_array_s( complex_array) : unsupported rank"
7582 end select
7683
7784 end procedure
8693 rank(3 )
8794 allocate (intrinsic_array% integer_3D, source = array)
8895 rank default
89- error stop " intrinsic_array_t integer_array: unsupported rank"
96+ error stop " intrinsic_array_s( integer_array) : unsupported rank"
9097 end select
9198
9299 end procedure
101108 rank(3 )
102109 allocate (intrinsic_array% logical_3D, source = array)
103110 rank default
104- error stop " intrinsic_array_t logical_array: unsupported rank"
111+ error stop " intrinsic_array_s( logical_array) : unsupported rank"
105112 end select
106113
107114 end procedure
116123 rank(3 )
117124 allocate (intrinsic_array% real_3D, source = array)
118125 rank default
119- error stop " intrinsic_array_t real_array: unsupported rank"
126+ error stop " intrinsic_array_s( real_array) : unsupported rank"
120127 end select
121128
122129 end procedure
131138 rank(3 )
132139 allocate (intrinsic_array% double_precision_3D, source = array)
133140 rank default
134- error stop " intrinsic_array_t double_precision_array: unsupported rank"
141+ error stop " intrinsic_array_s( double_precision_array) : unsupported rank"
135142 end select
136143
137144 end procedure
138145
139146#endif
140147
141- pure function one_allocated_component (self ) result(one_allocated)
148+ pure function allocated_components (self )
142149 type (intrinsic_array_t), intent (in ) :: self
143- logical one_allocated
144- one_allocated = 1 == count ( &
145- [ allocated (self% complex_1D), allocated (self% complex_double_1D), allocated (self% integer_1D), allocated (self% logical_1D), &
146- allocated (self% real_1D), allocated (self% complex_2D), allocated (self% complex_double_2D), allocated (self% integer_2D), &
147- allocated (self% logical_2D), allocated (self% real_2D), allocated (self% complex_3D), allocated (self% complex_double_3D), &
148- allocated (self% integer_3D), allocated (self% logical_3D), allocated (self% real_3D) &
149- ])
150+ logical , allocatable :: allocated_components(:)
151+ allocated_components = [ &
152+ allocated (self% complex_1D), allocated (self% real_1D), allocated (self% integer_1D), allocated (self% complex_double_1D) &
153+ ,allocated (self% complex_2D), allocated (self% real_2D), allocated (self% integer_2D), allocated (self% complex_double_2D) &
154+ ,allocated (self% complex_3D), allocated (self% real_3D), allocated (self% integer_3D), allocated (self% complex_double_3D) &
155+ ,allocated (self% logical_1D), allocated (self% double_precision_1D) &
156+ ,allocated (self% logical_2D), allocated (self% double_precision_2D) &
157+ ,allocated (self% logical_3D), allocated (self% double_precision_3D) &
158+ ]
150159 end function
151160
152161 module procedure as_character
153- integer , parameter :: single_number_width= 32
162+ integer , parameter :: single_number_width= 64
154163
155- if (.not. one_allocated_component(self)) error stop " intrinsic_array_s(as_character): invalid number of allocated components"
164+ associate(a = > allocated_components(self))
165+ call assert(count (a) == 1 , " intrinsic_array_s(as_character): invalid number of allocated components" , intrinsic_array_t(a))
166+ end associate
156167
157168 if (allocated (self% complex_1D)) then
158169 character_self = repeat (" " , ncopies = single_number_width* size (self% complex_1D))
@@ -182,7 +193,7 @@ pure function one_allocated_component(self) result(one_allocated)
182193 character_self = repeat (" " , ncopies = single_number_width* size (self% integer_2D))
183194 write (character_self, * ) self% integer_2D
184195 else if (allocated (self% logical_2D)) then
185- character_self = repeat (" " , ncopies = single_number_width* size (self% logical_1D ))
196+ character_self = repeat (" " , ncopies = single_number_width* size (self% logical_2D ))
186197 write (character_self, * ) self% logical_2D
187198 else if (allocated (self% real_2D)) then
188199 character_self = repeat (" " , ncopies = single_number_width* size (self% real_2D))
@@ -200,7 +211,7 @@ pure function one_allocated_component(self) result(one_allocated)
200211 character_self = repeat (" " , ncopies = single_number_width* size (self% integer_3D))
201212 write (character_self, * ) self% integer_3D
202213 else if (allocated (self% logical_3D)) then
203- character_self = repeat (" " , ncopies = single_number_width* size (self% logical_1D ))
214+ character_self = repeat (" " , ncopies = single_number_width* size (self% logical_3D ))
204215 write (character_self, * ) self% logical_3D
205216 else if (allocated (self% real_3D)) then
206217 character_self = repeat (" " , ncopies = single_number_width* size (self% real_3D))
0 commit comments