| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test the fix for PR72709 in which the type of the component 'header' is cast |
| 4 |
! as character[1:0], which makes it slightly more difficult than usual to |
| 5 |
! obtain the element length. This is one and the same bug as PR70752. |
| 6 |
! |
| 7 |
! Contributed by 'zmi' <[email protected]> |
| 8 |
! |
| 9 |
program read_exp_data |
| 10 |
implicit none |
| 11 |
|
| 12 |
type experimental_data_t |
| 13 |
integer :: nh = 0 |
| 14 |
character(len=:), dimension(:), allocatable :: header |
| 15 |
|
| 16 |
end type experimental_data_t |
| 17 |
|
| 18 |
character(*), parameter :: str(3) = ["#Generated by X ", & |
| 19 |
"#from file 'Y' ", & |
| 20 |
"# Experimental 4 mg/g"] |
| 21 |
type(experimental_data_t) :: ex |
| 22 |
integer :: nh_len |
| 23 |
integer :: i |
| 24 |
|
| 25 |
|
| 26 |
nh_len = 255 |
| 27 |
ex % nh = 3 |
| 28 |
allocate(character(len=nh_len) :: ex % header(ex % nh)) |
| 29 |
|
| 30 |
ex % header(1) = str(1) |
| 31 |
ex % header(2) = str(2) |
| 32 |
ex % header(3) = str(3) |
| 33 |
|
| 34 |
! Test that the string length is OK |
| 35 |
if (len (ex%header) .ne. nh_len) stop 1 |
| 36 |
|
| 37 |
! Test the array indexing |
| 38 |
do i = 1, ex % nh |
| 39 |
if (trim (ex%header(i)) .ne. trim (str(i))) stop i + 1 |
| 40 |
enddo |
| 41 |
|
| 42 |
end program read_exp_data |