[Fortran] 纯文本查看 复制代码
Program weather
Implicit None
Integer l, i, j, m, daysinyear, k
Integer, Allocatable :: site(:), lat(:), lon(:), year(:), month(:), day(:)
real, Allocatable :: rain(:)
Integer :: h, pre1, pre2, ier
Character (45) :: filename = 'SURF_CLI_CHN_MUL_DAY-PRE-13011-123456.txt'
Character (8) :: outfile = '12345678'
Character (Len=20) :: line
!=====================================
DO l = 2010, 2015
DO j = 1, 12
WRITE(filename(32:37),'(i6)') l*100+j
OPEN( UNIT=11, FILE='D:\气象?据\降水\'//filename, ACTION='READ' )
m = 0
DO
READ(11,*,IOSTAT=ier) line
IF( ier == -1 ) EXIT ! end-of-file
m = m + 1
END DO
ALLOCATE (site(m), lat(m), lon(m), year(m), month(m), day(m), rain(m))
REWIND(11)
DO i = 1, m
READ(11,*) site(i), lat(i), lon(i), h, year(i), month(i), day(i), pre1, pre2, rain(i)
rain(i) = rain(i)/10.0
IF( rain(i) == 3270.0 ) rain(i) = 0.0
END DO
CLOSE( UNIT=11 )
DO k = 1, daysinyear(l, j)
WRITE(outfile(1:8),'(i8)') l*10000 + j*100 + k
OPEN( UNIT=15, FILE='D:\气象?据\pre\'//outfile//'.txt' )
DO i = 1, m
IF( l==year(i) .AND. j==month(i) .AND. k==day(i) ) THEN
Write (15, "(i5,2x,i4,2x,i5,2x,i4,2x,i2,2x,i2,2x,f5.2)") site(i), lat(i), lon(i), year(i), month(i), day(i), rain(i)
WRITE(*,*) site(i), lat(i), lon(i), year(i), month(i), day(i), rain(i)
END IF
END DO
CLOSE( UNIT=15 )
END DO
DEALLOCATE( site, lat, lon, year, month, day, rain )
END DO
END DO
End Program weather
!=======================================
Integer Function daysinyear(year, month)
Integer, INTENT(IN) :: year, month
Integer :: daysinmonth(12) = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
If (((mod(year,4)==0) .And. (mod(year,100)/=0)) .Or. (mod(year,400)==0)) Then
daysinmonth(2) = 29
Else
daysinmonth(2) = 28
End If
daysinyear = daysinmonth(month)
End Function daysinyear