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

📄 main.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 3 页
字号:
    "      <components> </components>       <!-- names of components -->\n"    "      <fourier_space> </fourier_space> <!-- defined in k-space? -->\n"    "      <![CDATA[\n"    "        \n"    "      ]]>\n"    "    </vector>\n"    "  </field>\n"    "  \n"    "  <!-- The sequence of integrations to perform -->\n"    "  <sequence>\n"    "    <integrate>\n"    "      <algorithm> </algorithm> <!-- RK4EX, RK4IP, SIEX, SIIP -->\n"    "      <iterations> </iterations> <!-- default=3 for SI- algs -->\n"    "      <interval> </interval>   <!-- how far in main dim? -->\n"    "      <lattice> </lattice>     <!-- no. points in main dim -->\n"    "      <samples> </samples> <!-- no. pts in output moment group -->\n"    "      \n"    "      <k_operators>\n"    "        <constant> yes </constant>         <!-- yes/no -->\n"    "        <operator_names> </operator_names>\n"    "        <![CDATA[\n"    "          \n"    "        ]]>\n"    "      </k_operators>\n"    "      \n"    "      <vectors> </vectors>     <!-- vector names -->\n"    "      <![CDATA[\n"    "        \n"    "      ]]>\n"    "    </integrate>\n"    "  </sequence>\n"    "  \n"    "  <!-- The output to generate -->\n"    "  <output format=\"ascii\" precision=\"single\">\n"    "    <group>\n"    "      <sampling>\n"    "        <fourier_space> </fourier_space> <!-- sample in k-space? -->\n"    "        <lattice> </lattice>           <!-- no. points to sample -->\n"    "        <moments> </moments>           <!-- names of moments -->\n"    "        <![CDATA[\n"    "          \n"    "        ]]>\n"    "      </sampling>\n"    "    </group>\n"    "  </output>\n"    "  \n"    "</simulation>\n";        // check to see if an output file was given  if(outfilename==0) {    // ok, so no input file specified, we therefore spit it out to stdout    printf("%s",templateText);  }  else if (outfilename!=0) {    // ok, we have an input file, open it, biff out the string, close it    // btw, why am I using the old C syntax for this and not C++???    FILE *fp;    fp = fopen(outfilename, "w");    if (fp == NULL) {   	// make sure can actually open the file      printf("Unable to open output file: %s\n",outfilename);      printf("Sending output to stdout\n\n");            printf("%s",templateText);    }    else {       printf("This is xmds, version %s-%s\n", VERSION, RELEASE);      printf("Copyright 2000-2004 Greg Collecutt, Joseph Hope, Paul Cochrane and others\n");      printf("xmds is available from http://www.xmds.org\n\n");      printf("Writing a template to file with filename: %s\n",outfilename);      fprintf(fp, "%s", templateText);      printf("Done!\n");    }    fclose(fp);  }}/* ******************************************************************** */bool debugFlag = 0;                  //!< Print debugging information about xmds processesbool xmlDebugFlag = 0;               //!< Print debugging information about xml parsing processesvector<string> simulationText; //!< The text of the xmds simulation scriptvector<string> simHeaderText;                //!< The text of the xmds script's headervector<string> simBodyText;                  //!< The text of the xmds script's bodyvector<string> simFooterText;                //!< The text of the xmds script's footer/*!   @brief The main routine.  @param argc The number of arguments to the program  @param argv The "vector" of arguments to the program*/int main(         int argc,         char **argv) {  bool verbose = 0;  bool compileFlag = 1;  bool templateGenFlag = 0;  const char* infilename=0;  int resp;  while (1) {    static struct option long_options[] =     {	{"help", no_argument, 0, 'h'},	{"verbose", no_argument, 0, 'v'},	{"debug", no_argument, 0, 'd'},	{"nocompile", no_argument, 0, 'n'},	{"template", optional_argument, 0, 't'},	{"xmldebug", no_argument, 0, 'x'},	{0,0,0,0}    };    int option_index = 0;    resp = getopt_xmds_long(argc, argv, "hvdnxt", long_options, &option_index);    if (resp == -1) {	break;    }    switch (resp) {	case 'h':	    display_usage();	    return 0;	case 'v':	    verbose = 1;	    break;	case 'd':	    debugFlag = 1;	    break;	case 'n':	    compileFlag = 0;	    break;	case 't':	    templateGenFlag = 1;	    break;	case 'x':	    xmlDebugFlag = 1;	    break;	default:	  display_usage();	  return 0;        }  }  // process non-option command line elements  if (optind_xmds < argc) {      int fnameCount = 0;      while (optind_xmds < argc) {	  fnameCount++;	  if (fnameCount > 1) {	      // error, input file name already exists	      printf("Error: multiple input files not allowed\n\n");	      display_usage();	      return 0;	  }          // assign infilename pointer to the appropriate          // member of the argv array          infilename = argv[optind_xmds++];      }  }  // if asked to make a template, then just spit it out, either to file  // or to stdout and then return nicely  if (templateGenFlag) {    // at present, we'll reuse the input file.  I intend to change this to    // use the getopt_xmds stuff later, so will have to do that at some stage.    outputTemplate(infilename);    return 0;  }  // check to see that an input file was given  if(infilename==0) {    // error, no input file was specified    printf("Error: no input file specified!\n\n");    display_usage();    return 0;  }    if(verbose) {    printf("xmds: inputfile = '%s'\n",infilename);  }    // create the XMLParser  XMLParser myXMLParser;  // now load xmds script into the DOMImplementation  Document* theDocument=0;  if(verbose) {    printf("Parsing file '%s' ...\n",infilename);  }  try {    theDocument=myXMLParser.parseFromFile(infilename);    // now load the xmds file into memory for later use    // I tried doing this in vanilla C++, but couldn't    // it looks like it'll have to be in C for the most part    FILE *fin;    if ((fin = fopen(infilename,"r")) == NULL) {      printf("Can't open the input xmds script file: %s\n"	     "Exiting\n"	     ,infilename);      return 1;  // and barf    }    // now grab the file one line at a time    unsigned char temp;    string tempString = "";    while (!feof(fin)) {      temp = fgetc(fin);      if (temp != '\n') {	tempString += temp;      }      else {	simulationText.push_back(tempString);	tempString = "";      }    }    fclose(fin);    if (debugFlag) {      for (unsigned int i=0; i<simulationText.size(); i++) {	cout << simulationText[i] << "\n";      }    }    // now we need to replace all occurrences of " with \"    for (unsigned int i=0; i<simulationText.size(); i++) {      string simulationLine = simulationText[i];      unsigned int lineLen = simulationLine.size();      for (unsigned int j=0; j<lineLen; j++) {	if (simulationLine[j] == '\"') {	  if (debugFlag) {	    printf("Replaced a double quote at location %d, lineLen = %d\n",j,lineLen);	    printf("Line is:\n%s\n",simulationLine.c_str());	  }	  size_t textPos = j;	  simulationLine.replace(textPos, 1, "\\\"", 2);	  j++;	  lineLen++;  // because the line length increases as we add more characters	}      }      // I could check to make sure that simulationLine was altered, but      // I can't be bothered, and it should be pretty quick anyway      simulationText[i] = simulationLine;      }    // now we need to tear the text to bits a little    // first, grab the test up until we have a <simulation> tag    // then, go from the back, dropping anything that isn't a > symbol,    // keep that, and then try and get a </simulation> tag.    // the header, (ie the <?xml version="1.0"?> (plus possibly more text)    // and then the <simulation> tag), the body (the rest of the simulationText    // up until the footer, which is just the </simulation> tag.    // This ripping to bits is necessary so that we can piece together the     // simulation script with the xsil output at the end of the simulation    // without relying on system() calls.        // search for the text "<simulation>"    // barf if we get to the end of the file, and still haven't found it.    string simulationStartTag = "<simulation>";    string simulationEndTag = "</simulation>";        bool foundSimStartTag = false, foundSimEndTag = false;    // go through the text and rip out the header, body and footer    for (unsigned int i=0; i<simulationText.size(); i++) {      if (simulationText[i].find(simulationStartTag) != string::npos) {	foundSimStartTag = true;	if (verbose) {	  printf("Found the <simulation> start tag when pulling to bits!\n");	}      }      if (simulationText[i].find(simulationEndTag) != string::npos) {	foundSimEndTag = true;	if (verbose) {	  printf("Found the </simulation> end tag when pulling to bits!\n");	}      }      if (!foundSimStartTag && !foundSimEndTag) {	simHeaderText.push_back(simulationText[i]);      }      if (foundSimStartTag && !foundSimEndTag) {	simBodyText.push_back(simulationText[i]);      }      if (foundSimStartTag && foundSimEndTag) {	simFooterText.push_back(simulationText[i]);      }    }    // if we got to here and foundSimStart tag is still false, then barf appropriately    if (!foundSimStartTag) {      printf("Failed to find the string \"<simulation>\" within the simulation text\n");      printf("Exiting\n");      // I'm sure we should do something more intelligent here...      return 1;    }    if (debugFlag) {      // have a look at the header if it exists

⌨️ 快捷键说明

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