diff options
Diffstat (limited to 'src/refine.c')
-rw-r--r-- | src/refine.c | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/refine.c b/src/refine.c index a264ad6..e3bf310 100644 --- a/src/refine.c +++ b/src/refine.c @@ -36,14 +36,8 @@ #define NUM_PARAMS 9 /* Refine debug */ -#define REFINE_DEBUG 1 #define REFINE_DEBUG_MORE 0 -/* REFINE_DEBUG_MORE depends on REFINE_DEBUG */ -#if !REFINE_DEBUG && REFINE_DEBUG_MORE -#error You must enable REFINE_DEBUG to use REFINE_DEBUG_MORE -#endif - #define DELTA (0.0001e9) typedef struct { @@ -59,6 +53,20 @@ typedef struct { } Deviation; +static void refine_printf(DisplayWindow *dw, char *fmt, ...) { + + va_list ap; + char tmp[1024]; + + va_start(ap, fmt); + vsnprintf(tmp, 1023, fmt, ap); + va_end(ap); + + printf("%s", tmp); + displaywindow_message(dw, tmp); + +} + void refine_do_sequence(ControlContext *ctx) { double omega_offs; @@ -88,8 +96,8 @@ void refine_do_sequence(ControlContext *ctx) { reproject_lattice_changed(ctx); fit = refine_do_cell(ctx); - printf("RF: omega_offs=%f deg, fit=%f nm^-1\n", rad2deg(omega_offs), - fit/DISPFACTOR); + refine_printf(ctx->dw, " omega_offs=%f deg, fit=%f nm^-1\n", + rad2deg(omega_offs), fit/DISPFACTOR); fit_vals[idx++] = fit; if ( fit < fit_best ) { fit_best = fit; @@ -112,7 +120,8 @@ void refine_do_sequence(ControlContext *ctx) { gtk_widget_show_all(window_fit); /* Perform final refinement */ - printf("Best omega offset = %f deg (%f nm^-1)\n", rad2deg(omega_offs_best), fit_best/DISPFACTOR); + refine_printf(ctx->dw, "Best omega offset = %f deg (%f nm^-1)\n", + rad2deg(omega_offs_best), fit_best/DISPFACTOR); for ( j=0; j<ctx->images->n_images; j++ ) { ctx->images->images[j].omega += omega_offs_best; } @@ -188,11 +197,14 @@ static void refine_cell_delta(Basis *devcell_try, int comp) { } -static void refine_show_cell(Basis cell) { +static void refine_show_cell(DisplayWindow *dw, Basis cell) { - printf("a: %+10.8f %+10.8f %+10.8f\n", cell.a.x/DISPFACTOR, cell.a.y/DISPFACTOR, cell.a.z/DISPFACTOR); - printf("b: %+10.8f %+10.8f %+10.8f\n", cell.b.x/DISPFACTOR, cell.b.y/DISPFACTOR, cell.b.z/DISPFACTOR); - printf("c: %+10.8f %+10.8f %+10.8f\n", cell.c.x/DISPFACTOR, cell.c.y/DISPFACTOR, cell.c.z/DISPFACTOR); + refine_printf(dw, "a: %+10.8f %+10.8f %+10.8f\n", + cell.a.x/DISPFACTOR, cell.a.y/DISPFACTOR, cell.a.z/DISPFACTOR); + refine_printf(dw, "b: %+10.8f %+10.8f %+10.8f\n", + cell.b.x/DISPFACTOR, cell.b.y/DISPFACTOR, cell.b.z/DISPFACTOR); + refine_printf(dw, "c: %+10.8f %+10.8f %+10.8f\n", + cell.c.x/DISPFACTOR, cell.c.y/DISPFACTOR, cell.c.z/DISPFACTOR); } @@ -295,14 +307,10 @@ double refine_do_cell(ControlContext *ctx) { if ( ctx->images->images[i].rflist->features[j].partner != NULL ) nf++; } - #if REFINE_DEBUG - printf("%i features from image %i\n", nf, i); - #endif /* REFINE_DEBUG */ + refine_printf(ctx->dw, "%i features from image %i\n", nf, i); } - #if REFINE_DEBUG - printf("RF: There are %i partnered features in total\n", nf); - #endif /* REFINE_DEBUG */ + refine_printf(ctx->dw, "There are %i partnered features in total\n", nf); /* Initialise the 'deviation table' */ d = malloc(nf*sizeof(Deviation)); @@ -330,10 +338,8 @@ double refine_do_cell(ControlContext *ctx) { /* Determine the difference vector */ dix = rf->partner->x - rf->x; diy = rf->partner->y - rf->y; - #if REFINE_DEBUG - printf("RF: Image %3i, feature %3i: %3i %3i %3i dev = %+9.5f %+9.5f px ", + refine_printf(ctx->dw, "%3i: %3i: %3i %3i %3i dev %+9.5f %+9.5f px ", i, j, d[f].h, d[f].k, d[f].l, dix, diy); - #endif /* REFINE_DEBUG */ old_x = rf->partner->x; old_y = rf->partner->y; @@ -342,10 +348,9 @@ double refine_do_cell(ControlContext *ctx) { mapping_scale(rf->partner, &dx, &dy); rf->partner->x = old_x; rf->partner->y = old_y; - #if REFINE_DEBUG double mod = sqrt(dx*dx + dy*dy)/DISPFACTOR; - printf("=> %+10.5f %+10.5f nm^-1 (length %10.5f nm^1)\n", dx/DISPFACTOR, dy/DISPFACTOR, mod); - #endif /* REFINE_DEBUG */ + refine_printf(ctx->dw, "= %+10.5f %+10.5f nm^-1 (length %7.5f nm^1)\n", + dx/DISPFACTOR, dy/DISPFACTOR, mod); d[f].dx = dx; d[f].dy = dy; @@ -371,12 +376,9 @@ double refine_do_cell(ControlContext *ctx) { devcell->a.y = 0.0e9; devcell->b.y = 0.0e9; devcell->c.y = 0.0e9; devcell->a.z = 0.0e9; devcell->b.z = 0.0e9; devcell->c.z = 0.0e9; mean_dev = refine_mean_dev(d, nf, devcell, 0); - #if REFINE_DEBUG - printf("Initial mean deviation: %13.8f nm^1\n", mean_dev/DISPFACTOR); - #endif /* REFINE_DEBUG */ + refine_printf(ctx->dw, "Initial mean deviation: %13.8f nm^1\n", mean_dev/DISPFACTOR); /* Test confidence */ - printf("Testing confidence...\n"); conf = refine_test_confidence(d, nf); /* Determine direction of steepest gradient */ @@ -389,13 +391,13 @@ double refine_do_cell(ControlContext *ctx) { #if REFINE_DEBUG_MORE refine_mean_dev(d, nf, devcell, 1); - printf("Iteration %i starts at dev %14.12f\n", it, mean_dev/DISPFACTOR); - printf("Current dev cell:\n"); - printf("a = %8.5f %8.5f %8.5f\n", + printf(ctx->dw, "Iteration %i starts at dev %14.12f\n", it, mean_dev/DISPFACTOR); + printf(ctx->dw, "Current dev cell:\n"); + printf(ctx->dw, "a = %8.5f %8.5f %8.5f\n", devcell->a.x/DISPFACTOR, devcell->a.y/DISPFACTOR, devcell->a.z/DISPFACTOR); - printf("b = %8.5f %8.5f %8.5f\n", + printf(ctx->dw, "b = %8.5f %8.5f %8.5f\n", devcell->b.x/DISPFACTOR, devcell->b.y/DISPFACTOR, devcell->b.z/DISPFACTOR); - printf("c = %8.5f %8.5f %8.5f\n", + printf(ctx->dw, "c = %8.5f %8.5f %8.5f\n", devcell->c.x/DISPFACTOR, devcell->c.y/DISPFACTOR, devcell->c.z/DISPFACTOR); #endif /* REFINE_DEBUG_MORE */ @@ -421,21 +423,19 @@ double refine_do_cell(ControlContext *ctx) { } else { break; } - #if REFINE_DEBUG if ( !(it % 1000) ) { - printf("After %5i iterations: mean dev = %13.8f nm^1\n", it, mean_dev/DISPFACTOR); + refine_printf(ctx->dw, "After %5i iterations: mean dev = %13.8f nm^1\n", it, + mean_dev/DISPFACTOR); } - #endif /* REFINE_DEBUG */ + } free(devcell_try); free(devcell_try_best); - #if REFINE_DEBUG - printf("Final mean dev (%5i iterations) = %13.8f nm^1\n", it, mean_dev/DISPFACTOR); - printf("Final cell deviation:\n"); - refine_show_cell(*devcell); - printf("Confidence:\n"); - refine_show_cell(conf); - #endif /* REFINE_DEBUG */ + refine_printf(ctx->dw, "Final mean dev (%5i iterations) = %13.8f nm^1\n", it, mean_dev/DISPFACTOR); + refine_printf(ctx->dw, "Final cell deviation:\n"); + refine_show_cell(ctx->dw, *devcell); + refine_printf(ctx->dw, "Confidence:\n"); + refine_show_cell(ctx->dw, conf); /* Apply the final values to the cell */ conf_threshold = 2.5; |