aboutsummaryrefslogtreecommitdiff
path: root/src/list_tmp.h
blob: a524b2f9b5c7993b2e758b54e948e675ea27ab9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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