!+ Subroutine to read a string of numbers and form a list.
!
! Method:
!	Straightforward.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date			Comment
!	1.0		12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77  with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      SUBROUTINE READ_LIST(IERR, STRING, LENGTH, N_LIST, I_LIST)
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_io.ucf'
      INCLUDE 'incl/error.pcf'
      INCLUDE 'incl/def_std_io.icf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      CHARACTER	!, INTENT(IN)
     &     STRING*73
!             STRING TO BE ANALYSED
      INTEGER	!, INTENT(IN)
     &     LENGTH
!             LENGTH OF STRING SUPPLIED
      INTEGER	!, INTENT(OUT)
     &     N_LIST
!             NUMBER OF ITEMS IN DECODED LIST
     &   , I_LIST(NPD_IO_LIST)
!             ELEMENTS OF I/O LIST
!
!     LOCAL VARIABLES.
      CHARACTER
     &     FORM_STRING*6
!             STRING TO BE USED FOR FORMATTED I/O ON AN INTERNAL FILE.
      INTEGER
     &     I_END(NPD_IO_LIST)
!             LOCATIONS OF ENDS OF STRINGS
     &   , IOS
!             I/O STATUS
     &   , I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
!
!
!     FIND THE ENDS OF THE NUMBERS IN THE LIST, AND HENCE
!     THE NUMBER OF ELEMENTS.
      N_LIST=0
      DO J=1, LENGTH-1
         IF ( (STRING(J:J).NE.' ').AND.(STRING(J+1:J+1).EQ.' ') ) THEN
            N_LIST=N_LIST+1
            I_END(N_LIST)=J
         ENDIF
      ENDDO
!     IF THE LINE DID NOT END WITH TRAILING SPACE THE LAST ENDING WILL
!     NOT HAVE BEEN FOUND.
      IF (STRING(LENGTH:LENGTH).NE.' ') THEN
         N_LIST=N_LIST+1
         I_END(N_LIST)=LENGTH
      ENDIF
!
!     COPY SUBSTRINGS INTO A CHARACTER ARRAY AND READ THEM.
      DO I=1, N_LIST
         DO J=1, 6
            FORM_STRING(J:J)=' '
         ENDDO
         J=6
         DO WHILE ( (J.GT.0).AND.
     &              ((I_END(I)+J-6).GT.0).AND.
     &              (STRING((I_END(I)+J-6):(I_END(I)+J-6)).NE.' ') )
            FORM_STRING(J:J)=STRING((I_END(I)+J-6):(I_END(I)+J-6))
            J=J-1
         ENDDO
         IF (J.EQ.0) THEN
            WRITE(IU_ERR, '(/A)') '*** INTERNAL ERROR IN SUBROUTINE '
     &         //'READ_LIST'
            WRITE(IU_ERR, '(A)')
     &         'A NUMBER CONTAINS MORE THAN SIX DIGITS.'
            IERR=I_ERR_IO
            RETURN
         ENDIF
         READ(FORM_STRING, '(I6)', IOSTAT=IOS) I_LIST(I)
         IF (IOS.NE.0) THEN
            IERR=I_ERR_IO
            RETURN
         ENDIF
      ENDDO
!
!
      RETURN
      END
