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

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

      parameter (maxyear=3000,maxset=40)
      character*7 firsttime
      character*80 filename
      dimension depth(maxlevel),temp(maxlevel,maxcalc)
      dimension xshallow(maxyear,0:12),xdeep(maxyear,0:12)

      save firsttime
      save xshallow,xdeep,iyearmin,iyearmax

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

       iyearmin=5000
       iyearmax=0
       inumset=0
       do 55 n=1,maxyear

        read(9,*,end=44) iyear,xshallowin,xdum1,xdeepin,xdum2
        inumset=inumset+1
        xshallow(iyear,0)=xshallowin
        xdeep(iyear,0)=xdeepin
        if ( iyear .lt. iyearmin ) iyearmin=iyear
        if ( iyear .gt. iyearmax ) iyearmax=iyear

55     continue
44     continue
       close(9)

       do 60 iy=iyearmin,iyearmax-1
        xshallowdiff=(xshallow(iy+1,0)-xshallow(iy,0))/12.
        xdeepdiff=(xdeep(iy+1,0)-xdeep(iy,0))/12.

        do 65 mon=1,12
         xmon=mon
         xshallow(iy,mon)=xshallow(iy,0)+((xmon-1)*xshallowdiff)
         xdeep(iy,mon)=xdeep(iy,0)+(xmon*xdeepdiff)
65      continue

60     continue

       do 75 mon=1,12
        xshallow(iyearmax,mon)=xshallow(iyearmax,0)
        xdeep(iyearmax,mon)=xdeep(iyearmax,0)
75     continue
 
      endif

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

       if ( numlevels .le. maxlevel ) then
        dpt=depth(numlevels)
       else
        call overmax(maxlevel,numsec,numlevels,0,ic,np)
        dpt=temp(ic,np)
       endif

       iyear=iyearx
       if ( iyearx .lt. 1968 ) iyear=1968
       if ( iyearx .gt. iyearmax ) iyear=iyearmax

       if ( dpt .le. 550. ) then
        xbias=xshallow(iyear,monthx)
       else
        xbias=xdeep(iyear,monthx)
       endif

       ifix=1
       do 80 n=1,numlevels

        if ( n .le. maxlevel ) then
         if ( iyear .eq. 1986 .and. monthx .eq. 8 )
     *    write(98,*) depth(n),depth(n)*(1.-xbias),xbias
         depth(n)=depth(n)*(1.-xbias) 
        else
         call overmax(maxlevel,numsec,n,0,ic,np)
         temp(ic,np)=temp(ic,np)*(1-xbias)
        endif

80     continue

      endif

      return
      end
