-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.cpp
82 lines (70 loc) · 2.21 KB
/
main.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
#include <iostream>
#include <regex>
#include <string>
#include <hdf5.h>
#include "config.h"
#include "domain.h"
#include "parse_cmd_line.h"
void construct_domain( std::string config_or_h5_file,
Domain **dom,
bool *continue_from_h5 );
void extract_filename_prefix_and_suffix_from_h5filename( std::string h5_file,
std::string *prefix,
std::string *suffix );
int main( int argc, char *argv[] )
{
std::string config_or_h5_file;
parse_cmd_line( argc, argv, config_or_h5_file );
bool continue_from_h5 = false;
Domain *dom = NULL;
construct_domain( config_or_h5_file, &dom, &continue_from_h5 );
if( continue_from_h5 ){
dom->continue_pic_simulation();
} else {
dom->start_pic_simulation();
}
// finalize_whatever_left
delete dom;
return 0;
}
void construct_domain( std::string config_or_h5_file,
Domain **dom,
bool *continue_from_h5 )
{
std::string extension =
config_or_h5_file.substr( config_or_h5_file.find_last_of(".") + 1 );
if ( extension == "h5" ){
hid_t h5file_id = H5Fopen( config_or_h5_file.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
if( h5file_id < 0 ){
std::cout << "Can't open file: " << config_or_h5_file << std::endl;
exit( EXIT_FAILURE );
}
std::string filename_prefix, filename_suffix;
extract_filename_prefix_and_suffix_from_h5filename( config_or_h5_file,
&filename_prefix,
&filename_suffix );
*dom = new Domain( h5file_id );
(*dom)->set_output_filename_prefix_and_suffix( filename_prefix, filename_suffix );
*continue_from_h5 = true;
} else {
Config conf( config_or_h5_file );
conf.print();
*dom = new Domain( conf );
}
}
void extract_filename_prefix_and_suffix_from_h5filename( std::string h5_file,
std::string *prefix,
std::string *suffix )
{
std::regex rgx("[0-9]{7}");
std::smatch match;
std::regex_search( h5_file, match, rgx );
if( match.size() == 1 ){
*prefix = h5_file.substr( 0, match.position(0) );
*suffix = h5_file.substr( match.position(0) + 7 );
} else {
std::cout << "Can't identify filename prefix and suffix in " << h5_file << std::endl;
std::cout << "Aborting." << std::endl;
exit( EXIT_FAILURE );
}
}