Index: trunk/LMDZ.TITAN/libf/muphytitan/argparse.F90
===================================================================
--- trunk/LMDZ.TITAN/libf/muphytitan/argparse.F90	(revision 1897)
+++ trunk/LMDZ.TITAN/libf/muphytitan/argparse.F90	(revision 3083)
@@ -1,39 +1,27 @@
-! Copyright Jérémie Burgalat (2010-2015,2017)
-! 
-! jeremie.burgalat@univ-reims.fr
-! 
-! This software is a computer program whose purpose is to provide configuration 
-! file and command line arguments parsing features to Fortran programs.
-! 
-! This software is governed by the CeCILL-B license under French law and
-! abiding by the rules of distribution of free software.  You can  use, 
-! modify and/ or redistribute the software under the terms of the CeCILL-B
-! license as circulated by CEA, CNRS and INRIA at the following URL
-! "http://www.cecill.info". 
-! 
-! As a counterpart to the access to the source code and  rights to copy,
-! modify and redistribute granted by the license, users are provided only
-! with a limited warranty  and the software's author,  the holder of the
-! economic rights,  and the successive licensors  have only  limited
-! liability. 
-! 
-! In this respect, the user's attention is drawn to the risks associated
-! with loading,  using,  modifying and/or developing or reproducing the
-! software by the user in light of its specific status of free software,
-! that may mean  that it is complicated to manipulate,  and  that  also
-! therefore means  that it is reserved for developers  and  experienced
-! professionals having in-depth computer knowledge. Users are therefore
-! encouraged to load and test the software's suitability as regards their
-! requirements in conditions enabling the security of their systems and/or 
-! data to be ensured and,  more generally, to use and operate it in the 
-! same conditions as regards security. 
-! 
-! The fact that you are presently reading this means that you have had
-! knowledge of the CeCILL-B license and that you accept its terms.
+! Copyright (c) (2013-2015,2017) Jeremie Burgalat (jeremie.burgalat@univ-reims.fr).
+!
+! This file is part of SWIFT
+!
+! Permission is hereby granted, free of charge, to any person obtaining a copy of
+! this software and associated documentation files (the "Software"), to deal in
+! the Software without restriction, including without limitation the rights to
+! use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+! the Software, and to permit persons to whom the Software is furnished to do so,
+! subject to the following conditions:
+!
+! The above copyright notice and this permission notice shall be included in all
+! copies or substantial portions of the Software.
+!
+! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+! FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+! COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+! IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+! CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 !! file: argparse.F90
 !! summary: Command-line parser source file.
 !! author: J. Burgalat
-!! date: 2013-2015,2017
+!! date: 2013-2015,2017,2022
 
 #include "defined.h"
@@ -45,5 +33,5 @@
   !! For your own sanity, private methods that call Ancient Gods powers through
   !! evil black magic rituals are not described here.
-  !! 
+  !!
   !! If you only wish to have an overview of argparse usage, you'd better go
   !! [here](|url|/page/swift/p01_argparse.html).
@@ -52,5 +40,5 @@
   USE ERRORS
   USE FSYSTEM, ONLY : fs_termsize
-  USE STRING_OP, getpar => format_paragraph, splitstr  => format_string  
+  USE STRING_OP, getpar => format_paragraph, splitstr  => format_string
   IMPLICIT NONE
 
@@ -68,5 +56,5 @@
             argparser_add_option,       &
             argparser_add_positionals,  &
-            argparser_throw_error,      & 
+            argparser_throw_error,      &
             argparser_parse,            &
             argparser_help,             &
@@ -85,5 +73,5 @@
   ! ===========================
 
-  INTEGER, PARAMETER, PUBLIC :: ap_string  = st_string 
+  INTEGER, PARAMETER, PUBLIC :: ap_string  = st_string
     !! String value type identifier.
   INTEGER, PARAMETER, PUBLIC :: ap_complex = st_complex
@@ -98,30 +86,33 @@
   !> List of all available actions
 
-  INTEGER, PARAMETER, PUBLIC :: ap_store  = 1 
+  INTEGER, PARAMETER, PUBLIC :: ap_store   = 1
     !! store action ID : Each time the option is seen, values are replaced.
-  INTEGER, PARAMETER, PUBLIC :: ap_append = 2 
-    !! append action ID : Each time the option is seen, values are appended. 
-  INTEGER, PARAMETER, PUBLIC :: ap_count  = 3 
+  INTEGER, PARAMETER, PUBLIC :: ap_append  = 2
+    !! append action ID : Each time the option is seen, values are appended.
+  INTEGER, PARAMETER, PUBLIC :: ap_count   = 3
     !! count action ID : increase a counter each time the option is seen.
-  INTEGER, PARAMETER, PUBLIC :: ap_help   = 4 
+  INTEGER, PARAMETER, PUBLIC :: ap_help    = 4
     !! help action ID : help is requested !
+  INTEGER, PARAMETER, PUBLIC :: ap_version = 5
+    !! version action ID : version is requested !
 
   !> List of all available actions
-  INTEGER, DIMENSION(4), PARAMETER, PRIVATE :: ap_actions = (/ap_store,  &
+  INTEGER, DIMENSION(5), PARAMETER, PRIVATE :: ap_actions = (/ap_store,  &
                                                               ap_append, &
                                                               ap_count,  &
-                                                              ap_help/)
+                                                              ap_help,   &
+                                                              ap_version/)
   !> List of all recognized types by the parser
-  INTEGER, DIMENSION(5), PARAMETER, PRIVATE :: ap_types = (/ap_string,  & 
+  INTEGER, DIMENSION(5), PARAMETER, PRIVATE :: ap_types = (/ap_string,  &
                                                             ap_logical, &
                                                             ap_complex, &
                                                             ap_integer, &
-                                                            ap_real/) 
+                                                            ap_real/)
   !> The unknown flag
   !!
-  !! This flag is only intended to initialize flags. It is set by default during initialization 
+  !! This flag is only intended to initialize flags. It is set by default during initialization
   !! and quielty replaced by default flags, if user does not provide the relevant feature.
   INTEGER, PARAMETER :: ap_undef = -1
-    
+
   !> Add an option to the parser
   !!
@@ -131,11 +122,11 @@
   !! ```
   !!
-  !! The function defines a new argument based on input parameters, checks it and finally sets it 
-  !! in the parser. 
-  !! 
+  !! The function defines a new argument based on input parameters, checks it and finally sets it
+  !! in the parser.
+  !!
   !! In its first version both short (`sflag`) and long (`lflag`) options flags are mandatory. In its second
   !! form, a single flag (`flag`) is expected: the method will automatically deduce if it belongs to short or
   !! a long option flag based on the number of hyphens given.
-  !! 
+  !!
   !! `type` value should be one of the following module constants (which are aliases from [[string_op(module)]]):
   !!
@@ -145,5 +136,5 @@
   !! - `ap_integer` ([[string_op(module):st_integer(variable)]])
   !! - `ap_real` ([[string_op(module):st_real(variable)]])
-  !! 
+  !!
   !! `action` value should be one of the following module constants:
   !!
@@ -162,5 +153,5 @@
   !!  "X"  | Exactly X values. Where X is the string representation of an integer (0 is accepted).
   !!
-  !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only 
+  !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only
   !! produced by misuse of the function arguments. In such case, the program should be
   !! stopped: note that such error should not occur in _released_ programs.
@@ -168,9 +159,9 @@
     MODULE PROCEDURE ap_add_option_1, ap_add_option_2
   END INTERFACE
-  
+
   !> Get positional argument value(s)
   INTERFACE argparser_get_positional
     MODULE PROCEDURE ap_get_positional_sc, ap_get_positional_ve
-  END INTERFACE 
+  END INTERFACE
 
   !> Get optional argument value(s)
@@ -179,13 +170,13 @@
   !! FUNCTION argparser_get_value(this,name,output) RESULT(err)
   !! ```
