/[escript]/trunk/tools/escriptconvert/escriptconvert.cpp
ViewVC logotype

Diff of /trunk/tools/escriptconvert/escriptconvert.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2929 by caltinay, Wed Feb 3 03:22:31 2010 UTC revision 2930 by caltinay, Mon Feb 8 06:25:43 2010 UTC
# Line 43  string insertTimestep(const string& fStr Line 43  string insertTimestep(const string& fStr
43      return s;      return s;
44  }  }
45    
46    int usage()
47    {
48    #if USE_SILO
49        cerr << "Usage: escriptconvert {-vtk|-silo} <file.esd>" << endl;
50    #else
51        cerr << "Note: escriptconvert was compiled without Silo support!" << endl;
52        cerr << "Usage: escriptconvert [-vtk] <file.esd>" << endl;
53    #endif
54        fflush(stderr);
55        return -1;
56    }
57    
58  int main(int argc, char** argv)  int main(int argc, char** argv)
59  {  {
60  #if HAVE_MPI  #if HAVE_MPI
61      MPI_Init(&argc, &argv);      MPI_Init(&argc, &argv);
62  #endif  #endif
63    
 #if USE_SILO  
64      // turn off for debugging purposes      // turn off for debugging purposes
65      bool writeMultiMesh = true;      bool writeMultiMesh = true;
66    
67      // whether time-varying datasets should use the same mesh (from T=0)      // whether time-varying datasets should use the same mesh (from T=0)
68      // TODO: Add a command line option for this      // TODO: Add a command line option for this
69      bool writeMeshOnce = true;      bool writeMeshOnce = true;
70        bool doVTK = false, doSilo = false;
71        string esdFile;
72    
73      if (argc < 2) {  #if USE_SILO
74          cerr << "Usage: " << argv[0] << " <file.esd>" << endl; fflush(stderr);      if (argc != 3)
75          return -1;          return usage();
     }  
76    
77      string esdFile(argv[1]);      if (!strcmp(argv[1], "-vtk")) {
78            doVTK = true;
79        } else if (!strcmp(argv[1], "-silo")) {
80            doSilo = true;
81        } else {
82            return usage();
83        }
84        esdFile = string(argv[2]);
85        
86    #else // !USE_SILO
87        if (argc == 2) {
88            esdFile = string(argv[1]);
89        } else if (argc == 3) {
90            if (strcmp(argv[1], "-vtk"))
91                return usage();
92            esdFile = string(argv[2]);
93        } else {
94            return usage();
95        }
96        doVTK = true;
97    #endif
98    
99      ifstream in(esdFile.c_str());      ifstream in(esdFile.c_str());
100      if (!in.is_open()) {      if (!in.is_open()) {
# Line 171  int main(int argc, char** argv) Line 203  int main(int argc, char** argv)
203          if (dot != baseName.npos)          if (dot != baseName.npos)
204              baseName.erase(dot, baseName.length()-dot);              baseName.erase(dot, baseName.length()-dot);
205    
206          ostringstream siloFile;          ds->setCycleAndTime(timeStep, (double)timeStep);
207          siloFile << baseName;  
208            ostringstream outFilename;
209            outFilename << baseName;
210          if (nTimesteps > 1)          if (nTimesteps > 1)
211              siloFile << "." << timeStep;              outFilename << "." << timeStep;
212          siloFile << ".silo";          if (doSilo) {
213                outFilename << ".silo";
214                ds->saveSilo(outFilename.str(), writeMultiMesh);
215            } else {
216                outFilename << ".vtu";
217                ds->saveVTK(outFilename.str());
218            }
219    
         ds->setCycleAndTime(timeStep, (double)timeStep);  
         ds->saveSilo(siloFile.str(), writeMultiMesh);  
220    
221          // keep mesh from first timestep if it should be reused          // keep mesh from first timestep if it should be reused
222          if (writeMeshOnce && nTimesteps > 1 && timeStep == 0) {          if (writeMeshOnce && nTimesteps > 1 && timeStep == 0) {
223              meshFromTzero = ds->extractMesh();              meshFromTzero = ds->extractMesh();
224              meshFile = siloFile.str();              meshFile = outFilename.str();
225              MeshBlocks::iterator meshIt;              MeshBlocks::iterator meshIt;
226              for (meshIt = meshFromTzero.begin(); meshIt != meshFromTzero.end();              if (doSilo) {
227                      meshIt++)                  for (meshIt = meshFromTzero.begin();
228              {                          meshIt != meshFromTzero.end();
229                  // Prepend Silo mesh paths with the filename of the mesh to be                          meshIt++)
230                  // used                  {
231                  string fullSiloPath = meshFile + string(":");                      // Prepend Silo mesh paths with the filename of the mesh
232                  fullSiloPath += (*meshIt)->getSiloPath();                      // to be used
233                  (*meshIt)->setSiloPath(fullSiloPath);                      string fullSiloPath = meshFile + string(":");
234                        fullSiloPath += (*meshIt)->getSiloPath();
235                        (*meshIt)->setSiloPath(fullSiloPath);
236                    }
237              }              }
238          }          }
239    
# Line 203  int main(int argc, char** argv) Line 244  int main(int argc, char** argv)
244      MeshBlocks::iterator meshIt;      MeshBlocks::iterator meshIt;
245    
246      cout << "All done." << endl;      cout << "All done." << endl;
 #else // !USE_SILO  
     cerr << "Error: escriptconvert was compiled without Silo support! Exiting."  
         << endl;  
 #endif  
247    
248  #if HAVE_MPI  #if HAVE_MPI
249      MPI_Finalize();      MPI_Finalize();

Legend:
Removed from v.2929  
changed lines
  Added in v.2930

  ViewVC Help
Powered by ViewVC 1.1.26