本文整理汇总了C++中std::ofstream::precision方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::precision方法的具体用法?C++ ofstream::precision怎么用?C++ ofstream::precision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ofstream
的用法示例。
在下文中一共展示了ofstream::precision方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_footprint
void eventor::write_footprint(std::ofstream& fh)
{
// write the footprint out - write values out that are not mv
for (int j=0; j<footprint_height; j++)
for (int i=0; i<footprint_width; i++)
{
int idx = j*footprint_width+i;
if (wind_footprint[idx] > w_mv)
{
// get the true latitude / longitude from the rotated grid
FP_TYPE tru_lon, tru_lat;
tru_lon = mslp_field[0]->get_rotated_grid()->get_global_longitude_value(i,j);
tru_lat = mslp_field[0]->get_rotated_grid()->get_global_latitude_value(i,j);
// get the grid box corner points
std::list<FP_TYPE> gb_corners = mslp_field[0]->get_rotated_grid()->get_global_grid_box_values(i,j);
// write the data
fh.precision(2);
fh << std::fixed;
fh << tru_lon << "," << tru_lat << ",";
for (std::list<FP_TYPE>::iterator it_gbc = gb_corners.begin();
it_gbc != gb_corners.end(); it_gbc++)
fh << *it_gbc << ","; // order is lon0,lat0, lon1,lat1, lon2,lat2, lon3,lat3
fh.precision(0);
fh << mslp_footprint[idx] << ",";
fh.precision(2);
fh << wind_footprint[idx] << "," << std::endl;
}
}
}
示例2: write
static void
write(std::ofstream &file,
const CrsMatrixType A,
const std::string comment = "%% Tacho::MatrixMarket::Export",
const int uplo = 0) {
typedef typename CrsMatrixType::value_type value_type;
typedef typename CrsMatrixType::ordinal_type ordinal_type;
typedef typename CrsMatrixType::size_type size_type;
std::streamsize prec = file.precision();
file.precision(8);
file << std::scientific;
file << "%%MatrixMarket matrix coordinate "
<< (Util::isComplex<value_type>() ? "complex " : "real ")
<< ((uplo == Uplo::Upper || uplo == Uplo::Lower) ? "symmetric " : "general ")
<< std::endl;
file << comment << std::endl;
// cnt nnz
size_type nnz = 0;
for (ordinal_type i=0;i<A.NumRows();++i) {
const size_type jbegin = A.RowPtrBegin(i), jend = A.RowPtrEnd(i);
for (size_type j=jbegin;j<jend;++j) {
const auto aj = A.Col(j);
if (uplo == Uplo::Upper && i <= aj) ++nnz;
if (uplo == Uplo::Lower && i >= aj) ++nnz;
if (!uplo) ++nnz;
}
}
file << A.NumRows() << " " << A.NumCols() << " " << nnz << std::endl;
const int w = 10;
for (ordinal_type i=0;i<A.NumRows();++i) {
const size_type jbegin = A.RowPtrBegin(i), jend = A.RowPtrEnd(i);
for (size_type j=jbegin;j<jend;++j) {
const auto aj = A.Col(j);
bool flag = false;
if (uplo == Uplo::Upper && i <= aj) flag = true;
if (uplo == Uplo::Lower && i >= aj) flag = true;
if (!uplo) flag = true;
if (flag) {
value_type val = A.Value(j);
file << std::setw(w) << ( i+1) << " "
<< std::setw(w) << (aj+1) << " "
<< std::setw(w) << val << std::endl;
}
}
}
file.unsetf(std::ios::scientific);
file.precision(prec);
}
示例3: savetofile
bool GravStep::savetofile(std::ofstream& ofs, const unsigned int stepid) {
if (!ofs) {
debugout("savetofile() - No File found!", 99);
return false;
}
debugout("savetofile() - Objectlist", objects, 15);
ofs << "#" << stepid << ";" << numObjects << DELIMLINE;
ofs.precision(DATAPRECISION);
//Add Data of each object to datafile
std::vector<GravObject*>::iterator i;
for (i = objects.begin(); i != objects.end(); ++i) {
if (*i) {
//[Objekt ID];[Masse];[Radius];[Geschw.Vektor x];[Geschw.Vektor y];[Geschw.Vektor z];
//[Beschl.Vektor x];[Beschl.Vektor y];[Beschl.Vektor z];[Position x];[Position y];[Position z]
//debugout("Model - AddStep() - Adding data to file No"+i);
ofs << (*i)->id << DELIMDATA;
ofs << (*i)->mass << DELIMDATA;
ofs << (*i)->radius << DELIMDATA;
ofs << (*i)->vel.x << DELIMDATA;
ofs << (*i)->vel.y << DELIMDATA;
ofs << (*i)->vel.z << DELIMDATA;
ofs << (*i)->pos.x << DELIMDATA;
ofs << (*i)->pos.y << DELIMDATA;
ofs << (*i)->pos.z << DELIMLINE;
}
}
debugout("savetofile() - Step successfully saved!", 40);
return true;
}
示例4: pluginLoad
void pluginLoad()
{
if (notifyFrequency > 0)
{
// number of cells on the current CPU for each direction
const DataSpace<simDim> nrOfGpuCells = Environment<simDim>::get().SubGrid().getLocalDomain().size;
// create as much storage as cells in the direction we are interested in:
// on gpu und host
sliceDataField = new GridBuffer<float3_X, DIM1 >
(DataSpace<DIM1 > (nrOfGpuCells.y()));
Environment<>::get().PluginConnector().setNotificationPeriod(this, notifyFrequency);
const int rank = Environment<simDim>::get().GridController().getGlobalRank();
// open output file
std::stringstream oFileName;
oFileName << "lineSliceFields_" << rank << ".txt";
outfile.open(oFileName.str().c_str(), std::ofstream::out | std::ostream::trunc);
outfile.precision(8);
outfile.setf(std::ios::scientific);
}
}
示例5: TimeLoggingSolver
TimeLoggingSolver(Solver *_solver, std::string path, const InstructionInfoProvider* _iip)
: solver(_solver),
os(path.c_str(), std::ios::trunc),
queryCount(0),
iip(_iip) {
os.precision(2);
}
示例6: reportCSV
void ThermoPhase::reportCSV(std::ofstream& csvFile) const
{
int tabS = 15;
int tabM = 30;
csvFile.precision(8);
vector_fp X(nSpecies());
getMoleFractions(&X[0]);
std::vector<std::string> pNames;
std::vector<vector_fp> data;
getCsvReportData(pNames, data);
csvFile << setw(tabS) << "Species,";
for (size_t i = 0; i < pNames.size(); i++) {
csvFile << setw(tabM) << pNames[i] << ",";
}
csvFile << endl;
for (size_t k = 0; k < nSpecies(); k++) {
csvFile << setw(tabS) << speciesName(k) + ",";
if (X[k] > SmallNumber) {
for (size_t i = 0; i < pNames.size(); i++) {
csvFile << setw(tabM) << data[i][k] << ",";
}
csvFile << endl;
} else {
for (size_t i = 0; i < pNames.size(); i++) {
csvFile << setw(tabM) << 0 << ",";
}
csvFile << endl;
}
}
}
示例7: Show
void Matrix::Show() const
{
std::streamsize pr = cout.precision(5);
cout << std::left;
cout << "MATRIX " << n << 'x' << n << ": " << endl;
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
cout << std::setw(10);
cout << A[i][j];
cout << ' ';
}
cout << endl;
}
cout << endl;
cout.precision(pr);
}
示例8: WriteLasLine
void LasWell::WriteLasLine(std::ofstream & file,
const std::string & mnemonic,
const std::string & units,
double data,
const std::string & description)
{
file.precision(3);
file.setf(std::ios_base::fixed);
file << mnemonic << " ." << units << " " << data << " : " << description << "\n";
}
示例9: WriteOutput
void WriteOutput(const Points& centroids, std::ofstream& output) {
output.precision(15);
for (size_t centroid_id = 0; centroid_id != centroids.size();
++centroid_id) {
output << " centroid_id:" << centroid_id;
for (const double component : centroids[centroid_id]) {
output << '\t' << component;
}
output << std::endl;
}
}
示例10: addvector
/*!Add a field*/
void addvector(const string& nameoffield, Fem2D::Mesh* mesh, const KN<double>&val, const KN<double>&val2)
{
_ofdata.flags(std::ios_base::scientific);
_ofdata.precision(15);
_ofdata << "<DataArray type=\"Float32\" Name=\"";
_ofdata << nameoffield<<"\" NumberOfComponents=\"3\" format=\"ascii\">";
_ofdata << std::endl;
for(int i=0;i<val.size();++i) _ofdata<<checkprecision(val[i])<< " " << checkprecision(val2[i]) << " " << 0.0 << std::endl;
_ofdata << "</DataArray>" << std::endl;
_ofdata.flush();
}
示例11: write_cams
void write_cams(std::ofstream &file, CameraArray& cam_list)
{
file.precision(10);
file.setf(std::ios_base::scientific);
size_t n_cams = cam_list.size();
for (size_t i = 0; i < n_cams; ++i) {
Camera &cam = *(std::dynamic_pointer_cast<Camera>(cam_list[i]));
file << cam.focal[0] << " " << cam.disto_coeffs[0] << " " << cam.disto_coeffs[1] << std::endl;
file << cam.rotation.toRotationMatrix() << std::endl;
file << cam.translation.transpose() << std::endl;
}
}
示例12: write_points
void write_points(std::ofstream &file, std::vector<Point> &point_list)
{
size_t n_points = point_list.size();
for (size_t i = 0; i < n_points; ++i) {
Point &pt = point_list[i];
file.precision(10);
file.setf(std::ios_base::scientific);
file << pt.position.transpose() << std::endl;
file << pt.color.transpose() << std::endl;
write_visibility_list(file, pt);
}
}
示例13: write_vertices
void write_vertices(std::ofstream& fout,
const VectorF& vertices, const size_t dim) {
if (dim != 2 && dim != 3) {
throw IOError("Unsupported mesh dimension: " + std::to_string(dim));
}
fout.precision(16);
size_t num_vertices = vertices.size() / dim;
for (size_t i=0; i<num_vertices; i++) {
const auto& v = vertices.segment(i*dim, dim);
fout << "v";
for (size_t j=0; j<dim; j++) {
fout << " " << v[j];
}
fout << std::endl;
}
}
示例14: write_visibility_list
void write_visibility_list(std::ofstream &file, Point& pt)
{
file.precision(4);
file.unsetf(std::ios_base::scientific);
file.setf(std::ios_base::fixed, std::ios_base::floatfield);
size_t n_vis = pt.visibility_list.size();
file << n_vis << " ";
for (size_t i = 0; i < n_vis; ++i) {
Visibility &vis = pt.visibility_list[i];
file << vis.camera_idx << " " << vis.keypoint_idx << " " << vis.position.transpose() << " ";
}
file.unsetf(std::ios_base::fixed);
file.unsetf(std::ios_base::floatfield);
file << std::endl;
}
示例15: addmesh
void addmesh(Fem2D::Mesh* mesh)
{
Fem2D::Mesh& Th(*mesh);
_vecmesh.push_back(mesh);
_ofdata.flags(std::ios_base::scientific);
_ofdata.precision(15);
_ofdata << "<?xml version=\"1.0\"?>" << std::endl;
_ofdata << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" ;
_ofdata << std::endl;
_ofdata << "<UnstructuredGrid>" ; _ofdata << std::endl;
_ofdata << "<Piece NumberOfPoints=\"" << Th.nv << "\" NumberOfCells=\"" << Th.nt << "\">";
_ofdata << std::endl;
_ofdata << "<Points>" << std::endl;
_ofdata << "<DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">";
_ofdata << std::endl;
for(int k=0;k<Th.nv;++k) _ofdata << Th(k).x<<" "<<Th(k).y<< " " << 0.0 << std::endl;
_ofdata << "</DataArray>" << std::endl;
_ofdata << "</Points>" << std::endl;
_ofdata << "<Cells>" << std::endl;
_ofdata << "<DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">";
_ofdata << std::endl;
for(int i=0;i<Th.nt;++i)
for (int j=0; j <3; j++) _ofdata << Th(i,j) << " " ;
_ofdata << std::endl;
_ofdata << "</DataArray>" << std::endl;
_ofdata << "<DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">";
_ofdata << std::endl;
for(int i=0;i<Th.nt;++i) _ofdata << 3+3*(i) << " ";
_ofdata << std::endl;
_ofdata << "</DataArray>" << std::endl;
_ofdata << "<DataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">" ;
_ofdata<< std::endl;
for(int i=0;i<Th.nt;++i) _ofdata << 5 << " ";
_ofdata << std::endl;
_ofdata << "</DataArray>" << std::endl;
_ofdata << "</Cells>" << std::endl;
_ofdata << "<PointData >" << endl;
}