        SUBROUTINE  SNS
     *     (N, P, D, IJU,JU,IU,U, Z, B, TMP)                              SD 605
        INTEGER  P(1),  IJU(1), JU(1), IU(1)                              SD 606
C       REAL  D(1), U(1),  Z(1), B(1),  TMP(1),  TMPK, SUM                SD 607
        DOUBLE PRECISION  D(1), U(1),  Z(1), B(1),  TMP(1),  TMPK, SUM    SD 608
C                                                                         SD 609
C  ADDITIONAL PARAMETERS                                                  SD 610
C                                                                         SD 611
C    TMP   - REAL ONE-DIMENSIONAL WORK ARRAY;  DIMENSION = N              SD 612
C                                                                         SD 613
C-----------------------------------------------------------------------  SD 614
C                                                                         SD 615
C----SET TMP TO PERMUTED B                                                SD 616
        DO 1 K=1,N                                                        SD 617
   1      TMP(K) = B(P(K))                                                SD 618
C                                                                         SD 619
C----SOLVE  UT D Y = B  BY FORWARD SUBSTITUTION                           SD 620
        DO 3 K=1,N                                                        SD 621
          TMPK = TMP(K)                                                   SD 622
          JMIN = IU(K)                                                    SD 623
          JMAX = IU(K+1) - 1                                              SD 624
          IF (JMIN.GT.JMAX)  GO TO 3                                      SD 625
          MU = IJU(K) - JMIN                                              SD 626
          DO 2 J=JMIN,JMAX                                                SD 627
   2        TMP(JU(MU+J)) = TMP(JU(MU+J)) + U(J) * TMPK                   SD 628
   3      TMP(K) = TMPK * D(K)                                            SD 629
C                                                                         SD 630
C----SOLVE  U X = Y  BY BACK SUBSTITUTION                                 SD 631
        K = N                                                             SD 632
        DO 6 I=1,N                                                        SD 633
          SUM = TMP(K)                                                    SD 634
          JMIN = IU(K)                                                    SD 635
          JMAX = IU(K+1) - 1                                              SD 636
          IF (JMIN.GT.JMAX)  GO TO 5                                      SD 637
          MU = IJU(K) - JMIN                                              SD 638
          DO 4 J=JMIN,JMAX                                                SD 639
   4        SUM = SUM + U(J) * TMP(JU(MU+J))                              SD 640
   5      TMP(K) = SUM                                                    SD 641
          Z(P(K)) = SUM                                                   SD 642
   6      K = K-1                                                         SD 643
C                                                                         SD 644
        RETURN                                                            SD 645
        END                                                               SD 646
