Software Archive
Read-only legacy content
17060 Diskussionen

Automatic Objects

Intel_C_Intel
Mitarbeiter
2.777Aufrufe
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 Antworten
james1
Einsteiger
2.777Aufrufe
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?
Intel_C_Intel
Mitarbeiter
2.777Aufrufe
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
james1
Einsteiger
2.777Aufrufe
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

Intel_C_Intel
Mitarbeiter
2.777Aufrufe
How can i declare these structures in a module without a common statement.
james1
Einsteiger
2.777Aufrufe
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

Jugoslav_Dujic
Geschätzter Beitragender II
2.777Aufrufe
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.
Antworten