
CD-Section: Parse 'KSM' Keyworded Data
C A routine is available to examine input lines for the presece of KSM 
C symmetry data; if such data are found the data will be checked for 
C validity and stored in the Keyword Symmetry Module. Another routine 
C enables additional parameter checking to be carried out.
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     KWD_PARSESYMM    **
C**************************
C
CD-Routine: Parse Line Containing Symmetry Data - KWD_PARSESYMM
C This routine parses a given line of data, examining it for the presence
C of the keyword 'SYMMETRY' (as the first token) Any such data found is 
C automatically checked and, if valid, stored in the appropriate 
C Keyword Symmetry Module (KSM). If the line does not contain 
C symmetry data from the requested set, then it is merely passed back 
C to the calling program to allow further
C interpretation by that program. The symmetry data line must contain
C only symmetry data.
CD-end
CD-Fortran:
      SUBROUTINE KWD_PARSESYMM (LINE, IFLAG, BADTOK, ERRSTR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Parse line for symmetrydata and store any found.
C
C Author:  John W. Campbell, July 1995
C
C Arguments:
C
      CHARACTER*(*) LINE
      INTEGER IFLAG
      CHARACTER*(*) BADTOK
      CHARACTER*(*) ERRSTR

CD-Parameters:
C LINE     c (R)   Character string containing line to be parsed
C                  (Assume comments & continuations already removed)
C IFLAG    i (W)   Return flag = 0,  Symmetry data found & OK
C                              = 1,  Not symmetry data
C                              = 2,  No non-blank tokens
C                              < 0,  Symmetry data but error(s)
C                              =-1,  Inappropriate set 
C                                    specification
C                              =-2,  Innappropriate subset 
C                                    specification
C                              =-3,  Syntax error in set/subset 
C                                    specification
C                              =-4,  Invalid value
C                             -100,  Coding error in KWD routines, 
C                                    information supposedly already 
C                                    checked is found later to be invalid! 
C BADTOK   c (W)   Returns the token string for an invalid token
C ERRSTR   c (W)   Error string (max 80 chars) if IFLAG<0
CD-end
C
C====== Parameter statements
C 

C
C====== GLOBALS:
C

C
C====== FUNCTION TYPES:
C
      INTEGER NXTTOK
      INTEGER LENSTR
      INTEGER KDMSTR
C
C====== LOCALS:
C
      INTEGER I
      INTEGER LL
      INTEGER IL
      INTEGER M1
      INTEGER M2
      INTEGER IERR
      INTEGER ISET
      INTEGER ISUBSET
      INTEGER ISS
      INTEGER IVAL(2)
      REAL FVAL(2)
      CHARACTER*50 KEYWORD
      CHARACTER*50 FULLNAME
      CHARACTER*4 SEP

C     INTEGER I            !Return flag from NXTTOK routine
C     INTEGER LL           !Length of input line
C     INTEGER IL           !Last character accessed in line being parsed
C     INTEGER M1           !First character in token field
C     INTEGER M2           !Final character in token field
C     INTEGER IERR         !Error flag
C     INTEGER ISET         !Set number decoded from keyword string
C     INTEGER ISUBSET      !Subset number decoded from keyword string
C     INTEGER ISS          !Dataset/set/subset specific parameter flag 0/1/2
C     INTEGER IVAL(2)      !Dummy integer value array
C     REAL FVAL(2)         !Dummy real value array
C     CHARACTER*50 KEYWORD !Keyword string
C     CHARACTER*50 FULLNAME!Full parameter name
C     CHARACTER*4 SEP      !Token separator characters

      DATA SEP /'  ,='/
C
C-------------------------------------------------------------------------------
C
      IFLAG = 2
      SEP(2:2) = CHAR(9)
      BADTOK = ' '
      IL = 0
      LL = LEN(LINE)
C
C====== Get next token
C
100   I = NXTTOK (LINE, SEP, IL, M1, M2)
      IF (I.EQ.-1) RETURN
      IF (I.EQ.0) GO TO 100
C
C====== See if SYMMETRY  name
C
      CALL KWD_PARSEITEM (LINE(M1:M2), KEYWORD, ISET, ISUBSET, ISS, 
     +                    IERR)
      CALL CCPUPC (KEYWORD)
      IF (KEYWORD(1:4).NE.'SYMM') THEN
         IERR = 1
      ELSE
         IF (ISS.EQ.1) IERR = -1
         IF (ISS.EQ.2) IERR = -2
      END IF
      IF (IERR.LE.0) THEN
         IFLAG = 0
         IF (IERR.LT.0) THEN
            BADTOK = LINE(M1:M2)
            IFLAG = IERR
            IF (IERR.EQ.-1) 
     +         ERRSTR = 'Invalid or inappropriate set specification'
            IF (IERR.EQ.-2) 
     +         ERRSTR = 'Invalid or inappropriate subset specification'
            IF (IERR.EQ.-3) 
     +         ERRSTR = 'Syntax error in set/subset specification'
            RETURN
         END IF
         I = NXTTOK (LINE, SEP, IL, M1, M2)
         IF (I.LE.0) THEN
            CALL KSM_RESET
            RETURN
         ELSE
            M2 = LL
            IL = LL
            CALL KSM_SET_SYMM (LINE(M1:M2), IERR, ERRSTR)
            IF (IERR.GT.0) THEN
               BADTOK = LINE(M1:M2)
               IFLAG = - 4
               RETURN
            END IF
         END IF
      ELSE
C
C====== Non-symmetry keyword found
C
        IFLAG = 1
        RETURN
      END IF
      RETURN
      END
