Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

f77 equivalence -> f90

Status
Not open for further replies.

augh

Programmer
Dec 21, 2008
5
IT
I've got this (very old fashioned) piece of code

Code:
      COMMON /CHDATA/ HNO3 , HONO , HNO4 , CO   , HO2H , OOH  ,
     &                PAN  , PPN  , HCHO , CCHO , RCHO , MEK  ,
     &                RNO3 , MGLY , AFG2 , SO2  , ETHE , OLE1 ,
     &                OLE2 , OLE3 , OLE4 , ALK1 , ALK2 , ARO1 ,
     &                ARO2 , O3   , NO   , NO2  , NO3  , N2O5 ,
     &                HO2  , RO2  , CCO3 , C2CO , CRES 

      DIMENSION KINT(35)

      EQUIVALENCE (KINT,KHNO3)
[...]

      DATA KINT /1,2,3,4,5,6,7,8,9,10,....

The purpose is to use variables defined in the common statement (integer) to address elements in an array 'by name' (specifically, I'm talking about chemical species), e.g.

Code:
      REAL conc(35)

      print*,conc(HNO3)

My question is: how to avoid using common and equivalence to translate this in fortran 90 standard?
 
Just a question of style. The code that is in a common block shouldn't have been in a common block. It should have been in an include file. Say it is called offsets.fi. In F77, this would have been
Code:
      INTEGER HNO3 , HONO , HNO4 , CO   , HO2H , OOH ..
      INTEGER ... CHMAX
      PARAMETER (HNO3=1, HONO=2, HNO4=3...
      PARAMETER ( ..., CHMAX=35)
In the second bit
Code:
      INCLUDE 'offsets.fi'
      REAL CONC(CHMAX)
      ...
      PRINT *, CONC(HNO3)
In F90 syntax, the INTEGER and PARAMETER declarations do not have to be split. You can code it as
Code:
      INTEGER, PARAMETER:: HNO3=1, HONO=2... CHMAX=35
If you still use the include file technique, the second bit will still be the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top