program pwv_mon_avg
implicit none
integer :: stat,i,j,stat2,year,mon,mon_def(12)
character :: filename*12,filename_new*16
real*8 :: pwv_mm,sum,pwv_mon_mean
open (11,file='list.txt')
close (11,status='delete')
call system ('for %f in (*_mon.pwv) do echo %f >> list.txt')
open (11,file='list.txt')
mon_def=(/ 01,02,03,04,05,06,07,08,09,10,11,12 /)
stat=0
do while (stat==0)
read (11,*,iostat=stat) filename
if (stat/=0) exit
open (22,file=filename)
filename_new=filename(1:4)//'_mon_avg.pwv'
open (33,file=filename_new)
do i=1,12,1
j=0
stat2=0
do while (stat2==0)
read (22,*,iostat=stat2) year,mon,pwv_mm
if (stat2/=0) exit
if (mon==mon_def(i))then
j=j+1
if (j==1) then
sum=pwv_mm
else if (j>1) then
sum=sum+pwv_mm
end if
else
cycle
end if
end do
pwv_mon_mean= sum / (j*1D0)
write (33,'(i2.2,3x,f12.7)') mon,pwv_mon_mean
end do
end do
end program
1.76 KB, 下载次数: 4
以更新數據
fcode 发表于 2014-12-7 18:33
数据文件是空白的
program pwv_mon_avg
implicit none
integer :: stat, stat2, i, year, mon, mon_num(12)
character :: filename*12, filename_new*16
real(8) :: pwv_mm, pwv_mon_mean(12)
open (11,file='list.txt')
close (11,status='delete')
call system ('for %f in (*_mon.pwv) do echo %f >> list.txt')
open (11,file='list.txt')
do
read (11,*,iostat=stat) filename
if (stat/=0) exit
filename_new=filename(1:4)//'_mon_avg.pwv'
open (33,file=filename_new)
open (22,file=filename)
mon_num(:) = 0
pwv_mon_mean(:) = 0.0d0
do
read (22,*,iostat=stat2) year, mon, pwv_mm
if (stat2/=0) exit
pwv_mon_mean(mon) = pwv_mon_mean(mon) + pwv_mm
mon_num(mon) = mon_num(mon) + 1
end do
do i = 1, 12
if( mon_num(i)/=0 ) pwv_mon_mean(i) = pwv_mon_mean(i) / mon_num(i)
write (33,'(i2.2,3x,f12.7)') i, pwv_mon_mean(i)
end do
close(22)
close(33)
end do
close (11,status='delete')
write(*,*) "completed..."
read(*,*)
end program
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |