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

📄 main.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 3 页
字号:
/*  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: main.cc,v 1.40 2004/10/25 06:02:53 joehope Exp $*//*!  @mainpage Documentation for xmds-1.4-1  @author Paul Cochrane  @section intro Introduction  xmds is the eXtensible Multi-Dimensional Simulator.  XMDS is a code generator that integrates equations. You write them  down in human readable form in a XML file, and it goes away and  writes and compiles a C++ program that integrates those equations as  fast as it can possibly be done in your architecture.  Originally written by Greg Collecutt (and the majority of the code base is still  due to him), however is now maintained by Paul Cochrane.  @section install Installation  Download the source tarball from http://www.xmds.org, unpack, and run the configure script in  the xmds directory.<br>  (as root, to be installed into /usr/local/bin)<br>  ./configure<br>  (as a user, to be installed the bin/ directory in your home directory)<br>  ./configure --with-user<br>  For more details you can also read the INSTALL file, and even the hand-written  documentation.*//*!   @file main.cc  @brief The main routine and supporting routines  More detailed explanation...*/// This is the main entry routine for xmds#include<config.h>#include<xmlbasics.h>#include<dom3.h>#include<kissdom.h>#include<xmlparser.h>#include<xmdsutils.h>#include<xmdsclasses.h>#include<string>#include<cstdio>#include<cstdlib>#include<iostream>#include<fstream>#include<vector>#include<getopt_xmds.h>using namespace std;// *********************************************************************//! Displays xmds usagevoid display_usage() {  printf("\n");  printf("This is xmds version ");  printf(VERSION);  printf(" release ");  printf(RELEASE);  printf("\n");  printf("\n");  printf("      using C compiler ");  printf(XMDS_CC);  printf("\n");  if(strcmp(MPICC,"")) {    printf("    (and C compiler %s\n",MPICC);    printf(" for parallel work)\n");  }  printf(         "\n"         "Usage: xmds [options] infile\n"	 "Options:\n"         "  infile:         required,  The input file\n"	 "  -h/--help:      optional,  Display this information\n"         "  -v/--verbose:   optional,  Verbose mode\n"         "  -n/--nocompile: optional,  Turns off automatic compilation of simulation\n"         "  -t/--template:  optional,  Outputs an xmds template either to the terminal,\n"         "                               or to an optionally specified file\n"         "\n"	 "For further help, please see http://www.xmds.org\n"         );}// ********************************************************************/*!   @brief Routine to parse the preferences file  @param fPrefs         The input preferences file stream  @param cc             The string representing the C/C++ compiler  @param cflags         The C/C++ compiler flags  @param clibs          The libraries and library directories for the C/C++ compiler  @param cincludes      The include files and directories for the C/C++ compiler  @param cthreadlibs    The threading libraries for the C/C++ compiler  @param mpicc          The C/C++ compiler for MPI (i.e. parallel) simulations  @param mpicflags      The C/C++ compiler flags for the MPI C/C++ compiler  @param fftwlibs       The libraries for using fftw  @param fftw_mpi_libs  The libraries necessary for using fftw with MPI  @param verbose        Whether or not to print verbose information  @param debug          Whether or not to print debugging information*/int parsePrefs(ifstream &fPrefs,                string &cc, string &cflags, string &clibs, string &cincludes, string &cthreadlibs,                string &mpicc, string &mpicflags,                string &fftwlibs, string &fftw_mpi_libs,                bool verbose, bool debug) {    /*      I've thought of a better way to do this, but first I'll just get this version     going so that the feature is in, and then I'll go back and make it a bit more     elegant.     The idea is to read in each line of the prefs file individually (into a string),     and then process the line.  I'll need to read characters until I find an equals      sign (ignoring spaces as I go), biff that into macroVar and then grab everything     else and put that into macroVarValue.  I could treat the string read in (ie the     line I'm parsing) as a stack and pop characters off it until the equals sign     is found, putting chars into macroVar and then put the rest (without equals sign     into macroVarValue.     Anyway, to be done...     Also, I should make this into a function so that the code is only written the once!  */  // grab the text  char c;  string macroVar, macroVarValue, prefsString;  bool commentCharFlag;  prefsString = "";  while( !fPrefs.eof() ) {    // now we try the next line    macroVar = "";    macroVarValue = "";    commentCharFlag = 0;    // wait until we find the equals sign    while( (c = fPrefs.get()) != '=' && !fPrefs.eof() && !commentCharFlag) {      if (c == ' ') {        if (debug) { cout << "space character before '=' found\n"; }      }      else if (c == '#') {        if (debug) { cout << "comment character found (before '=' found)\n"; }        commentCharFlag = 1;        while ( (c = fPrefs.get()) != '\n' && !fPrefs.eof() ) {          if (debug) {	      cout << "looping until end of line\n"; 	  }           // cout << "c = " << c << "\n";        }        break;      }      else {        macroVar = macroVar + c;      }    }    // now loop until we find the return character    while( !commentCharFlag && (c = fPrefs.get()) != '\n' && !fPrefs.eof()) {      if (c == '#') {        if (debug) { cout << "comment character found\n"; }        commentCharFlag = 1;        while ( (c = fPrefs.get()) != '\n' && !fPrefs.eof() ) {          if (debug) { cout << "looping until end of line\n"; }          // cout << "c = " << c << "\n";        }        break;      }      macroVarValue = macroVarValue + c;    }            // cout << "macroVar = " + macroVar + "\n";    // cout << "macroVarValue = " + macroVarValue + "\n";    // now do some assignments    if (macroVar == "XMDS_CC") {      cc = macroVarValue;      if (verbose) { cout << "cc set to " + macroVarValue + "\n"; }    }    else if (macroVar == "XMDS_CFLAGS") {      cflags = macroVarValue;      if (verbose) { cout << "cflags set to " + macroVarValue + "\n"; }    }    else if (macroVar == "XMDS_LIBS") {      clibs = macroVarValue;      if (verbose) { cout << "clibs set to " + macroVarValue + "\n"; }    }    else if (macroVar == "XMDS_INCLUDES") {      cincludes = macroVarValue;      if (verbose) { cout << "cincludes set to " + macroVarValue + "\n"; }    }    else if (macroVar == "THREADLIBS") {      cthreadlibs = macroVarValue;      if (verbose) { cout << "cthreadlibs set to " + macroVarValue + "\n"; }    }    else if (macroVar == "MPICC") {      mpicc = macroVarValue;      if (verbose) { cout << "mpicc set to " + macroVarValue + "\n"; }    }    else if (macroVar == "MPICCFLAGS") {      mpicflags = macroVarValue;      if (verbose) { cout << "mpicflags set to " + macroVarValue + "\n"; }    }    else if (macroVar == "FFTW_LIBS") {      fftwlibs = macroVarValue;      if (verbose) { cout << "fftwlibs set to " + macroVarValue + "\n"; }    }    else if (macroVar == "FFTW_MPI_LIBS") {      fftw_mpi_libs = macroVarValue;      if (verbose) { cout << "fftw_mpi_libs set to " + macroVarValue + "\n"; }    }  }    return 0;}// ********************************************************************//! Routine to write to either stdout or file a template simulation script/*!  @param outfilename The output filename to sent the template simulation script to*/void outputTemplate(const char* outfilename) {  // this is the template text, at present taken directly from the   // tutorial, tutTemplateStart.tex of the latex documentation  // and relevant characters escaped so that they print out properly  const char* templateText =     "<?xml version=\"1.0\"?>\n"    "<simulation>\n"    "  \n"    "  <name> </name>      <!-- the name of the simulation -->\n"    "  \n"    "  <author> </author>  <!-- the author of the simulation -->\n"    "  <description>\n"    "    <!-- a description of what the simulation is supposed to do -->\n"    "  </description>\n"    "  \n"    "  <!-- Global system parameters and functionality -->\n"    "  <prop_dim> </prop_dim>    <!-- name of main propagation dim -->\n"    "  \n"    "  <stochastic> no </stochastic>  <!-- defaults to no -->\n"    "  <!-- these three tags only necessary when stochastic is yes -->\n"    "  <paths> </paths>               <!-- no. of paths -->\n"    "  <seed> 1 2 </seed>             <!-- seeds for rand no. gen -->\n"    "  <noises> </noises>             <!-- no. of noises -->\n"    "  \n"    "  <use_mpi> no </use_mpi>            <!-- defaults to no -->\n"    "  <error_check> yes </error_check>   <!-- defaults to yes -->\n"    "  <use_wisdom> yes </use_wisdom>     <!-- defaults to no -->\n"    "  <benchmark> yes </benchmark>       <!-- defaults to no -->\n"    "  <use_prefs> yes </use_prefs>       <!-- defaults to yes -->\n"    "  \n"    "  <!-- Global variables for the simulation -->\n"    "  <globals>\n"    "  <![CDATA[\n"    "    \n"    "  ]]>\n"    "  </globals>\n"    "  \n"    "  <!-- Field to be integrated over -->\n"    "  <field>\n"    "    <name> main </name>\n"    "    <dimensions> </dimensions> <!-- transverse dims -->\n"    "    <lattice> </lattice>       <!-- no. of points for each dim -->\n"    "    <domains> (,) </domains>   <!-- domain of each dimension -->\n"    "    <samples> </samples>       <!-- sample 1st point of dim? -->\n"    "    \n"    "    <vector>\n"    "      <name> main </name>\n"    "      <type> complex </type>           <!-- data type of vector -->\n"

⌨️ 快捷键说明

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