Skip to content

Commit 0322ddc

Browse files
authored
Merge pull request #2272 from willend/main
Fix cross-platform sort-order issue in PowderN
2 parents 7029032 + e555004 commit 0322ddc

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

mcstas-comps/examples/ILL/ILL_H22_D1B/ILL_H22_D1B.instr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* obtained by scanning the temperature. A complete thermal variation of the
3434
* diffraction patterns (1.5 - 300 K) can be achieved in few hours (3-5h).
3535
*
36-
* %Example: lambda=2.52 Detector: D1B_BananaTheta_I=5097.25
36+
* %Example: lambda=2.52 Detector: D1B_BananaTheta_I=4400
3737
*
3838
* %Parameters:
3939
* lambda: [AA] mean incident wavelength.

mcstas-comps/samples/PowderN.comp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,24 @@ struct line_info_struct
268268

269269
// PN_list_compare *****************************************************************
270270

271-
int PN_list_compare (void const *a, void const *b)
272-
{
273-
struct line_data const *pa = a;
274-
struct line_data const *pb = b;
275-
double s = pa->q - pb->q;
271+
int PN_list_compare(const void *a, const void *b)
272+
{
273+
const struct line_data *pa = a;
274+
const struct line_data *pb = b;
275+
276+
/* Sort by q */
277+
if (pa->q < pb->q) return -1;
278+
if (pa->q > pb->q) return 1;
279+
280+
/* In case of tie, sort by F2 also */
281+
if (pa->F2 < pb->F2) return -1;
282+
if (pa->F2 > pb->F2) return 1;
276283

277-
if (!s) return 0;
278-
else return (s < 0 ? -1 : 1);
284+
/* In case of tie, sort by j also */
285+
if (pa->j < pb->j) return -1;
286+
if (pa->j > pb->j) return 1;
287+
288+
return 0;
279289
} /* PN_list_compare */
280290

281291
#ifndef CIF2HKL
@@ -1140,7 +1150,7 @@ TRACE
11401150

11411151

11421152
l_1 = v*(t3 - t2 + t1 - t0); /* Length to exit */
1143-
1153+
11441154
pmul *= Nq*l_full*my_s_n *exp(-(line_info.my_a_v/v+my_s)*(l+l_1))
11451155
/(1-(p_inc+p_transmit));
11461156

mcstas-comps/union/Powder_process.comp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,24 @@ SHARE
138138

139139
// PN_list_compare *****************************************************************
140140

141-
int PN_list_compare_union (void const *a, void const *b)
142-
{
143-
struct line_data_union const *pa = a;
144-
struct line_data_union const *pb = b;
145-
double s = pa->q - pb->q;
146-
147-
if (!s) return 0;
148-
else return (s < 0 ? -1 : 1);
141+
int PN_list_compare_union(const void *a, const void *b)
142+
{
143+
const struct line_data_union *pa = a;
144+
const struct line_data_union *pb = b;
145+
146+
/* Sort by q */
147+
if (pa->q < pb->q) return -1;
148+
if (pa->q > pb->q) return 1;
149+
150+
/* In case of tie, sort by F2 also */
151+
if (pa->F2 < pb->F2) return -1;
152+
if (pa->F2 > pb->F2) return 1;
153+
154+
/* In case of tie, sort by j also */
155+
if (pa->j < pb->j) return -1;
156+
if (pa->j > pb->j) return 1;
157+
158+
return 0;
149159
} /* PN_list_compare */
150160

151161
int read_line_data_union(char *SC_file, struct line_info_struct_union *info)

mcxtrace-comps/samples/PowderN.comp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,24 @@ SHARE
261261
// used for qsort, to sort reflections
262262
// input: a,b: two 'line_data' reflection pointers.
263263
// output: -1,0,1 for a<b, a=b, a>b
264-
int PN_list_compare (void const *a, void const *b)
265-
{
266-
struct line_data const *pa = a;
267-
struct line_data const *pb = b;
268-
double s = pa->q - pb->q;
264+
int PN_list_compare(const void *a, const void *b)
265+
{
266+
const struct line_data *pa = a;
267+
const struct line_data *pb = b;
268+
269+
/* Sort by q */
270+
if (pa->q < pb->q) return -1;
271+
if (pa->q > pb->q) return 1;
272+
273+
/* In case of tie, sort by F2 also */
274+
if (pa->F2 < pb->F2) return -1;
275+
if (pa->F2 > pb->F2) return 1;
269276

270-
if (!s) return 0;
271-
else return (s < 0 ? -1 : 1);
277+
/* In case of tie, sort by j also */
278+
if (pa->j < pb->j) return -1;
279+
if (pa->j > pb->j) return 1;
280+
281+
return 0;
272282
} /* PN_list_compare */
273283

274284
#ifndef CIF2HKL

0 commit comments

Comments
 (0)