Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Fortran Manuals and Interfaces

$
0
0

Dear Steve:

A few years ago mecej4 on the MKL Forum helped me to fix - actually he fixed it and I just watched in awe, a bit like Shock and Awe in Fortran a program for the analysis of water supply systems. In mecej4's fix he used interfaces.

So in thinking about the Fortran Manuals - I dragged out Fortan 95/2003 explained.  The Metcalf book is more confusing than the Sonic Menu for hamburgers, but I digress. I could not make head nor tail of interfaces in the book. 

In the oldest iteration of the fixed program, we have a module called

Network that contains a lot of variable declarations, it ends then there are a series of subroutines, which are in the same file, but not in the module.

In the main program unit there are :

program Magni
  use Network
  implicit none
  
  interface
   subroutine PumpHead( H1, H4, a0, a1,  a2, a3, HRatio, retQ, flow0, pumpQ)
    use Network
    real(kind=dp) H1
    real(kind=dp) H4
    real(kind=dp) a0
    real(kind=dp) a1
    real(kind=dp) a2
    real(kind=dp) a3
    real(kind=dp) HRatio
    real(kind=dp) retQ
    real(kind=dp) flow0
    real(kind=dp) pumpQ
   end subroutine PumpHead
  
  end interface

a series of interface calls -- this program still compiles and run fine on the latest

A later version of the program has the subroutines within the module

  MODULE network
    INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)
    REAL (KIND=dp) :: g = 9.806, pi = 3.14159265D0

    TYPE snode
        INTEGER id
        INTEGER :: tank = -1
        INTEGER :: zone = 0
        REAL (KIND=dp) x
        REAL (KIND=dp) y
        REAL (KIND=dp) e
        REAL (KIND=dp) c0
        REAL (KIND=dp) qbase
        REAL (KIND=dp) cs
        REAL (KIND=dp) h
        REAL (KIND=dp) c
        REAL (KIND=dp) inddemand
        REAL (KIND=dp) parkdemand
        REAL (KIND=dp) leakdemand
        REAL (KIND=dp) resdemand
        REAL (KIND=dp) dumc
        REAL (KIND=dp) q
    END TYPE

    TYPE spipe
        INTEGER id
        INTEGER n1
        INTEGER n2
        INTEGER :: zone = 0
        INTEGER pumpstatus
        INTEGER nodei, nodej
        REAL (KIND=dp) :: a0 = 0.0
        REAL (KIND=dp) a1
        REAL (KIND=dp) a2
        REAL (KIND=dp) a3
        REAL (KIND=dp) length
        REAL (KIND=dp) diameter
        REAL (KIND=dp) c
        REAL (KIND=dp) wlrf !pipe wall roughness, m
        REAL (KIND=dp) e
        REAL (KIND=dp) pumpq
        REAL (KIND=dp) deltaq
        REAL (KIND=dp) q
        REAL (KIND=dp) h0
        REAL (KIND=dp) h1
        REAL (KIND=dp) h2
        REAL (KIND=dp) h3
        REAL (KIND=dp) h4
        REAL (KIND=dp) qt
        REAL (KIND=dp) v
        REAL (KIND=dp) :: k = 0.0
        REAL (KIND=dp) :: k1
        REAL (KIND=dp) :: RE
        REAL (KIND=dp) :: fr
        integer :: cv = 0
        integer :: prv = 0
        REAL (KIND=dp) :: prvcoeffic = 1.0
        REAL (KIND=dp) :: prvzeropressure
        REAL (KIND=dp) kvis !kinematic viscosity, m^2/s
        REAL (KIND=dp) tc !water temperature, celsius
    END TYPE

    TYPE spump

        INTEGER :: pump = -1
        INTEGER :: pipe = 0
        INTEGER :: ontime = 0
        INTEGER :: offtime = 0
        INTEGER :: tank = -1
        REAL (KIND=dp) :: onlevel = 0.0
        REAL (KIND=dp) :: offlevel = 0.0

    END TYPE
    TYPE stank

        INTEGER id
        REAL (KIND=dp) area
        REAL (KIND=dp) c
        REAL (KIND=dp) h0
        REAL (KIND=dp) hmax
        REAL (KIND=dp) hmin
        REAL (KIND=dp) hnext
        REAL (KIND=dp) k1
        INTEGER node
        REAL (KIND=dp) v
        REAL (KIND=dp) centreX
        REAL (KIND=dp) centerY
        REAL (KIND=dp) radius

    END TYPE

    TYPE constants

        REAL (KIND=dp) :: resdemfact = 0.15
        REAL (KIND=dp) :: inddemfact = 0.15
        REAL (KIND=dp) :: parkfactor = 540.0
        REAL (KIND=dp) :: demand = 0.0
        REAL (KIND=dp) :: flow0 = 0.01
        REAL (KIND=dp) :: gpmpercfs = 448.4
        REAL (KIND=dp) :: htol = 0.01
        REAL (KIND=dp) :: huge_int = 999999999
        REAL (KIND=dp) :: lperet = 0.15
        REAL (KIND=dp) :: lperft3 = 28.3
        REAL (KIND=dp) :: metricratio = 1000.0
        REAL (KIND=dp) :: limit = 1000000

        INTEGER :: maxhrs = 24
        INTEGER :: maxid
        INTEGER :: maxiter = 2000
        INTEGER :: maxnodes
        INTEGER :: maxpipes
        INTEGER :: maxpumps
        INTEGER :: maxsegs
        INTEGER :: maxtanks
        INTEGER :: maxtexts = 50
        INTEGER :: nodedataccount = 12
        INTEGER :: runtime = 1
        REAL (KIND=dp) :: qtol = 0.01
        REAL (KIND=dp) :: ttol = 5.0
        REAL (KIND=dp) :: unknown = -999999
        CHARACTER *2 :: units = 'SI'
    END TYPE

    !-----------------------------------------------------
    !
    !
    !
    !-----------------------------------------------------
    CONTAINS

    SUBROUTINE timingline(sw)
    IMPLICIT NONE
    INTEGER :: sw
    INTEGER :: tmpday, tmpmonth, tmpyear
    INTEGER :: tmphour, tmpminute, tmpsecond, tmphund, values(8)
    CHARACTER *2 :: mer

    CALL date_and_time(values=values)
    tmpyear = values(1)
    tmpmonth = values(2)
    tmpday = values(3)
    tmphour = values(5)
    tmpminute = values(6)
    tmpsecond = values(7)
    tmphund = values(8)
    IF (tmphour.GT.12) THEN
        mer = 'pm'
        tmphour = tmphour - 12
    ELSE
        mer = 'am'
    END IF
    WRITE (sw, 100) tmpday, tmpmonth, tmpyear
    WRITE (sw, 110) tmphour, tmpminute, tmpsecond, tmphund, mer
    WRITE (*, 100) tmpday, tmpmonth, tmpyear
    WRITE (*, 110) tmphour, tmpminute, tmpsecond, tmphund, mer
    WRITE (sw, 120)
    RETURN
100 FORMAT ('       Analysis Date : ', I2, '/', I2.2, '/', I4.4)
110 FORMAT ('       Time : ', I2, ':', I2.2, ':', I2.2, ':', I3.3, &
        '', A)
120 FORMAT ('        ')
    END SUBROUTINE
    !-------------------------------------------------------------------
    !

And there are no inferfaces:

I was wondering which is the preferred standard and really if the module contains the subroutines, is there any need for interfaces?

John


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>