Commit 5342d900 authored by GILLES Sebastien's avatar GILLES Sebastien

#0 Minor modifications during review (mostly about types).

parent 51470460
......@@ -62,7 +62,7 @@ namespace MoReFEM
const auto Nbits = Nvalue * sizeof(double);
std::vector<char> binary_values(Nbits);
std::memcpy(binary_values.data(), array, Nbits);
out.write(binary_values.data(), static_cast<long>(Nbits));
out.write(binary_values.data(), static_cast<std::streamsize>(Nbits));
out.close();
break;
}
......@@ -83,7 +83,7 @@ namespace MoReFEM
}
case binary_or_ascii::from_input_data:
{
assert( false && "This function should be called from Vector class, and this specific case "
assert(false && "This function should be called from Vector class, and this specific case "
"should have been addressed prior to this call (see Vector::Print() for instance "
"to see how).");
exit(EXIT_FAILURE);
......
......@@ -33,14 +33,16 @@ namespace MoReFEM::Advanced
if (in)
{
// Get length of file.
std::ifstream::pos_type block_size;
block_size = in.seekg(0, std::ifstream::end).tellg();
std::ifstream::pos_type block_size_helper;
block_size_helper = in.seekg(0, std::ifstream::end).tellg();
in.seekg(0, std::ifstream::beg);
std::vector<char> buffer(static_cast<std::size_t>(block_size));
const auto block_size = static_cast<std::size_t>(block_size_helper);
std::vector<char> buffer(block_size);
// Read data as a block.
in.read(buffer.data(), block_size);
in.read(buffer.data(), block_size_helper);
if (!in)
throw Exception("Unable to read file " + binary_file, invoking_file, invoking_line);
......@@ -48,16 +50,14 @@ namespace MoReFEM::Advanced
in.close();
// Buffer contains the entire file. Convert bytes back into doubles.
const unsigned long Ndouble_values = static_cast<std::size_t>(block_size) / sizeof(double);
std::vector<double> values(Ndouble_values);
std::memcpy(values.data(), buffer.data(), static_cast<std::size_t>(block_size));
const auto Ndouble_values = static_cast<std::size_t>(block_size) / sizeof(double);
ret.resize(Ndouble_values);
std::memcpy(ret.data(), buffer.data(), block_size);
for (std::size_t i = 0u; i < Ndouble_values; ++i)
for (auto& item : ret)
{
if (std::fabs(values[i]) <= epsilon)
ret.push_back(0.);
else
ret.push_back(values[i]);
if (std::fabs(item) <= epsilon)
item = 0.;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment