-2

我们可以编写简单的 bash 脚本以多种方式简化我们的任务。例如作为下面的 bash 脚本。

#!/bin/bash

name="Vijay"

echo "My name is $name."
echo "$name does no like to play football"

exit $?

可以在 Fortran 中实现相同的目标吗?我尝试了代码作为打击:

program simple
implicit none

character(len=1024),parameter :: name="Vijay"

write (name,"(A5)")  
print*, "My name is trim(name)" 
print*, "trim(name) does no like to play football"
end

但是,我收到错误消息:

Error: UNIT specification at (1) must be an INTEGER expression or a CHARACTER variable

感谢任何帮助解决此问题。

提前致谢

4

2 回答 2

3

这是一个非常基本的问题。我建议阅读有关 Fortran 的文章,例如http://en.wikipedia.org/wiki/Fortran_95_language_features,并查看代码示例。

一个提示:

write (name,"(A5)")

-->

write (*, '(A)' )  name
于 2013-05-01T07:56:04.207 回答
0

除了来自 MSB 的响应之外,该行:

print*, "My name is trim(name)" 

将打印出来,My name is trim(name)因为 Fortran 不会像 bash 那样在字符串中进行变量替换。你想要的是:

print*, "My name is "//trim(name)

//运算符用于 Fortran 中的字符串连接。

于 2013-05-01T23:46:56.977 回答