SPH
Info.cpp
Go to the documentation of this file.
1 
3 #include "Sph.h"
4 #include "io/Table.h"
5 
6 using namespace Sph;
7 
8 int printBinaryFileInfo(ILogger& logger, const Path& path) {
9  BinaryInput input;
10  Expected<BinaryInput::Info> info = input.getInfo(path);
11  if (!info) {
12  logger.write("Cannot obtain file info from '", path.native(), "'");
13  return -1;
14  }
15 
16  Size row = 0;
17  Table table(3);
18  table.setCell(0, row, "File name:");
19  table.setCell(1, row, path.fileName().native());
20  ++row;
21  table.setCell(0, row, "File version:");
22  table.setCell(1, row, std::to_string(int(info->version)));
23  ++row;
24  table.setCell(0, row, "Particle count:");
25  table.setCell(1, row, std::to_string(info->particleCnt));
26  ++row;
27  table.setCell(0, row, "Material count:");
28  table.setCell(1, row, std::to_string(info->materialCnt));
29  ++row;
30  table.setCell(0, row, "Quantity count:");
31  table.setCell(1, row, std::to_string(info->quantityCnt));
32  ++row;
33  table.setCell(0, row, "Run time:");
34  table.setCell(1, row, std::to_string(info->runTime));
35  ++row;
36  table.setCell(0, row, "Time step:");
37  table.setCell(1, row, std::to_string(info->timeStep));
38  ++row;
39  table.setCell(0, row, "Wallclock time:");
40  table.setCell(1, row, getFormattedTime(info->wallclockTime));
41  ++row;
42  table.setCell(0, row, "Run type:");
43  if (info->runType) {
44  table.setCell(1, row, EnumMap::toString<RunTypeEnum>(info->runType.value()));
45  } else {
46  table.setCell(1, row, "unknown");
47  }
48  ++row;
49  table.setCell(0, row, "Build date:");
50  if (info->buildDate) {
51  table.setCell(1, row, info->buildDate.value());
52  } else {
53  table.setCell(1, row, "unknown");
54  }
55  ++row;
56  logger.write(table.toString());
57  return 0;
58 }
59 
60 int printCompressedFileInfo(ILogger& logger, const Path& path) {
61  CompressedInput input;
62  Expected<CompressedInput::Info> info = input.getInfo(path);
63  if (!info) {
64  logger.write("Cannot obtain file info from '", path.native(), "'");
65  return -1;
66  }
67 
68  Size row = 0;
69  Table table(3);
70  table.setCell(0, row, "File name:");
71  table.setCell(1, row, path.fileName().native());
72  ++row;
73  table.setCell(0, row, "File version:");
74  table.setCell(1, row, std::to_string(int(info->version)));
75  ++row;
76  table.setCell(0, row, "Particle count:");
77  table.setCell(1, row, std::to_string(info->particleCnt));
78  ++row;
79  table.setCell(0, row, "Run time:");
80  table.setCell(1, row, std::to_string(info->runTime));
81  ++row;
82  table.setCell(0, row, "Run type:");
83  table.setCell(1, row, EnumMap::toString<RunTypeEnum>(info->runType));
84  logger.write(table.toString());
85  return 0;
86 }
87 
88 int main(int argc, char* argv[]) {
89  StdOutLogger logger;
90  if (argc != 2 || argv[1] == std::string("--help")) {
91  logger.write("Usage: opensph-info file");
92  return 0;
93  }
94 
95  const Optional<IoEnum> type = getIoEnum(Path(argv[1]).extension().native());
96  switch (type.valueOr(IoEnum::NONE)) {
98  return printBinaryFileInfo(logger, Path(argv[1]));
100  return printCompressedFileInfo(logger, Path(argv[1]));
101  default:
102  logger.write("Unknown file format.");
103  return -1;
104  }
105 }
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
int main(int argc, char *argv[])
Definition: Info.cpp:88
int printBinaryFileInfo(ILogger &logger, const Path &path)
Definition: Info.cpp:8
int printCompressedFileInfo(ILogger &logger, const Path &path)
Definition: Info.cpp:60
Includes common headers.
String getFormattedTime(const String &format)
Utility functions.
Definition: String.cpp:128
Helper container allowing to store strings in cells and print them into table.
Input for the binary file, generated by BinaryOutput.
Definition: Output.h:352
Expected< Info > getInfo(const Path &path) const
Opens the file and reads header info without reading the rest of the file.
Definition: Output.cpp:814
Expected< Info > getInfo(const Path &path) const
Definition: Output.cpp:1030
Wrapper of type that either contains a value of given type, or an error message.
Definition: Expected.h:25
Type & value()
Returns the reference to expected value.
Definition: Expected.h:69
Interface providing generic (text, human readable) output of the program.
Definition: Logger.h:22
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
Definition: Logger.h:37
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
INLINE Type valueOr(const TOther &other) const
Returns the stored value if the object has been initialized, otherwise returns provided parameter.
Definition: Optional.h:188
Object representing a path on a filesystem.
Definition: Path.h:17
std::string native() const
Returns the native version of the path.
Definition: Path.cpp:71
Path fileName() const
Returns the filename of the path.
Definition: Path.cpp:47
Standard output logger.
Definition: Logger.h:138
Definition: Table.h:12
std::string toString() const
Creates the text representation of the table.
Definition: Table.h:58
void setCell(const Size colIdx, const Size rowIdx, std::string text)
Sets the text in given cell.
Definition: Table.h:35
Optional< IoEnum > getIoEnum(const std::string &ext)
Returns the file type from file extension.
Definition: Settings.cpp:367
@ BINARY_FILE
@ NONE
No input/output.
@ COMPRESSED_FILE
Definition: MemoryPool.h:5