Hello
Problem 1.
In the code below I have noticed that this line-> std::string what =
"/why/do/I/delete";
will cause all files in this folder, set here line-> char
work_dir[]="/home/ryan/workspace/TesterTest";
to be deleted. If this line is deleted or commented out line-> std::string what =
"/why/do/I/delete";
then nothing gets deleted, i.e everything works fine.
Problem 2.
Now taking the code below, If you set this line-> int use_matrix = 1; /* or 0 */ as
such and delete the following two lines
line-> char work_dir[]="/home/ryan/workspace/TesterTest/";
line-> strcpy(config_path.workdir ,work_dir);
then correlogram_plot will not show the plot if this line-> std::string what =
"/why/do/I/delete";
is at the end of the program
Below is all the code needed to recreate the problem.
Is this a problem specific to me or is any one else able to recreate these two issues
Thank you
#include <iostream>
#include <sstream>
#include <fstream>
#include <gretl/libgretl.h>
#include <vector>
int arma_estimate (DATASET *dset, PRN *prn, int *resid_id)
{
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);
}
if (!err) {
/* save arma residual series? */
int v;
dataset_add_allocated_series(dset, model->uhat);
v = dset->v - 1 ; /* ID number of last series */
strcpy(dset->varname[v], "residual");
*resid_id = v;
model->uhat = NULL; /* don't double free! */
}
gretl_model_free(model);
free(list);
return err;
}
int CorrgramGretl (int varno, int order, int nparam, DATASET *dset,
gretlopt opt, PRN *prn)
{
int err;
err = corrgram(varno, order, nparam, dset, opt, prn);
if (err) {
errmsg(err, prn);
}
return err;
}
int main (void)
{
int use_matrix = 0; /* or 0 */
int use_residual = 1; /* or 0 */
int vnum; /* series ID for correlogram */
gretlopt opt = OPT_NONE;
DATASET *dset;
PRN *prn;
int err;
libgretl_init();
ConfigPaths config_path;
/* tell libgretl where to find gnuplot */
//gretl_set_path_by_name("gnuplot", "/usr/bin/gnuplot");
char gnu_dir[]="/usr/local/bin/gnuplot";
strcpy(config_path.gnuplot ,gnu_dir);
char work_dir[]="/home/ryan/workspace/TesterTest";
strcpy(config_path.workdir ,work_dir);
err = gretl_set_paths (&config_path);
dset = datainfo_new();
prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
err =
gretl_read_native_data("/usr/local/share/gretl/data/ramanathan/data9-7.gdt",
dset);
if (!err && use_residual) {
opt = OPT_R;
err = arma_estimate(dset, prn, &vnum);
} else {
vnum = 2; /* or whatever */
}
if (err) {
errmsg(err, prn);
exit(EXIT_FAILURE);
}
int order = 7; /* or whatever */
if (use_matrix) {
/* call correlogram_plot() directly */
gretl_matrix *cmat;
cmat = acf_matrix(dset->Z[vnum], order, dset, dset->n, &err);
if (!err) {
/* take pointers into the two @cmat columns */
const double *acf = cmat->val;
const double *pacf = acf + cmat->rows;
/* set the plus/minus range */
double pm = 1.96 / sqrt(dset->n);
correlogram_plot(dset->varname[vnum], acf, pacf, NULL,
order, pm, opt);
}
gretl_matrix_free(cmat);
}
else {
/* emulate "command"-style call */
opt = OPT_U; /* add --plot=<whatever> */
/* supply the parameter to --plot */
set_optval_string(CORRGM, OPT_U, "display");
err = CorrgramGretl(vnum, order, 1, dset, opt, prn);
}
destroy_dataset(dset);
gretl_print_destroy(prn);
libgretl_cleanup();
std::string what = "/why/do/I/delete";
return 0;
}