      SUBROUTINE MBTbiasant(itsprobe,temp,maxlevel,maxcalc,
     * numlevels,iyearx,levelmaxbias,depth,isoor,numsec)

C     MBTBIASANT CORRECTS MBT BIAS BASED ON INFORMATION FROM
C     ANTONOV.  THE CORRECTIONS ARE ON STANDARD LEVELS

      parameter (maxyear=3000,maxset=137,maxlayer=137)
      character*4 cdepthset
      character*7 firsttime
      character*80 filename,infile
      dimension xbias(maxyear,maxset)
      dimension temp(maxlevel,maxcalc)
      dimension depth(maxlevel)
      dimension xlayer(maxlayer,2)

      common /extra/ ir2,ireqsecond,ireqbio

      save firsttime
      save xbias,nlayers,xlayer

      if ( firsttime .ne. 'mbtbias' ) then
       firsttime = 'mbtbias'

c      set layers

       call setlayers(nlayers,xlayer,maxlayer)

       call clearstring(filename,80)
       call checkwhichdepthfile(cdepthset)
       if ( cdepthset .eq. 'orig' ) then
        call extraname('sys.inf'//CHAR(0),
     *   'antonov_mbtbias'//CHAR(0),filename)
       else
        infile='antonov_mbtbias_'//cdepthset//CHAR(0)
        call extraname('sys.inf'//CHAR(0),infile,filename)
       endif
       open(9,file=filename,status='old')

       xyear0=0.0
       iyear=0
       inumset=0
       do 55 n=1,maxyear

        read(9,*,end=44) xyear,xdep,xbias0,inum
        if ( xyear0 .ne. xyear ) then
         iyear=xyear
         xyear0=xyear
         inumset=0
        endif

        inumset=inumset+1
        if ( inum .ge. 30 ) then
         xbias(iyear,inumset)=xbias0
        else
         xbias(iyear,inumset)=0.0
        endif

55     continue
44     continue
       close(9)
 
      endif

      if ( itsprobe .eq. 1 ) then

       do 60 n0=1,numlevels

        if ( isoor .eq. 1 ) then
         n=n0
         ic=n0
         np=0
        else

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

         n=0
         do 65 n2=1,nlayers

          if ( dpt .ge. xlayer(n2,1) .and.
     *         dpt .lt. xlayer(n2,2) ) then
           n=n2
          endif

65       continue

        endif

c       write(6,*) 'nn',n,dpt,levelmaxbias,xbias(iyearx,n),iyearx
        if ( n .eq. 0 .or. n .gt. levelmaxbias ) return

        temp(ic,np+1)=temp(ic,np+1)-xbias(iyearx,n)

60     continue

      endif

      return
      end
