Software Archive
Read-only legacy content
17060 Discussions

Automatic Objects

Intel_C_Intel
Employee
2,773 Views
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?
0 Kudos
6 Replies
james1
Beginner
2,773 Views
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?
0 Kudos
Intel_C_Intel
Employee
2,773 Views
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
0 Kudos
james1
Beginner
2,773 Views
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

0 Kudos
Intel_C_Intel
Employee
2,773 Views
How can i declare these structures in a module without a common statement.
0 Kudos
james1
Beginner
2,773 Views
Example:


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

0 Kudos
Jugoslav_Dujic
Valued Contributor II
2,773 Views
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.
0 Kudos
Reply