       SUBROUTINE XBTBIASgourt12(itsprobe,depth,temp,maxlevel,
     * maxcalc,numsec,numlevels,iyearx,ixprobe,bmiss,ifix,iplat)
      parameter (maxyear=3000,maxset=40,nt4=8,n7db=8)
      parameter (maxdepth=3000)
      parameter (ntno=7,nt10=4)
      parameter (icmax=13)
      character*14 firsttime
      character*80 filename,text

      dimension icomma(icmax,2)
      dimension depth(maxlevel),temp(maxlevel,maxcalc)
      dimension itype4(nt4),itype7db(n7db)
      dimension itypeno(ntno),itype10(nt10)
      dimension doff(maxdepth,4)
      dimension slope(maxdepth,4)
      dimension tbias(maxdepth,4)

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

      save firsttime
      save doff,slope,tbias,iyearmin,iyearmax

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

c     read in bias corrections

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

      open(9,file=filename,status='old')

c      read in headers
      
      read(9,'(a)') text
      read(9,'(a)') text
       iyearmin=5000
       iyearmax=0

       do 50 i=1,maxyear
       	
      read(9,'(a)',end=44) text
c      write(9,*) text
      call findlastchar(nsp,text,80)
  
      call commafindx(nsp,icmax,ncomma,icomma,text)
      read(text(icomma(1,1):icomma(1,1)+icomma(1,2)-1),*)
     * iyear

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

c for T10
      call checkifallspace(text,icomma(2,1),icomma(2,2),ispace)
      if ( ispace .eq. 0 ) then
       read(text(icomma(2,1):icomma(2,1)+icomma(2,2)-1),*)
     *  doff(iyear,1)
       read(text(icomma(3,1):icomma(3,1)+icomma(3,2)-1),*)
     *  slope(iyear,1)
       read(text(icomma(4,1):icomma(4,1)+icomma(4,2)-1),*)
     *  tbias(iyear,1)
      endif

c for T4 
      call checkifallspace(text,icomma(5,1),icomma(5,2),ispace)
      if ( ispace .eq. 0 ) then
       read(text(icomma(5,1):icomma(5,1)+icomma(5,2)-1),*)
     *  doff(iyear,2)
       read(text(icomma(6,1):icomma(6,1)+icomma(6,2)-1),*)
     *  slope(iyear,2)
       read(text(icomma(7,1):icomma(7,1)+icomma(7,2)-1),*)
     *  tbias(iyear,2)
      endif

c for SX 
      call checkifallspace(text,icomma(8,1),icomma(8,2),ispace)
      if ( ispace .eq. 0 ) then
       read(text(icomma(8,1):icomma(8,1)+icomma(8,2)-1),*)
     *  doff(iyear,3)
       read(text(icomma(9,1):icomma(9,1)+icomma(9,2)-1),*)
     *  slope(iyear,3)
       read(text(icomma(10,1):icomma(10,1)+icomma(10,2)-1),*)
     *  tbias(iyear,3)
      endif

c for T7 
      call checkifallspace(text,icomma(11,1),icomma(11,2),ispace)
      if ( ispace .eq. 0 ) then
       read(text(icomma(11,1):icomma(11,1)+icomma(11,2)-1),*)
     *  doff(iyear,4)
       read(text(icomma(12,1):icomma(12,1)+icomma(12,2)-1),*)
     *  slope(iyear,4)
       read(text(icomma(13,1):icomma(13,1)+icomma(13,2)-1),*)
     *  tbias(iyear,4)
      endif

c       write(6,*) iyear,doff,slope,tbias
c       write(6,*) iyear,doff(iyear,1),slope(iyear,1),tbias(iyear,1),
c     * doff(iyear,2),slope(iyear,2),tbias(iyear,2),
c     * doff(iyear,3),slope(iyear,3),tbias(iyear,3),
c     * doff(iyear,4),slope(iyear,4),tbias(iyear,4)       

c      call clearstring(text,80)

50       continue
44       continue
       close(9)

       endif

       ntyp=0
       ifix=0
c      Determine shallow or deep
       
      if (numlevels .le. maxlevel) then
        dpt =depth(numlevels)
      else
        call overmax(maxlevel,numsec,numlevels,0,ic,np)
        dpt=temp(ic,np)
      endif
       
        shalmax=550 
        call xbtshallowdeep(ishallow,ixprobe,dpt,shalmax,iplat)
c        ixprobe=ixbttype
c      if ( ishallow .eq. -1) return
        if ( dpt .gt. 960.) return

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


       if ( itsprobe .eq. 2 ) then
       if ( ixprobe .ne. 2 .and. ixprobe .ne. 0 ) then

c      write(6,*) 'ixprobe',ixprobe,iyearx

      do 700 nn=1,n7db
700       if ( ixprobe .eq. itype7db(nn) ) ntyp=4

      do 701 nn=1,nt4
701       if ( ixprobe .eq. itype4(nn) ) ntyp=2

      do 702 nn=1,nt10
702       if ( ixprobe .eq. itype10(nn) ) ntyp=1

      do 703 nn=1,ntno
703       if ( ixprobe .eq. itypeno(nn) ) ntyp=0
       endif

      if (ntyp .eq. 0) then
      if (ishallow .eq. 1) ntyp=3
      if (ishallow .eq. 0) ntyp=4

      endif 
     
      ifix=1

      do 200 k=1,numlevels
       depth(k)=depth(k)+(doff(iyear,ntyp)+
     *  slope(iyear,ntyp)*depth(k))
       temp(k,1)=temp(k,1)-tbias(iyear,ntyp)
200      continue
      endif

      return
      end

