Re: Allocatable Arrays As Outputs
- From: "Craig Dedo" <cdedo@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 13:17:36 -0600
"Reinhold Bader" <Bader@xxxxxx> wrote in message news:fnq9fb$esc$1@xxxxxxxxxxxxxxxxxxxxxxx
Hello,
Infinity77 schrieb:
Hi All,
first of all, please forgive my poor mastering of Fortran. I am
still a beginner who uses Fortran sporadically.
I have a subroutine in which I declare 4 output variables as
allocatable. This is because, a priori, I don't know their lengths
(they're all one-dimensional vectors), and I discover this information
only when I read a file which contains both their lengths and the data
used to fill these vectors.
My problem is, I don't know how to correctly "declare" these variables
in the main program, as I keep getting errors on assumed-shape/size
and dummy arguments. My knowledge of Fortran is so slim I can't find a
way to solve this problem.
I am attaching a simplified version of my small program (1 subroutine
+ the main) in which I have only 1 allocatable array. I have used my
google-fu but either I can't interpret correctly the problem or what I
am doing is completely wrong.
Thank you for all your suggestions.
<snip>
Andrea.
Allocatable subroutine arguments may not be supported by every
compiler (while they are standard conforming in F2003, they're not
in Fortran 95 or earlier).
Even so, they require
a) an explicit interface (e.g., your subroutine ReadINSPEC should be
contained in a module, which in turn is use associated by the caller).
b) the actual argument to be an allocatable entity of same type, kind and rank.
Even though the Fortran 95 standard does not support allocatable arrays as procedure arguments, function results, or components of derived types, they are part of Fortran 2003. More importantly, removing these three restrictions on the use of allocatable arrays is at or near the top of the priority list of Fortran 2003 features for implementation with almost every Fortran compiler still under active development.
Therefore, there is little real risk in using allocatable arrays in these contexts.
Using allocatable arrays is preferable to using pointers to allocatable arrays, as suggested by another poster. Direct use of allocatables is easier to understand and easier to avoid troublesome mistakes.
In order to use allocatables in your procedures, you need to add the "Allocatable" attribute to the declaration of your arrays in the main program. E.g., you would write:
Character (Len=8), Allocatable :: propertyNames(:)
Hope this helps.
--
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423
Brookfield, WI 53008-0423
Voice: (262) 783-5869
Fax: (262) 783-5928
Mobile: (414) 412-5869
E-mail: <cdedo@xxxxxxxxx> or <craig@xxxxxxxxxx>
.
- Follow-Ups:
- Re: Allocatable Arrays As Outputs
- From: Richard Maine
- Re: Allocatable Arrays As Outputs
- References:
- Allocatable Arrays As Outputs
- From: Infinity77
- Re: Allocatable Arrays As Outputs
- From: Reinhold Bader
- Allocatable Arrays As Outputs
- Prev by Date: Re: Code as documentation
- Next by Date: Re: The concept of a record
- Previous by thread: Re: Allocatable Arrays As Outputs
- Next by thread: Re: Allocatable Arrays As Outputs
- Index(es):
Relevant Pages
|
|