9 int main(
int argc,
char *argv[])
11 bool DeleteFiles =
false;
14 std::cout <<
"Usage: CombinePartitions [DeleteFile] nproc outfile"
16 std::cout <<
" [DeleteFiles] = Delete partiion files (optional)" << std::endl;
17 std::cout <<
" nproc = Number of partitions" << std::endl;
18 std::cout <<
" outfile = Target output filename" << std::endl;
27 TiXmlDocument docOutput;
28 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
29 docOutput.LinkEndChild(decl);
31 TiXmlElement *master =
new TiXmlElement(
"NEKTAR");
32 std::string basename = argv[argc-1];
33 std::string extension = argv[argc-1];
34 basename = basename.substr(0, basename.find_last_of(
"."));
35 extension = extension.substr(extension.find_last_of(
".") + 1);
37 fs::path infile(argv[argc-1]);
38 bool isdirectory = fs::is_directory(infile);
40 for (
int n = 0; n < atoi(argv[argc-2]); ++n)
42 std::stringstream filename;
45 filename << argv[argc-1] <<
"/P" << n <<
".fld";
49 filename << basename <<
"_P" << n <<
"." << extension;
51 TiXmlDocument docInput;
52 if (!docInput.LoadFile(filename.str()))
54 std::cerr <<
"Unable to open file '" << filename.str() <<
"'." << std::endl;
57 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
60 if(n == 0 && nektar->FirstChildElement(
"Metadata"))
62 TiXmlElement *metadata = nektar->FirstChildElement(
"Metadata");
65 master->LinkEndChild(
new TiXmlElement(*metadata));
70 TiXmlElement *elements = nektar->FirstChildElement(
"ELEMENTS");
73 master->LinkEndChild(
new TiXmlElement(*elements));
74 elements = elements->NextSiblingElement();
78 docOutput.LinkEndChild(master);
82 std::string outname = basename +
"_combined" +
"." + extension; ;
83 if (!docOutput.SaveFile(outname))
85 std::cerr <<
"Unable to write file '" << outname <<
"'." << std::endl;
88 else if (!docOutput.SaveFile(argv[argc-1]))
90 std::cerr <<
"Unable to write file '" << argv[argc-1] <<
"'." << std::endl;
97 for (
int n = 0; n < atoi(argv[argc-2]); ++n)
99 std::string basename = argv[argc-1];
100 std::string extension = argv[argc-1];
101 basename = basename.substr(0, basename.find_last_of(
"."));
102 extension = extension.substr(extension.find_last_of(
".") + 1);
103 std::stringstream filename;
104 filename << basename <<
"_P" << n <<
"." << extension;
105 std::string deloutput =
"rm -rf ";
106 deloutput = deloutput + filename.str();
107 system(deloutput.c_str());