SUBROUTINE NEXT_WORD(UNIT_NUM, STRING_VALUE ) C---------------------------------------------------------------------- C- C- Purpose and Methods : Each call returns the next word in the file. C- This subroutine saves its variables for the line C- read in and current position within the line. C- Entry point INIT_NEXT_WORD must be called prior to C- the first call to NEXT_WORD C- C- Inputs : UNIT_NUM the IO unit number C- Outputs : STRING_VALUE the word read in C- C- Controls: NONE C- C- Created 18-MAY-1990 MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE C- C---------------------------------------------------------------------- IMPLICIT NONE C---------------------------------------------------------------------- C C Global definitions C INCLUDE 'LSMP$SOURCE:PARSE_TOKENS.PARAMS' INCLUDE 'LSMP$SOURCE:PARSE_TOKENS.INC' C C Procedure arguments C INTEGER UNIT_NUM CHARACTER*20 STRING_VALUE C C Local variables C INTEGER LENGTH ! length of word INTEGER COUNT ! loop index INTEGER IOSTAT ! IO error number CHARACTER*133 BUFFER ! the current line read in INTEGER LAST_POS ! the current position in the ! line C C LAST_POS and BUFFER must be saved across subroutine calls C LAST_POS must equal 134 on the first call so the first line gets C read in C SAVE LAST_POS, BUFFER C C if LAST_POS is equal to 134, a line needs to be read in first C IF (LAST_POS .EQ. 134) THEN CALL READ_LINE(UNIT_NUM, BUFFER) LAST_POS = 1 ENDIF C C check for end of line or comment C DO COUNT = LAST_POS, 133 IF (BUFFER(COUNT:COUNT) .EQ. '!') THEN STRING_VALUE = 'END_OF_LINE' LAST_POS = 134 GOTO 999 ENDIF IF (BUFFER(COUNT:COUNT) .NE. ' ') THEN LAST_POS = COUNT GOTO 15 ENDIF END DO C C have run out of spaces on the line C STRING_VALUE = 'END_OF_LINE' LAST_POS = 134 GOTO 999 C C Remaining string is not empty C 15 CONTINUE C C break into words C We know BUFFER(LAST_POS) is not a space C LENGTH = INDEX(BUFFER(LAST_POS:133), ' ') -1 IF (LENGTH .LE. 0) THEN LENGTH = 133 - LAST_POS + 1 ENDIF STRING_VALUE = BUFFER(LAST_POS:LAST_POS + LENGTH - 1) LAST_POS = LAST_POS + LENGTH C 999 RETURN C C C ENTRY INIT_NEXT_WORD() C---------------------------------------------------------------------- C- C- Purpose and Methods : C- C- Inputs : none C- Outputs : modifies LAST_POS so it has the proper value on the first call C- to NEXT_WORD C- Controls: none C- C- Created 5-JUL-1990 MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE C- C---------------------------------------------------------------------- LAST_POS = 134 C RETURN END