Commit abad420f authored by Nick R. Papior's avatar Nick R. Papior
Browse files

Fixed command line options for siesta

- The PEXSI branch introduced command line-options.
  However, that was also introduced in transiesta branch
  Now they are merged in a standard form.

- Updated manual to reflect these changes.

- Also fixed bug for piping AND using command line options
parent 16647190
......@@ -918,12 +918,17 @@ substitute spaces by \fdf*{:}.
\shell{siesta -L Hello}.
\option[-out|-o]%
Specify the output file (instead of printing to the terminal).
\shell{siesta -out RUN.out}.
\end{fdfoptions}
Additionally \tsiesta\ accepts these flags:
\begin{fdfoptions}
\option[-V]%
specify the bias for the current \tsiesta\ run
specify the bias for the current \tsiesta\ run.
\shell{transiesta -V 0.25:eV} or \shell{transiesta -V "0.25 eV"}
which sets the applied bias to $0.25\,\mathrm{eV}$.
......
......@@ -10,9 +10,18 @@
! Contains the short system label, used to generate file names
! slabel is currently set in reinit.
!
integer, parameter, public :: label_length = 60
integer, parameter, public :: label_length = 64
character(len=label_length), save, public :: slabel
! Standard files for output/input
! STDIN, the file that should be read fdf-options from
character(len=label_length), save, public :: stdin_file
! STDOUT, the file that is printed to.
! If ' ', then regular STDOUT is used
character(len=label_length), save, public :: stdout_file
! Derived type to hold some output file names
type, public:: filesOut_t
character(len=label_length+6)::
......
......@@ -24,6 +24,7 @@ C
use parallel, only : Node
use fdf
use files, only : slabel
use files, only : stdout_file, stdin_file
use siesta_master, only: input_file ! fdf data file
use sys, only : bye
......@@ -32,121 +33,145 @@ C
character(len=*), intent(out) :: sname
C Internal variables .................................................
character(len=50) filein, fileout
character(len=50) :: fileout
integer :: count, in, length, lun, lun_tmp, iostat
character :: slabel_default*59, sname_default*20
integer :: narg, count
integer :: in, length, lun, lun_tmp, iostat
character(len=256) :: line, val
logical debug_input, file_exists
C Print Welcome and Presentation .......................................
!
filein = "fdf_input"
! First we determine whether all output should be
! written to stdout or to a file.
if ( Node .eq. 0 ) then
stdout_file = cla_get_output()
if ( stdout_file /= ' ' ) then
close(unit=6)
open(unit=6,file=trim(stdout_file),form="formatted",
& position="rewind", action="write",status="unknown")
end if
end if
C Print Welcome and Presentation .......................................
! Default input-file
stdin_file = "fdf_input"
if (Node.eq.0) then
write(6,'(/a)')
write(6,'(/a)')
. ' *********************** '
write(6,'(a)')
write(6,'(a)')
. ' * WELCOME TO SIESTA * '
write(6,'(a)')
write(6,'(a)')
. ' *********************** '
! ..................
!
! Set name of file to read from. Done only
! in the master node.
!
! Set name of file to read from.
#ifndef NO_F2003
count = command_argument_count()
if ( count > 0 ) then
filein = ' '
call get_command_argument(count,filein,length)
inquire(file=filein,exist=debug_input)
if ( .not. debug_input ) count = 0
! The file-input name will default to be
! the last command line argument
narg = command_argument_count()
if ( narg > 0 ) then
stdin_file = ' '
call get_command_argument(narg,stdin_file,length)
inquire(file=stdin_file,exist=file_exists)
! Force reading from stdin
if ( .not. file_exists ) narg = 0
if ( stdin_file == stdout_file ) narg = 0
end if
#endif
c
c
c Choose proper file for fdf processing
c (INPUT_DEBUG if it exists or "standard input",
c processed and dumped to a temporary file)
c processed and dumped to a temporary file)
c
inquire(file='INPUT_DEBUG',exist=debug_input)
if (debug_input) then
write(6,'(a)') 'WARNING: ' //
$ 'Siesta is reading its input from file INPUT_DEBUG'
filein = 'INPUT_DEBUG'
inquire(file='INPUT_DEBUG',exist=debug_input)
if ( debug_input ) then
write(6,'(a)') 'WARNING: ' //
$ 'Siesta is reading its input from file INPUT_DEBUG'
stdin_file = 'INPUT_DEBUG'
#ifndef NO_F2003
else if ( count > 0 ) then
! Get file-name from input line
filein = ' '
call get_command_argument(count,filein,length)
if ( length > len(filein) ) then
call die ('The argument is too long to be retrieved, &
else if ( narg > 0 ) then
! Get file-name from input line
stdin_file = ' '
call get_command_argument(narg,stdin_file,length)
if ( length > len(stdin_file) ) then
call die ('The argument is too long to be retrieved, &
&please limit your-self to 50 characters for the input file')
end if
inquire(file=filein,exist=debug_input)
if ( .not. debug_input ) then
call die('Input file '//trim(filein)//' does not exist? &
end if
inquire(file=stdin_file, exist=file_exists)
if ( .not. file_exists ) then
call die('Input file '//trim(stdin_file)//' does not exist? &
&Have you specified the wrong file-name?')
end if
end if
write(*,'(/,2a)') 'reinit: Reading from ',trim(filein)
write(*,'(/,2a)') 'reinit: Reading from ',trim(stdin_file)
#endif
else
if (input_file/=' ') then ! Read data from given file
write(6,'(a)') 'reinit: Reading from '//trim(input_file)
call io_assign(lun)
open(lun,file=input_file,form='formatted',status='old')
rewind(lun)
else ! Read from standard input
write(6,'(/a)') 'reinit: Reading from standard input'
lun = 5
end if ! (input_file/=' ')
call io_assign(lun_tmp)
do ! make sure we get a new file
call system_clock( count )
write(filein,"(a,i5.5)") 'INPUT_TMP.', mod(count,100000)
inquire( file=filein, exist=file_exists )
if (.not.file_exists) exit
end do
!
open(lun_tmp,file=filein,
$ form='formatted',status='replace')
rewind(lun_tmp)
write(6,"(a,23('*'),a,28('*'))")
. '***', ' Dump of input data file '
c
do
read(lun,iostat=iostat,fmt='(a)') line
if (iostat /= 0 ) exit
length = len_trim(line)
if (length /= 0) then
write(6,'(a)') line(1:length)
if (.not. debug_input) then
write(lun_tmp,'(a)') line(1:length)
endif
endif
enddo
write(6,"(a,23('*'),a,29('*'))")
. '***', ' End of input data file '
call io_close(lun_tmp)
else
! This is reading from std-in (or SIESTA-master)
if ( input_file/=' ' ) then
! Read data from given file
! This is the case for running siesta under SIESTA-master
write(6,'(a)') 'reinit: Reading from '//trim(input_file)
call io_assign(lun)
open(lun,file=input_file,form='formatted',status='old')
rewind(lun)
else ! Read from standard input
write(6,'(/a)') 'reinit: Reading from standard input'
lun = 5
end if ! (input_file/=' ')
! make sure we get a new file
call io_assign(lun_tmp)
file_exists = .true.
do while ( file_exists )
call system_clock( count )
write(stdin_file,"(a,i5.5)") 'INPUT_TMP.', mod(count,100000)
inquire(file=stdin_file, exist=file_exists )
end do
! Open the input-file to dump the input data
open(lun_tmp,file=stdin_file,
& form='formatted',status='replace')
rewind(lun_tmp)
write(6,'(a)') 'reinit: Dumped input in '//trim(stdin_file)
write(6,"(a,23('*'),a,28('*'))")
& '***', ' Dump of input data file '
c
! "filein" for fdf is now the temporary file.
! This was necessary historically to allow
! the rewinds involved in fdf operation.
!
endif
endif
c ...
do
read(lun,iostat=iostat,fmt='(a)') line
if ( iostat /= 0 ) exit
length = len_trim(line)
! Truncate empty lines
if ( length /= 0 ) then
write(6,'(a)') line(1:length)
if (.not. debug_input) then
write(lun_tmp,'(a)') line(1:length)
end if
end if
end do
write(6,"(a,23('*'),a,29('*'))")
& '***', ' End of input data file '
call io_close(lun_tmp)
! "stdin_file" for fdf is now the temporary file.
! This was necessary historically to allow
! the rewinds involved in fdf operation.
!
end if ! Decide how the input-file should be read
end if ! Node .eq. 0
C Set up fdf ...
!
! Choose a 'unique' prefix for the log (and possible debug) fdf files
......@@ -156,14 +181,15 @@ C Set up fdf ...
call system_clock( count )
write(fileout,"(a,i5.5,a)") 'fdf-', mod(count,100000), ".log"
call fdf_init(filein,trim(fileout))
call fdf_init(stdin_file, trim(fileout))
#ifndef NO_F2003
! Read special variables from the command line
count = command_argument_count()
if ( count > 0 ) then
! Read special variables from the command line
! This is done by ALL nodes!
narg = command_argument_count()
if ( narg > 0 ) then
in = 0
do while ( in <= count - 1 )
do while ( in <= narg - 1 )
in = in + 1
call get_command_argument(in,line,length)
......@@ -171,13 +197,14 @@ C Set up fdf ...
! If it is not an option, skip it
if ( line(1:1) /= '-' ) cycle
! Truncate '-' to no '-'
do while ( line(1:1) == '-' )
line = line(2:)
end do
! We allow these line
if ( line(1:3) == 'fdf' ) then
if ( in >= count - 1 )
if ( in >= narg )
& call die('Missing argument on command line')
in = in + 1
call get_command_argument(in,line,length)
......@@ -186,40 +213,46 @@ C Set up fdf ...
! FDFLabel=0.1:eV
! FDFLabel:0.1:eV
! FDFLabel=0.1=eV
! "FDFLabel 0.1 eV"
line = cmd_tokenize(line)
call fdf_overwrite(line)
#ifdef TRANSIESTA
else if ( line(1:1) == 'V' ) then
if ( in >= count - 1 )
else if ( line(1:1) == 'L' ) then
if ( in >= narg )
& call die('Missing argument on command line')
in = in + 1
call get_command_argument(in,line,length)
line = cmd_tokenize(line)
line = 'TS.Voltage '//trim(line)
line = 'SystemLabel '//trim(line)
call fdf_overwrite(line)
#endif
else if ( line(1:1) == 'L' ) then
if ( in >= count - 1 )
#ifdef TRANSIESTA
else if ( line(1:1) == 'V' ) then
if ( in >= narg )
& call die('Missing argument on command line')
in = in + 1
call get_command_argument(in,line,length)
line = cmd_tokenize(line)
line = 'SystemLabel '//trim(line)
line = 'TS.Voltage '//trim(line)
call fdf_overwrite(line)
else if ( line(1:4) == 'help' .or. line(1:1) == 'h' ) then
write(*,'(a)')'Help for calling the tight-binding transport code'
write(*,'(a)')' -fdf <label>=<value>[:<unit>]'
write(*,'(a)')' Set the label to the corresponding value.'
#endif
else if ( line(1:4) == 'help' .or.
& line(1:1) == 'h' ) then
write(0,'(a)')'Help for calling SIESTA'
write(0,'(a)')''
write(0,'(a)')' -out|-o <file>'
write(0,'(a)')' Instead of writing to stdout, write to file.'
write(0,'(a)')' -L <name>'
write(0,'(a)')' Short-hand for setting SystemLabel.'
write(0,'(a)')' -fdf <label>=<value>[:<unit>]'
write(0,'(a)')' Set the label to the corresponding value.'
#ifdef TRANSIESTA
write(*,'(a)')' -V <value>:<unit>'
write(*,'(a)')' Short-hand for setting TS.Voltage.'
write(0,'(a)')' -V <value>:<unit>'
write(0,'(a)')' Short-hand for setting TS.Voltage.'
#endif
write(*,'(a)')' -L <name>'
write(*,'(a)')' Short-hand for setting SystemLabel.'
write(*,'(a)')' <fdf-file>'
write(*,'(a)')
write(0,'(a)')' <fdf-file>'
write(0,'(a)')
& ' Use file as fdf-input, you need not to pipe it in.'
call bye('Help-menu requested, stopping')
end if
......@@ -230,8 +263,7 @@ C Set up fdf ...
C Define Name of the system ...
sname_default = ' '
sname = fdf_string('SystemName',sname_default)
sname = fdf_string('SystemName',' ')
if (Node.eq.0) then
write(6,'(/a,71("-"))') 'reinit: '
write(6,'(a,a)') 'reinit: System Name: ',trim(sname)
......@@ -240,10 +272,9 @@ C Define Name of the system ...
C ...
C Define System Label (short name to label files) ...
slabel_default = 'siesta'
slabel = fdf_string('SystemLabel',slabel_default)
slabel = fdf_string('SystemLabel','siesta')
if (Node.eq.0) then
write(6,'(a,a)') 'reinit: System Label: ',slabel
write(6,'(a,a)') 'reinit: System Label: ',trim(slabel)
write(6,'(a,71("-"))') 'reinit: '
endif
C ...
......@@ -264,4 +295,44 @@ C ...
end if
end do
end function cmd_tokenize
function cla_get_output() result(outfile)
integer :: narg, in, length
character(len=128) :: line
character(len=128) :: outfile
outfile = ' '
#ifndef NO_F2003
! Read the output file from the command line (-out|-o)
narg = command_argument_count()
if ( narg > 0 ) then
in = 0
do while ( in <= narg - 1 )
in = in + 1
call get_command_argument(in,line,length)
! If it is not an option, skip it
if ( line(1:1) /= '-' ) cycle
! Truncate '-' to no '-'
do while ( line(1:1) == '-' )
line = line(2:)
end do
! We allow these line
if ( line(1:1) == 'o'.or.line(1:3) == 'out') then
if ( in >= narg )
& call die('Missing argument for output file')
in = in + 1
call get_command_argument(in,outfile,length)
end if
end do
end if
#endif
end function
end
......@@ -110,10 +110,6 @@
integer :: npSIESTA
external :: read_options
character(len=256) :: output_file
logical :: use_explicit_output_file
!---------------------------------------------------------------------- BEGIN
! Initialise MPI unless siesta is running as a subroutine
! of a driver program that may have initialized MPI already
......@@ -140,17 +136,9 @@ C Initialise MPI and set processor number
call MPI_Comm_Rank( MPI_Comm_World, Node, MPIerror )
call MPI_Comm_Size( MPI_Comm_World, Nodes, MPIerror )
! Keeper for PEXSI-runs..
PEXSINodes = Nodes
if (Node == 0) then
call get_command_line_options()
if (use_explicit_output_file) then
close(unit=6)
open(unit=6,file=trim(output_file),form="formatted",
$ position="rewind",
$ action="write",status="unknown")
endif
endif
if (.not. fdf_parallel()) then
call die('siesta_init: ERROR: FDF module ' //
......@@ -166,7 +154,7 @@ C Initialise MPI and set processor number
call setDebugOutputUnit()
#endif /* DEBUG_XC */
! Initialise read .................................................
! Initialise input/output...........................................
call reinit( sname )
#ifdef MPI
......@@ -618,41 +606,6 @@ C Initialise MPI and set processor number
call timer( 'Setup', 2 )
!--------------------------------------------------------------------------- END
CONTAINS
subroutine get_command_line_options()
use m_getopts
use f2kcli
character(len=200) :: opt_arg
character(len=10) :: opt_name
integer :: nargs, iostat, n_opts, nlabels
! Process options
!
use_explicit_output_file = .false.
n_opts = 0
do
call getopts('dho:',
$ opt_name,opt_arg,n_opts,iostat)
if (iostat /= 0) exit
select case(opt_name)
case ('d')
! debug = .true.
case ('o')
use_explicit_output_file = .true.
output_file = trim(opt_arg)
case ('h')
!call manual()
case ('?',':')
write(0,*) "Invalid option: ", opt_name(1:1)
write(0,*) "Usage: siesta [ -o output_file ]"
!write(0,*) "Use -h option for manual"
call die()
end select
enddo
end subroutine get_command_line_options
END subroutine siesta_init
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment