Add some string utils; rework Benchmark
This commit is contained in:
@@ -23,19 +23,11 @@ using namespace ABACUS;
|
||||
|
||||
namespace ABACUS {
|
||||
|
||||
void Benchmark_RAW_File (const char ff_file[], char whichDSF)
|
||||
void Benchmark_RAW_File (const string ff_file, char whichDSF)
|
||||
{
|
||||
// Check size of raw file:
|
||||
struct stat statbuf;
|
||||
string filename = ff_file;
|
||||
|
||||
stat (ff_file, &statbuf);
|
||||
int filesize = statbuf.st_size;
|
||||
|
||||
// Determine the number of entries approximately
|
||||
int entry_size = 2* sizeof(float) + 2*sizeof(int);
|
||||
|
||||
//const int MAXDATA = 50000000;
|
||||
const int MAXDATA = filesize/entry_size + 10;
|
||||
const int MAXDATA = count_lines(filename);
|
||||
|
||||
DP* omega = new DP[MAXDATA];
|
||||
int* iK = new int[MAXDATA];
|
||||
@@ -45,7 +37,7 @@ namespace ABACUS {
|
||||
string* label = new string[MAXDATA];
|
||||
|
||||
ifstream infile;
|
||||
infile.open(ff_file);
|
||||
infile.open(filename);
|
||||
|
||||
if (infile.fail()) ABACUSerror("The input file was not opened successfully in Benchmark_RAW_File. ");
|
||||
|
||||
@@ -73,14 +65,10 @@ namespace ABACUS {
|
||||
for (int i = 0; i < Ndata; ++i) sr_cont[i] = fabs(omega[i]) * ff[i] * ff[i];
|
||||
}
|
||||
|
||||
stringstream outfilename;
|
||||
string outfilename_string;
|
||||
outfilename << ff_file << "_bmk";
|
||||
outfilename_string = outfilename.str();
|
||||
const char* outfilename_c_str = outfilename_string.c_str();
|
||||
string outfilename = replace_all(filename, ".", "_") + ".bmk";
|
||||
|
||||
ofstream outfile1;
|
||||
outfile1.open(outfilename_c_str);
|
||||
outfile1.open(outfilename);
|
||||
outfile1.precision(16);
|
||||
|
||||
for (int i = 0; i < Ndata; i++) {
|
||||
@@ -93,12 +81,8 @@ namespace ABACUS {
|
||||
// Now the ordered one
|
||||
QuickSort(sr_cont, index, 0, Ndata - 1);
|
||||
|
||||
outfilename << "_srt";
|
||||
outfilename_string = outfilename.str();
|
||||
const char* outfilename2_c_str = outfilename_string.c_str();
|
||||
|
||||
ofstream outfile2;
|
||||
outfile2.open(outfilename2_c_str);
|
||||
outfile2.open(outfilename + "_srt");
|
||||
outfile2.precision(16);
|
||||
|
||||
for (int i = 0; i < Ndata; i++) {
|
||||
@@ -133,7 +117,8 @@ int main(int argc, char* argv[])
|
||||
ABACUSerror("");
|
||||
}
|
||||
|
||||
const char* rawfilename = argv[1];
|
||||
// const char* rawfilename = argv[1];
|
||||
string rawfilename = argv[1];
|
||||
char whichDSF = *argv[2];
|
||||
|
||||
Benchmark_RAW_File (rawfilename, whichDSF);
|
||||
|
||||
Reference in New Issue
Block a user