Index: /vtcross/trunk/src/shell/cr_shell.cpp
===================================================================
--- /vtcross/trunk/src/shell/cr_shell.cpp	(revision 168)
+++ /vtcross/trunk/src/shell/cr_shell.cpp	(revision 169)
@@ -62,4 +62,5 @@
     for(size_t i = 0; i < ce_info->numObservables; i++) {
 		LOG("Observable: %s\n", oList[i]->name);
+
 		for(size_t j = 0; j < oList[i]->numAffects; j++) {
 			LOG("\t\tAffect %s -> %s ", oList[i]->affection_list[j].u->name, \
@@ -75,136 +76,164 @@
 {
 
-	TiXmlElement* pElem;	//!current element
-	TiXmlElement* pChild;	//!current child of pElem
-	TiXmlElement* pChild1;	//!current child of pElem
-	TiXmlElement* pSecondChild;	//!current child of pElem
-	TiXmlHandle hDoc(doc);	//!handle to xml document
-	TiXmlHandle hRoot(0); //! handle to root element 
+	TiXmlElement *pElem;
+	TiXmlElement *pChild;
+	TiXmlElement *pChild1;
+	TiXmlElement *pSecondChild;
+	TiXmlHandle hDoc(doc);
+	TiXmlHandle hRoot(0);
 
 	int32_t count = 0;
-	int32_t i = 0;
-	int32_t j = 0;
-	int32_t k = 0;
-	int32_t match_found = 0;
+	size_t item_count = 0;
+    size_t affect_count = 0;
+	int32_t attribute_count = 0;
+    bool match_found = false;
 
 	pElem = hDoc.FirstChildElement().Element();
-	if(!pElem) { cout << "no valid root! quit-ing function!" << endl; return 0; }
+
+	if(!pElem) 
+        ERROR(1, "No valid root!");
+
 	hRoot = TiXmlHandle(pElem);
 
-	// Pull utility information from XML file.
-
 	pElem = hRoot.FirstChild("utilities").Element();
-	pChild1 = hRoot.Child("utilities",count).Element();
-
-
-	for(pChild = pChild1->FirstChildElement("utility"); pChild; pChild = pChild->NextSiblingElement())
-     	{
-		u[i] = new Utility;
+	pChild1 = hRoot.Child("utilities", count).Element();
+
+	for(pChild = pChild1->FirstChildElement("utility"); pChild; \
+            pChild = pChild->NextSiblingElement()) {
+
+		u[item_count] = new Utility;
+
    		const char *uName = pChild->Attribute("name");
-   		if(uName) u[i]->name = uName;	
+   		if(uName)
+            u[item_count]->name = uName;	
+
 		const char *uUnits = pChild->Attribute("units");
-   		if(uUnits) u[i]->units = uUnits;
+   		if(uUnits) 
+            u[item_count]->units = uUnits;
+
    		const char *uGoal = pChild->Attribute("goal");
-   		if(uGoal) u[i]->goal = uGoal;
-   		if(pChild->QueryFloatAttribute("target",&u[i]->target) != TIXML_SUCCESS) u[i]->target = -1;
-		i++;
-	}
-	ce_info->numUtilities = i;	
-	cout << "Initialize:: Parsed " << ce_info->numUtilities << " utilities." << endl;
-
-	// Pull observable information from XML file.
-	i = 0;
+   		if(uGoal) 
+            u[item_count]->goal = uGoal;
+
+   		if(pChild->QueryFloatAttribute("target", &u[i]->target) != TIXML_SUCCESS) 
+            u[i]->target = -1;
+
+		item_count++;
+	}
+
+	ce_info->numUtilities = item_count;	
+	LOG("Initialize:: Parsed %d utilities.\n", ce_info->numUtilities);
+
+	item_count = 0;
 	pElem = hRoot.FirstChild("observables").Element();
-	pChild1 = hRoot.Child("observables",count).Element();
-	
-	for(pChild = pChild1->FirstChildElement("observable"); pChild; pChild = pChild->NextSiblingElement())
-     	{
+	pChild1 = hRoot.Child("observables", count).Element();
+
+	for(pChild = pChild1->FirstChildElement("observable"); pChild; \
+            pChild = pChild->NextSiblingElement()) {
 
    		const char *oName = pChild->Attribute("name");
-		o[i] = new Observable;
-
-   		if(oName) o[i]->name = oName;
+		o[item_count] = new Observable;
+   		if(oName) 
+            o[item_count]->name = oName;
 		
-		j = 0;
-		for(pSecondChild = pChild->FirstChildElement("affect"); pSecondChild; pSecondChild = pSecondChild->NextSiblingElement())
-		{
+		affect_count = 0;
+		for(pSecondChild = pChild->FirstChildElement("affect"); pSecondChild; \
+                pSecondChild = pSecondChild->NextSiblingElement()) {
+
    			const char *oUtilName = pSecondChild->Attribute("utility");
-
-   			// If a utility affects this parameter find the utility object and assign it
 			if(oUtilName) {
-				// Search for correct utility
-				for( k=0 ; u[k]!=NULL ; k++ ){
-					if(u[k]->name == oUtilName) {
-						o[i]->affection_list[j].u = u[k];
-						// Set relationship
+				for(attribute_count = 0; u[attribute_count]! = NULL; attribute_count++ ) {
+					if(u[attribute_count]->name == oUtilName) {
+						o[i]->affection_list[affect_count].u = u[attribute_count];
+
 						const char *oRelate = pSecondChild->Attribute("relationship");
-   						if(oRelate) o[i]->affection_list[j].relation = oRelate;
-						j++;
-						match_found = 1;
+   						if(oRelate) 
+                            o[item_count]->affection_list[affect_count].relation = oRelate;
+
+						affect_count++;
+						match_found = true;
 				 		break;
 					}
 				}
 			}
-			if(!match_found) cout << "Error: " << o[i]->name << ": " << oUtilName << " not a valid utility: Affect not added." << endl;	
-			match_found = 0;	
+
+			if(!match_found) 
+                ERROR(1, "Error: %s: %s is not a valid utility.\n", \
+                        o[i]->name, oUtilName);
+            else
+                match_found = false;	
 		}
-		o[i]->numAffects = j; 
-		i++;
-	}
-	ce_info->numObservables = i;	
-	cout << "Initialize:: Parsed " << ce_info->numObservables << " observables." << endl;
+
+		o[item_count]->numAffects = affect_count; 
+		item_count++;
+	}
+
+	ce_info->numObservables = item_count;	
+	LOG("Initialize:: Parsed %d observables.\n", ce_info->numObservables);
+
+	pElem = hRoot.FirstChild("parameters").Element();
+	pChild1 = hRoot.Child("parameters", count).Element();
 	
-
-	// Pull parameter information from XML file.
-	pElem = hRoot.FirstChild("parameters").Element();
-	pChild1 = hRoot.Child("parameters",count).Element();
-	
-	i = 0;
-	for(pChild = pChild1->FirstChildElement("parameter"); pChild; pChild = pChild->NextSiblingElement())
-     	{
-		p[i] = new Parameter;
+	item_count = 0;
+	for(pChild = pChild1->FirstChildElement("parameter"); pChild; \
+            pChild = pChild->NextSiblingElement()) {
+
+		p[item_count] = new Parameter;
 
 		const char *pName = pChild->Attribute("name");
-   		if(pName) p[i]->name = pName;	
+   		if(pName) 
+            p[item_count]->name = pName;	
+
 		const char *pUnits = pChild->Attribute("units");
-   		if(pUnits) p[i]->units = pUnits;
-
-   		if(pChild->QueryFloatAttribute("min",&p[i]->min) != TIXML_SUCCESS) p[i]->min = -1;
-   		if(pChild->QueryFloatAttribute("max",&p[i]->max) != TIXML_SUCCESS) p[i]->max = -1;
-   		if(pChild->QueryFloatAttribute("step",&p[i]->step) != TIXML_SUCCESS) p[i]->step = -1;
+   		if(pUnits) 
+            p[item_count]->units = pUnits;
+
+   		if(pChild->QueryFloatAttribute("min", &p[i]->min) != TIXML_SUCCESS) 
+            p[item_count]->min = -1;
+
+   		if(pChild->QueryFloatAttribute("max", &p[i]->max) != TIXML_SUCCESS) 
+            p[item_count]->max = -1;
+
+   		if(pChild->QueryFloatAttribute("step", &p[i]->step) != TIXML_SUCCESS) 
+            p[item_count]->step = -1;
 		
-		j = 0;
-		for(pSecondChild = pChild->FirstChildElement("affect"); pSecondChild; pSecondChild = pSecondChild->NextSiblingElement())
-		{
+		affect_count = 0;
+		for(pSecondChild = pChild->FirstChildElement("affect"); pSecondChild; \
+                pSecondChild = pSecondChild->NextSiblingElement()) {
+
    			const char *pUtilName = pSecondChild->Attribute("utility");
-   			
-			// If a utility affects this parameter find the utility object and assign it
 			if(pUtilName) {
-				// Search for correct utility
-				for( k=0 ; u[k]!=NULL ; k++ ){
-					if(u[k]->name == pUtilName) {
-						// If match found, assign it to this index
-						p[i]->affection_list[j].u = u[k];	
+				for(attribute_count = 0; u[attribute_count] != NULL; attribute_count++) {
+					if(u[attribute_count]->name == pUtilName) {
+						p[item_count]->affection_list[affect_count].u = u[attribute_count];	
+
 						const char *pRelate = pSecondChild->Attribute("relationship");
-   						if(pRelate) {
-							p[i]->affection_list[j].relation = pRelate;
-						} else {
-							cout << "Error: No relation found." << endl;
-						}
-						match_found = 1;
-						j++;
+   						if(pRelate)
+							p[item_count]->affection_list[affect_count].relation = pRelate;
+						else
+							LOG("Error: No relation found.\n");
+
+						match_found = true;
+						affect_count++;
 						break;
 					}
 				}
 			}
-			if(!match_found) cout << "Error: " << p[i]->name << ": " << pUtilName << " not a valid utility: Affect not added." << endl;	
-			match_found = 0;	
+
+			if(!match_found) {
+                ERROR(1, "Error: %s: %s is not a valid utility.\n", \
+                        p[item_count]->name, pUtilName);
+            }
+
+			match_found = false;	
 		}
-		p[i]->numAffects = j; 
-		i++;
-
-	}
-	ce_info->numParameters = i;	
-	cout << "Initialize:: Parsed " << ce_info->numParameters << " parameters." << endl;
+
+		p[item_count]->numAffects = affect_count;
+		item_count++;
+	}
+
+	ce_info->numParameters = item_count;
+	LOG("Initialize:: Parsed %d parameters.\n", ce_info->numParameters);
+
 	return 1;
 }
