From 8810e9ff13e9fb0db420dbdc529ef2f9dfe89d7c Mon Sep 17 00:00:00 2001 From: taw27 Date: Sat, 31 Mar 2007 00:19:35 +0000 Subject: 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 --- src/cache.c | 148 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 67 deletions(-) (limited to 'src/cache.c') 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 + * Thomas White + * * dtr - Diffraction Tomography Reconstruction * */ - -#include "reflections.h" -#include "cache.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include #include - - 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;ix,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; inext = 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; + +} -- cgit v1.2.3