谁能给详细解释一下这段fortran程序

来源:百度知道 编辑:UC知道 时间:2024/06/23 00:28:37
请尽可能的详细一些,谢谢。

module q
implicit none
interface operator(.lower.)
module procedure zimu
end interface
contains

function zimu(str)result(str_rst)
character(len=80),intent(in)::str
character(len=80)::str_rst
integer::i
do i=1,len(str)
if(str(i:i)<='Z'.and.str(i:i)>='A')then
str_rst(i:i)=char(ichar(str(i:i))+32)
else
str_rst(i:i)=str(i:i)
end if
end do
end function zimu
end module q

program w

use q
character(len=80)::letter
print*,'input words:'
read*,letter
print*,zimu(letter)
end program w

module q
定义模块
implicit none
interface operator(.lower.)
module procedure zimu
end interface
用接口实现操作符重载或定义
contains

模块函数
function zimu(str)result(str_rst)
函数名叫zimu,result()用来定返回值名称
character(len=80),intent(in)::str
声明输入变量,长度80的字符串,属性为输入,就是不能改变这个量的值
character(len=80)::str_rst
integer::i
do i=1,len(str)
if(str(i:i)<='Z'.and.str(i:i)>='A')then
str_rst(i:i)=char(ichar(str(i:i))+32)
如果字母为大写,取出其asc码,加32后变为小写字母asc码,再转换回字符
else
str_rst(i:i)=str(i:i)
end if
end do
end function zimu
end module q

program w

use q 使用模块
character(len=80)::letter
print*,'input words:' 输出提示行
read*,letter 读入字符串
print*,zimu(letter)
调用zimu函数,改成.lower.letter也可以
end program w