-  !! 
+  !!
   !! This is the generic method that can be used to retrieve any kind of argument value(s) from the parser for a given
   !! argument name (as defined by the `dest` argument of [[argparse(module):argparser_add_option(interface)]].
   !! All the methods have the same dummy arguments only `output` dummy argument differs in type and shape.
-  !! 
+  !!
   !! @note
   !! For string vector, `output` is expected to be an allocatable vector of **assumed length**
   !! strings (thus string length is left to user responsability).
-  !! A good compromise for strings length is to use the [[string_op(module):st_slen(variable)]] 
+  !! A good compromise for strings length is to use the [[string_op(module):st_slen(variable)]]
   !! parameter.
   INTERFACE argparser_get_value
@@ -197,7 +188,7 @@
   !> Interface to [[argparse(module):argc(type)]] getters
   !!
-  !! All the functions have the same prototype, only kind and type of arguments changed 
+  !! All the functions have the same prototype, only kind and type of arguments changed
   !! from a function to the other.
-  INTERFACE argc_get_value                    
+  INTERFACE argc_get_value
     MODULE PROCEDURE ac_get_dv_sc, ac_get_rv_sc, ac_get_iv_sc, ac_get_lv_sc, &
                      ac_get_cv_sc, ac_get_sv_sc, ac_get_dv_ve, ac_get_rv_ve, &
@@ -230,9 +221,9 @@
     !! Defines a command-line argument.
     !!
-    !! An [[argparse(module):argc(type)]] object stores all information about a command-line 
+    !! An [[argparse(module):argc(type)]] object stores all information about a command-line
     !! argument, that is:
     !!
     !! - its name
-    !! - its optional flags 
+    !! - its optional flags
     !! - its type
     !! - its action
@@ -253,10 +244,10 @@
     TYPE(words)      :: meta
       !! Meta variable name(s) of the argument
-#if HAVE_FTNDTSTR 
+#if HAVE_FTNDTSTR
     CHARACTER(len=:), ALLOCATABLE :: default
-      !! Default flag 
+      !! Default flag
     CHARACTER(len=:), ALLOCATABLE :: name
       !! Name of the argument (needed to check and retrieve its value(s))
-    CHARACTER(len=:), ALLOCATABLE :: lflag 
+    CHARACTER(len=:), ALLOCATABLE :: lflag
       !! Long flag option (st_short_len max chars !)
     CHARACTER(len=:), ALLOCATABLE :: help
@@ -264,5 +255,5 @@
 #else
     CHARACTER(len=st_slen) :: default = ""
-      !! Default flag 
+      !! Default flag
     CHARACTER(len=st_slen) :: name
       !! Name of the argument (needed to check and retrieve its value(s))
@@ -278,5 +269,5 @@
     !! Command-line parser
     !!
-    !! This is the main object of the module. It stores definitions of CLI arguments and 
+    !! This is the main object of the module. It stores definitions of CLI arguments and
     !! their value(s) once the command-line have been parsed.
     TYPE(argc), PRIVATE, ALLOCATABLE, DIMENSION(:) :: args
@@ -298,24 +289,28 @@
 #if HAVE_FTNDTSTR
     CHARACTER(len=:), PRIVATE, ALLOCATABLE :: usg
-      !! Program command usage 
+      !! Program command usage
     CHARACTER(len=:), PRIVATE, ALLOCATABLE :: descr
       !! Program help description
-    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: eplg 
+    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: eplg
       !! Program help epilog
+    CHARACTER(len=:), PRIVATE, ALLOCATABLE :: vers
+      !! Application version string
 #else
     CHARACTER(len=st_llen), PRIVATE :: usg
-      !! Program command usage 
+      !! Program command usage
     CHARACTER(len=st_llen), PRIVATE :: descr
       !! Program help description
-    CHARACTER(len=st_llen), PRIVATE :: eplg 
+    CHARACTER(len=st_llen), PRIVATE :: eplg
       !! Program help epilog
+    CHARACTER(len=st_llen), PRIVATE :: vers
+      !! Application version string
 #endif
-    INTEGER, PRIVATE :: mxhlpos = 20 
+    INTEGER, PRIVATE :: mxhlpos = 20
       !! Position of the short help for options
     INTEGER, PRIVATE :: width = 0
-      !! Maximum width of the help 
+      !! Maximum width of the help
     LOGICAL, PRIVATE :: init = .false.
       !! Initialization control flag
-#if HAVE_FTNPROC    
+#if HAVE_FTNPROC
 
     CONTAINS
@@ -341,6 +336,8 @@
     PROCEDURE, PUBLIC  :: parse              => argparser_parse
       !! Parse the command-line (or the given input string).
-    PROCEDURE, PUBLIC  :: help               => argparser_help  
+    PROCEDURE, PUBLIC  :: help               => argparser_help
       !! Compute and print help
+    PROCEDURE, PUBLIC  :: version            => argparser_version
+      !! print version string
     PROCEDURE, PUBLIC  :: found              => argparser_found
       !! Check if an optional argument has been found on the command-line
@@ -356,5 +353,5 @@
     GENERIC, PUBLIC    :: add_option         => ap_add_option_1, &
                                                 ap_add_option_2
-    !> Get the values of the positionals stored in the parser.                                                
+    !> Get the values of the positionals stored in the parser.
     GENERIC, PUBLIC    :: get_positional     => ap_get_positional_sc, &
                                                 ap_get_positional_ve
@@ -372,5 +369,5 @@
                                                 ap_get_cv_ve, &
                                                 ap_get_sv_ve
-#endif       
+#endif
   END TYPE argparser
 
@@ -380,9 +377,9 @@
   ! -------------------------------
 
-  FUNCTION new_argparser(usg, dsc, epg, add_help, width, max_help_pos) RESULT(this) 
+  FUNCTION new_argparser(usg, dsc, epg, add_help, add_version, version_string,width, max_help_pos) RESULT(this)
     !! Initialize an argparser object.
-    !! 
+    !!
     !! The method initializes (properly) an [[argparse(module):argparser(type)]] object.
-    !! Even if all the arguments are optional, it is mandatory to **call** the method 
+    !! Even if all the arguments are optional, it is mandatory to **call** the method
     !! before using an argparser object.
     CHARACTER(len=*), INTENT(in), OPTIONAL :: usg
@@ -394,14 +391,20 @@
       !! An optional string with the epilog of the program's help
     LOGICAL, INTENT(in), OPTIONAL          :: add_help
-      !! An optional boolean flag with `.true.` to automatically set an option for program's help. 
+      !! An optional boolean flag with `.true.` to automatically set an option for program's help.
       !! Note that, the option flags `-h` and `--help` are no more available in that case.
+    LOGICAL, INTENT(in), OPTIONAL          :: add_version
+      !! An optional boolean flag with `.true.` to automatically set an option for program's help.
+      !! Note that, the option flags `-V` and `--version` are no more available in that case.
+    CHARACTER(len=*), INTENT(in), OPTIONAL :: version_string
+      !! An optional string with the text to display if the *version* option is found on the
+      !! command line. The text is displayed without any format.
     INTEGER, INTENT(in), OPTIONAL          :: width
       !! An optional integer with the maximum width the help text.
     INTEGER, INTENT(in), OPTIONAL          :: max_help_pos
-      !! An optional integer with the maximum position of the help string for each option of 
-      !! the program when help is requested. Note that this value is just an indicator. The 
-      !! helper computes the minimum position between this value and the maximum length of the 
+      !! An optional integer with the maximum position of the help string for each option of
+      !! the program when help is requested. Note that this value is just an indicator. The
+      !! helper computes the minimum position between this value and the maximum length of the
       !! options flags.
-    TYPE(argparser) :: this 
+    TYPE(argparser) :: this
       !! An initialized argparse object.
     INTEGER     :: zh
@@ -413,5 +416,5 @@
     IF (PRESENT(dsc)) THEN ; this%descr=dsc ; ELSE ; this%descr='' ; ENDIF
     IF (PRESENT(epg)) THEN ; this%eplg=epg  ; ELSE ; this%eplg=''  ; ENDIF
-    CALL fs_termsize(zh,this%width) 
+    CALL fs_termsize(zh,this%width)
     IF (PRESENT(width)) this%width = MAX(width,50)
     IF(PRESENT(max_help_pos)) this%mxhlpos = MAX(5,max_help_pos)
@@ -422,4 +425,11 @@
                     action=ap_help, help="Print this help and quit")
     ENDIF
