|
板凳
楼主 |
发表于 2017-3-19 14:12:28
|
只看该作者
本帖最后由 wxy 于 2017-3-19 14:14 编辑
再请教一下,我把计算出来的距离放入动态数组near,用minval找到距离最小值,如果要把最小值所在的那一行输出,应该怎么改呢,minloc和minval第一次用,[Fortran] 纯文本查看 复制代码 real function distance(lat1, lon1, lat2, lon2)
real , parameter :: R=6378.137
real lon1 , lat1 , lon2 , lat2
distance = abs(R*cos(lon1)*cos(lat1)+R*cos(lon2)*cos(lat2))/sqrt(sin(lon1)**2*sin(lon2)**2+sin(lat1)**2*sin(lat2)**2)
end function distance
program none
implicit none
integer i,m
character(len=12):: site
real :: lat , lon , lat1 , lon1 , distance , loc , nearmin
real , allocatable :: lat2(:) , lon2(:) , near(:)
open(7,file="find_close.txt")
open(10,file="near.txt")
m=46154 !行数
allocate(lat2(m),lon2(m),near(m))
Write (*,*) 'lon:'!输入经度
Read (*, '(f7.3)') lon
Write (*,*) 'lat:'!输入纬度
Read (*, '(f6.3)') lat
do i=1,m
lon1=lon
lat1=lat
read(7,*) site , lat2(i) , lon2(i)
write(10,'(a9,2x,f6.2,2x,f7.2,2x,f11.2)') site , lat2(i) , lon2(i) , distance(lat1, lon1, lat2(i), lon2(i))
end do
close(10)
!======================================================================================================================
open(10,file="near.txt")
do i=1,m
read(10,*)site , lat2(i) , lon2(i) , near(i)
nearmin= minval(near(:))
loc=minloc(near(:),1)
print *, nearmin, loc
end do
end program
|
|