*DECK ALSVDS
      SUBROUTINE ALSVDS(U,W,V,M,N,MP,NP,B,X)
*
*-----------------------------------------------------------------------
*
* LINEAR SYSTEM SOLUTION AFTER SINGULAR VALUE DECOMPOSITION.
*
* INPUT PARAMETERS:
*  U     : FIRST DECOMPOSED MATRIX. DIMENSION U(MP,NP)
*  W     : SINGULAR VALUES. DIMENSION W(NP)
*  V     : SECOND DECOMPOSED MATRIX. DIMENSION V(NP,NP)
*  M,N   : FIRST/SECOND MATHEMATICAL DIMENSION OF MATRIX A
*  MP,NP : FIRST/SECOND PHYSICAL DIMENSION OF MATRIX A
*  B     : RHS VECTOR. DIMENSION B(MP)
*
* OUTPUT PARAMETERS:
*  X     : SOLUTION VECTOR. DIMENSION X(NP)
*
*-----------------------------------------------------------------------
*
      INTEGER M,MP,N,NP
      DOUBLE PRECISION B(MP),U(MP,NP),V(NP,NP),W(NP),X(NP),S
      INTEGER I,J,JJ
      DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: TMP
*
      ALLOCATE(TMP(NP))
      DO 12 J=1,N
        S=0.0D0
        IF(W(J).NE.0.0D0)THEN
          DO 11 I=1,M
            S=S+U(I,J)*B(I)
11        CONTINUE
          S=S/W(J)
        ENDIF
        TMP(J)=S
12    CONTINUE
      DO 14 J=1,N
        S=0.0D0
        DO 13 JJ=1,N
          S=S+V(J,JJ)*TMP(JJ)
13      CONTINUE
        X(J)=S
14    CONTINUE
      DEALLOCATE(TMP)
      RETURN
      END
