You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Histogram_RAW_File.cc 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: Histogram_RAW_File.cc
  6. Purpose: Produce a histogram of matrix elements from a RAW file.
  7. ***********************************************************/
  8. #include "ABACUS.h"
  9. using namespace std;
  10. using namespace ABACUS;
  11. int main(int argc, char* argv[])
  12. {
  13. if (argc != 7) {
  14. cout << "Argument needed: rawfile, iKmin, iKmax, omega, domega, logscale_int" << endl;
  15. ABACUSerror("");
  16. }
  17. int n = 1;
  18. const char* rawfilename = argv[n++];
  19. int iKmin = atoi(argv[n++]);
  20. int iKmax = atoi(argv[n++]);
  21. DP om = atof(argv[n++]);
  22. DP dom = atof(argv[n++]);
  23. int logscale_int = atoi(argv[n++]); // see below for meaning
  24. ifstream RAW_infile;
  25. RAW_infile.open(rawfilename);
  26. if (RAW_infile.fail()) {
  27. cout << rawfilename << endl;
  28. ABACUSerror("Could not open RAW_infile... ");
  29. }
  30. stringstream outfilename;
  31. string outfilename_string;
  32. outfilename << rawfilename << "_hist";
  33. if (iKmin != iKmax) outfilename << "_iKmin_" << iKmin << "_iKmax_" << iKmax;
  34. outfilename << "_om_" << om << "_dom_" << dom << "_li_" << logscale_int;
  35. outfilename_string = outfilename.str();
  36. const char* outfilename_c_str = outfilename_string.c_str();
  37. ofstream outfile;
  38. outfile.open(outfilename_c_str);
  39. outfile.precision(16);
  40. // Use the binning in current ABACUS version's threads,
  41. // with logscale unit = 2^{1/64} \simeq 1.01
  42. int npts = 6400/logscale_int;
  43. DP logscale_used = logscale_int * (1.0/64) * log(2.0);
  44. DP omega_min = om - 0.5* dom;
  45. DP omega_max = om + 0.5* dom;
  46. DP omega;
  47. int iK;
  48. DP FF;
  49. DP dev;
  50. string label;
  51. Vect<int> nFF (0, npts);
  52. int nread = 0;
  53. int nfound = 0;
  54. int il = 0;
  55. while (RAW_infile.peek() != EOF) {
  56. RAW_infile >> omega >> iK >> FF >> dev >> label;
  57. nread++;
  58. if (iK >= iKmin && iK <= iKmax && omega > omega_min && omega < omega_max) {
  59. nfound++;
  60. il = int(-log(FF*FF)/logscale_used);
  61. if (il < 0) il=0;
  62. if (il > npts) continue;
  63. nFF[il] += 1;
  64. }
  65. }
  66. RAW_infile.close();
  67. if (nfound == 0) {
  68. cout << "Didn't find any contributing state." << endl;
  69. return(1);
  70. }
  71. for (int i = 0; i < npts; ++i) {
  72. if (i > 0) outfile << endl;
  73. outfile << i << "\t" << exp(-i * logscale_used) << "\t" << nFF[i] << "\t" << DP(nFF[i])/nfound;
  74. }
  75. outfile.close();
  76. // Now that we know the total number of entries, produce animated data:
  77. // the total number of entries is sliced into 100 pieces
  78. // and binned in the same way as before
  79. int stepsize = nfound/100;
  80. outfilename << "_sliced";
  81. outfilename_string = outfilename.str();
  82. const char* sliced_c_str = outfilename_string.c_str();
  83. ofstream sliced_file;
  84. sliced_file.open(sliced_c_str);
  85. sliced_file.precision(16);
  86. RAW_infile.open(rawfilename);
  87. if (RAW_infile.fail()) {
  88. cout << rawfilename << endl;
  89. ABACUSerror("Could not open RAW_infile... ");
  90. }
  91. nread = 0;
  92. nfound = 0;
  93. int nsteps = 0;
  94. for (int i = 0; i < npts; ++i) nFF[i] = 0;
  95. while (RAW_infile.peek() != EOF) {
  96. RAW_infile >> omega >> iK >> FF >> dev >> label;
  97. nread++;
  98. if (iK >= iKmin && iK <= iKmax && omega > omega_min && omega < omega_max) {
  99. nfound++;
  100. il = int(-log(FF*FF)/logscale_used);
  101. if (il < 0) il=0;
  102. if (il > npts) continue;
  103. nFF[il] += 1;
  104. }
  105. if (nfound == stepsize) {// || RAW_infile.peek() == EOF) {
  106. if (nsteps++ > 0) sliced_file << endl;
  107. sliced_file << DP(nFF[0])/stepsize;
  108. for (int i = 1; i < npts; ++i) sliced_file << "\t" << DP(nFF[i])/stepsize;
  109. for (int i = 0; i < npts; ++i) nFF[i] = 0;
  110. nfound = 0;
  111. }
  112. }
  113. RAW_infile.close();
  114. sliced_file.close();
  115. return(0);
  116. }