Subroutine ReadInputMain(cFilename, tOverride_input, kp)
use SystemData, only: tMolpro
use System, only: SysReadInput, SetSysDefaults
use Calc, only: CalcReadInput, SetCalcDefaults
use CalcData, only: tKP_FCIQMC, tUseProcsAsNodes
use kp_fciqmc_data_mod, only: kp_fciqmc_data
use kp_fciqmc_init, only: kp_fciqmc_read_inp
use Integrals_neci, only: IntReadInput, SetIntDefaults
Use Logging, only: LogReadInput, SetLogDefaults
use Parallel_neci, only: iProcIndex
use default_sets
use util_mod, only: get_free_unit
use real_time_read_input_module, only: real_time_read_input
!#ifdef NAGF95
! ! USe doesn't get picked up by the make scripts
! USe f90_unix_env, ONLY: getarg,iargc
!#endif
Implicit none
!#ifndef NAGF95
! Integer :: iargc
!#endif
! INPUT/OUTPUT params
character(*), parameter :: this_routine = 'ReadInputMain'
Character(len=*) cFilename !Input filename or "" if we check arg list or stdin
Character(len=255) cInp !temp storage for command line params
Character(len=32) cTitle
! Predeclared
Character(len=100) w, x !strings for input storage
Logical tEof !set when read_line runs out of lines
logical tExists !test for existence of input file.
Integer idDef !What default set do we use
integer neci_iargc
logical, intent(in) :: tOverride_input !If running through molpro, is this an override input?
integer, allocatable :: tmparr(:)
type(kp_fciqmc_data), intent(inout) :: kp
integer, parameter :: id_scratch_file = 7
class(FileReader_t), allocatable :: file_reader
type(TokenIterator_t) :: tokens
cTitle = ""
idDef = idDefault !use the Default defaults (pre feb08)
If (trim(adjustl(cFilename)) /= '') Then
file_reader = ManagingFileReader_t(trim(adjustl(cFilename)))
else if (neci_iArgC() > 0) then
! We have some arguments we can process instead
#ifdef BLUEGENE_HACKS
call neci_GetArg(neci_iArgC(), cInp)
#else
Call neci_GetArg(1, cInp) !Read argument 1 into inp
#endif
write(stdout, *) "Processing arguments", cinp
write(stdout, *) "Reading from file: ", Trim(cInp)
file_reader = ManagingFileReader_t(trim(adjustl(cInp)))
Else
write(stdout, *) "Reading from STDIN"
! Save the input to a temporary file so we can scan for the
! defaults option and then re-read it for all other options.
open(id_scratch_file, status='scratch')
file_reader = AttachedFileReader_t(file_id=stdin, echo_lines=id_scratch_file)
end if
Do while (file_reader%nextline(tokens, skip_empty=.true.))
w = to_upper(tokens%next())
Select case (w)
Case ("DEFAULTS")
x = to_upper(tokens%next())
select case (x)
!Add default options here
case ("DEFAULT")
idDef = idDefault
case ("FEB08")
idDef = idFeb08
case ("NOV11")
idDef = idNov11
case default
write(stdout, *) "No defaults selected - using 'default' defaults"
idDef = idDefault
end select
case ("END")
exit
end select
End Do
select case (idDef)
case (0)
write(stdout, *) 'Using the default set of defaults.'
case (idFeb08)
Feb08 = .true.
write(stdout, *) 'Using the Feb08 set of defaults.'
case (idNov11)
Nov11 = .true.
write(stdout, *) 'Using the November 2011 set of defaults'
end select
! Set up defaults.
call SetSysDefaults
call SetCalcDefaults
call SetIntDefaults
call SetLogDefaults
! Now return to the beginning and process the whole input file
select type(file_reader)
type is (AttachedFileReader_t)
file_reader = AttachedFileReader_t(file_id=id_scratch_file)
end select
call file_reader%rewind()
!Molpro writes out its own input file
if (.not. tMolpro .or. tOverride_input) then
if (iProcIndex == 0) then
call file_reader%set_echo_lines(stdout)
else
call file_reader%set_echo_lines()
end if
write(stdout, '(/,64("*"),/)')
end if
Do while (file_reader%nextline(tokens, skip_empty=.true.))
w = to_upper(tokens%next())
select case (w)
case ("TITLE")
do while (tokens%remaining_items() > 0)
w = tokens%next()
cTitle = trim(cTitle)//" "//trim(w)
end do
case ("DEFAULTS")
CONTINUE
case ("SYSTEM")
call SysReadInput(file_reader, tokens)
case ("CALC")
call CalcReadInput(file_reader)
case ("INTEGRAL")
call IntReadInput(file_reader)
case ("LOGGING")
call LogReadInput(file_reader)
case ("KP-FCIQMC")
tKP_FCIQMC = .true.
tUseProcsAsNodes = .true.
call kp_fciqmc_read_inp(file_reader, kp)
case ("REALTIME")
call real_time_read_input(file_reader)
case ("END")
exit
case default
call stop_all(this_routine, "Keyword "//trim(w)//" not recognized")
end select
end do
write(stdout, '(/,64("*"),/)')
call file_reader%close()
call sanitize_input()
RETURN
END SUBROUTINE ReadInputMain