I have written a program in c++11. My intention is to use MATLAB environment for plotting.
So, I followed these two links to have some idea:MATLAB_Build C++ Engine programs and c++ start MATLAB session. (There must be other ways to interface MATLAB and c++. But I want to know where is my fault before trying other ones)
As those above links have suggested I built my project accordingly using visual studio '17. The initial errors that I found was, my application could not locate the following .dll files libMatlabEngine.dll, libMatlabdataArray.lib.
So, I moved my .dlls to the executable location as suggested here. But after then my code is throwing the following error: 0xC0000005: Access violation executing location 0x0000000000000000.
Below is the piece of code that I'm trying. I guess it's the startMATLAB() which is returning a NULL pointer and the code is failing for that. But I can't figure out what's the reason.
Appreciate your help.
//Start the MATLAB engine
using namespace matlab::engine;
using namespace matlab::data;
unique_ptr<MATLABEngine> matlabptr = startMATLAB();
//Cretae a matlab array factory
ArrayFactory factory;
auto inputArray = factory.createArray({ 1, 6 }, cppData.cbegin(), cppData.cend());
auto time_array = factory.createArray({ 1, 6 }, time.cbegin(), time.cend());
matlabptr->setVariable(convertUTF8StringToUTF16String("data"), move(inputArray));
matlabptr->setVariable(convertUTF8StringToUTF16String("time"), move(time_array));
matlabptr->eval(convertUTF8StringToUTF16String("plot(time, data)"));
Related
I have a HU submodels FMU that is not running in a Simulink model.
I use Matlab2020b, FMIkit2.7 and the FMU created with Amesim 2019.1.
This is the error message:
AME_LIC_CACHE_INIT set to 100
Impossible to open file 'pV/pV_FrontAxle_Variant1.txt'.
Impossible to open file 'pV/pV_FrontAxle_Variant1.txt'.
Fatal error in FXA001 instance 1.
Terminating the program.
Simcenter Amesim model: initialization failed.
Failed to exit initialization mode
Failed to exit initialization mode. The FMU crashed (exception code: UNKOWN_EXEPTION_CODE).
I give 2 parameter in .txt file for the FXA001. It is worked in older versions of the model.
I tried to give the full path, copy the files to the folder where the model was and still not found.
Has anyone ever had such an issue?
Thank you!
Based on my experience, this issue might happen if the two text files do not have a header mentioning the Amesim table format they use.
For example for a so-called ā1Dā table:
#Table format: 1D
Otherwise the files may not be embedded properly when exporting the FMU.
I have a Modelica file that references c code during simulation through an external library *.a file.
For example:
model CallAdd
input Real FirstInput(start=0);
input Real SecondInput(start=0);
output Real FMUOutput(start=0);
function CAdd
input Real x(start=0);
input Real y(start=0);
output Real z(start=0);
external "C" annotation(Library = "CAdd", LibraryDirectory = "modelica://CallAdd");
end CAdd;
equation
FMUOutput = CAdd(FirstInput,SecondInput);
annotation(uses(Modelica(version = "3.2.1")));
end CallAdd;
When opening the Modelica model in OpenModelica the required files appear to be automatically loaded because it simulates and gives appropriate results.
However, when I try to compile the Modelica file with JModelica-SDK-1.12 I receive an error that the library *.a file could not be found.
So my question is: What is the proper way to reference additional files when using compile_fmu in JModelica?
With no success, I've tried:
# Import the compiler function
from pymodelica import compile_fmu
model_name = "CallAdd"
mo_file = "CallAdd.mo"
# Compile the model and save the return argument, for use later if wanted
my_fmu = compile_fmu(model_name, mo_file, target="cs",compiler_options = {'extra_lib_dirs':'C:/ToFolderContainingLib/'})
The strange thing is that when I was using JModelica-1.17 (non-SDK) the file compiled fine but the results didn't make sense. I was recommended to try the SDK version to see if it fixed my errors in my previous post here.
Try positioning the external library in sub-folder named as the platform your currently on. So in your example, I'd position the library (libCAdd.a) in sub-folder named linux64, as I'm on a 64bit Linux machine and then run the code.
If is a small piece of C code, as a last alternative you could try to include the C file directly in the Modelica code:
external "C" annotation(Include="
// the entire C code here
");
Hopefully the JModelica people will give you a better answer soon.
You could try to ask this on their website also:
http://www.jmodelica.org/forum
I am running a code that uses the fitsread function to open my fits movies and analyse them. It was working perfectly fine until about a week ago, when, without me doing anything, it started giving the following error whenever I try to run it:
Error using matlab.io.fits.openFile (line 48)
Unable to open file. File might be corrupt or filename might have unsupported
characters.
Error in fitsread>read_image_hdu (line 412)
fptr = fits.openFile(info.Filename);
Error in fitsread (line 125)
data = read_image_hdu(info,1,raw,pixelRegion);
I have tried manually checking the properties of such files using the fitsinfo function and nothing was wrong with the files themselves. I have also tried to re-set the default MATLAB path, delete them from the working folder and re-download them from a central University server where they were originally stored upon acquisition on a microscope, but it didn't help either. A collaborator has tried running the same code on his machine and it works well. I get this same error on both MATLAB versions R2011b and R2015b. It originally used to work on R2011b with the same files.
Thanks in advance to whoever will be able to help!
Using pentaho 5.3, Modified Java Script Value step to inject those data.
I want to dynamically set path and names in the MongoDB Output step. Here is my code
var meta = new org.pentaho.di.trans.TransMeta( source_path );
var mongoStep = meta.findStep("MongoDB Output");
mongoStep.setDescription('This is MongoDB Output by Ray');
Alert(mongoStep.getName()); // code is ok until here.
var mongoStepMeta = mongoStep.getStepMetaInterface() // error occurs here
When I want to get the getStepMetaInterface() to use step functions, the error occurs.
java.lang.LinkageError: loader constraint violation: loader (instance of org/pentaho/di/core/plugins/KettleURLClassLoader) previously initiated loading for a different type with name "org/pentaho/metastore/api/IMetaStore"
This error seems to be generated by the violation of .jar.
But when I use those original steps, like "Microsoft Access Input", I can successfully get getStepMetaInterface(). In this way, I can use all the functions defined in AccessInputMeta.java.
From my point of view, this problem may have a relation to the MongoDB Output step, because this is a plugin for kettle, but I am not sure.
Any response is appreciated!!
Yep, it's because of the plugin system. The Modified Java Script step and the Access Input step (among many others) are all in the Kettle engine and share a classloader. External plugins (like MongoDB Input/Output) have their own isolated classloaders. You have to do some voodoo with thread context classloaders and reflection in order to get at the Meta classes for those steps.
Here's an example of the hoops you have to jump through to get at external plugins (the Big Data plugin in this example) from the Modified Java Script step:
https://github.com/brosander/pentaho-hadoop-shims/blob/verification-2/test/verification/jobs/dependencies/ForceHiveToConnectRemotely.ktr
First, thanks to Mass who solves the problem.
Here is his advice:
This problem is caused by jar file conflict.
In pentaho installation there are two jar files:
-lib/metastore-5.3.0.0-213.jar
-plugins/pentaho-mongodb-plugin/lib/metastore-5.3.0.0-213.jar
Just remove the last jar file, this error will disappear.
I have a simple fortran project on Eclipse with two source files program.f90 and KASTBitmap.f90 which contains some functions I am currently writing as a library for bitmap images includes loading/saving/manipulating images.
I am trying to set a break point in KASTBitmap.f90 and when I start the debugger I get this error:
At line 18 of file ../KASTBitmap.f90 (unit = 1, file = 'FaceImg5.bmp')
Fortran runtime error: Non-existing record number
any ideas or hints are appreciated.