From 9f948988925efa060b0a861f20ae80cb21a6d5fd Mon Sep 17 00:00:00 2001 From: Michel Normand Date: Mon, 23 Feb 2015 10:05:08 +0100 Subject: [PATCH] harminv change protos with harminv complex harminv change protos with harminv complex This patch concern the harminv package, this is a prereq to a similar patch for meep package. This is related to meep issue 13 https://github.com/stevengj/meep/issues/13 Signed-off-by: Michel Normand --- harminv-main.c | 18 ++++++++++++------ harminv.c | 10 ++++++---- harminv.h | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/harminv-main.c b/harminv-main.c index ce81f70..26c3659 100644 --- a/harminv-main.c +++ b/harminv-main.c @@ -175,6 +175,7 @@ static int compar(const void *a, const void *b) { const int *ia = (const int *) a; const int *ib = (const int *) b; + cmplx aa, ab; switch (sortby) { case SORT_FREQUENCY: @@ -185,8 +186,9 @@ static int compar(const void *a, const void *b) return cmp(harminv_get_freq_error(hd, *ia), harminv_get_freq_error(hd, *ib)); case SORT_AMPLITUDE: - return cmp(cabs(harminv_get_amplitude(hd, *ia)), - cabs(harminv_get_amplitude(hd, *ib))); + harminv_get_amplitude(&aa, hd, *ia); + harminv_get_amplitude(&ab, hd, *ia); + return cmp(cabs(aa), cabs(ab)); case SORT_Q: return cmp(harminv_get_freq(hd,*ia) / harminv_get_decay(hd,*ia), harminv_get_freq(hd,*ib) / harminv_get_decay(hd,*ib)); @@ -208,6 +210,7 @@ static int mode_ok(harminv_data d, int k, void *ok_d_) mode_ok_data *ok_d = (mode_ok_data *) ok_d_; double errk, ampk, f; int ok; + cmplx aa; if (k == -1) { /* initialize */ int i; @@ -215,12 +218,14 @@ static int mode_ok(harminv_data d, int k, void *ok_d_) if (!harminv_get_num_freqs(d)) return 0; ok_d->min_err = harminv_get_freq_error(d, 0);; - ok_d->max_amp = cabs(harminv_get_amplitude(d, 0)); + harminv_get_amplitude(&aa, d, 0); + ok_d->max_amp = cabs(aa); for (i = 1; i < harminv_get_num_freqs(d); ++i) { double err, amp; if ((err = harminv_get_freq_error(d, i)) < ok_d->min_err) ok_d->min_err = err; - if ((amp = cabs(harminv_get_amplitude(d, i))) > ok_d->max_amp) + harminv_get_amplitude(&aa, d, i); + if ((amp = cabs(aa)) > ok_d->max_amp) ok_d->max_amp = amp; } @@ -241,7 +246,8 @@ static int mode_ok(harminv_data d, int k, void *ok_d_) f = fabs(harminv_get_freq(d, k)); errk = harminv_get_freq_error(d, k); - ampk = cabs(harminv_get_amplitude(d, k)); + harminv_get_amplitude(&aa, d, k); + ampk = cabs(aa); ok = ((!ok_d->only_f_inrange || (f >= ok_d->fmin && f <= ok_d->fmax)) && errk <= ok_d->err_thresh @@ -461,7 +467,7 @@ int main(int argc, char **argv) #endif freq = harminv_get_freq(hd, j) / dt; decay = harminv_get_decay(hd, j) / fabs(dt); - amp = harminv_get_amplitude(hd, j); + harminv_get_amplitude(&, hd, j); err = harminv_get_freq_error(hd, j); printf("%g, %e, %g, %g, %g, %e\n", freq * (specify_omega ? TWOPI : 1.0), decay, diff --git a/harminv.c b/harminv.c index ae8cc98..f7e416e 100644 --- a/harminv.c +++ b/harminv.c @@ -839,21 +839,23 @@ double harminv_get_Q(harminv_data d, int k) / (2 * harminv_get_decay(d, k))); } -cmplx harminv_get_omega(harminv_data d, int k) +void harminv_get_omega(cmplx *omega, harminv_data d, int k) { CHECK(d->nfreqs >= 0, "haven't computed eigensolutions yet"); CHECK(k >= 0 && k < d->nfreqs, "argument out of range in harminv_get_omega"); - return(I * clog(d->u[k])); + *omega = (I * clog(d->u[k])); + return; } -cmplx harminv_get_amplitude(harminv_data d, int k) +void harminv_get_amplitude(cmplx *amplitude, harminv_data d, int k) { CHECK(k >= 0 && k < d->nfreqs, "argument out of range in harminv_get_amplitude"); if (!d->amps) d->amps = harminv_compute_amplitudes(d); - return d->amps[k]; + *amplitude = d->amps[k]; + return; } double harminv_get_freq_error(harminv_data d, int k) diff --git a/harminv.h b/harminv.h index 8fdf34c..d41df0f 100644 --- a/harminv.h +++ b/harminv.h @@ -50,8 +50,8 @@ extern int harminv_get_num_freqs(harminv_data d); extern double harminv_get_freq(harminv_data d, int k); extern double harminv_get_Q(harminv_data d, int k); extern double harminv_get_decay(harminv_data d, int k); -extern harminv_complex harminv_get_omega(harminv_data d, int k); -extern harminv_complex harminv_get_amplitude(harminv_data d, int k); +extern void harminv_get_omega(harminv_complex *omega, harminv_data d, int k); +extern void harminv_get_amplitude(harminv_complex *amplitude, harminv_data d, int k); extern double harminv_get_freq_error(harminv_data d, int k); /* the following routines are undocumented and not recommended */