aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cache.c148
-rw-r--r--src/cache.h41
-rw-r--r--src/displaywindow.c10
-rw-r--r--src/displaywindow.h1
-rw-r--r--src/main.c21
-rw-r--r--src/reflections.h2
6 files changed, 125 insertions, 98 deletions
diff --git a/src/cache.c b/src/cache.c
index 1dac3ec..a146eb1 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -4,77 +4,91 @@
* Save the reflection datablock to save having to recalculate it
*
* (c) 2007 Gordon Ball <gfb21@cam.ac.uk>
+ * Thomas White <taw27@cam.ac.uk>
+ *
* dtr - Diffraction Tomography Reconstruction
*
*/
-
-#include "reflections.h"
-#include "cache.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
-
- ReflectionContext *load_rctx_from_file(const char *filename) {
- FILE *f;
- CacheHeader ch;
- ReflectionContext *rctx;
- Reflection r;
- Reflection *cr;
- Reflection_NoPointer rnp;
- rctx = reflection_init();
- f = fopen(filename, "rb");
- fread(&ch,sizeof(CacheHeader),1,f);
-
- int i;
- for (i=0;i<ch.count;i++) {
-
- fread(&rnp,sizeof(Reflection_NoPointer),1,f);
-
- cr = malloc(sizeof(Reflection));
- memcpy(cr,&rnp,sizeof(Reflection));
- //printf("reading (%f,%f,%f) i=%f (%d,%d,%d) %d\n",cr->x,cr->y,cr->z,cr->intensity,cr->h,cr->k,cr->l,cr->type);
- reflection_add_from_reflection(rctx,cr);
- }
-
- fclose(f);
- return rctx;
- }
-
- int save_rctx_to_file(const char *filename, ReflectionContext *rctx) {
- FILE *f;
- CacheHeader ch;
- Reflection *r;
- Reflection_NoPointer *rnp;
- char top[16] = "DTR-CACHE";
- int count=0;
-
- rnp = malloc(sizeof(Reflection_NoPointer));
-
- r = rctx->reflections;
- do {
- count++;
- } while ((r = r->next) != NULL );
-
-
- f = fopen(filename, "wb");
- memcpy(&ch.top,&top,sizeof(top));
- ch.count = count;
- ch.scale = 0.; //temp, currently doesn't do anything
- fwrite(&ch,sizeof(CacheHeader),1,f);
-
- r = rctx->reflections;
-
- do {
- memcpy(rnp,r,sizeof(Reflection_NoPointer));
- //printf("writing (%f,%f,%f) i=%f (%d,%d,%d) %d\n",rnp->x,rnp->y,rnp->z,rnp->intensity,rnp->h,rnp->k,rnp->l,rnp->type);
- fwrite(rnp,sizeof(Reflection_NoPointer),1,f);
- //fwrite(r,sizeof(Reflection_NoPointer),1,f);
- } while ((r = r->next) != NULL );
-
- fclose(f);
- return 0;
- }
-
-
- \ No newline at end of file
+
+#include "reflections.h"
+#include "cache.h"
+
+ReflectionContext *cache_load(const char *filename) {
+
+ FILE *f;
+ CacheHeader ch;
+ ReflectionContext *rctx;
+
+ rctx = reflection_init();
+ f = fopen(filename, "rb");
+ fread(&ch, sizeof(CacheHeader), 1, f);
+
+ int i;
+ for ( i=0; i<ch.count; i++ ) {
+
+ CachedReflection rnp;
+ Reflection *cr;
+
+ fread(&rnp, sizeof(CachedReflection), 1, f);
+
+ cr = malloc(sizeof(Reflection));
+ memcpy(cr, &rnp, sizeof(CachedReflection));
+ cr->next = NULL; /* Guarantee swift failure in the event of a screw-up */
+ //printf("reading (%f,%f,%f) i=%f (%d,%d,%d) %d\n",cr->x,cr->y,cr->z,cr->intensity,cr->h,cr->k,cr->l,cr->type);
+ reflection_add_from_reflection(rctx, cr);
+
+ }
+
+ fclose(f);
+
+ return rctx;
+}
+
+int cache_save(const char *filename, ReflectionContext *rctx) {
+
+ FILE *f;
+ CacheHeader ch;
+ Reflection *r;
+ CachedReflection *rnp;
+ int count;
+ char top[16] = "DTRCACHE\0\0\0\0\0\0\0\0";
+
+ count = 0;
+ r = rctx->reflections;
+ while ( r != NULL ) {
+ count++;
+ r = r->next;
+ };
+
+ f = fopen(filename, "wb");
+ memcpy(&ch.top, &top, sizeof(top));
+ ch.count = count;
+ ch.scale = 0.; //temp, currently doesn't do anything
+ fwrite(&ch, sizeof(CacheHeader), 1, f);
+
+ r = rctx->reflections;
+ rnp = malloc(sizeof(CachedReflection));
+ while ( r != NULL ) {
+
+ memcpy(rnp, r, sizeof(CachedReflection));
+ //printf("writing (%f,%f,%f) i=%f (%d,%d,%d) %d\n",rnp->x,rnp->y,rnp->z,rnp->intensity,rnp->h,rnp->k,rnp->l,rnp->type);
+ fwrite(rnp, sizeof(CachedReflection), 1, f);
+ r = r->next;
+
+ };
+ free(rnp);
+
+ fclose(f);
+
+ return 0;
+
+}
diff --git a/src/cache.h b/src/cache.h
index 9320703..38371e4 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -1,18 +1,31 @@
-#ifndef CACHE_H_
-#define CACHE_H_
-
-
+/*
+ * cache.c
+ *
+ * Save the reflection datablock to save having to recalculate it
+ *
+ * (c) 2007 Gordon Ball <gfb21@cam.ac.uk>
+ * Thomas White <taw27@cam.ac.uk>
+ *
+ * dtr - Diffraction Tomography Reconstruction
+ *
+ */
+
+#ifndef CACHE_H
+#define CACHE_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
typedef struct struct_cacheheader {
char top[16];
int count;
double scale;
} CacheHeader;
-/*
- * Necessary to define this because I'm developing this on an amd64 machine,
- * so pointers are 8 bytes instead of 4 on i386, so can't just dump reflection structs to disk
-*/
-typedef struct struct_specialreflect {
+
+/* Can't just use Reflection type because size of a pointer may vary */
+typedef struct struct_cachedreflection {
+
double x;
double y;
double z;
@@ -23,12 +36,10 @@ typedef struct struct_specialreflect {
signed int l;
ReflectionType type;
-} Reflection_NoPointer;
-
-extern ReflectionContext *load_rctx_from_file(const char *filename);
-
-int save_rctx_to_file(const char *filename, ReflectionContext *rctx);
+
+} CachedReflection;
+extern ReflectionContext *cache_load(const char *filename);
+extern int cache_save(const char *filename, ReflectionContext *rctx);
#endif /*CACHE_H_*/
-
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 1ed6493..f4a8b4a 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -447,7 +447,6 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Co
}
/* Zero plane */
- /*
glBegin(GL_QUADS);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, yellow_glass);
glVertex3f(50, 50, 0.0);
@@ -455,10 +454,9 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Co
glVertex3f(-50, -50, 0.0);
glVertex3f(-50, 50, 0.0);
glEnd();
- */
//octtree bit - temporary
- glBegin(GL_LINES);
+ /*glBegin(GL_LINES);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
disp_oct_stack(o);
@@ -466,7 +464,7 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Co
glBegin(GL_POINTS);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
disp_oct_list(ol);
- glEnd();
+ glEnd();*/
if ( gdk_gl_drawable_is_double_buffered(gldrawable) ) {
@@ -539,11 +537,11 @@ void displaywindow_open(ControlContext *ctx) {
char *title;
GdkGLConfig *glconfig;
- o = gen_octtree(ctx->reflectionctx,15);
+ /*o = gen_octtree(ctx->reflectionctx,15);
print_octtree(o);
int count=0;
ol = find_sparse_trees(o,3,1,&count);
-
+ */
filename = basename(ctx->filename);
title = malloc(10+strlen(filename));
strcpy(title, "dtr: ");
diff --git a/src/displaywindow.h b/src/displaywindow.h
index 6eae540..f4a7f27 100644
--- a/src/displaywindow.h
+++ b/src/displaywindow.h
@@ -8,7 +8,6 @@
*
*/
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
diff --git a/src/main.c b/src/main.c
index d708df5..5814e13 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,8 @@
* The Top Level Source File
*
* (c) 2007 Thomas White <taw27@cam.ac.uk>
+ * Gordon Ball <gfb21@cam.ac.uk>
+ *
* dtr - Diffraction Tomography Reconstruction
*
*/
@@ -59,21 +61,20 @@ static gint main_method_window_response(GtkWidget *method_window, gint response,
} else if ( ctx->inputfiletype == INPUT_MRC ) {
val = mrc_read(ctx);
} else if ( ctx->inputfiletype == INPUT_CACHE ) {
- ctx->reflectionctx = load_rctx_from_file(ctx->filename);
+ ctx->reflectionctx = cache_load(ctx->filename);
val=0;
}
- if (ctx->inputfiletype == INPUT_QDRP || ctx->inputfiletype == INPUT_MRC) {
+ if ( ctx->inputfiletype != INPUT_CACHE ) {
printf("Saving reflection block to reflect.cache\n");
- save_rctx_to_file("reflect.cache",ctx->reflectionctx);
+ cache_save("reflect.cache", ctx->reflectionctx);
}
-
if ( !val && (ctx->rmode == RECONSTRUCTION_PREDICTION) ) {
val = ipr_reduce(ctx);
}
- dump_histogram(ctx->reflectionctx);
+ //dump_histogram(ctx->reflectionctx);
if ( val == 0 ) {
displaywindow_open(ctx);
@@ -130,6 +131,10 @@ void main_method_dialog_open(ControlContext *ctx) {
gtk_combo_box_append_text(GTK_COMBO_BOX(ctx->combo_peaksearch), "Iterative Statistical");
gtk_combo_box_set_active(GTK_COMBO_BOX(ctx->combo_peaksearch), 3);
gtk_table_attach_defaults(GTK_TABLE(table), ctx->combo_peaksearch, 2, 3, 2, 3);
+
+ if ( ctx->inputfiletype == INPUT_CACHE ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(ctx->combo_peaksearch), FALSE);
+ }
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(table), TRUE, TRUE, 5);
@@ -160,7 +165,7 @@ int main(int argc, char *argv[]) {
}
if ( argc != 2 ) {
- fprintf(stderr, "Syntax: %s [<MRC file> | qdrp.rc]\n", argv[0]);
+ fprintf(stderr, "Syntax: %s [<MRC file> | qdrp.rc | reflect.cache]\n", argv[0]);
return 1;
}
@@ -174,11 +179,11 @@ int main(int argc, char *argv[]) {
} else if ( strcmp(filename+(strlen(filename)-4), ".mrc") == 0 ) {
printf("MRC tomography file detected.\n");
ctx->inputfiletype = INPUT_MRC;
- } else if (strcmp(filename, "reflect.cache") == 0 ) {
+ } else if ( strcmp(filename, "reflect.cache") == 0 ) {
printf("reflect.cache detected.\n");
ctx->inputfiletype = INPUT_CACHE;
} else {
- fprintf(stderr, "Input file must either be an MRC tomography file or a QDRP-style control file.\n");
+ fprintf(stderr, "Unrecognised input file type\n");
return 1;
}
ctx->filename = strdup(argv[1]);
diff --git a/src/reflections.h b/src/reflections.h
index a3a3993..ac08133 100644
--- a/src/reflections.h
+++ b/src/reflections.h
@@ -34,7 +34,7 @@ typedef struct reflection_struct {
ReflectionType type;
- struct reflection_struct *next;
+ struct reflection_struct *next; /* MUST BE LAST in order for caching to work */
} Reflection;