|
| 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 |
0 commit comments