-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbinary_decoder.cpp
106 lines (85 loc) · 3.18 KB
/
binary_decoder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "binary_decoder.h"
#include "grid_file_decoder.h"
#include "phasespace_file_decoder.h"
// test1: binary_decoder.exe H1pout09 -histogram x 30 35 100 -densityplot x 30 35 100 E 0 30 300 -dump_ppg -dump_csv -dump_clean -dump_xyzE
// test2: binary_decoder.exe H1dnout09 -dump_lineoutx -dump_gnuplot -dump_vtk -dump_vtk_nostretch
int main(const int argc, const char *argv[])
{
Parameters params;
std::string bin_filename, dat_filename, json_filename;
std::ifstream bin_file, dat_file, json_file;
std::cout << "ALaDyn binary decoder v" << MAJOR_RELEASE << "." << MINOR_RELEASE << "." << BUGFIX_RELEASE << std::endl;
if (argc > 1)
{
if (!(strcmp(argv[1], "-help") && strcmp(argv[1], "-h") && strcmp(argv[1], "/help") && strcmp(argv[1], "/h")))
{
params.man(argv[0]);
exit(-1);
}
}
if (argc == 1)
{
std::cout << "File basename (without extension): ";
std::cin >> params.filebasename;
}
else params.filebasename = std::string(argv[1]);
bin_filename = params.filebasename + ".bin";
dat_filename = params.filebasename + ".dat";
json_filename = params.filebasename + ".json";
bin_file.open(bin_filename, std::ios::binary | std::ios::in);
if (bin_file.fail())
{
bin_filename.clear();
bin_filename = params.filebasename + "_000.bin";
bin_file.open(bin_filename, std::ios::binary | std::ios::in);
if (bin_file.fail())
{
std::cerr << "Input file not found" << std::endl;
exit(-2);
}
else params.multifile = true;
}
else params.multifile = false;
if (params.multifile) std::cout << "Input files are " << params.filebasename << "_???.bin" << std::endl;
else std::cout << "Input file is " << params.filebasename << ".bin" << std::endl;
params.check_filename(params.filebasename.c_str());
bin_file.close();
params.check_forced_version(argc, argv);
dat_file.open(dat_filename);
if (dat_file.fail())
{
std::cerr << "Unable to find " << params.filebasename << ".dat, using routines for aladyn v1" << std::endl;
params.file_version = 1;
if (params.we_dont_know_if_we_have_to_do_swap) {
std::cerr << "Unable to determine if swap is required, please add command line flag" << std::endl;
exit(-3);
}
params.read_params_from_bin_file(params.filebasename.c_str());
if (params.we_dont_know_if_sim_is_2d) {
std::cerr << "Unable to determine if sim is 2D or not, please add command line flag" << std::endl;
exit(-4);
}
}
else
{
std::cout << "Found " << params.filebasename << ".dat" << std::endl;
params.read_params_from_dat_file(dat_file);
}
dat_file.close();
params.check_swap();
params.parse_command_line();
json_file.open(json_filename);
if (json_file.fail()) {
if (params.grid_file) create_json_from_grid_file(¶ms);
else if (params.phasespace_file) create_json_from_phasespace_file(¶ms);
}
else json_file.close();
params.parse_json();
if (params.grid_file) read_grid_file(¶ms);
else if (params.phasespace_file) read_phasespace_file(¶ms);
else {
std::cerr << "Unknown file name, I don't know what to do with it! Rename it or change tool!" << std::endl;
exit(-5);
}
return 0;
}