Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91398011
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, Nov 10, 17:37
Size
1 KB
Mime Type
text/x-c
Expires
Tue, Nov 12, 17:37 (2 d)
Engine
blob
Format
Raw Data
Handle
22257292
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,int nx, int 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(int x(0); x<nx;x++) {
for (int 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, int nx, int ny) {
std::cout << filename << std::endl;
double* double_values;
double_values= new double[nx*ny];
for(int x(0); x<nx;x++) {
for (int 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