-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcmdline.F90
126 lines (116 loc) · 4.78 KB
/
cmdline.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
module mod_cmdline
use mod_interfaces, only: print_compile_info
implicit none
private
public :: get_cmdline
contains
subroutine print_help()
integer, dimension(8) :: time_data
call date_and_time(values=time_data)
print '(a)', ''
print '(a)', 'ABIN: Multipurpose ab initio MD program.'
print '(a)', ''
call print_compile_info()
print '(a)', ''
print '(a)', 'cmdline options:'
print '(a)', ''
print '(a)', ' -h, --help print help and exit'
print '(a)', ' -V, --version print version and compiler options'
print '(a)', ' -i <input_parameters> default: input.in'
print '(a)', ' -x <input_coordinates> default: mini.dat'
print '(a)', ' -v <input_velocities> no default'
print '(a)', ''
end subroutine print_help
subroutine get_cmdline(chinput, chcoords, chveloc, &
& tc_server_name, tcpb_input_file, tcpb_host, tcpb_port)
use mod_error, only: fatal_error
use mod_utils, only: file_exists_or_exit
character(len=*), intent(inout) :: chinput, chcoords, chveloc
character(len=*), intent(inout) :: tc_server_name ! TeraChem MPI interface
character(len=*), intent(inout) :: tcpb_input_file ! TeraChem protobuf interface
character(len=*), intent(inout) :: tcpb_host
integer, intent(inout) :: tcpb_port
character(len=len(chinput)) :: arg
integer :: i
i = 0
do while (i < command_argument_count())
i = i + 1
call get_command_argument(i, arg)
select case (arg)
case ('-h', '--help')
call print_help()
stop 0
case ('-V', '--version')
call print_compile_info()
stop 0
case ('-i')
i = i + 1
call get_command_argument(i, arg)
! Format specifier is needed here in case of filenames with slashes/dashes
read (arg, '(A)') chinput
if (trim(chinput) == '') then
call fatal_error(__FILE__, __LINE__, &
& 'Empty -i argument. Provide filename with input parameters')
end if
case ('-x')
i = i + 1
call get_command_argument(i, arg)
read (arg, '(A)') chcoords
if (trim(chcoords) == '') then
call fatal_error(__FILE__, __LINE__, &
& 'Empty -x argument. Provide filename with coordinates')
end if
case ('-v')
i = i + 1
call get_command_argument(i, arg)
read (arg, '(A)') chveloc
if (trim(chveloc) == '') then
call fatal_error(__FILE__, __LINE__, &
& 'Empty -v argument. Provide filename with velocities')
end if
case ('-M')
i = i + 1
call get_command_argument(i, arg)
read (arg, '(A)') tc_server_name
if (trim(tc_server_name) == '') then
call fatal_error(__FILE__, __LINE__, &
& 'Empty -M argument. Provide name of the TeraChem MPI server')
end if
case ('--tcpb-input-file')
i = i + 1
call get_command_argument(i, arg)
read (arg, '(A)') tcpb_input_file
if (trim(tcpb_input_file) == '') then
call fatal_error(__FILE__, __LINE__, &
& 'Empty --tcpb-input-file argument. Provide name of the TeraChem input file')
end if
case ('--tcpb-host')
i = i + 1
call get_command_argument(i, arg)
read (arg, '(A)') tcpb_host
if (trim(tcpb_host) == '') then
call fatal_error(__FILE__, __LINE__, &
& 'Empty --tcpb-host argument. Provide hostname of the TeraChem TCPB server')
end if
case ('--tcpb-port')
i = i + 1
call get_command_argument(i, arg)
! NOTE: If the port number is too large, this will trim it!
! This is okay since in the launch script we determine port number automatically anyway.
read (arg, '(I5)') tcpb_port
! NOTE: When the parameter is missing, at least GCC compilers assign 0 as default
if (tcpb_port == 0) then
call fatal_error(__FILE__, __LINE__, &
& 'Empty --tcpb-port argument. Provide port of the TeraChem TCPB server')
end if
case default
call print_help()
call fatal_error(__FILE__, __LINE__, &
& 'Invalid command line argument "'//trim(arg)//'"')
end select
end do
call file_exists_or_exit(chinput)
! Input velocities and coordinates are checked in init,
! because of REMD
end subroutine get_cmdline
end module mod_cmdline