2005-06-09 05:30:34 +08:00
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
! Copyright (C) 2002-2020 Quantum ESPRESSO group
|
2005-06-09 05:30:34 +08:00
|
|
|
! This file is distributed under the terms of the
|
|
|
|
! GNU General Public License. See the file `License'
|
|
|
|
! in the root directory of the present distribution,
|
|
|
|
! or http://www.gnu.org/copyleft/gpl.txt .
|
|
|
|
!
|
|
|
|
!----------------------------------------------------------------------------
|
|
|
|
SUBROUTINE input_from_file( )
|
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
!! Check command-line arguments for -i[nput] "file name"
|
2018-02-07 21:09:37 +08:00
|
|
|
!! if "file name" is present, attach input unit 5 to the specified file
|
2020-08-10 04:30:49 +08:00
|
|
|
!! In parallel execution, must be called by a single processor
|
|
|
|
!
|
|
|
|
USE open_close_input_file, ONLY : get_file_name
|
2015-09-20 17:10:55 +08:00
|
|
|
!
|
2005-06-09 05:30:34 +08:00
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
2020-07-29 16:34:03 +08:00
|
|
|
INTEGER :: stdin = 5, stderr = 6, ierr = 0
|
|
|
|
CHARACTER(LEN = 256) :: input_file
|
2011-06-15 15:17:08 +08:00
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
input_file = get_file_name ( )
|
2013-01-21 05:02:07 +08:00
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
IF ( TRIM ( input_file ) /= ' ' ) THEN
|
2020-07-29 16:34:03 +08:00
|
|
|
!
|
|
|
|
OPEN ( UNIT = stdin, FILE = input_file, FORM = 'FORMATTED', &
|
|
|
|
STATUS = 'OLD', IOSTAT = ierr )
|
|
|
|
!
|
|
|
|
! do not call "errore" here: it may hang in parallel execution
|
|
|
|
! if this routine is called by a single processor
|
|
|
|
!
|
|
|
|
IF ( ierr > 0 ) WRITE (stderr, &
|
2020-08-10 04:30:49 +08:00
|
|
|
'(" *** Fatal error: input file ",A," not found ***")' ) TRIM( input_file )
|
2020-07-29 16:34:03 +08:00
|
|
|
!
|
2013-02-03 05:12:16 +08:00
|
|
|
ELSE
|
2020-07-29 16:34:03 +08:00
|
|
|
ierr = -1
|
|
|
|
ENDIF
|
2013-02-03 05:12:16 +08:00
|
|
|
!
|
|
|
|
END SUBROUTINE input_from_file
|
|
|
|
|
2005-06-22 18:08:02 +08:00
|
|
|
!----------------------------------------------------------------------------
|
2006-05-03 22:19:57 +08:00
|
|
|
!
|
2005-06-22 18:08:02 +08:00
|
|
|
SUBROUTINE get_file( input_file )
|
|
|
|
!
|
2018-02-07 21:09:37 +08:00
|
|
|
!! This subroutine reads, either from command line or from terminal,
|
2020-08-09 20:57:32 +08:00
|
|
|
!! the name of a file to be opened. To be used for serial codes only.
|
|
|
|
!! Expected syntax: "code [filename]" (one command-line option, or none)
|
2005-06-22 18:08:02 +08:00
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
USE open_close_input_file, ONLY : get_file_name
|
|
|
|
!
|
2005-06-22 18:08:02 +08:00
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
2018-02-07 21:09:37 +08:00
|
|
|
CHARACTER (LEN=*),INTENT(OUT) :: input_file
|
|
|
|
!! On output contains the path to the input file
|
2020-08-10 04:30:49 +08:00
|
|
|
INTEGER :: stdin = 5, stdout = 6, stderr = 6
|
|
|
|
LOGICAL :: exst
|
2005-06-22 18:08:02 +08:00
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
input_file = get_file_name ( )
|
2005-06-22 18:08:02 +08:00
|
|
|
!
|
2020-08-10 04:30:49 +08:00
|
|
|
IF ( TRIM ( input_file ) == ' ' ) THEN
|
2015-09-29 05:19:09 +08:00
|
|
|
10 WRITE(stdout,'(5x,"Input file > ")', advance="NO")
|
|
|
|
READ (stdin,'(a)', end = 20, err=20) input_file
|
2020-08-10 04:30:49 +08:00
|
|
|
IF ( TRIM(input_file) == ' ') GO TO 10
|
2005-06-22 18:08:02 +08:00
|
|
|
INQUIRE ( FILE = input_file, EXIST = exst )
|
2020-08-10 04:30:49 +08:00
|
|
|
IF ( .NOT. exst ) THEN
|
2015-09-29 05:19:09 +08:00
|
|
|
WRITE(stderr,'(A,": file not found")') TRIM(input_file)
|
2005-06-22 18:08:02 +08:00
|
|
|
GO TO 10
|
|
|
|
END IF
|
|
|
|
END IF
|
2005-06-22 21:56:55 +08:00
|
|
|
RETURN
|
2020-08-10 04:30:49 +08:00
|
|
|
20 WRITE(stdout,'("Fatal error reading file name ",A)') TRIM(input_file)
|
2005-06-22 18:08:02 +08:00
|
|
|
!
|
|
|
|
END SUBROUTINE get_file
|
2008-04-07 03:17:16 +08:00
|
|
|
|