# Final removal of equivalence - is this a valid approach?

**URL:** <https://fortran-lang.discourse.group/t/final-removal-of-equivalence-is-this-a-valid-approach/2551>\
**Category:** Help\
**Created:** [January 9, 2022, 7:19pm UTC](https://fortran-lang.discourse.group/t/final-removal-of-equivalence-is-this-a-valid-approach/2551 "2022-01-09T19:19:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![garynewport](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@garynewport](https://fortran-lang.discourse.group/u/garynewport)\
**Post date:** [January 9, 2022, 7:19pm UTC](https://fortran-lang.discourse.group/t/final-removal-of-equivalence-is-this-a-valid-approach/2551/1 "2022-01-09T19:19:59Z")

</div>

Sorry for all the posts on equivalence but each time I complete 1, the next one creates a slightly different issue.

I am down to the final one in my old code. I have an included file that defines the following…

```auto
integer, parameter :: mj = 4000
integer, parameter :: mh = 4
integer, parameter :: me = 9

double precision :: element(mj, me)
double precision :: velement(mj, me)

double precision :: hydrogen(mj), vhydrogen(mj)

equivalence (element,hydrogen) , (velement,vhydrogen)

```

If I then search the actual file that uses this include file, I have 55 for `element`, 14 for `velement`, 66 for `hydrogen` and no matches for `vhydrogen`.  
That tells me that I am only interested in the `equivalence (element,hydrogen)`

If I look at some of the `element` lines I get this such as…

```auto
element(j, k) = velement(j, k)
element(i, k) = element(mj, k)
element(j + 1, k) = element(j, k)

```

And so on.

Considering there are 55 for element and 66 for hydrogen (though many of them are not assignments that affect either variable’s contents), I feel I need to add the following…

```auto
element(j, k) = velement(j, k)
hydrogen(j) = velement(j,k)

element(i, k) = element(mj, k)
hydrogen(i) = element(mj, k)

element(j + 1, k) = element(j, k)
hydrogen(j + 1) = element(j, k)

```

The only issue is that each of those lines are within a loop that alters k, whilst hydrogen does not vary by this index; so I am assuming I could just as easily do this…

```auto
hydrogen(j) = velement(j, 1)

hydrogen(i) = element(mj, 1)

hydrogen(j + 1) = element(j, 1)

```

Again, my only thought is that it shouldn’t be for (2) = 1 but for (2) = k, where k is at it’s maximum value (which is `me`). So…

```auto
hydrogen(j) = velement(j, me)

hydrogen(i) = element(mj, me)

hydrogen(j + 1) = element(j, me)

```

Am I right in my thinking here?

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [January 9, 2022, 9:34pm UTC](https://fortran-lang.discourse.group/t/final-removal-of-equivalence-is-this-a-valid-approach/2551/2 "2022-01-09T21:34:49Z")

</div>

@garynewport , see this [**thread**](https://fortran-lang.discourse.group/t/compiling-modules-in-f77/2384/12).

By the way, you’ve previously mentioned you now have several of the books on modern Fortran.

I suggest reviewing those books closely and gaining good facility with modern Fortran before proceeding with your code. Because going by your original post here suggests you might eliminate what might be marked as obsolescent in the standard i.e., `EQUIVALENCE` only to create data duplication in your code that might lead to adverse consequences.

---

<div class="post-metadata">

**Author:** ![garynewport](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@garynewport](https://fortran-lang.discourse.group/u/garynewport)\
**Post date:** [January 10, 2022, 6:57pm UTC](https://fortran-lang.discourse.group/t/final-removal-of-equivalence-is-this-a-valid-approach/2551/3 "2022-01-10T18:57:45Z")

</div>

Thank you. I now remember reading this first time around, yet so much time has past!

I was reading around pointers, probably because I recalled your original reply, and will look at that again.

I want to move away from the includes and use modules instead. I then need to continue the journey through each subroutine to identify specifically what each one is doing. I’m about half way through at present.

And, yes, I am reading through the books. However, 99% of this code makes absolute sense and I can work out exactly what it is doing anyway. It’s when I hit curiousities and find the books not helping with specifics that I run to here. 🙂

Again, thank you.
