aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/detector.c21
-rw-r--r--libcrystfel/src/events.c33
-rw-r--r--libcrystfel/src/events.h3
3 files changed, 31 insertions, 26 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index d4d8b768..b44f2d43 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -956,10 +956,25 @@ static int parse_field_for_panel(struct panel *panel, const char *key,
reject = 1;
}
} else if ( strncmp(key, "dim", 3) == 0) {
- if ( panel->dim_structure == NULL ) {
- panel->dim_structure = initialize_dim_structure();
+ int dim_entry;
+ char *endptr;
+ if ( key[3] != '\0' ) {
+ if ( panel->dim_structure == NULL ) {
+ panel->dim_structure = initialize_dim_structure();
+ }
+ dim_entry = strtoul(key+3, &endptr, 10);
+ if ( endptr[0] != '\0' ) {
+ ERROR("Invalid dimension number %s\n", key+3);
+ } else {
+ if ( set_dim_structure_entry(panel->dim_structure,
+ dim_entry, val) )
+ {
+ ERROR("Failed to set dim structure entry\n");
+ }
+ }
+ } else {
+ ERROR("'dim' must be followed by a number, e.g. 'dim0'\n");
}
- set_dim_structure_entry(panel->dim_structure, key, val);
} else {
ERROR("Unrecognised field '%s'\n", key);
}
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c
index d0e521d3..c73a816c 100644
--- a/libcrystfel/src/events.c
+++ b/libcrystfel/src/events.c
@@ -646,8 +646,8 @@ struct dim_structure *default_dim_structure()
hsd = initialize_dim_structure();
- set_dim_structure_entry(hsd, "dim0", "ss");
- set_dim_structure_entry(hsd, "dim1", "fs");
+ set_dim_structure_entry(hsd, 0, "ss");
+ set_dim_structure_entry(hsd, 1, "fs");
return hsd;
}
@@ -675,37 +675,28 @@ static int parse_dim_structure_val(const char *val)
}
-int set_dim_structure_entry(struct dim_structure *hsd, const char *string_dim,
+int set_dim_structure_entry(struct dim_structure *hsd, int dim_entry,
const char *val_string)
{
- int dim_entry;
-
- dim_entry = atoi(string_dim+3)+1;
-
- if ( dim_entry > hsd->num_dims ) {
+ /* "dims" array needs element with zero index */
+ if ( dim_entry >= hsd->num_dims ) {
int di;
- int *new_dims = malloc(dim_entry*sizeof(int));
- if ( new_dims == NULL ) return 0;
+ int *new_dims = realloc(hsd->dims, (dim_entry+1)*sizeof(int));
+ if ( new_dims == NULL ) return 1;
- for ( di=0; di<dim_entry; di++ ) {
+ /* Initialise the elements just allocated */
+ for ( di=hsd->num_dims; di<=dim_entry; di++ ) {
new_dims[di] = HYSL_UNDEFINED;
}
- for ( di=0; di<hsd->num_dims; di++ ) {
- new_dims[di] = hsd->dims[di];
- }
-
- new_dims[dim_entry-1] = parse_dim_structure_val(val_string);
- free(hsd->dims);
hsd->dims = new_dims;
- hsd->num_dims = dim_entry;
-
- return 1;
+ hsd->num_dims = dim_entry+1;
}
hsd->dims[dim_entry] = parse_dim_structure_val(val_string);
- return 1;
+
+ return 0;
}
diff --git a/libcrystfel/src/events.h b/libcrystfel/src/events.h
index 4f717209..d7fae24a 100644
--- a/libcrystfel/src/events.h
+++ b/libcrystfel/src/events.h
@@ -98,8 +98,7 @@ extern void free_event_list(struct event_list *el);
extern struct dim_structure *initialize_dim_structure(void);
extern struct dim_structure *default_dim_structure(void);
extern int set_dim_structure_entry(struct dim_structure *hsd,
- const char *string_dim,
- const char *val_string);
+ int dim_entry, const char *val_string);
extern void free_dim_structure_entry(struct dim_structure *hsd);
extern void free_dim_structure(struct dim_structure *hsd);