新人,导师要求用fortran编程。给了一个简单的任务,处理数据的输入和输出,求帮助,哪里出错,在线等。
求好人帮助,新人求教。在线等,不胜感激。错误地方好像就是就是定义的x,y,z,l,m,n。错误类型如下:--------------------Configuration...
求好人帮助,新人求教。在线等,不胜感激。
错误地方好像就是就是定义的x,y,z,l,m,n。错误类型如下:
--------------------Configuration: 12 - Win32 Debug--------------------
Compiling Fortran...
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(22) : Error: Constants and expressions are invalid in read-only I/O lists. [X]
read (fileid,*)x(i),y(i),z(i)
---------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(22) : Error: Constants and expressions are invalid in read-only I/O lists. [Y]
read (fileid,*)x(i),y(i),z(i)
--------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(22) : Error: Constants and expressions are invalid in read-only I/O lists. [Z]
read (fileid,*)x(i),y(i),z(i)
-------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(23) : Error: This name has not been declared as an array. [L]
l(i)=(2*x(i)-a-b)/(b-a)
^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(24) : Error: This name has not been declared as an array. [M]
m(i)=(2*y(i)-c-d)/(d-c)
^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(25) : Error: This name has not been declared as an array. [N]
n(i)=(2*z(i)-e-f)/(f-e)
^
Error executing df.exe.
12.exe - 6 error(s), 0 warning(s)
程序代码如下。
program main
implicit none
integer,parameter :: fileid=10
integer,parameter :: num=8000
integer i,error
real a,b,c,d,e,f,x,y,z,l,m,n
a=-0.574213
b=53.0742
c=-0.574213
d=53.0742
e=-0.573119
f=52.9731
open(fileid,file="file.txt",status="old",iostat=error)
if(error/=0)then
write(*,*)"open file.txt fail."
stop
end if
do i=1,num
read (fileid,*)x(i),y(i),z(i)
l(i)=(2*x(i)-a-b)/(b-a)
m(i)=(2*y(i)-c-d)/(d-c)
n(i)=(2*z(i)-e-f)/(f-e)
end do
do i=1,num
write (*,"(F8.6)" l(i),m(i),n(i)
end do
stop
end program
有知道的么?劳烦相告。在线等。若满意可以再加分,谢谢。 展开
错误地方好像就是就是定义的x,y,z,l,m,n。错误类型如下:
--------------------Configuration: 12 - Win32 Debug--------------------
Compiling Fortran...
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(22) : Error: Constants and expressions are invalid in read-only I/O lists. [X]
read (fileid,*)x(i),y(i),z(i)
---------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(22) : Error: Constants and expressions are invalid in read-only I/O lists. [Y]
read (fileid,*)x(i),y(i),z(i)
--------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(22) : Error: Constants and expressions are invalid in read-only I/O lists. [Z]
read (fileid,*)x(i),y(i),z(i)
-------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(23) : Error: This name has not been declared as an array. [L]
l(i)=(2*x(i)-a-b)/(b-a)
^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(24) : Error: This name has not been declared as an array. [M]
m(i)=(2*y(i)-c-d)/(d-c)
^
C:\Program Files\Microsoft Visual Studio\MyProjects\12\12.f90(25) : Error: This name has not been declared as an array. [N]
n(i)=(2*z(i)-e-f)/(f-e)
^
Error executing df.exe.
12.exe - 6 error(s), 0 warning(s)
程序代码如下。
program main
implicit none
integer,parameter :: fileid=10
integer,parameter :: num=8000
integer i,error
real a,b,c,d,e,f,x,y,z,l,m,n
a=-0.574213
b=53.0742
c=-0.574213
d=53.0742
e=-0.573119
f=52.9731
open(fileid,file="file.txt",status="old",iostat=error)
if(error/=0)then
write(*,*)"open file.txt fail."
stop
end if
do i=1,num
read (fileid,*)x(i),y(i),z(i)
l(i)=(2*x(i)-a-b)/(b-a)
m(i)=(2*y(i)-c-d)/(d-c)
n(i)=(2*z(i)-e-f)/(f-e)
end do
do i=1,num
write (*,"(F8.6)" l(i),m(i),n(i)
end do
stop
end program
有知道的么?劳烦相告。在线等。若满意可以再加分,谢谢。 展开
2个回答
展开全部
数组 x(i),y(i),z(i) 没有定义
Error: Constants and expressions are invalid in read-only I/O lists. [X]
read (fileid,*)x(i),y(i),z(i)
---------------^
program main
implicit none
integer,parameter :: fileid=10
integer,parameter :: num=8000
integer i,error
!real a,b,c,d,e,f,x,y,z,l,m,n 这只定义了类型,变量可以这么干,数组不可以;
!下面这样可以
!dimension x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
!real a,b,c,d,e,f,x,y,z,l,m,n
!下面这样可以也可以
real x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
real a,b,c,d,e,f
!下面这样可以也可以
!real a,b,c,d,e,f,x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
!下面这样可以也可以
!real a,b,c,d,e,f,x( num),y(num),z(num),l(num),m(num),n(num)
!还有一种方法f90的
!real,dimension :: x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
!real a,b,c,d,e,f
a=-0.574213
b=53.0742
c=-0.574213
d=53.0742
e=-0.573119
f=52.9731
open(fileid,file="file.txt",status="old",iostat=error)
if(error/=0)then
write(*,*)"open file.txt fail."
stop
end if
do i=1,num
read (fileid,*)x(i),y(i),z(i)
l(i)=(2*x(i)-a-b)/(b-a)
m(i)=(2*y(i)-c-d)/(d-c)
n(i)=(2*z(i)-e-f)/(f-e)
end do
do i=1,num
write (*,"(F8.6)" l(i),m(i),n(i)
end do
stop
end program
另外 "(F8.6)" 也可以用了吗??
Error: Constants and expressions are invalid in read-only I/O lists. [X]
read (fileid,*)x(i),y(i),z(i)
---------------^
program main
implicit none
integer,parameter :: fileid=10
integer,parameter :: num=8000
integer i,error
!real a,b,c,d,e,f,x,y,z,l,m,n 这只定义了类型,变量可以这么干,数组不可以;
!下面这样可以
!dimension x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
!real a,b,c,d,e,f,x,y,z,l,m,n
!下面这样可以也可以
real x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
real a,b,c,d,e,f
!下面这样可以也可以
!real a,b,c,d,e,f,x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
!下面这样可以也可以
!real a,b,c,d,e,f,x( num),y(num),z(num),l(num),m(num),n(num)
!还有一种方法f90的
!real,dimension :: x(1: num),y(1:num),z(1:num),l(1:num),m(1:num),n(1:num)
!real a,b,c,d,e,f
a=-0.574213
b=53.0742
c=-0.574213
d=53.0742
e=-0.573119
f=52.9731
open(fileid,file="file.txt",status="old",iostat=error)
if(error/=0)then
write(*,*)"open file.txt fail."
stop
end if
do i=1,num
read (fileid,*)x(i),y(i),z(i)
l(i)=(2*x(i)-a-b)/(b-a)
m(i)=(2*y(i)-c-d)/(d-c)
n(i)=(2*z(i)-e-f)/(f-e)
end do
do i=1,num
write (*,"(F8.6)" l(i),m(i),n(i)
end do
stop
end program
另外 "(F8.6)" 也可以用了吗??
追问
按照上面一位那么做了,完成了。不过还是谢谢你。
另外“(F8.6)”是可以用的啊,不过我这个程序输出的话用“3(F10.6)”比较好。排3列,6位小数,10个字符。
追答
不用谢!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询