This is confusing, because it seems to work with the Intel compiler (2015) when the write is done in the same program before the read.
The compile fails with G95 giving the error message
write(1)TestData
1
Error: Data transfer element at (1) cannot have ALLOCATABLE components
Here is the example code. Invoke with "test" to write first and "test 1" to attempt to read the old file, which fails. Why?
implicit none
integer::i
character(len=1)::buf
logical::WriteFileFirst=.false.
type TestType
real*8,dimension(:),allocatable::a
end type TestType
type(TestType),dimension(:),allocatable::TestData
call getarg(1,buf)
if(buf.ne."")then
write(*,*)'using old file'
else
WriteFileFirst=.true.
write(*,*)'Writing file first'
endif
allocate(TestData(3))
do i=1,3
allocate(TestData(i)%a(2))
enddo
if(WriteFileFirst)then
do i=1,3
TestData(i)%a(1)=3
TestData(i)%a(2)=4
enddo
open(1,file='TestData',form='unformatted')
write(1)TestData
close(1)
endif
open(1,file='TestData',form='unformatted')
read(1)TestData
close(1)
write(*,*)'TestData(1)=',TestData(1)
end