Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>EQUIVALENCE</code> doesn't <em>do</em> anything, it certainly doesn't intialise anything, an <code>EQUIVALENCE</code> is a definition or declaration. These days (and ever since the publication of the Fortran 90 standard with a force growing all the time) <code>EQUIVALENCE</code> is a hack, and should be avoided wherever possible.</p> <p>The statement declares that 2 variables share storage (what the Fortran standards call <em>storage-association</em>). One interpretation of this is that the names which are equivalenced are simply aliases, but the (ab-)use of the statement allows the programmer to do some other things which are regarded, by 21st century professional software engineers, as well-dodgy. </p> <p>For example, and this applies in the snippet you've posted, <code>EQUIVALENCE</code> can be used to have variables of different types share the same storage. You have an array called <code>ASCN</code> which is (implicitly) of type <code>REAL*8</code> equivalenced to an array called <code>KLCKF2D</code> which is (again implicitly) of type <code>INTEGER</code>. What this means is that if you refer to the storage under one name the bit-patterns are interpreted as <code>REAL</code>s, using the other name they are <code>INTEGER</code>s -- and note that the bit pattern for a real with the value <code>100.0</code> will not (of course) be interpreted as the integer <code>100</code>.</p> <p>And the hackery doesn't stop there. One effect of the <code>COMMON</code> block declaration is to lay the variables out in memory, in your case the <code>10500 (= 100*21*5)</code> elements of <code>ASCN</code> are followed by the <code>8700</code> elements of <code>FEMPTY2</code>. With a little multiplication and addition you find that <code>38400 = 2*(10500+8700)</code> which accords with the default integer size in this program being 4-bytes, ie half the size of the <code>REAL*8</code>s used in the other variables. So the array <code>KLCKF2D</code> is larger than <code>ASCN</code> but the original programmer knew that the next <code>17400</code> bytes would be occupied by <code>FEMPTY2</code>.</p> <p>So yes, this may be a way of setting all the bits in that part of your program's in-memory data to <code>0</code>, but it's (now considered to be) a horrid hack. But it should be portable -- successive Fortran standards have been very conservative about deleting obsolete features from the language and compiler-writers even more so, backward-compatibility is VERY important to Fortran programmers.</p> <p>Oh, and to answer your question, yes <code>COMMON</code> blocks were (note the past tense) the FORTRAN77 way of declaring and using global variables. These days the language offers the much safer option of declaring variables to be shared globally by wrapping them in a <code>MODULE</code> and <code>USE</code>-associating them.</p> <p>I wouldn't have been surprised to see a line like</p> <pre><code>COMMON/COMMF2D/KLCKF2D(38400) </code></pre> <p>in your code, <code>COMMON</code> blocks can also be (ab-)used to rename and retype storage locations.</p> <p>While I'm giving your old code a kicking, implicit typing is also frowned upon these days, far better to explicitly type all declarations.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload