aboutsummaryrefslogtreecommitdiff
path: root/src/cache.c
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-03-31 00:19:35 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-03-31 00:19:35 +0000
commit8810e9ff13e9fb0db420dbdc529ef2f9dfe89d7c (patch)
treef256152050817b789554e0d18974fafcfbdf9644 /src/cache.c
parent3db95bb6d650a56eefd8c6d7dbd6bdc57e0e2350 (diff)
Fussiness:
Disable choice of peak detection algorithm when cached reflections used Fix formatting and namespace convention in cache.{c,h} Prevent reading beyond bounds of Reflection struct when saving cache Handle caching when no reflections were found (Temporarily?) disable octtree hooks Tweak some credits anad syntax message Other (mostly trivial) tweaks git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@15 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c148
1 files changed, 81 insertions, 67 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;
+
+}