Commit f42193dce8122169308fe60de36a1edd4ea9135c

Authored by Arnaud Blanchard
1 parent 74604ffc

Fix read tab value. Still only 2d array can be read

Showing 1 changed file with 19 additions and 14 deletions
//Read only array of dim 1
#include "blc_core.h"
#include "blc_channel.h"
#include "blc_program.h"
... ... @@ -18,6 +20,7 @@ static int file_get_lines_number(FILE* file){
return lines_nb;
}
static void array_def_with_tsv_file_first_line(blc_array *array, char const *filename, char const *time_str){
char const *ext;
FILE *file;
... ... @@ -29,12 +32,16 @@ static void array_def_with_tsv_file_first_line(blc_array *array, char const *fil
if (strcmp(ext, "tsv")!=0) EXIT_ON_ERROR("'%s' does not .tsv extension but '%s'", filename, ext);
SYSTEM_ERROR_CHECK(file=fopen(filename, "r"), NULL, "opening '%s'", filename);
SYSTEM_ERROR_CHECK(getline(&line, &linecap, file), -1, "Reading '%s'", filename);
pos=line;
length=0;
while(pos){
pos=strchr(pos+1, '\t');
if (pos) length++;
if (pos){
pos++;//next position;
if (pos[0]=='\t') EXIT_ON_ERROR("The array in file '%s' seems of dims 3 or more. Two tabs.", line);
if (pos[0]=='\n') EXIT_ON_ERROR("The array in file '%s' seems ill formed. 'tab' followed by return.", line);
}
length++;
}
if (time_str) length--; //The first coulmn dos not count it is the time.
... ... @@ -44,20 +51,18 @@ static void array_def_with_tsv_file_first_line(blc_array *array, char const *fil
}
int main(int argc, char** argv){
char const *period_str, *text;
char const *period_str;
char const *channel_name, *filename, *time_str;
char const *number_str;
char *default_output;
int number, ret;
uint64_t executing_time, previous_executing_time;
size_t linecap=0;
ssize_t line_size;
blc_channel channel;
FILE *file;
int period;
asprintf(&default_output, "/%s%d", basename(argv[0]), getpid()); //This will not be free but it is only allocate once
blc_program_set_description("Update channel with a tsv file");
blc_program_set_description("Update channel with a tsv file. Only array of dim 1 !");
blc_program_add_option(&number_str, 'n', "number", "integer", "Number of records (-1 for infinity)", "-1");
blc_program_add_option(&channel_name, 'o', "output_channel", "string", "Name of the channel to output the data", default_output);
blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to read line by line (default 0 i.e. as fast as possible)", NULL);
... ... @@ -65,12 +70,12 @@ int main(int argc, char** argv){
blc_program_add_parameter(&filename, "filename", 1, "File to load", NULL);
blc_program_init(&argc, &argv, blc_quit);
blc_command_forward_blc_channels();
if (period_str){
if (time_str) EXIT_ON_ERROR("You can either use fix period or first column time but not both: period '%s' and time (-t) activated", period_str);
period=strtod(period_str, NULL)*1000;
} else period=0;
number=strtod(number_str, NULL);
number=strtol(number_str, NULL, 10);
array_def_with_tsv_file_first_line(&channel, filename, time_str);
channel.create_or_open(channel_name, BLC_CHANNEL_WRITE);
... ... @@ -90,12 +95,12 @@ int main(int argc, char** argv){
else{
fscan_tsv_floats(file, channel.floats, channel.dims[0].length);
if (time_str) {
ret=fscanf(file, "%llu\t", &executing_time);
if (ret==0 && feof(file)){
if (number==-1) blc_command_ask_quit();
else EXIT_ON_ERROR("End of file and you request '%d' iterations. Only '%d' has been done.", number, blc_loop_iteration);
}
blc_command_loop_period=executing_time-previous_executing_time; //We request the BLC_COMMAND_LOOP to last the time during two records. This overwrite period effect
ret=fscanf(file, "%llu\t", &executing_time);
if (ret==0 && feof(file)){
if (number==-1) blc_command_ask_quit();
else EXIT_ON_ERROR("End of file and you request '%d' iterations. Only '%d' has been done.", number, blc_loop_iteration);
}
blc_command_loop_period=executing_time-previous_executing_time; //We request the BLC_COMMAND_LOOP to last the time during two records. This overwrite period effect
previous_executing_time=executing_time;
}
}
... ...