Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26755 Discussions

Allocatable or pointer attribute missing

awa5114
Beginner
154 Views

It seems like every time I try to allocate the dimensions of an array in a subroutine I get the following error message:

Error 3 error #6596: If a deferred-shape array is intended, then the ALLOCATABLE or POINTER attribute is missing; if an assumed-shape array is intended, the array must be a dummy argument. 
 
I do not wish to make a dummy argument. This array is local and needs to stay within the subroutine. Therefore I am left with the first option. Yes this is a deferred shape array and that is the intent. Do I need to add an intent statement to the declaration? How can I get the array to carray the allocatable attribute?
0 Kudos
6 Replies
awa5114
Beginner
154 Views

Nevermind, I got it. The declaration must explicitly state that the array is in fact allocatable as follows:

double precision, dimension(:,:),allocatable :: ArrayName

 

andrew_4619
Honored Contributor I
154 Views
double precision, dimension(:,:),allocatable :: ArrayName

real(dp), allocatable :: ArrayName(:,:)

It is mainly a style thing but the dimension attribute is largely superfluous these days. "Double precision" is also rather old hat, the "modern" way is to use REAL of a specific KIND.  This is more flexible in that you can then easily change the real kind

jimdempseyatthecove
Black Belt
154 Views

>>It is mainly a style thing but the dimension attribute is largely superfluous these days

Not when you wish to apply the array shape to multiple arrays:

double precision, dimension(:,:),allocatable :: ArrayName. BrrayName, CrrayName

Jim Dempsey

andrew_4619
Honored Contributor I
154 Views

jimdempseyatthecove wrote:

>>It is mainly a style thing but the dimension attribute is largely superfluous these days

Not when you wish to apply the array shape to multiple arrays:

double precision, dimension(:,:),allocatable :: ArrayName. BrrayName, CrrayName

Jim Dempsey

True, I did say " mostly". The usage I object to most is when the dimension statement is on a separate line and even worse seperated several lines from the type declareration. Do be honest I wouldn't lose any sleep if dimension was deleted from the language and I would bet if the language was being defined today it would not exist. 

FortranFan
Honored Contributor II
154 Views

jimdempseyatthecove wrote:

>>It is mainly a style thing but the dimension attribute is largely superfluous these days

Not when you wish to apply the array shape to multiple arrays:

double precision, dimension(:,:),allocatable :: ArrayName. BrrayName, CrrayName

Jim Dempsey

Since Andrew's comment was in connection with style, readers may want to note there is growing consensus from a style perspective in the programming community spanning different languages and paradigms to have only

    one variable per declaration

Some quick links on this view include Google Java Style Guide and C++ for Programmers, etc.  

Given all the attributes one can tack on to variable declarations in Fortran, I suggest the same style and avoid statements such as 

double precision, dimension(:,:),allocatable :: ArrayName. BrrayName, CrrayName

 

andrew_4619
Honored Contributor I
154 Views

I would agree with FF. Whilst I don't religiously follow one variable per declaration I do follow that rule for the most part particularly so with dummy args as it give much more clarity to see things at a glance IMO and also the option to tag a comment on the end .

Reply