Run a java program inside Matlab with a input file.

7 visualizaciones (últimos 30 días)
luigi ventre
luigi ventre el 1 de Dic. de 2021
Editada: Kojiro Saito el 7 de Dic. de 2021
Hi, I'm tring to run a java program from a matlab code. I already added the .jar file in the system static variables and I achived to lounch the progam. However I need to use a input file wrote inside matlab as a .txt file (or .dat dosen't matter). I'm using the system function:
system('java -jar mhclasses.jar');
system('java -jar javafoil.jar' );
where i can put the input file?
  3 comentarios
luigi ventre
luigi ventre el 2 de Dic. de 2021
I'll try thanks!
luigi ventre
luigi ventre el 2 de Dic. de 2021
nothing changes... I recive this message every time i run the script: 'no main manifest attribute, in mhclasses.jar'. The mhclasses.jar is a .jar file that i need to load to run javafoil.jar. On the user guide of this program (javafoil) looks like there is the possibility to run a main script (there are some exemple of java script to run)...
this is one of them:
//
// A simple JavaFoil example which creates a two element
// airfoil for downforce generation.
//
// switch to US country settings
Options.Country(0)
// create a cambered NACA airfoil for starting
Geometry.CreateAirfoil(0;61;15;30;6;40,000;0;0;1)
//
// create a copy of this first airfoil element to be used later
Modify.Select(1)
Modify.Duplicate()
// now select the first element again
Modify.Select(1)
// ... flip it upside down
Modify.Flip(25;0)
// ... scale it to 75%
Modify.Scale(75)
// ... rotate it 5 degrees trailing edge up around its nose (0;0)
Modify.Rotate(0;0;-5)
//
// now select the second element
Modify.Select(2)
// ... flip it upside down
Modify.Flip(25;0)
// ... scale this copy to 30%
Modify.Scale(30)
// ... move it back so that there is 5% overlap
Modify.Move(70.0;12)
// ...rotate it by 30 degrees around a point at (70%/12%)
Modify.Rotate(70;12;-30)
// finally: (THIS IS OMPORTANT!)
// select both elements again for all further analyses
// if only one element is selected on the modify card, only this element
// will be considered during the calculation of polars etc.!
Modify.Select(1;2)
// and move both elements up by 25% for ground clearance
// (note that the airfoil may not cross the y=0 line which is the ground
plane)
Modify.Move(0.0;25)
//
// switch ground effect simulation ON
Options.GroundEffect(1)
//
// prepare for analysis
Options.MachNumber(0)
Options.StallModel(0)
Options.TransitionModel(1)
Options.AspectRatio(0)
// velocity versus x/c should show no strong suction peaks in the
// nose region of 2nd element
Velocity.Analyze(0;0;1;0)
//
// polar for Re=500'000, alfa=-15 to +10 degrees
// with ground present a string suction force is generated
// (even for single element airfoils)
// therefore a Cl_min in the order of -5 to -6 can be seen.
Polar.Analyze(500000;500000;500000;-15;10;1;100;100;0;0)
//
// finally: export coordinates in XML format
Geometry.Save("Z:\groundforce-example.xml")
Onestly this is my first time with java....

Iniciar sesión para comentar.

Respuesta aceptada

Kojiro Saito
Kojiro Saito el 7 de Dic. de 2021
Editada: Kojiro Saito el 7 de Dic. de 2021
It might be better to read JavaFoil document.
I'm not familiar with JavaFoil, but it seems that "Script" option allows input files. If you want to input data.txt, try this.
!java.exe -cp "java\mhclasses.jar" -jar "java\javafoil.jar" Script="data.txt"
Alternatively, JavaFoil has embedded sample java code in Embedding and you can use it in MATLAB.
javaFoilPath = "C:\Path\To\MH AeroTools\JavaFoil\java";
javaaddpath(fullfile(javaFoilPath, 'mhclasses.jar'))
javaaddpath(fullfile(javaFoilPath, 'javafoil.jar'))
import MH.JavaFoil.*;
jf = JavaFoil;
% Start JavaFoil embedding
jf.startEmbedded ;
jf.runScriptLine("Options.Country(0)");
% You can input using CreateAirfoil
%jf.runScriptLine("Geometry.CreateAirfoil(0,121,12,30,0.000,40.000,0,0,1)");
% It seems that you can input txt file
jf.runScriptLine("Geometry.Open('data.txt')")
jf.runScriptLine("Polar.Analyze(500000,500000,100000,-5,15,1,100,100,0,0)");
jf.runScriptLine("Polar.Save('polar.txt')"); % Save the result
% Close JavaFoil embedding
jf.exitEmbedded;
clear jf
Again, I'm not familiar with JavaFoil, and it is rather JavaFoil specific question than MATLAB, so if you have further question, I think it's better to ask in JavaFoil community.
  1 comentario
luigi ventre
luigi ventre el 7 de Dic. de 2021
you have perfectly answered to my question eaven if you are not practise! thaks!!
I was looking for a method to use javafoil on matlab and save the polars.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by