Changeset - 857d43889502
[Not reviewed]
default
0 2 0
Roeland Merks - 15 years ago 2010-05-26 15:51:52
roeland.merks@cwi.nl
I have replaced the instances of strtod for the Qt conversion functions via QLocale. Possibly there is some remaining usage of atof and atoi.

user: Roeland Merks <roeland.merks@cwi.nl>
branch 'default'
changed src/perl/make_parameter_source.pl
changed src/xmlwrite.cpp
2 files changed with 363 insertions and 291 deletions:
0 comments (0 inline, 0 general)
src/perl/make_parameter_source.pl
Show inline comments
 
@@ -92,24 +92,26 @@ print cppfile <<END_HEADER;
 
// All edits will be discarded.
 

	
 
#include "parameter.h"
 
#include <cstdio>
 
#include <cstring>
 
#include <cstdlib>
 
#include <cerrno>
 
#include <iostream>
 
#include <sstream>
 
#include "output.h"
 
#include "parse.h"
 
#include "xmlwrite.h"
 
#include "warning.h"
 
#include <QLocale>
 

	
 
using namespace std;
 

	
 

	
 
Parameter::Parameter() {
 
END_HEADER
 

	
 
for ($i=0;$i<$lines;$i++) {
 
  if ($convtype[$i] ne "label" && $convtype[$i] ne "title") {
 
    if ($convtype[$i] eq "char *") {
 
      print cppfile "  $param[$i] = strdup($value[$i]);\n";
 
    } else {
 
@@ -273,45 +275,50 @@ for ($i=0;$i<$lines;$i++) {
 
	print cppfile "  ";
 
      }
 
      print cppfile "  text << $param[$i];\n";
 
    }
 
  }
 
  print cppfile "xmlNewProp(xmlpar, BAD_CAST \"val\", BAD_CAST text.str().c_str());\n";
 
  print cppfile "}\n";
 
}
 
print cppfile "}\n";
 

	
 
print cppfile "void Parameter::AssignValToPar(const char *namec, const char *valc) {\n";
 
print cppfile;
 

	
 
print cppfile "  QLocale standardlocale(QLocale::C);\n";
 
print cppfile "  bool ok;\n";
 
for ($i=0;$i<$lines;$i++) {
 

	
 
  if ($convtype[$i] eq "label" || $convtype[$i] eq "title") {
 
    next;
 
  }
 
  if ($convtype[$i] eq "double *") {
 
    next;
 
  } else {
 
    print cppfile "if (!strcmp(namec, \"$param[$i]\")) {\n";
 
    if ($convtype[$i] eq "bool") {
 
      print cppfile "$param[$i] = strtobool(valc);\n";
 
    } else {
 
      if ($convtype[$i] eq "char *") {
 
	print cppfile "  if ($param[$i]) { free($param[$i]); }\n";
 
	print cppfile "  $param[$i]=strdup(valc);\n";
 
      } else {
 
	if ($convtype[$i] eq "int") {
 
	  print cppfile "  $param[$i] = (int)strtol(valc, 0, 10);\n";
 
	  print cppfile "  $param[$i] = standardlocale.toInt(valc, &ok);\n";
 
	  print cppfile "  if (!ok) { MyWarning::error(\"Read error: cannot convert string \\\"%s\\\" to integer while reading parameter '$param[$i]' from XML file.\",valc); }\n";
 
	  # print cppfile "  $param[$i] = (int)strtol(valc, 0, 10);\n";
 
	} else {
 
	  print cppfile "  $param[$i] = strtod(valc, 0);\n";
 
	  # print cppfile "  $param[$i] = strtod(valc, 0);\n";
 
	  print cppfile "  $param[$i] = standardlocale.toDouble(valc, &ok);\n";
 
	  print cppfile "  if (!ok) { MyWarning::error(\"Read error: cannot convert string \\\"%s\\\" to double while reading parameter '$param[$i]' from XML file.\",valc); }\n";
 
	}
 
      }
 
    }
 
  }
 
  print cppfile "}\n";
 
}
 
print cppfile "}\n";
 

	
 
print cppfile "void Parameter::AssignValArrayToPar(const char *namec, vector<double> valarray) {\n";
 
print cppfile;
 

	
 
for ($i=0;$i<$lines;$i++) {
src/xmlwrite.cpp
Show inline comments
 
@@ -22,24 +22,25 @@
 
#include "mesh.h"
 
#include "parameter.h"
 

	
 
#include <ctime>
 
#include <cstring>
 
#include <string>
 
#include <sstream>
 
#include <QString>
 
#include <libxml/parser.h>
 
#include <libxml/tree.h>
 
#include <libxml/xpath.h>
 
#include <libxml/xmlreader.h>
 
#include <QLocale>
 
#include "xmlwrite.h"
 
#include "nodeset.h"
 
#include "warning.h"
 
#include "output.h" 
 

	
 
static const std::string _module_id("$Id$");
 

	
 
using namespace MyWarning;
 

	
 
void ThrowStringStream(stringstream &s) {
 
	
 
	static char *msg = 0;
 
@@ -310,25 +311,27 @@ getnodeset (xmlDocPtr doc, xmlChar *xpat
 
    xmlXPathFreeObject(result);
 
    // printf("No result\n");
 
    return NULL;
 
  }
 
  return result;
 
}
 

	
 

	
 

	
 
int Cell::XMLRead(xmlNode *cur)  {
 
  
 
  xmlNode *n = cur->xmlChildrenNode;
 
  
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  vector<int> tmp_nodes;
 

	
 
	while(n!=NULL) {
 
    if ((!xmlStrcmp(n->name, (const xmlChar *)"node"))) {
 
      xmlChar *nc = xmlGetProp(n, BAD_CAST "n");
 

	
 
      if (nc==0) {
 
	unique_warning("Token \"n\" not found in xmlwrite.cpp at or around line no. 966");
 
      }
 
      tmp_nodes.push_back(atoi( (char *)nc));
 
      xmlFree(nc);
 

	
 
@@ -339,114 +342,126 @@ int Cell::XMLRead(xmlNode *cur)  {
 
  int nnodes = tmp_nodes.size();
 
  for (int i=0;i<nnodes;i++) {
 
    m->AddNodeToCell( this, 
 
		      m->nodes[tmp_nodes[i]], 
 
		      m->nodes[tmp_nodes[(nnodes+i-1)%nnodes]],
 
		      m->nodes[tmp_nodes[(i+1)%nnodes]] );
 
	
 
  }
 

	
 
  n = cur->xmlChildrenNode;
 
  while(n!=NULL) {
 
	  if ((!xmlStrcmp(n->name, (const xmlChar *)"chem"))) {
 
		xmlChar *v_str = xmlGetProp(n, BAD_CAST "n");
 
		  xmlNode *v_node = n->xmlChildrenNode;
 
		  int nv=0;
 
		  while (v_node!=NULL) {
 
			  if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 

	
 
				  
 
				  if (nv>=Cell::NChem()) {
 
					  {
 
						  stringstream text;
 
						  text << "Exception in Mesh::XMLRead: Too many chemical values given for cell(s). Ignoring remaining values.";
 
						  //ThrowStringStream(text);
 
						  unique_warning(text.str().c_str());
 
						  break;
 
					  }
 
				  }
 
				  
 
				  xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
				  
 
				  if (nc==0) {
 
					  unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 1002");
 
				  }
 
				  double v = strtod( (char *)nc, 0 );
 
				  chem[nv++]=v;
 
				  xmlFree(nc);
 
			  }
 
			  v_node = v_node->next; 
 
	    xmlChar *v_str = xmlGetProp(n, BAD_CAST "n");
 
	    xmlNode *v_node = n->xmlChildrenNode;
 
	    int nv=0;
 
	    while (v_node!=NULL) {
 
	      if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
		
 
		
 
		if (nv>=Cell::NChem()) {
 
		  {
 
		    stringstream text;
 
		    text << "Exception in Mesh::XMLRead: Too many chemical values given for cell(s). Ignoring remaining values.";
 
		    //ThrowStringStream(text);
 
		    unique_warning(text.str().c_str());
 
		    break;
 
		  }
 
		}
 
		
 
		xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
		
 
		if (nc==0) {
 
		  unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 1002");
 
		}
 
		//double v = strtod( (char *)nc, 0 );
 
		double v=standardlocale.toDouble((char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)nc);
 
		chem[nv++]=v;
 
		xmlFree(nc);
 
	      }
 
	      v_node = v_node->next; 
 
	    }
 
	  }
 
	  n = n->next;
 
  }
 
	
 
	// read cell properties
 
	{
 
		xmlChar *v_str = xmlGetProp(cur, BAD_CAST "area");
 
		
 
		if (v_str==0) {
 
			unique_warning("Token \"area\" not found in xmlwrite.cpp at or around line no. 1018");
 
		}
 
		if (v_str != NULL) {
 
			area = strtod( (char *)v_str, 0);
 
		  //area = strtod( (char *)v_str, 0);
 
			area=standardlocale.toDouble((char *)v_str, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
			xmlFree(v_str);
 
		}
 
	}
 
	
 
	{
 
		xmlChar *v_str = xmlGetProp(cur, BAD_CAST "target_area");
 
		
 
		if (v_str==0) {
 
			unique_warning("Token \"target_area\" not found in xmlwrite.cpp at or around line no. 1029");
 
		}
 
    if (v_str != NULL) {
 
      target_area = strtod( (char *)v_str, 0);
 
      //target_area = strtod( (char *)v_str, 0);
 
      	target_area=standardlocale.toDouble((char *)v_str, &ok);
 
	if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 
      
 
      
 
  {
 
    xmlChar *v_str = xmlGetProp(cur, BAD_CAST "target_length");
 

	
 
    if (v_str==0) {
 
      unique_warning("Token \"target_length\" not found in xmlwrite.cpp at or around line no. 1041");
 
    }
 
    if (v_str != NULL) {
 
      target_length = strtod( (char *)v_str, 0);
 
      //target_length = strtod( (char *)v_str, 0);
 
      target_length=standardlocale.toDouble((char *)v_str, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 

	
 
  {
 
    xmlChar *v_str = xmlGetProp(cur, BAD_CAST "lambda_celllength");
 

	
 
    if (v_str==0) {
 
      unique_warning("Token \"lambda_celllength\" not found in xmlwrite.cpp at or around line no. 1052");
 
    }
 
    if (v_str != NULL) {
 
      lambda_celllength = strtod( (char *)v_str, 0);
 
      //lambda_celllength = strtod( (char *)v_str, 0);
 
      lambda_celllength=standardlocale.toDouble((char *)v_str, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 

	
 
  {
 
    xmlChar *v_str = xmlGetProp(cur, BAD_CAST "stiffness");
 

	
 
    if (v_str==0) {
 
      unique_warning("Token \"stiffness\" not found in xmlwrite.cpp at or around line no. 1063");
 
    }
 
    if (v_str != NULL) {
 
      stiffness = strtod( (char *)v_str, 0);
 
      //stiffness = strtod( (char *)v_str, 0);
 
      stiffness=standardlocale.toDouble((char *)v_str, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 

	
 
      
 
  {
 
    xmlChar *v_str = xmlGetProp(cur, BAD_CAST "fixed");
 

	
 
    if (v_str==0) {
 
      unique_warning("Token \"fixed\" not found in xmlwrite.cpp at or around line no. 1075");
 
    }
 
    if (v_str != NULL) {
 
@@ -683,32 +698,36 @@ void Wall::XMLAdd(xmlNode *parent) const
 
	text << transporters2[i];
 
	xmlNewProp(apo_val_xml, BAD_CAST "v", BAD_CAST text.str().c_str());
 
	
 
      }
 
    }
 
  } 
 
}
 

	
 

	
 
vector<double> XMLIO::XMLReadValArray(xmlNode *cur) {
 
  
 
  vector<double> result;
 
  
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  xmlNode *valarray_node = cur->xmlChildrenNode;
 
  while (valarray_node!=NULL) {
 
    if (!xmlStrcmp(valarray_node->name, (const xmlChar *)"val")) {
 
      xmlChar *vc = xmlGetProp(valarray_node, BAD_CAST "v");
 
      if (vc) {
 
		  result.push_back(strtod( (const char *)vc, 0));
 
		  xmlFree(vc);
 
	//result.push_back(strtod( (const char *)vc, 0));
 
	result.push_back(standardlocale.toDouble((char *)vc, &ok));
 
	if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)vc);
 
	xmlFree(vc);
 
      }
 
      
 
    }
 
    valarray_node = valarray_node->next;
 
  }
 
  return result;
 
}
 

	
 
void Mesh::XMLSave(const char *docname, xmlNode *options) const
 
{
 
	
 
	// based on libxml2 example code "tree2.c"
 
@@ -877,52 +896,61 @@ void Mesh::XMLSave(const char *docname, 
 
	xmlCleanupParser();
 
	
 
	/*
 
	 * this is to debug memory for regression tests
 
	 */
 
	//xmlMemoryDump();
 
}
 

	
 

	
 

	
 
void Mesh::XMLReadSimtime(const xmlNode *a_node) {
 
	
 
	xmlNode *root_node;
 
	root_node = (xmlNode *)a_node;
 
	xmlNode *cur;
 
	xmlChar *strsimtime = xmlGetProp(root_node, BAD_CAST "simtime");
 
    if (strsimtime) {
 
		double simtime = strtod((const char *)strsimtime, 0);
 
		time = simtime;
 
  xmlNode *root_node;
 
  root_node = (xmlNode *)a_node;
 
  xmlNode *cur;
 
  xmlChar *strsimtime = xmlGetProp(root_node, BAD_CAST "simtime");
 
  
 
  
 
  if (strsimtime) {
 
    //double simtime = strtod((const char *)strsimtime, 0);
 
    QLocale standardlocale(QLocale::C);
 
    bool ok;
 
    
 
    double simtime=standardlocale.toDouble((char *)strsimtime, &ok);
 
    if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)strsimtime);
 
      time = simtime;
 
		cerr << "Simtime = " << strsimtime << endl;
 
	} else {
 
		cerr << "No simtime found in file \n";
 
		time =0;
 
	}	
 
}
 

	
 
void Mesh::XMLReadPars(const xmlNode * a_node) {
 
	xmlNode *root_node;
 
	root_node = (xmlNode *)a_node;
 
	par.XMLRead(root_node);
 
	Seed(par.rseed);
 
	MakeDir(par.datadir);
 
}
 

	
 
void Mesh::XMLReadGeometry(const xmlNode * a_node)
 
{
 
  
 
	xmlNode *root_node;
 
	root_node = (xmlNode *)a_node;
 
	xmlNode *cur;
 
	
 
	QLocale standardlocale(QLocale::C);
 
	bool ok;
 
	// allocate Nodes
 
	cur = root_node->xmlChildrenNode;
 
	while (cur!=NULL) {
 
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"nodes"))){
 
			XMLReadNodes(cur);
 
		}
 
		cur=cur->next;
 
	}
 
	
 
	cur = root_node->xmlChildrenNode;
 
	while (cur!=NULL) {
 
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"nodesets"))) {
 
@@ -941,37 +969,44 @@ void Mesh::XMLReadGeometry(const xmlNode
 
    
 
	//cur = root_node;
 
    
 
	// allocate Cells
 
	cur = root_node;
 
	
 
	// allocate Cells
 
	cur = cur->xmlChildrenNode;
 
	while (cur!=NULL) {
 
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"cells"))){
 
			xmlChar *offsetxc = xmlGetProp(cur, BAD_CAST "offsetx");
 
			xmlChar *offsetyc = xmlGetProp(cur, BAD_CAST "offsety");
 
			double ox = strtod((const char*)offsetxc, 0);
 
			double oy = strtod((const char*)offsetyc, 0);
 
			
 
			//double ox = strtod((const char*)offsetxc, 0);
 
			double ox=standardlocale.toDouble((const char *)offsetxc, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)offsetxc);
 
			//double oy = strtod((const char*)offsetyc, 0);
 
			double oy=standardlocale.toDouble((const char *)offsetyc, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)offsetyc);
 
			Cell::setOffset(ox, oy);
 
			xmlFree(offsetxc);
 
			xmlFree(offsetyc);
 
			
 
			xmlChar *magnificationc = xmlGetProp(cur, BAD_CAST "magnification");
 
			Cell::SetMagnification(strtod((const char*)magnificationc, 0 ));
 
			//Cell::SetMagnification(strtod((const char*)magnificationc, 0 ));
 
			Cell::SetMagnification(standardlocale.toDouble((const char *)magnificationc, &ok));
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)magnificationc);
 
			xmlFree(magnificationc);
 
			
 
			xmlChar *baseareac = xmlGetProp(cur, BAD_CAST "base_area");
 
			Cell::BaseArea()= strtod((const char *)baseareac, 0 );
 
			//Cell::BaseArea()= strtod((const char *)baseareac, 0 );
 
			Cell::BaseArea() = standardlocale.toDouble((const char *)baseareac, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)baseareac);
 
			xmlFree(baseareac);
 
			
 
			
 
			XMLReadCells(cur);
 
		}
 
		cur=cur->next;
 
	}
 
    
 
	// allocate Walls (we need to have read the cells before constructing walls)
 
	vector <Wall *> tmp_walls;
 
	cur = root_node->xmlChildrenNode;
 
	while (cur!=NULL) {
 
@@ -1012,332 +1047,362 @@ void Mesh::XMLReadGeometry(const xmlNode
 

	
 
void Mesh::XMLParseTree(const xmlNode *root_node) {
 
	
 
	XMLReadSimtime(root_node);
 
	XMLReadPars(root_node);
 
	XMLReadGeometry(root_node);
 
	
 
}
 

	
 

	
 
void Mesh::XMLReadNodes(xmlNode *root) {
 
	
 
	xmlNode *cur = root;
 
	cur = cur->xmlChildrenNode;
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  xmlNode *cur = root;
 
  cur = cur->xmlChildrenNode;
 
	
 
	for (vector<Node *>::iterator i=nodes.begin();
 
		 i!=nodes.end();
 
		 i++) {
 
		delete *i;
 
	}
 
  for (vector<Node *>::iterator i=nodes.begin();
 
       i!=nodes.end();
 
       i++) {
 
    delete *i;
 
  }
 
	
 
	nodes.clear();
 
	Node::nnodes=0;
 
  nodes.clear();
 
  Node::nnodes=0;
 
	
 
	xmlChar *tlc = xmlGetProp(root, BAD_CAST "target_length");
 
  xmlChar *tlc = xmlGetProp(root, BAD_CAST "target_length");
 
	
 
	if (tlc != 0) {
 
		Node::target_length = strtod( (const char *)tlc, 0 );
 
		xmlFree(tlc);
 
	} else {
 
		// note that libxml2 also defines a token "warning"
 
		MyWarning::unique_warning("Warning: value found in XML file for Node::target_length.");
 
	}
 
  if (tlc != 0) {
 
    //Node::target_length = strtod( (const char *)tlc, 0 );
 
	  
 
    Node::target_length = standardlocale.toDouble((const char *)tlc, &ok);
 
    if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)tlc);
 
		
 
    xmlFree(tlc);
 
  } else {
 
    // note that libxml2 also defines a token "warning"
 
    MyWarning::unique_warning("Warning: value found in XML file for Node::target_length.");
 
  }
 
    
 
	while (cur!=NULL) {
 
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"node"))){
 
  while (cur!=NULL) {
 
    if ((!xmlStrcmp(cur->name, (const xmlChar *)"node"))){
 
			
 
			xmlChar *xc = xmlGetProp(cur, BAD_CAST "x");
 
      xmlChar *xc = xmlGetProp(cur, BAD_CAST "x");
 
			
 
			if (xc==0) {
 
				unique_warning("Token \"x\" not found in xmlwrite.cpp at or around line no. 722");
 
			}
 
      if (xc==0) {
 
	unique_warning("Token \"x\" not found in xmlwrite.cpp at or around line no. 722");
 
      }
 
			
 
			xmlChar *yc = xmlGetProp(cur, BAD_CAST "y");
 
      xmlChar *yc = xmlGetProp(cur, BAD_CAST "y");
 
			
 
			if (yc==0) {
 
				unique_warning("Token \"y\" not found in xmlwrite.cpp at or around line no. 727");
 
			}
 
      if (yc==0) {
 
	unique_warning("Token \"y\" not found in xmlwrite.cpp at or around line no. 727");
 
      }
 
			
 
      xmlChar *fixedc = xmlGetProp(cur, BAD_CAST "fixed");
 
      if (fixedc==0) {
 
	unique_warning("Token \"fixed\" not found in xmlwrite.cpp at or around line.");
 
      }
 
			
 
			xmlChar *fixedc = xmlGetProp(cur, BAD_CAST "fixed");
 
			if (fixedc==0) {
 
				unique_warning("Token \"fixed\" not found in xmlwrite.cpp at or around line.");
 
			}
 
      xmlChar *boundaryc = xmlGetProp(cur, BAD_CAST "boundary");
 
      if (boundaryc==0) {
 
	unique_warning("Token \"boundary\" not found in xmlwrite.cpp at or around line.");
 
      }
 
			
 
			xmlChar *boundaryc = xmlGetProp(cur, BAD_CAST "boundary");
 
			if (boundaryc==0) {
 
				unique_warning("Token \"boundary\" not found in xmlwrite.cpp at or around line.");
 
			}
 
      xmlChar *samc = xmlGetProp(cur, BAD_CAST "sam");
 
      if (samc==0) {
 
	unique_warning("Token \"sam\" not found in xmlwrite.cpp at or around line.");
 
      }
 
			
 
			xmlChar *samc = xmlGetProp(cur, BAD_CAST "sam");
 
			if (samc==0) {
 
				unique_warning("Token \"sam\" not found in xmlwrite.cpp at or around line.");
 
			}
 
      //double x = strtod( (char *)xc , 0);
 
      double x = standardlocale.toDouble((const char *)xc, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)xc);
 
		
 
      //double y = strtod( (char *)yc , 0 );
 
      double y = standardlocale.toDouble((const char *)yc, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)yc);
 
			
 
			double x = strtod( (char *)xc , 0);
 
			double y = strtod( (char *)yc , 0 );
 
			
 
			Node *new_node = new Node(x,y);
 
			nodes.push_back(new_node);
 
      Node *new_node = new Node(x,y);
 
      nodes.push_back(new_node);
 
			
 
			new_node->m = this;
 
			new_node->fixed = strtobool( (char *)fixedc);
 
			new_node->boundary = strtobool( (char *)boundaryc );
 
			new_node->sam = strtobool ( (char *)samc);
 
			new_node->node_set = 0;
 
      new_node->m = this;
 
      new_node->fixed = strtobool( (char *)fixedc);
 
      new_node->boundary = strtobool( (char *)boundaryc );
 
      new_node->sam = strtobool ( (char *)samc);
 
      new_node->node_set = 0;
 
			
 
			xmlFree(xc);
 
			xmlFree(yc);
 
			xmlFree(boundaryc);
 
			xmlFree(fixedc);
 
			xmlFree(samc);
 
      xmlFree(xc);
 
      xmlFree(yc);
 
      xmlFree(boundaryc);
 
      xmlFree(fixedc);
 
      xmlFree(samc);
 
			
 
			
 
		}
 
		cur=cur->next;
 
	}
 
    }
 
    cur=cur->next;
 
  }
 
	
 
	shuffled_nodes.clear();
 
	shuffled_nodes = nodes;
 
  shuffled_nodes.clear();
 
  shuffled_nodes = nodes;
 
	
 
	MyUrand r(shuffled_nodes.size());
 
	random_shuffle(shuffled_nodes.begin(),shuffled_nodes.end(),r);
 
  MyUrand r(shuffled_nodes.size());
 
  random_shuffle(shuffled_nodes.begin(),shuffled_nodes.end(),r);
 
	
 
}
 

	
 