+    IF (PRESENT(add_version)) THEN
+      IF (add_version) &
+        err = argparser_add_option(this,'version',sflag='-V',lflag='--version', &
+                    action=ap_version, help="Print the application version and quit")
+      this%vers = ''
+      if (PRESENT(version_string)) this%vers = TRIM(version_string)
+    ENDIF
     RETURN
   END FUNCTION new_argparser
@@ -432,5 +442,5 @@
     !! @note If **fccp** has not been built with support for finalization subroutine,
     !! it should be called whenever the argparser object is no more used.
-    TYPE(argparser), INTENT(inout) :: this 
+    TYPE(argparser), INTENT(inout) :: this
       !! An argparser object
     IF (ALLOCATED(this%args)) THEN
@@ -466,5 +476,5 @@
     !!
     !! The method initializes the entry for positional arguments in the parser.
-    !! Positional arguments are always seen by the parser as strings and the 
+    !! Positional arguments are always seen by the parser as strings and the
     !! default associated action is 'store'.
     OBJECT(argparser), INTENT(inout)                     :: this
@@ -475,5 +485,5 @@
       !! A vector of strings with the the displayed value name(s) of the positionals in the help command
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: help
-      !! An optional string with a short description of the positional argument(s) 
+      !! An optional string with a short description of the positional argument(s)
     TYPE(error) :: err
       !! Error object with the first error encountered in the process.
@@ -481,6 +491,6 @@
     CHARACTER(len=:), ALLOCATABLE :: sf,lf,de
     err = noerror
-    IF (.NOT.this%init) THEN 
-      err = error("argparse: parser not initialized yet",-1) 
+    IF (.NOT.this%init) THEN
+      err = error("argparse: parser not initialized yet",-1)
       RETURN
     ENDIF
@@ -504,5 +514,5 @@
         RETURN
       ENDIF
-      this%have_posal = this%posals%nrec /= 0 
+      this%have_posal = this%posals%nrec /= 0
     ENDIF
     RETURN
@@ -514,7 +524,7 @@
     !! given as optional argument and fills the parser's arguments.
     !! @note
-    !! If `cmd_line` is provided it should not contains the name of the program or 
-    !! the parsing process will certainly failed: program name will be seen as the 
-    !! first positional argument and all tokens of the string will then be seen as 
+    !! If `cmd_line` is provided it should not contains the name of the program or
+    !! the parsing process will certainly failed: program name will be seen as the
+    !! first positional argument and all tokens of the string will then be seen as
     !! positional.
     OBJECT(argparser), INTENT(inout)       :: this
@@ -523,5 +533,5 @@
       !! An optional string to parse that substitute for the actual command-line.
     LOGICAL, INTENT(in), OPTIONAL          :: auto
-      !! An optional boolean flag with `.true.` to instruct the parser wether to perform 
+      !! An optional boolean flag with `.true.` to instruct the parser wether to perform
       !! automatic actions or not when error occur during parsing. If `auto` is enabled,
       !! then the parser dumps program's usage and stops the program on error.
@@ -530,6 +540,7 @@
     CHARACTER(len=:), ALLOCATABLE :: cline,z
     LOGICAL                       :: zauto
-    LOGICAL                       :: rhelp 
-    INTEGER                       :: l 
+    LOGICAL                       :: rhelp
+    LOGICAL                       :: rvers
+    INTEGER                       :: l
     TYPE(words)                   :: cmd_tokens
     err = noerror
@@ -537,10 +548,10 @@
       err = error("parser not initialized yet",-1) ; RETURN
     ENDIF
-    rhelp = .false.
+    rhelp = .false. ; rvers = .false.
     zauto = .false. ; IF (PRESENT(auto)) zauto = auto
     IF (PRESENT(cmd_line)) THEN
       ALLOCATE(cline,source=cmd_line)
     ELSE
-      CALL GET_COMMAND(length=l) 
+      CALL GET_COMMAND(length=l)
       ALLOCATE(CHARACTER(len=l) :: z) ; CALL GET_COMMAND(z)
       CALL GET_COMMAND_ARGUMENT(0,length=l)
@@ -557,5 +568,5 @@
         EXIT ! ... No :)
       ELSE
-        err = ap_split_cmd(this,cline,cmd_tokens,rhelp) 
+        err = ap_split_cmd(this,cline,cmd_tokens,rhelp)
         ! we only stops processing if :
         !   - the internal error (string length) is raised
@@ -565,11 +576,11 @@
       CALL words_reset(cmd_tokens) ! not mandatory... at least theoretically
       ! Parses the options
-      err = ap_parse_options(this,cmd_tokens,rhelp) 
+      err = ap_parse_options(this,cmd_tokens,rhelp,rvers)
       IF (err /= noerror) EXIT
-      ! exit loop if help is requested. Parser is not completely filled but we
-      ! expect someone to use the help action..
-      IF (rhelp) EXIT
+      ! exit loop if help or version is requested. Parser is not completely filled but we
+      ! expect someone to use the help or version actions...
+      IF (rhelp.OR.rvers) EXIT
       ! Parses positionals
-      err = ap_parse_positionals(this,cmd_tokens) 
+      err = ap_parse_positionals(this,cmd_tokens)
       EXIT ! A one iterated loop :)
     ENDDO
@@ -581,8 +592,18 @@
     IF (zauto) THEN
       IF (rhelp) CALL argparser_help(this)
+      IF (rvers) CALL argparser_version(this)
       IF (err /= 0) CALL argparser_throw_error(this,err,2)
     ENDIF
-    RETURN 
+    RETURN
   END FUNCTION argparser_parse
+
+  SUBROUTINE argparser_version(this)
+    !! Print version string and exit program
+    OBJECT(argparser), INTENT(inout) :: this
+      !! An argparser object reference
+    WRITE(stdout,'(a)') TRIM(this%vers)
+    CALL argparser_clear(this)
+    CALL EXIT(0)
+  END SUBROUTINE argparser_version
 
   SUBROUTINE argparser_help(this)
@@ -606,5 +627,5 @@
     !!
     !! The method performs the following actions:
-    !!  
+    !!
     !! - Print the usage command of the program
     !! - Dump the provided @p error message
@@ -614,5 +635,5 @@
     !!
     !! The error message is always printed in standard error output.
