![forums.silverfrost.com Forum Index](templates/subSilver/images/logo_phpBB.gif) |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Anonymous Guest
|
Posted: Wed May 17, 2006 9:45 am Post subject: How to store variable-dimension arays in a module (or centra |
|
|
Hello. Quick Q. Among the different ways to set up an array with
*variable* dimensions (automatic, allocatable, etc.), I cannot
figure out how to store such an array in a common, central
location for several subroutines to operate on. A module does
not allow variable dimensions, and subroutines (which do allow
variable dimensions) do not allow global, or even territorial,
access to their variables.
Is there a quick solution, or am I trying to do the impossible?
With many thanks,
Ludwig
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Thu May 18, 2006 1:54 am Post subject: How to store variable-dimension arays in a module (or centra |
|
|
Ludwig
Are you sure that you want to access one data array as having different dimensions in different contexts?
Fortran allows you to do this via EQUIVALENCE statements or via COMMON blocks that are defined differently in different context but this is only because Fortran is a very old language.
The only other way that I can think of is to use a one-dimensional array and to calculate the offsets manually (i.e in the code) for other dimensions. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Anonymous Guest
|
Posted: Thu May 18, 2006 11:48 am Post subject: How to store variable-dimension arays in a module (or centra |
|
|
Dear Paul,
Many thanks for your commentary. The array would have consistent dimensions among all the subroutines that access it in a particular program. My reason for wanting variable array dimension is so that I don't have to change the array dimensions in the module that defines the array (i.e., a general math utility placed in a library) when I want to USE it in different programs for different purposes. I am beginning to suspect that what I seek cannot be done....
With many thanks and best regards,
Ludwig
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
brucebowler Guest
|
Posted: Thu May 18, 2006 12:32 pm Post subject: How to store variable-dimension arays in a module (or centra |
|
|
You can create an allocatable array in your main program, decide how big it needs to be, allocate it and then pass it, as an argument, from routine to routine which, unless you're dealing with multiple threads, does what you want to do. That is unless I missed something (entirely possible).
Also, I'm not sure your assertion that a "module does not allow variable dimensions" is correct. From Fortran 90/95 Explained by Metcalf and Reid (page 107 in my copy), they have an example that looks like...
module work_array
integer :: n
real, dimension(:,:, , allocatable :: work
end module work_array
program main
use work_array
read *,n
allocate (work(n,2*n,3*n))
.
.
.
end program main
Again, maybe I'm missing something but that sounds like what you're looking for
Bruce |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Thu May 18, 2006 2:18 pm Post subject: How to store variable-dimension arays in a module (or centra |
|
|
My comment was based on the assumption that you wanted to access some data as a one dimensional array (say) a( in one context and a two dimensional array a(:, in another. If you have a fixed number of dimensions (indexes) and simply want to vary the range in each dimension then that is quite a different thing. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|