      SUBROUTINE XBTBIASgood(itsprobe,depth,temp,maxlevel,
     * maxcalc,numsec,numlevels,iyearx,ixprobe,bmiss,ifix)

C     XBTBIASgood CORRECTS XBT BIAS BASED ON INFORMATION FROM
C     GOOD 2010  THE CORRECTIONS ARE MADE BEFORE
C     INTERPOLATION TO STANDARD LEVELS

      parameter (maxyear=3000,maxset=40,nt4=4,n7db=8)
      parameter (maxdepth=3000,ntno=7,nt10=3)
      character*7 firsttime
      character*80 filename,text
      dimension depth(maxlevel),temp(maxlevel,maxcalc)
      dimension zstretch(maxdepth,4)
      dimension itype4(nt4),itype7db(n7db)
      dimension itypeno(ntno),itype10(nt10)

      data itype4 /202,208,215,223/
      data itype7db /201,207,214,217,227,228,232,235/
      data itypeno /234,233,219,210,204,224,225/
      data itype10 /205,211,220/

      save firsttime
      save zstretch,iyearmin,iyearmax

      if ( firsttime .ne. 'xbtbias' ) then
       firsttime = 'xbtbias'
       iyearmin=5000
       iyearmax=0

       call clearstring(filename,80)
       call extraname('sys.inf'//CHAR(0),
     *  'good_corrections_xbt.dat'//CHAR(0),filename)

       open(9,file=filename,status='old')
       read(9,'(a)') text

       do 55 i=1,maxyear

        read(9,*,end=44) iyear,xt4,xt7,xt10,xunk
c       write(6,*) 'iyear',xt4,xt7,xt10,xunk
        zstretch(iyear,1)=xt4
        zstretch(iyear,2)=xt7
        zstretch(iyear,3)=xt10
        zstretch(iyear,4)=xunk

         if ( iyear .lt. iyearmin ) iyearmin=iyear
         if ( iyear .gt. iyearmax ) iyearmax=iyear

55     continue
44     continue
       close(9)

      endif
    
      iyear=iyearx
      if ( iyearx .lt. iyearmin ) iyear=iyearmin
      if ( iyearx .gt. iyearmax ) iyear=iyearmax
c       write(6,*) 'ixprobe',ixprobe,iyearx

c    See which type of XBT this is (T4/T6, T7/DB, or
c    other type.  Other type not corrected)

       ixbt=4
       ifix=0
      if ( itsprobe .eq. 2 ) then

       if ( ixprobe .ne. 2 .and. ixprobe .ne. 0 ) then
        do 150 nn=1,nt4
150      if ( ixprobe .eq. itype4(nn) ) ixbt=1
        do 155 nn=1,n7db
155      if ( ixprobe .eq. itype7db(nn) ) ixbt=2
        do 160 nn=1,nt10
160      if ( ixprobe .eq. itype10(nn) ) ixbt=3
        do 165 nn=1,ntno
165      if ( ixprobe .eq. itypeno(nn) ) ixbt=-1
c       write(6,*) 'itype',ixprobe,ixbt
        if ( ixbt .eq. -1 ) return
       endif

      ifix=1

c      calculate final depth

       do 200 k=1,numlevels
        depth(k)=depth(k)*zstretch(iyear,ixbt)
c       write(6,*) 'new z',k,iyear,depth(k),zstretch(k,ixbt)

200    continue

      endif

      return
      end
