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 97 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/perl/make_parameter_source.pl
Show inline comments
 
@@ -98,12 +98,14 @@ print cppfile <<END_HEADER;
 
#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
 
@@ -279,13 +281,14 @@ for ($i=0;$i<$lines;$i++) {
 
  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 *") {
 
@@ -297,15 +300,19 @@ for ($i=0;$i<$lines;$i++) {
 
    } 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";
 
}
src/xmlwrite.cpp
Show inline comments
 
@@ -28,12 +28,13 @@
 
#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$");
 
@@ -316,12 +317,14 @@ getnodeset (xmlDocPtr doc, xmlChar *xpat
 

	
 

	
 

	
 
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");
 
@@ -367,13 +370,15 @@ int Cell::XMLRead(xmlNode *cur)  {
 
				  
 
				  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 = 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; 
 
		  }
 
	  }
 
@@ -385,62 +390,72 @@ int Cell::XMLRead(xmlNode *cur)  {
 
		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);
 
    }
 
  }
 

	
 
      
 
  {
 
@@ -689,19 +704,23 @@ void Wall::XMLAdd(xmlNode *parent) const
 
}
 

	
 

	
 
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));
 
	//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;
 
  }
 
@@ -887,14 +906,21 @@ void Mesh::XMLSave(const char *docname, 
 
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);
 
    //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;
 
	}	
 
@@ -907,16 +933,18 @@ void Mesh::XMLReadPars(const xmlNode * a
 
	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);
 
		}
 
@@ -947,25 +975,32 @@ void Mesh::XMLReadGeometry(const xmlNode
 
	// 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;
 
@@ -1018,12 +1053,15 @@ void Mesh::XMLParseTree(const xmlNode *r
 
	
 
}
 

	
 

	
 
void Mesh::XMLReadNodes(xmlNode *root) {
 
	
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
	xmlNode *cur = root;
 
	cur = cur->xmlChildrenNode;
 
	
 
	for (vector<Node *>::iterator i=nodes.begin();
 
		 i!=nodes.end();
 
		 i++) {
 
@@ -1033,13 +1071,17 @@ void Mesh::XMLReadNodes(xmlNode *root) {
 
	nodes.clear();
 
	Node::nnodes=0;
 
	
 
	xmlChar *tlc = xmlGetProp(root, BAD_CAST "target_length");
 
	
 
	if (tlc != 0) {
 
		Node::target_length = strtod( (const char *)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.");
 
	}
 
    
 
@@ -1070,14 +1112,19 @@ void Mesh::XMLReadNodes(xmlNode *root) {
 
			
 
			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 y = strtod( (char *)yc , 0 );
 
      //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);
 
			
 
			Node *new_node = new Node(x,y);
 
			nodes.push_back(new_node);
 
			
 
			new_node->m = this;
 
			new_node->fixed = strtobool( (char *)fixedc);
 
@@ -1118,12 +1165,15 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
	walls.clear();
 
	Wall::nwalls = 0;
 
	tmp_walls->clear();
 
	//Node::nnodes=0;
 
	
 
	
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
	while (cur!=NULL) {
 
		
 
		vector<int> tmp_nodes;
 
		while(cur!=NULL) {
 
			if ((!xmlStrcmp(cur->name, (const xmlChar *)"wall"))) {
 
				
 
@@ -1161,21 +1211,27 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
				
 
				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);
 
	//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");
 
				
 
				double viz_flux;
 
				if (nc!=0) {
 
					viz_flux = strtod( (char *)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);
 
@@ -1247,13 +1303,16 @@ void Mesh::XMLReadWalls(xmlNode *root, 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. 835");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
		//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; 
 
						}
 
@@ -1279,13 +1338,16 @@ void Mesh::XMLReadWalls(xmlNode *root, 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 );
 
		//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; 
 
						}
 
						
 
@@ -1309,13 +1371,16 @@ void Mesh::XMLReadWalls(xmlNode *root, 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. 887");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
		//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; 
 
						}
 
						
0 comments (0 inline, 0 general)