Index: DCWoRMS/trunk/src/simulator/stats/implementation/DCWormsStatistics.java
===================================================================
--- DCWoRMS/trunk/src/simulator/stats/implementation/DCWormsStatistics.java	(revision 794)
+++ DCWoRMS/trunk/src/simulator/stats/implementation/DCWormsStatistics.java	(revision 821)
@@ -65,4 +65,5 @@
 import schedframe.resources.computing.profiles.energy.airthroughput.AirFlowValue;
 import schedframe.resources.computing.profiles.energy.power.PowerUsage;
+import schedframe.resources.computing.profiles.energy.thermal.TemperatureValue;
 import schedframe.resources.units.PEUnit;
 import schedframe.resources.units.ProcessingElements;
@@ -109,4 +110,5 @@
 	protected static final String ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME = "EnergyUsage.txt";
 	protected static final String AIRFLOW_STATISTICS_OUTPUT_FILE_NAME = "AirThroughput.txt";
+	protected static final String TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME = "Temperature.txt";
 
 	protected static final String DIAGRAMS_FILE_NAME_PREFIX = "Chart_";
@@ -141,4 +143,5 @@
 	protected Map<ResourceType, List<XYDataset>> resourcePowerUsageDiagrams;
 	protected Map<ResourceType, List<XYDataset>> resourceAirFlowDiagrams;
+	protected Map<ResourceType, List<XYDataset>> resourceTemperatureDiagrams;
 	protected Map<ResourceType, List<XYDataset>> resourceLoadDiagrams;
 	
@@ -250,4 +253,7 @@
 			if(ArrayUtils.contains(configuration.resForAirFlowChart, resourceName))
 				cStats.add(Stats.chartAirFlow);
+			cStats.add(Stats.textTemperature);
+			if(ArrayUtils.contains(configuration.resForTemperatureChart, resourceName))
+				cStats.add(Stats.chartTemperature);
 			type_stats.put(resourceName, cStats);
 		}		
@@ -259,4 +265,5 @@
 		resourcePowerUsageDiagrams = new HashMap<ResourceType, List<XYDataset>>();
 		resourceAirFlowDiagrams = new HashMap<ResourceType, List<XYDataset>>();
+		resourceTemperatureDiagrams = new HashMap<ResourceType, List<XYDataset>>();
 		
 		ganttDiagramTimetable = new Timetable(new FixedMillisecond(
@@ -292,4 +299,14 @@
 			airFlowStatsFile = null;
 		}
+		
+		PrintStream temperatureStatsFile = null;
+		try {
+			File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX
+					+ simulationIdentifier + "_"
+					+ TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME);
+			temperatureStatsFile = new PrintStream(new FileOutputStream(file));
+		} catch (IOException e) {
+			temperatureStatsFile = null;
+		}
 
 		basicResStats = gatherPEStats(jr.getExecutableTasks());
@@ -316,4 +333,5 @@
 					ResourcePowerStats energyUsage = null;
 					ResourceAirFlowStats airFlow = null;
+					ResourceTemperatureStats temperature = null;
 					if(type_stats.get(resourceName).contains(Stats.textLoad)){
 						resourceUsage = gatherResourceLoadStats(resource, basicResStats);
@@ -404,4 +422,42 @@
 						}
 					}
+					
+					if(type_stats.get(resourceName).contains(Stats.textTemperature)){
+						temperature = gatherResourceTemperatureStats(resource);
+						temperature.setMeanValue(calculateMeanValue(temperature));
+						temperature.setSumValue(temperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC));
+						
+						EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION));
+						if(resourceController.getComputingResources().contains(resource)) {
+							if( een != null /*&& een.getPp() != null*/ ){
+								accStats.meanTemperature.add(temperature.getSumValue());
+							}
+
+						} else if( een != null && een.getThermalProfile() != null ){
+							ComputingResource parent = resource.getParent();
+							een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION));
+							boolean top = true;
+							while(parent != null){
+								if(een != null &&  een.getThermalProfile() != null) {
+									top = false;
+									break;
+								}
+								parent = parent.getParent();
+							}
+							if(top == true){
+								accStats.meanTemperature.add(temperature.getSumValue());
+							}
+						}
+						if (temperatureStatsFile != null) {
+							Object txt = temperature.serialize(serializer);
+							temperatureStatsFile.println(txt);
+						}
+					}
+					if(type_stats.get(resourceName).contains(Stats.chartTemperature)){
+
+						if (configuration.creatediagrams_restemperature) {
+							createResourceTemperatureDiagramData(temperature);
+						}
+					}
 				}
 			}