-    !! @note 
+    !! @note
     !! If errors::error::id is 0 the method does nothing.
     OBJECT(argparser), INTENT(inout) :: this
@@ -638,5 +659,5 @@
   FUNCTION argparser_found(this,argname) RESULT(found)
     !! Check wether an argument has been found in the command-line.
-    !! @note 
+    !! @note
     !! Keep in mind that arguments in the parser always have a default
     !! value. This method is not intended to check if an argument has a value but
@@ -663,5 +684,5 @@
     CHARACTER(len=*), INTENT(in)  :: argname
       !! Name of the argument to check.
-    INTEGER :: num 
+    INTEGER :: num
       !! The number of actual values stored in the argument
     INTEGER  :: idx
@@ -693,9 +714,9 @@
     INTEGER :: ret
       !! The number of actual positionals arguments
-    ret = 0 
+    ret = 0
     IF (this%have_posal) THEN
       ret = words_length(this%posals%values)
     ENDIF
-  END FUNCTION argparser_get_num_positional 
+  END FUNCTION argparser_get_num_positional
 
   ! argparser private methods
@@ -703,5 +724,5 @@
 
   FUNCTION ap_check_state(this) RESULT(err)
-    !! Check current parser state 
+    !! Check current parser state
     !! The method returns an error based on the current parser's state:
     !! - Parser is ready (0)
@@ -712,5 +733,5 @@
       !! An argparser object reference
     TYPE(error) :: err
-      !! Error object with the *status* of the parser 
+      !! Error object with the *status* of the parser
     err = noerror
     IF (this%parsed == -1) THEN
@@ -719,5 +740,5 @@
       err = error("argparse: command-line parsing failed",-20)
     ELSE IF (.NOT.this%init) THEN
-      err = error("argparse: parser not initialized yet",-1) 
+      err = error("argparse: parser not initialized yet",-1)
     ENDIF
     RETURN
@@ -732,5 +753,5 @@
     INTEGER                               :: i
     TYPE(argc), ALLOCATABLE, DIMENSION(:) :: tmp
-    TYPE(error) :: err 
+    TYPE(error) :: err
     IF (.NOT.this%init)  THEN
       err = error("parser not initialized yet",-1) ; RETURN
@@ -739,6 +760,6 @@
     IF (this%nargs == 0) THEN
       ALLOCATE(this%args(1))
-      this%args(1) = arg 
-      this%nargs = 1 
+      this%args(1) = arg
+      this%nargs = 1
       RETURN
     ENDIF
@@ -749,6 +770,6 @@
     ALLOCATE(tmp(this%nargs))
     DO i=1,this%nargs ; tmp(i) = this%args(i) ; ENDDO
-    CALL clear_argc(this%args) 
-    DEALLOCATE(this%args) 
+    CALL clear_argc(this%args)
+    DEALLOCATE(this%args)
     this%nargs = this%nargs+1 ; ALLOCATE(this%args(this%nargs))
     DO i=1,this%nargs-1 ; this%args(i) = tmp(i) ; ENDDO
@@ -782,5 +803,5 @@
     ! empty parser
     IF (this%nargs == 0) RETURN
