- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using a set of C++ sparsematrix routines to represent sparse matrices in Fortran. I also have a toggle to switch between the Fortran arrays (ie. full) and the sparse functions. Trouble is that references exist to these sparse matrices all over the code and I have to put this code in everywhere I use this functionality:
if(iway == 0) then ! the old "full array" way
ALLOCATE ( GTJACB(NNIN+3,NNIN+3,LQTEAR) )
GTJACB = 0.D0
else ! the new sparse array function
iGTJACB = matrixCreate(NNIN+3,NNIN+3,LQTEAR)
endif
These can be 1 or 2 dimensional arrays too, eg:
if(iway == 0) then
ALLOCATE ( CREVAL(NNMOL1) )
CREVAL = 0.0D0
else
iCREVAL = matrixCreate(NNMOL1,1,1)
endif
I want to replace all these blocks with one call such as:
iGTJACB = f_matrixCreate(GTJACB,NNIN+3,NNIN+3,LQTEAR)
iCREVAL = f_matrixCreate(CREVAL,NNMOL1)
In the latter case CREVAL is a 1 dimensional array.
The code of f_matrixCreate should look something like:
INTEGER FUNCTION f_matrixCreate(iway, fArr, nSizeA, nSizeB, nSizeC)
IMPLICIT NONE
include 'sparsematrix.inc'
INTEGER :: iway
REAL*8, allocatable :: fArr(:,:,:)
INTEGER :: nSizeA
INTEGER :: nSizeB
INTEGER :: nSizeC
if(iway == 0) then
ALLOCATE ( fArr(nSizeA, nSizeB, nSizeC) )
fArr = 0.D0
else
f_matrixCreate = matrixCreate(nSizeA, nSizeB, nSizeC)
endif
RETURN
END
However this fails with an access violation on the ALLOACTE statement. I guess the syntax is not correct. Any idea how the code should look? Also what about the 1 and 2 dimensional cases? Do I need separate functions for 1, 2 and 3 dimensional cases?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sblionel wrote:Sounds like a good solution. Do you have an example of this?
You can't do it this way. The Fortran way to do this is to have separate procedures which accept the array as rank 1, 2 and 3, and then declare a generic interface with the three module procedures. The compiler will automatically select the correct one depending on which rank argument is passed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page