/* * cubeit.c * * "Full integration" of diffraction data * * (c) 2006-2010 Thomas White * * Part of CrystFEL - crystallography with a FEL * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include "image.h" #include "cell.h" #include "hdf5-file.h" #include "diffraction.h" #include "render.h" #define MAX_HITS (1024) static void show_help(const char *s) { printf("Syntax: %s [options]\n\n", s); printf( "'Full integration' of diffraction data.\n" "\n" " -h, --help Display this help message.\n" "\n" " -i, --input= Specify the name of the input stream.\n" " Can be '-' for stdin.\n" " -g. --geometry= Get detector geometry from file.\n" " -x, --prefix=

Prefix filenames from input file with

.\n" " --basename Remove the directory parts of the filenames.\n" " --no-check-prefix Don't attempt to correct the --prefix.\n" ); } static UnitCell *read_orientation_matrix(FILE *fh) { float u, v, w; struct rvec as, bs, cs; UnitCell *cell; char line[1024]; if ( fgets(line, 1023, fh) == NULL ) return NULL; if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) != 3 ) { ERROR("Couldn't read a-star\n"); return NULL; } as.u = u*1e9; as.v = v*1e9; as.w = w*1e9; if ( fgets(line, 1023, fh) == NULL ) return NULL; if ( sscanf(line, "bstar = %f %f %f", &u, &v, &w) != 3 ) { ERROR("Couldn't read b-star\n"); return NULL; } bs.u = u*1e9; bs.v = v*1e9; bs.w = w*1e9; if ( fgets(line, 1023, fh) == NULL ) return NULL; if ( sscanf(line, "cstar = %f %f %f", &u, &v, &w) != 3 ) { ERROR("Couldn't read c-star\n"); return NULL; } cs.u = u*1e9; cs.v = v*1e9; cs.w = w*1e9; cell = cell_new_from_axes(as, bs, cs); return cell; } static int find_chunk(FILE *fh, UnitCell **cell, char **filename) { char line[1024]; char *rval = NULL; do { rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; chomp(line); if ( strncmp(line, "Reflections from indexing", 25) != 0 ) { continue; } *filename = strdup(line+29); /* Skip two lines (while checking for errors) */ rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; *cell = read_orientation_matrix(fh); if ( *cell == NULL ) { STATUS("Got filename but no cell for %s\n", *filename); continue; } return 0; } while ( rval != NULL ); return 1; } static void interpolate_linear(double *vals, double v, int xs, int ys, int zs, int xv, int yv, double zv) { int k; double val1, val2; float f, c; c = (zv+0.5)*(float)zs; k = (int)c; f = c - (float)k; assert(f >= 0.0); assert(k < zs); val1 = v*(1.0-f); val2 = v*f; vals[xs*ys*k + xs*yv + xv] += val1; vals[xs*ys*(k+1) + xs*yv + xv] += val2; } static void interpolate_bilinear(double *vals, double v, int xs, int ys, int zs, int xv, double yv, double zv) { int k; double val1, val2; float f, c; c = (yv+0.5)*(float)ys; k = (int)c; f = c - (float)k; assert(f >= 0.0); assert(k < ys); val1 = v*(1.0-f); val2 = v*f; interpolate_linear(vals, val1, xs, ys, zs, xv, k, zv); interpolate_linear(vals, val2, xs, ys, zs, xv, k+1, zv); } static void interpolate_onto_grid(double *vals, double v, int xs, int ys, int zs, double xv, double yv, double zv) { int k; double val1, val2; float f, c; c = (xv+0.5)*(float)xs; k = (int)c; f = c - (float)k; assert(f >= 0.0); assert(k < xs); val1 = v*(1.0-f); val2 = v*f; interpolate_bilinear(vals, val1, xs, ys, zs, k, yv, zv); interpolate_bilinear(vals, val2, xs, ys, zs, k+1, yv, zv); } static void write_slice(const char *filename, double *vals, int z, int xs, int ys, int zs, double boost) { #ifdef HAVE_LIBPNG FILE *fh; png_structp png_ptr; png_infop info_ptr; png_bytep *row_pointers; int x, y; float max = 0.0; int w, h; w = xs; h = ys; for ( y=0; y max ) max = val; } } fh = fopen(filename, "wb"); if ( !fh ) { ERROR("Couldn't open output file.\n"); return; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if ( !png_ptr ) { ERROR("Couldn't create PNG write structure.\n"); fclose(fh); return; } info_ptr = png_create_info_struct(png_ptr); if ( !info_ptr ) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); ERROR("Couldn't create PNG info structure.\n"); fclose(fh); return; } if ( setjmp(png_jmpbuf(png_ptr)) ) { png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fh); ERROR("PNG write failed.\n"); return; } png_init_io(png_ptr, fh); png_set_IHDR(png_ptr, info_ptr, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); row_pointers = malloc(h*sizeof(png_bytep *)); /* Write the image data */ max /= boost; if ( max <= 6 ) { max = 10; } for ( y=0; y180 deg */ bin = rint(ang); angles[bin]++; } hdfile_close(hdfile); free(image.data); free(image.flags); } for ( i=0; i