I need a help for change the code below for use it as a simple void function.
I found this code on Gretl :
http://gretl.sourcearchive.com/documentation/1.8.2/genfuncs_8c-source.html
Now i ha some problem , can someone help me.
/**
* bkbp_filter:
* @y: array of original data.
* @bk: array into which to write the filtered series.
* @pdinfo: data set information.
*
* Calculates the Baxter & King bandpass filter.
*
* Returns: 0 on success, non-zero error code on failure.
*/
int bkbp_filter (const double *y, double *bk, const DATAINFO *pdinfo)
{
int t1 = pdinfo->t1, t2 = pdinfo->t2;
int bkl, bku;
double omubar, omlbar;
double avg_a;
double *a;
int i, k, t;
int err = 0;
/*
periods[0] and periods[1]: threshold periodicities for business cycle
k: order of the approximation
*/
/* get user settings if available (or the defaults) */
get_bkbp_periods(pdinfo, &bkl, &bku);
k = get_bkbp_k(pdinfo);
#if BK_DEBUG
fprintf(stderr, "lower limit = %d, upper limit = %d, \n",
bkl, bku);
#endif
if (bkl >= bku) {
strcpy(gretl_errmsg, "Error in Baxter-King frequencies");
return 1;
}
err = array_adjust_t1t2(y, &t1, &t2);
if (err) {
return err;
}
if (2 * k >= t2 - t1 + 1) {
strcpy(gretl_errmsg, "Insufficient observations");
return E_DATA;
}
a = malloc((k + 1) * sizeof *a);
if (a == NULL) {
return E_ALLOC;
}
omubar = M_2PI / bkl;
omlbar = M_2PI / bku;
/* first we compute the coefficients */
avg_a = a[0] = (omubar - omlbar) / M_PI;
for (i=1; i<=k; i++) {
a[i] = (sin(i * omubar) - sin(i * omlbar)) / (i * M_PI);
avg_a += 2 * a[i];
}
avg_a /= (2 * k + 1);
for (i=0; i<=k; i++) {
a[i] -= avg_a;
#if BK_DEBUG
fprintf(stderr, "a[%d] = %#9.6g\n", i, a[i]);
#endif
}
/* now we filter the series, skipping the first
and last k observations */
for (t=0; t<pdinfo->n; t++) {
if (t < t1 + k || t > t2 - k) {
bk[t] = NADBL;
} else {
bk[t] = a[0] * y[t];
for (i=1; i<=k; i++) {
bk[t] += a[i] * (y[t-i] + y[t+i]);
}
}
}
free(a);
return err;
}