<job>

<script language="VBScript">
</script>

<script language="JScript">
// SPEC result file parser
// Version 0.9
// November 8, 2005
// by Chad Roesle (chad_roesle@dell.com)
//
// DESCRIPTION:
// Takes any number of result files and parses data values for Excel table.
// Assumes the test names are the same for multiple results in a single file, so only lists the first set of names found.
//
// USAGE:
// Drag-and-drop any number of valid result files onto the script to parse only those files.
// Alternately, simply double-click on the script to parse all valid files in the current dir.
// A log file by the name below will be left in the script's dir with the info.
// The log file is Excel friendly and can be cut-and-pasted directly.
// Multiple runs will be appended to the end of the log file.


// USER VARIABLES
var sLogFile = "log.xls"; // Name for output log file

// GLOBAL VARIABLES
var fso = new ActiveXObject("Scripting.FileSystemObject"); // Create the file system object

main(); // call the main routine
WScript.Quit();

function main()
{ // Main execution routine
  var nScriptStartTime = new Date(); // Save script start time
  var aMain = new Array(); // main array of column arrays with names and results

  // START DOING REAL WORK
  f = fso.GetFolder(fso.GetParentFolderName(WScript.ScriptFullName)); // Get the folder for the script file
  sLogFile = f.Path + "\\" + sLogFile; // Add full path to log filename, so it is always in script dir

  // Check if file(s) were drag-and-dropped onto the script.  If so, process only those.  Otherwise, process all in dir.
  if (WScript.Arguments.length > 0)
  { // Use dropped files
    for (var i = 0; i < WScript.Arguments.length; i++)
    { // Get an enumeration of dropped filenames
      ParseFile(WScript.Arguments(i), aMain); // Parse the file
    }
  }
  else
  { // No dropped files - process all in the dir
    for (fc = new Enumerator(f.files); !fc.atEnd(); fc.moveNext())
    { // Cycle through all files in dir parsing only text files (.txt)
      var s = fc.item().Name;
      if ((s.substr(s.length-4) == ".txt") || (s.substr(s.length-4) == ".csv"))
      {
        ParseFile(s, aMain); // Parse the file
      }
    }
  }


/*
  // Output arrays in row/column form as saved in memory
  for (i = 0; i < aMain.length; i++)
  {
	sLine = "";
	var aTemp = aMain[i];
	for (j = 0; j < aTemp.length; j++)
	{
//		WriteLog(sLogFile, i + " " + j + "\t" + aTemp[j]);
		sLine = sLine + "\t" + aTemp[j];
	}
	WriteLog(sLogFile, sLine + "\n");
//	WriteLog(sLogFile, "\n");
  }
*/

  // Output arrays in format ready for Excel table to file
  if (aMain.length != 0)
  {
	nSize = 100000000000; // Start with arbitrarily large number - will be reset later based on actual array size
	for (k = 0; k < nSize; k++) // Go to each column array
	{
		sLine = "";
		for (i = 0; i < aMain.length; i++) // Get current row data value from current column
		{
			// Save current column array to temp array for reading
			var aTemp = aMain[i];
			nSize = aTemp.length; // Reset k loop end value based on actual number of rows in column

			sLine = sLine + aTemp[k] + "\t"; // Append column data values on a per row basis

			// Test names for each result record are saved but assumed to be the same; show names in first column and skip the rest
			if (i > 0) i++; // NOTE: comment out this line if row data is not lining up correctly to see row labels for each set of data
		}
		WriteLog(sLogFile, sLine); // Write the current row
	}
  }

  // Output script total parse time
  var nScriptEndTime = new Date();
  WriteLog(sLogFile, "Total Parse Time = " + (Date.UTC(nScriptEndTime.getYear(),nScriptEndTime.getMonth(),nScriptEndTime.getDay(),nScriptEndTime.getHours(),nScriptEndTime.getMinutes(),nScriptEndTime.getSeconds(),nScriptEndTime.getMilliseconds()) - Date.UTC(nScriptStartTime.getYear(),nScriptStartTime.getMonth(),nScriptStartTime.getDay(),nScriptStartTime.getHours(),nScriptStartTime.getMinutes(),nScriptStartTime.getSeconds(),nScriptStartTime.getMilliseconds())) + " ms");

} // END: main()


function ParseFile(sFilename, aMain)
{ // Opens the specified file

  var nFileStartTime = new Date(); // Save start time of parsing this file
  oFile = fso.OpenTextFile(sFilename,1); // Open the file

  // init arrays
  var aName = new Array();
  var aResult = new Array();

  while (!oFile.AtEndOfStream)
  { // Go through the remainder of the file line by line

	sLine = oFile.ReadLine(); // Next line

	if (sLine.substr(0,15) == "Benchmark: Part")
	{ // save part name
		var nPos = sLine.search("- part ");
		aName.push(sLine.substr(nPos+7)); // save part name
		aResult.push(sFilename); // save file name as column header
	}
	else if (sLine.substr(0,6) == "TIME- ")
	{ // save result name and time to arrays
		var sTemp = sLine.substr(6).split(" ");
		aName.push(trim(sTemp[0])); // Save test name
		if (sTemp[1] != "") // Find non-blank element to save as test result/time
			aResult.push(trim(sTemp[1]));
		else if (sTemp[2] != "")
			aResult.push(trim(sTemp[2]));
		else if (sTemp[3] != "")
			aResult.push(trim(sTemp[3]));
		else if (sTemp[4] != "")
			aResult.push(trim(sTemp[4]));
	}
  }

  //Save final result if results were found
  if (typeof(aName) != "undefined")
  {
	aMain.push(aName);
	aMain.push(aResult);
  }

  oFile.Close(); // Close the file

} // END: ParseFile()


function WriteLog(file, text)
{ // Writes the specified text to the end of the specified file
  fLog = fso.OpenTextFile(file,8,true); // Append to the existing log file
  fLog.WriteLine(text); // Write the specified text to the temp log file
  fLog.Close();
}

function trim(str)
{ // Removes any starting or ending white spaces (including tabs) from a string
  while (str.charAt(0) == " " || str.charAt(0) == "\t") str = str.substr(1);
  while (str.charAt(str.length-1) == " ") str = str.substr(0,str.length-1);
  return(str);
} // END: trim()


</script>
</job>