Commit 5f0906a3 authored by lhausamm's avatar lhausamm Committed by Loic Hausammann
Browse files

Write file header and change params file (bytes->MB)

parent 58533d22
......@@ -91,8 +91,8 @@ Snapshots:
output_list_on: 0 # (Optional) Enable the output list
output_list: snaplist.txt # (Optional) File containing the output times (see documentation in "Parameter File" section)
logger_max_steps: 10 # (Optional) Number of particle steps between two chunk writing if using logger
logger_size: 1e7 # buffer size of the logger file in bytes
logger_size: 10. # buffer size of the logger file in MB
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-2 # Time between statistics output
......
......@@ -56,6 +56,7 @@ void *dump_get(struct dump *d, size_t count, size_t *offset) {
return (char *)d->data + local_offset;
}
/**
* @brief Ensure that at least size bytes are available in the #dump.
*/
......
......@@ -6701,11 +6701,17 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params,
/* Logger params */
char logger_name_file[PARSER_MAX_LINE_SIZE];
e->logger_max_steps = parser_get_opt_param_int(params, "Snapshots:logger_max_steps", 10);
e->logger_size = parser_get_param_float(params, "Snapshots:logger_size");
e->logger_size = parser_get_param_float(params, "Snapshots:logger_size") * 1e6;
/* generate dump filename */
strcpy(logger_name_file, e->snapshotBaseName);
strcat(logger_name_file, ".dump");
/* init dump */
e->logger_dump = malloc(sizeof(struct dump));
dump_init(e->logger_dump, logger_name_file, e->logger_size);
struct dump *dump_file = e->logger_dump;
dump_init(dump_file, logger_name_file, e->logger_size);
logger_write_file_header(dump_file);
e->logger_time_offset = 0;
#endif
......
......@@ -257,6 +257,120 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset,
*offset = offset_new;
}
/**
* @brief Write a file header to a logger file
*
* @param offset Pointer to the offset of the previous log of this particle.
* @param dump The #dump in which to log the particle data.
*
*/
void logger_write_file_header(struct dump *dump) {
size_t i, j;
char *buff, *name_buff, *skip_header;
size_t *file_offset;
size_t mask_size;
struct logger_const log_const;
logger_const_init(&log_const);
file_offset = &dump->file_offset;
if (*file_offset != 0) error("Something was already written in the dump file");
/* Write version information */
buff = dump_get(dump, LOGGER_VERSION_SIZE, file_offset);
memcpy(buff, LOGGER_VERSION, LOGGER_VERSION_SIZE);
/* write number of bytes used for the offsets */
buff = dump_get(dump, LOGGER_OFFSET_SIZE, file_offset);
memcpy(buff, &log_const.offset, LOGGER_OFFSET_SIZE);
/* will write the offset of the first particle here */
skip_header = dump_get(dump, log_const.name, file_offset);
/* write number of bytes used for names */
buff = dump_get(dump, LOGGER_NAME_SIZE, file_offset);
memcpy(buff, &log_const.name, LOGGER_NAME_SIZE);
mask_size = log_const.nber_mask * (log_const.name + log_const.mask);
name_buff = dump_get(dump, mask_size, file_offset);
for(i=0; i<log_const.nber_mask; i++) {
j = i * (log_const.name + log_const.mask);
// name
memcpy(name_buff, &log_const.masks_name[j], log_const.name);
name_buff += j;
// mask
memcpy(name_buff, &log_const.masks[i], log_const.mask);
name_buff += log_const.mask;
}
/* last step */
memcpy(skip_header, file_offset, log_const.offset);
}
void logger_const_init(struct logger_const* log_const) {
log_const->name = 10;
log_const->offset = 7;
log_const->mask = 1;
log_const->nber_mask = 8;
// masks value
log_const->masks = malloc(sizeof(size_t)*log_const->nber_mask);
log_const->masks[0] = logger_mask_x;
log_const->masks[1] = logger_mask_v;
log_const->masks[2] = logger_mask_a;
log_const->masks[3] = logger_mask_u;
log_const->masks[4] = logger_mask_h;
log_const->masks[5] = logger_mask_rho;
log_const->masks[6] = logger_mask_consts;
log_const->masks[7] = logger_mask_timestamp;
// masks name
size_t name_size = sizeof(char) * log_const->name;
log_const->masks_name = malloc(name_size*log_const->nber_mask);
char *tmp = malloc(sizeof(char) * log_const->name);
tmp = "position";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "velocity";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "acceleration";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "entropy";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "cutoff radius";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "density";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "consts";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
tmp = "timestamp";
memcpy(log_const->masks_name, &tmp, log_const->name);
log_const->masks_name += log_const->name * sizeof(char);
}
/**
* @brief Read a logger message and store the data in a #part.
*
......
......@@ -29,6 +29,7 @@
/* Forward declaration */
struct dump;
#define LOGGER_VERSION "0.1"
/**
* Logger entries contain messages representing the particle data at a given
......@@ -78,6 +79,26 @@ struct dump;
#define logger_mask_consts 64
#define logger_mask_timestamp 128
/* header constants
* Thoses are definitions from the format and therefore should not be changed!
* Size in bytes
*/
#define LOGGER_VERSION_SIZE 20 // size of the version message
#define LOGGER_OFFSET_SIZE 1// size of the offset size information
#define LOGGER_NAME_SIZE 2 // size of the labels
#define LOGGER_MASK_SIZE 1 // size of the masks
#define LOGGER_NBER_SIZE 1 // size of the number of elements
struct logger_const {
size_t name;
size_t offset;
size_t mask;
size_t nber_mask;
size_t *masks;
char *masks_name;
};
/* Function prototypes. */
int logger_size(unsigned int mask);
void logger_log_part(struct part *p, unsigned int mask, size_t *offset,
......@@ -90,7 +111,8 @@ int logger_read_part(struct part *p, size_t *offset, const char *buff);
int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff);
int logger_read_timestamp(unsigned long long int *t, size_t *offset,
const char *buff);
void logger_write_file_header(struct dump *dump);
void logger_const_init(struct logger_const* log_const);
/**
......
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