]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
read and write different formats
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 4 May 2005 13:02:29 +0000 (13:02 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 4 May 2005 13:02:29 +0000 (13:02 +0000)
git-svn-id: https://svn.dealii.org/trunk@10646 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/contrib/utilities/Makefile.in
deal.II/contrib/utilities/gridio.cc

index 56dba7e6180dad73ccd464210ca974c62a0443f8..8bcfb36e866923f4f137508b9277a829ef8fe0f5 100644 (file)
@@ -1,6 +1,6 @@
 ############################################################
 # $Id$
-# Copyright (C) 2000, 2001, 2002, 2003 by the deal.II authors
+# Copyright (C) 2000, 2001, 2002, 2003, 2005 by the deal.II authors
 ############################################################
 
 ############################################################
@@ -38,7 +38,7 @@ endif
        @$(CXX) $(CXXFLAGS.o) -c $< -o $@
 %.exe : %.$o
        @echo =====linking======= $@
-       @$(CXX) $(LDFLAGS) -o $@ $^
+       @$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 
 default: gridio.exe embedding.exe interpolation.exe
index ac3ffa7fb47513f7274fc54606e3189c3efa248a..54003af87e11c2069882aab6327e9416bb74ffb4 100644 (file)
 
 using namespace std;
 
+template <int dim>
+void convert(const char* infile,
+            const char* outfile,
+            GridOut::OutputFormat oformat)
+{
+  Triangulation<dim> tr;
+  GridIn<dim> gin;
+  gin.attach_triangulation(tr);
+  gin.read(infile);
+
+  GridOut gout;
+  ofstream out(outfile);
+  gout.write(tr, out, oformat);
+}
+
+
 int main(int argc, char** argv)
 {
-  if (argc<2)
+  if (argc<4)
     {
       cerr << "Usage: " << argv[0]
-          << " -i informat -o outformat <filename>" << endl;
+          << " dim infile outfile" << endl;
       exit(1);
     }
 
-  GridOut::OutputFormat oformat;
-  int c;
-  const char* optstring="i:o:";
-  while((c=getopt(argc, argv, optstring)) != -1)
-  {
-      switch (c)
-      {
-         case 'i':
-             break;
-         case 'o':
-             oformat = GridOut::parse_output_format(optarg);
-             break;
-      }
-  }
-  string iname =argv[optind];
-//  if (iname.find_last_of('.') <= 0)
-//    iname.append(".inp");
+  const unsigned int d = atoi(argv[1]);
   
-  GridOutFlags::XFig xfig_flags;
-  xfig_flags.level_depth = false;
-
-  Triangulation<2> tr;
-
-   ifstream in (iname.c_str());
-   AssertThrow(in, ExcFileNotOpen(argv[1]));
-
-   GridIn<2> gin;
-   gin.attach_triangulation(tr);
-   gin.read_ucd(in);
-
-   GridOut gout;
-   gout.set_flags(xfig_flags);
-   
-   string oname(iname, 0, iname.find_last_of('.'));  
-   oname.append(GridOut::default_suffix(oformat));
-   cout << iname << " -> " << oname << endl;
-   ofstream out(oname.c_str());
+  std::string outstring(argv[3]);
+  GridOut::OutputFormat oformat = GridOut::eps;
+  
+  const unsigned int dotpos = outstring.find_last_of('.');
+  if (dotpos < outstring.length())
+    {
+      std::string ext = outstring.substr(dotpos+1);
+      if (ext == "inp")
+       ext = "ucd";
+      
+      oformat = GridOut::parse_output_format(ext);
+    }
 
-   gout.write(tr, out, oformat);
-   
-//  GridOut
+  if (d == 2)
+    convert<2>(argv[2], argv[3], oformat);
+  else if (d == 3)
+    convert<3>(argv[2], argv[3], oformat);
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.