        program analytical
        implicit none
!       **real variables in double precision
!       b: volume factor, stb/rb
!       conv: conversion factor, Darcy's law
!       dbdp: derivative of b with respect to p, stb/rb/psi
!       dy: block height, ft
!       dz: block width, ft
!       en: 1.d0
!       eps: tolerance for adding summation terms
!       fpb: conversion factor, ft3/bbl
!       k: permeability, md
!       length: half-length of reservoir, ft    
!       p: pressure, psi at x,t
!       phi: porosity, dimensionless
!       pi: pi
!       porig: original oil pressure, psi
!       qs: surface rate, stb/d 
!       sum: sum of terms
!       t: time, days
!       to: 2.d0
!       vis: viscosity, cp
!       x: pressure points, ft
                double precision b, conv, dbdp, dy,&                     
                       dz, en, eps, fpb, k, length, p, phi, pi,& 
                       porig, qs, sum, time,&                    
                       to, vis, x, t, c1i2, q
!
!       ***other double precision variables used for intermediate
!       calculation
                double precision term, xfac, teller, xnevner, frac,& 
                exparg, ee, toxl, sumx
!               
!       **integers
!       n: summation variable
!       nmx: number of terms in summation before cutoff
                integer n, nmx, kk
!
!       the open-close-open sequence for the file 'utdat' is to delete
!       old version. Otherwise, the last part of the largest 'utfil' 
!       would never be deleted.                 
                open (5,file='inndat', status='old')
                open (10,file='utdat', status='replace')
!
!     ** read and write input data.
                read  (5,*) k, phi, x, porig, b
                read  (5,*) vis, dbdp, t, dz, dy
                read  (5,*) qs, length, eps
                write (10,3020) k, phi, x, porig, b, vis,&
                       dbdp, t, dz, dy, qs, length, eps
!
!       ***begin calculations
!
!       **universal constants    
                conv = 0.00632827d0     
                fpb = 5.6146d0
                en = 1.d0
                to = 2.d0
                pi  = 3.1415926d0
!
!       **other constants
                c1i2 = conv*k*b/phi/vis/dbdp
                q = qs*vis*fpb/(conv*k*dy*dz*b)
!
!       *****start summation loop
                toxl = to*length
!               
                sum = 0.d0                             
                do  n = 0, 100
                        xfac = (to*n + en)*pi/toxl
                        teller = dcos(xfac*x)
                        xnevner = ((to*n + en)*pi)**to
                        frac = teller/xnevner
!
!       then the argument of the exponential
!
                        exparg = -xfac**2*c1i2*t
                        term = frac*dexp(exparg)
!
!       sjekker om vi har tatt med nok ledd
!                       
                        sum = sum + term
                        if (dabs(term).lt.eps) exit
                end do
!
!       slutt på summering
!
!       så regner vi ut trykket 
                p = porig - q*(x-length) - 8*length*q*sum                               
!
!       utskrifter
               write (10,*) 'tiden er  ', t
               write (10,*) 'x-verdien er  ', x
               write (10,*) 'trykket er  ', p
               write (10,*) 'antall ledd i sum ble  ', n
!       ** close files
                close (5)
                close (10)
!
!       ** format statements
!
 3020 format (&
       '  permeability, k, md  ......................... :', f12.4/&
       '  porosity, phi, fraction ...................... :', f8.4 /&
       '  pressure point, x, ft ......................... :', f10.2/&
       '  original oil pressure, porig, psia ........... :', f10.1/&
       '  volume factor, b, std vol / res vol .......... :', f10.4/&
       '  oil viscosity, vis, cp ....................... :', f10.4/&
       '  dbdp, std vol / res vol / psi................. :', f10.8/&
       '  time, t, days ................................ :', f10.6/&
       '  block width, dz, ft .......................... :', f8.1 /&
       '  block thickness, dy, ft ...................... :', f8.1 /&
       '  oil rate, qs, stb/d ...........................:', f8.1 /&
       '  half-length of reservoir, l, ft ...............:', f8.1/&
       '  summation term tolerance, eps .................:', e14.6//)
!
                end
!
!       end of main program
!
