Skip to content

Commit

Permalink
Merge pull request #5 from wsp-sag/bart-feat-omx-read
Browse files Browse the repository at this point in the history
Bart feat add float to omx reader
  • Loading branch information
i-am-sijia committed Oct 13, 2022
2 parents d03566a + 0fa64d0 commit 996a02a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import omx.OmxFile;
import omx.OmxMatrix;
import omx.OmxMatrix.OmxDoubleMatrix;
import omx.OmxMatrix.OmxFloatMatrix;
import omx.OmxLookup;

/**
Expand Down Expand Up @@ -81,36 +82,64 @@ public Matrix[] readMatrices() throws MatrixException {
*
*/
private Matrix readData(String name) {
OmxMatrix.OmxDoubleMatrix omxMat = null;

try {
omxMat = (OmxDoubleMatrix) omxFile.getMatrix(name);
double[][] values = omxMat.getData();

//convert to Matrix float[][]
float[][] valuesFloat = new float[values.length][values[0].length];
for (int i = 0 ; i < values.length; i++) {
for (int j = 0 ; j < values[0].length; j++) {
valuesFloat[i][j] = (float) values[i][j];
}
try {
OmxMatrix.OmxDoubleMatrix omxMat = null;
omxMat = (OmxDoubleMatrix) omxFile.getMatrix(name);
double[][] values = omxMat.getData();

//convert to Matrix float[][]
float[][] valuesFloat = new float[values.length][values[0].length];
for (int i = 0 ; i < values.length; i++) {
for (int j = 0 ; j < values[0].length; j++) {
valuesFloat[i][j] = (float) values[i][j];
}
}

Matrix m = new Matrix(name, name, valuesFloat);

//set zone numbers if found
//CUBE - 1 to X
//VISUM - 'NO'
//EMME - 'zone number'
//TransCAD - ?
if (omxFile.getLookupNames().contains("NO")) {
OmxLookup.OmxIntLookup omxZoneNums = (OmxLookup.OmxIntLookup)omxFile.getLookup("NO");
m.setExternalNumbersZeroBased(omxZoneNums.getLookup());
}
if (omxFile.getLookupNames().contains("zone number")) {
OmxLookup.OmxIntLookup omxZoneNums = (OmxLookup.OmxIntLookup)omxFile.getLookup("zone number");
m.setExternalNumbersZeroBased(omxZoneNums.getLookup());
}

return m;

}

Matrix m = new Matrix(name, name, valuesFloat);

//set zone numbers if found
//CUBE - 1 to X
//VISUM - 'NO'
//EMME - 'zone number'
//TransCAD - ?
if (omxFile.getLookupNames().contains("NO")) {
OmxLookup.OmxIntLookup omxZoneNums = (OmxLookup.OmxIntLookup)omxFile.getLookup("NO");
m.setExternalNumbersZeroBased(omxZoneNums.getLookup());
}
if (omxFile.getLookupNames().contains("zone number")) {
OmxLookup.OmxIntLookup omxZoneNums = (OmxLookup.OmxIntLookup)omxFile.getLookup("zone number");
m.setExternalNumbersZeroBased(omxZoneNums.getLookup());
}

return m;
catch (Exception e1) {

OmxMatrix.OmxFloatMatrix omxMat = null;
omxMat = (OmxFloatMatrix) omxFile.getMatrix(name);
float[][] valuesFloat = omxMat.getData();

Matrix m = new Matrix(name, name, valuesFloat);

//set zone numbers if found
//CUBE - 1 to X
//VISUM - 'NO'
//EMME - 'zone number'
//TransCAD - ?
if (omxFile.getLookupNames().contains("NO")) {
OmxLookup.OmxIntLookup omxZoneNums = (OmxLookup.OmxIntLookup)omxFile.getLookup("NO");
m.setExternalNumbersZeroBased(omxZoneNums.getLookup());
}
if (omxFile.getLookupNames().contains("zone number")) {
OmxLookup.OmxIntLookup omxZoneNums = (OmxLookup.OmxIntLookup)omxFile.getLookup("zone number");
m.setExternalNumbersZeroBased(omxZoneNums.getLookup());
}

return m;
}
}
catch (Exception e) {
throw new MatrixException("Matrix not found: " + name);
Expand Down
Binary file modified core/projects/mtc/release/mtc.jar
Binary file not shown.
Binary file modified model-files/runtime/mtc.jar
Binary file not shown.

0 comments on commit 996a02a

Please sign in to comment.