- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I've a work area in my program stored in a single one-dimensional array; I'd like to redefine this area using multidimensional arrays(two, three or four). Is there any efficient way to do that?
Thank you in advance,
Luiz.
I've a work area in my program stored in a single one-dimensional array; I'd like to redefine this area using multidimensional arrays(two, three or four). Is there any efficient way to do that?
Thank you in advance,
Luiz.
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the array is a local variable (not an argument), or is in COMMON, use EQUIVALENCE.
Another method is to pass the array as an argument to a subroutine that declares the argument wth the shape you want. Depending on what you want to do with it, the RESHAPE intrinsic may be of help - it will return a copy of the array with a different shape - you could store this in another array, but this means making a copy.
Another option is to use the "Compaq Fortran POINTER extension" as it is termed, for example:
Steve
Another method is to pass the array as an argument to a subroutine that declares the argument wth the shape you want. Depending on what you want to do with it, the RESHAPE intrinsic may be of help - it will return a copy of the array with a different shape - you could store this in another array, but this means making a copy.
Another option is to use the "Compaq Fortran POINTER extension" as it is termed, for example:
real array1d(10000) real array2d(100,100) pointer (p,array2d) ... p = loc(array1d) ! Now use array2d
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve for your answer,
but my point is the following:
in your example, using array1d and array2d, one needs to use
twenty thousand real positions, ten thousand for the first and ten
thousand for the second. Is there any way to spend only ten thousand
positions as in I?
Thank you again,
quiz
but my point is the following:
in your example, using array1d and array2d, one needs to use
twenty thousand real positions, ten thousand for the first and ten
thousand for the second. Is there any way to spend only ten thousand
positions as in I?
Thank you again,
quiz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Luiz,
In my example using POINTER, there are only 10,000 "real positions". array2d is not allocated any memory at all - it is considered to "live" at whatever address is stored in the pointer variable p, which is assigned the address of array1d. So in essence, the two arrays share the same space.
Steve
In my example using POINTER, there are only 10,000 "real positions". array2d is not allocated any memory at all - it is considered to "live" at whatever address is stored in the pointer variable p, which is assigned the address of array1d. So in essence, the two arrays share the same space.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
The alternative that mixes POINTER and LAC is fine, thank you. The
only problem is that, as the compilers points out, this is not a F95
standard. Do you know any F95 standard that does the same
construction (an allocated work one dimensional array that changes shape)
Thanks,
quiz
The alternative that mixes POINTER and LAC is fine, thank you. The
only problem is that, as the compilers points out, this is not a F95
standard. Do you know any F95 standard that does the same
construction (an allocated work one dimensional array that changes shape)
Thanks,
quiz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Passing arrays as arguments to subprograms passes the address of the first array element. Can't you redeclare the array to be any shape you want inside the subprogram?
For example, if you pass a 1000-element array A to a subprogram, then isn't the subprogram free to redeclare the array as B(10,10,10)? I think that's standard Fortran, but it requires you to do all the processing on the reshaped array within the subprogram. To prevent the subprogram from accessing the wrong parts of memory, the total number of array elements in the subprogram should be <= that of the array in the calling routine.
Mike Durisin
For example, if you pass a 1000-element array A to a subprogram, then isn't the subprogram free to redeclare the array as B(10,10,10)? I think that's standard Fortran, but it requires you to do all the processing on the reshaped array within the subprogram. To prevent the subprogram from accessing the wrong parts of memory, the total number of array elements in the subprogram should be <= that of the array in the calling routine.
Mike Durisin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mike,
That works - and was one of the first things I suggested. Yes, it is standard-conforming.
Steve
That works - and was one of the first things I suggested. Yes, it is standard-conforming.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry to repeat that information. I should have paid closer attention to what you wrote.
Mike
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If Ive understood Mike and Steve ideas, I may sum up three possibilities:
- common and/or equivalence
- reshape
- doc and pointer
There is still another, following Steve, that is to re shape
the rank of the vector intrinsically by defining the vector inside the called subroutine with a different rank from the one used in the calling subroutine.
But this alternative does not work if Ive to use an INTERFACE to pass
the parameters, and thats my actual problem.
My conclusion is: or I use RESHAPE and, as Steve said, Ill copy the original
array in a new one (and I wouldnt like to do that, otherwise Ill probably have memory problems) or I use a nonstandard
F9x feature LOC and POINTER with pointee. The COMOM alternative is not
possible in my case.
Am I wrong?
Thank you in advance.
Luiz.
If Ive understood Mike and Steve ideas, I may sum up three possibilities:
- common and/or equivalence
- reshape
- doc and pointer
There is still another, following Steve, that is to re shape
the rank of the vector intrinsically by defining the vector inside the called subroutine with a different rank from the one used in the calling subroutine.
But this alternative does not work if Ive to use an INTERFACE to pass
the parameters, and thats my actual problem.
My conclusion is: or I use RESHAPE and, as Steve said, Ill copy the original
array in a new one (and I wouldnt like to do that, otherwise Ill probably have memory problems) or I use a nonstandard
F9x feature LOC and POINTER with pointee. The COMOM alternative is not
possible in my case.
Am I wrong?
Thank you in advance.
Luiz.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, you could add:
!DEC$ ATTRIBUTES NO_ARG_CHECK :: argname
in the INTERFACE - this will suppress shape-matching warnings for this argument. That is non-standard, of course.
Another idea is to pass just the first element of the array - Fortran language rules for sequence association should do the rest.
Steve
!DEC$ ATTRIBUTES NO_ARG_CHECK :: argname
in the INTERFACE - this will suppress shape-matching warnings for this argument. That is non-standard, of course.
Another idea is to pass just the first element of the array - Fortran language rules for sequence association should do the rest.
Steve

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page