コード例 #1
0
void writeToFile(std::string const& id_area_fname, std::string const& csv_fname,
	std::vector<std::pair<std::size_t, double>> const& ids_and_areas,
	std::vector<MeshLib::Node*> const& mesh_nodes)
{
	std::ofstream ids_and_area_out(id_area_fname);
	if (!ids_and_area_out) {
		ERR("Unable to open the file \"%s\" - aborting.", id_area_fname.c_str());
		std::abort();
	}
	std::ofstream csv_out(csv_fname);
	if (!csv_out) {
		ERR("Unable to open the file \"%s\" - aborting.", csv_fname.c_str());
		std::abort();
	}

	ids_and_area_out << std::setprecision(20);
	csv_out << std::setprecision(20);

	ids_and_area_out << ids_and_areas[0].first << " " << ids_and_areas[0].second;
	csv_out << "ID x y z area node_id\n"; // CSV header
	csv_out << 0 << " " << *mesh_nodes[ids_and_areas[0].first]
			<< ids_and_areas[0].second << " " << ids_and_areas[0].first;
	for (std::size_t k(1); k<ids_and_areas.size(); k++) {
		ids_and_area_out << "\n"
			<< ids_and_areas[k].first << " " << ids_and_areas[k].second;
		csv_out << "\n" << k << " " << *mesh_nodes[ids_and_areas[k].first]
			<< ids_and_areas[k].second << " " << ids_and_areas[k].first;
	}
	ids_and_area_out << "\n";
	csv_out << "\n";
}
コード例 #2
0
static
void writeToFile(std::string const& id_area_fname, std::string const& csv_fname,
    std::vector<std::pair<std::size_t, double>> const& ids_and_areas,
    std::vector<MeshLib::Node*> const& mesh_nodes)
{
    std::ofstream ids_and_area_out(id_area_fname);
    if (!ids_and_area_out) {
        ERR("Unable to open the file \"%s\" - aborting.", id_area_fname.c_str());
        std::abort();
    }
    std::ofstream csv_out(csv_fname);
    if (!csv_out) {
        ERR("Unable to open the file \"%s\" - aborting.", csv_fname.c_str());
        std::abort();
    }

    ids_and_area_out.precision(std::numeric_limits<double>::digits10);
    csv_out.precision(std::numeric_limits<double>::digits10);

    csv_out << "ID x y z area node_id\n"; // CSV header
    for (std::size_t k(0); k<ids_and_areas.size(); k++) {
        ids_and_area_out << ids_and_areas[k].first << " "
                         << ids_and_areas[k].second << "\n";
        csv_out << k << " " << *(mesh_nodes[k]) << ids_and_areas[k].second
                << " " << ids_and_areas[k].first << "\n";
    }
    ids_and_area_out << "\n";
    csv_out << "\n";
}