C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    M_FINDWORD  FIND A "WORD" IN A LINE OF TEXT
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 01-07-31
C
C ABSTRACT: FIND A "WORD" IN A LINE OF TEXT, DELIMITED BY "," OR " "
C   OR "/".
C
C PROGRAM HISTORY LOG:
C   01-07-31  M. BARTH    ORIGINAL VERSION
C
C USAGE:    CALL M_FINDWORD(STRING,LENGTH,START_POS,LEFT,RIGHT)
C
C   INPUT ARGUMENT LIST:
C       STRING - C       CHARACTER STRING CONTAINING THE WORD(S).
C
C       LENGTH - I       LENGTH OF THE STRING.
C
C       START_POS -I     STARTING POSITION FOR THE SEARCH.  NOTE THAT 
C                        THE STARTING POSITION IS DEFINED TO BE THE LAST
C                        CHARACTER OF THE WORD FOUND PRIOR TO THIS CALL.  
C                        THE NEXT CHARACTER IS ASSUMED TO BE A DELIMITER 
C                        AND IS SKIPPED.  IN THE EXAMPLE BELOW IN 
C                        REMARKS, THE FIRST START_POS SHOULD BE SPECIFED 
C                        AS -1.  THEN 0 WILL BE SKIPPED AND THE T WILL 
C                        BE FOUND STARTING IN POSITION 1 OF STRING.
C
C   OUTPUT ARGUMENT LIST:
C       LEFT   - I       LEFTMOST POSITION, IN STRING, OF THE WORD 
C                        FOUND.  IF NO WORD IS FOUND, LEFT IS SET TO 0.
C
C       RIGHT  - I       RIGHTMOST POSITION OF THE WORD FOUND.  THIS 
C                        SHOULD BE USED AS START_POS IN ENSUING CALLS TO
C                        PARSE STRING.
C REMARKS:
C   THIS UTILITY SUBROUTINE CAN BE USED TO FIND A "WORD" IN A LINE OF
C   TEXT, AND IS PARTICULARY MEANT FOR PARSING COMMAND LINES.  A WORD
C   IS DEFINED AS TEXT BETWEEN CERTAIN DELIMITERS.  DELIMITERS 
C   RECOGNIZED BY THIS ROUTINE ARE A COMMA (","), A SPACE (" ") AND A 
C   SLASH ("/").
C
C     FOR EXAMPLE:
C
C     T ABC,23/34 DEF
C
C     SUCCESSIVE CALLS TO THIS ROUTINE CAN FIND ALL OF THE ABOVE WORDS.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE M_FINDWORD(STRING,LENGTH,START_POS,LEFT,RIGHT)

C     ------------------------------------------------------------------
C     INCLUDES 
C     ------------------------------------------------------------------
      INCLUDE 'IMPLICIT'

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      CHARACTER*(*) STRING
      INTEGER LENGTH,START_POS,LEFT,RIGHT

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER I,J

C     ------------------------------------------------------------------
C     LOOK FOR LEFT STARTING AT START_POS+2, THEN AFTER IT'S FOUND, LOOK
C     FOR RIGHT UNTIL WE HIT LENGTH.
C     ------------------------------------------------------------------
      LEFT = 0

      DO I = START_POS+2,LENGTH

         IF(STRING(I:I).NE.' '.AND.STRING(I:I).NE.'/'.AND.
     $      STRING(I:I).NE.',')THEN
     
            LEFT = I
            RIGHT = I
     
            DO J = LEFT,LENGTH
     
               IF(STRING(J:J).EQ.' '.OR.STRING(J:J).EQ.'/'.OR.
     $            STRING(J:J).EQ.',')THEN
     
                  RIGHT = J - 1
                  RETURN
     
               ELSE IF(J.EQ.LENGTH)THEN
     
                  RIGHT = J
                  RETURN

               ENDIF

            ENDDO

         ENDIF

      ENDDO
     
      RETURN
      END
C**---------------------------------------------------------------------
C**REQUIRED STANDARD FSL DISCLAIMER (NOVEMBER 2000)
C**---------------------------------------------------------------------
C**  OPEN SOURCE LICENSE/DISCLAIMER,  FORECAST SYSTEMS LABORATORY
C**  NOAA/OAR/FSL, 325 BROADWAY BOULDER, CO 80305
C**
C**  THIS SOFTWARE IS DISTRIBUTED UNDER THE OPEN SOURCE DEFINITION, 
C**  WHICH MAY BE FOUND AT http://www.opensource.org/osd.html.
C**
C**  IN PARTICULAR, REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS,
C**  WITH OR WITHOUT MODIFICATION, ARE PERMITTED PROVIDED THAT THE 
C**  FOLLOWING CONDITIONS ARE MET:
C**
C**  - REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THIS NOTICE, THIS LIST
C**    OF CONDITIONS AND THE FOLLOWING DISCLAIMER.
C**
C**  - REDISTRIBUTIONS IN BINARY FORM MUST PROVIDE ACCESS TO THIS 
C**    NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING DISCLAIMER, AND
C**    THE UNDERLYING SOURCE CODE.
C**
C**  - ALL MODIFICATIONS TO THIS SOFTWARE MUST BE CLEARLY DOCUMENTED, 
C**    AND ARE SOLELY THE RESPONSIBILITY OF THE AGENT MAKING THE 
C**    MODIFICATIONS.
C**
C**  - IF SIGNIFICANT MODIFICATIONS OR ENHANCEMENTS ARE MADE TO THIS
C**    SOFTWARE, THE FSL SOFTWARE POLICY MANAGER 
C**    (softwaremgr.fsl@noaa.gov) BE NOTIFIED.
C**
C**  THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN AND 
C**  ARE FURNISHED "AS IS."  THE AUTHORS, THE UNITED STATES GOVERNMENT,
C**  ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND AGENTS MAKE NO 
C**  WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS OF THE SOFTWARE
C**  AND DOCUMENTATION FOR ANY PURPOSE.  THEY ASSUME NO RESPONSIBILITY 
C**  (1) FOR THE USE OF THE SOFTWARE AND DOCUMENTATION; OR (2) TO 
C**  PROVIDE TECHNICAL SUPPORT TO USERS.
C**---------------------------------------------------------------------
