|
8#
楼主 |
发表于 2017-4-22 23:54:05
|
只看该作者
本帖最后由 wxy 于 2017-4-23 13:09 编辑
还想请教一下,在批量读取五个dat文件列表时出现了问题,总是end of file,并新建一个filename_1,到filename_5的空白文件,不知道为什麽[Fortran] 纯文本查看 复制代码 program nc2dssat
implicit none
integer i ,m
character,allocatable :: pre(:), rsd(:), tasmax(:), tasmin(:)
character(len=512) :: filename_1, filename_2, filename_3, filename_4, filename_5, line
!==================================================================================
!文件名列表
!==================================================================================
open(10,file="D:\miroc-esm-chem\historical\pr_v2\1951-1960\pre.dat") !降水
open(11,file="D:\miroc-esm-chem\historical\rsds_v1\1951-1960\rsd.dat") !辐射
open(12,file="D:\miroc-esm-chem\historical\tasmax_v1\1951-1960\tasmax.dat") !最高温
open(13,file="D:\miroc-esm-chem\historical\tasmin_v1\1951-1960\tasmin.dat") !最低温
open(14,file="D:\miroc-esm-chem\historical\test\historical.dat")!输入文件
do
read(10,*) filename_1
read(11,*) filename_2
read(12,*) filename_3
read(13,*) filename_4
read(14,*) filename_5
!=====================================================================================
!批量打开文件
!=====================================================================================
open(15,file="D:\miroc-esm-chem\historical\pr_v2\1951-1960\filename_1")
open(16,file="D:\miroc-esm-chem\historical\rsds_v1\1951-1960\filename_2")
open(17,file="D:\miroc-esm-chem\historical\tasmax_v1\1951-1960\filename_3")
open(18,file="D:\miroc-esm-chem\historical\tasmin_v1\1951-1960\filename_4")
open(19,file="D:\miroc-esm-chem\historical\test\filename_5")
!=====================================================================================
!文件行数
!=====================================================================================
i = 0
Do
Read (9, *, End=100) line
i = i + 1
End Do
100 m = i
Rewind (9)
!===========================================================
!文件名配对,相同文件合并
!===========================================================
if (filename_1==filename_2.and.filename_2==filename_3.and.filename_3==filename_4.and.filename_4==filename_5)then
allocate(pre(m), rsd(m), tasmax(m), tasmin(m))
do i=1,m
read(15,*)pre(i)
read(16,*)rsd(i)
read(17,*)tasmax(i)
read(18,*)tasmin(i)
write(19,"(5a,2x,6a,2x,6a,2x,5a)") rsd(i), tasmax(i), tasmin(i), pre(i)
end do
deallocate(rsd,tasmax,tasmin,pre)
close(15)
close(16)
close(17)
close(18)
close(19)
end if
end do
end program
|
|