- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
heres my problem,
When declaring my common statements such as...
common /cmg/ ng,ni(nb),nj(nb),nk(nb), ntsteps(nmax2)
I keep receiving this error...
D:Larryinit.f(10) : Error: A COMMON block data object must not be an automatic object. [NTSTEPS]
I get this error when my values in paranthesis are not hard coded into the program, but user defined (in this case nmax2). How could I declare my matrices in the common statements and still let the user define the value, without receiving this error?
When declaring my common statements such as...
common /cmg/ ng,ni(nb),nj(nb),nk(nb), ntsteps(nmax2)
I keep receiving this error...
D:Larryinit.f(10) : Error: A COMMON block data object must not be an automatic object. [NTSTEPS]
I get this error when my values in paranthesis are not hard coded into the program, but user defined (in this case nmax2). How could I declare my matrices in the common statements and still let the user define the value, without receiving this error?
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error message is telling you that any data you place in a COMMON block must be static, meaning that the size must be known at compile time. Space for a COMMON block is not allocated at runtime. Why does this data need to be in a COMMON block?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am rewriting a pre-existing program. One parameter that was hard-coded in the program before is now user defined. This parameter sets the size for many arrays, (which is used in many common statements). I just want to know if theres a simple code I can change or if I need to start from scratch. Like, if there is another way i can declare these arrays, where i will not receive this error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have to get the arrays out of the common block. Once that is done, you can use allocatable arrays to do the job. Whether moving your array out of the common blocks is a big deal depends upon your code, but either you can define a structure to contain the data and pass it around if the number of routines is small, or move these variables to a module and make them public, like global variables, and USE that module in the relevant routines.
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can i declare these structures in a module without a common statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Example:
prog.f90
Have fun.
data.f90
module data integer max_element integer, allocatable :: global_array(:) end module data
prog.f90
program main use data integer i max_element = 1000 allocate (global_array(max_element)) do i = 1, max_element global_array(i) = i end do call sub end subroutine sub use data type *, global_array(max_element/2) return end
Have fun.
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just a side warning: if all instances of original common /cmg/ were declared the same (i.e. same types, order & sizes, not necessarily names), James' suggestion will work fine. However, "old masters" sometimes used commons for cheating, i.e. declaring work arrays which were mapped to something else as needed in order to spare memory, kinda:
common /cmg/ ng, ni(nb), nj(nb), nk(nb) ... common /cmg/ iwork(3*nb+1) ... common /cmg/ ng,array(2*nb)This kind of spaghetti is hard to unwind if that's the case.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page