Add perl scripts to create graphs from logfiles Ignore logfiles.
[soft/lpc82x/exanh] / test / graph.pl
1 #!/usr/bin/perl -w
3 use strict;
4 use warnings;
6 # Author : Nathael Pajani
7 # Copyright 2016 Nathael Pajani <nathael.pajani@techno-innov.fr>
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 # How to use this script/programm
24 # FIXME : TODO.
26 use GD::Graph::bars;
29 my $debug = 1; # 0: no debug
31 my $file = $ARGV[0];
32 if (! -e $file) {
33         print "Need file name as first argument\n";
34         exit 1;
35 }
37 my $count = 0;
38 my @stime;
39 my @stempdata;
40 my @scapdata;
41 my @sresdata;
43 open(LOGFILE, "<", $file);
44 foreach my $line (<LOGFILE>) {
45         chomp($line); # remove the newline from $line.
46         my $w = "(.+?)";
47         if ($line =~ m/Temp read: $w - raw/) {
48                 push(@stime, $count);
49                 push(@stempdata, $1);
50                 # Increment counter
51                 $count++;
52         } elsif ($line =~ m/ADC9: $w, ADC10: $w/) {
53                 push(@scapdata, $1);
54                 push(@sresdata, $2);
55         }
56 }
59 print "Got ".$#stime." values\n";
61 # Temperature
62 my $tempgraph = GD::Graph::bars->new(($#stime*2), 800);
63 $tempgraph->set( 
64              x_label => 'time',
65              y_label => 'temp',
66              title   => 'Temp sensor vs time',
67              transparent => 0
68 ) or warn $tempgraph->error;
69 my @tempdata = (\@stime, \@stempdata);
70 my $temp_gd = $tempgraph->plot(\@tempdata) or die $tempgraph->error();
71 # Save graph
72 open(IMG, '>filetemp.png') or die $!;
73 binmode IMG;
74 print IMG $temp_gd->png;
75 close(IMG);
77 # Capacitance
78 my $capgraph = GD::Graph::bars->new(($#stime*2), 800);
79 $capgraph->set( 
80              x_label => 'time',
81              y_label => 'cap',
82              title   => 'Temp sensor vs time',
83              transparent => 0
84 ) or warn $capgraph->error;
85 my @capdata = (\@stime, \@scapdata);
86 my $cap_gd = $capgraph->plot(\@capdata) or die $capgraph->error();
87 # Save graph
88 open(IMG, '>filecap.png') or die $!;
89 binmode IMG;
90 print IMG $cap_gd->png;
91 close(IMG);
93 # Resistivity
94 my $resgraph = GD::Graph::bars->new(($#stime*2), 800);
95 $resgraph->set( 
96              x_label => 'time',
97              y_label => 'res',
98              title   => 'Temp sensor vs time',
99              transparent => 0
100 ) or warn $resgraph->error;
101 my @resdata = (\@stime, \@sresdata);
102 my $res_gd = $resgraph->plot(\@resdata) or die $resgraph->error();
103 # Save graph
104 open(IMG, '>fileres.png') or die $!;
105 binmode IMG;
106 print IMG $res_gd->png;
107 close(IMG);