回 帖 发 新 帖 刷新版面

主题:[讨论]为什么没有结果,太奇怪了

character::op,p 
real::x,y
do
read *,x,op,y
select case(op)
case('+')
print *,x+y
case('-')
print *,x-y
case('*')
print *,x*y
case('/')
if(y==0) then
print *,"chu shu wei 0!"
else
print *,x/y
endif
case default
print *,"shu ru cuo wu"
end select
print *,"if you want to contineu,press y"
print *,"if you not,press n"
read*,p
if(p=='n') then
exit
else
cycle
endif
enddo
end
这个程序是一个计算器程序,输入如:3+5
2-6 6*2 9/6然后问你是否继续,如果继续就按y,结束就按n
这个程序编译没有错误,关键是没有结果,一执行就没得反应啊
哪个高手帮帮我啊,


回复列表 (共29个回复)

21 楼

当然,对比较常见的表示方式:
MyString = "3.1415E-4 / -4.2E-3    " 也会出问题。
因此,若是真的要实现像 Mathematica、MatLab 等类似的识别功能,
程序的规模真的不小。 这个就是我为何选择 List-Directed I/O 的
原因,程序上面已经附上了。
当然,我的程序也还会有若干问题,欢迎诸位网友指正。

22 楼

[quote]19 楼: 若是 MyString = "3.1415_4 / 4.2D-3    ",则程序异常。


修改: 我发现,真正的问题源于

Input Error:real constant with a kind-parameter

--------------------------------------------------------------------------------

real(kind = 8):: x
read(*, *) x

when I input -- 1.0_8, List-Directed I/O syntax error (Intel Fortran 12.0 Compiler).
I don't know why real constant with kind-parameter as a input, the compiler message 
a error? The Fortran 2003 Standard mention this situation?

Thanks a lot.
[/quote]

恩,input确实不支持这种格式,原因不明,我在comp.lang.fortran上发个贴问问,看看有人知道么,不行就得去看gfortran的read实现去了。

23 楼

[quote]当然,对比较常见的表示方式:
MyString = "3.1415E-4 / -4.2E-3    " 也会出问题。
因此,若是真的要实现像 Mathematica、MatLab 等类似的识别功能,
程序的规模真的不小。 这个就是我为何选择 List-Directed I/O 的
原因,程序上面已经附上了。
当然,我的程序也还会有若干问题,欢迎诸位网友指正。[/quote]

当然这些输入也会有问题,不过那个程序也是抛砖引玉,要准确的识别,要做的识别工作可不小。

24 楼

[quote]19 楼: 若是 MyString = "3.1415_4 / 4.2D-3    ",则程序异常。


修改: 我发现,真正的问题源于

Input Error:real constant with a kind-parameter

--------------------------------------------------------------------------------

real(kind = 8):: x
read(*, *) x

when I input -- 1.0_8, List-Directed I/O syntax error (Intel Fortran 12.0 Compiler).
I don't know why real constant with kind-parameter as a input, the compiler message 
a error? The Fortran 2003 Standard mention this situation?

Thanks a lot.
[/quote]

comp.lang.fortran的Richard Maine 回复我了,他说这种输入格式只有在常数上有意义,可是read接受的并不是常数,而是变量,所以并不接受带kind的变量,一切以变量的类型声明为准,因此在输入里要避免输入这种形式。(http://groups.google.com/group/comp.lang.fortran/t/59dcecbb6b6de996?hl=en

25 楼

http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/
Intel 还没有给我回复。

26 楼

我当时的想法就是dongyuanxun 的做法. 不过没想asymptotic那么远. 
我曾经namelist上面也遇到过用"_8"这种方式也是读取错误.

27 楼

[quote]我当时的想法就是dongyuanxun 的做法. 不过没想asymptotic那么远. 
我曾经namelist上面也遇到过用"_8"这种方式也是读取错误.[/quote]
这种人机界面我宁愿用C/C++,用fortran不觉得心力交瘁么

28 楼

另外附intel论坛的回复

I understand why you might try that, but it's not allowed in Fortran.  The kind is taken from the corresponding variable in the I/O list.

Steve

29 楼

These days I look through --- The Fortran 2003 Handbook   chapter 10, and I find the following sentences:

the input values are not actually Fortran constants. They do not have to follow all the rules for Fortran literal constants and they are not allowed to have kind parameter.

我来回复

您尚未登录,请登录后再回复。点此登录或注册