From 3e638974d3b97ef114c5d5d9d7a4265a29467c27 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 24 Feb 2011 12:07:37 -0500 Subject: [PATCH] New tool for analyzing real data. Factorized the getopt generation procedure in CMake --- mytools/particleInfo.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ mytools/particleInfo.hpp | 23 ++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 mytools/particleInfo.cpp create mode 100644 mytools/particleInfo.hpp diff --git a/mytools/particleInfo.cpp b/mytools/particleInfo.cpp new file mode 100644 index 0000000..e651263 --- /dev/null +++ b/mytools/particleInfo.cpp @@ -0,0 +1,57 @@ +#include +#include +#include "particleInfo.hpp" + +using namespace std; +using namespace CosmoTool; + +bool loadParticleInfo(ParticleInfo& info, + const std::string& particles, + const std::string& extra_info) +{ + try + { + UnformattedRead f(particles); + + int numpart; + + f.beginCheckpoint(); + numpart = f.readInt32(); + f.endCheckpoint(); + + info.particles.resize(numpart); + + f.beginCheckpoint(); + for (int i = 0; i < numpart; i++) + info.particles[i].x = f.readReal32(); + f.endCheckpoint(); + + f.beginCheckpoint(); + for (int i = 0; i < numpart; i++) + info.particles[i].y = f.readReal32(); + f.endCheckpoint(); + + f.beginCheckpoint(); + for (int i = 0; i < numpart; i++) + info.particles[i].z = f.readReal32(); + f.endCheckpoint(); + } + catch (const NoSuchFileException& e) + { + return false; + } + + NcFile f_info(extra_info.c_str()); + + if (!f_info.is_valid()) + return false; + + info.ranges[0][0] = f_info.get_att("range_x_min")->as_double(0); + info.ranges[0][1] = f_info.get_att("range_x_max")->as_double(0); + info.ranges[1][0] = f_info.get_att("range_y_min")->as_double(0); + info.ranges[1][1] = f_info.get_att("range_y_max")->as_double(0); + info.ranges[2][0] = f_info.get_att("range_z_min")->as_double(0); + info.ranges[2][1] = f_info.get_att("range_z_max")->as_double(0); + + return true; +} diff --git a/mytools/particleInfo.hpp b/mytools/particleInfo.hpp new file mode 100644 index 0000000..b37555a --- /dev/null +++ b/mytools/particleInfo.hpp @@ -0,0 +1,23 @@ +#ifndef _PARTICLE_INFO_HEADER_HPP +#define _PARTICLE_INFO_HEADER_HPP + +#include +#include + +struct ParticleData { + float x, y, z; +}; + +typedef std::vector ParticleVector; + +struct ParticleInfo +{ + ParticleVector particles; + float ranges[3][2]; +}; + +bool loadParticleInfo(ParticleInfo& info, + const std::string& particles, + const std::string& extra_info); + +#endif