        SUBROUTINE NROC (N, IC, IA, JA, A, JAR, AR, P, FLAG)
C                                                                         CD 452
C       INPUT PARAMETERS: N, IC, IA, JA, A                                CD 453
C       OUTPUT PARAMETERS: JA, A, FLAG                                    CD 454
C                                                                         CD 455
C       PARAMETERS USED INTERNALLY:                                       CD 456
C NIA   \ P     - AT THE KTH STEP, P IS A LINKED LIST OF THE REORDERED    CD 457
C       \           COLUMN INDICES OF THE KTH ROW OF A;  P(N+1) POINTS    CD 458
C       \           TO THE FIRST ENTRY IN THE LIST.                       CD 459
C       \           SIZE = N+1.                                           CD 460
C NIA   \ JAR   - AT THE KTH STEP,JAR CONTAINS THE ELEMENTS OF THE        CD 461
C       \           REORDERED COLUMN INDICES OF A.                        CD 462
C       \           SIZE = N.                                             CD 463
C FIA   \ AR    - AT THE KTH STEP, AR CONTAINS THE ELEMENTS OF THE        CD 464
C       \           REORDERED ROW OF A.                                   CD 465
C       \           SIZE = N.                                             CD 466
C                                                                         CD 467
        INTEGER  IC(1), IA(1), JA(1), JAR(1), P(1), FLAG                  CD 468
C       REAL  A(1), AR(1)                                                 CD 469
        DOUBLE PRECISION  A(1), AR(1)                                     CD 470
C                                                                         CD 471
C  ******  FOR EACH NONEMPTY ROW  *******************************         CD 472
        DO 5 K=1,N                                                        CD 473
          JMIN = IA(K)                                                    CD 474
          JMAX = IA(K+1) - 1                                              CD 475
          IF(JMIN .GT. JMAX) GO TO 5                                      CD 476
          P(N+1) = N + 1                                                  CD 477
C  ******  INSERT EACH ELEMENT IN THE LIST  *********************         CD 478
          DO 3 J=JMIN,JMAX                                                CD 479
            NEWJ = IC(JA(J))                                              CD 480
            I = N + 1                                                     CD 481
   1        IF(P(I) .GE. NEWJ) GO TO 2                                    CD 482
              I = P(I)                                                    CD 483
              GO TO 1                                                     CD 484
   2        IF(P(I) .EQ. NEWJ) GO TO 102                                  CD 485
            P(NEWJ) = P(I)                                                CD 486
            P(I) = NEWJ                                                   CD 487
            JAR(NEWJ) = JA(J)                                             CD 488
            AR(NEWJ) = A(J)                                               CD 489
   3        CONTINUE                                                      CD 490
C  ******  REPLACE OLD ROW IN JA AND A  *************************         CD 491
          I = N + 1                                                       CD 492
          DO 4 J=JMIN,JMAX                                                CD 493
            I = P(I)                                                      CD 494
            JA(J) = JAR(I)                                                CD 495
   4        A(J) = AR(I)                                                  CD 496
   5      CONTINUE                                                        CD 497
        FLAG = 0                                                          CD 498
        RETURN                                                            CD 499
C                                                                         CD 500
C ** ERROR:  DUPLICATE ENTRY IN A                                         CD 501
 102    FLAG = N + K                                                      CD 502
        RETURN                                                            CD 503
        END                                                               CD 504
