﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
1732	Simulation errors with external functions which return record objects	e.da-silva	Martin Sjölund	"Hi,

It is not possible to use any external Modelica function which returns a record object. 

I built a simple external function that add two complex numbers. The real and imaginary components of the number are passed as argument of the exernal function. The result is stored in the content of two double variables passed by address:


------ RECORDFKT.h

#ifndef _RECORDFKT_H
#define _RECORDFKT_H

#ifdef RECORDEXT_dll
	#define RECORDEXT_Export __declspec(dllexport)
#else
	#ifdef __cplusplus
		#define RECORDEXT_Export __declspec(dllimport)
	#else
		#define RECORDEXT_Export
	#endif
#endif

#ifdef __cplusplus
	#define EXTERN extern ""C""
#else
	#define EXTERN extern
#endif 


EXTERN RECORDEXT_Export int addLibComplexNum(double realX1, double imgX1,double realX2, double imgX2,double* realY,double* imgY);


#endif //_RECORDFKT_H

------ RECORDFKT.cpp

#include ""recordFkt.h""

int addLibComplexNum(double realX1, double imgX1,double realX2, double imgX2,double* realY,double* imgY)
{
	*realY = realX1 + realX2;
	*imgY = imgX1 + imgX2;
	return 1;
}

------------------

The Modelica interface, a package, contains a function, a record and a model tester:

-----  ExpRecordPkg.mo

package ExpRecordPkg
  function addLibComplexNum ""function for external test""

    input ExpRecordPkg.ComplexRec x1;
    input ExpRecordPkg.ComplexRec x2;
    output ExpRecordPkg.ComplexRec y = ExpRecordPkg.ComplexRec(0,0);

  external ""C"" addLibComplexNum(x1.realComp,x1.imagComp,x2.realComp,x2.imagComp,y.realComp,y.imagComp) annotation(Library=""recordExterFkt"");

  end addLibComplexNum;

  model RecordExtFktTester
    parameter ExpRecordPkg.ComplexRec x1 = ExpRecordPkg.ComplexRec(2,2);
    parameter ExpRecordPkg.ComplexRec x2 = ExpRecordPkg.ComplexRec(2,1);
    ExpRecordPkg.ComplexRec y;
  equation 
     y = ExpRecordPkg.addLibComplexNum(x1,x2);
  end RecordExtFktTester;

  record ComplexRec
    Real realComp;
    Real imagComp;

  end ComplexRec;
  annotation (uses(Modelica(version=""3.2"")));
end ExpRecordPkg;

----------------

In OM 1.8.1 rev 11758, I get the following error message in OMShell:

>> simulate(ExpRecordPkg.RecordExtFktTester)
record SimulationResult
    resultFile = """",
    simulationOptions = ""startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'ExpRecordPkg.RecordExtFktTester', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''"",
    messages = ""Simulation failed for model: ExpRecordPkg.RecordExtFktTester
[C:/Users/erick/Desktop/TISC_OM_report/ProblemTester/recordExterFkt/modelica/ExpRecordPkg.mo:5:5-5:37:writable] Warning: Unused input variable x1 in function .ExpRecordPkg.addLibComplexNum.
[C:/Users/erick/Desktop/TISC_OM_report/ProblemTester/recordExterFkt/modelica/ExpRecordPkg.mo:6:5-6:37:writable] Warning: Unused input variable x2 in function .ExpRecordPkg.addLibComplexNum.
[C:/Users/erick/Desktop/TISC_OM_report/ProblemTester/recordExterFkt/modelica/ExpRecordPkg.mo:5:5-5:37:writable] Warning: Unused input variable x1 in function .ExpRecordPkg.addLibComplexNum.
[C:/Users/erick/Desktop/TISC_OM_report/ProblemTester/recordExterFkt/modelica/ExpRecordPkg.mo:6:5-6:37:writable] Warning: Unused input variable x2 in function .ExpRecordPkg.addLibComplexNum.
Error: Error building simulator. Buildlog: gcc  -O3 -falign-functions -msse2 -mfpmath=sse   -I\""C:/OpenModelica1.8.1//include/omc\"" -I. -L\""C:/Users/erick/Desktop/TISC_OM_report/ProblemTester/recordExterFkt/modelica\""   -c -o ExpRecordPkg.RecordExtFktTester.o ExpRecordPkg.RecordExtFktTester.c
In file included from ExpRecordPkg.RecordExtFktTester.c:15:
ExpRecordPkg.RecordExtFktTester_functions.c: In function '_ExpRecordPkg_addLibComplexNum':
ExpRecordPkg.RecordExtFktTester_functions.c:30: error: '_y' undeclared (first use in this function)
ExpRecordPkg.RecordExtFktTester_functions.c:30: error: (Each undeclared identifier is reported only once
ExpRecordPkg.RecordExtFktTester_functions.c:30: error: for each function it appears in.)
ExpRecordPkg.RecordExtFktTester_functions.c:32: error: 'struct ExpRecordPkg_ComplexRec' has no member named 'realComp_ext'
ExpRecordPkg.RecordExtFktTester_functions.c:32: error: 'struct ExpRecordPkg_ComplexRec' has no member named 'imagComp_ext'
ExpRecordPkg.RecordExtFktTester_functions.c:32: error: 'struct ExpRecordPkg_ComplexRec' has no member named 'realComp_ext'
ExpRecordPkg.RecordExtFktTester_functions.c:32: error: 'struct ExpRecordPkg_ComplexRec' has no member named 'imagComp_ext'
mingw32-make: *** [ExpRecordPkg.RecordExtFktTester.o] Error 1

Thanks in advance,
Erick"	defect	closed	high		Code Generation		invalid		e.da-silva