-    DO i=1, this%nargs 
+    DO i=1, this%nargs
       IF ((nn /= 0 .AND. TRIM(this%args(i)%name)  == TRIM(lna)) .OR. &
           (ns /= 0 .AND. TRIM(this%args(i)%sflag) == TRIM(lsf)) .OR. &
@@ -796,7 +817,7 @@
     !! Add an argument to the parser (interface #1)
     !!
-    !! The function defines a new argument based on input parameters, checks it and finally sets it 
+    !! The function defines a new argument based on input parameters, checks it and finally sets it
     !! in the parser. Both **short and long options flags** are mandatory input arguments of the function.
-    !! 
+    !!
     !!  `type` value should be one of the following module constants (which are aliases from [[string_op(module)]]):
     !!  - ap_string ([[string_op(module):st_string(variable)]])
@@ -805,5 +826,5 @@
     !!  - ap_integer ([[string_op(module):st_integer(variable)]])
     !!  - ap_real ([[string_op(module):st_real(variable)]])
-    !! 
+    !!
     !!  `action` value should be one of the following module constants:
     !!  - [[argparse(module):ap_store(variable)]]
@@ -830,11 +851,11 @@
       !! A string (3 characters minimum) with the long option flag of the argument
     INTEGER, INTENT(in), OPTIONAL                        :: type
-      !! An integer with the type of the argument 
+      !! An integer with the type of the argument
     INTEGER, INTENT(in), OPTIONAL                        :: action
-      !! An integer with the action of the argument 
+      !! An integer with the action of the argument
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: default
       !! A string with the default value of the argument if not provided in the CLI
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: nrec
-      !! A string with the expected number of specified values for the argument in the CLI. 
+      !! A string with the expected number of specified values for the argument in the CLI.
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: help
       !! A string with a short description of the argument
@@ -853,5 +874,5 @@
     de =''        ; IF (PRESENT(default)) de = TRIM(default)
     IF (.NOT.this%init)  THEN
-      err = error("argparse: parser not initialized yet",-1) 
+      err = error("argparse: parser not initialized yet",-1)
       RETURN
     ENDIF
@@ -876,9 +897,9 @@
     !! Add an argument to the parser (interface #2)
     !!
-    !! The function is a wrapper to ap_add_option_1. In this version, 
+    !! The function is a wrapper to ap_add_option_1. In this version,
     !! only one option flag is required. The method only checks for the (trimmed) length of **flag** in
-    !! order to choose wether it is a **short** or **long** option flag. Then the function simply calls 
+    !! order to choose wether it is a **short** or **long** option flag. Then the function simply calls
     !! ap_add_option_1 to set the argument.
-    !! 
+    !!
     !! Other dummy arguments have the same meaning as in ap_add_option_1.
     OBJECT(argparser), INTENT(inout)                     :: this
@@ -891,9 +912,9 @@
       !! A string with the type of the argument
     INTEGER, INTENT(in), OPTIONAL                        :: action
-      !! A string with the action of the argument 
+      !! A string with the action of the argument
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: default
       !! A string with the default value of the argument if not provided in the CLI
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: nrec
-      !! A string with the expected number of specified values for the argument in the CLI. 
+      !! A string with the expected number of specified values for the argument in the CLI.
     CHARACTER(len=*), INTENT(in), OPTIONAL               :: help
       !! A string with a short description of the argument
@@ -956,7 +977,7 @@
   END FUNCTION ap_check_in_parser
 
-  FUNCTION ap_parse_options(this,cmd,help_req) RESULT(err)
+  FUNCTION ap_parse_options(this,cmd,help_req,vers_req) RESULT(err)
     !! Parse options of the internal command line
-    !! This (internal) function manages the parsing of the command line options. 
+    !! This (internal) function manages the parsing of the command line options.
     OBJECT(argparser), INTENT(inout), TARGET :: this
       !! An argparser object reference
@@ -965,4 +986,6 @@
     LOGICAL, INTENT(out)                     :: help_req
       !! An output logical flag with `.true.` if help option has been found, `.false.` otherwise
+    LOGICAL, INTENT(out)                     :: vers_req
+      !! An output logical flag with `.true.` if version option has been found, `.false.` otherwise
     TYPE(error) :: err
       !! Error object with the first error encountered in the process
@@ -976,13 +999,19 @@
       ! get current element
       elt = words_current(cmd)
-      ! check element kind: is it an option flag (-1/0)or a value (1)?
+      ! check element kind: is it an option flag (-1/0) or a value (1)?
       ic = ap_check_string(this,elt,arg_idx)
       IF (ic <= 0) THEN
         IF (arg_idx /= -1) THEN
           err = ap_fill_argument(this,cmd,this%args(arg_idx))
-          IF (err == 0 .AND. this%args(arg_idx)%paction == ap_help) THEN
-            this%parsed = 1
-            err = argparser_get_value(this,'help',help_req)
-            EXIT
+          IF (err == 0) THEN
+            IF (this%args(arg_idx)%paction == ap_help) THEN
+              this%parsed = 1
+              err = argparser_get_value(this,'help',help_req)
+              EXIT
+            ELSE IF (this%args(arg_idx)%paction == ap_version) THEN
+              this%parsed = 1
+              err = argparser_get_value(this,'version',vers_req)
+              EXIT
+            ENDIF
           ENDIF
           IF (err /= 0) EXIT
@@ -998,5 +1027,5 @@
       ! iterates to next value
       CALL words_next(cmd)
-    ENDDO 
+    ENDDO
 
     ! Do we need to check for error here ?
@@ -1020,16 +1049,16 @@
         IF (this%args(i)%nrec < nv) THEN
           err = ac_fmt_val_err(this%args(i),-18) ! extra values
-        ELSE 
+        ELSE
           err = ac_fmt_val_err(this%args(i),-17) ! missing values
         ENDIF
-      ENDIF 
+      ENDIF
     ENDDO
     IF (err /= 0) this%parsed = 0
     RETURN
-  END FUNCTION ap_parse_options 
+  END FUNCTION ap_parse_options
 
   FUNCTION ap_parse_positionals(this,cmd) RESULT(err)
     !! Parse positional arguments of the internal command line
-    !! This (internal) function manages the parsing of the command line positional arguments. 
+    !! This (internal) function manages the parsing of the command line positional arguments.
     OBJECT(argparser), INTENT(inout) :: this
       !! An argparser object reference
@@ -1044,5 +1073,5 @@
 
     ! no positional required but current word is valid
-    ! Either : no positional required but valid element is present 
+    ! Either : no positional required but valid element is present
     !     Or : positional required but no valid element is present
     IF ((this%have_posal.AND..NOT.words_valid(cmd)) .OR. &
@@ -1054,5 +1083,5 @@
     CALL words_clear(this%posals%values)
     this%posals%fnd = .true.
-    DO 
+    DO
       na = words_length(this%posals%values)
       IF (words_valid(cmd)) THEN
@@ -1090,6 +1119,6 @@
     !! Fill an argument with values
     !!
-    !! The function parses remaining parts of the command line from the position of 
-    !! the given argument and attempts to retrieve its value(s) (if any). 
+    !! The function parses remaining parts of the command line from the position of
+    !! the given argument and attempts to retrieve its value(s) (if any).
     !! Several tests are performed and may raise errors. The function always stops
     !! at the first error encountered which can be one of the following :
@@ -1103,8 +1132,8 @@
       !! The command line
     TYPE(argc), INTENT(inout), TARGET :: arg
-      !! An argc object reference with the argument currently processed. 
+      !! An argc object reference with the argument currently processed.
     TYPE(error) :: err
       !! Error object with the first error encountered in the process
-    INTEGER                       :: ca, isopt, itmp 
+    INTEGER                       :: ca, isopt, itmp
     LOGICAL                       :: ltmp
     CHARACTER(len=:), ALLOCATABLE :: elt
@@ -1126,14 +1155,14 @@
       IF (arg%paction == ap_count) THEN
         elt = words_pop(arg%values)
-        READ(elt,*) itmp ; itmp = itmp + 1 
+        READ(elt,*) itmp ; itmp = itmp + 1
         CALL words_append(arg%values,TO_STRING(itmp))
-      ELSE IF (arg%ptype == ap_logical) THEN 
+      ELSE IF (arg%ptype == ap_logical) THEN
         elt = words_pop(arg%values)
-        READ(elt,*) ltmp 
+        READ(elt,*) ltmp
         CALL words_append(arg%values,TO_STRING(.NOT.ltmp))
       ENDIF
     ELSE
       ! For any other case, the algorithm is quite simple :
-      ! We consume tokens of the command-line until either the end or 
+      ! We consume tokens of the command-line until either the end or
       ! the next option (or '--' separator)
       ! When the exit condition is met we perform some tests based on the
@@ -1155,7 +1184,7 @@
           !    1) we have consumed all argument of command line
           !    2) current argument is not a value !
-          !    3) current argument the separator '--' 
+          !    3) current argument the separator '--'
           IF (isopt <= 0 .OR. TRIM(elt)=='--') CALL words_previous(cmd)
-          IF (arg%nrec == -2 .AND. words_length(arg%values) == 0) & 
+          IF (arg%nrec == -2 .AND. words_length(arg%values) == 0) &
             err = ac_fmt_val_err(arg,-17)
           IF (arg%paction /= ap_append .AND. arg%nrec > 0 .AND. ca /= arg%nrec) &
@@ -1178,12 +1207,12 @@
   END FUNCTION ap_fill_argument
 
-  FUNCTION ap_split_cmd(this,string,new_cmd,rhelp) RESULT(err) 
+  FUNCTION ap_split_cmd(this,string,new_cmd,rhelp) RESULT(err)
     !! Preprocess the command line
-    !! The function reads and splits the given string so merged options/values 
+    !! The function reads and splits the given string so merged options/values
     !! are splitted and saves the resulting string elements in a list of words.
     !! @warning
     !! For compilers that does not support allocatable strings in derived types,
     !! computation are highly dependent of [[string_op(module):st_slen(variable):
-    !! tokens length are limited by this parameter. 
+    !! tokens length are limited by this parameter.
     IMPLICIT NONE
     OBJECT(argparser), INTENT(in) :: this
@@ -1193,5 +1222,5 @@
     TYPE(words), INTENT(out)      :: new_cmd
       !! An output [[string_op(module):words(type)]] object with the processed command line
-    LOGICAL, INTENT(out)          :: rhelp   
+    LOGICAL, INTENT(out)          :: rhelp
       !! An output boolean flag with `.true.` if help is requested, `.false.` otherwise
     TYPE(error) :: err
@@ -1199,9 +1228,9 @@
     INTEGER                       :: isopt,j,tl,res
     CHARACTER(len=:), ALLOCATABLE :: elt
-    TYPE(words)                   :: splitted 
+    TYPE(words)                   :: splitted
     INTEGER                       :: arg_idx
     err = noerror ; rhelp = .false.
     IF (LEN_TRIM(string) == 0) THEN
-      err = error('internal error (empty string)',-255) 
+      err = error('internal error (empty string)',-255)
       RETURN
     ENDIF
@@ -1218,8 +1247,8 @@
           res = ap_check_string(this,"-"//elt(j:j),arg_idx)
           ! great we have another short option flag
-          IF (res == -1 .AND. arg_idx /= -1) THEN ! another short option ! 
+          IF (res == -1 .AND. arg_idx /= -1) THEN ! another short option !
             rhelp = (this%args(arg_idx)%paction == ap_help.OR.rhelp)
             ! we must not set some argument's values here  for help argument
-            ! if auto is not set the parse method will disable the option 
+            ! if auto is not set the parse method will disable the option
             ! during next! parsing process
             CALL words_append(new_cmd,"-"//elt(j:j))
@@ -1237,5 +1266,5 @@
         rhelp = (this%args(arg_idx)%paction == ap_help.OR.rhelp)
         ! we must not set some argument's values here for help argument
-        ! if auto is not set the parse method will disable the option during 
+        ! if auto is not set the parse method will disable the option during
         ! next parsing process
         CALL words_append(new_cmd,TRIM(elt))
@@ -1247,5 +1276,5 @@
     RETURN
   END FUNCTION ap_split_cmd
-   
+
   FUNCTION ap_check_string(this,string,idx) RESULT(ret)
     !! Check if a string is an option flag
@@ -1259,5 +1288,5 @@
     INTEGER, INTENT(out), OPTIONAL             :: idx
       !! An optional output intger with the index of the afferent argument in the parser (-1 if not found)
-    INTEGER :: ret 
+    INTEGER :: ret
       !! Return code with the following possible values:
       !! - -1 if the string is a SHORT option flag
@@ -1272,5 +1301,5 @@
     ! The combination of the (optional) output index and the return code
     ! allows to check if an option is known or not
-    ret = 1 
+    ret = 1
     ! '--' is special : it is a separator that is seen as a value.
     IF (TRIM(string) == '--') RETURN
@@ -1303,5 +1332,5 @@
     CHARACTER(len=:), ALLOCATABLE :: copt,spc,opts,text
     INTEGER                       :: i,j,ia,optmw,i1,io,n,zw,zh
-    IF (this%width == 0) CALL fs_termsize(zh,this%width) 
+    IF (this%width == 0) CALL fs_termsize(zh,this%width)
     zw = this%width
     ! Sets usage
@@ -1312,5 +1341,5 @@
     hlp = TRIM(this%usg)//NEW_LINE('A')//NEW_LINE('A')
     ! Sets description
-    IF (LEN_TRIM(this%descr) /= 0) & 
+    IF (LEN_TRIM(this%descr) /= 0) &
       hlp=hlp//getpar(this%descr,zw,2)//NEW_LINE('A')//NEW_LINE('A')
     ! Sets positionals
@@ -1380,13 +1409,13 @@
     !! Format command line usage.
     !!
-    !! The subroutine creates and formats the command line usage of the 
-    !! given argparser object. If [[argparser(type):usg(variable)]] is already set (i.e. not empty) 
-    !! then the method only computes the maximum width of the option part of the usage command 
-    !! (see `optmw` argument description) if needed. In the other case, the method builds the usage 
+    !! The subroutine creates and formats the command line usage of the
+    !! given argparser object. If [[argparser(type):usg(variable)]] is already set (i.e. not empty)
+    !! then the method only computes the maximum width of the option part of the usage command
+    !! (see `optmw` argument description) if needed. In the other case, the method builds the usage
     !! line based on the arguments stored in the parser.
     OBJECT(argparser), INTENT(inout) :: this
       !! An argparser object reference
     INTEGER, INTENT(out), OPTIONAL   :: optmw
-      !! An optional integer with the maximum length of the option part of the usage command. 
+      !! An optional integer with the maximum length of the option part of the usage command.
       !! This variable is intended to set a fancy indentation while printing option in the helper.
     CHARACTER(len=:), ALLOCATABLE :: usage, idts, copt,pgn
@@ -1428,5 +1457,5 @@
           usage = usage(:)//TRIM(copt)
         ENDIF
-      ENDIF 
+      ENDIF
       this%usg = usage
     ELSE
@@ -1439,5 +1468,5 @@
         optmw = omw
       ENDIF
-    ENDIF 
+    ENDIF
   END SUBROUTINE ap_format_usage
 
@@ -1462,8 +1491,10 @@
     IF (ALLOCATED(other%descr)) this%descr = other%descr
     IF (ALLOCATED(other%eplg))  this%eplg  = other%eplg
+    IF (ALLOCATED(other%vers))  this%vers  = other%vers
 #else
     this%usg   = other%usg
     this%descr = other%descr
     this%eplg  = other%eplg
+    this%vers  = other%vers
 #endif
     this%mxhlpos = other%mxhlpos
@@ -1507,6 +1538,6 @@
   FUNCTION ac_equals_arg(this,other) RESULT(ret)
     !! Check if two arguments are identical
-    !! The method checks if two arguments are equal based on their name, short option flag and long 
-    !! option flag.Two arguments are considered equals if at least one of these three members is equal 
+    !! The method checks if two arguments are equal based on their name, short option flag and long
+    !! option flag.Two arguments are considered equals if at least one of these three members is equal
     !! and not empty.
     TYPE(argc), INTENT(in) :: this
@@ -1529,7 +1560,7 @@
     tlf=TRIM(this%lflag) ; olf=TRIM(other%lflag)
 #endif
-    tn=LEN_TRIM(tna) ; on=LEN_TRIM(ona) 
+    tn=LEN_TRIM(tna) ; on=LEN_TRIM(ona)
     tl=LEN_TRIM(tlf) ; ol=LEN_TRIM(olf)
-    ts=LEN_TRIM(tsf) ; os=LEN_TRIM(osf) 
+    ts=LEN_TRIM(tsf) ; os=LEN_TRIM(osf)
     ! check on name :
     ! Returns True if at least of name, sflag and lflag is set to non-empty
@@ -1537,5 +1568,5 @@
     ret = ((tn/=0 .AND. on==tn) .AND. tna == ona) .OR. &
           ((tl/=0 .AND. ol==tl) .AND. tlf == olf) .OR. &
-          ((ts/=0 .AND. os==ol) .AND. tsf == osf) 
+          ((ts/=0 .AND. os==ol) .AND. tsf == osf)
     DEALLOCATE(tna,ona,tsf,osf,tlf,olf)
   END FUNCTION ac_equals_arg
@@ -1543,7 +1574,7 @@
   FUNCTION ac_differs_arg(this,other) RESULT(ret)
     !! Check if two arguments are different
-    !! The method checks if two arguments are different based on their names, short option flag 
+    !! The method checks if two arguments are different based on their names, short option flag
     !! and long option flag.
-    !! @note 
+    !! @note
     !! This function is the extact contrary of [[argparse(module):ac_equals_arg(function)]] !
     TYPE(argc), INTENT(in) :: this
@@ -1558,5 +1589,5 @@
   SUBROUTINE ac_clear_arg_sc(arg)
     !! argc destructor (scalar)
-    !! The subroutine frees all memory used by an argc object and resets its member to 
+    !! The subroutine frees all memory used by an argc object and resets its member to
     !! default values.
     TYPE(argc), INTENT(inout) :: arg
@@ -1606,5 +1637,5 @@
       args(i)%lflag   = ""
 #endif
-    ENDDO 
+    ENDDO
   END SUBROUTINE ac_clear_arg_ve
 
@@ -1622,5 +1653,5 @@
     TYPE(argc), INTENT(in) :: this
       !! An argc object
-    INTEGER :: num 
+    INTEGER :: num
       !! The number of values stored in the argument
     num = words_length(this%values)
@@ -1629,5 +1660,5 @@
   FUNCTION ac_get_usg_opt_str(arg) RESULT(line)
     !! Build and format the option string for the usage part of the help message
-    !! The function is private part of the help builder. It creates the 
+    !! The function is private part of the help builder. It creates the
     !! option string part of a given argument.
     TYPE(argc), INTENT(in), TARGET :: arg
@@ -1661,5 +1692,5 @@
   FUNCTION ac_get_opt_str(arg) RESULT(line)
     !! Build and format the option flag string for the option part of the help message
-    !! The function is private part of the help builder. It creates the 
+    !! The function is private part of the help builder. It creates the
     !! option string part of a given argument for the options part of the help.
     TYPE(argc), INTENT(in), TARGET :: arg
@@ -1701,6 +1732,6 @@
     !! The function formats argparse specific errors when extra (missing) values
     !! are (not) set or when given values are not consistent with argument's type.
-    !! For each of these errors, the basic error is updated with a more precise 
-    !! message. 
+    !! For each of these errors, the basic error is updated with a more precise
+    !! message.
     TYPE(argc), INTENT(in) :: arg
       !! An argc object
@@ -1723,9 +1754,9 @@
         IF (arg%nrec == -2) THEN
           msg = msg//' takes at least '//nv//' value(s))'
-        ELSE 
+        ELSE
           msg = msg//' takes exactly '//nv//' value(s))'
         ENDIF
       CASE (-18) ! extra values -> -18
-        IF (arg%nrec == -3) THEN 
+        IF (arg%nrec == -3) THEN
           msg = msg//' takes at most '//nv//' value(s))'
         ELSE
@@ -1740,8 +1771,8 @@
   FUNCTION ac_check_and_set(this,sf,lf,ty,ac,de,na,meta,check_flag) RESULT(ret)
     !! Interface to all argc's member tests
-    !! The function calls all the tests to perform on argc members. Some of these tests can 
-    !! alter argc's member values to fit argparser's requirements. 
+    !! The function calls all the tests to perform on argc members. Some of these tests can
+    !! alter argc's member values to fit argparser's requirements.
     !!
-    !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only 
+    !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only
     !! produced by misuse of the function arguments. In such case, the program should be
     !! stopped: note that such ezrror should not occur in _released_ programs.
@@ -1763,6 +1794,6 @@
       !! An optional vector of strings with the Meta-name of the values
     LOGICAL, INTENT(in), OPTIONAL                        :: check_flag
-      !! An optional boolean flag hat instructs the method wether to check for option flag 
-      !! or not. By default this test is enabled but it should be disabled if one wants to 
+      !! An optional boolean flag hat instructs the method wether to check for option flag
+      !! or not. By default this test is enabled but it should be disabled if one wants to
       !! check for POSITIONAL arguments as they do not have option flags.
     TYPE(error) :: ret
@@ -1789,18 +1820,18 @@
   FUNCTION ac_check_ac_ty_de_na(this,ac,ty,de,na) RESULT(ret)
     !! Check and set argc's action, type and default value
-    !! The method checks if input argument's options are valid and update the argc object 
-    !! consequently. 
+    !! The method checks if input argument's options are valid and update the argc object
+    !! consequently.
     !!
-    !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only 
+    !! On success, `noerror` is returned. Otherwise -9 error code is returned. Errors are only
     !! produced by misuse of the function arguments.
     TYPE(argc), INTENT(inout)  :: this
       !! An argc object to update
     INTEGER, INTENT(in)          :: ac
-      !! An integer with the action to set and check 
+      !! An integer with the action to set and check
     INTEGER, INTENT(in)          :: ty
       !! An integer with the type to set and check
     CHARACTER(len=*), INTENT(in) :: de
       !! A string with the default value to set and check
-    CHARACTER(len=*), INTENT(in) :: na 
+    CHARACTER(len=*), INTENT(in) :: na
       !! A string with the expected number of value to set and check
     TYPE(error) :: ret
@@ -1810,23 +1841,27 @@
     ret = noerror
     eprf = 'argparse: '//"Invalid argument `"//TRIM(this%name)//"'"
-    uty = error(eprf//" (type)",-9) 
+    uty = error(eprf//" (type)",-9)
     ina = error(eprf//" (inconsistent nargs)",-9)
     zna = TRIM(na)
     ! Checks action
     IF(ANY(ap_actions == ac).OR.ac == ap_undef) THEN
-      this%paction = ac 
+      this%paction = ac
     ELSE
-      ret = error(eprf//" (action)",-9) ; RETURN 
+      ret = error(eprf//" (action)",-9) ; RETURN
     ENDIF
     ! Checks and sets type and default as a function of the action
     SELECT CASE(this%paction)
-      ! HELP: fixed in any case: 
+      ! HELP: fixed in any case:
       CASE(ap_help)
         this%default = 'F'
         this%ptype = ap_logical
         this%nrec = 0
+      ! VERSION: fixed in any case:
+      CASE(ap_version)
+        this%default = 'F'
+        this%ptype = ap_logical
+        this%nrec = 0
       ! COUNT:
-      ! we always use "hard-coded" stuff and do not warn if dev has made
-      ! mistakes...
+      ! we always use "hard-coded" stuff and do not warn if dev has made mistakes...
       CASE(ap_count)
         ! default settings of the count action
@@ -1835,8 +1870,8 @@
         ret = set_def_val()
       ! STORE, APPEND actions
-      CASE (ap_store, ap_append) 
-        ! set type 
+      CASE (ap_store, ap_append)
+        ! set type
         IF (ty == ap_undef) THEN
-          this%ptype= ap_integer 
+          this%ptype= ap_integer
         ELSEIF (ANY(ap_types == ty)) THEN
           this%ptype = ty
@@ -1847,5 +1882,5 @@
         ret = set_def_val() ; IF (ret /= 0) RETURN
         ! check for nargs (if na is empty then we set "*")
-        ret = set_nrec("*") 
+        ret = set_nrec("*")
       ! UNDEFINED:
       !   -> 1) set to action to store
@@ -1855,9 +1890,9 @@
       CASE (ap_undef)
         ! 1) always define store action
-        this%paction = ap_store 
+        this%paction = ap_store
         ! 2) set type and nrec:
         !    2.1) If type is undef:
         !         - to default value type if default is given
-        !         - ap_logical otherwiset type 
+        !         - ap_logical otherwiset type
         !    2.2) set nrec
         !        - if final type is ap_logical set nrec to 0
@@ -1865,5 +1900,5 @@
         If (ty == ap_undef) THEN
           ! no explicit type : define logical trigger first
-          this%ptype = ap_logical ; this%nrec = 0 
+          this%ptype = ap_logical ; this%nrec = 0
           ! icheck the default value given
           IF (LEN_TRIM(de) > 0) THEN
@@ -1873,9 +1908,9 @@
           ENDIF
           IF (this%ptype == ap_logical) THEN
-            ret = set_nrec("0") 
+            ret = set_nrec("0")
           ELSE
-            ret = set_nrec("1") 
+            ret = set_nrec("1")
           ENDIF
-          ret = set_def_val() 
+          ret = set_def_val()
           IF (ret /= 0) RETURN
         ! type is given
@@ -1883,8 +1918,8 @@
           ! known type given :
           !  check default value and nrec: -> if na not given set "*"
-          this%ptype = ty 
+          this%ptype = ty
           ret = set_def_val() ; IF (ret /= 0) RETURN
           IF (this%ptype == ap_logical) THEN
-            ret = set_nrec("0") 
+            ret = set_nrec("0")
           ELSE
             ret = set_nrec("1")
@@ -1892,7 +1927,7 @@
         ELSE
           ! unknown type => bad end !
-          ret = uty ; RETURN 
+          ret = uty ; RETURN
         ENDIF
-    END SELECT 
+    END SELECT
     ! set default value as first value if ret is noerror ....
     IF (ret == 0) CALL words_append(this%values,this%default)
@@ -1904,5 +1939,5 @@
         !! Check and set argument's expected number of records
         !! The method compares `na` value with the expected and known flags and decides
-        !! wether to raise an error or defines nrec member of the argument object. If `na` 
+        !! wether to raise an error or defines nrec member of the argument object. If `na`
         !! is empty then `base` is used.
         CHARACTER(len=1),INTENT(in) :: base
@@ -1921,5 +1956,5 @@
             ! check numeric characters
             IF (VERIFY(zna,"0123456789")==0) READ(zna,*) this%nrec
-            IF (this%nrec == 0) terr = ina 
+            IF (this%nrec == 0) terr = ina
         END SELECT
       END FUNCTION set_nrec
@@ -1927,5 +1962,5 @@
       FUNCTION set_def_val() RESULT(terr)
         !! Check and set argument's default value
-        !! The method compares `de` value with the type already stored in the argument and 
+        !! The method compares `de` value with the type already stored in the argument and
         !! decides wether to raise an error or to save `de` as argument's default value.
         !! If `de` is empty then it sets a default value according to argument's type.
@@ -1935,5 +1970,5 @@
         terr = noerror
         IF (LEN_TRIM(de) /= 0) THEN
-          this%default = de ; t = string_is(de) 
+          this%default = de ; t = string_is(de)
           IF (t /= this%ptype) THEN
             terr = error(eprf//" (inconsistent default value: expected '"// &
@@ -1952,5 +1987,5 @@
         ENDIF
         RETURN
-      END FUNCTION set_def_val 
+      END FUNCTION set_def_val
   END FUNCTION ac_check_ac_ty_de_na
 
@@ -1969,5 +2004,5 @@
     CHARACTER(len=2), INTENT(in) :: sflag
       !! A 2-characters wide string with the short option flag
-    CHARACTER(len=*), INTENT(in) :: lflag 
+    CHARACTER(len=*), INTENT(in) :: lflag
       !! A string (at least 3 characters wide) with the long option flag
     TYPE(error) :: ret
@@ -2017,5 +2052,5 @@
     !! Set meta-variable of the given argc object
     !! The method set meta-variable in the argc object. If no `meta` are given, the method
-    !! uses argument's name to set the values. 
+    !! uses argument's name to set the values.
     !! @warning
     !! To be effective, this subroutine must be called after argparse::chk_opt_nargs
@@ -2042,5 +2077,5 @@
             j=j+1 ; IF (j>ms) j=1
             zmeta = to_upper(meta(j))
-            blk=INDEX(TRIM(zmeta),CHAR(32))-1 
+            blk=INDEX(TRIM(zmeta),CHAR(32))-1
             IF (blk <= 0) blk=LEN_TRIM(zmeta)
             CALL words_append(this%meta,zmeta(1:blk))
@@ -2063,5 +2098,5 @@
   FUNCTION ac_check_value(this,str) RESULT(err)
     !! Check if given string is a valid value for the argument
-    TYPE(argc), INTENT(in)       :: this 
+    TYPE(argc), INTENT(in)       :: this
       !! An argc object reference
     CHARACTER(len=*), INTENT(in) :: str
@@ -2093,5 +2128,5 @@
   FUNCTION ap_get_positional_sc(this,idx,value) RESULT(ret)
     !! Get positional arguments value at given index
-    !! @warning 
+    !! @warning
     !! On error, the status of `value` is undefined.
     OBJECT(argparser), INTENT(in)              :: this
@@ -2100,5 +2135,5 @@
       !! Subscript of the positional argument value to get
     CHARACTER(len=:), INTENT(out), ALLOCATABLE :: value
-      !! Output raw value of the positional. If `idx` is out of range, `value` is set to an 
+      !! Output raw value of the positional. If `idx` is out of range, `value` is set to an
       !! empty string.
     TYPE(error) :: ret
@@ -2117,11 +2152,11 @@
   FUNCTION ap_get_positional_ve(this,values) RESULT(ret)
     !! Get all positional arguments value
-    !! @warning 
+    !! @warning
     !! On error, the status of `values` is undefined.
     OBJECT(argparser), INTENT(in)                                  :: this
       !! An argparser object reference
     CHARACTER(len=st_slen), INTENT(out), ALLOCATABLE, DIMENSION(:) :: values
-      !! An allocatable vector of **assumed length** strings with the value(s) of all 
-      !! positionals arguments found. 
+      !! An allocatable vector of **assumed length** strings with the value(s) of all
+      !! positionals arguments found.
     TYPE(error) :: ret
       !! Error object with the first error encountered in the process
@@ -2532,5 +2567,5 @@
 
   !> Gets a scalar @p REAL(kind=8) value from given argument
-  !! @param[in,out] this An argc object 
+  !! @param[in,out] this An argc object
   !! @param[out] output A scalar with the first value of the argument
   !! @return An errors::error object with -21 if the destination variable's type
@@ -2538,5 +2573,5 @@
   FUNCTION ac_get_dv_sc(this, output) RESULT(ret)
     !! Get a scalar `REAL(kind=8)` value from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` value is undefined.
@@ -2563,5 +2598,5 @@
   FUNCTION ac_get_rv_sc(this, output) RESULT(ret)
     !! Get a scalar `REAL(kind=4)` value from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` value is undefined.
@@ -2588,5 +2623,5 @@
   FUNCTION ac_get_iv_sc(this, output) RESULT(ret)
     !! Get a scalar `INTEGER` value from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` value is undefined.
@@ -2613,5 +2648,5 @@
   FUNCTION ac_get_lv_sc(this, output) RESULT(ret)
     !! Get a scalar `INTEGER` value from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` value is undefined.
@@ -2638,5 +2673,5 @@
   FUNCTION ac_get_cv_sc(this, output) RESULT(ret)
     !! Get a scalar `COMPLEX` value from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` value is undefined.
@@ -2663,5 +2698,5 @@
   FUNCTION ac_get_sv_sc(this, output) RESULT(ret)
     !! Get a scalar `STRING` value from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2685,5 +2720,5 @@
   FUNCTION ac_get_dv_ve(this, output) RESULT(ret)
     !! Get a vector of `REAL(kind=8)` values from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2714,5 +2749,5 @@
   FUNCTION ac_get_rv_ve(this, output) RESULT(ret)
     !! Get a vector of `REAL(kind=4)` values from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2743,5 +2778,5 @@
   FUNCTION ac_get_iv_ve(this, output) RESULT(ret)
     !! Get a vector of `INTEGER` values from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2772,5 +2807,5 @@
   FUNCTION ac_get_lv_ve(this, output) RESULT(ret)
     !! Get a vector of `LOGICAL` values from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2801,5 +2836,5 @@
   FUNCTION ac_get_cv_ve(this, output) RESULT(ret)
     !! Get a vector of `COMPLEX` values from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2830,5 +2865,5 @@
   FUNCTION ac_get_sv_ve(this, output) RESULT(ret)
     !! Get a vector of `STRING` values from given argument
-    !! If no error occured, the function always returns at least a value (whatever the parser's 
+    !! If no error occured, the function always returns at least a value (whatever the parser's
     !! state is) which is the default value if no specific values are set in the argument.
     !! Otherwise, `output` status is undefined.
@@ -2872,5 +2907,5 @@
 
   FUNCTION apa2str(ap_a) RESULT(str)
-    !! Get the string representation of argparse actions constants 
+    !! Get the string representation of argparse actions constants
     INTEGER, INTENT(in) :: ap_a
      !! One of ap_store, ap_append,cap_count or ap_help module constants
@@ -2882,4 +2917,5 @@
       CASE(ap_count)  ; str = 'count'
       CASE(ap_help)   ; str = 'help'
+      CASE(ap_version); str = 'version'
       CASE DEFAULT    ; str = 'unknown'
     END SELECT
