Skip to content

Commit

Permalink
- FMI Import updated.
Browse files Browse the repository at this point in the history
- Added the new importFMU API.
- fmuWrapper.o is removed.
- fmi section is added to the makefile.Common.
- build fmi in order to get the executable and required files.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9996 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 4, 2011
1 parent c9cbf43 commit e7e9283
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 60 deletions.
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1359,5 +1359,13 @@ function reopenStandardStream
external "builtin";
end reopenStandardStream;

function importFMU "Imports the Functional Mockup Unit
Example command:
importFMU(\"A.fmu\");"
input String filename;
output Boolean success;
external "builtin";
end importFMU;

end Scripting;
end OpenModelica;
24 changes: 24 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -1216,6 +1216,30 @@ algorithm
b = System.reopenStandardStream(i-1,filename);
then
(cache,Values.BOOL(b),st);

case (cache,env,"importFMU",{Values.STRING(filename)},st,msg)
equation
// get OPENMODELICAHOME
omhome = Settings.getInstallationDirectoryPath();
pd = System.pathDelimiter();
// current directory
str = System.pwd() +& pd;
str1 = str +& filename;
filename = Util.if_(System.regularFileExists(str1), str1, filename);
// create the path till fmigenerator
s1 = Util.if_(System.os() ==& "Windows_NT", ".exe", "");
str2 = stringAppendList({omhome,pd,"bin",pd,"fmigenerator",s1});
// create the list of arguments for fmigenerator
str3 = "--fmufile=\"" +& filename +& "\" --outputdir=\"" +& str +& "\"";
call = str2 +& " " +& str3;

0 = System.spawnCall(str2, call);
then
(cache,Values.BOOL(true),st);

case (cache,env,"importFMU",_,st,msg)
then
(cache,Values.BOOL(false),st);

case (cache,env,"setDataPort",{Values.INTEGER(i)},st,msg)
equation
Expand Down
14 changes: 14 additions & 0 deletions FMI/import/CHANGES.txt
@@ -0,0 +1,14 @@
2011-10-04 [adeel.asghar@liu.se]
------------------------------

- Removed the generator.mak and added the Makefile.omdev.mingw.
- Removed the fmuwrapper.o (run the make file to create it).
- The executable is renamed from generator to fmigenerator.
- The executable takes two parameters --fmufile and --outputdir(optional). Run [fmigenerator -h] for usage help.
- Some minor changes in the source code, check the svn.
- Added a fmi section in the Makefile.common, so now one can compile FMI import from MDT using ctrl+B and then typing fmi.
- The fmi section copies the 7z.exe and 7z.dll to build/bin. It also copies the fmiModelica.tmp to /build/include/omc. Runs the fmi makefile.

------------------------------
Adeel.
adeel.asghar@liu.se
2 changes: 1 addition & 1 deletion FMI/import/source/fmuWrapper.h
Expand Up @@ -4,7 +4,7 @@

#include <windows.h>
#include "fmiModelFunctions.h"
//#include "xmlparser.h"
#include "xmlparser.h"
#define COMBINENAME(a,b) a##_##b

#ifdef __cplusplus
Expand Down
38 changes: 0 additions & 38 deletions FMI/import/source/generator.mak

This file was deleted.

51 changes: 34 additions & 17 deletions FMI/import/source/moGenerator.c
@@ -1,8 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "moGenerator.h"


#define QUOTEME_(x) #x
#define QUOTEME(x) QUOTEME_(x)
//#define _DEBUG_ 1
Expand All @@ -13,7 +15,7 @@
#define PATHSIZE 1024

#define MODEL_DESCRIPTION "modelDescription.xml"
#define FMU_TEMPLATE "..\\source\\fmuModelica.tmp"
#define FMU_TEMPLATE "..\\include\\omc\\fmuModelica.tmp"
#define FMU_PATH "..\\fmu"
#define BIN_PATH "..\\bin"

Expand Down Expand Up @@ -498,15 +500,30 @@ void blockcodegen(ModelDescription* md,size_t nx, size_t nz, const char* mid, co
fclose(pfile);
}

void printUsage() {
printf("Usage: fmigenerator [--fmufile=NAME] [--outputdir=PATH]\n");
printf("--fmufile The FMU file that contains the model description to be imported.\n");
printf("--outputdir The output directory.");
}

int main(int argc, char *argv[])
{
if (argc < 2) {
printUsage();
return EXIT_FAILURE;
} else if (strcasecmp(argv[1], "-h") == 0) {
printUsage();
return EXIT_FAILURE;
} else if (strcasecmp(argv[1], "--help") == 0) {
printUsage();
return EXIT_FAILURE;
}

size_t nx; // number of state variables
size_t nz; // number of state event indicators
size_t nsv; // number of scalar variables
fmiScalarVariable* list = NULL; // list of fmiScalarVariable;
char omPath[PATHSIZE]; // OpenModelica installation directory

// Allocated memory needed to be freed
const char * fmuname; // name of the fmu file <fmuname>.fmu
ModelDescription* md = NULL; // handle to the parsed XML file
Expand All @@ -516,30 +533,31 @@ int main(int argc, char *argv[])
const char * xmlFile = NULL;
const char * fmuDllPath = NULL;
printf("\n\n");
// printf("#### argc: %d\n",argc);
if (argc<=1) {
printf("#### Please give the fmu file...\n generator.exe <fmupath>\n");
freeElement(md);
return EXIT_FAILURE;
if (strncmp(argv[1], "--fmufile=", 10) == 0) {
fmuname = getFMUname(argv[1]+10);
}
if (argc > 2) {
if (strncmp(argv[2], "--outputdir=", 12) == 0) {
decompPath = argv[2]+12;
strcat(decompPath, "/");
if (access(decompPath, F_OK) == -1)
decompPath = getDecompPath(omPath,fmuname);
}
} else {
decompPath = getDecompPath(omPath,fmuname);
}
fmuname = getFMUname(argv[1]);
decompPath = getDecompPath(omPath,fmuname);
#ifdef _DEBUG_
printf("#### %s decompPath: %s\n",QUOTEME(__LINE__),decompPath);
#endif
decompress(argv[1],decompPath);

decompress(argv[1]+10,decompPath);
xmlFile = getXMLfile(decompPath,MODEL_DESCRIPTION);

md = parse(xmlFile);

mid = getModelIdentifier(md);
guid = getString(md, att_guid);
guid = getString(md, att_guid);
nx = getNumberOfStates(md);
nz = getNumberOfEventIndicators(md);
nsv = getNumberOfSV(md);
list = (fmiScalarVariable*)calloc(sizeof(fmiScalarVariable),nsv);

instScalarVariable(md,list);

# ifdef _DEBUG_
Expand Down Expand Up @@ -568,6 +586,5 @@ int main(int argc, char *argv[])
free(list);
freeScalarVariableLst(list,nsv);
freeElement((void*)md);
system("PAUSE");
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
9 changes: 6 additions & 3 deletions FMI/import/source/xmlparser.c
Expand Up @@ -255,7 +255,6 @@ const char * getDescription(ModelDescription* md, ScalarVariable* sv) {
const char * getVariableAttributeString(ModelDescription* md,
fmiValueReference vr, Elm type, Att a){
const char* value;
const char* declaredType;
Type* tp;
ScalarVariable* sv = getVariable(md, vr, type);
if (!sv) return NULL;
Expand Down Expand Up @@ -547,7 +546,7 @@ static void XMLCALL endElement(void *context, const char *elm) {
case elm_BooleanType:
case elm_EnumerationType:
break;
deaullt:
default:
logFatalTypeError("RealType or similar", ts->type);
return;
}
Expand Down Expand Up @@ -597,7 +596,7 @@ static void XMLCALL endElement(void *context, const char *elm) {
case elm_Boolean:
case elm_Enumeration:
break;
deault:
default:
logFatalTypeError("Real or similar", child->type);
return;
}
Expand Down Expand Up @@ -704,6 +703,8 @@ void printElement(int indent, void* element){
printList(indent, md->vendorAnnotations);
printList(indent, md->modelVariables);
break;
default:
break;
}
}

Expand Down Expand Up @@ -745,6 +746,8 @@ void freeElement(void* element){
freeList(md->vendorAnnotations);
freeList(md->modelVariables);
break;
default:
break;
}
// free the struct
free(e);
Expand Down
8 changes: 7 additions & 1 deletion Makefile.common
Expand Up @@ -20,7 +20,7 @@ INSTALL_SHAREDIR = ${DESTDIR}${datadir}/
INSTALL_MANDIR = ${DESTDIR}${datadir}/man/
INSTALL_JAVADIR = ${DESTDIR}${datadir}/omc/java

.PHONY : c_runtime omc omcd release debug qtclient mosh all mkbuilddirs test install-dirs susan susan_all susgen sustst
.PHONY : c_runtime omc omcd release debug qtclient mosh all mkbuilddirs fmi test install-dirs susan susan_all susgen sustst

mkbuilddirs:
if [ "$(EXE)" = ".app" ]; then mkdir -p $(builddir_app); fi
Expand Down Expand Up @@ -49,6 +49,12 @@ docs: mkbuilddirs omlibrary
# man pages
(cd doc/manpages/; for f in *.1; do gzip $$f -c > ../../$(builddir_man)/man1/$$f.gz && touch -r $$f ../../$(builddir_man)/man1/$$f.gz; done)

fmi:
(cp -p FMI/import/source/fmuModelica.tmp $(builddir_inc))
(cp -p FMI/import/bin/7z.dll $(builddir_bin))
(cp -p FMI/import/bin/7z.exe $(builddir_bin))
(cd FMI/import/source; time $(MAKE) -f Makefile.omdev.mingw)

testfast: test

test:
Expand Down

0 comments on commit e7e9283

Please sign in to comment.