|
@@ -0,0 +1,142 @@
|
|
1
|
+/**********************************************************
|
|
2
|
+
|
|
3
|
+This software is part of J.-S. Caux's ABACUS library.
|
|
4
|
+
|
|
5
|
+Copyright (c) J.-S. Caux.
|
|
6
|
+
|
|
7
|
+-----------------------------------------------------------
|
|
8
|
+
|
|
9
|
+File: Benchmark_RAW_File.cc
|
|
10
|
+
|
|
11
|
+Purpose: produces benchmarking files.
|
|
12
|
+ Two files are produced, each with line output: label sr_cont order,
|
|
13
|
+ - one in order of original RAW file
|
|
14
|
+ - one in order of decreasing sr_cont
|
|
15
|
+
|
|
16
|
+***********************************************************/
|
|
17
|
+
|
|
18
|
+#include "ABACUS.h"
|
|
19
|
+
|
|
20
|
+using namespace std;
|
|
21
|
+using namespace ABACUS;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+namespace ABACUS {
|
|
25
|
+
|
|
26
|
+ void Benchmark_RAW_File (const char ff_file[], char whichDSF)
|
|
27
|
+ {
|
|
28
|
+ // Check size of raw file:
|
|
29
|
+ struct stat statbuf;
|
|
30
|
+
|
|
31
|
+ stat (ff_file, &statbuf);
|
|
32
|
+ int filesize = statbuf.st_size;
|
|
33
|
+
|
|
34
|
+ // Determine the number of entries approximately
|
|
35
|
+ int entry_size = 2* sizeof(float) + 2*sizeof(int);
|
|
36
|
+
|
|
37
|
+ //const int MAXDATA = 50000000;
|
|
38
|
+ const int MAXDATA = filesize/entry_size + 10;
|
|
39
|
+
|
|
40
|
+ DP* omega = new DP[MAXDATA];
|
|
41
|
+ int* iK = new int[MAXDATA];
|
|
42
|
+ DP* ff = new DP[MAXDATA];
|
|
43
|
+ DP* ff_im = new DP[MAXDATA];
|
|
44
|
+ DP* dev = new DP[MAXDATA];
|
|
45
|
+ string* label = new string[MAXDATA];
|
|
46
|
+
|
|
47
|
+ ifstream infile;
|
|
48
|
+ infile.open(ff_file);
|
|
49
|
+
|
|
50
|
+ if (infile.fail()) ABACUSerror("The input file was not opened successfully in Benchmark_RAW_File. ");
|
|
51
|
+
|
|
52
|
+ int Ndata = 0;
|
|
53
|
+ while (((infile.peek()) != EOF) && (Ndata < MAXDATA)) {
|
|
54
|
+
|
|
55
|
+ infile >> omega[Ndata];
|
|
56
|
+ infile >> iK[Ndata];
|
|
57
|
+ if (whichDSF != 'Z') infile >> ff[Ndata];
|
|
58
|
+ if (whichDSF == 'q') infile >> ff_im[Ndata]; // imaginary part of overlap, quench case
|
|
59
|
+ infile >> dev[Ndata];
|
|
60
|
+ infile >> label[Ndata];
|
|
61
|
+
|
|
62
|
+ Ndata++;
|
|
63
|
+ }
|
|
64
|
+ infile.close();
|
|
65
|
+
|
|
66
|
+ int* index = new int[Ndata];
|
|
67
|
+ // Sum rule contribution
|
|
68
|
+ DP* sr_cont = new DP[MAXDATA];
|
|
69
|
+
|
|
70
|
+ for (int i = 0; i < Ndata; ++i) index[i] = i;
|
|
71
|
+
|
|
72
|
+ if (whichDSF == 'd') {
|
|
73
|
+ for (int i = 0; i < Ndata; ++i) sr_cont[i] = fabs(omega[i]) * ff[i] * ff[i];
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ stringstream outfilename;
|
|
77
|
+ string outfilename_string;
|
|
78
|
+ outfilename << ff_file << "_bmk";
|
|
79
|
+ outfilename_string = outfilename.str();
|
|
80
|
+ const char* outfilename_c_str = outfilename_string.c_str();
|
|
81
|
+
|
|
82
|
+ ofstream outfile1;
|
|
83
|
+ outfile1.open(outfilename_c_str);
|
|
84
|
+ outfile1.precision(16);
|
|
85
|
+
|
|
86
|
+ for (int i = 0; i < Ndata; i++) {
|
|
87
|
+
|
|
88
|
+ if (i > 0) outfile1 << endl;
|
|
89
|
+ outfile1 << index[i] << "\t" << sr_cont[i] << "\t" << label[i];
|
|
90
|
+ }
|
|
91
|
+ outfile1.close();
|
|
92
|
+
|
|
93
|
+ // Now the ordered one
|
|
94
|
+ QuickSort(sr_cont, index, 0, Ndata - 1);
|
|
95
|
+
|
|
96
|
+ outfilename << "_srt";
|
|
97
|
+ outfilename_string = outfilename.str();
|
|
98
|
+ const char* outfilename2_c_str = outfilename_string.c_str();
|
|
99
|
+
|
|
100
|
+ ofstream outfile2;
|
|
101
|
+ outfile2.open(outfilename2_c_str);
|
|
102
|
+ outfile2.precision(16);
|
|
103
|
+
|
|
104
|
+ for (int i = 0; i < Ndata; i++) {
|
|
105
|
+
|
|
106
|
+ if (i > 0) outfile2 << endl;
|
|
107
|
+ outfile2 << index[Ndata - 1 - i] << "\t" << sr_cont[Ndata - i - 1] << "\t" << label[index[Ndata - 1 - i] ];
|
|
108
|
+ }
|
|
109
|
+ outfile2.close();
|
|
110
|
+
|
|
111
|
+ delete[] omega;
|
|
112
|
+ delete[] iK;
|
|
113
|
+ delete[] ff;
|
|
114
|
+ delete[] ff_im;
|
|
115
|
+ delete[] dev;
|
|
116
|
+ delete[] label;
|
|
117
|
+
|
|
118
|
+ delete[] index;
|
|
119
|
+ delete[] sr_cont;
|
|
120
|
+
|
|
121
|
+ return;
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+} // namespace ABACUS
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+int main(int argc, char* argv[])
|
|
130
|
+{
|
|
131
|
+ if (argc != 3) {
|
|
132
|
+ cout << "Arguments needed: rawfile, whichDSF." << endl;
|
|
133
|
+ ABACUSerror("");
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ const char* rawfilename = argv[1];
|
|
137
|
+ char whichDSF = *argv[2];
|
|
138
|
+
|
|
139
|
+ Benchmark_RAW_File (rawfilename, whichDSF);
|
|
140
|
+
|
|
141
|
+ return(0);
|
|
142
|
+}
|