[Fortran] 纯文本查看 复制代码
Program hello
Implicit None
Real :: distance, row_3, k, dd(1,201801)
Integer :: row_1, row_2, i, nn, mm, ii
Real, Allocatable :: lonx(:), laty(:), ilon(:), ilat(:)
!--------------------------------------------------------------------------
!a文件坐标点
!--------------------------------------------------------------------------
nn = 96232
Allocate (lonx(nn), laty(nn))
Open (Unit=11, File='D:\气象数据\tmin\pointmatch_all.txt')
Do i = 1, nn
Read (11, *) row_1, row_2, lonx(i), laty(i), row_3
! write(*,*)lonx(i), laty(i)
End Do
Close (Unit=11)
!----------------------------------------------------------------------------
!b文件坐标点
!----------------------------------------------------------------------------
mm = 201801
Allocate (ilon(mm), ilat(mm))
Open (Unit=12, File='D:\气象数据\tmin\test.txt')
Do ii = 1, mm
Read (12, *) ilon(ii), ilat(ii), row_3
! write(*,*)ilon(ii), ilat(ii)
End Do
Close (Unit=12)
!----------------------------------------------------------------------------
!两个循环用来计算距离
!----------------------------------------------------------------------------
!Allocate (dd(mm))!放入坐标点距离
Open (Unit=13, File='D:\气象数据\tmin\test5.txt')
Do i = 1, nn
Do ii = 1, mm - 1
dd( i,ii) = distance(lonx(i), laty(i), ilon(ii), ilat(ii))
! write (*, *) dd(i,ii)
End Do
Write (*, *) dd(i, ii)
!--------------------------------------------------------------------------
!输出B文件中最近点坐标
!--------------------------------------------------------------------------
k = minloc(dd(i,1:ii), 1)
If (ii/=k) Cycle
!Write (*,*) lonx(i), laty(i), ilon(ii), ilat(ii),kk(ii)
Write (13, *) lonx(i), laty(i), ilon(ii), ilat(ii), dd(i, ii)
End Do
Deallocate (lonx, laty, ilon, ilat)
End Program hello
a文件有96232个坐标点,b有201801个点,我想把这两个文件的坐标点循环计算距离,然后把b中距离a中最近的坐标点(96232个)输出