      subroutine DECOMP(N,A,IPS,SKALES,JS)
        double precision A, SKALES, BIG, PIVOT, ROWNRM, SIZE
        integer IPS,N,JS,I,J,NM1,JP,IDXPIV,K,IP,IP1,KP
        dimension A(N,N), SKALES(N), IPS(N)
      JS = -1
      do 110 I = 1, N
         IPS(I) = I
         ROWNRM = 0.0
         do 100 J = 1, N
            ROWNRM = dmax1(ROWNRM,dabs(A(I,J)))
100      continue
         if (ROWNRM.eq.0.0) return
         SKALES(I) = 1.0/ROWNRM
110   continue
      NM1 = N-1
      do 160 I = 1, NM1
         BIG = 0.0
         do 120 J = I, N
            JP = IPS(J)
            SIZE = dabs(A(JP,I))*SKALES(JP)
            if (SIZE.le.BIG) go to 120
            BIG = SIZE
            IDXPIV = J
120      continue
         if (BIG.eq.0.0) return
         if (IDXPIV.eq.I) go to 130
         K = IPS(I)
         IPS(I) = IPS(IDXPIV)
         IPS(IDXPIV) = K
130      continue
         IP = IPS(I)
         PIVOT = A(IP,I)
         IP1 = I+1
         do 150 J = IP1, N
            JP = IPS(J)
            A(JP,I) = A(JP,I)/PIVOT
            do 140 K = IP1, N
               A(JP,K) = A(JP,K)-A(JP,I)*A(IP,K)
140         continue
150      continue
160   continue
      KP = IPS(N)
      if (A(KP,N).eq.0.0) return
      JS = 1
      return
      end
