Ignore:
Timestamp:
Oct 12, 2023, 10:30:22 AM (15 months ago)
Author:
slebonnois
Message:

BBT : Update for the titan microphysics and cloud model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.TITAN/libf/muphytitan/argparse.F90

    r1897 r3083  
    1 ! Copyright Jérémie Burgalat (2010-2015,2017)
    2 !
    3 ! jeremie.burgalat@univ-reims.fr
    4 !
    5 ! This software is a computer program whose purpose is to provide configuration
    6 ! file and command line arguments parsing features to Fortran programs.
    7 !
    8 ! This software is governed by the CeCILL-B license under French law and
    9 ! abiding by the rules of distribution of free software.  You can  use,
    10 ! modify and/ or redistribute the software under the terms of the CeCILL-B
    11 ! license as circulated by CEA, CNRS and INRIA at the following URL
    12 ! "http://www.cecill.info".
    13 !
    14 ! As a counterpart to the access to the source code and  rights to copy,
    15 ! modify and redistribute granted by the license, users are provided only
    16 ! with a limited warranty  and the software's author,  the holder of the
    17 ! economic rights,  and the successive licensors  have only  limited
    18 ! liability.
    19 !
    20 ! In this respect, the user's attention is drawn to the risks associated
    21 ! with loading,  using,  modifying and/or developing or reproducing the
    22 ! software by the user in light of its specific status of free software,
    23 ! that may mean  that it is complicated to manipulate,  and  that  also
    24 ! therefore means  that it is reserved for developers  and  experienced
    25 ! professionals having in-depth computer knowledge. Users are therefore
    26 ! encouraged to load and test the software's suitability as regards their
    27 ! requirements in conditions enabling the security of their systems and/or
    28 ! data to be ensured and,  more generally, to use and operate it in the
    29 ! same conditions as regards security.
    30 !
    31 ! The fact that you are presently reading this means that you have had
    32 ! knowledge of the CeCILL-B license and that you accept its terms.
     1! Copyright (c) (2013-2015,2017) Jeremie Burgalat (jeremie.burgalat@univ-reims.fr).
     2!
     3! This file is part of SWIFT
     4!
     5! Permission is hereby granted, free of charge, to any person obtaining a copy of
     6! this software and associated documentation files (the "Software"), to deal in
     7! the Software without restriction, including without limitation the rights to
     8! use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
     9! the Software, and to permit persons to whom the Software is furnished to do so,
     10! subject to the following conditions:
     11!
     12! The above copyright notice and this permission notice shall be included in all
     13! copies or substantial portions of the Software.
     14!
     15! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
     17! FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
     18! COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
     19! IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     20! CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3321
    3422!! file: argparse.F90
    3523!! summary: Command-line parser source file.
    3624!! author: J. Burgalat
    37 !! date: 2013-2015,2017
     25!! date: 2013-2015,2017,2022
    3826
    3927#include "defined.h"
     
    4533  !! For your own sanity, private methods that call Ancient Gods powers through
    4634  !! evil black magic rituals are not described here.
    47   !! 
     35  !!
    4836  !! If you only wish to have an overview of argparse usage, you'd better go
    4937  !! [here](|url|/page/swift/p01_argparse.html).
     
    5240  USE ERRORS
    5341  USE FSYSTEM, ONLY : fs_termsize
    54   USE STRING_OP, getpar => format_paragraph, splitstr  => format_string 
     42  USE STRING_OP, getpar => format_paragraph, splitstr  => format_string
    5543  IMPLICIT NONE
    5644
     
    6856            argparser_add_option,       &
    6957            argparser_add_positionals,  &
    70             argparser_throw_error,      & 
     58            argparser_throw_error,      &
    7159            argparser_parse,            &
    7260            argparser_help,             &
     
    8573  ! ===========================
    8674
    87   INTEGER, PARAMETER, PUBLIC :: ap_string  = st_string 
     75  INTEGER, PARAMETER, PUBLIC :: ap_string  = st_string
    8876    !! String value type identifier.
    8977  INTEGER, PARAMETER, PUBLIC :: ap_complex = st_complex
     
    9886  !> List of all available actions
    9987
    100   INTEGER, PARAMETER, PUBLIC :: ap_store  = 1
     88  INTEGER, PARAMETER, PUBLIC :: ap_store   = 1
    10189    !! store action ID : Each time the option is seen, values are replaced.
    102   INTEGER, PARAMETER, PUBLIC :: ap_append = 2
    103     !! append action ID : Each time the option is seen, values are appended. 
    104   INTEGER, PARAMETER, PUBLIC :: ap_count  = 3
     90  INTEGER, PARAMETER, PUBLIC :: ap_append  = 2
     91    !! append action ID : Each time the option is seen, values are appended.
     92  INTEGER, PARAMETER, PUBLIC :: ap_count   = 3
    10593    !! count action ID : increase a counter each time the option is seen.
    106   INTEGER, PARAMETER, PUBLIC :: ap_help   = 4
     94  INTEGER, PARAMETER, PUBLIC :: ap_help    = 4
    10795    !! help action ID : help is requested !
     96  INTEGER, PARAMETER, PUBLIC :: ap_version = 5
     97    !! version action ID : version is requested !
    10898
    10999  !> List of all available actions
    110   INTEGER, DIMENSION(4), PARAMETER, PRIVATE :: ap_actions = (/ap_store,  &
     100  INTEGER, DIMENSION(5), PARAMETER, PRIVATE :: ap_actions = (/ap_store,  &
    111101                                                              ap_append, &
    112102                                                              ap_count,  &
    113                                                               ap_help/)
     103                                                              ap_help,   &
     104                                                              ap_version/)
    114105  !> List of all recognized types by the parser
    115   INTEGER, DIMENSION(5), PARAMETER, PRIVATE :: ap_types = (/ap_string,  & 
     106  INTEGER, DIMENSION(5), PARAMETER, PRIVATE :: ap_types = (/ap_string,  &
    116107                                                            ap_logical, &
    117108                                                            ap_complex, &
    118109                                                            ap_integer, &
    119                                                             ap_real/) 
     110                                                            ap_real/)
    120111  !> The unknown flag
    121112  !!
    122   !! This flag is only intended to initialize flags. It is set by default during initialization 
     113  !! This flag is only intended to initialize flags. It is set by default during initialization
    123114  !! and quielty replaced by default flags, if user does not provide the relevant feature.
    124115  INTEGER, PARAMETER :: ap_undef = -1
    125    
     116
    126117  !> Add an option to the parser
    127118  !!
     
    131122  !! ```
    132123  !!
    133   !! The function defines a new argument based on input parameters, checks it and finally sets it 
    134   !! in the parser. 
    135   !! 
     124  !! The function defines a new argument based on input parameters, checks it and finally sets it
     125  !! in the parser.
     126  !!
    136127  !! In its first version both short (`sflag`) and long (`lflag`) options flags are mandatory. In its second
    137128  !! form, a single flag (`flag`) is expected: the method will automatically deduce if it belongs to short or
    138129  !! a long option flag based on the number of hyphens given.
    139   !! 
     130  !!
    140131  !! `type` value should be one of the following module constants (which are aliases from [[string_op(module)]]):
    141132  !!
     
    145136  !! - `ap_integer` ([[string_op(module):st_integer(variable)]])
    146137  !! - `ap_real` ([[string_op(module):st_real(variable)]])
    147   !! 
     138  !!
    148139  !! `action` value should be one of the following module constants:
    149140  !!
     
    162153  !!  "X"  | Exactly X values. Where X is the string representation of an integer (0 is accepted).
    163154  !!
    164   !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only 
     155  !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only
    165156  !! produced by misuse of the function arguments. In such case, the program should be
    166157  !! stopped: note that such error should not occur in _released_ programs.
     
    168159    MODULE PROCEDURE ap_add_option_1, ap_add_option_2
    169160  END INTERFACE
    170  
     161
    171162  !> Get positional argument value(s)
    172163  INTERFACE argparser_get_positional
    173164    MODULE PROCEDURE ap_get_positional_sc, ap_get_positional_ve
    174   END INTERFACE 
     165  END INTERFACE
    175166
    176167  !> Get optional argument value(s)
     
    179170  !! FUNCTION argparser_get_value(this,name,output) RESULT(err)
    180171  !! ```
    181   !! 
     172  !!
    182173  !! This is the generic method that can be used to retrieve any kind of argument value(s) from the parser for a given
    183174  !! argument name (as defined by the `dest` argument of [[argparse(module):argparser_add_option(interface)]].
    184175  !! All the methods have the same dummy arguments only `output` dummy argument differs in type and shape.
    185   !! 
     176  !!
    186177  !! @note
    187178  !! For string vector, `output` is expected to be an allocatable vector of **assumed length**
    188179  !! strings (thus string length is left to user responsability).
    189   !! A good compromise for strings length is to use the [[string_op(module):st_slen(variable)]] 
     180  !! A good compromise for strings length is to use the [[string_op(module):st_slen(variable)]]
    190181  !! parameter.
    191182  INTERFACE argparser_get_value
     
    197188  !> Interface to [[argparse(module):argc(type)]] getters
    198189  !!
    199   !! All the functions have the same prototype, only kind and type of arguments changed 
     190  !! All the functions have the same prototype, only kind and type of arguments changed
    200191  !! from a function to the other.
    201   INTERFACE argc_get_value                   
     192  INTERFACE argc_get_value
    202193    MODULE PROCEDURE ac_get_dv_sc, ac_get_rv_sc, ac_get_iv_sc, ac_get_lv_sc, &
    203194                     ac_get_cv_sc, ac_get_sv_sc, ac_get_dv_ve, ac_get_rv_ve, &
     
    230221    !! Defines a command-line argument.
    231222    !!
    232     !! An [[argparse(module):argc(type)]] object stores all information about a command-line 
     223    !! An [[argparse(module):argc(type)]] object stores all information about a command-line
    233224    !! argument, that is:
    234225    !!
    235226    !! - its name
    236     !! - its optional flags 
     227    !! - its optional flags
    237228    !! - its type
    238229    !! - its action
     
    253244    TYPE(words)      :: meta
    254245      !! Meta variable name(s) of the argument
    255 #if HAVE_FTNDTSTR 
     246#if HAVE_FTNDTSTR
    256247    CHARACTER(len=:), ALLOCATABLE :: default
    257       !! Default flag 
     248      !! Default flag
    258249    CHARACTER(len=:), ALLOCATABLE :: name
    259250      !! Name of the argument (needed to check and retrieve its value(s))
    260     CHARACTER(len=:), ALLOCATABLE :: lflag 
     251    CHARACTER(len=:), ALLOCATABLE :: lflag
    261252      !! Long flag option (st_short_len max chars !)
    262253    CHARACTER(len=:), ALLOCATABLE :: help
     
    264255#else
    265256    CHARACTER(len=st_slen) :: default = ""
    266       !! Default flag 
     257      !! Default flag
    267258    CHARACTER(len=st_slen) :: name
    268259      !! Name of the argument (needed to check and retrieve its value(s))
     
    278269    !! Command-line parser
    279270    !!
    280     !! This is the main object of the module. It stores definitions of CLI arguments and 
     271    !! This is the main object of the module. It stores definitions of CLI arguments and
    281272    !! their value(s) once the command-line have been parsed.
    282273    TYPE(argc), PRIVATE, ALLOCATABLE, DIMENSION(:) :: args
     
    298289#if HAVE_FTNDTSTR
    299290    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: usg
    300       !! Program command usage 
     291      !! Program command usage
    301292    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: descr
    302293      !! Program help description
    303     CHARACTER(len=:), PRIVATE, ALLOCATABLE :: eplg 
     294    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: eplg
    304295      !! Program help epilog
     296    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: vers
     297      !! Application version string
    305298#else
    306299    CHARACTER(len=st_llen), PRIVATE :: usg
    307       !! Program command usage 
     300      !! Program command usage
    308301    CHARACTER(len=st_llen), PRIVATE :: descr
    309302      !! Program help description
    310     CHARACTER(len=st_llen), PRIVATE :: eplg 
     303    CHARACTER(len=st_llen), PRIVATE :: eplg
    311304      !! Program help epilog
     305    CHARACTER(len=st_llen), PRIVATE :: vers
     306      !! Application version string
    312307#endif
    313     INTEGER, PRIVATE :: mxhlpos = 20 
     308    INTEGER, PRIVATE :: mxhlpos = 20
    314309      !! Position of the short help for options
    315310    INTEGER, PRIVATE :: width = 0
    316       !! Maximum width of the help 
     311      !! Maximum width of the help
    317312    LOGICAL, PRIVATE :: init = .false.
    318313      !! Initialization control flag
    319 #if HAVE_FTNPROC   
     314#if HAVE_FTNPROC
    320315
    321316    CONTAINS
     
    341336    PROCEDURE, PUBLIC  :: parse              => argparser_parse
    342337      !! Parse the command-line (or the given input string).
    343     PROCEDURE, PUBLIC  :: help               => argparser_help 
     338    PROCEDURE, PUBLIC  :: help               => argparser_help
    344339      !! Compute and print help
     340    PROCEDURE, PUBLIC  :: version            => argparser_version
     341      !! print version string
    345342    PROCEDURE, PUBLIC  :: found              => argparser_found
    346343      !! Check if an optional argument has been found on the command-line
     
    356353    GENERIC, PUBLIC    :: add_option         => ap_add_option_1, &
    357354                                                ap_add_option_2
    358     !> Get the values of the positionals stored in the parser.                                               
     355    !> Get the values of the positionals stored in the parser.
    359356    GENERIC, PUBLIC    :: get_positional     => ap_get_positional_sc, &
    360357                                                ap_get_positional_ve
     
    372369                                                ap_get_cv_ve, &
    373370                                                ap_get_sv_ve
    374 #endif       
     371#endif
    375372  END TYPE argparser
    376373
     
    380377  ! -------------------------------
    381378
    382   FUNCTION new_argparser(usg, dsc, epg, add_help, width, max_help_pos) RESULT(this)
     379  FUNCTION new_argparser(usg, dsc, epg, add_help, add_version, version_string,width, max_help_pos) RESULT(this)
    383380    !! Initialize an argparser object.
    384     !! 
     381    !!
    385382    !! The method initializes (properly) an [[argparse(module):argparser(type)]] object.
    386     !! Even if all the arguments are optional, it is mandatory to **call** the method 
     383    !! Even if all the arguments are optional, it is mandatory to **call** the method
    387384    !! before using an argparser object.
    388385    CHARACTER(len=*), INTENT(in), OPTIONAL :: usg
     
    394391      !! An optional string with the epilog of the program's help
    395392    LOGICAL, INTENT(in), OPTIONAL          :: add_help
    396       !! An optional boolean flag with `.true.` to automatically set an option for program's help. 
     393      !! An optional boolean flag with `.true.` to automatically set an option for program's help.
    397394      !! Note that, the option flags `-h` and `--help` are no more available in that case.
     395    LOGICAL, INTENT(in), OPTIONAL          :: add_version
     396      !! An optional boolean flag with `.true.` to automatically set an option for program's help.
     397      !! Note that, the option flags `-V` and `--version` are no more available in that case.
     398    CHARACTER(len=*), INTENT(in), OPTIONAL :: version_string
     399      !! An optional string with the text to display if the *version* option is found on the
     400      !! command line. The text is displayed without any format.
    398401    INTEGER, INTENT(in), OPTIONAL          :: width
    399402      !! An optional integer with the maximum width the help text.
    400403    INTEGER, INTENT(in), OPTIONAL          :: max_help_pos
    401       !! An optional integer with the maximum position of the help string for each option of 
    402       !! the program when help is requested. Note that this value is just an indicator. The 
    403       !! helper computes the minimum position between this value and the maximum length of the 
     404      !! An optional integer with the maximum position of the help string for each option of
     405      !! the program when help is requested. Note that this value is just an indicator. The
     406      !! helper computes the minimum position between this value and the maximum length of the
    404407      !! options flags.
    405     TYPE(argparser) :: this 
     408    TYPE(argparser) :: this
    406409      !! An initialized argparse object.
    407410    INTEGER     :: zh
     
    413416    IF (PRESENT(dsc)) THEN ; this%descr=dsc ; ELSE ; this%descr='' ; ENDIF
    414417    IF (PRESENT(epg)) THEN ; this%eplg=epg  ; ELSE ; this%eplg=''  ; ENDIF
    415     CALL fs_termsize(zh,this%width) 
     418    CALL fs_termsize(zh,this%width)
    416419    IF (PRESENT(width)) this%width = MAX(width,50)
    417420    IF(PRESENT(max_help_pos)) this%mxhlpos = MAX(5,max_help_pos)
     
    422425                    action=ap_help, help="Print this help and quit")
    423426    ENDIF
     427    IF (PRESENT(add_version)) THEN
     428      IF (add_version) &
     429        err = argparser_add_option(this,'version',sflag='-V',lflag='--version', &
     430                    action=ap_version, help="Print the application version and quit")
     431      this%vers = ''
     432      if (PRESENT(version_string)) this%vers = TRIM(version_string)
     433    ENDIF
    424434    RETURN
    425435  END FUNCTION new_argparser
     
    432442    !! @note If **fccp** has not been built with support for finalization subroutine,
    433443    !! it should be called whenever the argparser object is no more used.
    434     TYPE(argparser), INTENT(inout) :: this 
     444    TYPE(argparser), INTENT(inout) :: this
    435445      !! An argparser object
    436446    IF (ALLOCATED(this%args)) THEN
     
    466476    !!
    467477    !! The method initializes the entry for positional arguments in the parser.
    468     !! Positional arguments are always seen by the parser as strings and the 
     478    !! Positional arguments are always seen by the parser as strings and the
    469479    !! default associated action is 'store'.
    470480    OBJECT(argparser), INTENT(inout)                     :: this
     
    475485      !! A vector of strings with the the displayed value name(s) of the positionals in the help command
    476486    CHARACTER(len=*), INTENT(in), OPTIONAL               :: help
    477       !! An optional string with a short description of the positional argument(s) 
     487      !! An optional string with a short description of the positional argument(s)
    478488    TYPE(error) :: err
    479489      !! Error object with the first error encountered in the process.
     
    481491    CHARACTER(len=:), ALLOCATABLE :: sf,lf,de
    482492    err = noerror
    483     IF (.NOT.this%init) THEN 
    484       err = error("argparse: parser not initialized yet",-1) 
     493    IF (.NOT.this%init) THEN
     494      err = error("argparse: parser not initialized yet",-1)
    485495      RETURN
    486496    ENDIF
     
    504514        RETURN
    505515      ENDIF
    506       this%have_posal = this%posals%nrec /= 0 
     516      this%have_posal = this%posals%nrec /= 0
    507517    ENDIF
    508518    RETURN
     
    514524    !! given as optional argument and fills the parser's arguments.
    515525    !! @note
    516     !! If `cmd_line` is provided it should not contains the name of the program or 
    517     !! the parsing process will certainly failed: program name will be seen as the 
    518     !! first positional argument and all tokens of the string will then be seen as 
     526    !! If `cmd_line` is provided it should not contains the name of the program or
     527    !! the parsing process will certainly failed: program name will be seen as the
     528    !! first positional argument and all tokens of the string will then be seen as
    519529    !! positional.
    520530    OBJECT(argparser), INTENT(inout)       :: this
     
    523533      !! An optional string to parse that substitute for the actual command-line.
    524534    LOGICAL, INTENT(in), OPTIONAL          :: auto
    525       !! An optional boolean flag with `.true.` to instruct the parser wether to perform 
     535      !! An optional boolean flag with `.true.` to instruct the parser wether to perform
    526536      !! automatic actions or not when error occur during parsing. If `auto` is enabled,
    527537      !! then the parser dumps program's usage and stops the program on error.
     
    530540    CHARACTER(len=:), ALLOCATABLE :: cline,z
    531541    LOGICAL                       :: zauto
    532     LOGICAL                       :: rhelp
    533     INTEGER                       :: l
     542    LOGICAL                       :: rhelp
     543    LOGICAL                       :: rvers
     544    INTEGER                       :: l
    534545    TYPE(words)                   :: cmd_tokens
    535546    err = noerror
     
    537548      err = error("parser not initialized yet",-1) ; RETURN
    538549    ENDIF
    539     rhelp = .false.
     550    rhelp = .false. ; rvers = .false.
    540551    zauto = .false. ; IF (PRESENT(auto)) zauto = auto
    541552    IF (PRESENT(cmd_line)) THEN
    542553      ALLOCATE(cline,source=cmd_line)
    543554    ELSE
    544       CALL GET_COMMAND(length=l) 
     555      CALL GET_COMMAND(length=l)
    545556      ALLOCATE(CHARACTER(len=l) :: z) ; CALL GET_COMMAND(z)
    546557      CALL GET_COMMAND_ARGUMENT(0,length=l)
     
    557568        EXIT ! ... No :)
    558569      ELSE
    559         err = ap_split_cmd(this,cline,cmd_tokens,rhelp) 
     570        err = ap_split_cmd(this,cline,cmd_tokens,rhelp)
    560571        ! we only stops processing if :
    561572        !   - the internal error (string length) is raised
     
    565576      CALL words_reset(cmd_tokens) ! not mandatory... at least theoretically
    566577      ! Parses the options
    567       err = ap_parse_options(this,cmd_tokens,rhelp)
     578      err = ap_parse_options(this,cmd_tokens,rhelp,rvers)
    568579      IF (err /= noerror) EXIT
    569       ! exit loop if help is requested. Parser is not completely filled but we
    570       ! expect someone to use the help action..
    571       IF (rhelp) EXIT
     580      ! exit loop if help or version is requested. Parser is not completely filled but we
     581      ! expect someone to use the help or version actions...
     582      IF (rhelp.OR.rvers) EXIT
    572583      ! Parses positionals
    573       err = ap_parse_positionals(this,cmd_tokens) 
     584      err = ap_parse_positionals(this,cmd_tokens)
    574585      EXIT ! A one iterated loop :)
    575586    ENDDO
     
    581592    IF (zauto) THEN
    582593      IF (rhelp) CALL argparser_help(this)
     594      IF (rvers) CALL argparser_version(this)
    583595      IF (err /= 0) CALL argparser_throw_error(this,err,2)
    584596    ENDIF
    585     RETURN 
     597    RETURN
    586598  END FUNCTION argparser_parse
     599
     600  SUBROUTINE argparser_version(this)
     601    !! Print version string and exit program
     602    OBJECT(argparser), INTENT(inout) :: this
     603      !! An argparser object reference
     604    WRITE(stdout,'(a)') TRIM(this%vers)
     605    CALL argparser_clear(this)
     606    CALL EXIT(0)
     607  END SUBROUTINE argparser_version
    587608
    588609  SUBROUTINE argparser_help(this)
     
    606627    !!
    607628    !! The method performs the following actions:
    608     !! 
     629    !!
    609630    !! - Print the usage command of the program
    610631    !! - Dump the provided @p error message
     
    614635    !!
    615636    !! The error message is always printed in standard error output.
    616     !! @note 
     637    !! @note
    617638    !! If errors::error::id is 0 the method does nothing.
    618639    OBJECT(argparser), INTENT(inout) :: this
     
    638659  FUNCTION argparser_found(this,argname) RESULT(found)
    639660    !! Check wether an argument has been found in the command-line.
    640     !! @note 
     661    !! @note
    641662    !! Keep in mind that arguments in the parser always have a default
    642663    !! value. This method is not intended to check if an argument has a value but
     
    663684    CHARACTER(len=*), INTENT(in)  :: argname
    664685      !! Name of the argument to check.
    665     INTEGER :: num 
     686    INTEGER :: num
    666687      !! The number of actual values stored in the argument
    667688    INTEGER  :: idx
     
    693714    INTEGER :: ret
    694715      !! The number of actual positionals arguments
    695     ret = 0 
     716    ret = 0
    696717    IF (this%have_posal) THEN
    697718      ret = words_length(this%posals%values)
    698719    ENDIF
    699   END FUNCTION argparser_get_num_positional 
     720  END FUNCTION argparser_get_num_positional
    700721
    701722  ! argparser private methods
     
    703724
    704725  FUNCTION ap_check_state(this) RESULT(err)
    705     !! Check current parser state 
     726    !! Check current parser state
    706727    !! The method returns an error based on the current parser's state:
    707728    !! - Parser is ready (0)
     
    712733      !! An argparser object reference
    713734    TYPE(error) :: err
    714       !! Error object with the *status* of the parser 
     735      !! Error object with the *status* of the parser
    715736    err = noerror
    716737    IF (this%parsed == -1) THEN
     
    719740      err = error("argparse: command-line parsing failed",-20)
    720741    ELSE IF (.NOT.this%init) THEN
    721       err = error("argparse: parser not initialized yet",-1) 
     742      err = error("argparse: parser not initialized yet",-1)
    722743    ENDIF
    723744    RETURN
     
    732753    INTEGER                               :: i
    733754    TYPE(argc), ALLOCATABLE, DIMENSION(:) :: tmp
    734     TYPE(error) :: err 
     755    TYPE(error) :: err
    735756    IF (.NOT.this%init)  THEN
    736757      err = error("parser not initialized yet",-1) ; RETURN
     
    739760    IF (this%nargs == 0) THEN
    740761      ALLOCATE(this%args(1))
    741       this%args(1) = arg 
    742       this%nargs = 1 
     762      this%args(1) = arg
     763      this%nargs = 1
    743764      RETURN
    744765    ENDIF
     
    749770    ALLOCATE(tmp(this%nargs))
    750771    DO i=1,this%nargs ; tmp(i) = this%args(i) ; ENDDO
    751     CALL clear_argc(this%args) 
    752     DEALLOCATE(this%args) 
     772    CALL clear_argc(this%args)
     773    DEALLOCATE(this%args)
    753774    this%nargs = this%nargs+1 ; ALLOCATE(this%args(this%nargs))
    754775    DO i=1,this%nargs-1 ; this%args(i) = tmp(i) ; ENDDO
     
    782803    ! empty parser
    783804    IF (this%nargs == 0) RETURN
    784     DO i=1, this%nargs 
     805    DO i=1, this%nargs
    785806      IF ((nn /= 0 .AND. TRIM(this%args(i)%name)  == TRIM(lna)) .OR. &
    786807          (ns /= 0 .AND. TRIM(this%args(i)%sflag) == TRIM(lsf)) .OR. &
     
    796817    !! Add an argument to the parser (interface #1)
    797818    !!
    798     !! The function defines a new argument based on input parameters, checks it and finally sets it 
     819    !! The function defines a new argument based on input parameters, checks it and finally sets it
    799820    !! in the parser. Both **short and long options flags** are mandatory input arguments of the function.
    800     !! 
     821    !!
    801822    !!  `type` value should be one of the following module constants (which are aliases from [[string_op(module)]]):
    802823    !!  - ap_string ([[string_op(module):st_string(variable)]])
     
    805826    !!  - ap_integer ([[string_op(module):st_integer(variable)]])
    806827    !!  - ap_real ([[string_op(module):st_real(variable)]])
    807     !! 
     828    !!
    808829    !!  `action` value should be one of the following module constants:
    809830    !!  - [[argparse(module):ap_store(variable)]]
     
    830851      !! A string (3 characters minimum) with the long option flag of the argument
    831852    INTEGER, INTENT(in), OPTIONAL                        :: type
    832       !! An integer with the type of the argument 
     853      !! An integer with the type of the argument
    833854    INTEGER, INTENT(in), OPTIONAL                        :: action
    834       !! An integer with the action of the argument 
     855      !! An integer with the action of the argument
    835856    CHARACTER(len=*), INTENT(in), OPTIONAL               :: default
    836857      !! A string with the default value of the argument if not provided in the CLI
    837858    CHARACTER(len=*), INTENT(in), OPTIONAL               :: nrec
    838       !! A string with the expected number of specified values for the argument in the CLI. 
     859      !! A string with the expected number of specified values for the argument in the CLI.
    839860    CHARACTER(len=*), INTENT(in), OPTIONAL               :: help
    840861      !! A string with a short description of the argument
     
    853874    de =''        ; IF (PRESENT(default)) de = TRIM(default)
    854875    IF (.NOT.this%init)  THEN
    855       err = error("argparse: parser not initialized yet",-1) 
     876      err = error("argparse: parser not initialized yet",-1)
    856877      RETURN
    857878    ENDIF
     
    876897    !! Add an argument to the parser (interface #2)
    877898    !!
    878     !! The function is a wrapper to ap_add_option_1. In this version, 
     899    !! The function is a wrapper to ap_add_option_1. In this version,
    879900    !! only one option flag is required. The method only checks for the (trimmed) length of **flag** in
    880     !! order to choose wether it is a **short** or **long** option flag. Then the function simply calls 
     901    !! order to choose wether it is a **short** or **long** option flag. Then the function simply calls
    881902    !! ap_add_option_1 to set the argument.
    882     !! 
     903    !!
    883904    !! Other dummy arguments have the same meaning as in ap_add_option_1.
    884905    OBJECT(argparser), INTENT(inout)                     :: this
     
    891912      !! A string with the type of the argument
    892913    INTEGER, INTENT(in), OPTIONAL                        :: action
    893       !! A string with the action of the argument 
     914      !! A string with the action of the argument
    894915    CHARACTER(len=*), INTENT(in), OPTIONAL               :: default
    895916      !! A string with the default value of the argument if not provided in the CLI
    896917    CHARACTER(len=*), INTENT(in), OPTIONAL               :: nrec
    897       !! A string with the expected number of specified values for the argument in the CLI. 
     918      !! A string with the expected number of specified values for the argument in the CLI.
    898919    CHARACTER(len=*), INTENT(in), OPTIONAL               :: help
    899920      !! A string with a short description of the argument
     
    956977  END FUNCTION ap_check_in_parser
    957978
    958   FUNCTION ap_parse_options(this,cmd,help_req) RESULT(err)
     979  FUNCTION ap_parse_options(this,cmd,help_req,vers_req) RESULT(err)
    959980    !! Parse options of the internal command line
    960     !! This (internal) function manages the parsing of the command line options. 
     981    !! This (internal) function manages the parsing of the command line options.
    961982    OBJECT(argparser), INTENT(inout), TARGET :: this
    962983      !! An argparser object reference
     
    965986    LOGICAL, INTENT(out)                     :: help_req
    966987      !! An output logical flag with `.true.` if help option has been found, `.false.` otherwise
     988    LOGICAL, INTENT(out)                     :: vers_req
     989      !! An output logical flag with `.true.` if version option has been found, `.false.` otherwise
    967990    TYPE(error) :: err
    968991      !! Error object with the first error encountered in the process
     
    976999      ! get current element
    9771000      elt = words_current(cmd)
    978       ! check element kind: is it an option flag (-1/0)or a value (1)?
     1001      ! check element kind: is it an option flag (-1/0) or a value (1)?
    9791002      ic = ap_check_string(this,elt,arg_idx)
    9801003      IF (ic <= 0) THEN
    9811004        IF (arg_idx /= -1) THEN
    9821005          err = ap_fill_argument(this,cmd,this%args(arg_idx))
    983           IF (err == 0 .AND. this%args(arg_idx)%paction == ap_help) THEN
    984             this%parsed = 1
    985             err = argparser_get_value(this,'help',help_req)
    986             EXIT
     1006          IF (err == 0) THEN
     1007            IF (this%args(arg_idx)%paction == ap_help) THEN
     1008              this%parsed = 1
     1009              err = argparser_get_value(this,'help',help_req)
     1010              EXIT
     1011            ELSE IF (this%args(arg_idx)%paction == ap_version) THEN
     1012              this%parsed = 1
     1013              err = argparser_get_value(this,'version',vers_req)
     1014              EXIT
     1015            ENDIF
    9871016          ENDIF
    9881017          IF (err /= 0) EXIT
     
    9981027      ! iterates to next value
    9991028      CALL words_next(cmd)
    1000     ENDDO 
     1029    ENDDO
    10011030
    10021031    ! Do we need to check for error here ?
     
    10201049        IF (this%args(i)%nrec < nv) THEN
    10211050          err = ac_fmt_val_err(this%args(i),-18) ! extra values
    1022         ELSE 
     1051        ELSE
    10231052          err = ac_fmt_val_err(this%args(i),-17) ! missing values
    10241053        ENDIF
    1025       ENDIF 
     1054      ENDIF
    10261055    ENDDO
    10271056    IF (err /= 0) this%parsed = 0
    10281057    RETURN
    1029   END FUNCTION ap_parse_options 
     1058  END FUNCTION ap_parse_options
    10301059
    10311060  FUNCTION ap_parse_positionals(this,cmd) RESULT(err)
    10321061    !! Parse positional arguments of the internal command line
    1033     !! This (internal) function manages the parsing of the command line positional arguments. 
     1062    !! This (internal) function manages the parsing of the command line positional arguments.
    10341063    OBJECT(argparser), INTENT(inout) :: this
    10351064      !! An argparser object reference
     
    10441073
    10451074    ! no positional required but current word is valid
    1046     ! Either : no positional required but valid element is present 
     1075    ! Either : no positional required but valid element is present
    10471076    !     Or : positional required but no valid element is present
    10481077    IF ((this%have_posal.AND..NOT.words_valid(cmd)) .OR. &
     
    10541083    CALL words_clear(this%posals%values)
    10551084    this%posals%fnd = .true.
    1056     DO 
     1085    DO
    10571086      na = words_length(this%posals%values)
    10581087      IF (words_valid(cmd)) THEN
     
    10901119    !! Fill an argument with values
    10911120    !!
    1092     !! The function parses remaining parts of the command line from the position of 
    1093     !! the given argument and attempts to retrieve its value(s) (if any). 
     1121    !! The function parses remaining parts of the command line from the position of
     1122    !! the given argument and attempts to retrieve its value(s) (if any).
    10941123    !! Several tests are performed and may raise errors. The function always stops
    10951124    !! at the first error encountered which can be one of the following :
     
    11031132      !! The command line
    11041133    TYPE(argc), INTENT(inout), TARGET :: arg
    1105       !! An argc object reference with the argument currently processed. 
     1134      !! An argc object reference with the argument currently processed.
    11061135    TYPE(error) :: err
    11071136      !! Error object with the first error encountered in the process
    1108     INTEGER                       :: ca, isopt, itmp 
     1137    INTEGER                       :: ca, isopt, itmp
    11091138    LOGICAL                       :: ltmp
    11101139    CHARACTER(len=:), ALLOCATABLE :: elt
     
    11261155      IF (arg%paction == ap_count) THEN
    11271156        elt = words_pop(arg%values)
    1128         READ(elt,*) itmp ; itmp = itmp + 1 
     1157        READ(elt,*) itmp ; itmp = itmp + 1
    11291158        CALL words_append(arg%values,TO_STRING(itmp))
    1130       ELSE IF (arg%ptype == ap_logical) THEN 
     1159      ELSE IF (arg%ptype == ap_logical) THEN
    11311160        elt = words_pop(arg%values)
    1132         READ(elt,*) ltmp 
     1161        READ(elt,*) ltmp
    11331162        CALL words_append(arg%values,TO_STRING(.NOT.ltmp))
    11341163      ENDIF
    11351164    ELSE
    11361165      ! For any other case, the algorithm is quite simple :
    1137       ! We consume tokens of the command-line until either the end or 
     1166      ! We consume tokens of the command-line until either the end or
    11381167      ! the next option (or '--' separator)
    11391168      ! When the exit condition is met we perform some tests based on the
     
    11551184          !    1) we have consumed all argument of command line
    11561185          !    2) current argument is not a value !
    1157           !    3) current argument the separator '--' 
     1186          !    3) current argument the separator '--'
    11581187          IF (isopt <= 0 .OR. TRIM(elt)=='--') CALL words_previous(cmd)
    1159           IF (arg%nrec == -2 .AND. words_length(arg%values) == 0) & 
     1188          IF (arg%nrec == -2 .AND. words_length(arg%values) == 0) &
    11601189            err = ac_fmt_val_err(arg,-17)
    11611190          IF (arg%paction /= ap_append .AND. arg%nrec > 0 .AND. ca /= arg%nrec) &
     
    11781207  END FUNCTION ap_fill_argument
    11791208
    1180   FUNCTION ap_split_cmd(this,string,new_cmd,rhelp) RESULT(err) 
     1209  FUNCTION ap_split_cmd(this,string,new_cmd,rhelp) RESULT(err)
    11811210    !! Preprocess the command line
    1182     !! The function reads and splits the given string so merged options/values 
     1211    !! The function reads and splits the given string so merged options/values
    11831212    !! are splitted and saves the resulting string elements in a list of words.
    11841213    !! @warning
    11851214    !! For compilers that does not support allocatable strings in derived types,
    11861215    !! computation are highly dependent of [[string_op(module):st_slen(variable):
    1187     !! tokens length are limited by this parameter. 
     1216    !! tokens length are limited by this parameter.
    11881217    IMPLICIT NONE
    11891218    OBJECT(argparser), INTENT(in) :: this
     
    11931222    TYPE(words), INTENT(out)      :: new_cmd
    11941223      !! An output [[string_op(module):words(type)]] object with the processed command line
    1195     LOGICAL, INTENT(out)          :: rhelp   
     1224    LOGICAL, INTENT(out)          :: rhelp
    11961225      !! An output boolean flag with `.true.` if help is requested, `.false.` otherwise
    11971226    TYPE(error) :: err
     
    11991228    INTEGER                       :: isopt,j,tl,res
    12001229    CHARACTER(len=:), ALLOCATABLE :: elt
    1201     TYPE(words)                   :: splitted 
     1230    TYPE(words)                   :: splitted
    12021231    INTEGER                       :: arg_idx
    12031232    err = noerror ; rhelp = .false.
    12041233    IF (LEN_TRIM(string) == 0) THEN
    1205       err = error('internal error (empty string)',-255) 
     1234      err = error('internal error (empty string)',-255)
    12061235      RETURN
    12071236    ENDIF
     
    12181247          res = ap_check_string(this,"-"//elt(j:j),arg_idx)
    12191248          ! great we have another short option flag
    1220           IF (res == -1 .AND. arg_idx /= -1) THEN ! another short option ! 
     1249          IF (res == -1 .AND. arg_idx /= -1) THEN ! another short option !
    12211250            rhelp = (this%args(arg_idx)%paction == ap_help.OR.rhelp)
    12221251            ! we must not set some argument's values here  for help argument
    1223             ! if auto is not set the parse method will disable the option 
     1252            ! if auto is not set the parse method will disable the option
    12241253            ! during next! parsing process
    12251254            CALL words_append(new_cmd,"-"//elt(j:j))
     
    12371266        rhelp = (this%args(arg_idx)%paction == ap_help.OR.rhelp)
    12381267        ! we must not set some argument's values here for help argument
    1239         ! if auto is not set the parse method will disable the option during 
     1268        ! if auto is not set the parse method will disable the option during
    12401269        ! next parsing process
    12411270        CALL words_append(new_cmd,TRIM(elt))
     
    12471276    RETURN
    12481277  END FUNCTION ap_split_cmd
    1249    
     1278
    12501279  FUNCTION ap_check_string(this,string,idx) RESULT(ret)
    12511280    !! Check if a string is an option flag
     
    12591288    INTEGER, INTENT(out), OPTIONAL             :: idx
    12601289      !! An optional output intger with the index of the afferent argument in the parser (-1 if not found)
    1261     INTEGER :: ret 
     1290    INTEGER :: ret
    12621291      !! Return code with the following possible values:
    12631292      !! - -1 if the string is a SHORT option flag
     
    12721301    ! The combination of the (optional) output index and the return code
    12731302    ! allows to check if an option is known or not
    1274     ret = 1 
     1303    ret = 1
    12751304    ! '--' is special : it is a separator that is seen as a value.
    12761305    IF (TRIM(string) == '--') RETURN
     
    13031332    CHARACTER(len=:), ALLOCATABLE :: copt,spc,opts,text
    13041333    INTEGER                       :: i,j,ia,optmw,i1,io,n,zw,zh
    1305     IF (this%width == 0) CALL fs_termsize(zh,this%width) 
     1334    IF (this%width == 0) CALL fs_termsize(zh,this%width)
    13061335    zw = this%width
    13071336    ! Sets usage
     
    13121341    hlp = TRIM(this%usg)//NEW_LINE('A')//NEW_LINE('A')
    13131342    ! Sets description
    1314     IF (LEN_TRIM(this%descr) /= 0) & 
     1343    IF (LEN_TRIM(this%descr) /= 0) &
    13151344      hlp=hlp//getpar(this%descr,zw,2)//NEW_LINE('A')//NEW_LINE('A')
    13161345    ! Sets positionals
     
    13801409    !! Format command line usage.
    13811410    !!
    1382     !! The subroutine creates and formats the command line usage of the 
    1383     !! given argparser object. If [[argparser(type):usg(variable)]] is already set (i.e. not empty) 
    1384     !! then the method only computes the maximum width of the option part of the usage command 
    1385     !! (see `optmw` argument description) if needed. In the other case, the method builds the usage 
     1411    !! The subroutine creates and formats the command line usage of the
     1412    !! given argparser object. If [[argparser(type):usg(variable)]] is already set (i.e. not empty)
     1413    !! then the method only computes the maximum width of the option part of the usage command
     1414    !! (see `optmw` argument description) if needed. In the other case, the method builds the usage
    13861415    !! line based on the arguments stored in the parser.
    13871416    OBJECT(argparser), INTENT(inout) :: this
    13881417      !! An argparser object reference
    13891418    INTEGER, INTENT(out), OPTIONAL   :: optmw
    1390       !! An optional integer with the maximum length of the option part of the usage command. 
     1419      !! An optional integer with the maximum length of the option part of the usage command.
    13911420      !! This variable is intended to set a fancy indentation while printing option in the helper.
    13921421    CHARACTER(len=:), ALLOCATABLE :: usage, idts, copt,pgn
     
    14281457          usage = usage(:)//TRIM(copt)
    14291458        ENDIF
    1430       ENDIF 
     1459      ENDIF
    14311460      this%usg = usage
    14321461    ELSE
     
    14391468        optmw = omw
    14401469      ENDIF
    1441     ENDIF 
     1470    ENDIF
    14421471  END SUBROUTINE ap_format_usage
    14431472
     
    14621491    IF (ALLOCATED(other%descr)) this%descr = other%descr
    14631492    IF (ALLOCATED(other%eplg))  this%eplg  = other%eplg
     1493    IF (ALLOCATED(other%vers))  this%vers  = other%vers
    14641494#else
    14651495    this%usg   = other%usg
    14661496    this%descr = other%descr
    14671497    this%eplg  = other%eplg
     1498    this%vers  = other%vers
    14681499#endif
    14691500    this%mxhlpos = other%mxhlpos
     
    15071538  FUNCTION ac_equals_arg(this,other) RESULT(ret)
    15081539    !! Check if two arguments are identical
    1509     !! The method checks if two arguments are equal based on their name, short option flag and long 
    1510     !! option flag.Two arguments are considered equals if at least one of these three members is equal 
     1540    !! The method checks if two arguments are equal based on their name, short option flag and long
     1541    !! option flag.Two arguments are considered equals if at least one of these three members is equal
    15111542    !! and not empty.
    15121543    TYPE(argc), INTENT(in) :: this
     
    15291560    tlf=TRIM(this%lflag) ; olf=TRIM(other%lflag)
    15301561#endif
    1531     tn=LEN_TRIM(tna) ; on=LEN_TRIM(ona) 
     1562    tn=LEN_TRIM(tna) ; on=LEN_TRIM(ona)
    15321563    tl=LEN_TRIM(tlf) ; ol=LEN_TRIM(olf)
    1533     ts=LEN_TRIM(tsf) ; os=LEN_TRIM(osf) 
     1564    ts=LEN_TRIM(tsf) ; os=LEN_TRIM(osf)
    15341565    ! check on name :
    15351566    ! Returns True if at least of name, sflag and lflag is set to non-empty
     
    15371568    ret = ((tn/=0 .AND. on==tn) .AND. tna == ona) .OR. &
    15381569          ((tl/=0 .AND. ol==tl) .AND. tlf == olf) .OR. &
    1539           ((ts/=0 .AND. os==ol) .AND. tsf == osf) 
     1570          ((ts/=0 .AND. os==ol) .AND. tsf == osf)
    15401571    DEALLOCATE(tna,ona,tsf,osf,tlf,olf)
    15411572  END FUNCTION ac_equals_arg
     
    15431574  FUNCTION ac_differs_arg(this,other) RESULT(ret)
    15441575    !! Check if two arguments are different
    1545     !! The method checks if two arguments are different based on their names, short option flag 
     1576    !! The method checks if two arguments are different based on their names, short option flag
    15461577    !! and long option flag.
    1547     !! @note 
     1578    !! @note
    15481579    !! This function is the extact contrary of [[argparse(module):ac_equals_arg(function)]] !
    15491580    TYPE(argc), INTENT(in) :: this
     
    15581589  SUBROUTINE ac_clear_arg_sc(arg)
    15591590    !! argc destructor (scalar)
    1560     !! The subroutine frees all memory used by an argc object and resets its member to 
     1591    !! The subroutine frees all memory used by an argc object and resets its member to
    15611592    !! default values.
    15621593    TYPE(argc), INTENT(inout) :: arg
     
    16061637      args(i)%lflag   = ""
    16071638#endif
    1608     ENDDO 
     1639    ENDDO
    16091640  END SUBROUTINE ac_clear_arg_ve
    16101641
     
    16221653    TYPE(argc), INTENT(in) :: this
    16231654      !! An argc object
    1624     INTEGER :: num 
     1655    INTEGER :: num
    16251656      !! The number of values stored in the argument
    16261657    num = words_length(this%values)
     
    16291660  FUNCTION ac_get_usg_opt_str(arg) RESULT(line)
    16301661    !! Build and format the option string for the usage part of the help message
    1631     !! The function is private part of the help builder. It creates the 
     1662    !! The function is private part of the help builder. It creates the
    16321663    !! option string part of a given argument.
    16331664    TYPE(argc), INTENT(in), TARGET :: arg
     
    16611692  FUNCTION ac_get_opt_str(arg) RESULT(line)
    16621693    !! Build and format the option flag string for the option part of the help message
    1663     !! The function is private part of the help builder. It creates the 
     1694    !! The function is private part of the help builder. It creates the
    16641695    !! option string part of a given argument for the options part of the help.
    16651696    TYPE(argc), INTENT(in), TARGET :: arg
     
    17011732    !! The function formats argparse specific errors when extra (missing) values
    17021733    !! are (not) set or when given values are not consistent with argument's type.
    1703     !! For each of these errors, the basic error is updated with a more precise 
    1704     !! message. 
     1734    !! For each of these errors, the basic error is updated with a more precise
     1735    !! message.
    17051736    TYPE(argc), INTENT(in) :: arg
    17061737      !! An argc object
     
    17231754        IF (arg%nrec == -2) THEN
    17241755          msg = msg//' takes at least '//nv//' value(s))'
    1725         ELSE 
     1756        ELSE
    17261757          msg = msg//' takes exactly '//nv//' value(s))'
    17271758        ENDIF
    17281759      CASE (-18) ! extra values -> -18
    1729         IF (arg%nrec == -3) THEN 
     1760        IF (arg%nrec == -3) THEN
    17301761          msg = msg//' takes at most '//nv//' value(s))'
    17311762        ELSE
     
    17401771  FUNCTION ac_check_and_set(this,sf,lf,ty,ac,de,na,meta,check_flag) RESULT(ret)
    17411772    !! Interface to all argc's member tests
    1742     !! The function calls all the tests to perform on argc members. Some of these tests can 
    1743     !! alter argc's member values to fit argparser's requirements. 
     1773    !! The function calls all the tests to perform on argc members. Some of these tests can
     1774    !! alter argc's member values to fit argparser's requirements.
    17441775    !!
    1745     !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only 
     1776    !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only
    17461777    !! produced by misuse of the function arguments. In such case, the program should be
    17471778    !! stopped: note that such ezrror should not occur in _released_ programs.
     
    17631794      !! An optional vector of strings with the Meta-name of the values
    17641795    LOGICAL, INTENT(in), OPTIONAL                        :: check_flag
    1765       !! An optional boolean flag hat instructs the method wether to check for option flag 
    1766       !! or not. By default this test is enabled but it should be disabled if one wants to 
     1796      !! An optional boolean flag hat instructs the method wether to check for option flag
     1797      !! or not. By default this test is enabled but it should be disabled if one wants to
    17671798      !! check for POSITIONAL arguments as they do not have option flags.
    17681799    TYPE(error) :: ret
     
    17891820  FUNCTION ac_check_ac_ty_de_na(this,ac,ty,de,na) RESULT(ret)
    17901821    !! Check and set argc's action, type and default value
    1791     !! The method checks if input argument's options are valid and update the argc object 
    1792     !! consequently. 
     1822    !! The method checks if input argument's options are valid and update the argc object
     1823    !! consequently.
    17931824    !!
    1794     !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only 
     1825    !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only
    17951826    !! produced by misuse of the function arguments.
    17961827    TYPE(argc), INTENT(inout)  :: this
    17971828      !! An argc object to update
    17981829    INTEGER, INTENT(in)          :: ac
    1799       !! An integer with the action to set and check 
     1830      !! An integer with the action to set and check
    18001831    INTEGER, INTENT(in)          :: ty
    18011832      !! An integer with the type to set and check
    18021833    CHARACTER(len=*), INTENT(in) :: de
    18031834      !! A string with the default value to set and check
    1804     CHARACTER(len=*), INTENT(in) :: na 
     1835    CHARACTER(len=*), INTENT(in) :: na
    18051836      !! A string with the expected number of value to set and check
    18061837    TYPE(error) :: ret
     
    18101841    ret = noerror
    18111842    eprf = 'argparse: '//"Invalid argument `"//TRIM(this%name)//"'"
    1812     uty = error(eprf//" (type)",-9) 
     1843    uty = error(eprf//" (type)",-9)
    18131844    ina = error(eprf//" (inconsistent nargs)",-9)
    18141845    zna = TRIM(na)
    18151846    ! Checks action
    18161847    IF(ANY(ap_actions == ac).OR.ac == ap_undef) THEN
    1817       this%paction = ac 
     1848      this%paction = ac
    18181849    ELSE
    1819       ret = error(eprf//" (action)",-9) ; RETURN 
     1850      ret = error(eprf//" (action)",-9) ; RETURN
    18201851    ENDIF
    18211852    ! Checks and sets type and default as a function of the action
    18221853    SELECT CASE(this%paction)
    1823       ! HELP: fixed in any case: 
     1854      ! HELP: fixed in any case:
    18241855      CASE(ap_help)
    18251856        this%default = 'F'
    18261857        this%ptype = ap_logical
    18271858        this%nrec = 0
     1859      ! VERSION: fixed in any case:
     1860      CASE(ap_version)
     1861        this%default = 'F'
     1862        this%ptype = ap_logical
     1863        this%nrec = 0
    18281864      ! COUNT:
    1829       ! we always use "hard-coded" stuff and do not warn if dev has made
    1830       ! mistakes...
     1865      ! we always use "hard-coded" stuff and do not warn if dev has made mistakes...
    18311866      CASE(ap_count)
    18321867        ! default settings of the count action
     
    18351870        ret = set_def_val()
    18361871      ! STORE, APPEND actions
    1837       CASE (ap_store, ap_append) 
    1838         ! set type 
     1872      CASE (ap_store, ap_append)
     1873        ! set type
    18391874        IF (ty == ap_undef) THEN
    1840           this%ptype= ap_integer 
     1875          this%ptype= ap_integer
    18411876        ELSEIF (ANY(ap_types == ty)) THEN
    18421877          this%ptype = ty
     
    18471882        ret = set_def_val() ; IF (ret /= 0) RETURN
    18481883        ! check for nargs (if na is empty then we set "*")
    1849         ret = set_nrec("*") 
     1884        ret = set_nrec("*")
    18501885      ! UNDEFINED:
    18511886      !   -> 1) set to action to store
     
    18551890      CASE (ap_undef)
    18561891        ! 1) always define store action
    1857         this%paction = ap_store 
     1892        this%paction = ap_store
    18581893        ! 2) set type and nrec:
    18591894        !    2.1) If type is undef:
    18601895        !         - to default value type if default is given
    1861         !         - ap_logical otherwiset type 
     1896        !         - ap_logical otherwiset type
    18621897        !    2.2) set nrec
    18631898        !        - if final type is ap_logical set nrec to 0
     
    18651900        If (ty == ap_undef) THEN
    18661901          ! no explicit type : define logical trigger first
    1867           this%ptype = ap_logical ; this%nrec = 0 
     1902          this%ptype = ap_logical ; this%nrec = 0
    18681903          ! icheck the default value given
    18691904          IF (LEN_TRIM(de) > 0) THEN
     
    18731908          ENDIF
    18741909          IF (this%ptype == ap_logical) THEN
    1875             ret = set_nrec("0") 
     1910            ret = set_nrec("0")
    18761911          ELSE
    1877             ret = set_nrec("1") 
     1912            ret = set_nrec("1")
    18781913          ENDIF
    1879           ret = set_def_val() 
     1914          ret = set_def_val()
    18801915          IF (ret /= 0) RETURN
    18811916        ! type is given
     
    18831918          ! known type given :
    18841919          !  check default value and nrec: -> if na not given set "*"
    1885           this%ptype = ty 
     1920          this%ptype = ty
    18861921          ret = set_def_val() ; IF (ret /= 0) RETURN
    18871922          IF (this%ptype == ap_logical) THEN
    1888             ret = set_nrec("0") 
     1923            ret = set_nrec("0")
    18891924          ELSE
    18901925            ret = set_nrec("1")
     
    18921927        ELSE
    18931928          ! unknown type => bad end !
    1894           ret = uty ; RETURN 
     1929          ret = uty ; RETURN
    18951930        ENDIF
    1896     END SELECT 
     1931    END SELECT
    18971932    ! set default value as first value if ret is noerror ....
    18981933    IF (ret == 0) CALL words_append(this%values,this%default)
     
    19041939        !! Check and set argument's expected number of records
    19051940        !! The method compares `na` value with the expected and known flags and decides
    1906         !! wether to raise an error or defines nrec member of the argument object. If `na` 
     1941        !! wether to raise an error or defines nrec member of the argument object. If `na`
    19071942        !! is empty then `base` is used.
    19081943        CHARACTER(len=1),INTENT(in) :: base
     
    19211956            ! check numeric characters
    19221957            IF (VERIFY(zna,"0123456789")==0) READ(zna,*) this%nrec
    1923             IF (this%nrec == 0) terr = ina 
     1958            IF (this%nrec == 0) terr = ina
    19241959        END SELECT
    19251960      END FUNCTION set_nrec
     
    19271962      FUNCTION set_def_val() RESULT(terr)
    19281963        !! Check and set argument's default value
    1929         !! The method compares `de` value with the type already stored in the argument and 
     1964        !! The method compares `de` value with the type already stored in the argument and
    19301965        !! decides wether to raise an error or to save `de` as argument's default value.
    19311966        !! If `de` is empty then it sets a default value according to argument's type.
     
    19351970        terr = noerror
    19361971        IF (LEN_TRIM(de) /= 0) THEN
    1937           this%default = de ; t = string_is(de) 
     1972          this%default = de ; t = string_is(de)
    19381973          IF (t /= this%ptype) THEN
    19391974            terr = error(eprf//" (inconsistent default value: expected '"// &
     
    19521987        ENDIF
    19531988        RETURN
    1954       END FUNCTION set_def_val 
     1989      END FUNCTION set_def_val
    19551990  END FUNCTION ac_check_ac_ty_de_na
    19561991
     
    19692004    CHARACTER(len=2), INTENT(in) :: sflag
    19702005      !! A 2-characters wide string with the short option flag
    1971     CHARACTER(len=*), INTENT(in) :: lflag 
     2006    CHARACTER(len=*), INTENT(in) :: lflag
    19722007      !! A string (at least 3 characters wide) with the long option flag
    19732008    TYPE(error) :: ret
     
    20172052    !! Set meta-variable of the given argc object
    20182053    !! The method set meta-variable in the argc object. If no `meta` are given, the method
    2019     !! uses argument's name to set the values. 
     2054    !! uses argument's name to set the values.
    20202055    !! @warning
    20212056    !! To be effective, this subroutine must be called after argparse::chk_opt_nargs
     
    20422077            j=j+1 ; IF (j>ms) j=1
    20432078            zmeta = to_upper(meta(j))
    2044             blk=INDEX(TRIM(zmeta),CHAR(32))-1 
     2079            blk=INDEX(TRIM(zmeta),CHAR(32))-1
    20452080            IF (blk <= 0) blk=LEN_TRIM(zmeta)
    20462081            CALL words_append(this%meta,zmeta(1:blk))
     
    20632098  FUNCTION ac_check_value(this,str) RESULT(err)
    20642099    !! Check if given string is a valid value for the argument
    2065     TYPE(argc), INTENT(in)       :: this 
     2100    TYPE(argc), INTENT(in)       :: this
    20662101      !! An argc object reference
    20672102    CHARACTER(len=*), INTENT(in) :: str
     
    20932128  FUNCTION ap_get_positional_sc(this,idx,value) RESULT(ret)
    20942129    !! Get positional arguments value at given index
    2095     !! @warning 
     2130    !! @warning
    20962131    !! On error, the status of `value` is undefined.
    20972132    OBJECT(argparser), INTENT(in)              :: this
     
    21002135      !! Subscript of the positional argument value to get
    21012136    CHARACTER(len=:), INTENT(out), ALLOCATABLE :: value
    2102       !! Output raw value of the positional. If `idx` is out of range, `value` is set to an 
     2137      !! Output raw value of the positional. If `idx` is out of range, `value` is set to an
    21032138      !! empty string.
    21042139    TYPE(error) :: ret
     
    21172152  FUNCTION ap_get_positional_ve(this,values) RESULT(ret)
    21182153    !! Get all positional arguments value
    2119     !! @warning 
     2154    !! @warning
    21202155    !! On error, the status of `values` is undefined.
    21212156    OBJECT(argparser), INTENT(in)                                  :: this
    21222157      !! An argparser object reference
    21232158    CHARACTER(len=st_slen), INTENT(out), ALLOCATABLE, DIMENSION(:) :: values
    2124       !! An allocatable vector of **assumed length** strings with the value(s) of all 
    2125       !! positionals arguments found. 
     2159      !! An allocatable vector of **assumed length** strings with the value(s) of all
     2160      !! positionals arguments found.
    21262161    TYPE(error) :: ret
    21272162      !! Error object with the first error encountered in the process
     
    25322567
    25332568  !> Gets a scalar @p REAL(kind=8) value from given argument
    2534   !! @param[in,out] this An argc object 
     2569  !! @param[in,out] this An argc object
    25352570  !! @param[out] output A scalar with the first value of the argument
    25362571  !! @return An errors::error object with -21 if the destination variable's type
     
    25382573  FUNCTION ac_get_dv_sc(this, output) RESULT(ret)
    25392574    !! Get a scalar `REAL(kind=8)` value from given argument
    2540     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2575    !! If no error occured, the function always returns at least a value (whatever the parser's
    25412576    !! state is) which is the default value if no specific values are set in the argument.
    25422577    !! Otherwise, `output` value is undefined.
     
    25632598  FUNCTION ac_get_rv_sc(this, output) RESULT(ret)
    25642599    !! Get a scalar `REAL(kind=4)` value from given argument
    2565     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2600    !! If no error occured, the function always returns at least a value (whatever the parser's
    25662601    !! state is) which is the default value if no specific values are set in the argument.
    25672602    !! Otherwise, `output` value is undefined.
     
    25882623  FUNCTION ac_get_iv_sc(this, output) RESULT(ret)
    25892624    !! Get a scalar `INTEGER` value from given argument
    2590     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2625    !! If no error occured, the function always returns at least a value (whatever the parser's
    25912626    !! state is) which is the default value if no specific values are set in the argument.
    25922627    !! Otherwise, `output` value is undefined.
     
    26132648  FUNCTION ac_get_lv_sc(this, output) RESULT(ret)
    26142649    !! Get a scalar `INTEGER` value from given argument
    2615     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2650    !! If no error occured, the function always returns at least a value (whatever the parser's
    26162651    !! state is) which is the default value if no specific values are set in the argument.
    26172652    !! Otherwise, `output` value is undefined.
     
    26382673  FUNCTION ac_get_cv_sc(this, output) RESULT(ret)
    26392674    !! Get a scalar `COMPLEX` value from given argument
    2640     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2675    !! If no error occured, the function always returns at least a value (whatever the parser's
    26412676    !! state is) which is the default value if no specific values are set in the argument.
    26422677    !! Otherwise, `output` value is undefined.
     
    26632698  FUNCTION ac_get_sv_sc(this, output) RESULT(ret)
    26642699    !! Get a scalar `STRING` value from given argument
    2665     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2700    !! If no error occured, the function always returns at least a value (whatever the parser's
    26662701    !! state is) which is the default value if no specific values are set in the argument.
    26672702    !! Otherwise, `output` status is undefined.
     
    26852720  FUNCTION ac_get_dv_ve(this, output) RESULT(ret)
    26862721    !! Get a vector of `REAL(kind=8)` values from given argument
    2687     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2722    !! If no error occured, the function always returns at least a value (whatever the parser's
    26882723    !! state is) which is the default value if no specific values are set in the argument.
    26892724    !! Otherwise, `output` status is undefined.
     
    27142749  FUNCTION ac_get_rv_ve(this, output) RESULT(ret)
    27152750    !! Get a vector of `REAL(kind=4)` values from given argument
    2716     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2751    !! If no error occured, the function always returns at least a value (whatever the parser's
    27172752    !! state is) which is the default value if no specific values are set in the argument.
    27182753    !! Otherwise, `output` status is undefined.
     
    27432778  FUNCTION ac_get_iv_ve(this, output) RESULT(ret)
    27442779    !! Get a vector of `INTEGER` values from given argument
    2745     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2780    !! If no error occured, the function always returns at least a value (whatever the parser's
    27462781    !! state is) which is the default value if no specific values are set in the argument.
    27472782    !! Otherwise, `output` status is undefined.
     
    27722807  FUNCTION ac_get_lv_ve(this, output) RESULT(ret)
    27732808    !! Get a vector of `LOGICAL` values from given argument
    2774     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2809    !! If no error occured, the function always returns at least a value (whatever the parser's
    27752810    !! state is) which is the default value if no specific values are set in the argument.
    27762811    !! Otherwise, `output` status is undefined.
     
    28012836  FUNCTION ac_get_cv_ve(this, output) RESULT(ret)
    28022837    !! Get a vector of `COMPLEX` values from given argument
    2803     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2838    !! If no error occured, the function always returns at least a value (whatever the parser's
    28042839    !! state is) which is the default value if no specific values are set in the argument.
    28052840    !! Otherwise, `output` status is undefined.
     
    28302865  FUNCTION ac_get_sv_ve(this, output) RESULT(ret)
    28312866    !! Get a vector of `STRING` values from given argument
    2832     !! If no error occured, the function always returns at least a value (whatever the parser's 
     2867    !! If no error occured, the function always returns at least a value (whatever the parser's
    28332868    !! state is) which is the default value if no specific values are set in the argument.
    28342869    !! Otherwise, `output` status is undefined.
     
    28722907
    28732908  FUNCTION apa2str(ap_a) RESULT(str)
    2874     !! Get the string representation of argparse actions constants 
     2909    !! Get the string representation of argparse actions constants
    28752910    INTEGER, INTENT(in) :: ap_a
    28762911     !! One of ap_store, ap_append,cap_count or ap_help module constants
     
    28822917      CASE(ap_count)  ; str = 'count'
    28832918      CASE(ap_help)   ; str = 'help'
     2919      CASE(ap_version); str = 'version'
    28842920      CASE DEFAULT    ; str = 'unknown'
    28852921    END SELECT
Note: See TracChangeset for help on using the changeset viewer.