void chkmem(const char szMsg[]) { if (!_CrtCheckMemory()) Quit("chkmem(%s)", szMsg); }
int checkpoint(BOOLEAN force_checkpoint) { int retval=0, i, l=xml_indent_level; xml_indent_level=0; char buf[2048]; std::string enc_field, str; // The user may have set preferences for a long time between // checkpoints to reduce disk access. if (!force_checkpoint) { if (!boinc_time_to_checkpoint()) return CHECKPOINT_SKIPPED; } fflush(stderr); /* should be in this place! * in the Android or non-glibc malloc it causes huge system mmap2 overhead */ MFILE state_file; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif if (state_file.open(STATE_FILENAME, "wb")) SETIERROR(CANT_CREATE_FILE,"in checkpoint()"); retval = state_file.printf( "<ncfft>%d</ncfft>\n" "<cr>%e</cr>\n" "<fl>%d</fl>\n" "<prog>%.8f</prog>\n" "<potfreq>%d</potfreq>\n" "<potactivity>%d</potactivity>\n" "<signal_count>%d</signal_count>\n" "<flops>%f</flops>\n" "<spike_count>%d</spike_count>\n" "<pulse_count>%d</pulse_count>\n" "<gaussian_count>%d</gaussian_count>\n" "<triplet_count>%d</triplet_count>\n", analysis_state.icfft, ChirpFftPairs[analysis_state.icfft].ChirpRate, ChirpFftPairs[analysis_state.icfft].FftLen, std::min(progress,0.9999999), analysis_state.PoT_freq_bin, analysis_state.PoT_activity, signal_count, analysis_state.FLOP_counter, spike_count, pulse_count, gaussian_count, triplet_count ); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // checkpoint the best spike thus far (if any) if(best_spike->score) { retval = state_file.printf("<best_spike>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the spike proper str = best_spike->s.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bs_score>%f</bs_score>\n" "<bs_bin>%d</bs_bin>\n" "<bs_fft_ind>%d</bs_fft_ind>\n", best_spike->score, best_spike->bin, best_spike->fft_ind); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_spike>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // checkpoint the best gaussian thus far (if any) if(best_gauss->score) { retval = state_file.printf("<best_gaussian>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the gaussian proper str = best_gauss->g.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bg_score>%f</bg_score>\n" "<bg_display_power_thresh>%f</bg_display_power_thresh>\n" "<bg_bin>%d</bg_bin>\n" "<bg_fft_ind>%d</bg_fft_ind>\n", best_gauss->score, best_gauss->display_power_thresh, best_gauss->bin, best_gauss->fft_ind); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_gaussian>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // checkpoint the best pulse thus far (if any) // The check for len_prof is a kludge. if(best_pulse->score) { retval = state_file.printf("<best_pulse>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the pulse proper str = best_pulse->p.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bp_score>%f</bp_score>\n" "<bp_freq_bin>%d</bp_freq_bin>\n" "<bp_time_bin>%d</bp_time_bin>\n", best_pulse->score, best_pulse->freq_bin, best_pulse->time_bin); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_pulse>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // checkpoint the best triplet thus far (if any) if(best_triplet->score) { retval = state_file.printf("<best_triplet>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the triplet proper str = best_triplet->t.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bt_score>%f</bt_score>\n" "<bt_bperiod>%f</bt_bperiod>\n" "<bt_tpotind0_0>%d</bt_tpotind0_0>\n" "<bt_tpotind0_1>%d</bt_tpotind0_1>\n" "<bt_tpotind1_0>%d</bt_tpotind1_0>\n" "<bt_tpotind1_1>%d</bt_tpotind1_1>\n" "<bt_tpotind2_0>%d</bt_tpotind2_0>\n" "<bt_tpotind2_1>%d</bt_tpotind2_1>\n" "<bt_freq_bin>%d</bt_freq_bin>\n" "<bt_time_bin>%f</bt_time_bin>\n" "<bt_scale>%f</bt_scale>\n", best_triplet->score, best_triplet->bperiod, best_triplet->tpotind0_0, best_triplet->tpotind0_1, best_triplet->tpotind1_0, best_triplet->tpotind1_1, best_triplet->tpotind2_0, best_triplet->tpotind2_1, best_triplet->freq_bin, best_triplet->time_bin, best_triplet->scale); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // convert min PoT to chars, encode, and print for (i=0; i<swi.analysis_cfg.triplet_pot_length; i++) { buf[i] = (unsigned char)best_triplet->pot_min[i]; } enc_field=xml_encode_string(buf, swi.analysis_cfg.triplet_pot_length, _x_csv); retval = state_file.printf( "<bt_pot_min length=%d encoding=\"%s\">", enc_field.size(), xml_encoding_names[_x_csv] ); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); state_file.write(enc_field.c_str(), enc_field.size(), 1); retval = state_file.printf("</bt_pot_min>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // convert max PoT to chars, encode, and print for (i=0; i<swi.analysis_cfg.triplet_pot_length; i++) { buf[i] = (unsigned char)best_triplet->pot_max[i]; } enc_field=xml_encode_string(buf, swi.analysis_cfg.triplet_pot_length, _x_csv); state_file.printf( "<bt_pot_max length=%d encoding=\"%s\">", enc_field.size(), xml_encoding_names[_x_csv] ); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); state_file.write(enc_field.c_str(), enc_field.size(), 1); retval = state_file.printf("</bt_pot_max>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_triplet>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // The result (outfile) and state mfiles are now synchronized. // Flush them both. retval = outfile.flush(); if (retval) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.flush(); if (retval) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.close(); if (retval) SETIERROR(WRITE_FAILED,"in checkpoint()"); boinc_checkpoint_completed(); xml_indent_level=l; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif return 0; }
// Read the state file and set analysis_state accordingly. // Note: The state of analysis is saved in two places: // 1) at the end of processing the data for any given // chirp/fft pair. In this case, the icfft index // needs to be set for the *next* chirp/fft pair. // If analysis was in this state when saved, // PoT_freq_bin will have been set to -1. // 2) at the end of PoT processing for any given // frequency bin (for any given chirp/fft pair). // This is indicated by PoT_freq_bin containing // something other than -1. It will contain the // frequency bin just completed. In this case, we // are *not* finished processing for the current // chirp/fft pair and we do not increment icfft to // the next pair. We do however increment PoT_freq_bin // to the next frequency bin. // int parse_state_file(ANALYSIS_STATE& as) { static char buf[8192]; int ncfft, fl, PoT_freq_bin, PoT_activity; double cr=0,flops=0; FILE* state_file; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif ncfft = -1; progress = 0.0; PoT_freq_bin = -1; PoT_activity = POT_INACTIVE; state_file = boinc_fopen(STATE_FILENAME, "rb"); if (!state_file) SETIERROR(FOPEN_FAILED,"in parse_state_file()"); // main parsing loop while (fgets(buf, sizeof(buf), state_file)) { if (parse_int(buf, "<ncfft>", ncfft)) continue; else if (parse_double(buf, "<cr>", cr)) continue; else if (parse_int(buf, "<fl>", fl)) continue; else if (parse_double(buf, "<prog>", progress)) continue; else if (parse_int(buf, "<potfreq>", PoT_freq_bin)) continue; else if (parse_int(buf, "<potactivity>", PoT_activity)) continue; else if (parse_int(buf, "<signal_count>", signal_count)) continue; else if (parse_double(buf, "<flops>", flops)) continue; else if (parse_int(buf, "<spike_count>", spike_count)) continue; else if (parse_int(buf, "<pulse_count>", pulse_count)) continue; else if (parse_int(buf, "<gaussian_count>", gaussian_count)) continue; else if (parse_int(buf, "<triplet_count>", triplet_count)) continue; // best spike else if (xml_match_tag(buf, "<best_spike>")) { while (fgets(buf, sizeof(buf), state_file)) { if (xml_match_tag(buf, "</best_spike>")) break; // spike proper else if (xml_match_tag(buf, "<spike>")) { char *p = buf + strlen(buf); while(fgets(p, sizeof(buf)-(int)strlen(buf), state_file)) { if (xml_match_tag(buf, "</spike>")) break; p += strlen(p); } best_spike->s.parse_xml(buf); } // ancillary data else if (parse_double(buf, "<bs_score>", best_spike->score)) continue; else if (parse_int(buf, "<bs_bin>", best_spike->bin)) continue; else if (parse_int(buf, "<bs_fft_ind>", best_spike->fft_ind)) continue; } // end while in best_spike } // end if in best_spike // best gaussian.. else if (xml_match_tag(buf, "<best_gaussian>")) { while (fgets(buf, sizeof(buf), state_file)) { if (xml_match_tag(buf, "</best_gaussian>")) break; // gaussian proper else if (xml_match_tag(buf, "<gaussian>")) { char *p = buf + strlen(buf); while(fgets(p, sizeof(buf)-(int)strlen(buf), state_file)) { if (xml_match_tag(buf, "</gaussian>")) break; p += strlen(p); } best_gauss->g.parse_xml(buf); } // ancillary data else if (parse_double(buf, "<bg_score>", best_gauss->score)) continue; else if (parse_double(buf, "<bg_display_power_thresh>", best_gauss->display_power_thresh)) continue; else if (parse_int(buf, "<bg_bin>", best_gauss->bin)) continue ; else if (parse_int(buf, "<bg_fft_ind>", best_gauss->fft_ind)) continue; } // end while in best_gaissian } // end if in best_gaussian // best pulse else if (xml_match_tag(buf, "<best_pulse>")) { while (fgets(buf, sizeof(buf), state_file)) { if (xml_match_tag(buf, "</best_pulse>")) break; // pulse proper else if (xml_match_tag(buf, "<pulse>")) { char *p = buf + strlen(buf); while(fgets(p, sizeof(buf)-(int)strlen(buf), state_file)) { if (xml_match_tag(buf, "</pulse>")) break; p += strlen(p); } best_pulse->p.parse_xml(buf); } // ancillary data else if (parse_double(buf, "<bp_score>", best_pulse->score)) continue; else if (parse_int(buf, "<bp_freq_bin>", best_pulse->freq_bin)) continue; else if (parse_int(buf, "<bp_time_bin>", best_pulse->time_bin)) continue; } // end while in best_pulse } // end if in best_pulse // best triplet else if (xml_match_tag(buf, "<best_triplet>")) { while (fgets(buf, sizeof(buf), state_file)) { if (xml_match_tag(buf, "</best_triplet>")) break; // triplet proper else if (xml_match_tag(buf, "<triplet>")) { char *p = buf + strlen(buf); while(fgets(p, sizeof(buf)-(int)strlen(buf), state_file)) { if (xml_match_tag(buf, "</triplet>")) break; p += strlen(p); } best_triplet->t.parse_xml(buf); } // ancillary data else if (parse_double(buf, "<bt_score>", best_triplet->score)) continue; else if (parse_double(buf, "<bt_bperiod>", best_triplet->bperiod)) continue; else if (parse_int(buf, "<bt_tpotind0_0>", best_triplet->tpotind0_0)) continue; else if (parse_int(buf, "<bt_tpotind0_1>", best_triplet->tpotind0_1)) continue; else if (parse_int(buf, "<bt_tpotind1_0>", best_triplet->tpotind1_0)) continue; else if (parse_int(buf, "<bt_tpotind1_1>", best_triplet->tpotind1_1)) continue; else if (parse_int(buf, "<bt_tpotind2_0>", best_triplet->tpotind2_0)) continue; else if (parse_int(buf, "<bt_tpotind2_1>", best_triplet->tpotind2_1)) continue; else if (parse_int(buf, "<bt_freq_bin>", best_triplet->freq_bin)) continue; else if (parse_double(buf, "<bt_time_bin>", best_triplet->time_bin)) continue; else if (parse_double(buf, "<bt_scale>", best_triplet->scale)) continue; else if (xml_match_tag(buf, "<bt_pot_min")) { char *p = buf + strlen(buf); while(fgets(p, sizeof(buf)-(int)strlen(buf), state_file)) { if (xml_match_tag(buf, "</bt_pot_min")) break; p += strlen(p); } std::vector<unsigned char> pot_min( xml_decode_field<unsigned char>(buf,"bt_pot_min") ); int i; for (i=0; i<swi.analysis_cfg.triplet_pot_length; i++) { best_triplet->pot_min[i] = pot_min[i]; } } // end Min PoT else if (xml_match_tag(buf, "<bt_pot_max")) { char *p = buf + strlen(buf); while(fgets(p, sizeof(buf)-(int)strlen(buf), state_file)) { if (xml_match_tag(buf, "</bt_pot_max")) break; p += strlen(p); } std::vector<unsigned char> pot_max( xml_decode_field<unsigned char>(buf,"bt_pot_max") ); int i; for (i=0; i<swi.analysis_cfg.triplet_pot_length; i++) { best_triplet->pot_max[i] = pot_max[i]; } } // end Max PoT } // end while in best_triplet } // end if in best_triplet } // end main parsing loop fclose(state_file); analysis_state.FLOP_counter=flops; reload_graphics_state(); // so we can draw best_of signals // Adjust for restart - go 1 step beyond the checkpoint. as.PoT_activity = PoT_activity; if(PoT_freq_bin == -1) { as.icfft = ncfft+1; as.PoT_freq_bin = PoT_freq_bin; } else { as.icfft = ncfft; as.PoT_freq_bin = PoT_freq_bin+1; } // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif return 0; }
inline void DoneDBG() { DBG( _CrtCheckMemory() ); }
int APIENTRY WINMAIN(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LLMemType mt1(LLMemType::MTYPE_STARTUP); const S32 MAX_HEAPS = 255; DWORD heap_enable_lfh_error[MAX_HEAPS]; S32 num_heaps = 0; #if WINDOWS_CRT_MEM_CHECKS && !INCLUDE_VLD _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // dump memory leaks on exit #elif 1 // Experimental - enable the low fragmentation heap // This results in a 2-3x improvement in opening a new Inventory window (which uses a large numebr of allocations) // Note: This won't work when running from the debugger unless the _NO_DEBUG_HEAP environment variable is set to 1 _CrtSetDbgFlag(0); // default, just making explicit ULONG ulEnableLFH = 2; HANDLE* hHeaps = new HANDLE[MAX_HEAPS]; num_heaps = GetProcessHeaps(MAX_HEAPS, hHeaps); for(S32 i = 0; i < num_heaps; i++) { bool success = HeapSetInformation(hHeaps[i], HeapCompatibilityInformation, &ulEnableLFH, sizeof(ulEnableLFH)); if (success) heap_enable_lfh_error[i] = 0; else heap_enable_lfh_error[i] = GetLastError(); } #endif // *FIX: global gIconResource = MAKEINTRESOURCE(IDI_LL_ICON); LLAppViewerWin32* viewer_app_ptr = new LLAppViewerWin32(lpCmdLine); LLWinDebug::initExceptionHandler(viewer_windows_exception_handler); viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); // Set a debug info flag to indicate if multiple instances are running. bool found_other_instance = !create_app_mutex(); gDebugInfo["FoundOtherInstanceAtStartup"] = LLSD::Boolean(found_other_instance); bool ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Have to wait until after logging is initialized to display LFH info if (num_heaps > 0) { llinfos << "Attempted to enable LFH for " << num_heaps << " heaps." << llendl; for(S32 i = 0; i < num_heaps; i++) { if (heap_enable_lfh_error[i]) { llinfos << " Failed to enable LFH for heap: " << i << " Error: " << heap_enable_lfh_error[i] << llendl; } } } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // #if WINDOWS_CRT_MEM_CHECKS llinfos << "CRT Checking memory:" << llendflush; if (!_CrtCheckMemory()) { llwarns << "_CrtCheckMemory() failed at prior to cleanup!" << llendflush; } else { llinfos << " No corruption detected." << llendflush; } #endif viewer_app_ptr->cleanup(); #if WINDOWS_CRT_MEM_CHECKS llinfos << "CRT Checking memory:" << llendflush; if (!_CrtCheckMemory()) { llwarns << "_CrtCheckMemory() failed after cleanup!" << llendflush; } else { llinfos << " No corruption detected." << llendflush; } #endif } delete viewer_app_ptr; viewer_app_ptr = NULL; //start updater /*if(LLAppViewer::sUpdaterInfo) { _spawnl(_P_NOWAIT, LLAppViewer::sUpdaterInfo->mUpdateExePath.c_str(), LLAppViewer::sUpdaterInfo->mUpdateExePath.c_str(), LLAppViewer::sUpdaterInfo->mParams.str().c_str(), NULL); delete LLAppViewer::sUpdaterInfo ; LLAppViewer::sUpdaterInfo = NULL ; }*/ return 0; }
void checkHeap () { _CrtCheckMemory(); }
int ReportPulseEvent(float PulsePower,float MeanPower, float period, int time_bin,int freq_bin, float snr, float thresh, float *folded_pot, int scale, int write_pulse) { PULSE_INFO pi; pulse pulse; int retval=0, i, len_prof=static_cast<int>(floor(period)); float step,norm,index,MinPower=PulsePower*MeanPower*scale; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif // pulse info pi.score=snr/thresh; pi.p.peak_power=PulsePower-1; pi.p.mean_power=MeanPower; pi.p.fft_len=ChirpFftPairs[analysis_state.icfft].FftLen; pi.p.chirp_rate=ChirpFftPairs[analysis_state.icfft].ChirpRate; pi.p.period=static_cast<float>(period*static_cast<double>(pi.p.fft_len)/swi.subband_sample_rate); pi.p.snr = snr; pi.p.thresh = thresh; pi.p.len_prof = len_prof; pi.freq_bin=freq_bin; pi.time_bin=time_bin; pi.p.freq=cnvt_bin_hz(freq_bin, pi.p.fft_len); double t_offset=(static_cast<double>(time_bin)+0.5) *static_cast<double>(pi.p.fft_len)/ swi.subband_sample_rate; pi.p.detection_freq=calc_detection_freq(pi.p.freq,pi.p.chirp_rate,t_offset); pi.p.time=swi.time_recorded+t_offset/86400.0; time_to_ra_dec(pi.p.time, &pi.p.ra, &pi.p.decl); for (i=0;i<len_prof;i++) { if (folded_pot[i]<MinPower) MinPower=folded_pot[i]; } norm=255.0f/((PulsePower*MeanPower*scale-MinPower)); // Populate the min and max PoT arrays. These are only used // for graphics. #ifdef BOINC_APP_GRAPHICS if (!nographics()) { step=static_cast<float>(len_prof)/swi.analysis_cfg.pulse_pot_length; index=0; for (i=0;i<swi.analysis_cfg.pulse_pot_length;i++) { pi.pot_min[i]=255; pi.pot_max[i]=0; int j; for (j=0; j<step; j++) { unsigned int pot = static_cast<unsigned int>((folded_pot[static_cast<int>(floor(index))+j]-MinPower)*norm); if (pot<pi.pot_min[i]) { pi.pot_min[i]=pot; } if (pi.pot_min[i] >= 256) pi.pot_min[i] = 255; // kludge until we fix the assert failures BOINCASSERT(pi.pot_min[i] < 256); if (pot>pi.pot_max[i]) pi.pot_max[i]=pot; if (pi.pot_max[i] >= 256) pi.pot_max[i] = 255; // kludge until we fix the assert failures BOINCASSERT(pi.pot_max[i] < 256); } index+=step; } } #endif // Populate the result PoT if the folded PoT will fit. if (pi.p.len_prof < swi.analysis_cfg.pulse_pot_length) { pi.p.pot.resize(len_prof); for (i=0;i<len_prof;i++) { pi.p.pot[i] = (char)((folded_pot[i]-MinPower)*norm); } } else { pi.p.pot.clear(); } // Update gdata pulse info regardless of whether it is the // best thus far. If a pulse has made it this far, display it. #ifdef BOINC_APP_GRAPHICS if (!nographics()) sah_graphics->pi.copy(&pi); #endif // best thus far ? if (pi.score>best_pulse->score) { *best_pulse=pi; } if (write_pulse) { if (signal_count > swi.analysis_cfg.max_signals) { SETIERROR(RESULT_OVERFLOW,"in ReportPulseEvent"); } //for (i=0;i<len_prof;i++) { // sprintf(&pi.p.pot[i], "%02x",(int)((folded_pot[i]-MinPower)*norm)); // } retval = outfile.printf("%s", pi.p.print_xml(0,0,1).c_str()); if (retval >= 0) { outfile.printf("\n"); } if (retval < 0) { SETIERROR(WRITE_FAILED,"in ReportPulseEvent"); } else { signal_count++; pulse_count++; } } // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif return(retval); }
int ReportTripletEvent( float Power, float MeanPower, float period, float mid_time_bin, int start_time_bin, int freq_bin, int pot_len,const float *PoT, int write_triplet ) { TRIPLET_INFO ti; triplet triplet; int retval=0, i, j; double step,norm,index; double max_power=0; static int * inv; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif if (!inv) inv = (int*)calloc_a(swi.analysis_cfg.triplet_pot_length, sizeof(int), MEM_ALIGN); // triplet info ti.score=Power; ti.t.peak_power=Power; ti.t.mean_power=MeanPower; ti.freq_bin=freq_bin; ti.time_bin=mid_time_bin+start_time_bin+0.5f; ti.t.chirp_rate=ChirpFftPairs[analysis_state.icfft].ChirpRate; ti.t.fft_len=ChirpFftPairs[analysis_state.icfft].FftLen; ti.bperiod=period; ti.t.period=static_cast<float>(period*static_cast<double>(ti.t.fft_len)/swi.subband_sample_rate); ti.t.freq=cnvt_bin_hz(freq_bin, ti.t.fft_len); double t_offset=(static_cast<double>(mid_time_bin)+start_time_bin+0.5) *static_cast<double>(ti.t.fft_len)/ swi.subband_sample_rate; ti.t.detection_freq=calc_detection_freq(ti.t.freq,ti.t.chirp_rate,t_offset); ti.t.time=swi.time_recorded+t_offset/86400.0; time_to_ra_dec(ti.t.time, &ti.t.ra, &ti.t.decl); // Populate the min and max PoT arrays. These are only used // for graphics. memset(ti.pot_min,0xff,swi.analysis_cfg.triplet_pot_length*sizeof(int)); memset(ti.pot_max,0,swi.analysis_cfg.triplet_pot_length*sizeof(int)); step=static_cast<double>(pot_len)/swi.analysis_cfg.triplet_pot_length; ti.scale=static_cast<float>(1.0/step); index=0; for (i=0;i<pot_len;i++) { if (PoT[i]>max_power) max_power=PoT[i]; } norm=255.0/max_power; float mtb = mid_time_bin; if (pot_len > swi.analysis_cfg.triplet_pot_length) { ti.tpotind0_0 = ti.tpotind0_1 = static_cast<int>(((mtb-period)*swi.analysis_cfg.triplet_pot_length)/pot_len); ti.tpotind1_0 = ti.tpotind1_1 = static_cast<int>(((mtb)*swi.analysis_cfg.triplet_pot_length)/pot_len); ti.tpotind2_0 = ti.tpotind2_1 = static_cast<int>(((mtb+period)*swi.analysis_cfg.triplet_pot_length)/pot_len); for (j=0; j<pot_len; j++) { i = (j*swi.analysis_cfg.triplet_pot_length)/pot_len; if ((PoT[j]*norm)<ti.pot_min[i]) { ti.pot_min[i]=static_cast<unsigned int>(floor(PoT[j]*norm)); } if ((PoT[j]*norm)>ti.pot_max[i]) { ti.pot_max[i]=static_cast<unsigned int>(floor(PoT[j]*norm)); } } } else { memset(inv, -1, sizeof(inv)); for (i=0;i<swi.analysis_cfg.triplet_pot_length;i++) { j = (i*pot_len)/swi.analysis_cfg.triplet_pot_length; if (inv[j] < 0) inv[j] = i; if ((PoT[j]*norm)<ti.pot_min[i]) { ti.pot_min[i]=static_cast<unsigned int>(floor(PoT[j]*norm)); } if ((PoT[j]*norm)>ti.pot_max[i]) { ti.pot_max[i]=static_cast<unsigned int>(floor(PoT[j]*norm)); } } ti.tpotind0_0 = inv[static_cast<int>(mtb-period)]; ti.tpotind0_1 = inv[static_cast<int>(mtb-period+1)]; ti.tpotind1_0 = (inv[static_cast<int>(mtb)]+inv[static_cast<int>(mtb+1)])/2; ti.tpotind1_1 = (inv[static_cast<int>(mtb+1)]+inv[static_cast<int>(mtb+2)])/2; ti.tpotind2_0 = inv[static_cast<int>(mtb+period)]; if (mtb+period+1 >= pot_len) ti.tpotind2_1 = swi.analysis_cfg.triplet_pot_length-1; else ti.tpotind2_1 = inv[static_cast<int>(mtb+period+1)]; } // Update sah_graphics triplet info regardless of whether it is the // best thus far. If a triplet has made it this far, display it. #ifdef BOINC_APP_GRAPHICS if (!nographics()) sah_graphics->ti.copy(&ti); #endif // best thus far ? if (ti.score>best_triplet->score) { *best_triplet=ti; } if (write_triplet) { if (signal_count > swi.analysis_cfg.max_signals) { SETIERROR(RESULT_OVERFLOW,"in ReportTripletEvent"); } retval = outfile.printf("%s", ti.t.print_xml(0,0,1).c_str()); if (retval < 0) { SETIERROR(WRITE_FAILED,"in ReportTripletEvent"); } else { signal_count++; triplet_count++; } } // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif return(retval); }