IMPLICIT usage and equivalence

Just for confirmation…

I have, in one included file, the following line at the top:

IMPLICIT DOUBLE PRECISION (A-H,O-Z), INTEGER(I-N)

The variables and constants defined in this file are easy to identify as their data type, so no issues there.

A following included file then has a lot of COMMON statements. For example…

COMMON/ GIC / X(MJ,MH), VX(MJ,MH), GRV(MJ), zM(MJ),dM(MJ),Zmass,Zflux,dflux,xTimod,xCorm

Do I assume that the first included file’s rules apply throughout and affect this subsequent included file, such that I can accept that any variable not explicitly defined within it is either…

  • double precision if the variable name begins with any letter from A to H or from O to Z
  • integer if the variable name begins with I through to N?

Equally, two arrays are defined in this way…

real*8 element(MJ,ME),velement(MJ,ME)

Yet, the integers(?) MJ and ME are not defined anywhere; are these left for later definitions?

Oh, and one more thing (sorry).

I’m assuming that this statement causes the two arrays to be identical to each other in size and/or content?

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

If so, does this still exist within modern Fortran (F90) or is there a better way?

The implicit statement will only have effect in the files in which it is included. I.e. if you include it and the common block in one file, but only the common block in another, the variables will have different types between the two places the common block is defined (i.e. A to H or O to Z will have default real instead of double precision), causing lots of confusion and data access problems. Hopefully care has been taken for this not to happen though.

equivalence has been deprecated, and one would use pointers and targets in modern Fortran. FYI, equivalence says that two variables share memory space, i.e. that changing one changes the other. Pointers and targets allow this, but in a way that doesn’t allow you to do it with variables of different types. I.e.

equivalence an_integer, a_real

what does

an_integer = 42
print *, a_real

produce? You could probably work it out, but it’s technically not defined by the standard (i.e. could be different on different systems).

They are probably named constants (PARAMETERs) in some INCLUDE file you haven’t spotted yet!

Yes, they are indeed; thank you. :slight_smile:

1 Like