
CD-Section: Save and Restore Refineable Parameter Values
C These routines enable the refineable LDM parameter values to be saved
C for a given pack and plate before a refinement is carried out and
C restore, if required, if the refined values are not deemen to be
C acceptable. The routines are included as LDM routines as they need
C to access internal flags within the LDM.
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_SAVERP       **
C**************************
C
CD-Routine: Save Refineable Parameters - LDM_SAVERP
C This routine will save the values of the refineable parameters for
C a requested pack and plate.
CD-end
CD-Fortran:
      SUBROUTINE LDM_SAVERP (IPACK, IPLATE)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Save current values of refineable parameters
C
C Author:  John W. Campbell, September 1993
C
C Arguments:
C
      INTEGER IPACK
      INTEGER IPLATE
CD-Parameters:
C IPACK   i (R)  Pack number (explicit)
C IPLATE  i (R)  Plate number (explicit)
CD-end
C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      INCLUDE 'save_refpars.finc'
C
C====== LOCALS:
C
      INTEGER I
      INTEGER NSPDX
      INTEGER NSPDY
      REAL SPDX_MIN
      REAL SPDX_MAX
      REAL SPDY_MIN
      REAL SPDY_MAX
      INTEGER KFLAG
      INTEGER ND
      INTEGER KERR
      CHARACTER*2 ERRSTR

C     INTEGER I         !Temp/loop variable
C     INTEGER NSPDX     !Spatial distortion x polynomial order
C     INTEGER NSPDY     !Spatial distortion y polynomial order
C     REAL SPDX_MIN     !Spatial distortion Chebyshev x lower bound
C     REAL SPDX_MAX     !Spatial distortion Chebyshev x upper bound
C     REAL SPDY_MIN     !Spatial distortion Chebyshev y lower bound
C     REAL SPDY_MAX     !Spatial distortion Chebyshev y upper bound
C     INTEGER KFLAG     !Parameter status flag
C     INTEGER ND        !No. of decimal places flag
C     INTEGER KERR               !Error flag
C     CHARACTER*2 ERRSTR         !Error string (dummy)
C
C-------------------------------------------------------------------------------
C
      CALL LDM_GET_A (SAV_A, KFLAG, ND)
      SV_CH_A = CH_A
      CALL LDM_GET_B (SAV_B, KFLAG, ND)
      SV_CH_B = CH_B
      CALL LDM_GET_C (SAV_C, KFLAG, ND)
      SV_CH_C = CH_C
      CALL LDM_GET_ALPHA (SAV_ALPHA, KFLAG, ND)
      SV_CH_ALPHA = CH_ALPHA
      CALL LDM_GET_BETA (SAV_BETA, KFLAG, ND)
      SV_CH_BETA = CH_BETA
      CALL LDM_GET_GAMMA (SAV_GAMMA, KFLAG, ND)
      SV_CH_GAMMA = CH_GAMMA
      CALL LDM_GET_PHIX (IPACK, SAV_PHIX, KFLAG, ND, KERR, ERRSTR)
      SV_CH_PHIX = CH_PHIX(IPACK)
      CALL LDM_GET_PHIY (IPACK, SAV_PHIY, KFLAG, ND, KERR, ERRSTR)
      SV_CH_PHIY = CH_PHIY(IPACK)
      CALL LDM_GET_PHIZ (IPACK, SAV_PHIZ, KFLAG, ND, KERR, ERRSTR)
      SV_CH_PHIZ = CH_PHIZ(IPACK)
      CALL LDM_GET_CTOF (IPACK, IPLATE, SAV_CTOF, KFLAG, ND, 
     +                   KERR, ERRSTR)
      SV_CH_CTOF = CH_CTOF(IPACK,IPLATE)
      CALL LDM_GET_XC (IPACK, IPLATE, SAV_XC, KFLAG, ND, 
     +                 KERR, ERRSTR)
      SV_CH_XC = CH_XC(IPACK,IPLATE)
      CALL LDM_GET_YC (IPACK, IPLATE, SAV_YC, KFLAG, ND, 
     +                 KERR, ERRSTR)
      SV_CH_YC = CH_YC(IPACK,IPLATE)
      CALL LDM_GET_WC (IPACK, IPLATE, SAV_WC, KFLAG, ND, 
     +                 KERR, ERRSTR)
      SV_CH_WC = CH_WC(IPACK,IPLATE)
      CALL LDM_GET_YSCAL (IPACK, IPLATE, SAV_YSCAL, KFLAG, ND, 
     +                    KERR, ERRSTR)
      SV_CH_YSCAL = CH_YSCAL(IPACK,IPLATE)
      CALL LDM_GET_TWIST (IPACK, IPLATE, SAV_TWIST, KFLAG, ND, 
     +                    KERR, ERRSTR)
      SV_CH_TWIST = CH_TWIST(IPACK,IPLATE)
      CALL LDM_GET_TILT (IPACK, IPLATE, SAV_TILT, KFLAG, ND, 
     +                   KERR, ERRSTR)
      SV_CH_TILT = CH_TILT(IPACK,IPLATE)
      CALL LDM_GET_BULGE (IPACK, IPLATE, SAV_BULGE, KFLAG, ND, 
     +                    KERR, ERRSTR)
      SV_CH_BULGE = CH_BULGE(IPACK,IPLATE)
      CALL LDM_GET_ROFF (IPACK, IPLATE, SAV_ROFF, KFLAG, ND, 
     +                   KERR, ERRSTR)
      SV_CH_ROFF = CH_ROFF(IPACK,IPLATE)
      CALL LDM_GET_TOFF (IPACK, IPLATE, SAV_TOFF, KFLAG, ND, 
     +                   KERR, ERRSTR)
      SV_CH_TOFF = CH_TOFF(IPACK,IPLATE)
      CALL LDM_SPDXY (IPACK, IPLATE, SAV_SPDXY, 
     +                NSPDX, SPDX_MIN, SPDX_MAX, SAV_SPDX,
     +                NSPDY, SPDY_MIN, SPDY_MAX, SAV_SPDY,
     +                LDM_MAXSPD, KERR, ERRSTR)
      SV_CH_SPDXY = CH_SPDXY(IPACK,IPLATE)
      DO 100 I = 1, LDM_MAXSPD
         SV_CH_SPDX(I) = CH_SPDX(IPACK,IPLATE,I)
         SV_CH_SPDY(I) = CH_SPDY(IPACK,IPLATE,I)
100   CONTINUE
      RETURN
      END
