#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "bft_error.h"
#include "bft_mem.h"
#include "bft_printf.h"
#include "cs_base.h"
#include "cs_defs.h"
#include "cs_file.h"
#include "cs_file_csv_parser.h"
#include "cs_time_table.h"
Functions | |
static cs_time_table_t * | _time_table_by_name_try (const char *name) |
Print information concerning a time table, for debugging. More... | |
static int | _time_table_column_id_by_name (const cs_time_table_t *table, const char *name) |
Get column id corresponding to a given header/label. More... | |
static cs_time_table_t * | _time_table_create (const char *name) |
Allocate a new time table pointer and returns it. More... | |
static void | _free_time_table (cs_time_table_t *t) |
Free a given time table. More... | |
static cs_real_t | _time_table_compute_value (cs_time_table_t *table, const int col_id) |
Compute value for column using the current defined time. More... | |
cs_time_table_t * | cs_time_table_by_name_try (const char *name) |
Try to get time table based on name. More... | |
cs_time_table_t * | cs_time_table_by_name (const char *name) |
Get time table based on name. More... | |
void | cs_time_table_set_offset (cs_time_table_t *table, cs_real_t time_offset) |
Set time offset value for a time table. More... | |
void | cs_time_table_set_headers (cs_time_table_t *table, const int n_headers, const char **headers) |
Set headers labels for a time table. Number of headers needs to be equal to the number of columns, otherwise an error is raised. More... | |
cs_time_table_t * | cs_time_table_from_csv_file (const char *name, const char *file_name, const char *separator, const int n_headers, const int n_columns, const int *col_idx, const bool ignore_missing_tokens) |
Define a time table from a CSV file. More... | |
cs_time_table_t * | cs_time_table_from_csv_file_simple (const char *name, const char *file_name, const char *separator) |
Define a time table from a CSV file. We suppose that all columns are to be read, no headers line to skip and that missing tokens are to be ignored. More... | |
cs_time_table_t * | cs_time_table_from_csv_file_simple_headers (const char *name, const char *file_name, const char *separator, const int n_headers) |
Define a time table from a CSV file. We suppose that all columns are to be read and that missing tokens are to be ignored. More... | |
void | cs_time_table_set_time_col_id (cs_time_table_t *table, const int col_id) |
Define the column id for time based on an index. More... | |
void | cs_time_table_set_time_from_label (cs_time_table_t *table, const char *time_label) |
Define the column id for time based on a label. More... | |
void | cs_time_table_reset_position (cs_time_table_t *table) |
Reset time table time value (force search from beginning of table). More... | |
void | cs_time_table_update_position (cs_time_table_t *table, cs_real_t time, bool reset_time_value) |
Update time coefficients used for data interpolation. More... | |
cs_real_t | cs_time_table_compute_time_value (const char *name, cs_real_t t, const int col, bool overwrite_prev) |
Compute value using a given abscissa and a specific column. More... | |
cs_real_t | cs_time_table_compute_time_value_by_label (const char *name, cs_real_t t, const char *label, bool overwrite_prev) |
Compute value using a given abscissa and a label. More... | |
void | cs_time_table_compute_n_time_values (const char *name, cs_real_t t, const int n_cols, const int cols[], bool overwrite_prev, cs_real_t *retvals) |
Compute values for several columns of a time table for a given abscissa. More... | |
void | cs_time_table_compute_n_time_values_by_label (const char *name, cs_real_t t, const int n_cols, const char *labels[], bool overwrite_prev, cs_real_t *retvals) |
Compute values for several columns of a time table for a given abscissa. More... | |
void | cs_time_table_destroy_all (void) |
Free all data structures related to datasets. More... | |
Variables | |
static int | _n_time_tables = 0 |
static cs_time_table_t ** | _time_tables = NULL |
|
static |
Free a given time table.
[in] | t | pointer to time table which is to be freed. |
|
static |
Print information concerning a time table, for debugging.
[in] | t | pointer to time table |
Get time table by name (internal function)
[in] | name | name of the time table |
|
static |
Get column id corresponding to a given header/label.
[in] | table | pointer to time table |
[in] | name | name of the header/column |
|
inlinestatic |
Compute value for column using the current defined time.
[in] | table | Pointer to time table structure |
[in] | col_id | Column id for which to compute time value |
|
static |
Allocate a new time table pointer and returns it.
[in] | name | name of the new time table |
cs_time_table_t* cs_time_table_by_name | ( | const char * | name | ) |
Get time table based on name.
[in] | name | Name of time table |
cs_time_table_t* cs_time_table_by_name_try | ( | const char * | name | ) |
Try to get time table based on name.
[in] | name | Name of time table |
void cs_time_table_compute_n_time_values | ( | const char * | name, |
cs_real_t | t, | ||
const int | n_cols, | ||
const int | cols[], | ||
bool | overwrite_prev, | ||
cs_real_t * | retvals | ||
) |
Compute values for several columns of a time table for a given abscissa.
[in] | name | Name of the time table to use |
[in] | t | Time for which we seek values |
[in] | n_cols | Number of values to compute |
[in] | cols | Array with the indices of columns for computation |
[in] | overwrite_prev | Start search of value using first value |
[out] | retvals | Array of output values |
void cs_time_table_compute_n_time_values_by_label | ( | const char * | name, |
cs_real_t | t, | ||
const int | n_cols, | ||
const char * | labels[], | ||
bool | overwrite_prev, | ||
cs_real_t * | retvals | ||
) |
Compute values for several columns of a time table for a given abscissa.
[in] | name | Name of the time table to use |
[in] | t | Time for which we seek values |
[in] | n_cols | Number of values to compute |
[in] | labels | Array with the labels of columns for computation |
[in] | overwrite_prev | Start search of value using first value |
[out] | retvals | Array of output values |
cs_real_t cs_time_table_compute_time_value | ( | const char * | name, |
cs_real_t | t, | ||
const int | col, | ||
bool | overwrite_prev | ||
) |
Compute value using a given abscissa and a specific column.
[in] | name | Name of the used time table |
[in] | t | Time for which we seek values |
[in] | col | Index of column used for computation |
[in] | overwrite_prev | Start search of value using first value |
cs_real_t cs_time_table_compute_time_value_by_label | ( | const char * | name, |
cs_real_t | t, | ||
const char * | label, | ||
bool | overwrite_prev | ||
) |
Compute value using a given abscissa and a label.
[in] | name | Name of the used time table |
[in] | t | Time for which we seek values |
[in] | label | Label of column used for computation |
[in] | overwrite_prev | Start search of value using first value |
void cs_time_table_destroy_all | ( | void | ) |
Free all data structures related to datasets.
cs_time_table_t* cs_time_table_from_csv_file | ( | const char * | name, |
const char * | file_name, | ||
const char * | separator, | ||
const int | n_headers, | ||
const int | n_columns, | ||
const int * | col_idx, | ||
const bool | ignore_missing_tokens | ||
) |
Define a time table from a CSV file.
[in] | name | Name of the table to be created |
[in] | file_name | Path to CSV file |
[in] | separator | Separator used in the CSV file |
[in] | n_headers | Number of header lines to be ignored during parsing |
[in] | n_columns | Number of columns to read. -1 for all |
[in] | col_idx | Array containing indexes of columns to read if n_columns != -1 |
[in] | ignore_missing_tokens | Should we ignore missing tokens |
cs_time_table_t* cs_time_table_from_csv_file_simple | ( | const char * | name, |
const char * | file_name, | ||
const char * | separator | ||
) |
Define a time table from a CSV file. We suppose that all columns are to be read, no headers line to skip and that missing tokens are to be ignored.
[in] | name | Name of the table to be created |
[in] | file_name | Path to CSV file |
[in] | separator | Separator used in the CSV file |
cs_time_table_t* cs_time_table_from_csv_file_simple_headers | ( | const char * | name, |
const char * | file_name, | ||
const char * | separator, | ||
const int | n_headers | ||
) |
Define a time table from a CSV file. We suppose that all columns are to be read and that missing tokens are to be ignored.
[in] | name | Name of the table to be created |
[in] | file_name | Path to CSV file |
[in] | separator | Separator used in the CSV file |
[in] | n_headers | Number of header lines to be ignored during parsing |
void cs_time_table_reset_position | ( | cs_time_table_t * | table | ) |
Reset time table time value (force search from beginning of table).
[in] | table | Pointer to time table structure |
void cs_time_table_set_headers | ( | cs_time_table_t * | table, |
const int | n_headers, | ||
const char ** | headers | ||
) |
Set headers labels for a time table. Number of headers needs to be equal to the number of columns, otherwise an error is raised.
[in] | table | Pointer to time table structure |
[in] | n_headers | Number of headers to define |
[in] | headers | Array of headers strings |
void cs_time_table_set_offset | ( | cs_time_table_t * | table, |
cs_real_t | time_offset | ||
) |
Set time offset value for a time table.
[in] | table | Pointer to time table structure |
[in] | time_offset | Value of time offset for the table. |
void cs_time_table_set_time_col_id | ( | cs_time_table_t * | table, |
const int | col_id | ||
) |
Define the column id for time based on an index.
[in] | table | Pointer to time table structure |
[in] | col_id | Index of column which is to be used as time |
void cs_time_table_set_time_from_label | ( | cs_time_table_t * | table, |
const char * | time_label | ||
) |
Define the column id for time based on a label.
[in] | table | Pointer to time table structure |
[in] | time_label | Label to identify index of column which is to be used as time |
void cs_time_table_update_position | ( | cs_time_table_t * | table, |
cs_real_t | time, | ||
bool | reset_time_value | ||
) |
Update time coefficients used for data interpolation.
[in] | table | Pointer to time table structure |
[in] | time | Time value |
[in] | reset_time_value | Reset current time value (bool) |
|
static |
|
static |