Skip to content

Commit

Permalink
NRLib: Fixed missing precision in LAS file export
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobStoren committed Nov 6, 2015
1 parent e8cf23b commit 38be5ba
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions ThirdParty/NRLib/nrlib/well/laswell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,19 @@ void LasWell::AddLog(const std::string & name,
}


int calculatePrecision(double value)
{
double absVal = fabs(value);
if (1e-16 < absVal && absVal < 1.0e3){
int logVal = static_cast<int>(log(absVal));
int numDigitsAfterPoint = abs(logVal - 6);
return numDigitsAfterPoint;
}
else{
return 3;
}
}

void LasWell::WriteToFile(const std::string & filename,
const std::vector<std::string> & comment_header)
{
Expand Down Expand Up @@ -518,13 +531,17 @@ void LasWell::WriteToFile(const std::string & filename,
file.precision(3);
for (size_t i = 0; i < logs[0]->size(); ++i) {
for (size_t j = 0; j < logs.size(); ++j) {
file << (*logs[j])[i] << " ";
// Calculate a sensible precision. LAS does not support scientific notation
double value = (*logs[j])[i];
int numDigitsAfterPoint = calculatePrecision(value);

file.precision(numDigitsAfterPoint);
file << value << " ";
}
file << "\n";
}
}


void LasWell::WriteLasLine(std::ofstream & file,
const std::string & mnemonic,
const std::string & units,
Expand Down

0 comments on commit 38be5ba

Please sign in to comment.