diff options
author | Thomas White <taw@physics.org> | 2019-06-04 17:05:50 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-06-04 17:05:50 +0200 |
commit | 02af27133bb83a2ca187d52623d9db35375489a7 (patch) | |
tree | 2409def99ee5d0f2c7f5b12db2957a50e46d6a74 /libcrystfel | |
parent | a701ed47b95e13d5d7d174f9ba79895329eee985 (diff) |
spectrum_set_pdf: Use gsl_sort_index() instead of gsl_sort2()
This allows compatibility with older versions of GSL.
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/spectrum.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libcrystfel/src/spectrum.c b/libcrystfel/src/spectrum.c index a1b1c899..be454a59 100644 --- a/libcrystfel/src/spectrum.c +++ b/libcrystfel/src/spectrum.c @@ -348,6 +348,9 @@ static void normalise_pdf(double *k, double *pdf, int n) */ void spectrum_set_pdf(Spectrum *s, double *kvals, double *heights, int n) { + size_t *perm; + int i; + /* Free old contents (if any - may be NULL) */ free(s->gaussians); free(s->k); @@ -359,12 +362,20 @@ void spectrum_set_pdf(Spectrum *s, double *kvals, double *heights, int n) s->pdf = malloc(n * sizeof(double)); if ( s->pdf == NULL ) return; - memcpy(s->k, kvals, n*sizeof(double)); - memcpy(s->pdf, heights, n*sizeof(double)); + perm = malloc(n * sizeof(size_t)); + if ( perm == NULL ) return; + + gsl_sort_index(perm, kvals, 1, n); + + for ( i=0; i<n; i++ ) { + s->k[i] = kvals[perm[i]]; + s->pdf[i] = heights[perm[i]]; + } + free(perm); + s->n_samples = n; s->rep = SPEC_HISTOGRAM; - gsl_sort2(s->k, 1, s->pdf, 1, n); normalise_pdf(s->k, s->pdf, s->n_samples); } |