Skip to content

Commit

Permalink
harminv change protos with harminv complex
Browse files Browse the repository at this point in the history
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
NanoComp/meep#13

Signed-off-by: Michel Normand <normand@linux.vnet.ibm.com>
  • Loading branch information
michelmno committed Feb 26, 2015
1 parent 24de4ef commit 9f94898
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
18 changes: 12 additions & 6 deletions harminv-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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));
Expand All @@ -208,19 +210,22 @@ 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;
ok_d->num_ok = 0;
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;

}
Expand All @@ -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
Expand Down Expand Up @@ -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(&amp, hd, j);
err = harminv_get_freq_error(hd, j);
printf("%g, %e, %g, %g, %g, %e\n",
freq * (specify_omega ? TWOPI : 1.0), decay,
Expand Down
10 changes: 6 additions & 4 deletions harminv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions harminv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 9f94898

Please sign in to comment.