o_gnuplot.cpp 3.87 KB
Newer Older
Arnaud Blanchard's avatar
Arnaud Blanchard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <sys/time.h>
#include "graph.h"

blc_channel input;
blc_array history_array;

char const *with_option, *style_option;

int sx, sy;
int sampling_period;
int interactive_mode=0;
int final_columns_nb, final_rows_nb;
int offset=0;
int bands=1;
int dims_nb, *lengths;
double min, max;
enum {RUN, PAUSE};
int status=RUN;

void refresh_period_cb(char const*argument, void*){
26
    sampling_period=strtol(argument, NULL, 10)*1000;
Arnaud Blanchard's avatar
Arnaud Blanchard committed
27
28
29
}

int main(int argc, char *argv[]){
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    char const *refresh_string, *min_str, *max_str, *history_str, *channel_name, *sample_string, *verbatim;
    char const *xmin_str, *xmax_str, *label_max_str;
    float xmin, xmax, lmax;
    int status=0;
    
    blc_program_set_description("Display the content of the blc_channel depending on its type and format");
    blc_program_add_option(&min_str, 'm', "min", "FL32", "minimal value", NULL);
    blc_program_add_option(&max_str, 'M', "max", "FL32", "maximal value", NULL);
    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(&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);
    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_parameter(&channel_name, "blc_channel", 1, "channel you want to graph", NULL);
    
    blc_program_init(&argc, &argv, blc_quit);
50
    blc_command_forward_blc_channels();
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    
    input.open(channel_name, BLC_CHANNEL_READ);
    if (min_str) min=strtof(min_str, NULL);
    else switch (input.type){
        case 'UIN8':case 'UI16':case 'UI32':case 'IN16':case 'IN32':case 'IN64':case 'FL32':case'FL64':min=0.0;break;
        case 'INT8':min=INT8_MIN;break;
        default: EXIT_ON_CHANNEL_ERROR(&input, "No default min value");
    }
    
    if (max_str) max=strtof(max_str, NULL);
    else switch (input.type){
        case 'UIN8':max=UINT8_MAX;break;
        case 'INT8':max=INT8_MAX;break;
        case 'FL32': case 'FL64':max=1.0;break;
        default: EXIT_ON_CHANNEL_ERROR(&input, "No default max value");
    }
    
68
    if (xmin_str) SSCANF(1, xmin_str, "%f", &xmin);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    else xmin=0;
    
    if (xmax_str) SSCANF(1, xmax_str, "%f", &xmax);
    else xmax=input.total_length;
    
    if (label_max_str) {
        SSCANF(1, label_max_str, "%f", &lmax);
        if (xmax_str==NULL) xmax=lmax; //We still want to see all the graph
    }
    else lmax=input.total_length;
    
    sampling_period=strtol(refresh_string, NULL, 10)*1000;
    
    fprintf(stderr, "=== %s: ", blc_program_name);
    if (history_str) fprintf(stderr, "sample period (%.3fms), history(%s), ",  sampling_period/1000.f, history_str);
    fprintf(stderr, "min(%.3lf), max(%.2lf) === \n", min, max);
    
    blc_command_add("p", refresh_period_cb,  "ms", "sampling period", NULL);
    
    if (history_str) create_history_graph(&input, input.name+1, strtol(history_str, NULL, 10), sampling_period, strtol(sample_string, NULL, 10)*1000, min, max, verbatim);
    else create_graph(&input, input.name+1, sampling_period, min, max, xmin, xmax, lmax, verbatim);
    
    return (status);
Arnaud Blanchard's avatar
Arnaud Blanchard committed
92
}