aboutsummaryrefslogtreecommitdiff
path: root/src/fit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fit.c')
-rw-r--r--src/fit.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/fit.c b/src/fit.c
index 296fe2f..a5d531a 100644
--- a/src/fit.c
+++ b/src/fit.c
@@ -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);
}
}