00001 /**************************************************************** 00002 * This file is part of the C++ port of the Fortran likelihood 00003 * code for the WMAP 5yr release provided by the WMAP team 00004 * at http://lambda.gsfc.nasa.gov/ . 00005 * 00006 * The code was ported by Georg Robbers for easier 00007 * interfacing with cmbeasy (http://www.cmbeasy.org). 00008 * Bugs in this port should be reported to the 00009 * cmbeasy authors (bugs@cmbeasy.org). 00010 ****************************************************************/ 00011 00012 #include "WMAP_5yr_util.h" 00013 00014 #include "port_helper.h" 00015 00016 #include <string> 00017 #include <iostream> 00018 #include <iomanip> 00019 #include <ctime> 00020 00021 namespace wmap_util 00022 { 00023 00024 using namespace std; 00025 00026 bool bwmap_likelihood_ok, bwmap_likelihood_good; 00027 const bool bwmap_warnings_are_errors = false; 00028 00029 namespace // unnamed, simulates "private" 00030 { 00031 const int n_errs_max = 10; 00032 string err_msg[n_errs_max]; 00033 int n_errs, err_code[n_errs_max]; 00034 00035 const int n_warn_max = 10; 00036 string warn_msg[n_warn_max]; 00037 int n_warn, warn_code[n_warn_max]; 00038 00039 struct Timer 00040 { 00041 string desc; 00042 clock_t start_count, end_count; 00043 int checkpoint_count; 00044 bool stub; 00045 }; 00046 00047 int tlun; 00048 int n_timers = 0; 00049 const int max_n_timers = 6; 00050 Timer timers[max_n_timers]; 00051 } 00052 00053 //X don't need this in c++: 00054 //X void get_free_lun( lun ) 00055 //X { 00056 //X int, intent(out) lun; 00057 //X 00058 //X int, save last_lun = 19; 00059 //X bool usingd; 00060 //X 00061 //X lun = last_lun; 00062 //X while ( true ) { 00063 //X inquire( unit=lun, opened=usingd ); 00064 //X if ( ! usingd ) break; 00065 //X lun = lun + 1; 00066 //X } 00067 //X 00068 //X last_lun = lun; 00069 //X } 00070 00071 00072 bool wmap_likelihood_ok() { return bwmap_likelihood_ok; } 00073 bool wmap_likelihood_good() { return bwmap_likelihood_good; } 00074 00075 00076 00077 void wmap_likelihood_error_init( ) 00078 { 00079 bwmap_likelihood_ok = true; 00080 bwmap_likelihood_good = true; 00081 n_errs = 0; 00082 n_warn = 0; 00083 } 00084 00085 00086 void wmap_likelihood_error( string msg, int code ) 00087 { 00088 bwmap_likelihood_ok = false ; 00089 bwmap_likelihood_good = false ; 00090 00091 if ( n_errs < n_errs_max ) 00092 { 00093 n_errs = n_errs + 1; 00094 err_msg[n_errs] = msg; 00095 err_code[n_errs] = code; 00096 } 00097 else 00098 { 00099 cout << "*** error log full"; 00100 exit( -1 ); 00101 } 00102 } 00103 00104 void wmap_likelihood_warning( string msg, int code ) 00105 { 00106 if ( bwmap_warnings_are_errors ) 00107 bwmap_likelihood_ok = false; 00108 00109 bwmap_likelihood_good = false; 00110 00111 if ( n_warn < n_warn_max ) 00112 { 00113 n_warn = n_warn + 1; 00114 warn_msg[n_warn] = msg; 00115 warn_code[n_warn] = code; 00116 } 00117 else 00118 { 00119 cout << "*** warning log full"; 00120 exit( -1 ); 00121 } 00122 } 00123 00124 void wmap_likelihood_error_report( ) 00125 { 00126 int i; 00127 00128 cout << "------------------------------------------------------------" << endl; 00129 cout << "WMAP likelihood evaluation report:" << endl; 00130 00131 if ( bwmap_likelihood_ok ) 00132 { 00133 cout << "no errors" << endl; 00134 } 00135 else 00136 { 00137 cout << "number of errors = " << n_errs << endl; 00138 for (i = 1; i <= n_errs; ++i ) 00139 { 00140 cout << "" << endl; 00141 cout << "error #" << i << endl; 00142 cout << err_msg[i] << endl; 00143 cout << "error code = " << err_code[i] << endl; 00144 } 00145 } 00146 00147 if ( n_warn > 0 ) 00148 { 00149 cout << "number of warnings = " << n_warn << endl ; 00150 for (i = 1; i <= n_warn; ++i ) 00151 { 00152 cout << "" << endl ; 00153 cout << "warning #" << i << "::" << endl ; 00154 cout << warn_msg[i] << endl ; 00155 cout << "warning code = " << warn_code[i] << endl ; 00156 } 00157 } 00158 cout << "------------------------------------------------------------" << endl; 00159 00160 } 00161 00162 void wmap_timing_start(std::string desc) 00163 { 00164 cout << setw(8) << setprecision(4); 00165 int k; 00166 REAL elapsed_sec; 00167 00168 // if ( n_timers == 0 ) then 00169 // call get_free_lun( tlun ) 00170 // open(tlun,file=ofn_timing,action='write',status='unknown') 00171 // end if 00172 00173 if ( n_timers >= max_n_timers ) { 00174 cout << "*** too many timing levels" << endl; 00175 exit(-1); 00176 } 00177 00178 if ( n_timers > 0 && timers[n_timers].stub ) { 00179 timers[n_timers].stub = false; 00180 cout << " ....... "; 00181 cout << timers[n_timers].desc << endl; 00182 } 00183 00184 n_timers = n_timers + 1; 00185 k = n_timers; 00186 00187 timers[k].desc = desc; 00188 timers[k].start_count = clock(); 00189 timers[k].checkpoint_count = -1; 00190 timers[k].stub = true; 00191 } 00192 00193 00194 void wmap_timing_checkpoint(std::string desc) 00195 { 00196 clock_t start_count, end_count; 00197 00198 if ( timers[n_timers].checkpoint_count == -1 ) { 00199 start_count = timers[n_timers].start_count; 00200 if ( timers[n_timers].stub ) { 00201 timers[n_timers].stub = false; 00202 cout << " ....... "; 00203 cout << timers[n_timers].desc << endl; 00204 } 00205 } else { 00206 start_count = timers[n_timers].checkpoint_count; 00207 } 00208 end_count = clock(); 00209 00210 REAL elapsed_sec =(float)(end_count-start_count)/CLOCKS_PER_SEC; 00211 cout << " " << n_timers << " " << " - "; 00212 cout << elapsed_sec << " " << desc << endl; 00213 00214 timers[n_timers].checkpoint_count = end_count; 00215 } // 00216 00217 00218 void wmap_timing_end( ) 00219 { 00220 clock_t /*start_count,*/ end_count; 00221 REAL elapsed_sec; 00222 00223 if ( n_timers == 0 ) { 00224 cout << "*** n_timers == 0 in wmap_timing_end" << endl ; 00225 exit(-1); 00226 } 00227 00228 end_count = clock(); 00229 elapsed_sec = (float)(end_count-timers[n_timers].start_count)/CLOCKS_PER_SEC; 00230 00231 cout << " " << n_timers << " "; 00232 cout << elapsed_sec << " - " << timers[n_timers].desc << endl; 00233 n_timers = n_timers - 1; 00234 00235 // if ( n_timers == 0 ) then 00236 // close(tlun) 00237 // end if 00238 } // 00239 00240 00241 } // end namespace 00242
1.4.6