SUBROUTINE CMINTG(TOKEN,NCHARS, INTVAL,ISTAT) NOLINEUP C C CONVERT CHARACTER STRING TO INTEGER (SIGN OPTIONAL) C MODIFIED 1982-APR-20 -- JWB -- PROTECT AGAINST OVERFLOW C C INPUTS-- C . TOKEN() - TOKEN TO BE CONVERTED - CHAR*1(NCHARS) C . NCHARS - NUMBER OF CHARACTERS IN TOKEN C C OUTPUTS-- C . INTVAL - INTEGER VALUE CONVERTED FROM TOKEN C . ISTAT - RESULT CODE = 0 IF OK C . = 1 IF ILLEGAL CHARACTER C CHARACTER*1 TOKEN(1) INTEGER NCHARS, INTVAL, ISTAT CHARACTER*1 DIGIT(10), MINUS, PLUS INTEGER SIGN, MAXVAL C DATA DIGIT /'0','1','2','3','4','5','6','7','8','9'/ DATA MINUS /'-'/ , PLUS /'+'/ DATA MAXVAL / 200000000 / C SIGN = 1 ISTAT = 0 INTVAL = 0 ICHAR = 1 IF (NCHARS.GT.0) THEN IF (TOKEN(1).EQ.PLUS) ICHAR = 2 IF (TOKEN(1).EQ.MINUS) THEN ICHAR = 2 SIGN = -1 ENDIF C DO WHILE (ICHAR.LE.NCHARS .AND. ISTAT.EQ.0) INDEX = 0 DO FOR I=1,10 IF (TOKEN(ICHAR).EQ.DIGIT(I)) INDEX = I END FOR IF (INDEX.EQ.0) THEN ISTAT = 1 ELSE IF (INTVAL.LE.MAXVAL) THEN INTVAL = INTVAL*10 + (INDEX-1) ELSE INTVAL = 0 ENDIF ICHAR = ICHAR + 1 ENDIF END WHILE IF (INTVAL.NE.0) INTVAL = INTVAL*SIGN IF (ISTAT.NE.0) INTVAL = 0 ENDIF RETURN END