1 /*
2  * fortran-module.c
3  *
4  *  Created on: 31/mag/2011
5  *      Author: leonardo
6  */
7 
8 #include <mps/mps.h>
9 
10 /**
11  * @brief Caller for mps_solve routine.
12  *
13  * Since fortran complex are
14  * identical to internal mpsolve cplx_t complex type, i.e.
15  * two double in a struct, we can simply cast silently the
16  * arguments of the fortran routine.
17  */
18 void
mps_roots_(int * n,cplx_t * coeff,cplx_t * roots)19 mps_roots_ (int * n, cplx_t * coeff, cplx_t * roots)
20 {
21   /* Create a new mps_context and a new polynomial */
22   mps_context *s = mps_context_new ();
23   mps_monomial_poly * p = mps_monomial_poly_new (s, *n);
24   int i;
25 
26   for (i = 0; i <= *n; i++)
27     mps_monomial_poly_set_coefficient_d (s, p, i, cplx_Re (coeff[i]), cplx_Im (coeff[i]));
28   mps_context_set_input_poly (s, MPS_POLYNOMIAL (p));
29 
30   /* Set the output precision to DBL_EPSILON and the default goal
31    * to approximate. Try to find all the possible digits representable
32    * in floating point. */
33   mps_context_set_output_prec (s, 53);
34   mps_context_set_output_goal (s, MPS_OUTPUT_GOAL_APPROXIMATE);
35 
36   mps_mpsolve (s);
37 
38   mps_context_get_roots_d (s, &roots, NULL);
39   mps_context_free (s);
40 }
41