Commit 992cb2af authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger: add time in logger_index and logger_reader

parent 0cf66ac0
......@@ -29,49 +29,24 @@
#include "logger_tools.h"
/**
* @brief Initialize the #logger_index.
* @brief Initialize the #logger_index by reading the index file.
*
* @param index The #logger_index.
* @param reader The #logger_reader.
* @param basename The basename of the index files.
* @param filename The filename.
*/
void logger_index_init(struct logger_index *index, struct logger_reader *reader,
char *basename) {
/* Set pointers to 0. */
index->data = NULL;
/* Set variables default value. */
index->total_number_particles = 0;
for(int i = 0; i < swift_type_count; i++) {
index->number_particles[i] = 0;
}
}
/**
* @brief Read a single index file.
*
* @param index The #logger_index.
* @param i The index of the file.
*/
void logger_index_read_file(struct logger_index *index, int i) {
/* Cleanup the memory of previous file. */
logger_index_free_current_file(index);
char *filename) {
/* Open file. */
FILE *f = NULL;
char name[200];
sprintf(name, "%s_%04i.index", index->basename, i);
f = fopen(name, "rb");
f = fopen(filename, "rb");
/* Read the double time. */
double time;
fread(&time, sizeof(double), 1, f);
fread(&index->time, sizeof(double), 1, f);
/* Read the integer time. */
double int_time;
fread(&int_time, sizeof(integertime_t), 1, f);
fread(&index->int_time, sizeof(integertime_t), 1, f);
/* Read the number of particles. */
fread(index->number_particles, sizeof(long long), swift_type_count, f);
......
......@@ -38,28 +38,16 @@ struct logger_index_data {
};
/**
* @brief This structure will contain the data related to
* the index file.
* @brief This structure contains the data related to
* an index file.
*
* It is initialized with #logger_index_init and freed with
* #logger_index_free.
*
* The files are read with #logger_index_read_file and
* can be freed with #logger_index_free_current_file.
*/
struct logger_index {
/* The reader */
struct logger_reader *reader;
/* List of the time for each file */
double *times;
/* Number of files */
int number_files;
/* List of all the index filenames */
char *basename;
/* Particles' ids and offsets */
struct logger_index_data *data;
......@@ -68,14 +56,18 @@ struct logger_index {
/* Number of particles per type */
long long number_particles[swift_type_count];
/* Time of the index file */
double time;
/* Integer time of the index file */
integertime_t int_time;
};
void logger_index_init(struct logger_index *index, struct logger_reader *reader,
char *basename);
void logger_index_read_file(struct logger_index *index, int i);
char *filename);
void logger_index_free(struct logger_index *index);
void logger_index_free_current_file(struct logger_index *index);
#endif // __LOGGER_LOGGER_INDEX_H__
......@@ -55,6 +55,9 @@
*/
struct logger_reader {
/* Time of each index file #TODO */
double *times;
/* Information contained in the index file */
struct logger_index index;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment