C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_SET_SPDXN    **
C**************************
C
C
CD-Doc:
C SPDX_N           SUBROUTINE LDM_SET_SPDXN (IPACK, IPLATE, IVAL, 
C                 +                          IERR, ERRSTR)
CD-end
      SUBROUTINE LDM_SET_SPDXN (IPACK, IPLATE, IVAL, IERR, ERRSTR)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set value of plate dependent integer parameter SPDX_N
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      INTEGER IPACK
      INTEGER IPLATE
      INTEGER IVAL
      INTEGER IERR
      CHARACTER*(*) ERRSTR

C  IPACK     (R)   Pack number, 0=all packs
C  IPLATE    (R)   Plate number, 0=all plates
C  IVAL      (R)   Polynomial order
C  IERR      (W)   Error flag =0 OK
C                             =-1 Invalid pack number
C                             =-2 Invalid plate number
C                             =3 Value must be >0
C                             =4 Value out of range (other)
C  ERRSTR    (W)   Error description string if error found
C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      EXTERNAL LDM_BDAT
C
C====== LOCALS:
C
      INTEGER I
      INTEGER J
C
C-------------------------------------------------------------------------------
C
      IERR = 0
      ERRSTR = ' '
      CALL LDM_CHK_SPL (IPACK, IPLATE, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      CALL LDM_ERR_I (IVAL, 1, LDM_MAXSPD, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      IF (IPACK.EQ.0) THEN
         IF (IPLATE.EQ.0) THEN
            DO 100 I = 1, LDM_MAXPK
               DO 50 J = 1, LDM_MAXPL
                  SPDXN(I,J) = IVAL
                  IS_SPDXN(I,J) = 2
                  CH_SPDXN(I,J) = CH_MASK
50             CONTINUE
100         CONTINUE
         ELSE
            DO 150 I = 1, LDM_MAXPK
                SPDXN(I,IPLATE) = IVAL
                IS_SPDXN(I,IPLATE) = 2
                CH_SPDXN(I,IPLATE) = CH_MASK
150         CONTINUE
         END IF
      ELSE
         IF (IPLATE.EQ.0) THEN
            DO 200 J = 1, LDM_MAXPL
               SPDXN(IPACK,J) = IVAL
               IS_SPDXN(IPACK,J) = 2
               CH_SPDXN(IPACK,J) = CH_MASK
200         CONTINUE
         ELSE
            SPDXN(IPACK,IPLATE) = IVAL
            IS_SPDXN(IPACK,IPLATE) = 1
            CH_SPDXN(IPACK,IPLATE) = CH_MASK
         END IF
      END IF
      CALL LDM_CLR_GEN (IPACK, IPLATE, 2)
      RETURN
      END
