[Gretl-devel] libgretl arma

Allin Cottrell cottrell at wfu.edu
Fri Feb 17 10:41:28 EST 2012

On Fri, 17 Feb 2012, Emrah Samdan wrote:

> I have implemented what you have offered so far and i am very grateful to
> you. But my new problem is, i am getting a model from the arma function
> then i call the same function again with other parameters. However, it
> gives a segmentation fault in the line where i read the native gretl data
> in the second call.
> Do you have any idea about the reason of this ? libgretl parts in the
> function that i am calling  are:
> fileName = generateXML(powerResults, predictions, numberOfTuples,
> santralName, queryTime); // generates an .gdt file for gretl
> prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
> dset = datainfo_new();
> err = gretl_read_native_data(fileName, dset); //it crashes here
> Sorry for my exhaustive questions, but i really couldn't find a way out.

It's possible that a malformed .gdt data file might crash 
gretl. If you can send me the file as created by your 
generateXML() function I'll take a look. In the meantime I'm 
attaching a working example of a libgretl program that does
ARMA estimation twice, with different parameters.

Allin Cottrell
-------------- next part --------------
#include <gretl/libgretl.h>

int arma_estimate (int p, int q, DATASET *dset, PRN *prn)
    MODEL *model;
    int *list;
    int err;

    model = gretl_model_new();
    list = gretl_list_new(5);

    list[1] = p;        /* AR order */
    list[2] = 0;        /* order of integration */
    list[3] = q;        /* 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);


    return err;

#define PREFIX "/opt/esl"

int make_estimation (int p, int q, PRN *prn)
    DATASET *dset;
    int err;

    dset = datainfo_new();

    /* give the full path to the gretl datafile unless it's 
       in the current working directory */
    err = gretl_read_native_data(PREFIX "/share/gretl/data/data9-7.gdt", dset);

    if (err) {
	errmsg(err, prn);
    } else {
        err = arma_estimate(p, q, dset, prn);

    return err;

int main (void)
    PRN *prn;

    prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
    make_estimation(1, 1, prn);
    make_estimation(2, 1, prn);
    return 0;

More information about the Gretl-devel mailing list