aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-03-06 19:07:47 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:17 +0100
commit1eed22ddf6c38b248c09b8d78b7677981f19fe5f (patch)
treea5d58b46d90ed290a3c43bfd8928fa895eb693e3 /src
parentc4ea30cbf98a29cbe1dce13b9eca22f92dfa9ef9 (diff)
sum_stack: Get image size from first image
Diffstat (limited to 'src')
-rw-r--r--src/sum_stack.c82
1 files changed, 72 insertions, 10 deletions
diff --git a/src/sum_stack.c b/src/sum_stack.c
index 570ba3fc..e7b1245f 100644
--- a/src/sum_stack.c
+++ b/src/sum_stack.c
@@ -55,7 +55,6 @@ struct sum_args
struct queue_args
{
FILE *fh;
- char *prefix;
int config_cmfilter;
int config_noisefilter;
double *sum;
@@ -64,6 +63,10 @@ struct queue_args
SumMethod sum_method;
double threshold;
double min_gradient;
+
+ char *use_this_one_instead;
+ char *prefix;
+ int config_basename;
};
@@ -226,15 +229,11 @@ out:
static void *get_image(void *qp)
{
- char line[1024];
+ char *line;
struct sum_args *pargs;
char *rval;
struct queue_args *qargs = qp;
- /* Get the next filename */
- rval = fgets(line, 1023, qargs->fh);
- if ( rval == NULL ) return NULL;
-
pargs = malloc(sizeof(struct sum_args));
pargs->w = qargs->w;
@@ -246,9 +245,34 @@ static void *get_image(void *qp)
pargs->config_noisefilter = qargs->config_noisefilter;
pargs->sum = qargs->sum;
- chomp(line);
- pargs->filename = malloc(strlen(qargs->prefix) + strlen(line) + 1);
+ /* Get the next filename */
+ if ( qargs->use_this_one_instead != NULL ) {
+
+ line = qargs->use_this_one_instead;
+ qargs->use_this_one_instead = NULL;
+
+ } else {
+
+ line = malloc(1024*sizeof(char));
+ rval = fgets(line, 1023, qargs->fh);
+ if ( rval == NULL ) {
+ free(pargs);
+ return NULL;
+ }
+ chomp(line);
+
+ }
+
+ if ( qargs->config_basename ) {
+ char *tmp;
+ tmp = safe_basename(line);
+ free(line);
+ line = tmp;
+ }
+
+ pargs->filename = malloc(strlen(qargs->prefix)+strlen(line)+1);
snprintf(pargs->filename, 1023, "%s%s", qargs->prefix, line);
+ free(line);
return pargs;
}
@@ -273,6 +297,12 @@ int main(int argc, char *argv[])
struct queue_args qargs;
int n_done;
const int chunk_size = 1000;
+ struct hdfile *hdfile;
+ struct image image;
+ char *prepare_line;
+ char prepare_filename[1024];
+ char *rval;
+ int config_basename = 0;
/* Long options */
const struct option longopts[] = {
@@ -286,6 +316,7 @@ int main(int argc, char *argv[])
{"intermediate", 1, NULL, 'p'},
{"threshold", 1, NULL, 't'},
{"min-gradient", 1, NULL, 4},
+ {"basename", 0, &config_basename, 1},
{0, 0, NULL, 0}
};
@@ -380,10 +411,41 @@ int main(int argc, char *argv[])
return 1;
}
- qargs.w = 1024; /* FIXME! */
- qargs.h = 1024; /* FIXME! */
+ /* Get first filename and use it to set up the summed array */
+ prepare_line = malloc(1024*sizeof(char));
+ rval = fgets(prepare_line, 1023, fh);
+ if ( rval == NULL ) {
+ ERROR("Failed to get filename to prepare indexing.\n");
+ return 1;
+ }
+ chomp(prepare_line);
+ if ( config_basename ) {
+ char *tmp;
+ tmp = safe_basename(prepare_line);
+ free(prepare_line);
+ prepare_line = tmp;
+ }
+ snprintf(prepare_filename, 1023, "%s%s", prefix, prepare_line);
+ qargs.use_this_one_instead = prepare_line;
+
+ hdfile = hdfile_open(prepare_filename);
+ if ( hdfile == NULL ) {
+ ERROR("Couldn't open '%s'\n", prepare_filename);
+ return 1;
+ }
+
+ if ( hdf5_read(hdfile, &image, 0) ) {
+ ERROR("Couldn't read '%s'\n", prepare_filename);
+ return 1;
+ }
+
+ hdfile_close(hdfile);
+ qargs.w = image.width;
+ qargs.h = image.height;
+
qargs.sum_method = sum;
qargs.threshold = threshold;
+ qargs.config_basename = config_basename;
qargs.config_cmfilter = config_cmfilter;
qargs.config_noisefilter = config_noisefilter;
qargs.sum = calloc(qargs.w*qargs.h, sizeof(double));