Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One thing you could do is to run a separate program using <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html" rel="nofollow">Runtime</a> to start a <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Process.html" rel="nofollow">Process</a> consisting of your fortran code. The following is an example of this:</p> <pre><code>Runtime rt = Runtime.getRuntime(); try { String[] env = {"/path/to/program"}; Process proc = rt.exec("your_program", env); System.out.println("return value: " + proc.waitFor()); } catch (Exception ex) { System.err.println(ex); } </code></pre> <p>The above code will execute /path/to/program/your_program and wait for it to finish and then read off the return code.</p> <p>Alternatively, you could write some information to <em>stdout</em> and read that from your java program:</p> <pre><code>import java.io.*; ... Runtime rt = Runtime.getRuntime(); try { String[] env = {"/path/to/program"}; Process proc = rt.exec("your_program", env); System.out.println("return value: " + proc.waitFor()); InputStream stream = proc.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); while (reader.ready()) { // Do something with the data here. System.out.println(reader.readLine()); } } catch (Exception ex) { System.err.println(ex); } </code></pre> <p>If you need to supply the external program with arguments you pass them as an array of strings. As an example, if I wanted to run <code>ls -lh /etc/</code> that is what the following code does:</p> <pre><code> String[] cmd = {"ls", "-lh", "/etc/"}; String[] env = {"/bin/"}; Process proc = rt.exec(cmd, env); </code></pre> <p>You could also try using <a href="http://en.wikipedia.org/wiki/Java_Native_Interface" rel="nofollow">Java Native Interface</a> to communicate with C/C++ code which can interface with fortran.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload