TABLE OF CONTENTS


ABINIT/m_argparse [ Modules ]

[ Top ] [ Modules ]

NAME

 m_argparse

FUNCTION

   Simple argument parser used in main programs

COPYRIGHT

  Copyright (C) 2008-2018 ABINIT group (MG)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

PARENTS

CHILDREN

SOURCE

21 #if defined HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "abi_common.h"
26 
27 module m_argparse
28 
29  use defs_basis
30  use m_abicore
31  use m_errors
32  use m_xmpi
33  use m_xomp
34  use m_xieee
35  use m_abi_linalg
36  use m_fft
37  use m_exit
38 
39  use m_build_info,      only : dump_config, abinit_version
40  use m_io_tools,        only : open_file
41  use m_cppopts_dumper,  only : dump_cpp_options
42  use m_optim_dumper,    only : dump_optim
43  use m_fstrings,        only : atoi, itoa, firstchar, sjoin
44  use m_time,            only : str2sec
45  use m_libpaw_tools,    only : libpaw_log_flag_set
46 
47  implicit none
48 
49  private

m_abi_linalg/parse_yesno [ Functions ]

[ Top ] [ m_abi_linalg ] [ Functions ]

NAME

  parse_yesno

FUNCTION

  This function receives an argument, arg of the form --foo[=bool_value]
  that begins with optname (i.e. --foo) and returns the value of bool_value
  If bool_value is not present, returns default (.True. if not specified)

SOURCE

346 logical function parse_yesno(arg, optname, default) result(bool)
347 
348 
349 !This section has been created automatically by the script Abilint (TD).
350 !Do not modify the following lines by hand.
351 #undef ABI_FUNC
352 #define ABI_FUNC 'parse_yesno'
353 !End of the abilint section
354 
355  implicit none
356 
357 !Arguments ------------------------------------
358 !scalars
359  character(len=*),intent(in) :: arg,optname
360  logical,optional,intent(in) :: default
361 
362  bool = .True.; if (present(default)) bool = default
363 
364  ! Assume default if value is not given
365  if (len_trim(optname) == len_trim(arg)) return
366 
367  select case (arg(len(optname)+1:))
368  case ("=yes", "=y")
369    bool = .True.
370  case ("=no", "=n")
371    bool = .False.
372  case default
373    write(std_out,*)"Wrong option ",trim(arg),". Will default to ",bool
374    MSG_ERROR("Aborting now")
375  end select
376 
377 end function parse_yesno

m_argparse/args_parser [ Functions ]

[ Top ] [ m_argparse ] [ Functions ]

NAME

  args_parser

FUNCTION

  Simple command line argument parser for abinit.

PARENTS

      abinit

SOURCE

 95 type(args_t) function args_parser() result(args)
 96 
 97 
 98 !This section has been created automatically by the script Abilint (TD).
 99 !Do not modify the following lines by hand.
