Octopus
command_line.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21! ---------------------------------------------------------
22!
34!
35! ---------------------------------------------------------
37
38
60
61#ifdef FC_COMMAND_LINE_MODULE
62 use fc_command_line_module
63#endif
64 use string_oct_m
65 use iso_c_binding
66
67 implicit none
68
69#ifdef FC_COMMAND_LINE_INCLUDE
70 include fc_command_line_include
71#endif
72
73 private
74 public :: &
76 getopt_end, &
87#if FC_COMMAND_LINE_ARGUMENTS != 2003
88 public :: &
91#endif
92
93
94 ! ---------------------------------------------------------
95 ! First, the public interfaces.
96
97
103 interface
104 subroutine getopt_casida_spectrum
105 implicit none
106 end subroutine getopt_casida_spectrum
107
108 subroutine getopt_center_geom
109 implicit none
110 end subroutine getopt_center_geom
111
113 implicit none
114 end subroutine getopt_dielectric_function
115
116 subroutine getopt_vibrational(mode)
117 implicit none
118 integer, intent(inout) :: mode
119 end subroutine getopt_vibrational
120
121 subroutine getopt_xyz_anim
122 implicit none
123 end subroutine getopt_xyz_anim
124
125 subroutine getopt_oscillator_strength(mode, omega, searchinterval, &
126 order, nresonances, nfrequencies, time, &
127 l, m, damping, file)
128 use iso_c_binding
129 implicit none
130 integer, intent(inout) :: mode
131 real(c_double), intent(inout) :: omega
132 real(c_double), intent(inout) :: searchinterval
133 integer, intent(inout) :: order, nresonances, nfrequencies
134 real(c_double), intent(inout) :: time
135 integer, intent(inout) :: l, m
136 real(c_double), intent(inout) :: damping
137 character(kind=c_char), intent(inout) :: file(*)
138 end subroutine getopt_oscillator_strength
139
140 subroutine getopt_harmonic_spectrum(w0, m, ar, x, y, z, pol) bind(c)
141 use iso_c_binding
142 implicit none
143 real(c_double) , intent(inout) :: w0
144 integer , intent(inout) :: m
145 integer , intent(inout) :: ar
146 character(kind=c_char) , intent(inout) :: pol(*)
147 real(c_double) , intent(inout) :: x
148 real(c_double) , intent(inout) :: y
149 real(c_double) , intent(inout) :: z
150 end subroutine getopt_harmonic_spectrum
151
152 subroutine getopt_help(mode, name)
153 use iso_c_binding
154 implicit none
155 character(kind=c_char), intent(inout) :: mode(*)
156 character(kind=c_char), intent(inout) :: name(*)
157 end subroutine getopt_help
158
159 subroutine getopt_photoelectron_spectrum(estep, espan, &
160 thstep, thspan, phstep, phspan, pol, center, pvec, integrate)
161 use iso_c_binding
162 implicit none
163 real(c_double), intent(inout) :: estep
164 real(c_double), intent(inout) :: espan(2)
165 real(c_double), intent(inout) :: thstep
166 real(c_double), intent(inout) :: thspan(2)
167 real(c_double), intent(inout) :: phstep
168 real(c_double), intent(inout) :: phspan(2)
169 real(c_double), intent(inout) :: pol(3)
170 real(c_double), intent(inout) :: center(3)
171 real(c_double), intent(inout) :: pvec(3)
172 integer, intent(inout) :: integrate
173 end subroutine getopt_photoelectron_spectrum
174
175 end interface
176
182#if FC_COMMAND_LINE_ARGUMENTS == 77 && ! defined(FC_COMMAND_LINE_INTRINSIC)
183
184 interface command_argument_count
185#ifdef FC_COMMAND_LINE_IMPLICIT
186 integer function iargc()
187 implicit none
188 end function iargc
189#else
190 module procedure iargc
191#endif
192 end interface
193
194 interface get_command_argument
195#ifdef FC_COMMAND_LINE_IMPLICIT
196 subroutine getarg(c, a)
197 implicit none
198 integer, intent(in) :: c
199 character(len=*), intent(out) :: a
200 end subroutine getarg
201#else
202 module procedure getarg
203#endif
204 end interface
205
206#endif /* FC_COMMAND_LINE_ARGUMENTS == 77 */
208
209 ! ---------------------------------------------------------
212
213 interface
214 subroutine set_number_clarg(argc)
215 implicit none
216 integer, intent(in) :: argc
217 end subroutine set_number_clarg
218
219 subroutine set_clarg(i, argstring) bind(c)
220 use iso_c_binding
221 implicit none
222 integer, intent(in) :: i
223 character(kind=c_char), intent(in) :: argstring(*)
224 end subroutine set_clarg
225
226 subroutine clean_clarg()
227 implicit none
228 end subroutine clean_clarg
229 end interface
230
231
232contains
233
234 subroutine getopt_octopus(config_str)
235 character(len=*), intent(in) :: config_str
236 interface
237 subroutine getopt_octopus_low(config_str) bind(c, name='getopt_octopus')
238 use iso_c_binding
239 implicit none
240 character(kind=c_char), intent(in) :: config_str(*)
241 end subroutine getopt_octopus_low
242 end interface
243
244 call getopt_octopus_low(string_f_to_c(config_str))
245 end subroutine getopt_octopus
246
247 ! ---------------------------------------------------------
251 subroutine getopt_init(ierr)
252 integer, intent(out) :: ierr
253
254 integer :: argc, i
255 character(len=100), allocatable :: argstring(:)
256
257#ifdef FC_COMMAND_LINE_ARGUMENTS
259 allocate(argstring(0:argc))
260 call set_number_clarg(argc)
261 do i = 0, argc
262 call get_command_argument(i, argstring(i))
263 call set_clarg(i, string_f_to_c(argstring(i)))
264 end do
265 deallocate(argstring)
266 ierr = 0
267#else
268 ierr = -1
269#endif
270 end subroutine getopt_init
271
272
273 subroutine getopt_end
274#ifdef FC_COMMAND_LINE_ARGUMENTS
275 call clean_clarg()
276#endif
277 end subroutine getopt_end
278
279!if there is no way to access command line, define some dummy
280!functions to avoid problems when linking
281
282#if defined(FC_COMMAND_LINE_INTRINSIC) || ! defined(FC_COMMAND_LINE_ARGUMENTS)
284 integer function command_argument_count()
285#if defined(FC_COMMAND_LINE_INTRINSIC)
286 command_argument_count = iargc()
287#else
289#endif
290 end function command_argument_count
291
292 subroutine get_command_argument(c, a)
293 integer, intent(in) :: c
294 character(len=*), intent(out) :: a
296#if defined(FC_COMMAND_LINE_INTRINSIC)
297 call getarg(c, a)
298#endif
299
300 end subroutine get_command_argument
301
302#endif
304
305end module command_line_oct_m
306
307
308
309!! Local Variables:
310!! mode: f90
311!! coding: utf-8
312!! End:
Each program/utility that needs to use the getopt features should have an interface here – the defini...
If Fortran 2003 interface to command line arguments is not available, define it using an interface ov...
subroutine, public getopt_octopus(config_str)
subroutine, public getopt_init(ierr)
Initializes the getopt machinery. Must be called before attempting to parse the options....
subroutine, public getopt_end
integer function, public command_argument_count()
subroutine, public get_command_argument(c, a)
character(kind=c_char, len=1) function, dimension(:), allocatable, public string_f_to_c(f_string)
convert a Fortran string to a C string
Definition: string.F90:273