I currently have a 6D numpy array in Python, where the first 4 indices specify which 2D matrix is required. I can pass that into Fortran90 using f2py, then access the 2D matrices using:
subroutine mySubroutine(myArray)
real(8), dimension(:,:,:,:,:,:) :: myArray
matrix = myArray(a,b,c,d,:,:)
However, the matrices can in general be different sizes. The only method I've found that allows for this is to make the final two dimensions equal to the largest possible size, store smaller matrices in the top left, and get the smaller matrix using:
matrix = myArray(a,b,c,d,1:matrixSize,1:matrixSize)
The problem with this is that it's very inefficient memory-wise, as I'm storing huge empty sections of the array that are never used. In Python I can address this by making lists of lists of lists of lists of 2D numpy arrays of the correct size, but I'm not sure how to pass them to Fortran using f2py, or if that's even possible. Any ideas would be appreciated. Thanks!