writeVector(): Avoid unneeded type conversion
std::floor() returns a double so assigning it to an int introduces a type conversion. There is no need to do that. In the process, do away with the restriction that we only write entire lines.
This commit is contained in:
parent
a39e5a1366
commit
a29e5db8e1
@ -44,7 +44,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace OPM
|
namespace OPM
|
||||||
{
|
{
|
||||||
@ -119,18 +118,19 @@ namespace OPM
|
|||||||
\param[in] os is is stream of the file.
|
\param[in] os is is stream of the file.
|
||||||
\param[out] vag_grid is a resized and filled vector containing the quantiy read.
|
\param[out] vag_grid is a resized and filled vector containing the quantiy read.
|
||||||
\param[in] n number of doubles on each line.
|
\param[in] n number of doubles on each line.
|
||||||
The function will only write full lines an potentially skip numbers at end of the vector.
|
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void writeVector(std::ostream& os,std::vector<T>& vec,int n){
|
void writeVector(std::ostream& os,std::vector<T>& vec,int n){
|
||||||
using namespace std;
|
typedef typename std::vector<T>::size_type sz_t;
|
||||||
int lines = floor(vec.size()/n);
|
|
||||||
assert(vec.size()%n==0);
|
const sz_t nn = n;
|
||||||
for(int j=0;j< lines;++j){
|
|
||||||
for(int i=0;i< n;++i){
|
for (sz_t i = 0; i < vec.size(); ++i) {
|
||||||
os << vec[j*n+i] << " ";
|
os << vec[i] << (((i % nn) == 0) ? '\n' : ' ');
|
||||||
}
|
}
|
||||||
os << endl;
|
|
||||||
|
if ((vec.size() % nn) != 0) {
|
||||||
|
os << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user