rank mismatch for "common" arrays

rank mismatch for "common" arrays

I am working with some very complex, and rather old fortran code (most of it was written in fortran77 but some was earlier). I need to have the memory dynamically allocated and am therefore converting "COMMON" block statements to modules with use statements. 
I have come to a problem where the rank of a given variable within the common block changes between routines (the overall memory footprint is the same however). 

A highly simplified example of this would be 

      Subroutine sub1 
      COMMON /cblock/array(L,N,M) 
      !code using the array in a 3D manner 

      Subroutine sub2 
      COMMON /cblock/array(L*N*M) 
      !code using the array in a 1D manner 

As you can see the array is of rank 3 in the first routine and of rank 1 in the second routine. 

I have searched high and low for a method of making this function with allocatable arrays, but have not been successful. 

It seems like with all the additional functionality built into the modern fortran standards there should be a way to duplicate what the common blocks did in an instance like this. 

Thank you.

P.S.  L,N,M would have been compile time parameters defined using include statements but will now be run time variable integers that are defined and used to allocate the arrays before sub1 or sub 2 would be called. I have sucsessfully converted a number of other common blocks to the modules and understand that portion of the process. It is only where these variables are treated as different rank that are giving me problems.

15 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.