Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic array of matrix

Status
Not open for further replies.

ScMi

Technical User
Apr 16, 2008
1
IT
Hi to All,
is it possible to create an array of n-elements, each of them is a matrix with different dimensions, with n that is an integer determinated by in-code calculation?

Thanks for any suggestion!

Michele
 
Depends on which version of Fortran you're using. With 77 it is possible with a lot of fiddling. With 90 and 95, create each matrix as a type and then create an array of that type.

In the F77 case, create a huge 1D array to hold the values, and another 2D array to hold the starting point and and matrix sizes of the array. Say 1st one is 10x10, 2nd one is 4x5. Assume 6 space indentation
Code:
! stick this in a header
parameter (ixstart = 1, ixrows = 2, ixcols = 3, ixmax = 3)
parameter (nstoremax = 1000, nmatrixmax = 10)
real store(nstoremax)
integer info(nmatrixmax, ixmax), lastinfo, laststore
....
....
! initialization
lastinfo = 0
laststore = 0

integer function matrixadd (ncol, nrow)
include 'headerfile'
integer ncol, nrow
lastinfo = lastinfo + 1
info(lastinfo, ixstart) = laststart + 1
info(lastinfo, ixcols) = ncol
info(lastinfo, ixrows) = nrow
laststart = laststart + nrow * ncol
matrixadd = lastinfo
end

real function matget (mat, jx, jy)
include 'headerfile'
integer ix
ix = info(mat, ixstart) + (jx - 1) * info(mat,ixcols) + jy - 1
matget = store(ix)
end

subroutine matset (mat, jx, jy, val)
include 'headerfile'
integer ix
ix = info(mat, ixstart) + (jx - 1) * info(mat,ixcols) + jy - 1
store(ix) = val
end
With a bit of tweaking, you can get this method to work in the other variants too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top