@@ -411,4 +467,7 @@
 		createAccumulatedResourceSimulationStatistic();
 		
+		if (temperatureStatsFile != null) {
+			temperatureStatsFile.close();
+		}
 		if (airFlowStatsFile != null) {
 			airFlowStatsFile.close();
@@ -635,4 +694,31 @@
 	}
 	
+	private ResourceTemperatureStats gatherResourceTemperatureStats(ComputingResource resource) {
+
+		ResourceTemperatureStats resTemperature = new ResourceTemperatureStats(resource.getName(), resource.getType(), "resourceTemperatureStats");
+		Map<Long, Double> temperature = resTemperature.getHistory();
+		
+		ExtensionList extensionList = resource.getExtensionList();
+		if(extensionList != null){
+			for (Extension extension : extensionList) {
+				if (extension.getType() == ExtensionType.ENERGY_EXTENSION) {
+					EnergyExtension ee = (EnergyExtension)extension;
+					if(ee.getThermalProfile() == null)
+						break;
+
+					List<TemperatureValue> temperatureHistory = ee.getThermalProfile().getTemperatureHistory();
+					if(temperatureHistory.size() == 0)
+						break;
+					long endSimulationTime = DateTimeUtilsExt.currentTimeMillis();
+					temperatureHistory.add(new TemperatureValue(endSimulationTime, ee.getThermalProfile().getTemperatureHistory().get(ee.getThermalProfile().getTemperatureHistory().size()-1).getValue()));
+					for(TemperatureValue af: temperatureHistory){
+						temperature.put(af.getTimestamp(), af.getValue());
+					}
+				}
+			}
+		}
+		return resTemperature;
+	}
+	
 	private void createResourceLoadDiagram(ResourceUsageStats resLoadStats) {
 
@@ -667,4 +753,19 @@
 		} else {
 			energyDiagramData.add(dataset);
+		}
+	}
+	
+	private void createResourceTemperatureDiagramData(ResourceDynamicStats temperatureStats) {
+		
+		XYDataset dataset = createResourceChartDataSet(temperatureStats,
+				startSimulationTime, endSimulationTime);
+		
+		List<XYDataset> temperatureDiagramData = resourceTemperatureDiagrams.get(temperatureStats.getResourceType());
+		if(temperatureDiagramData == null){
+			temperatureDiagramData = new ArrayList<XYDataset>();
+			temperatureDiagramData.add(dataset);
+			resourceTemperatureDiagrams.put(temperatureStats.getResourceType(), temperatureDiagramData);
+		} else {
+			temperatureDiagramData.add(dataset);
 		}
 	}
@@ -770,4 +871,17 @@
 						subtitle, axisName);
 				if (!saveXYPlotChart(resourceAirFlowDiagram, fileName + "AirThroughput - "+resType.getName()))
+					return false;
+			}
+		}
+		
+		chartName = "Temperature diagram for "
+			+ DataCenterWorkloadSimulator.SIMULATOR_NAME;
+		JFreeChart resourceTemperatureDiagram = null;
+		if (configuration.creatediagrams_restemperature) {
+			String axisName = "TEMPERATURE [C]";
+			for(ResourceType resType: resourceTemperatureDiagrams.keySet()){
+				resourceTemperatureDiagram = getResourceDynamicDiagram(resourceTemperatureDiagrams.get(resType), simulationTime, chartName,
+						subtitle, axisName);
+				if (!saveXYPlotChart(resourceTemperatureDiagram, fileName + "Temperature - "+resType.getName()))
 					return false;
 			}
@@ -1322,8 +1436,14 @@
 			Integer o1int;
 			Integer o2int;
-
+			String o1string;
+			String o2string;
+			o1string = o1.substring(0, o1.indexOf("_"));
+			o2string = o2.substring(0, o2.indexOf("_"));
 			o1int = Integer.parseInt(o1.substring(o1.indexOf("_")+1));
 			o2int = Integer.parseInt(o2.substring(o2.indexOf("_")+1));
-			return o1int.compareTo(o2int);
+			if(o1string.compareTo(o2string) != 0)
+				return o1string.compareTo(o2string);
+			else
+				return o1int.compareTo(o2int);
 		}
 	}
@@ -1401,4 +1521,6 @@
 	chartEnergy,
 	textAirFlow,
-	chartAirFlow;
+	chartAirFlow,
+	textTemperature,
+	chartTemperature;
 }
