
C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**********************
C**     LSM_SCP_X    **
C**********************
C
C **** LSM SERVICE ROUTINE ONLY ****
C
      SUBROUTINE LSM_SCP_X (IOPT, X)
C
      INCLUDE 'implicit_none.finc'
      INCLUDE 'limits.finc'
C
C Purpose: Copies the values of the parameters being refined between the
C          internal scaling arrays (SCP) and the refinement routines
C          'X' array. Uses current values of refinement flags and
C          pack/plate present with valid data flags.
C
C Author:  Steffi Arzt, July 1997
C
C Arguments:
C
      INTEGER IOPT
      DOUBLE PRECISION X(MXPAR)
C
C  Parameters: 
C  IOPT        i (R)   Flag =1 Copy parameter values from SCP to 'X'
C                           =2 Copy parameter values from 'X' to SCP
C  REAL X()    r (R)   Array containing parameters to be refined
C
C====== PARAMETERS:
C

C
C====== GLOBALS:
C
      INCLUDE 'ref_flags.finc'
      INCLUDE 'scps_counters.finc'
      INCLUDE 'other_scale.finc'
      INCLUDE 'scp.finc'
      INCLUDE 'x_array.finc'
C
C====== LOCALS:
C
      INTEGER I, J, M, K
 
C     INTEGER I, J, M, K            ! Temp/loop variables
C          
C-------------------------------------------------------------------------------
C
C
C====== Initialize
C
      
C
C====== Copy SCP into X and XC
C
      IF (IOPT.EQ.1) THEN
         DO 10 I = 1, MXPAR
            X(I) = 0.0
            XC(I) = 0.0
 10      CONTINUE
      END IF

      J = 1

      IF (IOPT.EQ.1) THEN
         IF (ABSCORLOC) THEN
            DO 60 M = 1, MAXPACK
               DO 50 I = 1, MAXCOEFFS
                  IF (REFLAGSLOC(M,I)) THEN
                     X(J) = SCPLOC((M-1)*MAXCOEFFS+I)
                     J = J + 1
                  END IF  
 50            CONTINUE
 60         CONTINUE
         ELSE
      	    DO 20 I = 1, MXPAR
               IF (REFLAGS(I)) THEN
                  X(J) = SCP(I)
                  XC(J) = SCP(I)
                  J = J + 1
               END IF
20          CONTINUE
         END IF
         NXELE = J - 1
         RETURN
      END IF
        
C
C====== Copy X into SCP
C
      J = 1
      K = 1
      IF (IOPT.EQ.2) THEN
         IF (ABSCORLOC) THEN
            DO 70 M = 1, MAXPACK
               DO 80 I = 1, MAXCOEFFS
                  IF (REFLAGSLOC(M,I)) THEN
                     SCPLOC((M-1)*MAXCOEFFS+I) = X(K)
                     K = K + 1
                  END IF  
 80            CONTINUE
 70         CONTINUE
         ELSE
      	    DO 30 I = 1, MXPAR
               IF (REFLAGS(I)) THEN
                  SCP(I) = X(J) 
                  J = J + 1
               END IF
30          CONTINUE
            DO 40 I = 1, MXPAR
               XC(I) = X(I)
40          CONTINUE   
         END IF                  
      END IF

      RETURN
      END
