- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems like every time I try to allocate the dimensions of an array in a subroutine I get the following error message:
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nevermind, I got it. The declaration must explicitly state that the array is in fact allocatable as follows:
double precision, dimension(:,:),allocatable :: ArrayName
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 .
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page