        SUBROUTINE oildensity(x,P,T,M7Plus,SG7Plus,DenOil)

c***********************************************************************
c       This subroutine calculates the density of oil at the specified
c          pressure and temperature.  The correlation used is that of
c          Standing and Katz described in Amyx, James W.,Bass, Daniel
c          M., Jr., and Whiting, Robert L., Petroleum Reservoir
c          Engineering, McGraw-Hill,1960, pp.295-305. The equations
c          used to represent the charts are from Standing, M. B.,
c          Volumetric and Phase Behavior of Oil Field Hydrocarbon
c          Systems, Society of Petroleum Engineers, 1977, 122-123.

c       Author: Scott K. Laudeman
c       Date: June 20, 1987

c       Input Variables.

c          x: Array containing mole fraction of each component.
c             Components are assigned subscripts as shown below.
c                1: carbon dioxide
c                2: hydrogen sulfide
c                3: nitrogen
c                4: methane
c                5: ethane
c                6: propane
c                7: isobutane
c                8: n-butane
c                9: isopentane
c               10: n-pentane
c               11: n-hexane
c               12: heptanes plus
c          P: Pressure, psia.
c          T: Temperature, Deg. F.

c       Output Variables

c          DenOil: Oil density at specified conditions, lbs/cf.

c       Other Variables

c          DenPCor: Density correction for pressure, lbs/cf.
c          DenTCor: Density correction for temperature, lbs/cf.
c          DenWater: Density of water, lbs/cf.
c          density: Array containing densities for each component,
c             lbs/cf.
c          DenPseudo: Pseudo-liquid density at 14.7 psia and 60 Deg. F.
c          Den2Plus: Density of ethane plus fraction, lbs/cf.
c          Den3Plus: Density of propane plus fraction, lbs/cf.
c          i: Loop counter.
c          M: Array containing molecular weights for each component,
c             lbs/(lb*mole).
c          M7Plus: Heptanes plus molecular weight, lbs/(lb*mole).
c          NumComp: Number of components.
c          Prct1: Weight percent methane.
c          Prct2: Weight percent ethane.
c          SG7Plus: Heptanes plus specific gravity, lbs/cf.
c          Vol3Plus: Volume of propane plus fraction, cf.
c          Wght1Plus: Weight of oil, lbs.
c          Wght2Plus: Weight of ethane plus fraction, lbs.
c          Wght3Plus: Weight of propane plus fraction, lbs.

c***********************************************************************


c***********************************************************************
c       Declarations
c***********************************************************************

c=======================================================================
c       Constants
c=======================================================================

           PARAMETER (DenWater=62.365,NumComp=12)

c=======================================================================
c       Variables
c=======================================================================

        REAL    density(NumComp),M(NumComp),M7Plus,x(NumComp)

c=======================================================================
c       Initialize Arrays
c=======================================================================

        DATA M/0.0,0.0,0.0,16.043,30.070,44.097,58.123,58.123,
     1     72.150,72.150,86.177,0.0/
        DATA density/0.0,0.0,0.0,18.710,22.214,31.618,35.103,
     1     36.422,38.959,39.360,41.400,0.0/

c----------------------------------------------------------------------
c       Molecular weights and densitys are from Gas Processors
c          Suppliers Association, Engineering Data Book, Volume II
c          (1987) 23-2:3.
c----------------------------------------------------------------------


c***********************************************************************
c       Main Program
c***********************************************************************

        M(12)       = M7Plus
        density(12) = SG7Plus*DenWater

c=======================================================================
c       Calculate weight percent methane ,weight percent ethane, and
c          density of propane plus fraction.
c=======================================================================

        Wght3Plus = 0
        Vol3Plus  = 0
        DO 10 i = 6,NumComp
           Wght3Plus = Wght3Plus + x(i)*M(i)
           Vol3Plus  =  Vol3Plus + x(i)*M(i)/density(i)
10      CONTINUE
        Wght2Plus = Wght3Plus + x(5)*M(5)
        Wght1Plus = Wght2Plus + x(4)*M(4)

        Prct1 = 100*x(4)*M(4)/Wght1Plus
        Prct2 = 100*x(5)*M(5)/Wght2Plus
        Den3Plus  = Wght3Plus/Vol3Plus

c=======================================================================
c       Calculate pseudo-liquid density.
c=======================================================================

        Den2Plus = Den3Plus*(1 - .01386*Prct2 - .000082*Prct2**2)
     1                         +   .379*Prct2 +   .0042*Prct2**2

        DenPseudo = Den2Plus*(1 -  .012*Prct1 - .000158*Prct1**2)
     1                          + .0133*Prct1 +  .00058*Prct1**2

c=======================================================================
c       Correct density to specified pressure and temperature.
c=======================================================================

        DenPCor = (.167 + 16.181*10**(-.0425*DenPseudo))*(P/1000)
     1      - .01*(.299 +    263*10**(-.0603*DenPseudo))*(P/1000)**2

        DenOil = DenPseudo + DenPCor

        DenTCor = (.0133 +     152.4*DenOil**(-2.45))*(T - 60)
     1        - (8.1E-06 - .0622*10**(-.0764*DenOil))*(T - 60)**2

        DenOil = DenOil - DenTCor

        RETURN

        END
