变量错误
Error in variable
你能帮我解决以下错误吗?
real(16), parameter :: &
1
Error: Invalid character in name at (1)
包含上述代码的模块如下:
module degree_trig
real(16), parameter :: &
quadpi = 3.141592653589793238462643383279502884197
real(16), parameter :: dgr_to_rad = (quadpi/180)
intrinsic cos, sin, tan
contains
function sind(dgr_argument)
real(4) sind, dgr_argument
sind = sin(dgr_to_rad * dgr_argument)
end function
function cosd(dgr_argument)
real(4) cosd, dgr_argument
cosd = cos(dgr_to_rad * dgr_argument)
end function
function tand(dgr_argument)
real(4) tand, dgr_argument
tand = tan(dgr_to_rad * dgr_argument)
end function
function dsind(dgr_argument)
real(8) dsind, dgr_argument
dsind = sin(dgr_to_rad * dgr_argument)
end function
function dcosd(dgr_argument)
real(8) dcosd, dgr_argument
dcosd = cos(dgr_to_rad * dgr_argument)
end function
function dtand(dgr_argument)
real(8) dtand, dgr_argument
dtand = tan(dgr_to_rad * dgr_argument)
end function
end ! module
首先,它在 gfortran 4.9 中编译。
但是你确定你把它保存在.f90文件中了吗?
我的意思是该错误看起来像是编译器需要固定格式。
顺便说一句,存储在常量 quadpi 中的值不是四倍精度的。我建议您定义一个 qp 整数参数(以及 sp、dp 用于单精度和双精度)。使用函数selected_real_kind存储四倍精度对应的kind值,将该kind的精度传入函数(即四倍精度为33,双精度为15,单精度为6)。
您必须在数字常量处附加 _qp(以及 _dp 和 _sp 用于其他类型的数字常量)。
我建议你写:
module degree_trig
implicit none
integer, parameter :: sp = selected_real_kind(6)
integer, parameter :: dp = selected_real_kind(15)
integer, parameter :: qp = selected_real_kind(33)
real(qp), parameter :: &
quadpi = 3.141592653589793238462643383279502884197_qp
real(qp), parameter :: dgr_to_rad = (quadpi/180.0_qp)
contains
elemental function sind(dgr_argument)
real(sp), intent(in) :: dgr_argument
real(sp) sind
sind = sin(dgr_to_rad * dgr_argument)
end function
你能帮我解决以下错误吗?
real(16), parameter :: &
1
Error: Invalid character in name at (1)
包含上述代码的模块如下:
module degree_trig
real(16), parameter :: &
quadpi = 3.141592653589793238462643383279502884197
real(16), parameter :: dgr_to_rad = (quadpi/180)
intrinsic cos, sin, tan
contains
function sind(dgr_argument)
real(4) sind, dgr_argument
sind = sin(dgr_to_rad * dgr_argument)
end function
function cosd(dgr_argument)
real(4) cosd, dgr_argument
cosd = cos(dgr_to_rad * dgr_argument)
end function
function tand(dgr_argument)
real(4) tand, dgr_argument
tand = tan(dgr_to_rad * dgr_argument)
end function
function dsind(dgr_argument)
real(8) dsind, dgr_argument
dsind = sin(dgr_to_rad * dgr_argument)
end function
function dcosd(dgr_argument)
real(8) dcosd, dgr_argument
dcosd = cos(dgr_to_rad * dgr_argument)
end function
function dtand(dgr_argument)
real(8) dtand, dgr_argument
dtand = tan(dgr_to_rad * dgr_argument)
end function
end ! module
首先,它在 gfortran 4.9 中编译。
但是你确定你把它保存在.f90文件中了吗? 我的意思是该错误看起来像是编译器需要固定格式。
顺便说一句,存储在常量 quadpi 中的值不是四倍精度的。我建议您定义一个 qp 整数参数(以及 sp、dp 用于单精度和双精度)。使用函数selected_real_kind存储四倍精度对应的kind值,将该kind的精度传入函数(即四倍精度为33,双精度为15,单精度为6)。 您必须在数字常量处附加 _qp(以及 _dp 和 _sp 用于其他类型的数字常量)。
我建议你写:
module degree_trig
implicit none
integer, parameter :: sp = selected_real_kind(6)
integer, parameter :: dp = selected_real_kind(15)
integer, parameter :: qp = selected_real_kind(33)
real(qp), parameter :: &
quadpi = 3.141592653589793238462643383279502884197_qp
real(qp), parameter :: dgr_to_rad = (quadpi/180.0_qp)
contains
elemental function sind(dgr_argument)
real(sp), intent(in) :: dgr_argument
real(sp) sind
sind = sin(dgr_to_rad * dgr_argument)
end function