QQ截图20170121113910.png (20.93 KB, 下载次数: 438)
PROGRAM EX
implicit none
INTEGER M,I
REAL,ALLOCATABLE:: A(:),B(:),C(:),D(:),E(:)
OPEN(8,FILE="CN003830.wth")
READ(8,*)M
ALLOCATE(A(M),B(M),C(M),D(M),E(M))
DO I=3,M
READ(8,*)A(I),B(I),C(I),D(I),E(I)
ENDDO
DO I=3,M
WRITE(*,*)A(I),B(I),C(I),D(I),E(I)
ENDDO
END
QQ截图20170121191001.png (20.28 KB, 下载次数: 430)
li913 发表于 2017-1-21 15:52
1、如果你有其他语言的编程经验,上手很快,但如果没有,认真看书;
2、读文件的操作需要你去看看书,也就 ...
program ex
implicit none
integer m,i
integer , allocatable :: days(:)
real , allocatable :: tMax(:) , tMin(:)
real :: srad
open(8,file="cn003830.wth")
!read(8,*)m !//m无法再文件中获取,需手动输入或获取文件行数减去3,得到。
m = 300 !//我假设是300个
allocate(days(m),tMax(m),tMin(m))
do i = 1,4
read(8,*)
end do !//跳过前4行
do i = 1,m
read(8,*) days(i) , srad , tMax(i) , tMin(i)
write(*,*) days(i) , tMax(i) , tMin(i)
enddo
end program ex
vvt 发表于 2017-1-22 10:55
[mw_shl_code=fortran,true]program ex
implicit none
integer m,i
vvt 发表于 2017-1-22 17:19
定义一个real变量,名叫srad
wxy 发表于 2017-1-23 08:52
我在试着把这个获取文件行数的代码放到这个代码里面自动赋值给m,理论上是对的吗,昨天试了一晚上赋值给m ...
program ex
implicit none
integer m,i
INTEGER , allocatable :: days(:),year(:)
real , allocatable :: tMax(:) , tMin(:) , rain(:)
real :: srad
open(8,file="cn003830.wth")
!read(8,*)m !//m无法再文件中获取,需手动输入或获取文件行数减去3,得到。
open(10,file="test.wth")
open(11,file="A:\EX\test.wth")
m = 10592 !//我假设是300个
allocate(year(m),days(m),tMax(m),tMin(m),rain(m))
do i = 1,4
read(8,*)
end do !//跳过前4行
do i = 1,m
read(8,*)year(i), days(i) , srad , tMax(i) , tMin(i) , rain(i)
end do
close(8)
year(I)=days(i)/1000
WHERE (year(i)=year(i)+1)
write(10,"(i5.5,2xf5.1,2xf5.1,2xf4.1)") days(i) , tMax(i) , tMin(i) , rain(i)
ELSE WHERE
write(11,"(i5.5,2xf5.1,2xf5.1,2xf4.1)") days(i) , tMax(i) , tMin(i) , rain(i)
end where
end program ex
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |