diff options
author | Thomas White <taw@physics.org> | 2017-04-28 17:15:13 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-05-02 12:03:12 +0200 |
commit | cb6389ae61e8f7e279ea16f8ab1a94969d6c0dc9 (patch) | |
tree | f4c0cd181bf503e1d69488e66d929458139ed779 | |
parent | 8fbfaf71b1efef4bfdb40ce85200e772e82e9773 (diff) |
Skeleton image file API
-rw-r--r-- | libcrystfel/src/image.c | 129 | ||||
-rw-r--r-- | libcrystfel/src/image.h | 19 | ||||
-rw-r--r-- | libcrystfel/src/stream.h | 3 | ||||
-rw-r--r-- | src/im-sandbox.c | 2 | ||||
-rw-r--r-- | src/indexamajig.c | 18 | ||||
-rw-r--r-- | src/process_image.h | 2 |
6 files changed, 155 insertions, 18 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 2cc0d792..f322cbdd 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -299,3 +299,132 @@ void free_all_crystals(struct image *image) free(image->crystals); image->n_crystals = 0; } + + +/**************************** Image field lists *******************************/ + +struct imagefile_field_list +{ + char **fields; + int n_fields; + int max_fields; +}; + + +struct imagefile_field_list *new_imagefile_field_list() +{ + struct imagefile_field_list *n; + + n = calloc(1, sizeof(struct imagefile_field_list)); + if ( n == NULL ) return NULL; + + n->max_fields = 32; + n->fields = malloc(n->max_fields*sizeof(char *)); + if ( n->fields == NULL ) { + free(n); + return NULL; + } + + return n; +} + + +void free_imagefile_field_list(struct imagefile_field_list *n) +{ + int i; + for ( i=0; i<n->n_fields; i++ ) { + free(n->fields[i]); + } + free(n->fields); + free(n); +} + + +void add_imagefile_field(struct imagefile_field_list *copyme, const char *name) +{ + int i; + + /* Already on the list? Don't re-add if so. */ + for ( i=0; i<copyme->n_fields; i++ ) { + if ( strcmp(copyme->fields[i], name) == 0 ) return; + } + + /* Need more space? */ + if ( copyme->n_fields == copyme->max_fields ) { + + char **nfields; + int nmax = copyme->max_fields + 32; + + nfields = realloc(copyme->fields, nmax*sizeof(char *)); + if ( nfields == NULL ) { + ERROR("Failed to allocate space for new HDF5 field.\n"); + return; + } + + copyme->max_fields = nmax; + copyme->fields = nfields; + + } + + copyme->fields[copyme->n_fields] = strdup(name); + if ( copyme->fields[copyme->n_fields] == NULL ) { + ERROR("Failed to add field for copying '%s'\n", name); + return; + } + + copyme->n_fields++; +} + + +/****************************** Image files ***********************************/ + +struct imagefile *imagefile_open(const char *filename) +{ +} + + +int imagefile_read(struct imagefile *imfile, struct image *image, + struct event *event) +{ +} + + +struct hdfile *imagefile_get_hdfile(struct imagefile *imfile) +{ +} + + +void imagefile_copy_fields(struct imagefile *f, + const struct imagefile_field_list *copyme, + FILE *fh, struct event *ev) +{ + int i; + + if ( copyme == NULL ) return; + + for ( i=0; i<copyme->n_fields; i++ ) { + +#warning FIXME Implement imagefile field copying +#if 0 + char *val; + char *field; + + field = copyme->fields[i]; + val = hdfile_get_string_value(f, field, ev); + + if ( field[0] == '/' ) { + fprintf(fh, "hdf5%s = %s\n", field, val); + } else { + fprintf(fh, "hdf5/%s = %s\n", field, val); + } + + free(val); +#endif + + } +} + + +void imagefile_close(struct imagefile *imfile) +{ +} diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index 2ed7140f..f310a09b 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -123,7 +123,7 @@ struct beam_params * struct detector *det; * struct beam_params *beam; * char *filename; - * const struct copy_hdf5_field *copyme; + * const struct imagefile_field_list *copyme; * * int id; * @@ -155,8 +155,8 @@ struct beam_params * returned by the low-level indexing system. <structfield>n_crystals</structfield> * is the number of crystals which were found in the image. * - * <structfield>copyme</structfield> represents a list of HDF5 fields to copy - * to the output stream. + * <structfield>copyme</structfield> represents a list of fields in the image + * file (e.g. HDF5 fields or CBF headers) to copy to the output stream. **/ struct image; @@ -174,7 +174,7 @@ struct image { struct beam_params *beam; /* The nominal beam parameters */ char *filename; struct event *event; - const struct copy_hdf5_field *copyme; + const struct imagefile_field_list *copyme; struct stuff_from_stream *stuff_from_stream; double avg_clen; /* Average camera length extracted @@ -242,10 +242,17 @@ extern int imagefile_read(struct imagefile *imfile, struct image *image, struct event *event); extern struct hdfile *imagefile_get_hdfile(struct imagefile *imfile); extern void imagefile_copy_fields(struct imagefile *imfile, - struct copy_hdf5_file *copyme, FILE *fh, - struct event *ev); + const struct imagefile_field_list *copyme, + FILE *fh, struct event *ev); extern void imagefile_close(struct imagefile *imfile); +/* Field lists */ +extern struct imagefile_field_list *new_imagefile_field_list(void); +extern void free_imagefile_field_list(struct imagefile_field_list *f); + +extern void add_imagefile_field(struct imagefile_field_list *copyme, + const char *name); + #ifdef __cplusplus } #endif diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h index a95c7df0..764e3e36 100644 --- a/libcrystfel/src/stream.h +++ b/libcrystfel/src/stream.h @@ -39,6 +39,7 @@ struct image; struct hdfile; struct event; +struct imagefile; #include "cell.h" #define GEOM_START_MARKER "----- Begin geometry file -----" @@ -106,7 +107,7 @@ extern int read_chunk(Stream *st, struct image *image); extern int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf); -extern int write_chunk(Stream *st, struct image *image, struct hdfile *hdfile, +extern int write_chunk(Stream *st, struct image *image, struct imagefile *imfile, int include_peaks, int include_reflections, struct event *ev); diff --git a/src/im-sandbox.c b/src/im-sandbox.c index 2dabf3e9..60400ad8 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -375,7 +375,7 @@ static void run_work(const struct index_args *iargs, Stream *st, cleanup_indexing(iargs->ipriv); free_detector_geometry(iargs->det); free(iargs->hdf5_peak_path); - free_copy_hdf5_field_list(iargs->copyme); + free_imagefile_field_list(iargs->copyme); cell_free(iargs->cell); if ( iargs->profile ) time_accounts_print(taccs); time_accounts_free(taccs); diff --git a/src/indexamajig.c b/src/indexamajig.c index f48fac17..439f9be3 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -172,9 +172,9 @@ static void show_help(const char *s) } -static void add_geom_beam_stuff_to_copy_hdf5(struct copy_hdf5_field *copyme, - struct detector *det, - struct beam_params *beam) +static void add_geom_beam_stuff_to_field_list(struct imagefile_field_list *copyme, + struct detector *det, + struct beam_params *beam) { int i; @@ -183,12 +183,12 @@ static void add_geom_beam_stuff_to_copy_hdf5(struct copy_hdf5_field *copyme, struct panel *p = &det->panels[i]; if ( p->clen_from != NULL ) { - add_copy_hdf5_field(copyme, p->clen_from); + add_imagefile_field(copyme, p->clen_from); } } if ( beam->photon_energy_from != NULL ) { - add_copy_hdf5_field(copyme, beam->photon_energy_from); + add_imagefile_field(copyme, beam->photon_energy_from); } } @@ -257,7 +257,7 @@ int main(int argc, char *argv[]) iargs.stream_peaks = 1; iargs.stream_refls = 1; iargs.int_diag = INTDIAG_NONE; - iargs.copyme = new_copy_hdf5_field_list(); + iargs.copyme = new_imagefile_field_list(); if ( iargs.copyme == NULL ) { ERROR("Couldn't allocate HDF5 field list.\n"); return 1; @@ -431,7 +431,7 @@ int main(int argc, char *argv[]) break; case 10 : - add_copy_hdf5_field(iargs.copyme, optarg); + add_imagefile_field(iargs.copyme, optarg); break; case 11 : @@ -627,7 +627,7 @@ int main(int argc, char *argv[]) geom_filename); return 1; } - add_geom_beam_stuff_to_copy_hdf5(iargs.copyme, iargs.det, iargs.beam); + add_geom_beam_stuff_to_field_list(iargs.copyme, iargs.det, iargs.beam); /* If no peak path from geometry file, use these (but see later) */ if ( iargs.hdf5_peak_path == NULL ) { @@ -806,7 +806,7 @@ int main(int argc, char *argv[]) create_sandbox(&iargs, n_proc, prefix, config_basename, fh, st, tempdir); - free_copy_hdf5_field_list(iargs.copyme); + free_imagefile_field_list(iargs.copyme); cell_free(iargs.cell); free(iargs.beam->photon_energy_from); free(prefix); diff --git a/src/process_image.h b/src/process_image.h index d63679cf..14f90c78 100644 --- a/src/process_image.h +++ b/src/process_image.h @@ -80,7 +80,7 @@ struct index_args int min_pix_count; int max_pix_count; int local_bg_radius; - struct copy_hdf5_field *copyme; + struct imagefile_field_list *copyme; int integrate_saturated; int use_saturated; int no_revalidate; |