Pergunta

I'm new to Fortran, but am generally finding that I can do most things that I could with C or Matlab, once I get my head around modules and types. However, I'm stumped by this difference in results, depending on whether I use gfortran (gcc version 4.6.2) or ifort(13.0.2). Gfortran gives me the results I expect, but ifort gives me 3 blank lines! Any ideas why?

module define_structures
implicit none
private

public modelling_params

    type modelling_params
        real, dimension(:), allocatable :: freqs
        real, dimension(:), allocatable :: offsets      
        complex, dimension(:), allocatable :: data
    end type modelling_params   
end module define_structures

program main

use define_structures
    implicit none

    type (modelling_params) :: S

    S%data = [(1,1) ,(2,3), (3,1)]
    S%freqs = [1, 3, 7]
    S%offsets = [100, 200, 300]
    print *,S%data
    print *,S%freqs
    print *,S%offsets


end program main

Here's the output from compiling with gfortran

(  1.0000000    ,  1.0000000    ) (  2.0000000    ,  3.0000000    ) (  3.0000000    ,  1.0000000    )
1.0000000       3.0000000       7.0000000    
100.00000       200.00000       300.00000   

And with ifort, I just get 3 blank lines, though it compiles fine!!

Thanks in advance.

Foi útil?

Solução

Support for reallocation of allocatable variables on assignment in ifort is enabled when the -assume realloc_lhs command line option is passed to the compiler. If you insert the following immediately after the first assignment:

print *, allocated(S%data)

you would see F, which means that the allocatable field is not allocated when assigned to. The code works as expected with -assume realloc_lhs.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top