⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsilfield.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 2 页
字号:
/*  Copyright (C) 2000-2004  Code contributed by Greg Collecutt, Joseph Hope and Paul Cochrane  This file is part of xmds.   This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as published by the Free Software Foundation; either version 2  of the License, or (at your option) any later version.  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*//*  $Id: xsilfield.cc,v 1.15 2004/11/02 22:43:23 joehope Exp $*//*! @file xsilfield.cc  @brief XSIL format parsing classes and methods  More detailed explanation...*/#include<string>#include<xmlbasics.h>#include<dom3.h>#include<xmdsutils.h>#include<xsilfield.h>#define DEBUG 0// ******************************************************************************// ******************************************************************************//                              xsilField public// ******************************************************************************// ******************************************************************************long nxsilFields=0; //!< The number of xsil fields// ******************************************************************************xsilField::xsilField() {  if(DEBUG) {    nxsilFields++;    printf("xsilField::xsilField\n");    printf("nxsilFields=%li\n",nxsilFields);  }};// ******************************************************************************xsilField::~xsilField() {  if(DEBUG) {    nxsilFields--;    printf("xsilField::~xsilField\n");    printf("nxsilFields=%li\n",nxsilFields);  }};// ******************************************************************************void xsilField::processElement(			       const Element *const yourElement) {  if(DEBUG) {    printf("xsilField::processElement\n");  }  fieldName="";  nIndependentVariables=0;  variableNamesList.clear();  latticeList.clear();  const NodeList* candidateElements;  const NamedNodeMap* elementAttributes;  const Node* attributeNode;  list<XMLString> anXMLStringList;  // ************************************  // find name  elementAttributes = yourElement->attributes();  attributeNode = elementAttributes->getNamedItem("Name");  if(attributeNode != 0) {    fieldName = *attributeNode->nodeValue();  }  else  {    throw xmdsException(yourElement,"Where is my Name='...' attribute?");  }  // ************************************  // find n_independent Param assignment  candidateElements = yourElement->getElementsByTagName("Param",0);  if(candidateElements->length()>1) {    throw xmdsException(yourElement,"Only one <Param> element expected ");  }  elementAttributes = candidateElements->item(0)->attributes();  attributeNode = elementAttributes->getNamedItem("Name");  if(attributeNode != 0) {    if(*attributeNode->nodeValue() == "n_independent") {      if(!candidateElements->item(0)->textContent(0)->asULong(nIndependentVariables)) {	throw xmdsException(candidateElements->item(0),"Invalid positive integer format");      }    }    else {      throw xmdsException(candidateElements->item(0),"Unknown <Param> element");    }  }  else {    throw xmdsException(candidateElements->item(0),"Where is my Name='...' attribute?");  }  // ************************************  // find Arrays  candidateElements = yourElement->getElementsByTagName("Array",0);  if(candidateElements->length() != 2) {    throw xmdsException(yourElement,"Exactly two <Array> elements expected ");  }  // ************************************  // find variables Array  elementAttributes = candidateElements->item(0)->attributes();  attributeNode = elementAttributes->getNamedItem("Name");  if(attributeNode != 0) {    if(*attributeNode->nodeValue() != "variables") {      sprintf(errorMessage(),"Unknown <Array> element '%s'",attributeNode->nodeValue()->c_str());      throw xmdsException(yourElement,errorMessage());    }  }  else    throw xmdsException(candidateElements->item(0),"Where is my Name='...' attribute?");  const Element* myVariablesArrayElement = dynamic_cast<const Element*>(candidateElements->item(0));  // ************************************  // find data Array  elementAttributes = candidateElements->item(1)->attributes();  attributeNode = elementAttributes->getNamedItem("Name");  if(attributeNode != 0) {    if(*attributeNode->nodeValue() != "data") {      sprintf(errorMessage(),"Unknown <Array> element '%s'",attributeNode->nodeValue()->c_str());      throw xmdsException(yourElement,errorMessage());    }  }  else {    throw xmdsException(candidateElements->item(1),"Where is my Name='...' attribute?");  }  const Element* myDataArrayElement = dynamic_cast<const Element*>(candidateElements->item(1));  // ************************************  // process variables Array  unsigned long nVariables;  candidateElements = myVariablesArrayElement->getElementsByTagName("Dim",0);  if(candidateElements->length()>1) {    throw xmdsException(myVariablesArrayElement,"Only one <Dim> element expected ");  }  if(!candidateElements->item(0)->textContent(0)->asULong(nVariables)) {    throw xmdsException(candidateElements->item(0),"Invalid positive integer format");  }  getAssignmentStrings(myVariablesArrayElement,"Stream",1,nVariables,variableNamesList);  // ************************************  // process data Array  candidateElements = myDataArrayElement->getElementsByTagName("Dim",0);  if(candidateElements->length() != nIndependentVariables + 1) {    sprintf(errorMessage(),"Exactly %li <Dim> elements expected",nIndependentVariables + 1);    throw xmdsException(myDataArrayElement,errorMessage());  }  for(unsigned long i=0 ; i<candidateElements->length(); i++) {    unsigned long nextDim;    if(!candidateElements->item(i)->textContent(0)->asULong(nextDim)) {      throw xmdsException(candidateElements->item(i),"Invalid positive integer format");    }    latticeList.push_back(nextDim);  }  candidateElements = myDataArrayElement->getElementsByTagName("Stream",0);  if(candidateElements->length() != 1) {    throw xmdsException(myDataArrayElement,"A <Stream> element expected");  }  const Element* myStreamElement = dynamic_cast<const Element*>(candidateElements->item(0));  // get the Metalink tags  candidateElements = myDataArrayElement->getElementsByTagName("Metalink",1);  if (candidateElements->length() != 1) {    throw xmdsException(myDataArrayElement,"<Metalink> element expected");  }  // get the Format attribute  elementAttributes = candidateElements->item(0)->attributes();  attributeNode = elementAttributes->getNamedItem("Format");  if(attributeNode != 0) {    if(*attributeNode->nodeValue() != "Text" && *attributeNode->nodeValue() != "Binary") {      sprintf(errorMessage(),"Unknown <Metalink> attribute '%s'",attributeNode->nodeValue()->c_str());      throw xmdsException(yourElement,errorMessage());    }  }  else {    throw xmdsException(candidateElements->item(0),"Where is my Format='...' attribute?");  }  //  determine the stream format and work out where the data is  streamFormat = *attributeNode->nodeValue();  if(streamFormat == "Text") {    // ok then, the data is ascii, go get it tiger!    data = *myStreamElement->textContent(0);  }  else if (streamFormat == "Binary") {    // data is binary, the textContent of the Stream element is the datafile filename    binDatFname = *myStreamElement->textContent(0);    // try to remove whitespace chars    std::string tmp = binDatFname.c_str();    std::string tmp2;    for (unsigned long int i=0; i<tmp.length(); i++) {      if (!isspace(tmp[i])) {	tmp2 += tmp[i];      }    }    // biff the temporary variable into the binary data filename    binDatFname = tmp2.c_str();        // need to check what encoding the data is in    // is it big or little endian??    attributeNode = elementAttributes->getNamedItem("Encoding");    if (attributeNode != 0) {      if (*attributeNode->nodeValue() != "LittleEndian" && *attributeNode->nodeValue() != "BigEndian") {	sprintf(errorMessage(),"Unknown <Metalink> attribute '%s'", attributeNode->nodeValue()->c_str());	throw xmdsException(yourElement,errorMessage());      }    }    else {      throw xmdsException(candidateElements->item(0),"Where is my Encoding='...' attribute?");    }    // the binary encoding of the data file    binEncoding = *attributeNode->nodeValue();    // get the precision attribute    elementAttributes = candidateElements->item(0)->attributes();        attributeNode = elementAttributes->getNamedItem("precision");        if(attributeNode != 0) {      if(*attributeNode->nodeValue() != "single" && *attributeNode->nodeValue() != "double") {	sprintf(errorMessage(),"Unknown <Metalink> attribute '%s'",attributeNode->nodeValue()->c_str());	throw xmdsException(yourElement,errorMessage());      }    }    else {      throw xmdsException(candidateElements->item(0),"Where is my precison='...' attribute?");    }    // the precison of the binary data    binPrecision = *attributeNode->nodeValue();  }};// ******************************************************************************void xsilField::writeAsFormat(			      FILE *const outfile,			      const outputFormatEnum& format,			      const long& iD,			      const char *datFileNameBase) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -