def main(module=None):
    """
    @brief Main function of the runcode.py module

    @param module (string): the name of the module to run (
      available modules are: telemac2d, telemac3d, artemis, tomawac,
      sisyphe, artemis, postel3d, ...)

    @return None
    """

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    if module is None:
        parser = ArgumentParser(
            formatter_class=RawDescriptionHelpFormatter,
            description=('''\n
runcode is the execution launcher for all TELEMAC modules.\n
where module can be:\n
    mascaret     the 1D hydrodyanmic / tracer / water quality solver
    telemac2d    the 2D hydrodyanmic / tracer / water quality solver
    telemac3d    the 3D hydrodynamic / tracer / water quality solver
    artemis      the phase resolving wave solver
    tomawac      the 3rd generation wave transformation solver
    sisyphe      the sediment transport and geomorphogical solver
    stbtel       a pre-processor for the modules
    postel3d     a post-processor for telemac3d
            '''),
            usage=' (--help for help)\n---------\n        =>  '
            '%(prog)s module [options] casfile(s)\n---------',
            epilog=('''\nexamples:\n---------
1:     => runcode.py telemac2d -s t2d.cas
---------'''))
        parser.add_argument("module",
                            default=None,
                            choices=[
                                'telemac2d', 'telemac3d', 'artemis', 'tomawac',
                                'stbtel', 'postel3d', 'sisyphe', 'partel',
                                'estel3d', 'mascaret'
                            ])
    else:
        parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
                                description=('''\n
%(prog)s is one of the execution launcher for the TELEMAC system.
            '''),
                                epilog=('''\nexamples:\n---------
1:     => %(prog)s -s t2d.cas
---------'''))
        parser.set_defaults(module=module)

    parser = add_runcode_argument(parser, module=module)
    # Arguments
    parser.add_argument("args", metavar='cas file(s)', nargs="+")

    options = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root())

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Checking if symlink is available
    if options.use_link and not check_sym_link(options.use_link):
        raise TelemacException(\
                '\nThe symlink option is only '
                'available on Linux systems. '
                'Remove the option and try again')

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    code_name = options.module
    cas_files = options.args

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # bypass errors and carries on
    options.bypass = False
    if options.split or options.merge or options.run:
        if options.w_dir == '':
            raise TelemacException(\
                    '\nPlease use option -w (--workdirectory)'
                    ' with either of the options '
                    '--split, --run or --merge\n')
    # parsing for proper naming
    CFGS.compute_execution_info()
    cfg = CFGS.configs[CFGS.cfgname]

    print('\n\nRunning your CAS file(s) for:\n' + '~' * 72 + '\n')
    CFGS.light_dump()
    if options.w_dir != '':
        print('     +> directory        ' + options.w_dir)
        options.tmpdirectory = False
    print('\n\n' + '~' * 72 + '\n')

    # >>> Check wether the config has been compiled for the runcode
    if options.compileonly:
        cfg['REBUILD'] = 1
    if code_name not in cfg['MODULES']:
        raise TelemacException(\
                '\nThe code requested is not installed '
                'on this system : {}\n'.format(code_name))

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcpts = Messages()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Run the Code from the CAS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for cas_file in cas_files:
        run_study(cas_file, code_name, options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty():
        raise TelemacException(\
                '\n\nHummm ... I could not complete '
                'my work.\n{}{}'.format('~'*72, xcpts.except_messages()))


# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nMy work is done\n\n')
    sys.exit(0)
def run_mascaret():
    """
    Main function that runs the mascaret executable in the current folder
    """

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n'+72*'~'+'\n')
    parser = ArgumentParser(
        formatter_class=RawDescriptionHelpFormatter,
        description=('''\n\
Run the mascaret executable in the current folder, given a CAS file.
        '''))
    parser.add_argument("args", nargs='*')
    # ~~> Environment
    parser = add_config_argument(parser)
    parser.add_argument(
        "-s", "--sortiefile", action="store_true", dest="sortie_file",
        default=False,
        help="specify whether there is a sortie file, default is no")
    parser.add_argument(
        "-b", "--bypass", action="store_true",
        dest="bypass", default=False,
        help="will bypass execution failures and try to carry on "
             "(final report at the end)")
    options = parser.parse_args()

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root())

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if len(options.args) < 1:
        print('\nThe name of the CAS file is required\n')
        parser.print_help()
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cas = options.args[0]
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    xcpts = Messages()

    # still in lower case
    # parsing for proper naming
    CFGS.compute_execution_info()
    cfg = CFGS.configs[CFGS.cfgname]

    create_mascaret_files(cfg, cas)

    mascaret_exe = path.join(cfg['root'], 'builds', CFGS.cfgname, 'bin',
                             'mascaret' + cfg['sfx_exe'])
    _, code = xcpts.run_cmd(mascaret_exe, options.bypass)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty() or code != 0:
        print('\n\nHummm ... I could not complete my work.\n'+'~'*72
              + xcpts.except_messages())
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print('\n\nMy work is done\n\n')
        sys.exit(0)
def main():
    """
     @brief Main function of validateTELEMAC.
    """
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Handles input arguments
    options = set_parser()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)
    version = CFGS.configs[CFGS.cfgname].get('version', 'trunk')

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root(), version)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    # Checking if symlink is available
    if options.use_link and not check_sym_link(options.use_link):
        raise TelemacException(\
                '\nThe symlink option is only available on Linux systems. '
                'Remove the option and try again')

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Forces not to use any Xwindows backend for Jenkins ~~~~~~~~~~
    if options.vnv_post:
        import matplotlib.pyplot as plt

        plt.switch_backend('agg')

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcpts = Messages()

    # ~~~~ Reporting summary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if options.notebook:
        type_valid = 'notebooks'
    else:
        type_valid = 'examples'

    report = Report(options.report_name, type_valid)

    # ~~~ Running validation
    cfg = config_corrections(options, CFGS.cfgname)

    if options.notebook:
        run_validation_notebooks(options, report, xcpts)
    else:
        if options.vnv_mode == 'slurm':
            run_validation_python_slurm(cfg, options, report, xcpts)
        else:
            run_validation_python_mpi(cfg, options, report, xcpts)

    # Writting report
    if options.report_name != '':
        report.write()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty():
        print('\n\nHummm ... I could not complete my work.\n'
              '{}\n{}'.format('~' * 72, xcpts.except_messages()))
        sys.exit(1)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print('\n\nMy work is done\n\n')
        sys.exit(0)