#!/usr/bin/perl
#Use as:
#plot_reconstructed.pl Art_threshold-010.0_reconstructed_v2.txt > <new filename>.jgr
#then you can plot with j and jp

for($arg_index = 0; $arg_index <= $#ARGV; $arg_index++) {
    if ($ARGV[$arg_index] eq "-b" || $ARGV[$arg_index] eq "--base") {
	$base_tag = $ARGV[$arg_index+1];
	$arg_index++;
    }
    elsif ($ARGV[$arg_index] eq "-t" || $ARGV[$arg_index] eq "--tag") {
	$tag_hash{$ARGV[$arg_index+1]} = $ARGV[$arg_index+1];
	$arg_index++;
    }
    else {
	push(@filelist, $ARGV[$arg_index]);
# HER FILE ISMI @filelist te
    }
}

foreach $pathname (@filelist) {
    open(INFILE, $pathname) or 
	die("Could not open file '$pathname'\n");

    @dirstruct = split(/\//, $pathname);
    $filename = $dirstruct[$#dirstruct];
    ($benchmark, $part2, $part3) = split(/\_/, $filename);
    @part2split = split(/\-/, $part2);
    $threshold = $part2split[1];
    printf("(* Benchmark: %s *)\n", $benchmark);
    printf("(* Threshold: %s *)\n", $threshold);

    printf("newgraph\n");
    printf("xaxis 
                  size 5 \n");
    printf("label : TIME\n");
    printf("yaxis 
                  size 4\n");
    printf("label : Power [W]\n");

    printf("newcurve marktype none linetype solid");
    
    $Reached_Actual_Data = 0;

    while ($line = <INFILE>) {
	@fields = split(/\t+/, $line);
        #split to tabs

	if ($fields[0] =~ /TIME/) {
	    $label_model = $fields[2];
            $label_rec   = $fields[25];
            printf(" label : %s\n", $label_model);
            printf("pts\n");
            $Reached_Actual_Data = 1;
	}
        elsif ($Reached_Actual_Data == 1){
          printf("%7.2f %10.5f\n", $fields[0], $fields[2]);
        }
#        printf("%s %s %s", $fields[0], $fields[2], $fields[25]);
    }

    close(INFILE);
    open(INFILE, $pathname) or 
	die("Could not open file '$pathname'\n");

    printf("copycurve color 0.4 0.2 0.8");
    
    $Reached_Actual_Data = 0;

    while ($line = <INFILE>) {
	@fields = split(/\t+/, $line);
        #split to tabs

	if ($fields[0] =~ /TIME/) {
            printf(" label : %s\n", $label_rec);
            printf("pts\n");
            $Reached_Actual_Data = 1;
	}
        elsif ($Reached_Actual_Data == 1){
          printf("%7.2f %10.5f\n", $fields[0], $fields[25]);
        }
    }

    close(INFILE);
}