100 #undef ABI_FUNC
101 #define ABI_FUNC 'args_parser'
102 !End of the abilint section
103 
104  implicit none
105 
106 !Local variables-------------------------------
107  integer :: ii,ierr
108  logical :: iam_master,verbose
109  real(dp) :: timelimit
110  character(len=500) :: arg,msg
111 
112 ! *************************************************************************
113 
114  args%exit = 0; ierr=0; verbose = .False.
115 
116 #ifndef HAVE_FC_COMMAND_ARGUMENT
117  call wrtout(std_out,"get_command_argument is not supported by FC. Ignoring command lines options!")
118  return ! Nothing to do
119 #else
120 
121  if (command_argument_count()==0) return
122 
123  iam_master = (xmpi_comm_rank(xmpi_world) == 0)
124 
125  ! Store full command line for future reference.
126  call get_command(args%cmdline)
127 
128   do ii=1,command_argument_count()
129     call get_command_argument(ii, arg)
130     !write(std_out,*)"arg", TRIM(arg)
131 
132     if (arg == "-v" .or. arg == "--version") then
133       call wrtout(std_out,TRIM(abinit_version),"COLL")
134       args%exit = args%exit + 1
135 
136     else if (arg == "-b" .or. arg == "--build") then
137       call print_kinds(unit=std_out)
138       call xmpi_show_info(unit=std_out)
139       call dump_cpp_options(std_out)
140       call dump_config(std_out)
141       call dump_optim(std_out)
142 
143       args%exit = args%exit + 1
144 
145     else if (arg == "-d" .or. arg == "--dry-run") then
146       args%dry_run = 1
147 
148     else if (arg == "--abimem-level") then
149       call get_command_argument(ii+1, arg)
150       args%abimem_level = atoi(arg)
151 
152     else if (arg == "-j" .or. arg == "--omp-num-threads") then
153       call get_command_argument(ii+1, arg)
154       call xomp_set_num_threads(atoi(arg))
155 
156     ! timelimit handler.
157     else if (arg == "-t" .or. arg == "--timelimit") then
158       call get_command_argument(ii+1, arg)
159       timelimit = str2sec(arg)
160       if (timelimit < zero) then
161         write(std_out,*)"Wrong timelimit argument:",trim(arg)
162         args%exit = args%exit + 1
163       else
164         call exit_init(timelimit)
165       end if
166 
167     ! IEEE exceptions.
168     else if (arg == "--ieee-halt") then
169       call xieee_halt_ifexc(.True.)
170     else if (arg == "--ieee-signal") then
171       call xieee_signal_ifexc(.True.)
172 
173     ! Enable/disable non-blocking ialltoall in MPI-FFT
174     else if (begins_with(arg, "--fft-ialltoall")) then
175       call fft_allow_ialltoall(parse_yesno(arg, "--fft-ialltoall"))
176 
177     ! Enable/disable [Z,C]GEMM3
178     else if (begins_with(arg, "--xgemm3m")) then
179       call linalg_allow_gemm3m(parse_yesno(arg, "--xgemm3m"))
180 
181     ! Enable/disable PLASMA
182     else if (begins_with(arg, "--plasma")) then
183       call linalg_allow_plasma(parse_yesno(arg, "--plasma"))
184 
185     else if (arg == "--gnu-mtrace") then
186       if (iam_master) then
187         call clib_mtrace(ierr)
188         if (ierr/=0 .and. iam_master) write(std_out,"(a,i0)")"clib_mtrace returned ierr: ",ierr
189     end if
190 
191     else if (arg == "--log") then
192        ! Enable logging
193        call abi_log_status_state(new_do_write_log=.True.,new_do_write_status=.True.)
194        call libpaw_log_flag_set(.True.)
195 
196     else if (arg == "-i" .or. arg == "--input") then
197       ! Redirect stdin to file.
198       call get_command_argument(ii+1, arg)
199       if (iam_master) then
200         close(std_in)
201         if (open_file(arg, msg, unit=std_in, form='formatted', status='old', action="read") /= 0) then
202           MSG_ERROR(msg)
203         end if
204       end if
205 
206     !else if (arg == "-o" .or. arg == "--output") then
207     !  ! Redirect stdout to file.
208     !  call get_command_argument(ii+1, arg)
209     !  if (iam_master) then
210     !  close(std_out)
211     !  if (open_file(arg, msg, unit=std_out, form='formatted', status='new', action="write") /= 0) then
212     !    MSG_ERROR(message)
213     !  end if
214     !  end if
215 
216     else if (arg == "-h" .or. arg == "--help") then
217       if (iam_master) then
218         ! Document the options.
219         write(std_out,*)"-v, --version              Show version number and exit."
220         write(std_out,*)"-b, --build                Show build parameters and exit."
221         write(std_out,*)"-d, --dry-run              Validate input file and exit."
222         write(std_out,*)"-j, --omp-num-threads      Set the number of OpenMp threads."
223         write(std_out,*)"--abimem-level NUM         Set memory profiling level. Requires HAVE_MEM_PROFILING"
224         write(std_out,*)"--ieee-halt                Halt the code if one of the *usual* IEEE exceptions is raised."
225         write(std_out,*)"--ieee-signal              Signal the occurrence of the *usual* IEEE exceptions."
226         write(std_out,*)"--fft-ialltoall[=bool]     Use non-blocking ialltoall in MPI-FFT (used only if ndat>1 and MPI3)."
227         write(std_out,*)"--xgemm3m[=bool]           Use [Z,C]GEMM3M]"
228         write(std_out,*)"--gnu-mtrace               Enable mtrace (requires GNU and clib)."
229         write(std_out,*)"--log                      Enable log files and status files in parallel execution."
230         write(std_out,*)"-i FILE                    Read input data from FILE instead of stdin."
231         write(std_out,*)"                           Useful if MPI library does not handle `abinit < files` redirection"
232         write(std_out,*)"-t, --timelimit            Set the timelimit for the run. Accepts time in Slurm notation:"
233         write(std_out,*)"                               days-hours"
234         write(std_out,*)"                               days-hours:minutes"
235         write(std_out,*)"                               days-hours:minutes:seconds"
236         write(std_out,*)"                               minutes"
237         write(std_out,*)"                               minutes:seconds"
238         write(std_out,*)"                               hours:minutes:seconds"
239         write(std_out,*)"--verbose                  Verbose mode"
240         write(std_out,*)"-h, --help                 Show this help and exit."
241       end if
242       args%exit = args%exit + 1
243 
244     else if (arg == "--verbose") then
245       verbose = .True.
246 
247     else
248       if (firstchar(arg, "-")) then
249         MSG_WARNING("Unsupported option: "//trim(arg))
250         args%exit = args%exit + 1
251       else
252         continue
253       end if
254     end if
255   end do
256 
257   if (verbose) call args_print(args)
258 #endif
259 
260 end function args_parser

m_argparse/args_print [ Functions ]

[ Top ] [ m_argparse ] [ Functions ]

NAME

  args_print

FUNCTION

  Print object.

PARENTS

      m_argparse

CHILDREN

      wrtout

SOURCE

280 subroutine args_print(args)
281 
282 
283 !This section has been created automatically by the script Abilint (TD).
284 !Do not modify the following lines by hand.
285 #undef ABI_FUNC
286 #define ABI_FUNC 'args_print'
287 !End of the abilint section
288 
289  implicit none
290 
291 !Arguments ------------------------------------
292  type(args_t),intent(in) :: args
293 
294 ! *************************************************************************
295 
296  call wrtout(std_out, sjoin("Command line:", args%cmdline))
297  call wrtout(std_out, sjoin("exit:", itoa(args%abimem_level)))
298  call wrtout(std_out, sjoin("abimem_level:", itoa(args%abimem_level)))
299  call wrtout(std_out, sjoin("dry_run:", itoa(args%abimem_level)))
300 
301 end subroutine args_print

m_argparse/args_t [ Types ]

[ Top ] [ m_argparse ] [ Types ]

NAME

 args_t

FUNCTION

 Stores the command line options

SOURCE

61  type,public :: args_t
62 
63    integer :: exit=0
64      ! /=0 to exit after having parsed the command line options.
65 
66    integer :: abimem_level=0
67 
68    integer :: dry_run=0
69      ! /= 0 to exit after the validation of the input file.
70 
71    character(len=500) :: cmdline=""
72      ! The entire command line
73 
74  end type args_t
75 
76  public :: args_parser   ! Parse command line options.

m_argparse/begins_with [ Functions ]

[ Top ] [ m_argparse ] [ Functions ]

NAME

  begins_with

FUNCTION

  Returns true if argument arg begins with string

SOURCE

313 pure logical function begins_with(arg, string) result(bool)
314 
315 
316 !This section has been created automatically by the script Abilint (TD).
317 !Do not modify the following lines by hand.
318 #undef ABI_FUNC
319 #define ABI_FUNC 'begins_with'
320 !End of the abilint section
321 
322  implicit none
323 
324 !Arguments ------------------------------------
325 !scalars
326  character(len=*),intent(in) :: arg,string
327 
328  bool = .False.; if (len(arg) >= len(string)) bool = (arg(1:len(string)) == string)
329 
330 end function begins_with