Topic: Apparent Allocation error

Jeff, I have found a problem that has me completely stumped.  Following is a code snippet starting at line 783 in WinDam.f90:

    ! set initial input
    Qin1 = Hin%Hyd(1)
    ! initialize time integral values and stored values
    Hout%Hyd(1) = Qout1
    EmbIntgrl(1) = 0.
    Time = T1
    Hout%Elev(1) = Elev1
    EmbTime(1) = Time

Qout1 has a value of 4821.  When Hout%Hyd(1) is set to Qout1, Hout%Elev(1) is also set to the same value and the assignment Hout%Elev(1) = Elev1 never happens.  It's as if Hout%Hyd and Hout%Elev are allocated to the same space.

I can send you the entire program and dataset that's causing the problem if you want.  The program consists of a mainline (WinDAM.f90) and approximately 60 modules and subroutines.  Just tell me your email and I'll send it to you.

Don

Re: Apparent Allocation error

More info.  I had an associate compile the program using the old Compaq Fortran and we get the same results.  So it appears to be something in the code that's causing the problem.  Is it possible that some type of optimization is the culprit?

Don

Re: Apparent Allocation error

Hi Jeff.  Found a work around.  If I remove Elev from the Hout structure and make it a stand-alone array, the problem goes away.  As I say, it's a work-around, not a solution.  Here is the entire Hout structure:

Type Hydro_Out
    Real(8), Allocatable :: Hyd(:)            ! Outflow Hydrograph
!   Real(8), Allocatable :: Elev(:)           ! Outflow elevations at discharges
    Real(8), Allocatable :: HydCtl(:)         ! Hydraulic Control computed in QBreach
    Real(8)              :: DeltaT            ! Time increment of hydrograph
    Real(8)              :: StartTime         ! Starting time of first non-zero hydrograph value
    Real(8)              :: PeakQ             ! Peak of the outflow hydrograph
    Real(8)              :: TimeQ             ! Time of peak, outflow hydrograph
    Real(8)              :: Duration          ! Duration of flow, outflow hydrograph
    Real(8)              :: StorVol           ! Storage volume, ac. ft. of outflow hydrograph
    Integer(4)           :: nHydPts           ! Number of points in the outflow hydrograph
    Integer(4)           :: nPeak             ! Hydrograph pointer to peak
    Character(10)        :: HydID             ! Hydrograph Identifier
End Type Hydro_Out
Type (Hydro_Out)         :: Hout
Real(8), Allocatable     :: ElevOut(:)        ! Outflow elevations at discharges

Notice that Elev is commented out and ElevOut is its replacement.

Re: Apparent Allocation error

Don,

I'll have to research this behavior a bit.  At first glance, I don't see an issue, of course.  I'll see if I can reproduce the behavior.

Jeff Armstrong
Approximatrix, LLC

Re: Apparent Allocation error

Hi Jeff.
I tried changing the structure, ie, separating the Hyd and Elev statements so they aren't adjacent, but that didn't help.  I've been programming for over 50 years and I've never run into something like this. 

One other thing I need to check that I just thought of.  I need to check HydCtl to see if it gets corrupted also.  Will let you know.

Don

Re: Apparent Allocation error

Jeff,
Apparently there can only be one allocated array within a structure. The array Hout%HydCtl() is also being corrupted and gets set to the same value that is assigned to Hout%Hyd(?)  Hope this helps.
Don