24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1592  |  回复: 10
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

superstat54

木虫 (小有名气)

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

比如从文件中读入这样一串字符 "100 + x*x"复制给a,"sin(x)"赋值给b,如果程序中x=0.5,怎么在程序中把这一串字符"a + b"转换为表达式100 + x*x + sin(x) ,并求出其值?
回复此楼
已阅   回复此楼   关注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的回帖
查看全部 11 个回答

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的回帖
信息提示
请填处理意见