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

Add option W to specify size ond position of the window

parent 76d50b4d
......@@ -6,33 +6,14 @@
using namespace std;
void init_term(FILE *pipef, char const *title, char const* verbatim){
fprintf(pipef, "set term qt 1 noraise\n"); //Keep focus on the calling terminal
fprintf(pipef, "set term qt font \"arial\"\n"); //Keep focus on the calling terminal
fprintf(pipef, "set datafile nofpe_trap\n"); //Speend up acquisition but crash if there is a problem with the DATA
fprintf(pipef, "set title '%s'\n", title); //axis x en y only
fprintf(pipef, "set border 3\n"); //axis x en y only
fprintf(pipef, "set title font ',20'\n");
fprintf(pipef, "set label font ',10'\n");
fprintf(pipef, "set key font ',10'\n");
fprintf(pipef, "set terminal qt noenhanced\n");//avoid interpretation of '_'
fprintf(pipef, "set style %s\n", style_option);
fprintf(pipef, "set boxwidth 0.9 relative\n");
fprintf(pipef, "set grid\n");
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(FILE *pipef, deque <blc_channel>&inputs, int refresh_period, float ymin, float ymax, float xmin, float xmax, float label_max){
blc_channel *input=nullptr;
char const *gnuplot_format=NULL;
char command[LINE_MAX];
int i, offset=0, columns_nb=0, rows_nb=0;
FILE *pipef;
size_t element_size;
int ret;
SYSTEM_ERROR_CHECK(pipef=popen("gnuplot", "w"), nullptr, "Calling gnuplot");
input=&inputs.front();
switch (input->dims_nb){
......@@ -64,7 +45,6 @@ void create_graph(deque <blc_channel>&inputs, const char *title, int refresh_per
case 'FL64':gnuplot_format="%float64";break;
default: EXIT_ON_ARRAY_ERROR(input, "The type is not managed");
}
init_term(pipef, title, verbatim);
if (ymin!=ymax) fprintf(pipef, "set yrange [%f:%f]\n", ymin, ymax);
if (columns_nb==1) xmin=-1;
......
......@@ -15,9 +15,7 @@
extern char const *with_option, *style_option, *surface_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(FILE *pipef, std::deque <blc_channel> &inputs, int history_length, int refresh_period, int sampling_period, float min, float max);
void create_graph(FILE *pipef, std::deque <blc_channel> &inputs, int refresh_period, float min, float max, float xmin, float xmax, float label_max);
#endif /* history_graph_h */
......@@ -9,7 +9,6 @@ using namespace std;
typedef struct history:blc_array{
blc_channel *input;
void init_timer();
int wait_next_k();
template <typename D_t> void start_refresh();
......@@ -108,7 +107,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(FILE *pipef, deque <blc_channel> &inputs, int history_length, int refresh_period, int sampling_period, float min, float max){
blc_channel *input=nullptr;
char const *gnuplot_format=NULL;
......@@ -118,7 +117,6 @@ void create_history_graph(deque <blc_channel> &inputs, char const *title, int hi
char code;
int i, columns_nb=0;
FILE *pipef;
pthread_t thread;
if (inputs.size()>1) EXIT_ON_ERROR("Only one channel is managed for history plots");
......@@ -136,7 +134,6 @@ void create_history_graph(deque <blc_channel> &inputs, char const *title, int hi
break;
}
SYSTEM_ERROR_CHECK(pipef=popen("gnuplot", "w"), NULL, "Calling gnuplot");
switch (input->type){
case 'UIN8':
......@@ -173,13 +170,11 @@ void create_history_graph(deque <blc_channel> &inputs, char const *title, int hi
break;
default: EXIT_ON_ARRAY_ERROR(input, "The type is not managed");
}
init_term(pipef, title, verbatim);
fprintf(pipef, "set xlabel 'time(s)'\n");
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);
......
......@@ -29,8 +29,27 @@ void refresh_period_cb(char *argument, void*){
sampling_period=strtol(argument, NULL, 10)*1000;
}
FILE *init_term(char const *title, char const* verbatim){
FILE *pipef;
SYSTEM_ERROR_CHECK(pipef=popen("gnuplot", "w"), NULL, "Calling gnuplot");
fprintf(pipef, "set term qt 1 noraise\n"); //Keep focus on the calling terminal
fprintf(pipef, "set term qt font \"arial\"\n");
fprintf(pipef, "set datafile nofpe_trap\n"); //Speed up acquisition but crash if there is a problem with the DATA
fprintf(pipef, "set title '%s'\n", title); //axis x en y only
fprintf(pipef, "set border 3\n"); //axis x en y only
fprintf(pipef, "set title font ',20'\n");
fprintf(pipef, "set label font ',10'\n");
fprintf(pipef, "set key font ',10'\n");
fprintf(pipef, "set terminal qt noenhanced\n");//avoid interpretation of '_'
fprintf(pipef, "set style %s\n", style_option);
fprintf(pipef, "set boxwidth 0.9 relative\n");
fprintf(pipef, "set grid\n");
if (verbatim) fprintf(pipef, "%s\n", verbatim);
return pipef;
}
int main(int argc, char *argv[]){
char const *refresh_string, *ymin_str, *ymax_str, *history_str, *sample_string, *verbatim;
char const *refresh_string, *ymin_str, *ymax_str, *history_str, *sample_string, *verbatim, *window_string;
char **channel_names;
char const *xmin_str, *xmax_str, *label_max_str;
float xmin, xmax, lmax;
......@@ -51,10 +70,12 @@ int main(int argc, char *argv[]){
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);
blc_program_add_option(&history_str, 'H', "history", "UI32", "size of the history", NULL);
blc_program_add_option(&refresh_string, 'P', "period", "UI32", "graph refresh period in ms", "100");
blc_program_add_option(&window_string, 'W', "window", "string", "window posistion and size: 'px,py,sx,sy'", nullptr);
blc_program_add_multiple_parameters(&channel_names, "blc_channel", -1, "channel you want to graph");
blc_program_init(&argc, &argv, blc_quit);
blc_command_forward_blc_channels();
for (char *const*channel_name_pt = channel_names; *channel_name_pt!=nullptr; channel_name_pt++){
inputs.emplace_back();
......@@ -112,8 +133,17 @@ int main(int argc, char *argv[]){
blc_command_add("p", refresh_period_cb, "ms", "sampling period", NULL);
if (history_str) create_history_graph(inputs, (char const*)inputs[0].name+1, strtol(history_str, NULL, 10), sampling_period, strtol(sample_string, NULL, 10)*1000, ymin, ymax, verbatim);
else create_graph(inputs, inputs[0].name+1, sampling_period, ymin, ymax, xmin, xmax, lmax, verbatim);
FILE *pipef = init_term(inputs[0].name+1, verbatim);
if (window_string){
int px,py, sx, sy;
SSCANF(4, window_string, "%d,%d,%d,%d", &px, &py, &sx, &sy);
fprintf(pipef, "set term qt 1 position %d,%d size %d,%d\n", px, py, sx, sy);
}
if (history_str) create_history_graph(pipef, inputs, strtol(history_str, NULL, 10), sampling_period, strtol(sample_string, NULL, 10)*1000, ymin, ymax);
else create_graph(pipef, inputs, sampling_period, ymin, ymax, xmin, xmax, lmax);
return (status);
}
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