From dc8ef0be34d397cbed52be03789d6a96aa343aa3 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 15 Dec 2011 12:12:10 -0500 Subject: [PATCH] Flash fixes --- src/h5_readFlash.cpp | 26 +++++++++++++++++++------- src/h5_readFlash.hpp | 14 +++++++------- src/loadFlash.cpp | 23 +++++++++++++++-------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/h5_readFlash.cpp b/src/h5_readFlash.cpp index 0559a8f..0c78f58 100644 --- a/src/h5_readFlash.cpp +++ b/src/h5_readFlash.cpp @@ -179,13 +179,13 @@ void h5_read_flash3_particles (H5File* file, int* totalparticles, int* localnp, int* particle_offset, - float pos1[], - float pos2[], - float pos3[], - float vel1[], - float vel2[], - float vel3[], - int id[]) + float *pos1, + float *pos2, + float *pos3, + float *vel1, + float *vel2, + float *vel3, + int *id) { herr_t status; @@ -339,15 +339,27 @@ void h5_read_flash3_particles (H5File* file, /* convert buffer into particle struct */ + if (id) { for(p=0; p < (pcount); p++) { id[p+poffset] = (int) *(partBuffer+iptag-1+p*numProps); + } } + + if (pos1 && pos2 && pos3) { + for(p=0; p < (pcount); p++) { pos1[p+poffset] = (float) *(partBuffer+ipx-1+p*numProps); pos2[p+poffset] = (float) *(partBuffer+ipy-1+p*numProps); pos3[p+poffset] = (float) *(partBuffer+ipz-1+p*numProps); + } + } + + + if (vel1 && vel2 && vel3) { + for(p=0; p < (pcount); p++) { vel1[p+poffset] = (float) *(partBuffer+ipvx-1+p*numProps); vel2[p+poffset] = (float) *(partBuffer+ipvy-1+p*numProps); vel3[p+poffset] = (float) *(partBuffer+ipvz-1+p*numProps); } + } memspace.close(); //status = H5Sclose(memspace); diff --git a/src/h5_readFlash.hpp b/src/h5_readFlash.hpp index 273ca07..5187232 100644 --- a/src/h5_readFlash.hpp +++ b/src/h5_readFlash.hpp @@ -23,13 +23,13 @@ void h5_read_flash3_particles (H5File* file, int* totalparticles, int* localnp, int* particle_offset, - float pos1[], - float pos2[], - float pos3[], - float vel1[], - float vel2[], - float vel3[], - int id[]); + float *pos1, + float *pos2, + float *pos3, + float *vel1, + float *vel2, + float *vel3, + int *id); void h5_read_flash3_header_info(H5File* file, double* time, /* simulation time */ diff --git a/src/loadFlash.cpp b/src/loadFlash.cpp index cc58521..ada498d 100644 --- a/src/loadFlash.cpp +++ b/src/loadFlash.cpp @@ -51,29 +51,36 @@ SimuData *CosmoTool::loadFlashMulti(const char *fname, int id, int loadflags) data->Omega_Lambda = omegalambda; // particle data - for (int i = 0; i < 3; i++) { - data->Pos[i] = new float[data->NumPart]; - if (data->Pos[i] == 0) { - delete data; + if (loadflags& NEED_POSITION) { + for (int i = 0; i < 3; i++) { + data->Pos[i] = new float[data->NumPart]; + if (data->Pos[i] == 0) { + delete data; return 0; } - } + } } + + if (loadflags &NEED_VELOCITY) { for (int i = 0; i < 3; i++) { data->Vel[i] = new float[data->NumPart]; if (data->Vel[i] == 0) { delete data; return 0; } - } + } } + if (loadflags & NEED_GADGET_ID) { data->Id = new int[data->NumPart]; if (data->Id == 0) { delete data; return 0; } + } int offset = 0; + + if (loadflags &(NEED_GADGET_ID|NEED_POSITION|NEED_VELOCITY)) h5_read_flash3_particles(&file, &npart, &npart, &offset, data->Pos[0], data->Pos[1], data->Pos[2], data->Vel[0], data->Vel[1], data->Vel[2], @@ -81,8 +88,8 @@ SimuData *CosmoTool::loadFlashMulti(const char *fname, int id, int loadflags) for (int i = 0; i < 3; i++) { for (int n = 0; n < data->NumPart; n++) { - data->Pos[i][n] = data->Pos[i][n] * data->Hubble / kpc2cm; - data->Vel[i][n] = data->Vel[i][n] * data->Hubble / km2cm; + if (loadflags& NEED_POSITION) data->Pos[i][n] = data->Pos[i][n] * data->Hubble / kpc2cm; + if (loadflags&NEED_VELOCITY) data->Vel[i][n] = data->Vel[i][n] * data->Hubble / km2cm; } }