I am compiling a code in Fortran. If I use a recent version of Intel Fortran it compiles. However, I need to compile the same code with gfortran
(I have gcc version 6.3.0 (GCC)
).
At these two lines of the code
read(F%Unit) FileSettings%TCosmoTheoryParams
Write(F%Unit) CosmoSettings%TCosmoTheoryParams
I get the error `
Error: Data transfer element at (1) cannot have ALLOCATABLE components unless it is processed by a defined input/output procedure`
How to modify the code, keeping the compiler gcc
?
The full compiler error, within the 'make' compilation
mpif90 -cpp -O3 -ffast-math -ffree-line-length-none -fopenmp -fmax-errors=4 -march=native -DMPI -DEFTCOSMOMC -I../EFTCAMB/ReleaseEFTMPI -JReleaseEFTMPI -IReleaseEFTMPI/ -c CosmoTheory.f90 -o ReleaseEFTMPI/CosmoTheory.o
CosmoTheory.f90:253:52:
read(F%Unit) FileSettings%TCosmoTheoryParams
1
Error: Data transfer element at (1) cannot have ALLOCATABLE components unless it is processed by a defined input/output procedure
CosmoTheory.f90:183:54:
Write(F%Unit) CosmoSettings%TCosmoTheoryParams
1
Error: Data transfer element at (1) cannot have ALLOCATABLE components unless it is processed by a defined input/output procedure
And the snippet of code where these lines are from:
subroutine TCosmoTheoryPredictions_ReadTheory(this, F, first)
Class(TCosmoTheoryPredictions) this
class(TFileStream) :: F
logical, intent(in) :: first
type(TCosmoTheorySettings), save :: FileSettings
!JD 02/14 new variables for handling new pk arrays
integer :: num_k, num_z
real(mcp), allocatable :: temp(:,:)
real(mcp), allocatable :: k(:), z(:)
real(mcp), allocatable :: cl(:)
real(mcp), allocatable :: valArray(:)
integer i,j
if (first) then
read(F%Unit) FileSettings%TCosmoTheoryParams
if (FileSettings%use_LSS) call F%ReadSizedArray(FileSettings%power_redshifts)
if (FileSettings%use_CMB) call F%ReadSizedArray(FileSettings%cl_lmax)
call F%ReadSizedArray(FileSettings%ArraySizes) !not used
end if
subroutine TCosmoTheoryPredictions_WriteTheory(this, F, first)
Class(TCosmoTheoryPredictions) this
class(TFileStream) :: F
logical, intent(in) :: first
integer ArraySizes(1)
real(mcp) :: valArray(6)
integer i,j
if (first .and. new_chains) then
Write(F%Unit) CosmoSettings%TCosmoTheoryParams
if (CosmoSettings%use_LSS) call F%WriteSizedArray(CosmoSettings%power_redshifts)
if (CosmoSettings%use_CMB) call F%WriteSizedArray(CosmoSettings%cl_lmax)
ArraySizes(1)=size(valArray)
call F%WriteSizedArray(ArraySizes)
end if
Definition of TCosmoTheorySettings
:
Type, extends(TCosmoTheoryParams):: TCosmoTheorySettings
!Just add the allocatable components
integer, allocatable :: cl_lmax(:,:)
integer, allocatable :: ArraySizes(:)
!e.g. lmax_cl(1,1) is lmax for TT; zero if CL is not used; order is T, E, B, Phi
real(mcp), dimension(:), allocatable :: power_redshifts
contains
procedure, private :: Initialize_PKSettings
procedure, private :: Initialize_CMBSettings
procedure :: InitForLikelihoods => TCosmoTheorySettings_InitForLikelihoods
procedure :: ReadParams => TCosmoTheorySettings_ReadParams
end type TCosmoTheorySettings
Type TCosmoTheoryParams
contains only ordinary non-allocatable and non-pointer data components and no procedures