C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C*****************************
C**     LDM_SET_SPIN        **
C*****************************
C
C
CD-Doc:
C SPINdle          SUBROUTINE LDM_SET_SPIN (IPACK, VALUE, IERR, ERRSTR)
CD-end
      SUBROUTINE LDM_SET_SPIN (IPACK, VALUE, IERR, ERRSTR)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set value of pack dependent real parameter SPINDLE
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      INTEGER IPACK
      REAL    VALUE
      INTEGER IERR
      CHARACTER*(*) ERRSTR

C  IPACK     (R)   Pack number, 0=all packs
C  VALUE     (R)   Value for the spindle setting in degrees (any); if set
C                  globally, each successive spindle angle will be incremented
C                  by the current value of the DSPIN parameter
C  IERR      (W)   Error flag =0 OK
C                             =-1 Invalid pack number
C  ERRSTR    (W)   Error description string if error found
C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      INCLUDE 'ldm_lrl.finc'
      EXTERNAL LDM_BDAT
C
C====== LOCALS:
C
      INTEGER I
C
C-------------------------------------------------------------------------------
C
      IF (.NOT.INIT_SPIN) THEN
         CALL LDM_DF_SPIN (0, IERR, ERRSTR, LDM_MAXPK)
         INIT_SPIN = .TRUE.
      END IF
      IERR = 0
      ERRSTR = ' '
      CALL LDM_CHK_SPK (IPACK, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      IF (IPACK.EQ.0) THEN
         DO 100 I = 1, LDM_MAXPK
            SPIN(I) = VALUE + (I-1)*DSPIN
            IS_SPIN(I) = 2
            CH_SPIN(I) = CH_MASK
            ND_SPIN(I) = -1000
100      CONTINUE
      ELSE        
         SPIN(IPACK) = VALUE
         IS_SPIN(IPACK) = 1
         CH_SPIN(IPACK) = CH_MASK
         ND_SPIN(IPACK) = -1000
      END IF
      CALL LDM_CLR_GEN (IPACK, -1, 2)
      RETURN
      END
