aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/list_tmp.h
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-11-15 12:05:55 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:40 +0100
commit38089071300b8e04ed42236dd08d9055094fb3b8 (patch)
tree91e1487ac820eb549e7652750867cd4fec039097 /libcrystfel/src/list_tmp.h
parent404c612223dbfa0210902ebc5c9226927335aa65 (diff)
Introduce "libcrystfel"
Diffstat (limited to 'libcrystfel/src/list_tmp.h')
-rw-r--r--libcrystfel/src/list_tmp.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/libcrystfel/src/list_tmp.h b/libcrystfel/src/list_tmp.h
new file mode 100644
index 00000000..a524b2f9
--- /dev/null
+++ b/libcrystfel/src/list_tmp.h
@@ -0,0 +1,106 @@
+/*
+ * Template for creating indexed 3D lists of a given type, usually indexed
+ * as signed h,k,l values where -INDMAX<={h,k,l}<=+INDMAX.
+ *
+ * These are used, for example, for:
+ * - a list of 'double complex' values for storing structure factors,
+ * - a list of 'double' values for storing reflection intensities,
+ * - a list of 'unsigned int' values for counts of some sort.
+ *
+ * When LABEL and TYPE are #defined appropriately, including this header
+ * defines functions such as:
+ * - new_list_<LABEL>(), for creating a new list of the given type,
+ * - set_<LABEL>(), for setting a value in a list,
+ * - lookup_<LABEL>(), for retrieving values from a list,
+ * ..and so on.
+ *
+ * See src/utils.h for more information.
+ *
+ */
+
+#include <stdio.h>
+
+#define ERROR_T(...) fprintf(stderr, __VA_ARGS__)
+
+static inline void LABEL(integrate)(TYPE *ref, signed int h,
+ signed int k, signed int l,
+ TYPE i)
+{
+ int idx;
+
+ if ( (abs(h) > INDMAX) || (abs(k) > INDMAX) || (abs(l) > INDMAX) ) {
+ ERROR_T("\nReflection %i %i %i is out of range!\n", h, k, l);
+ ERROR_T("You need to re-configure INDMAX and re-run.\n");
+ exit(1);
+ }
+
+ if ( h < 0 ) h += IDIM;
+ if ( k < 0 ) k += IDIM;
+ if ( l < 0 ) l += IDIM;
+
+ idx = h + (IDIM*k) + (IDIM*IDIM*l);
+ ref[idx] += i;
+}
+
+
+static inline void LABEL(set)(TYPE *ref, signed int h,
+ signed int k, signed int l,
+ TYPE i)
+{
+ int idx;
+
+ if ( (abs(h) > INDMAX) || (abs(k) > INDMAX) || (abs(l) > INDMAX) ) {
+ ERROR_T("\nReflection %i %i %i is out of range!\n", h, k, l);
+ ERROR_T("You need to re-configure INDMAX and re-run.\n");
+ exit(1);
+ }
+
+ if ( h < 0 ) h += IDIM;
+ if ( k < 0 ) k += IDIM;
+ if ( l < 0 ) l += IDIM;
+
+ idx = h + (IDIM*k) + (IDIM*IDIM*l);
+ ref[idx] = i;
+}
+
+
+static inline TYPE LABEL(lookup)(const TYPE *ref, signed int h,
+ signed int k, signed int l)
+{
+ int idx;
+
+ if ( (abs(h) > INDMAX) || (abs(k) > INDMAX) || (abs(l) > INDMAX) ) {
+ ERROR_T("\nReflection %i %i %i is out of range!\n", h, k, l);
+ ERROR_T("You need to re-configure INDMAX and re-run.\n");
+ exit(1);
+ }
+
+ if ( h < 0 ) h += IDIM;
+ if ( k < 0 ) k += IDIM;
+ if ( l < 0 ) l += IDIM;
+
+ idx = h + (IDIM*k) + (IDIM*IDIM*l);
+ return ref[idx];
+}
+
+
+static inline TYPE *LABEL(new_list)(void)
+{
+ TYPE *r;
+ size_t r_size;
+ r_size = IDIM*IDIM*IDIM*sizeof(TYPE);
+ r = malloc(r_size);
+ memset(r, 0, r_size);
+ return r;
+}
+
+
+static inline void LABEL(zero_list)(TYPE *ref)
+{
+ memset(ref, 0, IDIM*IDIM*IDIM*sizeof(TYPE));
+}
+
+
+#undef LABEL
+#undef TYPE
+#undef ERROR_T