Hello all, again this nasty Java -> Octave connection.
I also want to embed Octave into a Java program and call Octave functions from Java. Initially I started with programming an execution engine which starts octave.exe and connected to its standard input and output pipes. This concept works (in the meantime I also found two solutions which implement the same technique) but is somewhat ugly and inefficient due to conversions to and from strings What I tried now was to call the Octave DLLs (Windows platform) directly via a C wrapper and using JNI. This technique provides a very elegant solution and I have used this in the past to call C and FORTRAN codes from Java. I want to define some global variables, set the values from Java, execute some user supplied functions and finally return the results (global variables set inside the user functions) to Java. Now with the Octrave DLLs I stumbled across a problem. To study the interface to ther DLLs I started with a C++ program. Basically I used the following logic: //----------------------------- // start and initialize Octave (once, then keep it alive) char * pArgs[] = {"octave.exe","--path", "C:\\Programme\\Octave", "--norc", NULL}; int iRet = octave_main (4 pArgs, true); //----------------------------- // execute some commands std::string s = std::string("global Output;\nglobal Input;\nInput=12;\nOutput=2*Input;\n"); octave_value x = eval_string (s, false, parse_status); // examine the returned "x" with x.isnumeric() etc. works when code is in an executable (.exe) file // what does the follwing code do? It works, but where is the variable in Octave? set_global_value (std::string(cName), val); octave_value vReturn = get_global_value (std::string(cName)); // the variable has the correct value, but is_globally_visible (std::string(Name)) returns false... // what does global mean here? // terminate Octave do_octave_atexit(); //----------------------------- All this works well when I have the code inside an executable C++ program (MSVC8.0). So far so good. Now for the interface via JNI I have to put this into a DLL which provides a thin layer between Java objects and the C interface to Octave. If I put the same code inside a DLL I can initialize Octave, but the eval_string () and other functions doe not work - they seem to do nothing. I found can do somethings with set_global_value () and get_global_value (), but this is not enough and also these "global" values seem to be something else than global variables in Octave. Anyway, I see that eval_string() seems to work when called from a C executable, but not when I call it from a DLL. Could this have something to do with i/o streams which are different in a DLL and in an EXE? Any ideas where to look and how to test? Thank You, Martin -- View this message in context: http://www.nabble.com/Java-package-tp15052296p19308994.html Sent from the octave-dev mailing list archive at Nabble.com. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev