[Fortran] 纯文本查看 复制代码
program filter_radiosonde
implicit none
integer :: stat,time_array_size,stat2,array_size,i,yr,doy,hr,stat3,array_pointer,stat4,stat5,RH,height
integer, allocatable :: RH_array(:),yr_array(:),doy_array(:),hr_array(:)
character :: filename*50,filename_correct*50,time_error*50,file_error*50
real*8 :: last_timeall,pressure,temp,timeall
real*8, allocatable :: time_array(:),timeall_array(:),height_array(:),pressure_array(:),temp_array(:)
logical :: array_logical
open (11,file='list.txt')
close (11,status='delete')
call system ('dir /b *.radio1 > list.txt')
open (11,file='list.txt')
stat=0
do while (stat==0)
read (11,*,iostat=stat) filename
if (stat/=0) exit
open (22,file=trim(filename))
filename_correct=filename(1:6)//'_c.radio1'
time_error=filename(1:6)//'_e.time'
file_error=filename(1:6)//'_e.radio1'
open (33,file=trim(filename_correct))
open (44,file=trim(time_error))
open (55,file=trim(file_error))
time_array_size=0
last_timeall=0.0
stat2=0
do while (stat2==0)
read (22,*,iostat=stat2)
if (stat2/=0) then
time_array_size=time_array_size+1
last_timeall=timeall
end if
if (stat2/=0) exit
if (timeall - last_timeall < 1.0d-7) then
time_array_size=time_array_size+1
last_timeall=timeall
end if
end do
rewind (22)
if (.not. allocated(time_array)) then
allocate (time_array(time_array_size))
end if
time_array_size=0
last_timeall=0.0
stat3=0
do while (stat3==0)
read (22,*,iostat=stat3)
if (stat3/=0) then
time_array_size=time_array_size+1
time_array(time_array_size)=timeall
last_timeall=timeall
end if
if (stat3/=0) exit
if (timeall-last_timeall<1d-7) then
time_array_size=time_array_size+1
time_array(time_array_size)=timeall
last_timeall=timeall
end if
end do
rewind (22)
array_size=0
do i=1,time_array_size
if ( allocated(timeall_array) .or. array_size/=0 ) then
deallocate (timeall_array(array_size))
deallocate (height_array(array_size))
deallocate (pressure_array(array_size))
deallocate (temp_array(array_size))
deallocate (RH_array(array_size))
deallocate (yr_array(array_size))
deallocate (doy_array(array_size))
deallocate (hr_array(array_size))
end if
stat4=0
do while (stat4==0)
read (22,*,iostat=stat4) timeall,height,pressure,temp,RH,yr,doy,hr
if (stat4/=0) exit
if (time_array(i)-timeall<1d-7) then
array_size=array_size+1
end if
if (timeall - time_array(i)>0) exit
end do
rewind (22)
if (.not. allocated (timeall_array)) then
allocate (timeall_array(array_size))
allocate (height_array(array_size))
allocate (pressure_array(array_size))
allocate (temp_array(array_size))
allocate (RH_array(array_size))
allocate (yr_array(array_size))
allocate (doy_array(array_size))
allocate (hr_array(array_size))
end if
array_pointer=0
stat5=0
do while (stat5==0)
read (22,*,iostat=stat5) timeall,height,pressure,temp,RH,yr,doy,hr
if (stat5/=0) exit
if (time_array(i)-timeall<1d-7) then
array_pointer=array_pointer+1
timeall_array(array_pointer)= timeall
height_array(array_pointer)= height
pressure_array(array_pointer)= pressure
temp_array(array_pointer)= temp
RH_array(array_pointer) = RH
yr_array(array_pointer) = yr
doy_array(array_pointer) = doy
hr_array(array_pointer) = hr
end if
if (timeall - time_array(i)>0) exit
end do
rewind (22)
array_logical=.true.
if ( height_array(1) - 300.0 > 1d-7 .or. pressure_array(array_size) - 300.0 < 1d-7 ) then
array_logical=.false.
end if
do array_pointer=1,array_size-1
if (pressure(array_pointer+1)-pressure(array_pointer) > 200.0 ) then
array_logical=.false.
end if
end do
if (array_logical) then
write (44,30) timeall_array(1),yr_array(1),doy_array(1),hr_array(1)
30 format (f12.7,1x,i4.4,1x,i3.3,1x,i2.2)
end if
do array_pointer=1,array_size
if (array_logical) then
write (33,50) timeall_array(array_pointer),height_array(array_pointer),pressure_array(array_pointer)&
&,temp_array(array_pointer),RH_array(array_pointer),yr_array(array_pointer)&
&,doy_array(array_pointer),hr_array(array_pointer)
50 format (f12.7,1x,i5.5,1x,f6.1,1x,f5.1,1x,i3.3,1x,i4.4,1x,i3.3,1x,i2.2)
else if (.not. array_logical) then
write (55,50) timeall_array(array_pointer),height_array(array_pointer),pressure_array(array_pointer)&
&,temp_array(array_pointer),RH_array(array_pointer),yr_array(array_pointer)&
&,doy_array(array_pointer),hr_array(array_pointer)
end if
end do
end do
close (22)
close (33)
close (44)
close (55)
end do
end program