From: guido Date: Wed, 4 May 2005 13:02:29 +0000 (+0000) Subject: read and write different formats X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f61e9e98281a7ffa0e287ea74dac2d1be886dcde;p=dealii-svn.git read and write different formats git-svn-id: https://svn.dealii.org/trunk@10646 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/contrib/utilities/Makefile.in b/deal.II/contrib/utilities/Makefile.in index 56dba7e618..8bcfb36e86 100644 --- a/deal.II/contrib/utilities/Makefile.in +++ b/deal.II/contrib/utilities/Makefile.in @@ -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 diff --git a/deal.II/contrib/utilities/gridio.cc b/deal.II/contrib/utilities/gridio.cc index ac3ffa7fb4..54003af87e 100644 --- a/deal.II/contrib/utilities/gridio.cc +++ b/deal.II/contrib/utilities/gridio.cc @@ -16,54 +16,48 @@ using namespace std; +template +void convert(const char* infile, + const char* outfile, + GridOut::OutputFormat oformat) +{ + Triangulation tr; + GridIn 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 " << 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); }