#!/bin/awk -f
BEGIN {   
    filename="";
    run=1;   
    times[""]="";    
    version="";
    capacity="";
    phase="";
    versionList[""]="";
    gamma="";
    num_gamma=split("HashMap TreeSet",gammaList," ");
    delta="";
    num_delta=split("DeltaNodeInt DeltaNodeIntRange",deltaList," ");
    num_phase=split("0 1 2 3 10",phaseList, " ");  
    machine[""]="";
    key="";
   
}
{
    if(filename != FILENAME){
		filename=FILENAME;
		n=split(filename,array,".");
		version=array[1];
		versionList[version]=version;
		gamma=array[2];
		delta=array[3];		
		phase=substr(array[4],6,length(array[4])+1);
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," "); 
		key=version","gamma","delta","phase","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(g=1;g<=num_gamma;g++){
    		   	   for(d=1;d<=num_delta;d++){
    		   	   	   gamma=gammaList[g];
					   delta=deltaList[d];			   	 
					   printf("Machine: %s with %d cores (%s) and %s memory\n",machine["OS"],int(machine["processor"])+1,machine["model"],machine["memtotal"]);
					   printf("Version:%s\tGamma:%s\tDelta:%s\tFile:sorted1000X.csv\n",version,gamma,delta,phase);
				 	   printf("\nPhase:");
					   for(p=1;p<=num_phase;p++){						   	  
						   printf("\t%s",phaseList[p]);
					   }
					   for(run=1;run<=30;run++){
							printf("\nRun%s",run);
							for(p=1;p<=num_phase;p++){
									phase=phaseList[p];
									key=version","gamma","delta","phase","run;
									printf("\t%s",times[key]);
							}
					   }
					   printf("\nVersion:");
					   for(p=1;p<=num_phase;p++){
					   	   printf("\t%s",version);
					   }
					   printf("\nGamma:");
					   for(p=1;p<=num_phase;p++){
					   	   printf("\t%s",gamma);
					   }
					   printf("\nDelta:");
					   for(p=1;p<=num_phase;p++){
					   	   printf("\t%s",delta);
					   }					
					   printf("\nPhase:");
					   for(p=1;p<=num_phase;p++){						   	  
						   printf("\t%s",phaseList[p]);
					   }					   					   
					   printf("\nAverage6-30");
					   printf("\nMedian6-30");
					   printf("\nVariance6-30");
					   printf("\nDiff");
					   printf("\n");
				   }
			   }	  
		}
	} 
	
}
