24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1568  |  回复: 10

superstat54

木虫 (小有名气)

[求助] Fortran 怎么把字符串转换为表达式

比如从文件中读入这样一串字符 "100 + x*x"复制给a,"sin(x)"赋值给b,如果程序中x=0.5,怎么在程序中把这一串字符"a + b"转换为表达式100 + x*x + sin(x) ,并求出其值?
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lurencyj

木虫 (著名写手)

【答案】应助回帖


感谢参与,应助指数 +1
jjdg: 金币+1, 感谢参与 2012-03-21 01:43:17
可以用use语句试试。。。
很女子很弓虽大
2楼2012-03-19 21:34:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

superstat54

木虫 (小有名气)

引用回帖:
2楼: Originally posted by lurencyj at 2012-03-19 21:34:52:
可以用use语句试试。。。

能否写的详细些?谢谢!
3楼2012-03-19 21:38:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lurencyj

木虫 (著名写手)

【答案】应助回帖


jjdg: 金币+1, 感谢参与 2012-03-21 01:43:23
The USE statement has the syntax

       USE environment-name,filename
where filename is optional, and is a character-valued expression. It causes the text of the named environment to be, in effect, placed in the program at the point where the USE statement was encountered, and the programs whose object code is in the environment to be callable from the program in which the USE statement is found, as well as (less usefully) from any other programs loaded into memory at the same time.

In some implementations, because ENVIRONMENTs are incompatible with the available linkage loading mechanisms, the filename may be compulsory the first time a USE statement referring to environments in a given file is encountered, but not in subroutines, even externally compiled subroutines, later in the source stream.
很女子很弓虽大
4楼2012-03-19 21:41:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

superstat54

木虫 (小有名气)

引用回帖:
4楼: Originally posted by lurencyj at 2012-03-19 21:41:09:
The USE statement has the syntax

       USE environment-name,filename
where filename is optional, and is a character-valued expression. It causes the text of the named environment to be, in eff ...

麻烦编写一段简单Fortran代码示例一下……
5楼2012-03-19 21:50:35
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lurencyj

木虫 (著名写手)

【答案】应助回帖

★ ★
superstat54: 金币+1, 有帮助, 谢谢! 2012-03-19 21:57:26
jjdg: 金币+1, 感谢参与 2012-03-21 01:43:31
貌似不一样,use是模块化面向对象的。

sorry
很女子很弓虽大
6楼2012-03-19 21:53:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

马永涛的虫

新虫 (小有名气)

【答案】应助回帖


感谢参与,应助指数 +1
jjdg: 金币+1, 感谢参与 2012-03-21 01:43:37
可以直接读啊:
        read(2,999)line
        write(20,999)line
        enddo
999   format(a)
       然后赋值就行了
      a=100 + x*x
      b=sin(x)
再给X赋值,求a+b
7楼2012-03-20 14:27:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

superstat54

木虫 (小有名气)

引用回帖:
7楼: Originally posted by 马永涛的虫 at 2012-03-20 14:27:28:
可以直接读啊:
        read(2,999)line
        write(20,999)line
        enddo
999   format(a)
       然后赋值就行了
      a=100 + x*x
      b=sin(x)
再给X赋值,求a+b

read(2, 999) line
line是字符型吗?
a = 100 + x*x
b = sin(x)
是怎么回事?a,b是字符型变量还是实数型?
8楼2012-03-20 15:33:17
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

锐利的碎片

木虫 (正式写手)

star watcher

【答案】应助回帖

★ ★ ★
感谢参与,应助指数 +1
jjdg: 金币+1, 感谢参与 2012-03-21 01:43:43
superstat54: 金币+2, 提供一种解决问题的思路,谢谢!不过就太麻烦了。 2012-03-21 21:19:54
一个办法,用yacc和bison产生C语言的parser,然后用fortran调用。不过我觉得没必要搞这么麻烦,如果不是计算量很大,用python,matlab的eval就简单多了。
9楼2012-03-20 18:33:57
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

马永涛的虫

新虫 (小有名气)


jjdg: 金币+1, 感谢参与 2012-03-21 01:43:49
引用回帖:
7楼: Originally posted by 马永涛的虫 at 2012-03-20 14:27:28:
可以直接读啊:
        read(2,999)line
        write(20,999)line
        enddo
999   format(a)
       然后赋值就行了
      a=100 + x*x
      b=sin(x)
再给X赋值,求a+b

line 是读那一行,就是你要的字符型变量在的那一行。a和b的类型是实型,但要你在前面声明。
10楼2012-03-20 21:09:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 superstat54 的主题更新
信息提示
请填处理意见