Hello Allin
Below you will find a complete compilable cpp program that demonstrates that the
corrgram() function does not plot(at least on my machine) the ACF and PACF when called
through the c/c++ api. I use the dataset from /share/gretl/data/ramanathan/data9-7.gdt .
The only library that this program is linking to is gretl-1.0.
When I use the Gretl gui everything plots just fine.
Thank you
#include <gretl/libgretl.h>
int arma_estimate (DATASET *dset, PRN *prn)
{
MODEL *model;
int *list;
int err;
model = gretl_model_new();
list = gretl_list_new(5);
list[1] = 1; /* AR order */
list[2] = 0; /* order of integration */
list[3] = 1; /* MA order */
list[4] = LISTSEP; /* separator */
list[5] = 1; /* position of dependent variable in dataset */
*model = arma(list, NULL, dset, OPT_NONE, prn);
err = model->errcode;
if (err) {
errmsg(err, prn);
} else {
printmodel(model, dset, OPT_NONE, prn);
}
gretl_model_free(model);
free(list);
return err;
}
int CorrgramGretl(int varno, int order, int nparam, DATASET *dset, gretlopt opt, PRN
*prn){
int err = 0;
err = corrgram (varno, order, nparam, dset, opt, prn);
return 0;
}
int main (void)
{
DATASET *dset;
PRN *prn;
int err;
libgretl_init();
dset = datainfo_new();
prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
/* Give the full path to the gretl datafile unless it's
in the current working directory. Note that PREFIX is
defined in the Makefile
*/
err =
gretl_read_native_data("/usr/local/share/gretl/data/ramanathan/data9-7.gdt",
dset);
if (err) {
errmsg(err, prn);
exit(EXIT_FAILURE);
}
err = arma_estimate(dset, prn);
gretlopt opt = OPT_R;
/* gretl_matrix *acf_mat;//const gretl_matrix *PM
// acf_mat = gretl_matrix_alloc(m, 100);
acf_mat = acf_matrix(dset->Z[2], 0, dset, dset->n,&err);
const char *vname = "N";
const double *acf=const_cast<const double* >( &acf_mat->val[0]);
const double *pacf=const_cast<const double* >( &acf_mat->val[1]);
int m = 30;
double pm = 1.0;
correlogram_plot (vname,acf,pacf,acf_mat,m, pm,opt);
*/
err = CorrgramGretl(2, 7, 1, dset, opt, prn);
destroy_dataset(dset);
gretl_print_destroy(prn);
libgretl_cleanup();
return 0;
}