program main
implicit none
integer i , m
integer , allocatable :: site(:) , lat(:) , lon(:) ,height(:) , year(:) , month(:) , day(:) , rain1(:) , rain2(:) , rain3(:)
character(len=37) :: line , filename
!=================================================
!批量读取文件
!=================================================
open(11,file='1.dat')
do
read(11,*) filename
open(10,file=filename)
!=================================================
!获取文件行数
!=================================================
i = 0
Do
Read (10, *, End=100) line
i = i + 1
End Do
100 m = i
Rewind (10)
!=================================================
!数据写入test.txt
!=================================================
allocate(site(m) , lat(m) , lon(m) ,height(m) , year(m) , month(m) , day(m) , rain1(m) , rain2(m) , rain3(m) )
open (7,file="test.txt")
do i=1,m
read (10,*)site(i) , lat(i) , lon(i) ,height(i) , year(i) , month(i) ,day(i) , rain1(i) , rain2(i) , rain3(i)
write(7,*) site(i),lat(i),lon(i) , year(i) , month(i) , day(i) , rain3(i)
end do
end do
end program
QQ截图20170413181816.png (36 KB, 下载次数: 278)
fcode 发表于 2017-4-13 19:19
你忘了写 deallocate,所以第二次循环的时候,site 等数组已经分配过了。
QQ截图20170413205916.png (28.36 KB, 下载次数: 252)
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |