Commit f653f041 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

format

parent 4f43c44f
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
#include "io.h" #include "io.h"
#include "logger_tools.h" #include "logger_tools.h"
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
/** /**
* @brief print a header struct * @brief print a header struct
...@@ -32,7 +32,6 @@ void header_print(const struct header *h) { ...@@ -32,7 +32,6 @@ void header_print(const struct header *h) {
} }
/* mask contains... TODO */ /* mask contains... TODO */
}; };
/** /**
...@@ -88,8 +87,7 @@ int header_change_offset_direction(struct header *h, void *map) { ...@@ -88,8 +87,7 @@ int header_change_offset_direction(struct header *h, void *map) {
h->forward_offset = !h->forward_offset; h->forward_offset = !h->forward_offset;
size_t offset = LOGGER_VERSION_SIZE; size_t offset = LOGGER_VERSION_SIZE;
return io_write_data(map, LOGGER_NBER_SIZE, &h->forward_offset, return io_write_data(map, LOGGER_NBER_SIZE, &h->forward_offset, &offset);
&offset);
} }
/** /**
...@@ -109,7 +107,8 @@ int header_read(struct header *h, void *map) { ...@@ -109,7 +107,8 @@ int header_read(struct header *h, void *map) {
io_read_data(map, LOGGER_NBER_SIZE, &h->forward_offset, &offset); io_read_data(map, LOGGER_NBER_SIZE, &h->forward_offset, &offset);
if (h->forward_offset != 0 && h->forward_offset != 1) if (h->forward_offset != 0 && h->forward_offset != 1)
error(EIO, "Non boolean value for the offset direction (%i)", h->forward_offset); error(EIO, "Non boolean value for the offset direction (%i)",
h->forward_offset);
/* read offset to first data */ /* read offset to first data */
h->offset_first = 0; h->offset_first = 0;
...@@ -152,7 +151,7 @@ int header_read(struct header *h, void *map) { ...@@ -152,7 +151,7 @@ int header_read(struct header *h, void *map) {
header_print(h); header_print(h);
#endif #endif
error(EIO, "Wrong header size (in header %li, current %li)", error(EIO, "Wrong header size (in header %li, current %li)",
h->offset_first, offset); h->offset_first, offset);
} }
return 0; return 0;
......
...@@ -20,7 +20,7 @@ struct header { ...@@ -20,7 +20,7 @@ struct header {
/* Number of bytes for names */ /* Number of bytes for names */
size_t name; size_t name;
/* number of masks */ /* number of masks */
size_t nber_mask; size_t nber_mask;
......
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "io.h"
#include "header.h" #include "header.h"
#include "io.h"
#include "logger_tools.h" #include "logger_tools.h"
/** /**
......
...@@ -149,7 +149,7 @@ static PyObject *loadFromIndex(__attribute__((unused)) PyObject *self, ...@@ -149,7 +149,7 @@ static PyObject *loadFromIndex(__attribute__((unused)) PyObject *self,
/* Reset header */ /* Reset header */
header_free(&h); header_free(&h);
if (header_read(&h, map) != 0) return NULL; if (header_read(&h, map) != 0) return NULL;
} }
......
...@@ -127,7 +127,8 @@ int tools_reverse_offset(const struct header *h, void *map, size_t *offset) { ...@@ -127,7 +127,8 @@ int tools_reverse_offset(const struct header *h, void *map, size_t *offset) {
/* modify previous offset */ /* modify previous offset */
size_t abs_prev_offset = cur_offset - prev_offset + LOGGER_MASK_SIZE; size_t abs_prev_offset = cur_offset - prev_offset + LOGGER_MASK_SIZE;
error_code = io_write_data(map, LOGGER_OFFSET_SIZE, &prev_offset, &abs_prev_offset); error_code =
io_write_data(map, LOGGER_OFFSET_SIZE, &prev_offset, &abs_prev_offset);
if (error_code != 0) error(errno, "Unable to write offset"); if (error_code != 0) error(errno, "Unable to write offset");
#ifdef SWIFT_DEBUG_CHECKS #ifdef SWIFT_DEBUG_CHECKS
...@@ -192,7 +193,8 @@ int tools_check_offset(const struct header *h, void *map, size_t *offset) { ...@@ -192,7 +193,8 @@ int tools_check_offset(const struct header *h, void *map, size_t *offset) {
if (pointed_mask != mask) if (pointed_mask != mask)
error(EIO, "Error in the offset (mask %lu != %lu) at %lu and %lu", mask, error(EIO, "Error in the offset (mask %lu != %lu) at %lu and %lu", mask,
pointed_mask, pointed_mask,
*offset - header_get_mask_size(h, mask) - LOGGER_MASK_SIZE - LOGGER_OFFSET_SIZE, *offset - header_get_mask_size(h, mask) - LOGGER_MASK_SIZE -
LOGGER_OFFSET_SIZE,
pointed_offset - LOGGER_MASK_SIZE - LOGGER_OFFSET_SIZE); pointed_offset - LOGGER_MASK_SIZE - LOGGER_OFFSET_SIZE);
if (pointed_mask == 128) return 0; if (pointed_mask == 128) return 0;
......
...@@ -42,14 +42,14 @@ struct header; ...@@ -42,14 +42,14 @@ struct header;
#define error(err, s, ...) \ #define error(err, s, ...) \
({ \ ({ \
error_no_return(err, s, ##__VA_ARGS__); \ error_no_return(err, s, ##__VA_ARGS__); \
exit(1); \ exit(1); \
}) })
#define error_no_return(err, s, ...) \ #define error_no_return(err, s, ...) \
({ \ ({ \
char error_msg[STRING_SIZE]; \ char error_msg[STRING_SIZE]; \
sprintf(error_msg, "%s:%s():%i: " s ": %s\n", __FILE__, __FUNCTION__, \ sprintf(error_msg, "%s:%s():%i: " s ": %s\n", __FILE__, __FUNCTION__, \
__LINE__, ##__VA_ARGS__, strerror(err)); \ __LINE__, ##__VA_ARGS__, strerror(err)); \
}) })
#endif #endif
......
#include "particle.h" #include "particle.h"
#include "header.h" #include "header.h"
#include "io.h" #include "io.h"
#include "timeline.h"
#include "logger_tools.h" #include "logger_tools.h"
#include "timeline.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
/** /**
* @brief print a particle * @brief print a particle
...@@ -156,7 +156,8 @@ int particle_read(struct particle *part, const struct header *h, void *map, ...@@ -156,7 +156,8 @@ int particle_read(struct particle *part, const struct header *h, void *map,
if (h_offset == 0) return 0; if (h_offset == 0) return 0;
/* get absolute offset of next particle */ /* get absolute offset of next particle */
h_offset += *offset - header_get_mask_size(h, mask) - LOGGER_MASK_SIZE - LOGGER_OFFSET_SIZE; h_offset += *offset - header_get_mask_size(h, mask) - LOGGER_MASK_SIZE -
LOGGER_OFFSET_SIZE;
part_next.time = time_array_get_time(times, h_offset); part_next.time = time_array_get_time(times, h_offset);
...@@ -182,8 +183,7 @@ int particle_read(struct particle *part, const struct header *h, void *map, ...@@ -182,8 +183,7 @@ int particle_read(struct particle *part, const struct header *h, void *map,
* @return error code * @return error code
*/ */
int particle_interpolate(struct particle *part_curr, int particle_interpolate(struct particle *part_curr,
const struct particle *part_next, const struct particle *part_next, const double time) {
const double time) {
if (!part_curr) error(EFAULT, "part_curr is NULL"); if (!part_curr) error(EFAULT, "part_curr is NULL");
if (!part_next) error(EFAULT, "part_next is NULL"); if (!part_next) error(EFAULT, "part_next is NULL");
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#define __PARTICLE_H__ #define __PARTICLE_H__
#include "header.h" #include "header.h"
#include "timeline.h"
#include "logger_tools.h" #include "logger_tools.h"
#include "timeline.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -57,7 +57,6 @@ int particle_read_field(struct particle *part, void *map, size_t *offset, ...@@ -57,7 +57,6 @@ int particle_read_field(struct particle *part, void *map, size_t *offset,
const char *field, const size_t size); const char *field, const size_t size);
int particle_interpolate(struct particle *part_curr, int particle_interpolate(struct particle *part_curr,
const struct particle *part_next, const struct particle *part_next, const double time);
const double time);
#endif //__PARTICLE_H__ #endif //__PARTICLE_H__
...@@ -21,8 +21,7 @@ double time_convert_to_double(const integertime_t ti, const double timeBase) { ...@@ -21,8 +21,7 @@ double time_convert_to_double(const integertime_t ti, const double timeBase) {
* *
* @return converted time * @return converted time
*/ */
integertime_t time_convert_to_integer(const double ti, integertime_t time_convert_to_integer(const double ti, const double timeBase) {
const double timeBase) {
return ti / timeBase; // should add timebegin return ti / timeBase; // should add timebegin
} }
...@@ -35,8 +34,8 @@ integertime_t time_convert_to_integer(const double ti, ...@@ -35,8 +34,8 @@ integertime_t time_convert_to_integer(const double ti,
* @param map file mapping * @param map file mapping
* @param offset In: position in the file, Out: shifted by the timestamp * @param offset In: position in the file, Out: shifted by the timestamp
*/ */
int time_read(integertime_t *timestamp, double *time, const struct header *h, void *map, int time_read(integertime_t *timestamp, double *time, const struct header *h,
size_t *offset) { void *map, size_t *offset) {
int error_code = 0; int error_code = 0;
size_t mask = 0; size_t mask = 0;
size_t prev_offset = 0; size_t prev_offset = 0;
...@@ -60,7 +59,8 @@ int time_read(integertime_t *timestamp, double *time, const struct header *h, vo ...@@ -60,7 +59,8 @@ int time_read(integertime_t *timestamp, double *time, const struct header *h, vo
/* read data */ /* read data */
// TODO // TODO
error_code = io_read_data(map, sizeof(unsigned long long int), timestamp, offset); error_code =
io_read_data(map, sizeof(unsigned long long int), timestamp, offset);
error_code = io_read_data(map, sizeof(double), time, offset); error_code = io_read_data(map, sizeof(double), time, offset);
return error_code; return error_code;
...@@ -160,7 +160,8 @@ int time_array_init(struct time_array *t, const struct header *h, void *map, ...@@ -160,7 +160,8 @@ int time_array_init(struct time_array *t, const struct header *h, void *map,
* *
* @return integer time of the chunk * @return integer time of the chunk
*/ */
integertime_t time_array_get_integertime(struct time_array *t, const size_t offset) { integertime_t time_array_get_integertime(struct time_array *t,
const size_t offset) {
const struct time_array *tmp = time_array_get_time_array(t, offset); const struct time_array *tmp = time_array_get_time_array(t, offset);
return tmp->timestamp; return tmp->timestamp;
} }
...@@ -235,7 +236,8 @@ void time_array_print(const struct time_array *t) { ...@@ -235,7 +236,8 @@ void time_array_print(const struct time_array *t) {
while (t->next) { while (t->next) {
i += 1; i += 1;
t = t->next; t = t->next;
if (i < threshold || i > up_threshold) printf(", %lli (%g)", t->timestamp, t->time); if (i < threshold || i > up_threshold)
printf(", %lli (%g)", t->timestamp, t->time);
if (i == threshold) printf(", ..."); if (i == threshold) printf(", ...");
} }
......
...@@ -26,11 +26,12 @@ struct time_array { ...@@ -26,11 +26,12 @@ struct time_array {
double time_convert_to_double(const integertime_t ti, const double timeBase); double time_convert_to_double(const integertime_t ti, const double timeBase);
integertime_t time_convert_to_integer(const double ti, const double timeBase); integertime_t time_convert_to_integer(const double ti, const double timeBase);
int time_read(integertime_t *timestamp, double *time, const struct header *h, void *map, int time_read(integertime_t *timestamp, double *time, const struct header *h,
size_t *offset); void *map, size_t *offset);
int time_array_init(struct time_array *t, const struct header *h, void *map, int time_array_init(struct time_array *t, const struct header *h, void *map,
int fd); int fd);
integertime_t time_array_get_integertime(struct time_array *t, const size_t offset); integertime_t time_array_get_integertime(struct time_array *t,
const size_t offset);
double time_array_get_time(struct time_array *t, const size_t offset); double time_array_get_time(struct time_array *t, const size_t offset);
struct time_array *time_array_get_time_array(struct time_array *t, struct time_array *time_array_get_time_array(struct time_array *t,
const size_t offset); const size_t offset);
......
Supports Markdown
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