Merge pull request #34 from tboudreaux/fix/opatIndexError
Fix floating point round off error when looking up tables by composition
This commit is contained in:
@@ -171,9 +171,13 @@ void OpatIO::LookupEpsilon() {
|
||||
for (int j = 1; j < static_cast<int>(header.numTables); j++) {
|
||||
epsilon = std::min(epsilon, std::fabs(tableIDToIndex.at(j).at(i) - tableIDToIndex.at(j-1).at(i)));
|
||||
}
|
||||
if (epsilon < 1e-8) {
|
||||
indexEpsilon.at(i) = 1e-8;
|
||||
} else {
|
||||
indexEpsilon.at(i) = epsilon * 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int OpatIO::lookupTableID(std::vector<double> index) {
|
||||
std::vector<bool> IndexOkay;
|
||||
|
||||
@@ -16,4 +16,5 @@ subdir('network')
|
||||
|
||||
# Subdirectories for sandbox tests
|
||||
subdir('dobj_sandbox')
|
||||
subdir('opatIO_sandbox')
|
||||
|
||||
|
||||
BIN
tests/opatIO_sandbox/GS98hz.opat
Normal file
BIN
tests/opatIO_sandbox/GS98hz.opat
Normal file
Binary file not shown.
1
tests/opatIO_sandbox/meson.build
Normal file
1
tests/opatIO_sandbox/meson.build
Normal file
@@ -0,0 +1 @@
|
||||
executable('tryGS98', 'opacity.cpp', dependencies: [opatio_dep])
|
||||
28
tests/opatIO_sandbox/opacity.cpp
Normal file
28
tests/opatIO_sandbox/opacity.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
//#include <string>
|
||||
#include "opatIO.h"
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
std::string FILENAME = "GS98hz.opat";
|
||||
OpatIO opatIO(FILENAME);
|
||||
Header header = opatIO.getHeader();
|
||||
std::cout << header.version << std::endl;
|
||||
std::cout << header.comment << std::endl;
|
||||
std::cout << header.numTables << std::endl;
|
||||
|
||||
std::vector<TableIndex> tableIndex = opatIO.getTableIndex();
|
||||
|
||||
//print out the X,Z pairs in the table
|
||||
for (size_t i=0; i< tableIndex.size()-1; i++){
|
||||
std::cout << "Table [" << i << "]: {" << tableIndex[i].index.at(0) << ", "
|
||||
<< tableIndex[i].index.at(1) << "}" << std::endl;
|
||||
}
|
||||
|
||||
//find the table index corresponding to X=0.1, Z=0.001
|
||||
std::vector<double> index = {0.1, 0.001};
|
||||
OPATTable tab = opatIO.getTable(index);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user