      SUBROUTINE XBTBIASish(itsprobe,ixprobe,depth,temp,maxlevel,
     * maxcalc,numsec,numlevels,iyearx,monthx,ifix)

C     XBTBIASish CORRECTS XBT BIAS BASED ON INFORMATION FROM
C     ISHII et al.  THE CORRECTIONS ARE MADE BEFORE
C     INTERPOLATION TO STANDARD LEVELS

C     IFIX=0 IF NO CORRECTION APPLIED
C     IFIX=1 IF CORRECTION APPLIED

      parameter (maxyear=3000,maxtype=1000)
      parameter (numtype=12)
      character*7 firsttime
      character*80 filename,text
      dimension depth(maxlevel),temp(maxlevel,maxcalc)
      dimension xcorr(maxyear,12,numtype),xcorrin(numtype)
      dimension xcorrdiff(numtype),icolumntype(0:maxtype)

      save firsttime
      save xcorr,iyearmin,iyearmax,icolumntype

      if ( firsttime .ne. 'xbtbias' ) then
       firsttime = 'xbtbias'
       call clearstring(filename,80)
       call extraname('sys.inf'//CHAR(0),
     *  'ishii_biascorrect.txt'//CHAR(0),filename)
       open(9,file=filename,status='old')

       iyearmin=5000
       iyearmax=0
       inumset=0
       read(9,'(a)') text
       do 55 n=1,maxyear

        read(9,*,end=44) iyear,(xcorrin(i),i=1,numtype)

        inumset=inumset+1
        do 56 ix=1,numtype
56       xcorr(iyear,6,ix)=xcorrin(ix)
        if ( iyear .lt. iyearmin ) iyearmin=iyear
        if ( iyear .gt. iyearmax ) iyearmax=iyear

55     continue
44     continue
       close(9)

       do 60 iy=iyearmin,iyearmax-1
        do 61 n=1,numtype
61      xcorrdiff(n)=(xcorr(iy+1,6,n)-xcorr(iy,6,n))/12.
    
        do 65 mon=1,6
         xmon0=mon
         mon0=mon+6
         xmon=mon+6
    
         do 66 n=1,numtype
          xcorr(iy,mon0,n)=xcorr(iy,6,n)+(xmon0*xcorrdiff(n))
          if ( mon .ne. 6 ) 
     *     xcorr(iy+1,mon,n)=xcorr(iy,6,n)+(xmon*xcorrdiff(n))
c         if ( iy .eq. 1986 .and. n .eq. 11) write(6,*) 'xcorr',iy,
c    *     mon0,n,xmon,xcorrdiff(n),(xmon*xcorrdiff(n)),
c    *     xcorr(iy,6,n),xcorr(iy,mon0,n)
66       continue

65      continue

60     continue

       do 75 mon=7,12
        do 76 n=1,numtype
         xcorr(iyearmax,mon,n)=xcorr(iyearmax,6,n)
         if ( mon .ne. 12 ) 
     *    xcorr(iyearmin,mon-6,n)=xcorr(iyearmin,6,n)
76      continue
75     continue

       call clearstring(filename,80)
       call extraname('sys.inf'//CHAR(0),
     *  'ishii_type.txt'//CHAR(0),filename)
       open(9,file=filename,status='old')

       read(9,'(a)') text
       read(9,'(a)') text

       call arrayinit(icolumntype,0,maxtype)
       do 150 n=1,maxtype
        read(9,*,end=104) intype,inval         
        icolumntype(intype)=inval
150    continue
104    continue
       close(9)
c      write(6,*) 'columntype 213 ',icolumntype(213)
 
      endif

      itype=0
      if ( itsprobe .eq. 2 ) then

       t1=444.444
       t2=2210838.36
       t3=1486.89
c      t1=462.9629
c      t2=2244447.86
c      t3=1498.1481

       itype=icolumntype(ixprobe)
       ifix=0
       if ( itype .eq. 0 ) return
       ifix=1

c      T5 (Sipp or unknown)
       if ( ixprobe .eq. 204 .or. ixprobe .eq. 210. ) then
        t1=549.450523
        t2=3518716.
        t3=1875.82409
c      T10
       elseif ( ixprobe .eq. 205 .or. ixprobe .eq. 211 ) then
        t1=462.962941
        t2=2127411.12
        t3=1458.56475
c      Fast Deep
       elseif ( ixprobe .eq. 213 .or. ixprobe .eq. 236 ) then
        t1=  549.450523
        t2=  3039466.26
        t3=  1743.40651
       endif
 
       iyear=iyearx
       if ( iyearx .lt. iyearmin ) iyear=iyearmin
       if ( iyearx .gt. iyearmax ) iyear=iyearmax

       xbias=xcorr(iyear,monthx,itype)
c      write(6,*) 'xb',iyear,monthx,itype,xbias,ixprobe
c      write(6,*) 'bias:',xcorr(iyear,monthx,itype),itype,iyear,monthx


       do 80 n=1,numlevels

        if ( n .le. maxlevel ) then
c        if ( iyear .eq. 1986 .and. monthx .eq. 8 )
c    *    write(98,*) depth(n),depth(n)*(1.-xbias),xbias
         t0=t3 - sqrt(t2 - (t1*depth(n)))
         depth(n)=depth(n) - (xbias* t0)
c        write(6,*) 'withbias',depth(n),t0,xbias,(xbias*t0)
        else
         call overmax(maxlevel,numsec,n,0,ic,np)
         t0=t3 - sqrt(t2 - (t1*temp(ic,np)))
         temp(ic,np)=temp(ic,np)-(xbias* t0)
        endif

80     continue

      endif

      return
      end
