Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rambaut committed Jan 26, 2025
2 parents d66f811 + 508e349 commit c094a78
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 63 deletions.
2 changes: 0 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@
<zipgroupfileset dir="${lib}" includes="jdom.jar"/>
<zipgroupfileset dir="${lib}" includes="commons-math-2.2.jar"/>
<zipgroupfileset dir="${lib}" includes="mtj.jar"/>
<!-- <zipgroupfileset dir="${lib}" includes="JRI.jar"/> -->
<zipgroupfileset dir="${lib}" includes="colt.jar"/>
<zipgroupfileset dir="${lib}" includes="beagle.jar"/>
<zipgroupfileset dir="${lib}" includes="EJML-core-0.30.jar"/>
Expand Down Expand Up @@ -726,7 +725,6 @@
<!-- <fileset dir="${Mac_dir}/lib"/> -->
<fileset dir="lib">
<include name="*.jar"/>
<exclude name="JRI.jar"/>
</fileset>
</copy>
<copy file="${common_dir}/VERSION HISTORY.txt" todir="${Mac_package_dir}"/>
Expand Down
Binary file removed lib/JRI.jar
Binary file not shown.
126 changes: 65 additions & 61 deletions src/dr/geo/contouring/ContourWithR.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

package dr.geo.contouring;

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.RVector;
import org.rosuda.JRI.Rengine;
//import org.rosuda.JRI.REXP;
//import org.rosuda.JRI.RVector;
//import org.rosuda.JRI.Rengine;

/**
* @author Marc Suchard
Expand All @@ -42,26 +42,28 @@ public ContourWithR(final double[] xValues, final double[] yValues) {
}

public ContourWithR(final double[] xValues, final double[] yValues, int N) {
this.xValues = xValues;
this.yValues = yValues;
this.N = N;
throw new UnsupportedOperationException("R jnilib no longer supported");
// this.xValues = xValues;
// this.yValues = yValues;
// this.N = N;
}

private final double[] xValues;
private final double[] yValues;

public ContourPath[] getContourPaths(double hpdValue) {
makeContour(xValues, yValues, hpdValue, N);
if (contourList == null)
return null;

ContourPath[] contourPaths = new ContourPath[getNumberContours()];

for(int i=0; i<getNumberContours(); i++) {
double[][] cont = getContour(i);
contourPaths[i] = new ContourPath(null,1,cont[0],cont[1]);
}
return contourPaths;
throw new UnsupportedOperationException("R jnilib no longer supported");
// makeContour(xValues, yValues, hpdValue, N);
// if (contourList == null)
// return null;
//
// ContourPath[] contourPaths = new ContourPath[getNumberContours()];
//
// for(int i=0; i<getNumberContours(); i++) {
// double[][] cont = getContour(i);
// contourPaths[i] = new ContourPath(null,1,cont[0],cont[1]);
// }
// return contourPaths;
}


Expand All @@ -70,43 +72,45 @@ public void makeContour(double[] xValues, double[] yValues, double hpd) {
}

public void makeContour(double[] xValues, double[] yValues, double hpd, int N) {


REXP x = rEngine.eval("makeContour(" +
makeRString(xValues) + "," +
makeRString(yValues) + "," +
hpd + "," +
N + ")");
contourList = x.asVector();
throw new UnsupportedOperationException("R jnilib no longer supported");

// REXP x = rEngine.eval("makeContour(" +
// makeRString(xValues) + "," +
// makeRString(yValues) + "," +
// hpd + "," +
// N + ")");
// contourList = x.asVector();
}

public int getNumberContours() {
if (contourList != null)
return contourList.size();
return 0;
throw new UnsupportedOperationException("R jnilib no longer supported");
// if (contourList != null)
// return contourList.size();
// return 0;
}




public double[][] getContour(int whichContour) {

if (contourList != null) {
double[][] result = new double[2][];
RVector oneContour = contourList.at(whichContour).asVector();
result[0] = oneContour.at(1).asDoubleArray();
result[1] = oneContour.at(2).asDoubleArray();
return result;
}
return null;
throw new UnsupportedOperationException("R jnilib no longer supported");

// if (contourList != null) {
// double[][] result = new double[2][];
// RVector oneContour = contourList.at(whichContour).asVector();
// result[0] = oneContour.at(1).asDoubleArray();
// result[1] = oneContour.at(2).asDoubleArray();
// return result;
// }
// return null;
}


private static Rengine rEngine = null;
// private static Rengine rEngine = null;
private int N;


private RVector contourList = null;
// private RVector contourList = null;

private static final String[] rArgs = {"--no-save", "--max-vsize=1G"};

Expand Down Expand Up @@ -137,27 +141,27 @@ private String makeRString(double[] values) {

static public boolean processWithR = false;

static {
try {
System.loadLibrary("jri");
processWithR = true;
System.err.println("JRI loaded. Will process using R contouring.");

// if (!Rengine.versionCheck()) {
// throw new RuntimeException("JRI library version mismatch");
// static {
// try {
// System.loadLibrary("jri");
// processWithR = true;
// System.err.println("JRI loaded. Will process using R contouring.");
//
//// if (!Rengine.versionCheck()) {
//// throw new RuntimeException("JRI library version mismatch");
//// }
//
// rEngine = new Rengine(rArgs, false, null);
//
// if (!rEngine.waitForR()) {
// throw new RuntimeException("Cannot load R");
// }

rEngine = new Rengine(rArgs, false, null);

if (!rEngine.waitForR()) {
throw new RuntimeException("Cannot load R");
}

for (String command : rBootCommands) {
rEngine.eval(command);
}
} catch (UnsatisfiedLinkError e) {
System.err.println("JRI not available. Will process using Java contouring.");
}
}
//
// for (String command : rBootCommands) {
// rEngine.eval(command);
// }
// } catch (UnsatisfiedLinkError e) {
// System.err.println("JRI not available. Will process using Java contouring.");
// }
// }
}

0 comments on commit c094a78

Please sign in to comment.