Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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
Can';t用双精度变量或更高精度变量替换Fortran实变量_Fortran_Precision_Gfortran_Fortran90_Single Precision - Fatal编程技术网

Can';t用双精度变量或更高精度变量替换Fortran实变量

Can';t用双精度变量或更高精度变量替换Fortran实变量,fortran,precision,gfortran,fortran90,single-precision,Fortran,Precision,Gfortran,Fortran90,Single Precision,我使用的是一个已知代码(CAMB),它生成如下值: k(h/Mpc) Pk/s8^2(Mpc/h)^3 5.2781500000e-06 1.9477400000e+01 5.5479700000e-06 2.0432300000e+01 5.8315700000e-06 2.1434000000e+01 6.1296700000e-06 2.2484700000e+01 6.4430100000e-06 2.3587000000e+01 6.7723700000e-06 2.474340000

我使用的是一个已知代码(CAMB),它生成如下值:

k(h/Mpc) Pk/s8^2(Mpc/h)^3
5.2781500000e-06 1.9477400000e+01
5.5479700000e-06 2.0432300000e+01
5.8315700000e-06 2.1434000000e+01
6.1296700000e-06 2.2484700000e+01
6.4430100000e-06 2.3587000000e+01
6.7723700000e-06 2.4743400000e+01
7.1185600000e-06 2.5956400000e+01
7.4824500000e-06 2.7228900000e+01
7.8649500000e-06 2.8563800000e+01
8.2669900000e-06 2.9964100000e+01
k(h/Mpc) Pk/s8^2(Mpc/h)^3
5.3594794736e-06 1.8529569626e+01
5.6332442000e-06 1.9437295914e+01
5.9209928622e-06 2.0389484405e+01
6.2234403231e-06 2.1388326645e+01
6.5413364609e-06 2.2436098099e+01
6.8754711720e-06 2.3535198212e+01
7.2266739153e-06 2.4688137054e+01
7.5958159869e-06 2.5897554398e+01
7.9838137026e-06 2.7166225433e+01
8.3916311269e-06 2.8497039795e+01
8.8202796178e-06 2.9893053055e+01
9.2708232842e-06 3.1357446670e+01
9.7443817140e-06 3.2893573761e+01
我希望得到更精确的生成值,如下所示:

k(h/Mpc) Pk/s8^2(Mpc/h)^3
5.2781500000e-06 1.9477400000e+01
5.5479700000e-06 2.0432300000e+01
5.8315700000e-06 2.1434000000e+01
6.1296700000e-06 2.2484700000e+01
6.4430100000e-06 2.3587000000e+01
6.7723700000e-06 2.4743400000e+01
7.1185600000e-06 2.5956400000e+01
7.4824500000e-06 2.7228900000e+01
7.8649500000e-06 2.8563800000e+01
8.2669900000e-06 2.9964100000e+01
k(h/Mpc) Pk/s8^2(Mpc/h)^3
5.3594794736e-06 1.8529569626e+01
5.6332442000e-06 1.9437295914e+01
5.9209928622e-06 2.0389484405e+01
6.2234403231e-06 2.1388326645e+01
6.5413364609e-06 2.2436098099e+01
6.8754711720e-06 2.3535198212e+01
7.2266739153e-06 2.4688137054e+01
7.5958159869e-06 2.5897554398e+01
7.9838137026e-06 2.7166225433e+01
8.3916311269e-06 2.8497039795e+01
8.8202796178e-06 2.9893053055e+01
9.2708232842e-06 3.1357446670e+01
9.7443817140e-06 3.2893573761e+01
这里是生成数据的代码部分:

在上面代码的开头,我尝试对变量声明进行以下修改:

1)第一次尝试:

!Export files of total  matter power spectra in h^{-1} Mpc units, against k/h.
Type(MatterTransferData), intent(in) :: MTrans
Type(CAMBdata) :: State
character(LEN=Ini_max_string_len), intent(IN) :: FileNames(*)
character(LEN=name_tag_len) :: columns(3)
integer itf, i, unit
integer points
! Added : way of declaring double precision
integer, parameter :: wp = selected_real_kind(15,307)
real(wp), dimension(:,:), allocatable :: outpower
!Export files of total  matter power spectra in h^{-1} Mpc units, against k/h.
Type(MatterTransferData), intent(in) :: MTrans
Type(CAMBdata) :: State
character(LEN=Ini_max_string_len), intent(IN) :: FileNames(*)
character(LEN=name_tag_len) :: columns(3)
integer itf, i, unit
integer points
! Added : way of declaring double precision
double precision, dimension(:,:), allocatable :: outpower
但它没有编译:

 real(wp), dimension(:,:), allocatable :: outpower
       1
Error: Symbol ‘wp’ at (1) has no IMPLICIT type
../results.f90:3660:25:

             allocate(outpower(points,ncol))
                     1
Error: Allocate-object at (1) is neither a data pointer nor an     allocatable variable
../results.f90:3676:16:

outpower(:,1) = exp(PK_data%matpower(:,1))
            1
Error: Unclassifiable statement at (1)
../results.f90:3679:20:

                 outpower(:,3) = exp(PK_data%vvpower(:,1))
                1
