C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C****************************
C**     LDM_SET_SYST       **
C****************************
C
C
CD-Doc:
C SYSTem           SUBROUTINE LDM_SET_SYST (VALSTR, IVAL, IERR, ERRSTR)
CD-end
      SUBROUTINE LDM_SET_SYST (VALSTR, IVAL, IERR, ERRSTR)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set value of code/integer parameter SYSTEM
C
C Author:  John W. Campbell, June 1993
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                  1'st 3 characters checked (case insensitive) for the
C                  following strings:
C                             Triclinic
C                             Monoclinic
C                             Orthorhombic
C                             Tetragonal
C                             Hexagonal
C                             Rhombohedral
C                             Cubic
C  IVAL      (R)   Value for the parameter (used if VALSTR = ' ') (1-7)
C                  1=Triclinic...7=Cubic
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_lrl.finc'
      EXTERNAL LDM_BDAT
C
C====== LOCALS:
C
      INTEGER I
      INTEGER IS
      CHARACTER*3 SYS(7)
      CHARACTER*3 CODE

C     INTEGER I          !Loop variable
C     INTEGER IS         !System no. if found
C     CHARACTER*3 SYS(7) !Valid crystal system codes
C     CHARACTER*3 CODE   !Code being matched (upper case)

      DATA SYS /'TRI','MON','ORT','TET','HEX','RHO','CUB' /
C
C-------------------------------------------------------------------------------
C
      IERR = 0
      ERRSTR = ' '
      IF (VALSTR.NE.' ') THEN
         CODE = VALSTR
         CALL CCPUPC(CODE)
         DO 100 I = 1,7
            IS = I
            IF (CODE.EQ.SYS(I)) GO TO 120
100      CONTINUE
         IERR = 1
         ERRSTR = 
     +   'Invalid code - must be Tri, Mon, Ort, Tet, Hex, Rho or Cub'
         RETURN
120      SYST = IS
      ELSE
         CALL LDM_ERR_I (IVAL, 1, 7, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         SYST = IVAL
      END IF
      IS_SYST = 1
      CH_SYST = CH_MASK
      CALL LDM_CLR_GEN (-1, -1, 1)
      RETURN
      END
