source: GenericIORewrite.cxx @ fc4fc2f

Revision fc4fc2f, 1.8 KB checked in by Hal Finkel <hfinkel@…>, 8 years ago (diff)

add a GIO rewriter (to compress files, etc.)

  • Property mode set to 100644
Line 
1#include <cstdlib>
2#include <iostream>
3#include <iomanip>
4#include <string>
5#include <algorithm>
6#include <limits>
7#include <stdexcept>
8#include <stdint.h>
9
10#include "GenericIO.h"
11
12using namespace gio;
13using namespace std;
14
15int main(int argc, char *argv[]) {
16  MPI_Init(&argc, &argv);
17
18  if (argc < 2) {
19    cerr << "Usage: " << argv[0] << " <mpiioOld> <mpiioNew>" << endl;
20    exit(-1);
21  }
22
23  GenericIO::setNaturalDefaultPartition();
24  GenericIO::setDefaultShouldCompress(true);
25
26  {
27    int arg = 1;
28    int Rank, NRanks;
29    MPI_Comm_rank(MPI_COMM_WORLD, &Rank);
30    MPI_Comm_size(MPI_COMM_WORLD, &NRanks);
31
32    string FileName(argv[arg++]);
33    string NewFileName(argv[arg++]);
34
35    unsigned Method = GenericIO::FileIOPOSIX;
36    const char *EnvStr = getenv("GENERICIO_USE_MPIIO");
37    if (EnvStr && string(EnvStr) == "1")
38      Method = GenericIO::FileIOMPI;
39
40    GenericIO GIO(MPI_COMM_WORLD, FileName, Method);
41    GIO.openAndReadHeader(GenericIO::MismatchDisallowed);
42
43    vector<GenericIO::VariableInfo> VI;
44    GIO.getVariableInfo(VI);
45
46    size_t NElem = GIO.readNumElems();
47
48    double PhysOrigin[3], PhysScale[3];
49    GIO.readPhysOrigin(PhysOrigin);
50    GIO.readPhysScale(PhysScale);
51
52    vector< vector<char> > Vars(VI.size());
53    for (size_t i = 0; i < VI.size(); ++i) {
54      Vars[i].resize(VI[i].Size*NElem + GIO.requestedExtraSpace());
55      GIO.addVariable(VI[i], &Vars[i][0], GenericIO::VarHasExtraSpace);
56    }
57
58    GIO.readData(-1, false);
59
60    GenericIO NewGIO(MPI_COMM_WORLD, NewFileName);
61    NewGIO.setNumElems(NElem);
62
63    for (int d = 0; d < 3; ++d) {
64      NewGIO.setPhysOrigin(PhysOrigin[d], d);
65      NewGIO.setPhysScale(PhysScale[d], d);
66    }
67
68    for (size_t i = 0; i < VI.size(); ++i)
69      NewGIO.addVariable(VI[i], &Vars[i][0], GenericIO::VarHasExtraSpace);
70
71    NewGIO.write();
72  }
73
74  MPI_Barrier(MPI_COMM_WORLD);
75  MPI_Finalize();
76
77  return 0;
78}
79
Note: See TracBrowser for help on using the repository browser.