@::!/dos/rocks
@echo off
goto :init

:header
    echo %__NAME% v%__VERSION%
    echo Sistema de Simulacion de Predespacho del MER
    echo.
    goto :eof

:usage
    echo USAGE:
    echo   %__BAT_NAME% "INPUTFILE" "<PERIODO>" 
    echo.
    echo.  /?, --help           shows this help
    echo.  /v, --version        shows the version
    echo.  /e, --verbose        shows detailed output
    echo.
    echo.  Si no se especifica un periodo sel Sistema
    echo.  ejecuta las 24 horas del dia [0-23]
    goto :eof

:version
    if "%~1"=="full" call :header & goto :eof
    echo %__VERSION%
    goto :eof

:missing_argument
    call :header
    call :usage
    echo.
    echo ****                           ****
    echo ****    MISSING "INPUTFILE"    ****
    echo ****                           ****
    echo.
    goto :eof

:init
    set "__NAME=%~n0"
    set "__VERSION=1.0 beta"
    set "__YEAR=2020"

    set "__BAT_FILE=%~0"
    set "__BAT_PATH=%~dp0"
    set "__BAT_NAME=%~nx0"

    set "OptHelp="
    set "OptVersion="
    set "OptVerbose="

    set "InputFileArg="
    set "PeriodoArg="


:parse
    if "%~1"=="" goto :validate


    if /i "%~1"=="-h"         call :header & call :usage "%~2" & goto :end
    if /i "%~1"=="--help"     call :header & call :usage "%~2" & goto :end


    if /i "%~1"=="-v"         call :version      & goto :end
    if /i "%~1"=="--version"  call :version full & goto :end

    if not defined InputFileArg     set "InputFileArg=%~1"     & shift & goto :parse
    if not defined PeriodoArg  set "PeriodoArg=%~1"  & shift & goto :parse

    shift
    goto :parse

:validate
    if not defined InputFileArg call :missing_argument & goto :end

:main
    if defined OptVerbose (
        echo **** DEBUG IS ON
    )

    echo InputFileArg:    "%InputFileArg%"

    if defined PeriodoArg      echo PeriodoArg: "%PeriodoArg%"
    if not defined PeriodoArg set "PeriodoArg=23"
    echo PeriodoArg   "%PeriodoArg%"


    goto :runmodel
    

:runmodel
    %LOCALAPPDATA%\Merelec\spr\mc3\python.exe main.py -i %InputFileArg% -p %PeriodoArg%


:end
    call :cleanup
    exit /B

:cleanup
    REM The cleanup function is only really necessary if you
    REM are _not_ using SETLOCAL.
    set "__NAME="
    set "__VERSION="
    set "__YEAR="

    set "__BAT_FILE="
    set "__BAT_PATH="
    set "__BAT_NAME="

    set "OptHelp="
    set "OptVersion="
    set "OptVerbose="

    set "InputFileArg="
    set "InputFileArg2="
    set "NamedFlag="

    pause

    goto :eof

