Skip to content

Commit

Permalink
By default: do not output protected variables to result-file
Browse files Browse the repository at this point in the history
- To override: Add simflags="-emit_protected"
- The library testing now adds -emit_protected if the compareVars is non-empty (and adds a variableFilter to only output these variables)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19318 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 26, 2014
1 parent b84a109 commit 0a61f6b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -10652,6 +10652,7 @@ template ScalarVariableAttribute(SimVar simVar, Integer classIndex, String class
causality = "<%caus%>" isValueChangeable = "<%isValueChangeable%>"
alias = <%alias%>
classIndex = "<%classIndex%>" classType = "<%classType%>"
isProtected = "<%isProtected%>"
<%getInfoArgs(info)%>
>>
end ScalarVariableAttribute;
Expand Down
5 changes: 4 additions & 1 deletion SimulationRuntime/c/simulation/simulation_input_xml.cpp
Expand Up @@ -456,7 +456,10 @@ void read_input_xml(MODEL_DATA* modelData,
omc_ScalarVariable &v = in[i]; \
read_var_info(v, info); \
read_var_attribute(v, attribute); \
if (info.name[0] == '$') { /* filter internal variables */ \
if (info.name[0] == '$') { \
out[j].filterOutput = 1; \
} else if (!omc_flag[FLAG_EMIT_PROTECTED] && 0 == v["isProtected"].compare("true")) { \
infoStreamPrint(LOG_DEBUG, 0, "filtering protected variable %s", info.name); \
out[j].filterOutput = 1; \
} \
mapAlias[info.name] = j; /* create a mapping for Alias variable to get the correct index */ \
Expand Down
10 changes: 5 additions & 5 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -321,7 +321,6 @@ int startInteractiveSimulation(int argc, char**argv, void* data)
void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilter, int resultFormatHasCheapAliasesAndParameters)
{
#ifndef _MSC_VER
int cheap = resultFormatHasCheapAliasesAndParameters;
regex_t myregex;
int flags = REG_EXTENDED;
int rc;
Expand All @@ -332,6 +331,7 @@ void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilte
modelData->realVarsData[0].filterOutput = 1;
modelData->realVarsData[modelData->nStates].filterOutput = 1;
}

if(0 == strcmp(filter, ".*")) { // This matches all variables, so we don't need to do anything
return;
}
Expand All @@ -347,7 +347,7 @@ void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilte
for(long i=0; i<modelData->nVariablesReal; i++) if(!modelData->realVarsData[i].filterOutput) {
modelData->realVarsData[i].filterOutput = regexec(&myregex, modelData->realVarsData[i].info.name, 0, NULL, 0) != 0;
}
for(long i=0; i<modelData->nAliasReal; i++) {
for(long i=0; i<modelData->nAliasReal; i++) if(!modelData->realAlias[i].filterOutput) {
if(modelData->realAlias[i].aliasType == 0) /* variable */ {
modelData->realAlias[i].filterOutput = regexec(&myregex, modelData->realAlias[i].info.name, 0, NULL, 0) != 0;
if (0 == modelData->realAlias[i].filterOutput) {
Expand All @@ -363,7 +363,7 @@ void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilte
for (long i=0; i<modelData->nVariablesInteger; i++) if(!modelData->integerVarsData[i].filterOutput) {
modelData->integerVarsData[i].filterOutput = regexec(&myregex, modelData->integerVarsData[i].info.name, 0, NULL, 0) != 0;
}
for (long i=0; i<modelData->nAliasInteger; i++) {
for (long i=0; i<modelData->nAliasInteger; i++) if(!modelData->integerAlias[i].filterOutput) {
if(modelData->integerAlias[i].aliasType == 0) /* variable */ {
modelData->integerAlias[i].filterOutput = regexec(&myregex, modelData->integerAlias[i].info.name, 0, NULL, 0) != 0;
if (0 == modelData->integerAlias[i].filterOutput) {
Expand All @@ -379,7 +379,7 @@ void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilte
for (long i=0; i<modelData->nVariablesBoolean; i++) if(!modelData->booleanVarsData[i].filterOutput) {
modelData->booleanVarsData[i].filterOutput = regexec(&myregex, modelData->booleanVarsData[i].info.name, 0, NULL, 0) != 0;
}
for (long i=0; i<modelData->nAliasBoolean; i++) {
for (long i=0; i<modelData->nAliasBoolean; i++) if(!modelData->booleanAlias[i].filterOutput) {
if(modelData->booleanAlias[i].aliasType == 0) /* variable */ {
modelData->booleanAlias[i].filterOutput = regexec(&myregex, modelData->booleanAlias[i].info.name, 0, NULL, 0) != 0;
if (0 == modelData->booleanAlias[i].filterOutput) {
Expand All @@ -395,7 +395,7 @@ void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilte
for (long i=0; i<modelData->nVariablesString; i++) if(!modelData->stringVarsData[i].filterOutput) {
modelData->stringVarsData[i].filterOutput = regexec(&myregex, modelData->stringVarsData[i].info.name, 0, NULL, 0) != 0;
}
for (long i=0; i<modelData->nAliasString; i++) {
for (long i=0; i<modelData->nAliasString; i++) if(!modelData->stringAlias[i].filterOutput) {
if(modelData->stringAlias[i].aliasType == 0) /* variable */ {
modelData->stringAlias[i].filterOutput = regexec(&myregex, modelData->stringAlias[i].info.name, 0, NULL, 0) != 0;
if (0 == modelData->stringAlias[i].filterOutput) {
Expand Down
4 changes: 4 additions & 0 deletions SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -35,6 +35,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {

/* FLAG_CLOCK */ "clock",
/* FLAG_CPU */ "cpu",
/* FLAG_EMIT_PROTECTED */ "emit_protected",
/* FLAG_F */ "f",
/* FLAG_HELP */ "help",
/* FLAG_IIF */ "iif",
Expand Down Expand Up @@ -71,6 +72,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {

/* FLAG_CLOCK */ "selects the type of clock to use -clock=RT, -clock=CYC or -clock=CPU",
/* FLAG_CPU */ "dumps the cpu-time into the results-file",
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get detailed information that specifies the command-line flag",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
Expand Down Expand Up @@ -107,6 +109,7 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {

/* FLAG_CLOCK */ "selects the type of clock to use -clock=RT, -clock=CYC or -clock=CPU\n RT=monotonic real-time clock, CPU=process-based CPU-time, CYC=cpu cycles measured with RDTSC",
/* FLAG_CPU */ " - dumps the cpu-time into the result-file\n - $cpuTime is the variable name inside the result-file",
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get detailed information that specifies the command-line flag\n e.g. -help=f prints detailed information for command-line flag f",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
Expand Down Expand Up @@ -143,6 +146,7 @@ const int FLAG_TYPE[FLAG_MAX] = {

/* FLAG_CLOCK */ FLAG_TYPE_OPTION,
/* FLAG_CPU */ FLAG_TYPE_FLAG,
/* FLAG_EMIT_PROTECTED */ FLAG_TYPE_FLAG,
/* FLAG_F */ FLAG_TYPE_OPTION,
/* FLAG_HELP */ FLAG_TYPE_OPTION,
/* FLAG_IIF */ FLAG_TYPE_OPTION,
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -42,6 +42,7 @@ enum _FLAG

FLAG_CLOCK,
FLAG_CPU,
FLAG_EMIT_PROTECTED,
FLAG_F,
FLAG_HELP,
FLAG_IIF,
Expand Down

0 comments on commit 0a61f6b

Please sign in to comment.