      program debtopt
      implicit real*8(a-h,o-z)
      double precision cumnorm(625,2),smple(100)
      common /normdta/ cumnorm,ncum
      open(unit=19,file='CumNorm.dta')
      ndraw=100
      ncum=607
C----------------------------------------------------------------------C
C Load initial values - Normal Cumulative Distribution                 C
C----------------------------------------------------------------------C
      do 10 i=1,ncum
        read(19,9999) idum,(cumnorm(i,j),j=1,2)
   10 continue
C----------------------------------------------------------------------C
C Draw the sample of normal random variables                           C
C----------------------------------------------------------------------C
      do 50 i=1,ndraw
   25   call rndnorm(znorm)
        if(znorm.lt.-3.50.or.znorm.gt.3.50) goto 25
        smple(i) = 5.0 +3.0*znorm
   50 continue
C----------------------------------------------------------------------C
C Compute the mean and variance of the distribution                    C
C----------------------------------------------------------------------C
      xopt = 0.0
      do 75 i=1,ndraw
        if(smple(i).gt.4.0) xopt = xopt + (smple(i)-4.0)/real(ndraw)
   75 continue
      write(6,9998) xopt
 9998 format(x,10f8.4)
 9999 format(x,i5,f8.4,x,f8.4)
      end

