      SUBROUTINE VALGET (X, INTEG, IVAL)
      IMPLICIT NONE
C
C ***      READ A NUMERIC VALUE IN FREE FORMAT
C            X     IS RETURNED FLOATING POINT VERSION
C            INTEG IS RETURNED INTEGER VERSION
C            IVAL  IS A CONTROL CODE: 'F' = FLOATING POINT VALUE IS EXPECTED
C
      REAL X
      INTEGER INTEG
      CHARACTER*1 IVAL
C
      INCLUDE MATLAB$KOM:IOP.KOM
C
      CHARACTER*1 A(80), NULL
      INTEGER INTX(80), I, J, ICOUNT, ISTART, IFCOUN
      REAL FRAC, EX, BAS, FSIGN
C
      DATA NULL / Z'00' /
C
C
      DO 40 I = 1, 80
        A(I) = Z'20'
40    CONTINUE
C
C ***      CHECK IF THE CURRENT PLOT IS DONE
C           THIS IS MERELY THE MOST CONVENIENT PLACE TO DO IT
      CALL CHKEND
C
C ***      GET THE TERMINAL INPUT STRING
      CALL GETLAB (A)
C
C ***      TEST FOR A BLANK INPUT LINE
C           IF SO,  RETURN (DON'T CHANGE THE INPUT VALUE)
      DO 1 I = 1, 80
        IF (A(I).NE.' ') GOTO 2
1     CONTINUE
      GO TO 9999
C
C
2     CONTINUE
      INTEG = 0
      X = 0
C
C ***      TEST FOR LEADING BLANKS AND LOOK FOR A NEGATIVE SIGN
C      WRITE (WTE, 342) (A(I), I = 1, 80)
C342   FORMAT (1X, 80Z2)
      ICOUNT = 1
      ISIGN = 1
3     CONTINUE
      IF (A(ICOUNT).EQ.' ' .AND. ICOUNT.LE.80) THEN
        ICOUNT = ICOUNT + 1
C        WRITE (WTE, 657)
C657     FORMAT (' FOUND A LEADING BLANK')
        GOTO 3
      ENDIF
      IF (A(ICOUNT).EQ.'-') THEN
        ISIGN = -1
        ICOUNT = ICOUNT + 1
C        WRITE (WTE, 546) ICOUNT
C546     FORMAT (' FOUND A NEGATIVE SIGN', I2)
      ENDIF
      ISTART = ICOUNT
C
C ***      NOW RESOLVE THE INTEGER PORTION OF THE NUMBER.
C           STOP AT END OF STRING OR AT A DECIMAL POINT.
4     CONTINUE
      IF (A(ICOUNT).NE.'.' .AND. A(ICOUNT).NE.NULL .AND.
     .    ICOUNT.LE.80) THEN
        INTX(ICOUNT) = ICHAR(A(ICOUNT))-48
        ICOUNT = ICOUNT+1
        GOTO 4
      ENDIF
      ICOUNT = ICOUNT-1
C      WRITE (WTE, 7) ICOUNT
C7     FORMAT (' ICOUNT = ', I2)
      DO 5 J = ISTART, ICOUNT
        INTEG = INTEG+INTX(J) * 10**(ICOUNT-J)
5     CONTINUE
      INTEG = INTEG*ISIGN
C      WRITE (WTE, 10) INTEG
C10    FORMAT (1X, I6)
C
C ***      SEE IF THIS IS NUMBER HAS A FRACTIONAL PORTION.  IF SO, RESOLVE
C           ITS VALUE AND RETURN IT AS PART OF THE FLOATING POINT NUMBER.
      ICOUNT = ICOUNT+1
      FRAC = 0.0
      IF (IVAL.EQ.'F' .AND. A(ICOUNT).EQ.'.') THEN
        ICOUNT = ICOUNT+1
        IFCOUN = ICOUNT
20      CONTINUE
        IF (A(ICOUNT).NE.NULL .AND. ICOUNT.LE.80) THEN
          INTX(ICOUNT) = ICHAR(A(ICOUNT))-48
          ICOUNT = ICOUNT+1
          GOTO 20
        ENDIF
        ICOUNT = ICOUNT - 1
        DO 25 J = IFCOUN, ICOUNT
          EX = FLOAT(IFCOUN-J-1)
          BAS = FLOAT(INTX(J))
          FRAC = FRAC+ BAS * 10.** EX
25      CONTINUE
      ENDIF
      FSIGN = ISIGN
      FRAC = FRAC*FSIGN
      X = FLOAT(INTEG)+FRAC
C      WRITE (WTE, 30) X, FRAC
C30    FORMAT (' X = ', 2F10.4)
C
9999  CONTINUE
      RETURN
      END
