#!/usr/bin/perl # glucopilot2gnuplot # Author: Shankar Chakkere # Date: 12 Feb 1999 # Status: Working # Abstract: # This program will extract the information from the imported GlucoPilot text # for ploting in Gnuplot or any other spread sheet. # The Glucopilot export file is in reverse order, current ( last ) entry on top # of the file. The data has to be filtered because it is difficult to plot using # Gnuplot which needs just 2 colums of data. The program provides the switches to # filter according to the category ( Pre breakfast, Lunch, Dinner etc. ) with or # without from /to dates. # # History: # # 5 march 1999 # Add -c to filter file according to category # # 17 march 1999 # Add -f and -t to filter file according to `from date` to\or `to date` # # Note: Convert the GlucoPilot text to unix format before using on unix # machines ( reason CR/LF) # Copyright (C) 1999 Shankar Chakkere # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Visit http://www.fsf.org for more information ############################################################################## ($#ARGV < 0 ) && &usage; # $#ARGV -1 when no command line parameter # Clear all flags $cat = 0; $from = 0; $to = 0; # Extract switches while ($ARGV[0] =~ m/^-/) { $_= shift(@ARGV); s/^-//; while (s/^.//) { if ($& eq 'c') { $cat = 1; $pattern = $ARGV[0]; shift(@ARGV); } elsif ($& eq 'f') { $from = 1; $fromdate = $ARGV[0]; shift(@ARGV); } elsif ($& eq 't') { $to = 1; $todate = $ARGV[0]; shift(@ARGV); } else { &badusage("Unknown option \-$&\n"); } } } #while ($ARGV[0] =~ m/^-/) $file = $ARGV[0]; open(FILE, $file) || die "Can't open input file : $file"; $number = 0; # To count number of datas # Print the Title print "$0 extracted data "; print " Category: $pattern" if $cat; print " From: $fromdate" if $from; print " To: $todate" if $to; print "\n"; # Pass flag should be set to extract the data. $pass = 0; # Pass all if no flags $pass = 1 if (!$to && !$from && !$cat); # Pass from the start of the file till the 'from date' $pass = 1 if ($from && !$to); # pass all if just category $pass = 1 if ($cat && !$to && !$from) ; # Flag to indicate still in from date, this is needed to include all # data of `from date` $inequal = 0; while () { if(/^"/){ chop(); # no CR/LF chop(); # remove extra " at the end ($date,$time,$type,$category,$level,$remarks) = (split(/","/)); ($quote,$date)=split(/"/,$date); # Remove starting " # Filter `To date` # Note: `To date` comes first before `From date`. # because the list is in reverse order, current data first. if ($to && !$pass) # set pass flag if date is found { $pass = 1 if ($todate eq $date); } # Set stop flag (pass = 0) if ($from && $pass ) { # pass while in equality $inequal = 1 if ($fromdate eq $date); $pass = 0 if (($fromdate ne $date) && $inequal); } if ($cat) # if -c { &pushdata if(($pass) && ($pattern eq $category)); } else #if -t or -f { &pushdata if($pass); } } # if(/^"/) } # while ( # Print the data # NOTE:GlucoPilot will store the current data on the top of the list # and I don't know a way to tell Excel to reverse the table. for ($i=1 ; $i <=$number ; $i++) { print "$i $data2prn[$number - $i]"; } close FILE; sub usage { die <