cc compare.for          2/18/92  "Compare Models"

      program draw        
      implicit none
      PARAMETER (INFILE0=1,INFILE1=2)
      PARAMETER (OUTFILE1=9)
      PARAMETER (IOfile = 'file.io')      
                                       
c      include 'models.h'

      real psi,rho
      real k,mcall1,mcall2,sz,rate1,rate2,rate,oldrate,div1,div2,div3
      integer mtime,flag,ifdiv1,ifdiv2,ifdiv3,reps1
      character*22 string1
      character*12 string2
      real t,mcall,tdiv1,szdiv,tmp,market
      real biasbscall,biaseur,biasamc,biasams
      real*8 mbiasbscall,mbiaseur,mbiasamc,mbiasams
      real*8 vbiasbscall,vbiaseur,vbiasamc,vbiasams
      real ceur,cams,camc,cbscall,xmu
      character*40 fname,fname1
      integer*4 total,records,i,n1,n2,n3,n4
      real v(4),units,ends,tmp,m,xunits
      real sn1,sn2,sn3,sn4
      integer reps(4),n,itmp
      integer data1(0:2000,2), data2(0:2000,2), 
     & data3(0:2000,2), data4(0:2000,2)

CMPF  ONFE reps
CMPF  ONFE v          

      open(UNIT=INFILE0,FILE=IOfile,STATUS='OLD',
     &     ACCESS='SEQUENTIAL',ERR=998)
      read(INFILE0,55,ERR=999,END=234) fname1
c      print *,fname1

 1111  continue

      open(UNIT=INFILE1,FILE=fname1,STATUS='OLD',
     &     ACCESS='SEQUENTIAL',ERR=998)


      total = 0
      records = 0
      units = 0.1
      ends = 1.0
      n = int(ends/units)
      do 123 i = 0,n
        data1(i,1) = 0
        data1(i,2) = 0
        data2(i,1) = 0
        data2(i,2) = 0
        data3(i,1) = 0
        data3(i,2) = 0
        data4(i,1) = 0
        data4(i,2) = 0
 123    continue

      vbiasbscall = 0.0
      vbiasamc = 0.0
      vbiaseur = 0.0
      vbiasams = 0.0

      do 222 i=1, 30000
777    read(INFILE1,'(A22,I3,F7.2,2(F7.2),F7.2,A12,I2,F6.2,
     & F8.4,3(I4,F8.4),4(1X,F9.4))',ERR=999,END=333) string1,mtime,k,
     & mcall1,mcall2,sz,string2,flag,rate1,rate2,ifdiv1,div1,
     & ifdiv2,div2,ifdiv3,div3,biasbscall,biasamc,biaseur,biasams
 
       total = total + 1
       market = (mcall2 + mcall1)*0.5
c       print *,'records=',records,'bias=',biasbscall
       if (mtime.eq.0.or.biasbscall.eq.0.0.or.
     &   biasbscall.ge.2*market .or.biasamc.ge.2*market.or.
     &   biaseur.ge.2*market.or.biasams.ge.2*market  ) goto 222
       if (biasbscall.eq.0.0) goto 222
       m = (mcall2 - mcall1)/2.0
       xunits = 2*units*m
       itmp = int(abs(biasbscall)/xunits)
c       print *,biasbscall,n,xunits,itmp
          if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
          data1(itmp,1) = data1(itmp,1) + 1

       itmp = int(abs(biasamc)/xunits)
          if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
          data2(itmp,1) = data2(itmp,1) + 1

       itmp = int(abs(biaseur)/xunits)
          if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
          data3(itmp,1) = data3(itmp,1) + 1

       itmp = int(abs(biasams)/xunits)
          if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
          data4(itmp,1) = data4(itmp,1) + 1

       records = records + 1
222   continue
 
333   continue
      close(INFILE1)

c      read(INFILE0,55,ERR=998) fname
c      open(UNIT=OUTFILE1,FILE=fname,STATUS='UNKNOWN',
c     &     ACCESS='SEQUENTIAL',ERR=998)

c      close(INFILE0)
       
        n1 = 0
        n2 = 0
        n3 = 0
        n4 = 0
       do 338 i=0,n-1
         n1=n1+data1(i,1)
         n2=n2+data2(i,1)         
         n3=n3+data3(i,1)
         n4=n4+data4(i,1)
 338   continue
       sn1 = float(100*n1)/float(records)
       sn2 = float(100*n2)/float(records)
       sn3 = float(100*n3)/float(records)
       sn4 = float(100*n4)/float(records)
       print *,fname1,total,records,sn1,sn2,sn3,sn4
    
       read(INFILE0,55,ERR=999,END=234) fname1
       goto 1111

c      WRITE(OUTFILE1,*) 'TitleText: '//fname1
c      WRITE(OUTFILE1,*) 'Ticks: true'
c      WRITE(OUTFILE1,*) 'BoundBox: on'
c      WRITE(OUTFILE1,*) 'YUnitText:  Record # '
c      WRITE(OUTFILE1,*) 'XUnitText: Model Bias (relative to A/B price '
c      WRITE(OUTFILE1,*) 'Markers: on'
c      WRITE(OUTFILE1,*) 'StyleMarkers: on'
c      WRITE(OUTFILE1,*) 'NoLines: true'
c      WRITE(OUTFILE1,*) 'PixelMarkers: true'

c      WRITE(OUTFILE1,*) 
c      WRITE(OUTFILE1,*) '"B-S '

c      do 445 i=0,n
c      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data1(i,1)
c 445  continue

c      WRITE(OUTFILE1,*) 
c      WRITE(OUTFILE1,*) '"American Constant  '

c      do 556 i=0,n
c      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data2(i,1)
c 556  continue

c      WRITE(OUTFILE1,*) 
c      WRITE(OUTFILE1,*) '"European Stochastic'

c      do 667 i=0,n
c      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data3(i,1)
c 667  continue

c      WRITE(OUTFILE1,*) 
c      WRITE(OUTFILE1,*) '"American Stochastic'

c      do 889 i=0,n
c      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data4(i,1)
c 889  continue

 234   close(INFILE0)
c       close(OUTFILE1)



c      print *, '---- Program finished ----'
c      print *, 'Total records =',total
c      stop 
       
999   print *, 'read or write file error!'
      total = total + 1
c      goto 777

998   stop 'open or read file error!'

55    format (A40)
66    format (F9.6,F9.6)

      end





