我目前正在努力了解更多关于Fortran的细节。 在此过程中,我正在尝试使用已经用Python实现的算法来实现它。 我有一个小数组,看起来像这样:
small_array = some_class(a, b, [x,y,z])
使用小数组创建一个中等大小的数组。
medium_array = [small_array_1, small_array_2, ...]
使用m个中等大小的数组,创建一个大数组。
big_array = [medium_array_1, medium_array_2, ...]
我曾在Fortran中尝试使用派生类型,但这样只会以一种更加困难的方式得到所需的功能。
我想要做的是获得big_array中medium_array的数量以及medium_array中small_array的数量。我尝试使用Extent(...)
,但这不能用于派生类型。
我还想以标准数组的方式访问这些派生类型(或者其他可行的方法),例如big_array(1,1,:)
,以便访问第一个 big_array 和middle_array 中的所有 small_arrays。
是否有更好的方式来实现此目的?
编辑: 以下是我正在尝试在Fortran中定义的内容(Python代码):
H1_pg1a = primitive_gaussian(some values..) # These will be derive types in Fortran i suppose, in python these are implemented as class
H1_pg1b = primitive_gaussian(some values..)
H1_pg2a = primitive_gaussian(some values..)
H2_pg1a = primitive_gaussian(some values..)
H2_pg1b = primitive_gaussian(some values..)
H2_pg2a = primitive_gaussian(some values..)
H1_1s = [H1_pg1a, H1_pg1b] # These will be lists of derive types
H1_2s = [H1_pg2a]
H2_1s = [H2_pg1a, H2_pg1b]
H2_2s = [H2_pg2a]
molecule = [H1_1s, H1_2s, H2_1s, H2_2s] # These will be lists of lists of derive types
我需要做的是获取有关分子的一些信息:
nbasis = len(molecule)
这将会被实现成类似如下的方式:
for i in range(nbasis): # iteration über spalten
for j in range(nbasis): # iteraion über zeilen
nprimitives_i = len(molecule[i])
nprimitives_j = len(molecule[j])
for k in range(nprimitives_i):
for l in range(nprimitives_j):
...
我希望能够像这样访问类或派生类型的值
molecule[i][k].some_value
我开始实现
primitive_gaussian
作为一个派生类型,然后定义另一个派生类型用于派生类型列表以及派生类型列表的列表。通过这样做,我只能使用molecule%H1_1s&H1_pg1a%some_value
访问值,但我无法迭代它们。
small_array
和medium_array
是派生类型吗?如果是,那么Size
内置函数是否符合您的要求? - Ian Bush