Skip to content

Commit

Permalink
- Adding support to compare results with csv-files
Browse files Browse the repository at this point in the history
- Adding python-script to convert the Buildings reference files to csv-files


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17763 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 19, 2013
1 parent 10ab1de commit b08fc05
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Examples/BuildModelRecursive.mos
Expand Up @@ -3,6 +3,8 @@
library:=$TypeName(Modelica);
libraryVersion:="default";
referenceFiles:="";
referenceFileExtension:="mat";
referenceFileNameDelimiter:=".";

setCommandLineOptions({"+g=Modelica","+d=nogen,"});
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
Expand Down Expand Up @@ -129,7 +131,7 @@ referenceFiles := \""+referenceFiles+"\";
referenceCell := if referenceFiles == \"\" then \"\" else \"<td>&nbsp;</td>\";
if simRes then
system(\"touch "+s+".simsuccess\");
reference := \""+referenceFiles+"/"+s+".mat\";
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".",referenceFileNameDelimiter)+"."+referenceFileExtension+"\";
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
prefix := \"files/"+s+".diff\";
if referenceExists then
Expand Down
42 changes: 42 additions & 0 deletions Examples/ConvertBuildingsReferenceToCSV.py
@@ -0,0 +1,42 @@
# Converts the buildings .txt format to equidistant csv-files

import os
import sys
from optparse import OptionParser

def convertDir(indir,outdir):
for fil in os.listdir(indir):
with open(indir+"/"+fil) as f:
v = {}
for line in f.readlines():
line = line.strip().split('=')
if line[1][0] == '[':
l = [str(float(s)) for s in line[1].strip('[]').split(',')]
if len(l)==2:
diff = float(l[1])-float(l[0])
l = [str(float(l[0])+x*diff) for x in range(101)]
if len(l)<>101:
raise Exception("Assumed buildings result format has exactly 101 data points")
v[line[0]] = l
keys = v.keys()
keys.remove('time')
keys.sort()
keys = ['time'] + keys
values = [v[key] for key in keys]
# Transpose
rows = map(list, zip(*values))
o = open(outdir+"/"+fil[0:-4]+'.csv', 'w')
o.write(','.join(keys) + '\n')
for row in rows:
o.write(','.join(row) + '\n')

def main():
parser = OptionParser()
parser.add_option("--input-dir", help="Directory containing .txt reference files in the Buildings package format", type="string", dest="input_dir", default=os.path.abspath('.'))
parser.add_option("--output-dir", help="Directory to generate csv-files in", type="string", dest="output_dir", default=os.path.abspath('.'))
(options, args) = parser.parse_args()
if len(args)<>0:
parser.error('This program does not take positional arguments')
convertDir(options.input_dir,options.output_dir)
if __name__ == '__main__':
sys.exit(main())
6 changes: 2 additions & 4 deletions SimulationRuntime/c/simulation/results/read_csv.cpp
Expand Up @@ -85,8 +85,6 @@ char** read_csv_variables(FILE *fin)
free(res);
return NULL;
}
res[numVar] = 0;
res[numVar+1] = 0;
tmp = res;
tmp[0] = buf;
tmp = tmp+1;
Expand All @@ -109,8 +107,8 @@ char** read_csv_variables(FILE *fin)
{
++buf;
}
}while(*buf != '\0');

} while(*buf != '\0');
*tmp=0;
return res;
}

Expand Down

0 comments on commit b08fc05

Please sign in to comment.