[Fortran] 纯文本查看 复制代码
Program weather
Implicit None
Integer l, i, j, m, daysinyear, k, mm, e, z
Integer, Allocatable :: site1(:), site2(:), year(:), month(:), day(:)
Real, Allocatable :: lat(:), lon(:), h(:), tmax(:), tmin(:), lonx(:), laty(:)
Integer :: ave, ier
Real :: h2
Character (45) :: filename = 'SURF_CLI_CHN_MUL_DAY-TEM-12001-123456.txt'
Character (8) :: outfile = '12345678'
Character (Len=20) :: line
!=====================================
Open (5, File='D:\气象数据New\经纬度高程\经纬度高程.txt')
e = 2421
Allocate (site2(e), lonx(e), laty(e))
Do z = 1, e
Read (5, *) site2(z), lonx(z), laty(z), h2
write(*,*) site2(z), lonx(z), laty(z), h2
End Do
Deallocate (site2, lonx, laty)
Close (5)
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 (site1(m), lat(m), lon(m), h(m), year(m), month(m), day(m), tmax(m), tmin(m))
Rewind (11)
mm = 0
Do i = 1, m
mm = mm + 1
Read (11, *) site1(mm), lat(mm), lon(mm), h(mm), year(mm), month(mm), day(mm), ave, tmax(mm), tmin(mm)
lat(mm) = lat(mm)/100
lon(mm) = lon(mm)/100
tmax(mm) = tmax(mm)*0.1
tmin(mm) = tmin(mm)*0.1
If (h(mm)>=100000) Then
h(mm) = (h(mm)-100000)
End If
h(mm) = h(mm)*0.1
If (tmax(mm)==3270.0 .Or. tmax(mm)==3276.6 .Or. tmin(mm)==3270.0 .Or. tmin(mm)==3276.6) mm = mm - 1
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:\气象数据\tmax\'//outfile//'.txt')
Open (Unit=16, File='D:\气象数据\tmin\'//outfile//'.txt')
Do i = 1, mm
If (l==year(i) .And. j==month(i) .And. k==day(i)) Then
Do While (site1(i)==site2(z))
Write (15, '(i5,2x,f6.2,2x,f5.2,2x,f12.4,2x,f12.4,2x,f6.2)') &
&site1(i), lon(i), lat(i), lonx(z), laty(z), tmax(i) + (h(i)/100)*0.6
! "(i5,2x,f5.2,2x,f6.2,2x,f5.0,2x,i5,2x,i2,2x,i2,2x,f6.2)"
Write (16, '(i5,2x,f6.2,2x,f5.2,2x,f12.4,2x,f12.4,2x,f6.2)') &
&site1(i), lon(i), lat(i), lonx(z), laty(z), tmin(i) + (h(i)/100)*0.6
Print *, site1(i), year(i), month(i), day(i)
End Do
End If
End Do
Close (Unit=15)
End Do
Deallocate (site1, lat, lon, h, year, month, day, tmax, tmin)
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