【发布时间】:2020-01-06 12:21:06
【问题描述】:
我想为非表格数据构建一个数据结构。我不确定在(现代)Fortran 中这样做的正确方法是什么。
我有一组房屋数据,其中包括其位置(纬度、经度)和价格。我有另一个工厂数据,包括它们的位置(纬度,经度)和它们产生的污染量。对于每个房子,我需要创建一个在房子半径 5 公里内的工厂列表。不仅仅是这些工厂的数量,还有这些工厂的整个(纬度、经度、污染)向量。每个房子附近都有不同数量的工厂,从零到大约八十个不等。
MODULE someDefinitions
IMPLICIT NONE
INTEGER, PARAMETER :: N_houses=82390, N_factories=4215
TYPE house
REAL :: lat,lon,price
! a few more fields which are not important here
END TYPE
TYPE factory
REAL :: lat,lon,pollution
! a few more fields which are not important here
END TYPE
Contains
PURE FUNCTION haversine(deglat1,deglon1,deglat2,deglon2) RESULT (dist)
! Some code for computing haversine distance in meters
END FUNCTION haversine
END MODULE someDefinitions
PROGRAM createStructure
USE someDefinitions
IMPLICIT NONE
TYPE(factory), DIMENSION(N_factories) :: factories
TYPE(house), DIMENSION(N_houses) :: houses
INTEGER :: i,j
! more variables definitions as needed
! code to read houses data from the disk
! code to read factories data from the disk
DO i=1,N_houses
DO j=1,N_factories
!here I compute the distance between houses(i) and factories(j)
! If this distance<=5000 I want to add the index j to the list of indices
! associated with house i. How? What is the right data structure to do
! that? some houses have zero factories within 5000 meters from them.
! Some houses have about 80 factories around them. It's unbalanced.
END DO !j
END DO !i
END PROGRAM createStructure
创建的结构随后将用于进一步的计算。 N_houses x N_factories 的矩阵太大而无法保存在内存中。 注意:如果有任何帮助,我知道 Fortran 2008。
【问题讨论】:
-
可能有更好的算法方法来处理您的问题,但乍一看似乎您可能对this other question 的方法感兴趣。