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

C  IPACK     (R)   Pack number, 0=all packs
C  IVAL      (R)   Value for the pack id >= 0; if setting globally then
C                  Pack id's will be incremented by 1 for each successive pack
C  IERR      (W)   Error flag =0 OK
C                             =-1 Invalid pack number
C                             =2 Value must be >=0
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
      INTEGER J
C
C-------------------------------------------------------------------------------
C
      IF (.NOT.INIT_PID) THEN
         CALL LDM_DF_PID (0, IERR, ERRSTR, LDM_MAXPK)
         INIT_PID = .TRUE.
      END IF
      IERR = 0
      ERRSTR = ' '
      CALL LDM_CHK_SPK (IPACK, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      CALL LDM_ERR_I (IVAL, 0, 0, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      IF (IPACK.EQ.0) THEN
         DO 100 I = 1, LDM_MAXPK
            PID(I) = IVAL + I - 1
            IS_PID(I) = 2
            CH_PID(I) = CH_MASK
100      CONTINUE
      ELSE        
         PID(IPACK) = IVAL
         IS_PID(IPACK) = 1
         CH_PID(IPACK) = CH_MASK
      END IF
      RETURN
      END
