!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!

      subroutine pivot2(ab,n,nd,outer,scratch,eps) 1
C
C     This subroutine switches two columns of a matrix to get
C         a nonzero entry in the diagonal.
C     Martin J. McBride.  12/04/85.
C     General Electric CRD, Information System Operation.
C
      integer n,nd,col,outer,i
      real*8 ab(nd,1),scratch(1),temp,eps

C  Get first column with non-zero element in row OUTER.
      col = outer + 1
   10 if (col .gt. n) go to 90
      if (abs(ab(outer,col)) .gt. eps) go to 20
         col = col + 1
         go to 10

C  Switch column OUTER with column COL, which has non-zero element in
C  row OUTER.
   20 do 30 i = 1,n
         temp = ab(i,outer)
         ab(i,outer) = ab(i,col)
         ab(i,col) = temp
   30 continue
      temp = scratch(n+outer)
      scratch(n+outer) = scratch(n+col)
      scratch(n+col) = temp

   90 continue
      return
      end