本文整理汇总了C++中MFILE类的典型用法代码示例。如果您正苦于以下问题:C++ MFILE类的具体用法?C++ MFILE怎么用?C++ MFILE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MFILE类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_checkpoint
int do_checkpoint(MFILE& mf, int nchars) {
int retval;
string resolved_name;
FILE* f = fopen("temp", "w");
if (!f) return 1;
fprintf(f, "%d", nchars);
fclose(f);
retval = mf.flush();
if (retval) return retval;
boinc_resolve_filename_s(CHECKPOINT_FILE, resolved_name);
retval = boinc_rename("temp", resolved_name.c_str());
if (retval) return retval;
return 0;
}
示例2: do_checkpoint
/* Save the computation state into checkpoint file */
int do_checkpoint(MFILE& mf, int n, cl_float *input, int matrixSize) {
int retval;
string resolved_name;
FILE* f = fopen("temp", "w");
if (!f) return 1;
fprintf(f, "%d", n); //write inversion number
fprintf(f, " ");
fprintf(f, "%d", matrixSize); //write matrixSize
fprintf(f, " ");
for (int i=0;i<matrixSize*matrixSize;++i) {
fprintf(f, " ");
fprintf(f, "%f", input[i]);
}
fclose(f);
retval = mf.flush();
if (retval) return retval;
boinc_resolve_filename_s(CHECKPOINT_FILE, resolved_name);
retval = boinc_rename("temp", resolved_name.c_str());
if (retval) return retval;
return 0; //return 0 to indicate success.
}
示例3: main
int main(int argc, char * argv[]) {
int i, retval, lastInversion=0, checkpointExists=0, matrixSize=0;
double fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256];
MFILE out;
FILE* state, *infile;
generate_random_input_file(MATRIX_SIZE); //call this if you don't want to
//construct the input file manually
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "-early_exit")) early_exit = true;
if (!strcmp(argv[i], "-early_crash")) early_crash = true;
if (!strcmp(argv[i], "-early_sleep")) early_sleep = true;
if (!strcmp(argv[i], "-run_slow")) run_slow = true;
if (!strcmp(argv[i], "-cpu_time")) {
cpu_time = atof(argv[++i]);
}
}
retval = boinc_init();
if (retval) {
fprintf(stderr,
"%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file in boinc\\win_build, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
getchar();
exit(-1);
}
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so retrieve the current matrix and inversion number
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
printf("Checkpoint file is detected. Read from checkpoint file ... \n");
checkpointExists=fscanf(state, "%d", &lastInversion);
if (checkpointExists == 1) {
isStateFileInUse=true;
printf("Last inversion # is : %d\n",lastInversion);
fscanf(state,"%d",&matrixSize);
width=height=matrixSize;
printf("Initialize host ....\n");
initialize_host(state);
}
fclose(state);
} else {
printf("There's no valid checkpoint file!\n");
}
retval = out.open(output_path, "wb");
if (retval) {
fprintf(stderr,
"%s APP: matrix_inversion output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr,
"%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("matrix_inversion", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr,
"%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
if (checkpointExists != 1) { //checkpoint file is not found.
matrixSize=get_matrix_size(infile);
printf("Matrix Size: width = height = %d\n",matrixSize);
width=height=matrixSize;
// Initialize Host application
printf("Initialize host ....\n");
//.........这里部分代码省略.........
示例4: handle_rpc
int GUI_RPC_CONN::handle_rpc() {
int n, retval=0;
MIOFILE mf;
MFILE m;
char* p;
mf.init_mfile(&m);
int left = GUI_RPC_REQ_MSG_SIZE - request_nbytes;
#ifdef _WIN32
n = recv(sock, request_msg+request_nbytes, left, 0);
#else
n = read(sock, request_msg+request_nbytes, left);
#endif
if (n <= 0) {
request_nbytes = 0;
return ERR_READ;
}
request_nbytes += n;
// buffer full?
if (request_nbytes >= GUI_RPC_REQ_MSG_SIZE) {
request_nbytes = 0;
return ERR_READ;
}
request_msg[request_nbytes] = 0;
if (!strncmp(request_msg, "OPTIONS", 7)) {
char buf[1024];
sprintf(buf, "HTTP/1.1 200 OK\n"
"Server: BOINC client\n"
"Access-Control-Allow-Origin: *\n"
"Access-Control-Allow-Methods: POST, GET, OPTIONS\n"
"Content-Length: 0\n"
"Keep-Alive: timeout=2, max=100\n"
"Connection: Keep-Alive\n"
"Content-Type: text/plain\n\n"
);
send(sock, buf, strlen(buf), 0);
request_nbytes = 0;
if (log_flags.gui_rpc_debug) {
msg_printf(0, MSG_INFO,
"[gui_rpc] processed OPTIONS"
);
}
return 0;
}
bool http_request;
if (complete_post_request(request_msg)) {
http_request = true;
} else {
p = strchr(request_msg, 3);
if (p) {
*p = 0;
http_request = false;
} else {
if (log_flags.gui_rpc_debug) {
msg_printf(0, MSG_INFO,
"[gui_rpc] partial GUI RPC Command = '%s'\n", request_msg
);
}
return 0;
}
}
request_nbytes = 0;
if (log_flags.gui_rpc_debug) {
msg_printf(0, MSG_INFO,
"[gui_rpc] GUI RPC Command = '%s'\n", request_msg
);
}
// Policy:
// - the first auth failure gets an error message; after that, disconnect
// - if we get an unexpected auth1 or auth2, disconnect
mf.printf("<boinc_gui_rpc_reply>\n");
if (match_req(request_msg, "auth1")) {
if (got_auth1 && auth_needed) {
retval = ERR_AUTHENTICATOR;
} else {
handle_auth1(mf);
got_auth1 = true;
}
} else if (match_req(request_msg, "auth2")) {
if ((!got_auth1 || got_auth2) && auth_needed) {
retval = ERR_AUTHENTICATOR;
} else {
retval = handle_auth2(request_msg, mf);
got_auth2 = true;
}
} else if (auth_needed && !is_local) {
auth_failure(mf);
if (sent_unauthorized) {
retval = ERR_AUTHENTICATOR;
}
sent_unauthorized = true;
// operations that require authentication only for non-local clients start here.
// Use this only for information that should be available to people
// sharing this computer (e.g. what jobs are running)
// but not for anything sensitive (passwords etc.)
//.........这里部分代码省略.........
示例5: main
int main(int argc, char **argv) {
int i;
int c, nchars = 0, retval, n;
double fsize, fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256];
MFILE out;
FILE* state, *infile;
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "-early_exit")) early_exit = true;
if (!strcmp(argv[i], "-early_crash")) early_crash = true;
if (!strcmp(argv[i], "-early_sleep")) early_sleep = true;
if (!strcmp(argv[i], "-run_slow")) run_slow = true;
if (!strcmp(argv[i], "-cpu_time")) {
cpu_time = atof(argv[++i]);
}
}
retval = boinc_init();
if (retval) {
fprintf(stderr, "%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: upper_case output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("uppercase", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr, "%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
// main loop - read characters, convert to UC, write
//
for (i=0; ; i++) {
c = fgetc(infile);
if (c == EOF) break;
c = toupper(c);
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
//.........这里部分代码省略.........
示例6: write_state_file
// Write the client_state.xml file
//
int CLIENT_STATE::write_state_file() {
MFILE mf;
int retval, ret1, ret2, attempt;
#ifdef _WIN32
char win_error_msg[4096];
#endif
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] Writing state file"
);
}
#ifdef _WIN32
retval = mf.open(STATE_FILE_NEXT, "wc");
#else
retval = mf.open(STATE_FILE_NEXT, "w");
#endif
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
msg_printf(0, MSG_INTERNAL_ERROR,
"Can't open %s: %s",
STATE_FILE_NEXT, boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ERR_FOPEN;
}
MIOFILE miof;
miof.init_mfile(&mf);
ret1 = write_state(miof);
ret2 = mf.close();
if (ret1) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't write state file: %s", boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret1;
}
if (ret2) {
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret2;
}
// only attempt to rename the current state file if it exists.
//
if (boinc_file_exists(STATE_FILE_NAME)) {
if (boinc_file_exists(STATE_FILE_PREV)) {
retval = boinc_delete_file(STATE_FILE_PREV);
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"Can't delete previous state file; %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#else
msg_printf(0, MSG_INFO,
"Can't delete previous state file: %s",
strerror(errno)
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
retval = boinc_rename(STATE_FILE_NAME, STATE_FILE_PREV);
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"Can't rename current state file to previous state file; %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#else
msg_printf(0, MSG_INFO,
"Can't rename current state file to previous state file: %s",
strerror(errno)
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
retval = boinc_rename(STATE_FILE_NEXT, STATE_FILE_NAME);
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] Done writing state file"
);
}
if (!retval) break; // Success!
//.........这里部分代码省略.........
示例7: main
int main(int argc, char **argv) {
int i;
int c, nchars = 0, retval, n;
double fsize, fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256];
MFILE out;
FILE* state, *infile;
for (i=0; i<argc; i++) {
if (strstr(argv[i], "early_exit")) early_exit = true;
if (strstr(argv[i], "early_crash")) early_crash = true;
if (strstr(argv[i], "early_sleep")) early_sleep = true;
if (strstr(argv[i], "run_slow")) run_slow = true;
if (strstr(argv[i], "critical_section")) critical_section = true;
if (strstr(argv[i], "network_usage")) network_usage = true;
if (strstr(argv[i], "cpu_time")) {
cpu_time = atof(argv[++i]);
}
if (strstr(argv[i], "trickle_up")) trickle_up = true;
if (strstr(argv[i], "trickle_down")) trickle_down = true;
}
retval = boinc_init();
if (retval) {
fprintf(stderr, "%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
fprintf(stderr, "%s app started; CPU time %f, flags:%s%s%s%s%s%s%s\n",
boinc_msg_prefix(buf, sizeof(buf)),
cpu_time,
early_exit?" early_exit":"",
early_crash?" early_crash":"",
early_sleep?" early_sleep":"",
run_slow?" run_slow":"",
critical_section?" critical_section":"",
trickle_up?" trickle_up":"",
trickle_down?" trickle_down":""
);
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: upper_case output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("uppercase", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr, "%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
if (network_usage) {
//.........这里部分代码省略.........
示例8: main
int main(int argc, char **argv) {
int i,p,q,pq;
int c, nchars = 0, retval, n;
double fsize, fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256],sentence[1025];
MFILE out;
FILE* state, *infile;
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "-early_exit")) early_exit = true;
if (!strcmp(argv[i], "-early_crash")) early_crash = true;
if (!strcmp(argv[i], "-early_sleep")) early_sleep = true;
if (!strcmp(argv[i], "-run_slow")) run_slow = true;
if (!strcmp(argv[i], "-cpu_time")) {
cpu_time = atof(argv[++i]);
}
}
retval = boinc_init();
if (retval) {
fprintf(stderr, "%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: encrypt output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
for(i=0; ;i++){
c = fgetc(infile);
if(c==EOF) break;
sentence[i]=c;
}
sentence[i]='\0';
p=43;
q=3;
pq=p*q;
//e=19 d=31
strcpy(sentence,rsaencrypt(sentence,19,pq));
for (i=0;sentence[i]!='\0'; i++) {
c=sentence[i];
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
if (early_crash && i>30) {
boinc_crash();
}
if (early_sleep && i>30) {
boinc_disable_timer_thread = true;
//.........这里部分代码省略.........
示例9: handle_rpc
int GUI_RPC_CONN::handle_rpc() {
char request_msg[4096];
int n, retval=0;
MIOFILE mf;
MFILE m;
char* p;
mf.init_mfile(&m);
// read the request message in one read()
// so that the core client won't hang because
// of malformed request msgs
//
#ifdef _WIN32
n = recv(sock, request_msg, 4095, 0);
#else
n = read(sock, request_msg, 4095);
#endif
if (n <= 0) return ERR_READ;
request_msg[n-1] = 0; // replace 003 with NULL
if (log_flags.guirpc_debug) {
msg_printf(0, MSG_INFO,
"[guirpc_debug] GUI RPC Command = '%s'\n", request_msg
);
}
// Policy:
// - the first auth failure gets an error message; after that, disconnect
// - if we get an unexpected auth1 or auth2, disconnect
mf.printf("<boinc_gui_rpc_reply>\n");
if (match_req(request_msg, "auth1")) {
if (got_auth1 && auth_needed) {
retval = ERR_AUTHENTICATOR;
} else {
handle_auth1(mf);
got_auth1 = true;
}
} else if (match_req(request_msg, "auth2")) {
if ((!got_auth1 || got_auth2) && auth_needed) {
retval = ERR_AUTHENTICATOR;
} else {
retval = handle_auth2(request_msg, mf);
got_auth2 = true;
}
} else if (auth_needed && !is_local) {
auth_failure(mf);
if (sent_unauthorized) {
retval = ERR_AUTHENTICATOR;
}
sent_unauthorized = true;
// operations that require authentication only for non-local clients start here.
// Use this only for information that should be available to people
// sharing this computer (e.g. what jobs are running)
// but not for anything sensitive (passwords etc.)
} else if (match_req(request_msg, "exchange_versions")) {
handle_exchange_versions(mf);
} else if (match_req(request_msg, "get_state")) {
gstate.write_state_gui(mf);
} else if (match_req(request_msg, "get_results")) {
bool active_only = false;
parse_bool(request_msg, "active_only", active_only);
mf.printf("<results>\n");
gstate.write_tasks_gui(mf, active_only);
mf.printf("</results>\n");
} else if (match_req(request_msg, "get_screensaver_tasks")) {
handle_get_screensaver_tasks(mf);
} else if (match_req(request_msg, "result_show_graphics")) {
handle_result_show_graphics(request_msg, mf);
} else if (match_req(request_msg, "get_file_transfers")) {
gstate.write_file_transfers_gui(mf);
} else if (match_req(request_msg, "get_simple_gui_info")) {
handle_get_simple_gui_info(mf);
} else if (match_req(request_msg, "get_project_status")) {
handle_get_project_status(mf);
} else if (match_req(request_msg, "get_disk_usage")) {
handle_get_disk_usage(mf);
} else if (match_req(request_msg, "get_messages")) {
handle_get_messages(request_msg, mf);
} else if (match_req(request_msg, "get_message_count")) {
handle_get_message_count(request_msg, mf);
} else if (match_req(request_msg, "get_host_info")) {
handle_get_host_info(request_msg, mf);
} else if (match_req(request_msg, "get_statistics")) {
handle_get_statistics(request_msg, mf);
} else if (match_req(request_msg, "get_newer_version")) {
handle_get_newer_version(mf);
} else if (match_req(request_msg, "get_cc_status")) {
handle_get_cc_status(this, mf);
} else if (match_req(request_msg, "get_all_projects_list")) {
read_all_projects_list_file(mf);
// Operations that require authentication start here
} else if (auth_needed) {
auth_failure(mf);
if (sent_unauthorized) {
retval = ERR_AUTHENTICATOR;
//.........这里部分代码省略.........
示例10: result_spike
int result_spike(SPIKE_INFO &si) {
int retval=0;
if (signal_count >= swi.analysis_cfg.max_signals) {
SETIERROR(RESULT_OVERFLOW,"in result_spike");
}
retval = outfile.printf("%s", si.s.print_xml(0,0,1).c_str());
if (retval < 0) {
SETIERROR(WRITE_FAILED,"in result_spike");
} else {
signal_count++;
spike_count++;
}
return 0;
}
示例11: ReportPulseEvent
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] = (unsigned 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");
//.........这里部分代码省略.........
示例12: ReportTripletEvent
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");
}
//.........这里部分代码省略.........