Commit d8939afd authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Manage matrixes as vector or scaler. Fix double free

parent 1bd60ba5
......@@ -21,7 +21,7 @@ void init_term(FILE *pipef, char const *title, char const* verbatim){
if (verbatim) fprintf(pipef, "%s\n", verbatim);
}
void create_graph(deque <blc_channel>inputs, const char *title, int refresh_period, float ymin, float ymax, float xmin, float xmax, float label_max, char const *verbatim){
void create_graph(deque <blc_channel>&inputs, const char *title, int refresh_period, float ymin, float ymax, float xmin, float xmax, float label_max, char const *verbatim){
blc_channel *input=nullptr;
char const *gnuplot_format=NULL;
char command[LINE_MAX];
......@@ -73,7 +73,7 @@ void create_graph(deque <blc_channel>inputs, const char *title, int refresh_peri
if (columns_nb==1) xmin=-1;
if (xmin!=xmax) fprintf(pipef, "set xrange [%f:%f]\n", xmin, xmax);
if (input->dims_nb==2){
if (input->dims_nb==2 && input->dims[0].length>1 && input->dims[1].length>1){
fprintf(pipef, "set xrange [%f:%f]\n", 0.f, 10.f);
fprintf(pipef, "set yrange [%f:%f]\n", 0.f, 10.f);
fprintf(pipef, "set zrange [%f:%f]\n", ymin, ymax);
......@@ -81,10 +81,15 @@ void create_graph(deque <blc_channel>inputs, const char *title, int refresh_peri
offset=snprintf(command, LINE_MAX, "splot '-' binary format='%s' array=%dx%d title 'values' with pm3d ", gnuplot_format, columns_nb, rows_nb);
}
else{
offset=snprintf(command, LINE_MAX, "plot '-' binary format='%s' record=%d using ($0*%f):1 title '%s' with %s", gnuplot_format, columns_nb, label_max/(float)columns_nb, input->name+1, with_option);
if (with_option==nullptr){
if (inputs[0].total_length==1) with_option="boxes";
else with_option="lines";
}
offset=snprintf(command, LINE_MAX, "plot '-' binary format='%s' record=%zu using ($0*%f):1 title '%s' with %s", gnuplot_format, inputs[0].total_length, label_max/(float)inputs[0].total_length, input->name+1, with_option);
for(i=1; i<inputs.size();i++){
offset+=snprintf(command+offset, LINE_MAX-offset, ", '-' binary format='%s' record=%d using ($0*%f):1 title '%s' with %s", gnuplot_format, columns_nb, label_max/(float)columns_nb, inputs[i].name+1, with_option);
offset+=snprintf(command+offset, LINE_MAX-offset, ", '-' binary format='%s' record=%zu using ($0*%f):1 title '%s' with %s", gnuplot_format, inputs[i].total_length, label_max/(float)inputs[i].total_length, inputs[i].name+1, with_option);
}
/* for(i=1; i!=rows_nb; i++){
if (i<10) code=48+i;
......@@ -105,7 +110,7 @@ void create_graph(deque <blc_channel>inputs, const char *title, int refresh_peri
}
SYSTEM_SUCCESS_CHECK(fflush(pipef), 0, nullptr);
}
SYSTEM_ERROR_CHECK(ret=pclose(pipef), -1, NULL);
SYSTEM_ERROR_CHECK(ret=pclose(pipef), -1, nullptr);
if (ret!=0) EXIT_ON_ERROR("Gnuplot quititing with error code '%d'", ret);
}
......
......@@ -16,7 +16,7 @@
extern char const *with_option, *style_option;
void init_term(FILE *pipef, char const *title, char const* verbatim);
void create_history_graph(std::deque <blc_channel> inputs, char const *title, int history_length, int refresh_period, int sampling_period, float min, float max, char const *verbatim);
void create_graph(std::deque <blc_channel> inputs, char const*title, int refresh_period, float min, float max, float xmin, float xmax, float label_max, char const *verbatim);
void create_history_graph(std::deque <blc_channel> &inputs, char const *title, int history_length, int refresh_period, int sampling_period, float min, float max, char const *verbatim);
void create_graph(std::deque <blc_channel> &inputs, char const*title, int refresh_period, float min, float max, float xmin, float xmax, float label_max, char const *verbatim);
#endif /* history_graph_h */
......@@ -101,7 +101,7 @@ static void *refresh_history_cb(void *history_pt){
return NULL;
}
void create_history_graph(deque <blc_channel> inputs, char const *title, int history_length, int refresh_period, int sampling_period, float min, float max, char const *verbatim){
void create_history_graph(deque <blc_channel> &inputs, char const *title, int history_length, int refresh_period, int sampling_period, float min, float max, char const *verbatim){
blc_channel *input=nullptr;
char const *gnuplot_format=NULL;
......@@ -164,6 +164,8 @@ void create_history_graph(deque <blc_channel> inputs, char const *title, int his
init_term(pipef, title, verbatim);
fprintf(pipef, "set xlabel 'time(s)'\n");
if (with_option==nullptr) with_option="lines";
if (min!=max) fprintf(pipef, "set yrange [%f:%f]\n", min, max);
......
......@@ -44,7 +44,7 @@ int main(int argc, char *argv[]){
blc_program_add_option(&sample_string, 'p', "period", "UI32", "sampling period in ms or history", "10");
blc_program_add_option(&style_option, 's', "style", "string", "gnuplot option set option (style, boxwidth, ...)", "fill solid");
blc_program_add_option(&verbatim, 't', "text", "string", "text directly put on the gnuplot set commandline", NULL);
blc_program_add_option(&with_option, 'w', "with", "string", "gnuplot option with (lines, boxes, dots,...)", "lines");
blc_program_add_option(&with_option, 'w', "with", "string", "gnuplot option with (lines, boxes, dots,...)", nullptr);
blc_program_add_option(&xmin_str, 'x', "xmin", "FL32", "minimal abscissa value", NULL);
blc_program_add_option(&xmax_str, 'X', "xmax", "FL32", "maximal abscissa value", NULL);
blc_program_add_option(&label_max_str, 'L', "label-max", "FL32", "display the absisca scale in order to have the last value as label-max ", NULL);
......
Markdown is supported
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