
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C***************************
C**      LSC_RFACTS_OUT    **
C***************************
C
C **** LSC SERVICE ROUTINE ONLY ****
C
C Routine: Output the R-factor tables - LSC_RFACTS_OUT
C The routine LSC_RFACTS_OUT is used to output R-factor analysis
C tables using the information collected by the subroutine LSC_RFACTS
C which must be called prior to calling this routine.
C
      SUBROUTINE LSC_RFACTS_OUT (IUN, IR1, IR2, IR3, PLMERGE)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Outputs R-factor tables calculated in LSC_RFACTS
C
C Author:  Steffi Arzt, John Campbell, July 1997
C
C Arguments:
C
      INTEGER IUN
      INTEGER IR1
      INTEGER IR2
      INTEGER IR3
      LOGICAL PLMERGE
C
C Parameters:
C IUN    i  (R)   Fortran unit number for the output
C IR1    i  (R)   =1 Output first R-factor table, =0 do not
C IR2    i  (R)   =1 Output second R-factor table, =0 do not
C IR3    i  (R)   =1 Output third R-factor table, =0 do not
C PLMERGEl  (R)   .true. = merged plate data
C                 .false. = plate data seperate

C
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'rout_arrays.finc'

C
C====== LOCALS:
C
      INTEGER I
      INTEGER NNSUM
C     INTEGER I, NNSUM          ! Temp/loop variables

C
C-------------------------------------------------------------------------------
C
      NNSUM = 0
      IF (IR1.NE.0) THEN
        CALL LSC_ROUT(IUN, 1, RFAC1, NREF1, 1, NBINR(1), 1, PLMERGE)
      END IF
      IF (IR2.NE.0) THEN
         CALL LSC_ROUT(IUN, 2, RFAC2, NREF2, 1, NBINR(1), 1, PLMERGE)
      END IF
      IF (IR3.NE.0) THEN
         CALL LSC_ROUT(IUN, 3, RFAC3, NREF3, 1, NBINR(1), 1, PLMERGE)
      END IF

      IF (NRANGE.GT.1) THEN
         DO 270 I = 1, NRANGE-1
            NNSUM = NNSUM + NBINR(I)
            IF (IR1.NE.0) THEN
               CALL LSC_ROUT(IUN,1,RFAC1,NREF1,NNSUM+1,
     +                    NNSUM+NBINR(I+1),I+1, PLMERGE)
            END IF
            IF (IR2.NE.0) THEN
               CALL LSC_ROUT(IUN,2,RFAC2,NREF2,NNSUM+1,
     +                       NNSUM+NBINR(I+1),I+1, PLMERGE)
            END IF
            IF (IR3.NE.0) THEN
               CALL LSC_ROUT(IUN,3,RFAC3,NREF3,NNSUM+1,
     +                       NNSUM+NBINR(I+1),I+1, PLMERGE)
            END IF
 270     CONTINUE
      END IF

      CALL LSC_RFOUT (IUN, PLMERGE)

      CALL LSC_ROUT(IUN,4,RFACP,NREFP,1,NPK_RF,I, PLMERGE)
      
 280  RETURN

      END
