subroutine aptffip (ius, fd, iamax, idmax, iemax, aword, iword,
     &                    fword, mtype, lword, nword, achar, nerr)

ccbeg.
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c                             SUBROUTINE APTFFIP
c
c     call aptffip (ius, fd, iamax, idmax, iemax, aword, iword,
c    &              fword, mtype, lword, nword, achar, nerr)
c
c     Version:  aptffip  Updated    1993 February 18 15:20.
c               aptffip  Originated 1993 February 16 14:00.
c
c     Author:   Arthur L. Edwards, LLNL, L-298, Telephone (925) 422-4123.
c
c
c     Purpose:  To read a free field input line from I/O unit ius in format
c               (80a1), store the ASCII result in achar, then crack the input
c               line into fields separated by the delimiter fd, storing the
c               results into aword, iword and fword according to the field type
c               mtype, and also return the length of each field, lword, the
c               number of fields, nword, and a result flag nerr.
c               Character array aword has words of length iamax.
c               The maximum number of digits in an integer, and the maximum
c               magnitude of floating point exponents are specified by idmax
c               and iemax, to allow use on computers with different word sizes.
c
c     Input:    ius, fd, iamax, idmax, iemax.
c
c     Output:   aword, iword, fword, mtype, lword, nword, achar, nerr.
c
c     Calls: aptchap 
c
c     Glossary:
c
c     achar     Output   A character*1 array of 80 characters, the uncracked
c                          input line.
c
c     aword     Output   A character*iamax array of input line fields.  Size 40.
c                          Initialized to blank characters.  If the n'th data
c                          field translated is a character field (mtype = 0,
c                          1 or 4), it will be stored in the leftmost characters
c                          of aword(n), and right-filled with blank characters,
c                          as necessary.  The number of characters preceding the
c                          first blank is lword.
c
c     fd        Input    A type character*1 field delimiter.
c
c     fword     Output   A floating-point array, size 40.
c                          Initialized to zero.
c                          The maximum allowable exponent is iemax.
c                          If the data field is translated into an integer
c                          (mtype = 2) or into a floating-point number
c                          (mtype = 3), its floating-point value will be
c                          returned in fword.  If the field is formatted as an
c                          integer, but contains more than idmax digits after
c                          any leading zeros, it will be translated into a
c                          floating-point number, and returned in fword.
c                          The data field may have leading or trailing
c                          blanks.  The first non-blank character may be a "+"
c                          or "-".  The mantissa may contain any number of
c                          digits, but no more than one decimal point, and
c                          may have trailing blanks.  If an exponent is given,
c                          it must begin with "e", "E", "d", "D", "+" or "-".
c                          An initial "e", "E", "d" or "D" may be followed by
c                          a "+" or "-".  The digits of the exponent may have
c                          leading and trailing blanks, but no additional
c                          characters following any trailing blanks.
c                          Note:  do not equivalence iword to fword.
c                          Note:  the largest floating-point value possible on
c                          the Cray is approximately 1.e+2465.
c
c     iamax     Input    The length of words in character array aword.
c
c     idmax     Input    Maximum number of digits in an integer.  Depends on
c                          the machine.  At least 13 on a Cray.
c
c     iemax     Input    Maximum size (positive or negative) of the exponent
c                          of a floating-point number.  Depends on the machine.
c                          Approximately 2465 on a Cray.
c
c     ius       Input    Input file I/O unit, for reading next input line.
c
c     iword     Output   An integer array, size 40.  Initialized to zero.
c                          If the n'th data field translated is
c                          an integer (mtype = 2), its integer value will be
c                          stored in iword(n), and its floating-point value
c                          stored in fword(n).  The maximum number of digits
c                          is idmax.  The data field may have leading or
c                          trailing blanks.  The first non-blank character may
c                          be a "+" or "-".  All other characters must be
c                          digits, with no more than idmax digits following any
c                          leading zeros.
c                          Note:  the largest integer possible on the Cray
c                          is 2**46 - 1 = 7.03687e+13.
c                          Note:  do not equivalence iword to fword.
c
c     lword     Output   An integer array, size 40.  The number of characters
c                          preceding the first blank, in each output word aword.
c
c     mtype     Output   An integer array, size 40.  The first nword values
c                          indicate the data types of the data fields
c                          translated from the character string achar:
c                          0:  Not recognizable as an integer or floating-point
c                              number, and longer than iamax characters
c                              (nerr = 0), or a floating-point number whose
c                              exponent exceeds the limit iemax (nerr = 5).
c                              Returned in aword.
c                              Also, blank fields after last non-blank field.
c                          1:  Not recognizable as an integer or floating-point
c                              number.  Field has 1 to iamax characters.
c                              Returned in aword, left-adjusted, right-filled
c                              with blanks, as necessary.
c                          2:  Data field translated into integer mode.
c                              The integer value is returned in iword, and the
c                              floating-point value is returned in fword.
c                              Also returned in aword, as for mtype = 0 or 1.
c                          3:  Data field translated into floating-point
c                              mode, and returned in fword.  The integer value
c                              can not be stored in iword, because of the
c                              possibility of overflow of numbers with large
c                              exponents.  If nerr = 4, the data field was
c                              an integer with more than idmax digits.
c                              Also returned in aword, as for mtype = 1.
c
c     nerr      Output   Result sentinal.  0 if input line was cracked.
c                          Otherwise, the last error found by aptchap:
c                         -1 if an end of file was reached in the input file.
c                          4 if an integer exceeds idmax characters (in any
c                            field).  If so, a floating-point result is returned
c                            in fword, with mtype = 3.
c                          5 if a floating-point exponent exceeds iemax (in any
c                            field).  If so, a character string is returned in
c                            aword, with mtype = 0.
c                         10 if the system could not read the input line.
c
c     nword     Output   The number of data fields found in achar.
c                          Zero if input line was blank.
c
c     Example:  Following is an example of a valid input line, and how it would
c               be cracked and typed by aptffip, when iamax = 8.
c               Input:  abc charstringxxx 10 1.0e+01 6 7.12
c
c               nword = 6
c               word  aword      iword   fword   mtype                lword
c                 1   abc        0       0.0       1  ASCII             3
c                 2   charstring 0       0.0       1  ASCII             9
c                 3   10         10      10.0      2  integer           2
c                 4   1.0e+01    0       10.0      3  floating-point    7
c                 5   6          6       6.0       2  integer           1
c                 6   7.12       0       7.12      3  floating-point    4
c
c     Changes:
c
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccend.

