Skip to content
Snippets Groups Projects
Commit fb4c01cf authored by lhausamm's avatar lhausamm Committed by Loic Hausammann
Browse files

update file header

parent 5f0906a3
No related branches found
No related tags found
1 merge request!502Logger
...@@ -257,6 +257,26 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset, ...@@ -257,6 +257,26 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset,
*offset = offset_new; *offset = offset_new;
} }
void logger_ensure_size(size_t total_nr_parts, size_t logger_size) {
size_t limit, i;
struct logger_const log_const;
logger_const_init(&log_const);
limit = log_const.offset + log_const.mask;
for(i=0; i < log_const.nber_mask; i++) {
limit += log_const.masks_size[i];
}
limit *= total_nr_parts;
if (logger_size < limit) error("Need a larger logger size");
logger_const_free(&log_const);
}
/** /**
* @brief Write a file header to a logger file * @brief Write a file header to a logger file
* *
...@@ -265,6 +285,8 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset, ...@@ -265,6 +285,8 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset,
* *
*/ */
void logger_write_file_header(struct dump *dump) { void logger_write_file_header(struct dump *dump) {
message("writing header");
size_t i, j; size_t i, j;
char *buff, *name_buff, *skip_header; char *buff, *name_buff, *skip_header;
size_t *file_offset; size_t *file_offset;
...@@ -310,16 +332,21 @@ void logger_write_file_header(struct dump *dump) { ...@@ -310,16 +332,21 @@ void logger_write_file_header(struct dump *dump) {
/* last step */ /* last step */
memcpy(skip_header, file_offset, log_const.offset); memcpy(skip_header, file_offset, log_const.offset);
logger_const_free(&log_const);
} }
void logger_const_init(struct logger_const* log_const) { void logger_const_init(struct logger_const* log_const) {
log_const->name = 10; log_const->name = 20 * sizeof(char);
log_const->offset = 7; log_const->offset = 7;
log_const->mask = 1; log_const->mask = 1;
log_const->nber_mask = 8; log_const->nber_mask = 8;
char *cur_name;
char tmp[log_const->name];
size_t block_size;
// masks value // masks value
log_const->masks = malloc(sizeof(size_t)*log_const->nber_mask); log_const->masks = malloc(sizeof(size_t)*log_const->nber_mask);
log_const->masks[0] = logger_mask_x; log_const->masks[0] = logger_mask_x;
...@@ -332,44 +359,61 @@ void logger_const_init(struct logger_const* log_const) { ...@@ -332,44 +359,61 @@ void logger_const_init(struct logger_const* log_const) {
log_const->masks[7] = logger_mask_timestamp; log_const->masks[7] = logger_mask_timestamp;
// masks name // masks name
size_t name_size = sizeof(char) * log_const->name; block_size = log_const->name * log_const->nber_mask;
log_const->masks_name = malloc(name_size*log_const->nber_mask); log_const->masks_name = malloc(block_size);
char *tmp = malloc(sizeof(char) * log_const->name); cur_name = log_const->masks_name;
tmp = "position"; strcpy(tmp, "position");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "velocity"; strcpy(tmp, "velocity");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "acceleration"; strcpy(tmp, "acceleration");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "entropy"; strcpy(tmp, "entropy");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "cutoff radius"; strcpy(tmp, "cutoff radius");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "density"; strcpy(tmp, "density");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "consts"; strcpy(tmp, "consts");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
tmp = "timestamp"; strcpy(tmp, "timestamp");
memcpy(log_const->masks_name, &tmp, log_const->name); memcpy(cur_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char); cur_name += log_const->name;
log_const->masks_size = malloc(sizeof(size_t) * log_const->nber_mask);
log_const->masks_size[0] = 3 * sizeof(double);
log_const->masks_size[1] = 3 * sizeof(float);
log_const->masks_size[2] = 3 * sizeof(float);
log_const->masks_size[3] = sizeof(float);
log_const->masks_size[4] = sizeof(float);
log_const->masks_size[5] = sizeof(float);
log_const->masks_size[6] = sizeof(float) + sizeof(long long);
log_const->masks_size[7] = 8;
// todo masks_type
} }
void logger_const_free(struct logger_const* log_const) {
free(log_const->masks);
free(log_const->masks_name);
free(log_const->masks_size);
}
/** /**
* @brief Read a logger message and store the data in a #part. * @brief Read a logger message and store the data in a #part.
......
...@@ -90,12 +90,14 @@ struct dump; ...@@ -90,12 +90,14 @@ struct dump;
#define LOGGER_NBER_SIZE 1 // size of the number of elements #define LOGGER_NBER_SIZE 1 // size of the number of elements
struct logger_const { struct logger_const {
size_t name; size_t name; // labels size
size_t offset; size_t offset; // offset size
size_t mask; size_t mask; // mask size
size_t nber_mask; size_t nber_mask; // number of different masks
size_t *masks; size_t *masks; // value of each masks (e.g. logger_mask_...)
char *masks_name; size_t *masks_size; // size of each mask
char *masks_name; // label of each mask
char *masks_type; // type of data (e.g. 'CHAR', 'INT', 'FLOAT')
}; };
...@@ -113,7 +115,8 @@ int logger_read_timestamp(unsigned long long int *t, size_t *offset, ...@@ -113,7 +115,8 @@ int logger_read_timestamp(unsigned long long int *t, size_t *offset,
const char *buff); const char *buff);
void logger_write_file_header(struct dump *dump); void logger_write_file_header(struct dump *dump);
void logger_const_init(struct logger_const* log_const); void logger_const_init(struct logger_const* log_const);
void logger_const_free(struct logger_const* log_const);
void logger_ensure_size(size_t total_nr_parts, size_t logger_size);
/** /**
* @brief Should this particle write its data now ? * @brief Should this particle write its data now ?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment