diff --git a/examples/test.c b/examples/test.c index 61ffcf76b2ef2f33d7724bdb8a0d69f1da80f48f..5a1de5c571350e9bc6b447e2a1c14e3654656aed 100644 --- a/examples/test.c +++ b/examples/test.c @@ -795,15 +795,11 @@ int main ( int argc , char *argv[] ) { /* Dump the first few particles. */ // for(k=0; k<10; ++k) - // printParticle(parts, k); + // printParticle(parts, k, N); // printParticle( parts , 6178 , N ); // pairs_single( dim , 8525152967533 , parts , N , periodic ); // printParticle( parts , 515150 ); // printParticle( parts , 494849 ); - - tic = getticks(); - write_output("output.hdf5", dim, parts, N, periodic); - printf( "main: writing particle properties took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout); /* Dump the kernel to make sure its ok. */ // kernel_dump( 100 ); @@ -822,7 +818,7 @@ int main ( int argc , char *argv[] ) { tic = getticks(); space_init( &s , dim , parts , N , periodic , h_max ); printf( "main: space_init took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout); - + /* Set the default time step to 1.0f. */ printf( "main: dt_max is %f.\n" , dt_max ); @@ -850,6 +846,11 @@ int main ( int argc , char *argv[] ) { tic = getticks(); engine_init( &e , &s , dt_max , nr_threads , nr_queues , engine_policy_steal | engine_policy_keep ); printf( "main: engine_init took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout); + + /* Write the state of the system as it is before starting time integration. */ + tic = getticks(); + write_output("output.hdf5", &e); + printf( "main: writing particle properties took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout); /* Init the runner history. */ #ifdef HIST @@ -873,7 +874,7 @@ int main ( int argc , char *argv[] ) { if(j % 100 == 0) { char fileName[200]; sprintf(fileName, "output_%05i.hdf5", j); - write_output(fileName, dim, parts, N, periodic); + write_output(fileName, &e); } /* Dump the first few particles. */ diff --git a/src/io.c b/src/io.c index a6d3914411fb0db369f3ba545bc460cf02d58e44..7a1c3a5f3a722a70a03f835c1d741f29b18f9cb9 100644 --- a/src/io.c +++ b/src/io.c @@ -36,6 +36,7 @@ #include "task.h" #include "part.h" #include "space.h" +#include "engine.h" /** * @brief Error macro @@ -545,10 +546,16 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, enu * Calls #error() if an error occurs. * */ -void write_output ( char* fileName, double dim[3], struct part *parts, int N, int periodic) +void write_output ( char* fileName, struct engine *e) { + hid_t h_file=0, h_grp=0; + int N = e->s->nr_parts; + int periodic = e->s->periodic; int numParticles[6]={N,0}; + int numParticlesHighWord[6]={0}; + int numFiles = 1; + struct part* parts = e->s->parts; FILE* xmfFile; writeXMFheader(&xmfFile, fileName, N); @@ -584,9 +591,16 @@ void write_output ( char* fileName, double dim[3], struct part *parts, int N, i error("Error while creating file header\n"); /* Read the relevant information and print status */ - writeAttribute(h_grp, "BoxSize", DOUBLE, &dim[0], 1); - writeAttribute(h_grp, "NumPart_Total", UINT, numParticles, 6); + writeAttribute(h_grp, "BoxSize", DOUBLE, e->s->dim, 1); + writeAttribute(h_grp, "NumPart_ThisFile", UINT, numParticles, 6); + writeAttribute(h_grp, "Time", DOUBLE, &e->time, 1); + /* GADGET-2 legacy values */ + writeAttribute(h_grp, "NumPart_Total", UINT, numParticles, 6); + writeAttribute(h_grp, "NumPart_Total_HighWord", UINT, numParticlesHighWord, 6); + writeAttribute(h_grp, "Flag_Entropy_ICs", UINT, numParticlesHighWord, 6); + writeAttribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1); + /* Close header */ H5Gclose(h_grp); diff --git a/src/io.h b/src/io.h index 88608e29b5f91d52d1d7d6f3fa057c87877eef87..a99d7684de8d4c3b4a322a7b46fec97a5f51bd17 100644 --- a/src/io.h +++ b/src/io.h @@ -22,6 +22,6 @@ void read_ic ( char* fileName, double dim[3], struct part **parts, int* N, int* periodic); -void write_output ( char* fileName, double dim[3], struct part *parts, int N, int periodic); +void write_output ( char* fileName, struct engine* e);