File harminv_change_protos_with_harminv_complex.patch of Package harminv

From: Michel Normand <normand@linux.vnet.ibm.com>
Subject: harminv change protos with harminv complex
Date: Mon, 23 Feb 2015 10:05:08 +0100

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 <normand@linux.vnet.ibm.com>
---
 harminv-main.c |   18 ++++++++++++------
 harminv.c      |   10 ++++++----
 harminv.h      |    4 ++--
 3 files changed, 20 insertions(+), 12 deletions(-)

Index: harminv-1.3.1/harminv.h
===================================================================
--- harminv-1.3.1.orig/harminv.h
+++ harminv-1.3.1/harminv.h
@@ -50,8 +50,8 @@ extern int harminv_get_num_freqs(harminv
 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 */
Index: harminv-1.3.1/harminv.c
===================================================================
--- harminv-1.3.1.orig/harminv.c
+++ harminv-1.3.1/harminv.c
@@ -839,21 +839,23 @@ double harminv_get_Q(harminv_data d, int
 	    / (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)
Index: harminv-1.3.1/harminv-main.c
===================================================================
--- harminv-1.3.1.orig/harminv-main.c
+++ harminv-1.3.1/harminv-main.c
@@ -179,6 +179,7 @@ static int compar(const void *a, const v
 {
      const int *ia = (const int *) a;
      const int *ib = (const int *) b;
+     cmplx aa, ab;
 
      switch (sortby) {
 	 case SORT_FREQUENCY:
@@ -189,8 +190,9 @@ static int compar(const void *a, const v
 	      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));
@@ -212,6 +214,7 @@ static int mode_ok(harminv_data d, int k
      mode_ok_data *ok_d = (mode_ok_data *) ok_d_;
      double errk, ampk, f;
      int ok;
+     cmplx aa;
 
      if (k == -1) { /* initialize */
 	  int i;
@@ -219,12 +222,14 @@ static int mode_ok(harminv_data d, int k
 	  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;
 	  
 	  }
@@ -245,7 +250,8 @@ static int mode_ok(harminv_data d, int k
 
      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
@@ -460,7 +466,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,
openSUSE Build Service is sponsored by