Error: Unclassifiable statement at (1)
compilation terminated due to -fmax-errors=4.
make[1]: *** [results.o] Error 1
make: *** [camb] Error 2
2)我也试过:

!Export files of total  matter power spectra in h^{-1} Mpc units, against k/h.
Type(MatterTransferData), intent(in) :: MTrans
Type(CAMBdata) :: State
character(LEN=Ini_max_string_len), intent(IN) :: FileNames(*)
character(LEN=name_tag_len) :: columns(3)
integer itf, i, unit
integer points
! Added : way of declaring double precision
integer, parameter :: wp = selected_real_kind(15,307)
real(wp), dimension(:,:), allocatable :: outpower
!Export files of total  matter power spectra in h^{-1} Mpc units, against k/h.
Type(MatterTransferData), intent(in) :: MTrans
Type(CAMBdata) :: State
character(LEN=Ini_max_string_len), intent(IN) :: FileNames(*)
character(LEN=name_tag_len) :: columns(3)
integer itf, i, unit
integer points
! Added : way of declaring double precision
double precision, dimension(:,:), allocatable :: outpower
但同样,没有编译成功

call Transfer_GetMatterPowerS(State, MTrans, outpower(1,1), itf,  minkh,dlnkh, points)
                                                                                                      1
Error: Type mismatch in argument ‘outpower’ at (1); passed REAL(8) to    REAL(4)
make[1]: *** [results.o] Error 1
make: *** [camb] Error 2
更新1:

!Export files of total  matter power spectra in h^{-1} Mpc units, against k/h.
Type(MatterTransferData), intent(in) :: MTrans
Type(CAMBdata) :: State
character(LEN=Ini_max_string_len), intent(IN) :: FileNames(*)
character(LEN=name_tag_len) :: columns(3)
integer itf, i, unit
integer points
! Added : way of declaring double precision
integer, parameter :: wp = selected_real_kind(15,307)
real(wp), dimension(:,:), allocatable :: outpower
!Export files of total  matter power spectra in h^{-1} Mpc units, against k/h.
Type(MatterTransferData), intent(in) :: MTrans
Type(CAMBdata) :: State
character(LEN=Ini_max_string_len), intent(IN) :: FileNames(*)
character(LEN=name_tag_len) :: columns(3)
integer itf, i, unit
integer points
! Added : way of declaring double precision
double precision, dimension(:,:), allocatable :: outpower
使用
-fmax errors=1
,我得到以下结果:

 call Transfer_GetMatterPowerS(State, MTrans, outpower(1,1), itf,  minkh,dlnkh, points)
                                                                                                      1
Error: Type mismatch in argument ‘outpower’ at (1); passed REAL(8) to REAL(4)
compilation terminated due to -fmax-errors=1.
除了
@Steve
给出的带有编译选项
-freal-4-real-8
的解决方案之外,我真的没有其他解决方案可以直接包含到代码中,即我给出的部分吗

更新2:下面是3个相关子程序
Transfer\u GetMatterPowerS
Transfer\u GetMatterPowerData
Transfer\u SaveMatterPower
,它们在尝试获得双精度时会产生错误:




请显示完整的。第一个错误之后的所有错误都是在错误上运行的。使用-fmax errors=1编译,并修复错误。你可以尝试跳过一个正确的双精度移植,使用-freal-4-real-8选项。你没有把所有相关的.code都放进去,这就是我问的原因。我没有对你的要求大发雷霆,我要求你做一个,请阅读链接。我看到了你的更新1。您似乎已更改函数的一个实际参数的精度,但未能更改相应伪参数的精度。这就是错误消息告诉您的。我不理解你对-freal-4-real-8的评论(除非你的编译器版本很古老)。我建议你不要使用选项。事实上,我相当坚持使用拐杖选项来完成正确的移植工作。对于手头的作业,请使用-fmax errors=1,并在发生错误时解决每个错误。在更新1中,错误指向
Transfer\u GetMatterPowerS
子例程,尤其是与实际参数
outpower
关联的伪参数类型不匹配。您需要编辑子例程并将该伪参数提升为双精度。最简单的方法是使用
类型
模块,该模块包含在需要的地方,并将
实际
更改为
实际(dp)
。请显示完整的。第一个模块之后的所有错误都是在错误上运行的。使用-fmax errors=1编译,并修复错误。你可以尝试跳过一个正确的双精度移植,使用-freal-4-real-8选项。你没有把所有相关的.code都放进去,这就是我问的原因。我没有对你的要求大发雷霆,我要求你做一个,请阅读链接。我看到了你的更新1。您似乎已更改函数的一个实际参数的精度,但未能更改相应伪参数的精度。这就是错误消息告诉您的。我不理解你对-freal-4-real-8的评论(除非你的编译器版本很古老)。我建议你不要使用选项。事实上,我相当坚持使用拐杖选项来完成正确的移植工作。对于手头的作业,请使用-fmax errors=1,并在发生错误时解决每个错误。在更新1中,错误指向
Transfer\u GetMatterPowerS
子例程,尤其是与实际参数
outpower
关联的伪参数类型不匹配。您需要编辑子例程并将该伪参数提升为双精度。最简单的方法是使用
类型
模块,该模块包含在需要的地方,并将
REAL
更改为
REAL(dp)