Skip to content

Commit

Permalink
- revise command line arguments for c-runtime (second part)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15011 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Jan 30, 2013
1 parent 2212f21 commit 04fbc95
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
34 changes: 32 additions & 2 deletions SimulationRuntime/c/simulation/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const char *FLAG_NAME[FLAG_MAX] = {
"LOG_UNKNOWN",

/* FLAG_F */ "f",
/* FLAG_HELP */ "help",
/* FLAG_IIF */ "iif",
/* FLAG_IIM */ "iim",
/* FLAG_IIT */ "iit",
Expand All @@ -65,6 +66,34 @@ const char *FLAG_DESC[FLAG_MAX] = {
"unknown",

/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get deteiled information the specifies the command-line flag",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method",
/* FLAG_IIT */ "value specifies a time for the initialization of the model",
/* FLAG_INTERACTIVE */ "specify interactive simulation",
/* FLAG_IOM */ "value specifies the initialization optimization method",
/* FLAG_JAC */ "specify jacobian",
/* FLAG_L */ "value specifies a time where the linearization of the model should be performed",
/* FLAG_LV */ "value specifies the logging level",
/* FLAG_MEASURETIMEPLOTFORMAT */ "value specifies the output format of the measure time functionality",
/* FLAG_MT */ "this command line parameter is DEPRECATED",
/* FLAG_NLS */ "value specifies the nonlinear solver",
/* FLAG_NOEMIT */ "do not emit any results to the result file",
/* FLAG_NUMJAC */ "specify numerical jacobian",
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output",
/* FLAG_OVERRIDE */ "override the variables or the simulation settings in the XML setup file",
/* FLAG_OVERRIDE_FILE */ "will override the variables or the simulation settings in the XML setup file with the values from the file",
/* FLAG_PORT */ "value specifies interactive simulation port",
/* FLAG_R */ "value specifies a new result file than the default Model_res.mat",
/* FLAG_S */ "value specifies the solver",
/* FLAG_W */ "shows all warnings even if a related log-stream is inactive"
};

const char *FLAG_DETAILED_DESC[FLAG_MAX] = {
"unknown",

/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get deteiled information the specifies the command-line flag\n e.g. -help=f prints detaild information for command-line flag f",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method\n none\n numeric\n symbolic",
/* FLAG_IIT */ "value specifies a time for the initialization of the model",
Expand All @@ -78,19 +107,20 @@ const char *FLAG_DESC[FLAG_MAX] = {
/* FLAG_NLS */ "value specifies the nonlinear solver",
/* FLAG_NOEMIT */ "do not emit any results to the result file",
/* FLAG_NUMJAC */ "specify numerical jacobian",
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output as time = value, a = value, b = value, c = value",
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output\n time = value, a = value, b = value, c = value",
/* FLAG_OVERRIDE */ "override the variables or the simulation settings in the XML setup file\n e.g. var1=start1,var2=start2,par3=start3,startTime=val1,stopTime=val2,stepSize=val3,\n tolerance=val4,solver=\"see -s\",outputFormat=\"mat|plt|csv|empty\",variableFilter=\"filter\"",
/* FLAG_OVERRIDE_FILE */ "will override the variables or the simulation settings in the XML setup file with the values from the file\n note that: -overrideFile CANNOT be used with -override\n use when variables for -override are too many and do not fit in command line size\n overrideFileName contains lines of the form: var1=start1",
/* FLAG_PORT */ "value specifies interactive simulation port",
/* FLAG_R */ "value specifies a new result file than the default Model_res.mat",
/* FLAG_S */ "value specifies the solver\n dassl\n euler\n rungekutta\n inline-euler\n inline-rungekutta\n qss",
/* FLAG_S */ "value specifies the solver\n dassl\n euler\n rungekutta\n inline-euler\n inline-rungekutta\n dasslwort\n dasslSymJac\n dasslNumJac\n dasslColorSymJac\n dasslInternalNumJac\n qss",
/* FLAG_W */ "shows all warnings even if a related log-stream is inactive"
};

const int FLAG_TYPE[FLAG_MAX] = {
FLAG_TYPE_UNKNOWN,

/* FLAG_F */ FLAG_TYPE_OPTION,
/* FLAG_HELP */ FLAG_TYPE_OPTION,
/* FLAG_IIF */ FLAG_TYPE_OPTION,
/* FLAG_IIM */ FLAG_TYPE_OPTION,
/* FLAG_IIT */ FLAG_TYPE_OPTION,
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/simulation/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum _FLAG
FLAG_UNKNOWN = 0,

FLAG_F,
FLAG_HELP,
FLAG_IIF,
FLAG_IIM,
FLAG_IIT,
Expand Down Expand Up @@ -76,6 +77,7 @@ enum _FLAG_TYPE

extern const char *FLAG_NAME[FLAG_MAX];
extern const char *FLAG_DESC[FLAG_MAX];
extern const char *FLAG_DETAILED_DESC[FLAG_MAX];
extern const int FLAG_TYPE[FLAG_MAX];

int checkCommandLineArguments(int argc, char **argv);
Expand Down
63 changes: 44 additions & 19 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
data->simulationInfo.solverMethod = "dassl";
}

int methodflag = flagSet("s", argc, argv);
if(methodflag)
if(optionSet("s", argc, argv))
{
string* method = (string*) getOption("s", argc, argv);
if(!(method == NULL)){
const string *method = getOption("s", argc, argv);
if(method)
{
data->simulationInfo.solverMethod = method->c_str();
INFO1(LOG_SOLVER, " | overwrite solver method: %s [from command line]", data->simulationInfo.solverMethod);
INFO1(LOG_SOLVER, "overwrite solver method: %s [from command line]", data->simulationInfo.solverMethod);
}
}

Expand Down Expand Up @@ -569,28 +569,53 @@ int initRuntimeAndSimulation(int argc, char**argv, DATA *data)
for(i=1; i<FLAG_MAX; ++i)
{
if(FLAG_TYPE[i] == FLAG_TYPE_FLAG)
INFO1(LOG_STDOUT, "<-%s>", FLAG_NAME[i]);
INFO2(LOG_STDOUT, "<-%s>\n %s", FLAG_NAME[i], FLAG_DESC[i]);
else if(FLAG_TYPE[i] == FLAG_TYPE_OPTION)
INFO1(LOG_STDOUT, "<-%s=value>", FLAG_NAME[i]);
INFO2(LOG_STDOUT, "<-%s=value>\n %s", FLAG_NAME[i], FLAG_DESC[i]);
else if(FLAG_TYPE[i] == FLAG_TYPE_FLAG_VALUE)
INFO1(LOG_STDOUT, "<-%s value>", FLAG_NAME[i]);
INFO2(LOG_STDOUT, "<-%s value>\n %s", FLAG_NAME[i], FLAG_DESC[i]);
else
WARNING1(LOG_STDOUT, "<-%s> [unknown flag-type]", FLAG_NAME[i]);

INDENT(LOG_STDOUT);
INFO1(LOG_STDOUT, "%s", FLAG_DESC[i]);

/* detailed information for some flags */
if(i == FLAG_LV)
for(j=firstOMCErrorStream; j<LOG_MAX; ++j)
INFO2(LOG_STDOUT, " %-18s [%s]", LOG_STREAM_NAME[j], LOG_STREAM_DESC[j]);

RELEASE(LOG_STDOUT);
WARNING1(LOG_STDOUT, "[unknown flag-type] <-%s>", FLAG_NAME[i]);
}

RELEASE(LOG_STDOUT);
EXIT(0);
}

if(optionSet("help", argc, argv))
{
std::string option = *getOption("help", argc, argv);

for(i=1; i<FLAG_MAX; ++i)
{
if(option == std::string(FLAG_NAME[i]))
{
if(FLAG_TYPE[i] == FLAG_TYPE_FLAG)
INFO2(LOG_STDOUT, "detaild flag-description for: <-%s>\n%s", FLAG_NAME[i], FLAG_DETAILED_DESC[i]);
else if(FLAG_TYPE[i] == FLAG_TYPE_OPTION)
INFO2(LOG_STDOUT, "detaild flag-description for: <-%s=value>\n%s", FLAG_NAME[i], FLAG_DETAILED_DESC[i]);
else if(FLAG_TYPE[i] == FLAG_TYPE_FLAG_VALUE)
INFO2(LOG_STDOUT, "detaild flag-description for: <-%s value>\n%s", FLAG_NAME[i], FLAG_DETAILED_DESC[i]);
else
WARNING1(LOG_STDOUT, "[unknown flag-type] <-%s>", FLAG_NAME[i]);

/* detailed information for some flags */
INDENT(LOG_STDOUT);
if(i == FLAG_LV)
{
for(j=firstOMCErrorStream; j<LOG_MAX; ++j)
INFO2(LOG_STDOUT, " %-18s [%s]", LOG_STREAM_NAME[j], LOG_STREAM_DESC[j]);
}
RELEASE(LOG_STDOUT);

EXIT(0);
}
}

WARNING1(LOG_STDOUT, "invalid command line option: -help=%s", option.c_str());
WARNING1(LOG_STDOUT, "use %s -help for a list of all command-line flags", argv[0]);
EXIT(0);
}

setGlobalVerboseLevel(argc, argv);
initializeDataStruc(data);
Expand Down

0 comments on commit 04fbc95

Please sign in to comment.