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

      program draw        
                  
      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
      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,mpTimerElapsed,i
      real*8 bstime,amctime,eustime,amstime,othertime 
      real v(4),units,ends,tmp
      integer reps(4),n,itmp
      integer data1(0:1000,2), data2(0:1000,2), 
     & data3(0:1000,2), data4(0:1000,2)

CMPF  ONFE reps
CMPF  ONFE v          

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

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

      total = 0
      records = 0
      units = 0.01
      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
       if (mtime.eq.0.or.biasbscall.eq.0.0) goto 222
       if (biasbscall.eq.0.0) goto 222
       itmp = int(abs(biasbscall)/units)
c       print *,biasbscall,itmp
       if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
       if (biasbscall.gt.0.0) then
          data1(itmp,1) = data1(itmp,1) + 1
       else
          data1(itmp,2) = data1(itmp,2) + 1   
       endif 
       itmp = int(abs(biasamc)/units)
       if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
       if (biasamc.gt.0.0) then
          data2(itmp,1) = data2(itmp,1) + 1
       else
          data2(itmp,2) = data2(itmp,2) + 1   
       endif
       itmp = int(abs(biaseur)/units)
       if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
       if (biaseur.gt.0.0) then
          data3(itmp,1) = data3(itmp,1) + 1
       else
          data3(itmp,2) = data3(itmp,2) + 1 
       endif
       itmp = int(abs(biasams)/units)
       if (itmp.gt.n.or.itmp.lt.-n) itmp = n 
       if (biasams.gt.0.0) then
          data4(itmp,1) = data4(itmp,1) + 1
       else
          data4(itmp,2) = data4(itmp,2) + 1 
       endif
       records = records + 1
222   continue
 
333   continue
      close(INFILE1)

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

      close(INFILE0)

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

      WRITE(OUTFILE1,*) 
      WRITE(OUTFILE1,*) '"B-S '
      do 444 i=n,1,-1
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) -i*units,data1(i,2)
444   continue
      do 445 i=0,n
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data1(i,1)
 445  continue

      WRITE(OUTFILE1,*) 
      WRITE(OUTFILE1,*) '"American Constant  '
      do 555 i=n,1,-1
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) -i*units,data2(i,2)
 555  continue
      do 556 i=0,n
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data2(i,1)
 556  continue

      WRITE(OUTFILE1,*) 
      WRITE(OUTFILE1,*) '"European Stochastic'
      do 666 i=n,1,-1
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) -i*units,data3(i,2)
 666  continue
      do 667 i=0,n
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data3(i,1)
 667  continue

      WRITE(OUTFILE1,*) 
      WRITE(OUTFILE1,*) '"American Stochastic'
      do 888 i=n,1,-1
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) -i*units,data4(i,2)
 888  continue
      do 889 i=0,n
      write(OUTFILE1,'(f7.2,1X,I6)',ERR=998) i*units,data4(i,1)
 889  continue

      close(INFILE0)
      close(OUTFILE1)



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

998   stop 'open or read file error!'

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

      end





