新人,导师要求用fortran编程。给了一个简单的任务,处理数据的输入和输出,求帮助,哪里出错,在线等。

2024-12-15 00:17:59
推荐回答(2个)
回答1:

数组 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)" 也可以用了吗??

回答2:

real a,b,c,d,e,f,x,y,z,l,m,n

改为
real a,b,c,d,e,f,x(num),y(num),z(num),l(num),m(num),n(num)

数组的定义,必须给出具体大小。