c.... Dimensioned arguments.

c---- Input line uncracked ASCII words.
      dimension achar   (1)
      character*1 achar

c---- Cracked fields.  ASCII (mtype = 0, 1).
      dimension aword   (1)
      character*(*) aword

c---- Cracked fields.  Real (mtype = 2, 3).
      dimension fword   (1)

c---- Cracked fields.  Integer (mtype = 2).
      dimension iword   (1)

c---- Number of characters in input fields.
      dimension lword   (1)

c---- Cracked field types (0, 1, 2 or 3).
      dimension mtype   (1)

c---- Scalar arguments.

c---- Field delimiter.
      character*1 fd

c.... Local variables.

c---- Index in several arrays.
      common /laptffip/ i

c---- Max # of characters to translate.
      common /laptffip/ nchar

c---- Max # of fields to translate.
      common /laptffip/ nwordm

c.... Initialize.

      nchar  = 80                     ! Max # of characters to translate.
      nwordm = 40                     ! Max # of fields to translate.

c---- Result sentinal.
      nerr = 0
cbugc***DEBUG begins.
cbug 9801 format (/ 'aptffip parsing an input line.  ius=',i3 /
cbug     &  '  iamax=',i3,'  idmax=',i3,'  iemax=',i5)
cbug      write (3, 9801) ius, iamax, idmax, iemax
cbugc***DEBUG ends.

      do 110 i = 1, nwordm
        aword(i) = ' '
        iword(i) = 0
        fword(i) = 0.0
        mtype(i) = 0
        lword(i) = 0
  110 continue
cbugc***DEBUG begins.
cbug 9802 format (/ 'aptffip initial aword is' / ('"',a,'"'))
cbug      write (3, 9802) aword(1)
cbugc***DEBUG ends.

c.... Read a line from the input disk file.

  800 format (80a1)

c++++ Read input line.
      read (unit=ius, fmt=800, err=120, end=130)
     &  (achar(i), i = 1, 80)

c.... Crack space delimited fields to ASCII, integer and floating-point.

      call aptchap (achar, 1, nchar, nwordm, fd, iamax, idmax, iemax,
     &              aword, iword, fword, mtype, lword, nword, nerr)

      go to 210

c---- System can not read input line.
  120 nerr = 10
      go to 210

c---- Found end of file.
  130 nerr = -1

  210 return

c.... End of subroutine aptffip.      (+ 1 line).
      end

UCRL-WEB-209832