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

C  IPACK     (R)   Pack number, 0=all packs
C  IPLATE    (R)   Plate number, 0=all plates
C  VALSTR    (R)   The file name (max 120 chars) if blank then form from
C                  template
C  IERR      (W)   Error flag =0 OK
C                             =-1 Invalid pack number
C                             =-2 Invalid plate number
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
      IF (IPACK.EQ.0) THEN
         IF (IPLATE.EQ.0) THEN
            DO 100 I = 1, LDM_MAXPK
               DO 50 J = 1, LDM_MAXPL
                  FNAME(I,J) = VALSTR
                  IS_FNAME(I,J) = 2
                  CH_FNAME(I,J) = CH_MASK
50             CONTINUE
100         CONTINUE
         ELSE
            DO 150 I = 1, LDM_MAXPK
                FNAME(I,IPLATE) = VALSTR
                IS_FNAME(I,IPLATE) = 2
                CH_FNAME(I,IPLATE) = CH_MASK
150         CONTINUE
         END IF
      ELSE
         IF (IPLATE.EQ.0) THEN
            DO 200 J = 1, LDM_MAXPL
               FNAME(IPACK,J) = VALSTR
               IS_FNAME(IPACK,J) = 2
               CH_FNAME(IPACK,J) = CH_MASK
200         CONTINUE
         ELSE
            FNAME(IPACK,IPLATE) = VALSTR
            IS_FNAME(IPACK,IPLATE) = 1
            CH_FNAME(IPACK,IPLATE) = CH_MASK
         END IF
      END IF
      RETURN
      END
