Added support for more options in reading flash files

This commit is contained in:
Guilhem Lavaux 2012-03-30 10:48:44 -05:00
parent 607f452f7c
commit aeb9b33d2d
3 changed files with 41 additions and 22 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -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;
}
}