#!/usr/bin/perl 

use File::Find;

$prog="gnuplot";

#chdir("/home/johnny/dd/data");

open(PROG, "|$prog");

print PROG "set terminal png color\n";
print PROG "set lmargin 7\n";
print PROG "set bmargin 5\n";
print PROG "set label 1 \"Seconds\" at screen .5, screen .02 norotate\n";
print PROG "set label 2 \"cwd_\" at screen .01, screen .5 rotate\n"; 

#opendir(DIR, "/home/johnny/dd/data");
#while (defined($file = readdir(DIR))) {
 
sub genGraph { 
  $File::Find::name =~ /^(.*)\/(.*)$/;
  $path = $1;
  $file = $2; 
      
  if($file =~ /^\.\.?$/) { return };
  if( !($file =~ /\.txt$/)) { return };
  if($file =~ /^SKIP/) { return };
    
  $image = $file;
  $image =~ s/\.txt/.png/;
  $file2 = "SKIP" . $file;
    
  my($ps, $t1, $vs, $t2, $ext) = split(/\./, $file);
  
  $p1 = $path . "/" . $image;
  print PROG "set output \"$p1\"\n";
  $p1 = $path . "/" . $file;
  $p2 = $path . "/" . $file2;
  $t1 = $t1 . "($ps)";
  $t2 = $t2 . "($ps)";
  print PROG "plot \"$p1\" title \"$t1\" , \"$p2\" title \"$t2\" \n";
}

find(\&genGraph, ("/home/johnny/dd/data"));
close(PROG);
