Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88607285
map_2d_square.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 19, 17:36
Size
2 KB
Mime Type
text/x-c++
Expires
Mon, Oct 21, 17:36 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21797234
Attached To
rTAMAAS tamaas
map_2d_square.cpp
View Options
/**
*
* @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>
/* -------------------------------------------------------------------------- */
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>;
Event Timeline
Log In to Comment