C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C****************************
C**     LDM_SET_DGEOM      **
C****************************
C
C
CD-Doc:
C DGEOm            SUBROUTINE LDM_SET_DGEOM (VALSTR, IVAL, IERR, ERRSTR)
CD-end
      SUBROUTINE LDM_SET_DGEOM (VALSTR, IVAL, IERR, ERRSTR)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set value of code/integer parameter DGEOM
C
C Author:  John W. Campbell, July 1997
C
C Arguments:
C
      CHARACTER*(*) VALSTR
      INTEGER IVAL
      INTEGER IERR
      CHARACTER*(*) ERRSTR

C  VALSTR    (R)   Code to be checked and decoded; if blank use IVAL instead
C                  full code checked must be 'flat' or 'cyl'
C  IVAL      (R)   Value for the parameter (used if VALSTR = ' ') 1 or 2
C                  1=flat, 2=cyl
C  IERR      (W)   Error flag =0 OK
C                             =1 Invalid code or syntax error in string
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'
      INCLUDE 'ldm_derived.finc'
      EXTERNAL LDM_BDAT
C
C====== FUNCTION TYPES:
C
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER I
      INTEGER IT
      CHARACTER*4 TYPE(2)
      CHARACTER*4 CODE

C     INTEGER I              !Loop variable
C     INTEGER IT             !Type code
C     CHARACTER*4 TYPE(2)    !Valid detector geometry strings
C     CHARACTER*4 CODE       !Code for matching (upper case

      DATA TYPE /'FLAT','CYL'/
C
C-------------------------------------------------------------------------------
C
      IERR = 0
      ERRSTR = ' '
      IF (VALSTR.NE.' ') THEN
         CODE = VALSTR
         CALL CCPUPC(CODE)
         DO 100 I = 1,2
            IT = I
            IF (CODE.EQ.TYPE(I)) GO TO 120
100      CONTINUE
         IERR = 1
         ERRSTR = 
     +   'Invalid code - must be flat or cyl'
         RETURN
120      DGEOM = IT
      ELSE
         CALL LDM_ERR_I (IVAL, 1, 2, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         DGEOM = IVAL
      END IF
      IS_DGEOM = 1
      CH_DGEOM = CH_MASK
C
C====== Set dependent parameters
C
      IDGEOM = DGEOM
      CALL LDM_CLR_GEN (-1, -1, 2)
      RETURN
      END
