2005-06-09 05:30:34 +08:00
|
|
|
!
|
|
|
|
! Copyright (C) 2002-2005 PWSCF group
|
|
|
|
! 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 .
|
|
|
|
!
|
2006-10-03 22:29:27 +08:00
|
|
|
#if defined(__ABSOFT)
|
2006-10-11 22:42:42 +08:00
|
|
|
# define getenv getenv_
|
2006-10-03 22:29:27 +08:00
|
|
|
# define getarg getarg_
|
|
|
|
# define iargc iargc_
|
|
|
|
#endif
|
2005-06-09 05:30:34 +08:00
|
|
|
!
|
|
|
|
!----------------------------------------------------------------------------
|
|
|
|
SUBROUTINE input_from_file( )
|
|
|
|
!
|
2005-06-09 15:36:58 +08:00
|
|
|
! This subroutine checks program arguments and, if input file is present,
|
|
|
|
! attach input unit ( 5 ) to the specified file
|
2005-06-09 05:30:34 +08:00
|
|
|
!
|
|
|
|
!
|
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
|
|
|
INTEGER :: unit = 5, &
|
2005-06-09 15:36:58 +08:00
|
|
|
ilen, iiarg, nargs, ierr
|
2005-06-22 18:08:02 +08:00
|
|
|
! do not define iargc as external: g95 does not like it
|
|
|
|
INTEGER :: iargc
|
2005-06-09 05:30:34 +08:00
|
|
|
CHARACTER (LEN=80) :: input_file
|
|
|
|
!
|
|
|
|
! ... Input from file ?
|
|
|
|
!
|
|
|
|
nargs = iargc()
|
|
|
|
!
|
|
|
|
DO iiarg = 1, ( nargs - 1 )
|
|
|
|
!
|
|
|
|
CALL getarg( iiarg, input_file )
|
|
|
|
!
|
|
|
|
IF ( TRIM( input_file ) == '-input' .OR. &
|
|
|
|
TRIM( input_file ) == '-inp' .OR. &
|
|
|
|
TRIM( input_file ) == '-in' ) THEN
|
|
|
|
!
|
|
|
|
CALL getarg( ( iiarg + 1 ) , input_file )
|
|
|
|
!
|
|
|
|
OPEN ( UNIT = unit, FILE = input_file, FORM = 'FORMATTED', &
|
|
|
|
STATUS = 'OLD', IOSTAT = ierr )
|
|
|
|
!
|
2006-02-07 16:52:56 +08:00
|
|
|
! TODO: return error code instead
|
|
|
|
!CALL errore( 'input_from_file', 'input file ' // TRIM( input_file ) &
|
|
|
|
! & // ' not found' , ierr )
|
2005-06-09 05:30:34 +08:00
|
|
|
!
|
|
|
|
END IF
|
|
|
|
!
|
|
|
|
END DO
|
|
|
|
|
2005-06-09 15:36:58 +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 )
|
|
|
|
!
|
|
|
|
! This subroutine reads, either from command line or from terminal,
|
|
|
|
! the name of a file to be opened
|
2006-02-07 16:52:56 +08:00
|
|
|
! TODO: return error code if an error occurs
|
2005-06-22 18:08:02 +08:00
|
|
|
!
|
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
|
|
|
CHARACTER (LEN=*) :: input_file
|
|
|
|
!
|
|
|
|
CHARACTER (LEN=256) :: prgname
|
|
|
|
! do not define iargc as external: g95 does not like it
|
2005-06-22 21:56:55 +08:00
|
|
|
INTEGER :: nargs, iargc
|
2005-06-22 18:08:02 +08:00
|
|
|
LOGICAL :: exst
|
|
|
|
!
|
|
|
|
nargs = iargc()
|
|
|
|
CALL getarg (0,prgname)
|
|
|
|
!
|
|
|
|
IF ( nargs == 0 ) THEN
|
|
|
|
10 PRINT '("Input file > ",$)'
|
|
|
|
READ (5,'(a)', end = 20, err=20) input_file
|
|
|
|
IF ( input_file == ' ') GO TO 10
|
|
|
|
INQUIRE ( FILE = input_file, EXIST = exst )
|
|
|
|
IF ( .NOT. exst) THEN
|
|
|
|
PRINT '(A,": file not found")', TRIM(input_file)
|
|
|
|
GO TO 10
|
|
|
|
END IF
|
|
|
|
ELSE IF ( nargs == 1 ) then
|
|
|
|
CALL getarg (1,input_file)
|
|
|
|
ELSE
|
2006-02-07 16:52:56 +08:00
|
|
|
PRINT '(A,": too many arguments ",i4)', TRIM(prgname), nargs
|
2005-06-22 18:08:02 +08:00
|
|
|
END IF
|
2005-06-22 21:56:55 +08:00
|
|
|
RETURN
|
2006-02-07 16:52:56 +08:00
|
|
|
20 PRINT '(A,": reading file name ",A)', TRIM(prgname), TRIM(input_file)
|
2005-06-22 18:08:02 +08:00
|
|
|
!
|
|
|
|
END SUBROUTINE get_file
|
2006-05-03 22:19:57 +08:00
|
|
|
!
|
|
|
|
!----------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
SUBROUTINE get_arg_nimage( nimage )
|
|
|
|
!
|
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
|
|
|
INTEGER :: nimage
|
|
|
|
!
|
|
|
|
INTEGER :: nargs, iiarg
|
|
|
|
CHARACTER(LEN=10) :: np
|
|
|
|
INTEGER :: iargc
|
|
|
|
!
|
|
|
|
nimage = 1
|
|
|
|
nargs = iargc()
|
|
|
|
!
|
|
|
|
DO iiarg = 1, ( nargs - 1 )
|
|
|
|
!
|
|
|
|
CALL getarg( iiarg, np )
|
|
|
|
!
|
|
|
|
IF ( TRIM( np ) == '-nimage' .OR. TRIM( np ) == '-nimages' ) THEN
|
|
|
|
!
|
|
|
|
CALL getarg( ( iiarg + 1 ), np )
|
|
|
|
READ( np, * ) nimage
|
|
|
|
!
|
|
|
|
END IF
|
|
|
|
!
|
|
|
|
END DO
|
|
|
|
!
|
|
|
|
RETURN
|
|
|
|
END SUBROUTINE get_arg_nimage
|
|
|
|
!
|
|
|
|
!----------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
SUBROUTINE get_arg_ntg( ntask_groups )
|
|
|
|
!
|
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
|
|
|
INTEGER :: ntask_groups
|
|
|
|
!
|
|
|
|
INTEGER :: nargs, iiarg
|
|
|
|
CHARACTER(LEN=20) :: np
|
|
|
|
INTEGER :: iargc
|
|
|
|
!
|
|
|
|
ntask_groups = 1
|
|
|
|
nargs = iargc()
|
|
|
|
!
|
|
|
|
DO iiarg = 1, ( nargs - 1 )
|
|
|
|
!
|
|
|
|
CALL getarg( iiarg, np )
|
|
|
|
!
|
|
|
|
IF ( TRIM( np ) == '-ntg' .OR. TRIM( np ) == '-ntask_groups' ) THEN
|
|
|
|
!
|
|
|
|
CALL getarg( ( iiarg + 1 ), np )
|
|
|
|
READ( np, * ) ntask_groups
|
|
|
|
!
|
|
|
|
END IF
|
|
|
|
!
|
|
|
|
END DO
|
|
|
|
!
|
|
|
|
RETURN
|
|
|
|
END SUBROUTINE get_arg_ntg
|
|
|
|
|
2006-10-11 22:42:42 +08:00
|
|
|
SUBROUTINE get_env ( variable_name, variable_value )
|
|
|
|
!
|
|
|
|
! Wrapper for intrinsic getenv - all machine-dependent stuff here
|
|
|
|
!
|
|
|
|
CHARACTER (LEN=*) :: variable_name, variable_value
|
|
|
|
!
|
|
|
|
CALL getenv ( variable_name, variable_value)
|
|
|
|
!
|
|
|
|
END SUBROUTINE get_env
|