!+ Subroutine to open a SAMSON-file for input
!
! 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 OPEN_SAMSON_IN(IERR, IUNIT, FILE_IN, L_WARN)
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY VARIABLES
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      LOGICAL	!, INTENT(IN)
     &     L_WARN
!             IF TRUE PRINT WARNING MESSAGE
      INTEGER	!, INTENT(OUT)
     &     IUNIT
!             ERROR FLAG
      CHARACTER	!, INTENT(IN)
     &     FILE_IN*(*)
!             NAME OF INPUT FILE
!
!     LOCAL VARIABLES
      LOGICAL
     &     L_EXIST
!             EXISTENCE FLAG FOR FILE
      INTEGER
     &     IOS
!             READING ERROR FLAG
     &   , LENGTH
!             LENGTH OF INPUT FILE
!
!     FUNCTIONS CALLED:
      INTEGER
     &     NAME_LENGTH
!             FUNCTION TO FIND LENGTH OF NAME
!
!
!     FIND LENGTH OF FILE NAME.
      LENGTH=NAME_LENGTH(FILE_IN)
!     CHECK FOR THE EXISTENCE OF THE FILE.
      INQUIRE(FILE=FILE_IN(1: LENGTH), EXIST=L_EXIST)
      IF (.NOT.L_EXIST) THEN
!        WE RETURN THE MISSING DATA FLAG, BUT THIS ERROR MAY NOT BE FATAL.
         IF (L_WARN) THEN
            WRITE(IU_ERR, '(A, /, A, /, A)')
     &         '***WARNING: THE FILE ', FILE_IN(1:LENGTH)
     &         , ' DOES NOT EXIST.'
         ENDIF
         IERR=I_MISSING_DATA
         RETURN
      ENDIF
!
!     NOW OPEN THE FILE.
      OPEN(UNIT=IUNIT, FILE=FILE_IN(1: LENGTH), IOSTAT=IOS
     &   , STATUS='OLD')
      IF (IOS.NE.0) THEN
         WRITE(IU_ERR, '(/, 3A)')
     &      '*** ERROR: FILE ', FILE_IN(1: LENGTH)
     &      , 'COULD NOT BE OPENED.'
         IERR=I_ERR_IO
         RETURN
      ENDIF
!
!
      RETURN
      END
