Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jmat/function/InvokeDoubleFunction.java


1   package jmat.function;
2   
3   import jmat.data.Matrix;
4   
5   import jmat.io.data.MatrixFile;
6   
7   import java.io.File;
8   import java.io.IOException;
9   
10  
11  /**
12   * DOCUMENT ME!
13   *
14   * @author $author$
15   * @version $Revision: 1.3 $
16   */
17  public class InvokeDoubleFunction
18  {
19      //~ Instance fields ////////////////////////////////////////////////////////
20  
21      File functionFile;
22      File resultFile;
23  
24      //~ Constructors ///////////////////////////////////////////////////////////
25  
26      public InvokeDoubleFunction(String fn, String rf)
27      {
28          functionFile = new File(fn);
29          resultFile = new File(rf);
30      }
31  
32      public InvokeDoubleFunction(File fn, File rf)
33      {
34          functionFile = fn;
35          resultFile = rf;
36      }
37  
38      //~ Methods ////////////////////////////////////////////////////////////////
39  
40      public double eval()
41      {
42          try
43          {
44              Process p = Runtime.getRuntime().exec(functionFile.getName());
45              p.waitFor();
46  
47              MatrixFile mf = new MatrixFile(resultFile);
48              Matrix X = mf.getMatrix();
49  
50              return new Double(X.get(0, 0)).doubleValue();
51          }
52           catch (Exception e)
53          {
54              System.out.println("Error : File " + resultFile + " unreadable : " +
55                  e);
56  
57              return Double.NaN;
58          }
59      }
60  }
61  ///////////////////////////////////////////////////////////////////////////////
62  //  END OF FILE.
63  ///////////////////////////////////////////////////////////////////////////////