StatMech
Loading...
Searching...
No Matches
SrednickiAnsatz.cpp File Reference

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
16 {
17 if(argc != 4) {
18 std::cerr << "Usage: 1.This 2.Directory 3.Nmin 4.Nmax" << std::endl;
19 std::exit(EX_USAGE);
20 }
21 std::string const InputDir( std::string(argv[1])+"/ProcessedData");
22 int const Nmin = std::atoi(argv[2]);
23 int const Nmax = std::atoi(argv[3]);
24
25 std::vector<std::string> dirList;
26 {
27 std::string str;
28 int dataNo;
29 for(const std::filesystem::directory_entry &entry : std::filesystem::directory_iterator(InputDir)) {
30 if ( entry.is_directory() ) {
31 str = entry.path().string();
32 dataNo = std::atoi(str.substr(str.find("_No")+3).c_str());
33 debug_print("# dir=" << str << ", dataNo=" << dataNo);
34 if(dataNo>= dirList.size()) dirList.resize(dataNo+1);
35 dirList.at(dataNo) = str;
36 }
37 }
38 }
39 // #pragma omp parallel for schedule(dynamic, 10)
40 // for(size_t sample = 0;sample < dirList.size(); ++sample) {
41 //
42 // #pragma omp critical
43 // std::cout << "# Dir: " << dirList[sample] << std::endl;
44 //
45 // }
46 #pragma omp parallel for schedule(dynamic, 10)
47 for(size_t sample = 0;sample < dirList.size(); ++sample) {
48 #pragma omp critical
49 std::cout << "# Dir(" << sample << "): " << dirList[sample] << std::endl;
50
51 std::filesystem::create_directories(std::regex_replace(dirList[sample], std::regex("/LocalRandomMatrix"), "/LocalRandomMatrix/test"));
52 int Ndata, itemp;
53 double Energy, Stddev, dtemp;
54 std::ifstream InFile;
55 for(int n = Nmin;n <= Nmax; ++n) {
56 std::stringstream ss("");
57 ss << "/SrednickiAnsatz_Diagonal_N" << n << ".txt";
58 std::string InFileName(dirList[sample] + ss.str());
59 if( InFile.is_open() ) { InFile.close(); InFile.clear(); }
60 InFile.open(InFileName);
61 if( !InFile.is_open() ) {
62 std::cerr << "Error: Can't open file " << InFileName << std::endl;
63 continue;
64 }
65 std::string OutFName(std::regex_replace(InFileName, std::regex("/LocalRandomMatrix"), "/LocalRandomMatrix/test"));
66 std::ofstream OutFile(OutFName); checkIsFileOpen(OutFile, OutFName);
67 std::string str;
68 OutFile << std::scientific;
69 for(getline(InFile, str); !InFile.eof(); getline(InFile, str)) {
70 if( str[0] == '#' || str[0] == '\n' ) {
71 OutFile << str << "\n";
72 continue;
73 }
74 ss.str(str); ss.clear(std::stringstream::goodbit);
75 ss >> itemp >> Energy >> dtemp >> dtemp >> dtemp >> dtemp >> Ndata;
76 Stddev = 0;
77 for(int j = 0;j < Ndata; ++j) {
78 dtemp = Gaussian();
79 Stddev += dtemp*dtemp;
80 }
81 Stddev = sqrt( Stddev/(double)Ndata )/(double)std::log(Ndata);
82 dtemp = NAN;
83 OutFile << n << " "
84 << Energy << " "
85 << dtemp << " "
86 << Stddev << " "
87 << dtemp << " "
88 << dtemp << " "
89 << Ndata << "\n";
90 }
91 OutFile.close();
92 }
93 }
94 return 0;
95}
namespace filesystem
Definition Fluc_randHOp.cpp:38
bool checkIsFileOpen(std::ifstream &file, std::string const &filename)
Definition file_util.hpp:22
debug_print("# Determining GPU configuration.")