Page MenuHomec4science

map_2d_square.cpp
No OneTemporary

File Metadata

Created
Sat, Apr 27, 21:05

map_2d_square.cpp

/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "map_2d_square.hh"
#include <fstream>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
template <typename T>
void Map2dSquare<T>::loadFromTextFile(std::string filename, int each) {
std::string line;
std::ifstream myfile (filename.c_str());
UInt n = 0;
if (myfile.is_open()) {
while (! myfile.eof() ) {
getline (myfile,line);
if (line[0] == '#')
continue;
if (line.size() == 0)
continue;
std::stringstream s;
s << line;
UInt i,j;
s >> i;
s >> j;
if (n < i) n = i;
if (n < j) n = j;
}
++n;
std::cout << "read " << n << " x " << n << " grid points" << std::endl;
myfile.clear(); // forget we hit the end of file
myfile.seekg(0, std::ios::beg); // move to the start of the file
n = int(n/Real(each));
setGridSize(n);
while (! myfile.eof() ) {
getline (myfile,line);
if (line == "") continue;
std::stringstream s;
s << line;
int i,j;
s >> i;
s >> j;
T val = this->readValue(s);
if (i % each == 0 && j % each == 0) {
this->at(i/each,j/each) = val;
}
}
myfile.close();
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
T Map2dSquare<T>::readValue(std::stringstream & sstr) {
SURFACE_FATAL("To implement");
}
/* -------------------------------------------------------------------------- */
template <>
Complex Map2dSquare<Complex>::readValue(std::stringstream & sstr) {
Real h = 0.,hIm = 0.;
sstr >> h;
sstr >> hIm;
return Complex(h,hIm);
}
/* -------------------------------------------------------------------------- */
template class Map2dSquare<Complex>;
template class Map2dSquare<Real>;
template class Map2dSquare<int>;
template class Map2dSquare<unsigned long>;
__END_TAMAAS__

Event Timeline