void NRLib::WriteStormBinarySurf(const RegularSurface<A> & surf, const std::string & filename) { std::ofstream file; OpenWrite(file, filename.c_str(), std::ios::out | std::ios::binary); file.precision(14); file << "STORMGRID_BINARY\n\n" << surf.GetNI() << " " << surf.GetNJ() << " " << surf.GetDX() << " " << surf.GetDY() << "\n" << surf.GetXMin() << " " << surf.GetXMax() << " " << surf.GetYMin() << " " << surf.GetYMax() << "\n"; if (surf.GetMissingValue() == STORM_MISSING) { // Purify *sometimes* claims a UMR for the call below. No-one understands why... WriteBinaryDoubleArray(file, surf.begin(), surf.end()); } else { std::vector<double> data(surf.GetN()); std::copy(surf.begin(), surf.end(), data.begin()); std::replace(data.begin(), data.end(), surf.GetMissingValue(), static_cast<A>(STORM_MISSING)); WriteBinaryDoubleArray(file, data.begin(), data.end()); } file.close(); }
void NRLib::WriteIrapClassicAsciiSurf(const RegularSurface<A> & surf, double angle, const std::string & filename) { std::ofstream file; OpenWrite(file, filename); file << std::fixed << std::setprecision(6) << -996 << " " << surf.GetNJ() << " " << surf.GetDX() << " " << surf.GetDY() << "\n" << std::setprecision(2) << surf.GetXMin() << " " << surf.GetXMax() << " " << surf.GetYMin() << " " << surf.GetYMax() << "\n" << surf.GetNI() << " " << std::setprecision(6) << angle*180/NRLib::Pi << " " << std::setprecision(2) << surf.GetXMin() << " " << surf.GetYMin() << "\n" << " 0 0 0 0 0 0 0\n"; file.precision(6); if (surf.GetMissingValue() == IRAP_MISSING) { for (size_t i = 0; i < surf.GetN(); i++) { file << surf(i) << " "; if((i+1) % 6 == 0) file << "\n"; } } else { for (size_t i = 0; i < surf.GetN(); i++) { if (surf.IsMissing(surf(i))) file << IRAP_MISSING << " "; else file << surf(i) << " "; if((i+1) % 6 == 0) file << "\n"; } } file.close(); }