Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66205170
reader.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
Sun, Jun 9, 00:11
Size
1 KB
Mime Type
text/x-c
Expires
Tue, Jun 11, 00:11 (2 d)
Engine
blob
Format
Raw Data
Handle
18185944
Attached To
rTSUNAMIPROJECT PHPC-TSUNAMI-PROJECT
reader.cpp
View Options
//
// Created by Arnaud Pannatier on 06.05.18.
//
#include "reader.h"
#include <fstream>
#include <iostream>
#include <limits>
Grid Reader::readGridFromFile (std::string filename,std::size_t nx, std::size_t ny) {
Grid ret = Grid(nx,ny);
std::cout << filename << std::endl;
std::ifstream file (filename, std::ios::in | std::ios::binary);
if (file.is_open())
{
char * memblock;
file.ignore( std::numeric_limits<std::streamsize>::max() );
std::streamsize size = file.gcount();
file.clear();
std::cout << size << " -- size " << std::endl;
memblock = new char[size];
file.seekg (0, std::ios::beg);
file.read (memblock, size);
file.close();
//std::cout << "the entire file content is in memory" << std::endl;
double* double_values = reinterpret_cast<double*>(memblock);
for(std::size_t x(0); x<nx;x++) {
for (std::size_t y (0); y < ny; y++) {
ret (x, y) = double_values[y * nx + x];
}
}
delete memblock;
}else{
std::cout<< "File is not open ! " << std::endl;
}
return ret;
}
void Reader::writeGridInFile (Grid& g,std::string filename, std::size_t nx, std::size_t ny) {
std::cout << filename << std::endl;
double* double_values;
double_values= new double[nx*ny];
for(std::size_t x(0); x<nx;x++) {
for (std::size_t y (0); y < ny; y++) {
double_values[x * nx + y] = g(y,x);
}
}
char* memblock = reinterpret_cast<char*>(double_values);
std::ofstream file(filename, std::ios::out | std::ios::binary);
file.write (memblock, sizeof(memblock)*nx*ny);
std::cout << "Grid Saved ! " << std::endl;
delete double_values;
}
Event Timeline
Log In to Comment