diff options
author | gfb21 <gfb21@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-02-17 13:50:28 +0000 |
---|---|---|
committer | gfb21 <gfb21@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-02-17 13:50:28 +0000 |
commit | e3bfcf077994c70aa965f9422d778bae5088f382 (patch) | |
tree | 0a9eef8179f9b3770bf5c1d3a7b096d623e0d715 /src/cache.c | |
parent | 7144216342686b49e4f759c2fdd8de4946db8fdb (diff) |
Added reflection-caching support
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@8 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/cache.c b/src/cache.c new file mode 100644 index 0000000..1dac3ec --- /dev/null +++ b/src/cache.c @@ -0,0 +1,80 @@ +/* + * cache.c + * + * Save the reflection datablock to save having to recalculate it + * + * (c) 2007 Gordon Ball <gfb21@cam.ac.uk> + * dtr - Diffraction Tomography Reconstruction + * + */ + +#include "reflections.h" +#include "cache.h" +#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 |