Re: Allocatable Arrays As Outputs



"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>

.



Relevant Pages

  • Allocatable Arrays As Outputs
    ... please forgive my poor mastering of Fortran. ... I don't know how to correctly "declare" these variables ... I am attaching a simplified version of my small program (1 subroutine ... readkeywordName, numberOfProps, ...
    (comp.lang.fortran)
  • Re: Help! Bug that I can not figure out
    ... Fortran however doesn't do optional arguments like ... The first thing that the subroutine does is read ... C Declare the C function ... INTERFACE!emrl ...
    (comp.lang.fortran)
  • Re: pointer plus an integer
    ... The biggest attraction to f77 was the dynamically allocatable array, at least so says Richard Maine. ... f90 allowed free-form, with much more-relaxed rules for appearance. ... It didn't have allocatable arrays. ... and he seems to be a walking fortran encyclopedia. ...
    (comp.lang.c)
  • Re: Problem to pass complex array between subroutine and main program
    ... some compilers and there is a "technical report" about the ... allocatable arrays (that is: official enhancements are possible). ... Allocatable procedure arguments are part of Fortran 2003 and are ...
    (comp.lang.fortran)
  • Re: Fortran90 to C
    ... >FORTRAN to C converter. ... ALLOCATABLE arrays, MODULEs, array operations, and other key F90 features. ... It is unlikely to be useful to someone who has used modern Fortran. ...
    (comp.lang.fortran)