#!/bin/awk -f
BEGIN {   
    filename="";
    run=1;   
    times[""]="";    
    version="";
    versionList[""]="";
    op="";
    tuple="";
    num_op=split("NaN noDelta noGamma",opList, " ");
	size="";
    num_size=split("1 3 10 300 1000",sizeList, " ");  
    machine[""]="";
    key="";
   
}
{
    if(filename != FILENAME){
		filename=FILENAME;
		n=split(filename,array,".");
		version=array[1];
		versionList[version]=version;
		op=array[2];
		size=substr(array[4],0,length(array[4])-1);
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," "); 
		key=version","op","size","run;		
		times[key]=array[3];
		#printf("%s %s\n",key,times[key]);
		run++;
    }else{	
	 	key="hardware";
		if(match($0, "Linux.*")){
		    machine["OS"]=substr($0,1,index($0,"#"));
		}
		if(match($0, "processor")){
		    split($0,array," ");
		    machine["processor"]=array[3];
		}    
		if(match($0, "model name")){
		    split($0,array,":");
		    machine["model"]=array[2];
		}

		if(match($0, "MemTotal:")){
		    split($0,array," ");
		    machine["memtotal"]=array[2];
		}

		if(match($0, "====.*")){
		    machine["header"]=$0
		}
    }  
   
}
END {     
    for(version in versionList){if(version != ""){
    	for(p=1; p<=num_op; p++){
    		op=opList[p];
    		if(match(op, "noDelta")){
    			tuple="PvWatts"
    	   	}else if(match(op, "noGamma")){
    	   		tuple="SumMonth"
    	   	}else if(match(op, "NaN")){
    	   		tuple="NaN"
    	   	} 
    		   	   				   	 
		   printf("Machine: %s with %d cores (%s) and %s memory\n",machine["OS"],int(machine["processor"])+1,machine["model"],machine["memtotal"]);
		   printf("Version:%s\tOptimisation:%s\tTuple:%s\t\n",version,op,tuple);
	 	   printf("\nFileSize:");
		   for(s=1;s<=num_size;s++){						   	  
			   printf("\t%s",sizeList[s]);
		   }
		   for(run=1;run<=30;run++){
				printf("\nRun%s",run);
				for(s=1;s<=num_size;s++){
						size=sizeList[s];
						key=version","op","size","run;
						#printf("%s\n",key);
						printf("\t%s",times[key]);
				}
		   }
		   printf("\nVersion:");
		   for(s=1;s<=num_size;s++){
		   	   printf("\t%s",version);
		   }
		   printf("\nOptimisation:");
		   for(s=1;s<=num_size;s++){
		   	   printf("\t%s",op);
		   }
		   printf("\nTuple:");
		   for(s=1;s<=num_size;s++){
		   	   printf("\t%s",tuple);
		   }					  					
		   printf("\nFile Size:");
		   for(s=1;s<=num_size;s++){						   	  
			   printf("\t%s",sizeList[s]);
		   }					   					   
		   printf("\nAverage6-30");
		   printf("\nMedian6-30");
		   printf("\nVariance6-30");
		   printf("\nSpeedup");
		   printf("\n");
				  
		}	  
		}
	} 
	
}
