From 468f5222b8f04aef6d51ec0c95ef32aba56e8ba8 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 20 May 2014 16:27:41 +0200 Subject: [PATCH] New tool to convert a gadget to a HDF5 file --- sample/CMakeLists.txt | 4 +++ sample/gadgetToArray.cpp | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 sample/gadgetToArray.cpp diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 5180106..47a74b5 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -37,6 +37,10 @@ if (HDF5_FOUND) add_executable(testHDF5 testHDF5.cpp) target_link_libraries(testHDF5 ${tolink}) + + add_executable(gadgetToArray gadgetToArray.cpp) + target_link_libraries(gadgetToArray ${tolink}) + endif (HDF5_FOUND) diff --git a/sample/gadgetToArray.cpp b/sample/gadgetToArray.cpp new file mode 100644 index 0000000..eb01e9a --- /dev/null +++ b/sample/gadgetToArray.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "cic.hpp" +#include "loadGadget.hpp" +#include "miniargs.hpp" +#include +#include "hdf5_array.hpp" + +using namespace CosmoTool; +using namespace std; + +int main(int argc, char **argv) +{ + typedef boost::multi_array array_type; + uint32_t res; + char *fname; + int id; + + MiniArgDesc desc[] = { + { "SNAPSHOT", &fname, MINIARG_STRING }, + { 0, 0, MINIARG_NULL } + }; + + if (!parseMiniArgs(argc, argv, desc)) + return 1; + + H5::H5File f("density.h5", H5F_ACC_TRUNC); + + + SimuData *p = loadGadgetMulti(fname, 0, 0); + double L0 = p->BoxSize/1000; + array_type parts(boost::extents[p->TotalNumPart][3]); + uint64_t q = 0; + + try { + for (int cpuid=0;;cpuid++) { + p = loadGadgetMulti(fname, cpuid, NEED_POSITION); + for (uint32_t i = 0; i < p->NumPart; i++) + { + parts[q][0] = p->Pos[0][i]/1000; + parts[q][1] = p->Pos[1][i]/1000; + parts[q][2] = p->Pos[2][i]/1000; + q++; + } + + delete p; + } + } catch (const NoSuchFileException& e) {} + + hdf5_write_array(f, "particles", parts); + + return 0; +}