CombinePartitions.cpp 2.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdlib>
#include <iostream>
#include <sstream>

#include <tinyxml/tinyxml.h>

int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        std::cout << "Usage: CombinePartitions [nproc] [outfile]"
                  << std::endl;
        std::cout << "  [nproc]            = Number of partitions" << std::endl;
        std::cout << "  [outfile]          = Target output filename" << std::endl;
        exit(1);
    }

    TiXmlDocument docOutput;
    TiXmlDeclaration * decl = new TiXmlDeclaration("1.0", "utf-8", "");
    docOutput.LinkEndChild(decl);

    TiXmlElement *master = new TiXmlElement("NEKTAR");
    for (int n = 0; n < atoi(argv[1]); ++n)
    {
25
26
27
28
        std::string basename = argv[2];
        std::string extension = argv[2];
        basename = basename.substr(0, basename.find_last_of("."));
        extension = extension.substr(extension.find_last_of(".") + 1);
29
        std::stringstream filename;
30
        filename << basename << "_P" << n << "." << extension;
31
32
33
34
35
36
37
        TiXmlDocument docInput;
        if (!docInput.LoadFile(filename.str()))
        {
            std::cerr << "Unable to open file '" << filename.str() << "'." << std::endl;
            exit(1);
        }
        TiXmlElement *nektar = docInput.FirstChildElement("NEKTAR");
38
39
        
        // load up root processor's meta data
40
        if(n == 0 && nektar->FirstChildElement("Metadata"))
41
        {
42
            TiXmlElement *metadata = nektar->FirstChildElement("Metadata");
Spencer Sherwin's avatar
... ?    
Spencer Sherwin committed
43
44
45
46
            if(metadata)
            {
                master->LinkEndChild(new TiXmlElement(*metadata));
            }
47
48
49
        }

        // load the elements from seperate files. 
50
        TiXmlElement *elements = nektar->FirstChildElement("ELEMENTS");
51
52
53
54
55
56
        while (elements)
        {
            master->LinkEndChild(new TiXmlElement(*elements));
            elements = elements->NextSiblingElement();
        }
    }
57
    
58
59
60
61
62
63
64
65
    docOutput.LinkEndChild(master);
    if (!docOutput.SaveFile(argv[2]))
    {
        std::cerr << "Unable to write file '" << argv[1] << "'." << std::endl;
    }

    exit(0);
}