Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
定义自己的类型时,ifort和gfortran的结果不同_Fortran_Gfortran_Intel Fortran - Fatal编程技术网

定义自己的类型时,ifort和gfortran的结果不同

定义自己的类型时,ifort和gfortran的结果不同,fortran,gfortran,intel-fortran,Fortran,Gfortran,Intel Fortran,我是Fortran新手,但我发现只要我熟悉了模块和类型,我就可以用C或Matlab做大多数事情。然而,我被结果上的差异难住了,这取决于我是使用gfortran(gcc版本4.6.2)还是ifort(13.0.2)。Gfortran给了我预期的结果,但ifort给了我3个空行!你知道为什么吗 module define_structures implicit none private public modelling_params type modelling_params

我是Fortran新手,但我发现只要我熟悉了模块和类型,我就可以用C或Matlab做大多数事情。然而,我被结果上的差异难住了,这取决于我是使用gfortran(gcc版本4.6.2)还是ifort(13.0.2)。Gfortran给了我预期的结果,但ifort给了我3个空行!你知道为什么吗

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
下面是使用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   
使用ifort,我只得到3个空行,尽管它编译得很好


提前感谢。

-ASSUE realloc_lhs
命令行选项传递给编译器时,将启用对
ifort
中赋值时可分配变量的重新分配的支持。如果您在第一次分配后立即插入以下内容:

print *, allocated(S%data)

您将看到
F
,这意味着分配给时未分配可分配字段。代码在
-假设realloc_lhs

完全如您所说的那样工作,Hristo。添加
-假设realloc_lhs
作为编译器选项使其按预期工作。不过,我很好奇为什么没有从编译器中得到警告。如果您尝试在启用运行时检查的情况下运行,则在分配给未分配的数组时应该会出现错误。