diff options
author | tlatorre <tlatorre@uchicago.edu> | 2020-01-06 12:40:51 -0600 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2020-01-06 12:40:51 -0600 |
commit | fd5251dc5cc7cf3f94f6f3640a8da12ebd571c34 (patch) | |
tree | 7def9bd5dce57a1f5385d4c63dc3dee3868bda8e /src | |
parent | 837b18e78be24da4632d5f8e2e3a99012f8dc92d (diff) | |
download | sddm-fd5251dc5cc7cf3f94f6f3640a8da12ebd571c34.tar.gz sddm-fd5251dc5cc7cf3f94f6f3640a8da12ebd571c34.tar.bz2 sddm-fd5251dc5cc7cf3f94f6f3640a8da12ebd571c34.zip |
add ctrl-z handler to allow you to skip events
This commit updates the ./fit program to add a ctrl-z handler to allow you to
skip events. This is really handy when testing nwe things. Currently if you
press ctrl-z and it has already done at least one of the initial fits, it will
skip to move on to the final minimization stage. If you press ctrl-z during the
final minimization, it will skip fitting the event. Currently this will *not*
save the result to the file but I may change that in the future.
Diffstat (limited to 'src')
-rw-r--r-- | src/fit.c | 40 |
1 files changed, 32 insertions, 8 deletions
@@ -69,6 +69,7 @@ char *GitSHA1(void); char *GitDirty(void); static int stop = 0; +static int quit = 0; static nlopt_opt opt; #define EV_RECORD 0x45562020 // 'EV ' @@ -5583,7 +5584,18 @@ int fit_event2(event *ev, double *xopt, double *fmin, int *id, size_t n, double nlopt_optimize(opt,x,&fval); gettimeofday(&tv_stop, NULL); - if (stop) goto stop; + if (quit) { + /* If ctrl-c was pressed, quit the fit. */ + goto stop; + } else if (stop && i > 0) { + /* If ctrl-z was pressed, and we've already got at least 1 fit, move on + * to the "real" minimization. */ + stop = 0; + break; + } else if (stop) { + /* If ctrl-z was pressed and we don't have a fit, quit the fit. */ + goto stop; + } long long elapsed = (tv_stop.tv_sec - tv_start.tv_sec)*1000 + (tv_stop.tv_usec - tv_start.tv_usec)/1000; @@ -5768,6 +5780,8 @@ stop: free(result); nlopt_destroy(opt); + stop = 0; + return NLOPT_FORCED_STOP; } @@ -6046,9 +6060,15 @@ void usage(void) exit(1); } -void sigint_handler(int dummy) +void sigint_handler(int sig_num) { - stop = 1; + switch (sig_num) { + case SIGINT: + quit = 1; + case SIGTSTP: + stop = 1; + break; + } } void sprintf_particle_string(int *id, size_t n, char *str) @@ -6299,6 +6319,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); signal(SIGINT, sigint_handler); + signal(SIGTSTP, sigint_handler); f = zebra_open(filename); @@ -6580,12 +6601,14 @@ skip_mc: if (particle_combo) { i = particle_combo_to_array(particle_combo,id); - if (do_fit(&ev,id,i,hdf5_fits+nfits,maxtime,fmin_best) == NLOPT_FORCED_STOP) { + if (do_fit(&ev,id,i,hdf5_fits+nfits,maxtime,fmin_best) != NLOPT_FORCED_STOP) + nfits++; + + if (quit) { printf("ctrl-c caught. quitting...\n"); goto end; } - nfits++; if (output) save_output(output, hdf5_events, nevents, hdf5_mcgn, nmcgn, hdf5_fits, nfits, hdf5_rhdr, nrhdr); } else { @@ -6599,13 +6622,14 @@ skip_mc: id[k] = particles[combos[j*i+k]]; } - if (do_fit(&ev,id,i,hdf5_fits+nfits,maxtime,fmin_best) == NLOPT_FORCED_STOP) { + if (do_fit(&ev,id,i,hdf5_fits+nfits,maxtime,fmin_best) != NLOPT_FORCED_STOP) + nfits++; + + if (quit) { printf("ctrl-c caught. quitting...\n"); goto end; } - nfits++; - if (output) save_output(output, hdf5_events, nevents, hdf5_mcgn, nmcgn, hdf5_fits, nfits, hdf5_rhdr, nrhdr); } } |