program nc2dssat
implicit none
integer i ,m
character,allocatable :: pre(:), rsd(:), tasmax(:), tasmin(:)
character(len=512) :: filename_1, filename_2, filename_3, filename_4
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") !最低温
do
read(10,*) filename_1
read(11,*) filename_2
read(12,*) filename_3
read(13,*) filename_4
open(10,file=filename_1)
open(11,file=filename_2)
open(12,file=filename_3)
open(13,file=filename_4)
i=3652 !文件行数
m=i
!===========================================================
!文件名配对,相同文件合并
!===========================================================
if (filename_1==filename_2.and.filename_1==filename_3.and.filename_1==filename_4)then
allocate(pre(m), rsd(m), tasmax(m), tasmin(m))
open(14,file="D:\miroc-esm-chem\historical\test.txt")
do i=1,m
read(10,*)pre(i)
read(11,*)rsd(i)
read(12,*)tasmax(i)
read(13,*)tasmin(i)
write(14,"(5a,2x,6a,2x,6a,2x,5a)") rsd(i), tasmax(i), tasmin(i), pre(i)
end do
close(10)
close(11)
close(12)
close(13)
close(14)
deallocate(rsd,tasmax,tasmin,pre)
end if
end do
end program
QQ截图20170422142058.png (31.94 KB, 下载次数: 349)
QQ截图20170422153520.png (30.76 KB, 下载次数: 352)
fcode 发表于 2017-4-22 16:38
open(10,file="D:\miroc-esm-chem\historical\pr_v2\1951-1960\pre.dat") !降水
open(11,file="D:\mi ...
QQ截图20170422184012.png (27.78 KB, 下载次数: 329)
fcode 发表于 2017-4-22 19:28
给出 pre.dat , rsd.dat , tasmax.dat 和 tasmin.dat 文件的内容
QQ截图20170422193747.png (9.93 KB, 下载次数: 333)
fcode 发表于 2017-4-22 19:28
给出 pre.dat , rsd.dat , tasmax.dat 和 tasmin.dat 文件的内容
fcode 发表于 2017-4-22 19:28
给出 pre.dat , rsd.dat , tasmax.dat 和 tasmin.dat 文件的内容
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
QQ截图20170423003133.png (38.2 KB, 下载次数: 375)
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |