# Requiring comprehension of equivalence to enable removal

**URL:** <https://fortran-lang.discourse.group/t/requiring-comprehension-of-equivalence-to-enable-removal/2477>\
**Category:** Help\
**Created:** [December 31, 2021, 6:09pm UTC](https://fortran-lang.discourse.group/t/requiring-comprehension-of-equivalence-to-enable-removal/2477 "2021-12-31T18:09:11Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [December 31, 2021, 7:25pm UTC](https://fortran-lang.discourse.group/t/requiring-comprehension-of-equivalence-to-enable-removal/2477/5 "2021-12-31T19:25:01Z")

</div>

> [@FortranFan](#):
>
> basically the `pres` vector of `mj` elements is mapped to the `mj` elements in the 1st column of your data array `x` , `r` to the next column, and so forth.

@garynewport , you can create "minimal working example"s of sections of your legacy code and try them out to understand the behavior per `FORTRAN 77` and other dialects/extensions upon which such legacy code may be based. So for example,

```Fortran
! legacy
   integer, parameter :: mj = 2
   double precision x(mj,4)
   double precision, dimension(mj) :: temp, xl, r, pres
   equivalence (x(1, 1), pres), (x(1, 4), temp)
   equivalence (x(1, 2), r), (x(1, 3), xl)
   integer :: i
   do i = 1, mj
      x(i,1) = 1D5*i
      x(i,2) = 1D0*i
      x(i,3) = 1D1*i
      x(i,4) = 300D0*i
   end do
   print *, "pres = ", pres
   print *, "r = ", r
   print *, "x1 = ", xl
   print *, "temp = ", temp
end

```

vis-a-vis

```Fortran
! EQUIVALENCE replaced by TARGET<->POINTER paired semantics starting Fortran 90 standard
   integer, parameter :: mj = 2
   double precision, target :: x(mj,4)
   double precision, pointer, dimension(:) :: temp, xl, r, pres
   integer :: i
   pres(1:mj) => x(1:mj,1)
   r(1:mj) => x(1:mj,2)
   xl(1:mj) => x(1:mj,3)
   temp(1:mj) => x(1:mj,4)
   do i = 1, mj
      x(i,1) = 1D5*i
      x(i,2) = 1D0*i
      x(i,3) = 1D1*i
      x(i,4) = 300D0*i
   end do
   print *, "pres = ", pres
   print *, "r = ", r
   print *, "x1 = ", xl
   print *, "temp = ", temp
end

```

You can then run both the programs and check whether the output is equivalent - it should be the same.

---

_[View the full topic](https://fortran-lang.discourse.group/t/requiring-comprehension-of-equivalence-to-enable-removal/2477)._
