数组内的Fortran数组

Gvi*_*000 3 arrays fortran matrix dimension

我试图在Fortran中创建一个类似于MATLAB中的单元格的数组.

基本上(例如)我试图创建一个数组X(10),其中元素X(1)是一个维度为(20,2)X(2)的数组,是一个维度为(25,2)的数组,等等.

我怎样才能做到这一点?

Ian*_*anH 5

使用包含单个组件的派生类型可以实现特定情况的等效.单元阵列对应于该派生类型的数组,位于单元阵列的每个元素内的数组则是每个数组元素的数组分量.

就像是:

TYPE Cell
  ! Allocatable component (F2003) allows runtime variation 
  ! in the shape of the component.
  REAL, ALLOCATABLE :: component(:,:)
END TYPE Cell

! For the sake of this example, the "cell array" equivalent 
! is fixed length.
TYPE(Cell) :: x(10)

! Allocate components to the required length.  (Alternative 
! ways of achieving this allocation exist.)
ALLOCATE(x(1)%component(20,2))
ALLOCATE(x(2)%component(25,2))
...
! Work with x...
Run Code Online (Sandbox Code Playgroud)

MATLAB中的单元比上面的特定类型具有更多的灵活性(这实际上更类似于结构的MATLAB概念).对于接近单元阵列灵活性的东西,您需要使用无限多态组件和其他中间类型定义.