fortran - 假定字符长度为 (1) 的实体必须是虚拟参数或 PARAMETER
问题描述
在主线中,我如何声明“to_upper”和“string”以便调用这个函数?
Pure Function to_upper (str) Result (string)
! Changes a string to upper case
Implicit None
Character(*), Intent(In) :: str
Character(LEN(str)) :: string
Integer :: ic, i
program tescc
character (*) to_upper, to_lower
character (*) tes1,tes2
tes1='LoWs' tes2=to_upper(tes1)
print*,tes1,',',tes2
end
gfortran -o tescc tescc.f tescc.f:4:24: 4 |
character (*) tes1,tes2 |
1 Error: Entity with assumed character length at (1) must be a dummy argument or a PARAMETER tescc.f:4:29:
解决方案
您需要声明三个字符串,一个用于函数,一个用于输入字符串,另一个用于输出字符串。您首先需要结束此功能。您需要说函数名称是一个字符串,因为这就是它返回的内容。
这个函数什么都不做,所以你需要完成函数算法的编写。但,
这是运行此函数的示例代码:
program main
implicit none
character(100) :: to_upper
character(100) :: some_str, other_str
some_str = "hello world"
other_str = to_upper(some_str)
end program main
pure function to_upper (str) Result (string)
! Changes a string to upper case
implicit None
Character(*), Intent(In) :: str
Character(LEN(str)) :: string
Integer :: ic, i
end function