Testing an equivalence with a module variable

Well, I thought I had finished the model, ran it for the maximum time I could think of and it keeps crashing. Through a series of error checking processes (each test taking several hours to complete) I have identified the following:

  1. Certain variables are being set to NaN
  2. The offence seems to be occurring within my henyey function
  3. The issue seems to be with a variable I have that is shared across the model through a module

So, I have gone back to the very first code (for a variety of reasons) and return to a problem I asked about some time ago; an equivalence within this function.

Originally, this function was a subroutine and all variables were implied. The top section of the original code looked like this:

    subroutine henyey(mode)
    
        include 'parm.h'
        include 'xvar.h'
        logical lconv
        dimension d(mh,mh+1),ca(mh),dx(mh)
        equivalence (ha(1,mh+1),d(1,1)) , (d(1,mh+1),ca(1))
        save

ha (within the equivalence) was defined as HA(MH,2*MH+1) within the included file xvar.h

Originally, I replaced ca(1) in the code by accepting that ca(i) became d(i, 5) (since mh was defined as 4 in parm.h).
I did the same with d(1, 1) and ha(1, mh + 1); making d(i, j) into ha(i, j + 4)

However, I had a problem in that another subroutine needed d to be passed in (and taken out). I obviously hadn’t explored how I might transfer in the relevant section of ha (nor how to assign the results of this subroutine to that section - in the aim of making the subroutine a function). I simply did a loop to assign…

for i = 1 to mh
    for j = 1 to mh
        d(i, j) = ha(i, j + 4)
    end if
end if

call girl(d, m, n)

for i = 1 to mh
    for j = 1 to mh
        ha(i, j + 4) = d(i, j)
    end if
end if

I believe this assignment is wrong but also concerned that my other assumptions might be flawed.
I am also curious if there is a way of changing the subroutine girl such that I pass in only the part of ha of interest, and girl returns the results, assigned to the relevant part of ha, such that girl becomes a function instead?

So, call girl(ha, m, n) and call girl(d, m, n) become ha = girl(ha, m, n) and either ````d = girl(d, m, n)or something along the lines of ha(1:i, 1:j) = girl(ha(1:i, 1:j), m, n)```

I’ve been trying to test the old code in my model, but since I removed the use of includes, moving to use instead, then I cannot test using the equivalence statement; getting the error EQUIVALENCE attribute conflicts with USE ASSOCIATED attribute in 'ha' at...

Any help gratefully received as always. I think I have included sufficient detail but happy to provide more if needed.

Are you sure that you have the array indices the right way round? This is what I think is the memory map of your EQUIVALENCE block:

Address ha d c

0 (1,1) o-o-b o-o-b
1 (2,1) o-o-b o-o-b
2 (3,1) o-o-b o-o-b
3 (4,1) o-o-b o-o-b
4 (1,2) o-o-b o-o-b
:
:
14 (3,4) o-o-b o-o-b
15 (4,4) o-o-b o-o-b
16 (1,5) (1,1) o-o-b
17 (2,5) (2,1) o-o-b
18 (3,5) (3,1) o-o-b
19 (4,5) (4,1) o-o-b
20 o-o-b (1,2) o-o-b
22 o-o-b (2,2) o-o-b
23 o-o-b (3.2) o-o-b
24 o-o-b (4,2) o-o-b
:
:
31 o-o-b (4,4) o-o-b
32 o-o-b (1,5) (1)
33 o-o-b (1,5) (2)
34 o-o-b (1,5) (3)
35 o-o-b (1,5) (4)
36 o-o-b o-o-b (5)

where o-o-b means out-of-bounds.

I think that is really my question. :slight_smile:

I know I have seen somewhere (probably in one of the replies I have received), where the transference from one array to another requires the indices to be swapped.