
(libload "libc/libc")
(libload "gsl/aux_structure")
(libload "gsl/integration")

(de f ( x params)
    ((-double-) x)
    ((-gptr-) params)
    (let ((ret (double 0)))
      #{ {
      double alpha;
      alpha = *(double *) $params;
      
      $ret = log(alpha *$x) /sqrt($x);
      } #} 
      ret))

(dhc-make () f)


(setq w (gsl_integration_workspace_alloc 1000))
(setq alpha (double-matrix))
(alpha 1)

(setq func (alloc_gsl_function))
(setval_function_gsl_function func (gptr f))
(setval_params_gsl_function func  (idx-ptr alpha))

(setq mresult (double-matrix))
(setq merror  (double-matrix))
(gsl_integration_qags func 0 1 0 1e-7 1000 w (idx-ptr mresult)  (idx-ptr merror))

(printf "integration result is: %g\n" (mresult))
(printf "estimated error is : %g\n" (merror))

(free func)
