Commit 0cf66ac0 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger: update index and add major/minor verions into header

parent 126b5f06
......@@ -47,7 +47,7 @@ include_HEADERS = logger_header.h logger_io.h logger_particle.h logger_time.h lo
# Common source files
AM_SOURCES = logger_header.c logger_io.c logger_particle.c logger_time.c logger_tools.c logger_reader.c \
logger_logfile.c
logger_index.c logger_logfile.c
if HAVEPYTHON
AM_SOURCES += logger_python_wrapper.c
endif
......
......@@ -116,15 +116,13 @@ void header_read(struct header *h, struct logger_logfile *log) {
error("Wrong file format");
/* Read major version number */
int major;
offset = io_read_data(map, sizeof(int), &major, offset);
offset = io_read_data(map, sizeof(int), &h->major_version, offset);
/* Read minor version number */
int minor;
offset = io_read_data(map, sizeof(int), &minor, offset);
offset = io_read_data(map, sizeof(int), &h->minor_version, offset);
if (h->log->reader->verbose > 0)
message("File version %i.%i", major, minor);
message("File version %i.%i", h->major_version, h->minor_version);
/* read the offset directions */
offset = io_read_data(map, LOGGER_NUMBER_SIZE, &h->offset_direction, offset);
......
......@@ -60,6 +60,12 @@ struct header {
/* Logger version. */
char version[STRING_SIZE];
/* Dump major version */
int major_version;
/* Dump minor version */
int minor_version;
/* Offset of the first record. */
size_t offset_first_record;
......
......@@ -39,12 +39,14 @@ void logger_index_init(struct logger_index *index, struct logger_reader *reader,
char *basename) {
/* Set pointers to 0. */
index->offsets = NULL;
index->ids = NULL;
index->data = NULL;
/* Set variables default value. */
index->current_file = -1;
index->number_of_particles = 0;
index->total_number_particles = 0;
for(int i = 0; i < swift_type_count; i++) {
index->number_particles[i] = 0;
}
}
/**
......@@ -57,12 +59,11 @@ void logger_index_read_file(struct logger_index *index, int i) {
/* Cleanup the memory of previous file. */
logger_index_free_current_file(index);
/* Save current index. */
index->current_file = i;
/* Open file. */
FILE *f = NULL;
f = fopen(index->filenames[i], "wb");
char name[200];
sprintf(name, "%s_%04i.index", index->basename, i);
f = fopen(name, "rb");
/* Read the double time. */
double time;
......@@ -73,32 +74,23 @@ void logger_index_read_file(struct logger_index *index, int i) {
fread(&int_time, sizeof(integertime_t), 1, f);
/* Read the number of particles. */
long long N_total[swift_type_count];
fread(N_total, sizeof(long long), swift_type_count, f);
fread(index->number_particles, sizeof(long long), swift_type_count, f);
/* Count total number of particles. */
long long N = 0;
for(int i = 0; i < swift_type_count; i++) {
N += N_total[i];
for(int j = 0; j < swift_type_count; j++) {
N += index->number_particles[j];
}
index->number_of_particles = N;
index->total_number_particles = N;
/* Read the particles ids. */
if (posix_memalign((void**)&index->ids, IO_BUFFER_ALIGNMENT,
N * sizeof(long long)) != 0)
error("Unable to allocate the offset buffer");
fread(index->ids, sizeof(size_t), N, f);
/* Read the particles offsets. */
if (posix_memalign((void**)&index->offsets, IO_BUFFER_ALIGNMENT,
N * sizeof(size_t)) != 0)
error("Unable to allocate the offset buffer");
fread(index->offset, sizeof(size_t), N, f);
if (posix_memalign((void**)&index->data, IO_BUFFER_ALIGNMENT,
N * sizeof(struct logger_index_data)) != 0)
error("Unable to allocate index data buffer");
fread(index->data, sizeof(struct logger_index_data), N, f);
/* Close the file. */
fclose(f);
......@@ -110,19 +102,17 @@ void logger_index_read_file(struct logger_index *index, int i) {
* @param index The #logger_index.
*/
void logger_index_free_current_file(struct logger_index *index) {
/* Free the particles offsets. */
if (index->offsets)
free(index->offsets);
index->offsets = NULL;
/* Free the particles ids. */
if (index->ids)
free(index->ids);
index->ids = NULL;
/* Free the index data */
if (index->data)
free(index->data);
index->data = NULL;
/* Set variables to default value. */
index->current_file = -1;
index->number_of_particles = 0;
index->total_number_particles = 0;
for(int i = 0; i < swift_type_count; i++) {
index->number_particles[i] = 0;
}
}
/**
......@@ -132,21 +122,6 @@ void logger_index_free_current_file(struct logger_index *index) {
*/
void logger_index_free(struct logger_index *index) {
/* Set variables to default value. */
index->current_file = -1;
index->number_of_particles = 0;
/* Free the memory allocated for current file. */
logger_index_free_file_data(index);
/* Free the filenames. */
for(int i = 0; i < index->number_files; i++) {
if (index->filenames[i])
free(index->filenames[i]);
index->filenames[i] = NULL;
}
/* Free the array of filenames. */
free(index->filenames);
index->filenames = NULL;
logger_index_free_current_file(index);
}
......@@ -17,6 +17,8 @@
*
******************************************************************************/
#include "logger_tools.h"
/**
* @file logger_index.h
* @brief This file deals with the index files.
......@@ -26,6 +28,15 @@
struct logger_reader;
struct logger_index_data {
/* The particle's id */
long long id;
/* The particle's offset */
size_t offset;
};
/**
* @brief This structure will contain the data related to
* the index file.
......@@ -47,19 +58,16 @@ struct logger_index {
int number_files;
/* List of all the index filenames */
char **filenames;
/* Index of current file */
int current_file;
char *basename;
/* Offsets of the particles in current file */
size_t *offsets;
/* ids of the particles in current file */
long long *ids;
/* Particles' ids and offsets */
struct logger_index_data *data;
/* Number of particles */
size_t number_of_particles;
size_t total_number_particles;
/* Number of particles per type */
long long number_particles[swift_type_count];
};
void logger_index_init(struct logger_index *index, struct logger_reader *reader,
......
......@@ -28,6 +28,7 @@
#include "../src/dimension.h"
#include "../src/inline.h"
#include "../src/logger.h"
#include "../src/part_type.h"
#ifdef HAVE_PYTHON
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
......
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