aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-09-26 14:00:33 +0200
committerThomas White <taw@physics.org>2018-09-26 14:56:50 +0200
commitabc9ed8e31fde81f893043ba67c41d18629747ed (patch)
tree0c6938bdc19fc194b92deb54b372dadeea3a95b5 /libcrystfel/src
parentfaa55d4c60589587ec8760b52a3b864cf69ed4aa (diff)
parse_symmetry_operations(): Handle numbers, e.g. k-2h
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/symmetry.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/libcrystfel/src/symmetry.c b/libcrystfel/src/symmetry.c
index 5f3b67f2..06cc368c 100644
--- a/libcrystfel/src/symmetry.c
+++ b/libcrystfel/src/symmetry.c
@@ -36,6 +36,7 @@
#include <string.h>
#include <math.h>
#include <assert.h>
+#include <ctype.h>
#include "symmetry.h"
#include "utils.h"
@@ -1656,19 +1657,45 @@ static IntegerMatrix *parse_symmetry_operation(const char *s)
int c;
size_t cl;
- int sign = +1;
- int nh = 0;
- int nk = 0;
- int nl = 0;
-
+ signed int nh = 0;
+ signed int nk = 0;
+ signed int nl = 0;
+ signed int mult = 1;
+ int ndigit = 0;
+ signed int sign = +1;
+
+ /* We have one expression something like "-2h+k" */
cl = strlen(els[i]);
-
for ( c=0; c<cl; c++ ) {
- if ( els[i][c] == '-' ) sign = -1;
- if ( els[i][c] == '+' ) sign = +1;
- if ( els[i][c] == 'h' ) nh += sign;
- if ( els[i][c] == 'k' ) nk += sign;
- if ( els[i][c] == 'l' ) nl += sign;
+
+ if ( els[i][c] == '-' ) sign *= -1;
+ if ( els[i][c] == 'h' ) {
+ nh = mult*sign;
+ mult = 1;
+ ndigit = 0;
+ sign = +1;
+ }
+ if ( els[i][c] == 'k' ) {
+ nk = mult*sign;
+ mult = 1;
+ ndigit = 0;
+ sign = +1;
+ }
+ if ( els[i][c] == 'l' ) {
+ nl = mult*sign;
+ mult = 1;
+ ndigit = 0;
+ sign = +1;
+ }
+ if ( isdigit(els[i][c]) ) {
+ if ( ndigit > 0 ) {
+ mult *= 10;
+ mult += els[i][c] - '0';
+ } else {
+ mult *= els[i][c] - '0';
+ }
+ ndigit++;
+ }
}
intmat_set(m, i, 0, nh);