void Mesh::XMLReadWalls(xmlNode *root, vector<Wall *> *tmp_walls) {
 
	
 
	xmlNode *cur = root;
 
	cur = cur->xmlChildrenNode;
 
  xmlNode *cur = root;
 
  cur = cur->xmlChildrenNode;
 
	
 
	for (list<Wall *>::iterator i=walls.begin();
 
		 i!=walls.end();
 
		 i++) {
 
		delete *i;
 
	}
 
  for (list<Wall *>::iterator i=walls.begin();
 
       i!=walls.end();
 
       i++) {
 
    delete *i;
 
  }
 
	
 
	walls.clear();
 
	Wall::nwalls = 0;
 
	tmp_walls->clear();
 
	//Node::nnodes=0;
 
  walls.clear();
 
  Wall::nwalls = 0;
 
  tmp_walls->clear();
 
  //Node::nnodes=0;
 
	
 
	
 
	while (cur!=NULL) {
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  while (cur!=NULL) {
 
		
 
		vector<int> tmp_nodes;
 
		while(cur!=NULL) {
 
			if ((!xmlStrcmp(cur->name, (const xmlChar *)"wall"))) {
 
    vector<int> tmp_nodes;
 
    while(cur!=NULL) {
 
      if ((!xmlStrcmp(cur->name, (const xmlChar *)"wall"))) {
 
				
 
				xmlChar *nc = xmlGetProp(cur, BAD_CAST "c1");
 
	xmlChar *nc = xmlGetProp(cur, BAD_CAST "c1");
 
				
 
				if (nc==0) {
 
					unique_warning("Token \"c1\" not found in xmlwrite.cpp at or around line no. 777");
 
				}
 
				int c1 = atoi( (char *)nc);
 
				xmlFree(nc);
 
	if (nc==0) {
 
	  unique_warning("Token \"c1\" not found in xmlwrite.cpp at or around line no. 777");
 
	}
 
	int c1 = atoi( (char *)nc);
 
	xmlFree(nc);
 
				
 
				nc = xmlGetProp(cur, BAD_CAST "c2");
 
	nc = xmlGetProp(cur, BAD_CAST "c2");
 
				
 
				if (	nc==0) {
 
					unique_warning("Token \"c2\" not found in xmlwrite.cpp at or around line no. 785");
 
				}
 
				int c2 = atoi( (char *)nc);
 
				xmlFree(nc);
 
	if (	nc==0) {
 
	  unique_warning("Token \"c2\" not found in xmlwrite.cpp at or around line no. 785");
 
	}
 
	int c2 = atoi( (char *)nc);
 
	xmlFree(nc);
 
				
 
				nc = xmlGetProp(cur, BAD_CAST "n1");
 
	nc = xmlGetProp(cur, BAD_CAST "n1");
 
				
 
				if (	nc==0) {
 
					unique_warning("Token \"n1\" not found in xmlwrite.cpp at or around line no. 793");
 
				}
 
				int n1 = atoi( (char *)nc);
 
				xmlFree(nc);
 
	if (	nc==0) {
 
	  unique_warning("Token \"n1\" not found in xmlwrite.cpp at or around line no. 793");
 
	}
 
	int n1 = atoi( (char *)nc);
 
	xmlFree(nc);
 
				
 
				nc = xmlGetProp(cur, BAD_CAST "n2");
 
	nc = xmlGetProp(cur, BAD_CAST "n2");
 
				
 
				if (	nc==0) {
 
					unique_warning("Token \"n2\" not found in xmlwrite.cpp at or around line no. 801");
 
				}
 
				int n2 = atoi( (char *)nc);
 
				xmlFree(nc);
 
	if (	nc==0) {
 
	  unique_warning("Token \"n2\" not found in xmlwrite.cpp at or around line no. 801");
 
	}
 
	int n2 = atoi( (char *)nc);
 
	xmlFree(nc);
 
				
 
	nc = xmlGetProp(cur, BAD_CAST "length");
 
				
 
				nc = xmlGetProp(cur, BAD_CAST "length");
 
				
 
				if (	nc==0) {
 
					unique_warning("Token \"length\" not found in xmlwrite.cpp at or around line no. 809");
 
				}
 
				double length = strtod( (char *)nc, 0);
 
				xmlFree(nc);
 
	if (	nc==0) {
 
	  unique_warning("Token \"length\" not found in xmlwrite.cpp at or around line no. 809");
 
	}
 
	//double length = strtod( (char *)nc, 0);
 
	double length = standardlocale.toDouble((const char *)nc, &ok);
 
	if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
	xmlFree(nc);
 
				
 
				
 
				nc = xmlGetProp(cur, BAD_CAST "viz_flux");
 
	nc = xmlGetProp(cur, BAD_CAST "viz_flux");
 
				
 
				double viz_flux;
 
				if (nc!=0) {
 
					viz_flux = strtod( (char *)nc, 0);
 
				} else {
 
					// if the info is not there, we really don't care.
 
					// It is just for visualization anyhow.
 
					viz_flux = 0.;
 
				}
 
				xmlFree(nc);
 
	double viz_flux;
 
	if (nc!=0) {
 
	  //viz_flux = strtod( (char *)nc, 0);
 
	  double viz_flux = standardlocale.toDouble((const char *)nc, &ok);
 
	  if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
	} else {
 
	  // if the info is not there, we really don't care.
 
	  // It is just for visualization anyhow.
 
	  viz_flux = 0.;
 
	}
 
	xmlFree(nc);
 
				
 
				Wall::WallType wall_type;
 
				{
 
					xmlChar *v_str = xmlGetProp(cur, BAD_CAST "wall_type");
 
	Wall::WallType wall_type;
 
	{
 
	  xmlChar *v_str = xmlGetProp(cur, BAD_CAST "wall_type");
 
					
 
					if (v_str != 0) {
 
	  if (v_str != 0) {
 
						
 
						if (!xmlStrcmp(v_str, (const xmlChar *)"aux_source")) {
 
							wall_type = Wall::AuxSource;
 
						} else {
 
							if (!xmlStrcmp(v_str, (const xmlChar *)"aux_sink")) {
 
								wall_type = Wall::AuxSink;
 
							} else {
 
								wall_type = Wall::Normal;
 
							}
 
						}
 
						xmlFree(v_str);
 
	    if (!xmlStrcmp(v_str, (const xmlChar *)"aux_source")) {
 
	      wall_type = Wall::AuxSource;
 
	    } else {
 
	      if (!xmlStrcmp(v_str, (const xmlChar *)"aux_sink")) {
 
		wall_type = Wall::AuxSink;
 
	      } else {
 
		wall_type = Wall::Normal;
 
	      }
 
	    }
 
	    xmlFree(v_str);
 
						
 
					} else {
 
						wall_type = Wall::Normal;
 
					}
 
				}
 
	  } else {
 
	    wall_type = Wall::Normal;
 
	  }
 
	}
 
				
 
				bool dead = false;
 
				{
 
					// Note: property "delete" is used to manually clean up wall lists in XML files
 
					// Simply add property 'delete="true"' to the wall and it will be removed from
 
					// the mesh. (This saves us from manually reindexing the file). Otherwise do not use it.
 
					xmlChar *v_str = xmlGetProp(cur, BAD_CAST "delete");
 
	bool dead = false;
 
	{
 
	  // Note: property "delete" is used to manually clean up wall lists in XML files
 
	  // Simply add property 'delete="true"' to the wall and it will be removed from
 
	  // the mesh. (This saves us from manually reindexing the file). Otherwise do not use it.
 
	  xmlChar *v_str = xmlGetProp(cur, BAD_CAST "delete");
 
					
 
					if (v_str != 0) {
 
						dead = strtobool( (char *)v_str);
 
						xmlFree(v_str);
 
					}
 
	  if (v_str != 0) {
 
	    dead = strtobool( (char *)v_str);
 
	    xmlFree(v_str);
 
	  }
 
					
 
				}
 
	}
 
				
 
				Cell *cc1 = c1 != -1 ? cells[c1] : boundary_polygon;
 
				Cell *cc2 = c2 != -1 ? cells[c2] : boundary_polygon;
 
	Cell *cc1 = c1 != -1 ? cells[c1] : boundary_polygon;
 
	Cell *cc2 = c2 != -1 ? cells[c2] : boundary_polygon;
 
				
 
				Wall *w = new Wall( nodes[n1], nodes[n2], cc1, cc2);
 
				w->length = length;
 
				w->viz_flux = viz_flux;
 
				w->wall_type = wall_type;
 
				w->dead = dead;
 
				tmp_walls->push_back(w);
 
				walls.push_back(w);
 
	Wall *w = new Wall( nodes[n1], nodes[n2], cc1, cc2);
 
	w->length = length;
 
	w->viz_flux = viz_flux;
 
	w->wall_type = wall_type;
 
	w->dead = dead;
 
	tmp_walls->push_back(w);
 
	walls.push_back(w);
 
				
 
				xmlNode *w_node = cur->xmlChildrenNode;
 
				while (w_node!=NULL) {
 
					if ((!xmlStrcmp(w_node->name, (const xmlChar *)"transporters1"))) {
 
	xmlNode *w_node = cur->xmlChildrenNode;
 
	while (w_node!=NULL) {
 
	  if ((!xmlStrcmp(w_node->name, (const xmlChar *)"transporters1"))) {
 
						
 
						xmlNode *v_node = w_node->xmlChildrenNode;
 
						int nv=0;
 
						while (v_node!=NULL) {
 
	    xmlNode *v_node = w_node->xmlChildrenNode;
 
	    int nv=0;
 
	    while (v_node!=NULL) {
 
							
 
							if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
								if (nv>=Cell::NChem()) {
 
									{
 
										stringstream text;
 
										text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
										//ThrowStringStream(text);
 
										unique_warning(text.str().c_str());
 
										break;
 
									}
 
								}
 
								xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
	      if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
		if (nv>=Cell::NChem()) {
 
		  {
 
		    stringstream text;
 
		    text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
		    //ThrowStringStream(text);
 
		    unique_warning(text.str().c_str());
 
		    break;
 
		  }
 
		}
 
		xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
								
 
								if (nc==0) {
 
									unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 835");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
								w->transporters1[nv++]=v;
 
								xmlFree(nc);
 
		if (nc==0) {
 
		  unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 835");
 
		}
 
		//double v = strtod( (char *)nc, 0 );
 
		double v = standardlocale.toDouble((const char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
		w->transporters1[nv++]=v;
 
		xmlFree(nc);
 
								
 
							}
 
							v_node = v_node->next; 
 
						}
 
	      }
 
	      v_node = v_node->next; 
 
	    }
 
						
 
					}
 
	  }
 
					
 
					
 
					if ((!xmlStrcmp(w_node->name, (const xmlChar *)"transporters2"))) {
 
	  if ((!xmlStrcmp(w_node->name, (const xmlChar *)"transporters2"))) {
 
						
 
						xmlNode *v_node = w_node->xmlChildrenNode;
 
						int nv=0;
 
						while (v_node!=NULL) {
 
							if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
								if (nv>=Cell::NChem()) {
 
									{
 
										stringstream text;
 
										text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
										unique_warning(text.str().c_str());
 
										break;
 
										// ThrowStringStream(text);
 
									}
 
								}
 
	    xmlNode *v_node = w_node->xmlChildrenNode;
 
	    int nv=0;
 
	    while (v_node!=NULL) {
 
	      if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
		if (nv>=Cell::NChem()) {
 
		  {
 
		    stringstream text;
 
		    text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
		    unique_warning(text.str().c_str());
 
		    break;
 
		    // ThrowStringStream(text);
 
		  }
 
		}
 
								
 
								xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
		xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
								
 
								if (nc==0) {
 
									unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 861");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
								w->transporters2[nv++]=v;
 
								xmlFree(nc);
 
							}
 
							v_node = v_node->next; 
 
						}
 
		if (nc==0) {
 
		  unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 861");
 
		}
 
		//double v = strtod( (char *)nc, 0 );
 
		double v = standardlocale.toDouble((const char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
		w->transporters2[nv++]=v;
 
		xmlFree(nc);
 
	      }
 
	      v_node = v_node->next; 
 
	    }
 
						
 
					} 
 
	  } 
 
					
 
					if ((!xmlStrcmp(w_node->name, (const xmlChar *)"apoplast"))) {
 
	  if ((!xmlStrcmp(w_node->name, (const xmlChar *)"apoplast"))) {
 
						
 
						xmlNode *v_node = w_node->xmlChildrenNode;
 
						int nv=0;
 
						while (v_node!=NULL) {
 
	    xmlNode *v_node = w_node->xmlChildrenNode;
 
	    int nv=0;
 
	    while (v_node!=NULL) {
 
							
 
							if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
								if (nv>=Cell::NChem()) {
 
									{
 
										stringstream text;
 
										text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
										//ThrowStringStream(text);
 
										unique_warning(text.str().c_str());
 
										break;
 
									}
 
								}
 
								xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
	      if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
		if (nv>=Cell::NChem()) {
 
		  {
 
		    stringstream text;
 
		    text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
		    //ThrowStringStream(text);
 
		    unique_warning(text.str().c_str());
 
		    break;
 
		  }
 
		}
 
		xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
								
 
								if (nc==0) {
 
									unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 887");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
								w->apoplast[nv++]=v;
 
								xmlFree(nc);
 
							}
 
							v_node = v_node->next; 
 
						}
 
		if (nc==0) {
 
		  unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 887");
 
		}
 
		//double v = strtod( (char *)nc, 0 );
 
		double v = standardlocale.toDouble((const char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
		w->apoplast[nv++]=v;
 
		xmlFree(nc);
 
	      }
 
	      v_node = v_node->next; 
 
	    }
 
						
 
					}
 
					w_node=w_node->next;
 
				}
 
	  }
 
	  w_node=w_node->next;
 
	}
 
				
 
			}
 
			cur = cur->next;
 
		}
 
      }
 
      cur = cur->next;
 
    }
 
		
 
	}
 
	//  CleanUpWalls();
 
  }
 
  //  CleanUpWalls();
 
}
 

	
 

	
 
void Mesh::XMLReadWallsToCells(xmlNode *root, vector<Wall *> *tmp_walls) {
 
	
 
	// Add the walls to the cells (do this after reading the walls; read walls after reading cells...)
 
	// 1. Read Nodes
 
	// 2. Read Cells
 
	// 3. Read Walls
 
	// 4. Read Walls into Cells
 
	
 
	xmlNode *cur = root->xmlChildrenNode;
0 comments (0 inline, 0 general)