Exemple #1
0
int test_locale (const char *langstr)
{
#ifndef ENABLE_NLS
    return 1;
#else
    const char *lcode;
    char *orig, ocpy[64];
    int langid, err = 0;

    langid = lang_id_from_name(langstr);
    lcode = get_setlocale_string(langid);
    orig = setlocale(LC_ALL, NULL);

    gretl_error_clear();

    *ocpy = '\0';
    strncat(ocpy, orig, 63);

    err = set_locale_with_workaround(langid, lcode);

    if (err) {
	gretl_errmsg_sprintf(_("%s: locale is not supported "
			       "on this system"), lcode);
    } else {
	setlocale(LC_ALL, ocpy); /* restore the original locale */
    } 

    return err;
#endif
}
Exemple #2
0
static int 
re_estimate_VECM (irfboot *b, GRETL_VAR *v, int targ, int shock, 
		  int iter, int scount)
{
    static int (*jbr) (GRETL_VAR *, const DATASET *) = NULL;
    static void *handle = NULL;
    int err = 0;

    gretl_error_clear();

    if (iter == 0) {
	/* first round: open the Johansen plugin */
	jbr = get_plugin_function("johansen_boot_round", &handle);
	if (jbr == NULL) {
	    return E_FOPEN;
	}
    }

    /* The various VECM matrices may need to be re-set to the sizes
       expected by johansen_stage_1() */
    maybe_resize_vecm_matrices(v);

    err = johansen_stage_1(v, b->dset, OPT_NONE, NULL);

    if (!err) {
	/* call the plugin function */
	err = jbr(v, b->dset);
    }

#if BDEBUG
    gretl_matrix_print(v->jinfo->Beta, "var->jinfo->Beta");
    gretl_matrix_print(v->jinfo->Alpha, "var->jinfo->Alpha");
    gretl_matrix_print(v->S, "var->S (Omega)");
    gretl_matrix_print(v->B, "var->B");
#endif

    if (!err) {   
	err = gretl_VAR_do_error_decomp(v->S, v->C, v->ord);
    }

    if (!err) {
	err = recalculate_impulse_responses(b, v, targ, shock, iter);
    }

    if (iter == BOOT_ITERS - 1 || VAR_FATAL(err, iter, scount)) {
	if (handle != NULL) {
	    close_plugin(handle);
	    handle = NULL;
	    jbr = NULL;
	}
    }

    return err;
}
Exemple #3
0
int gretl_spawn (char *cmdline)
{
    GError *error = NULL;
    gchar *errout = NULL;
    gchar *sout = NULL;
    int ok, status;
    int ret = 0;

    gretl_error_clear();

    ok = g_spawn_command_line_sync(cmdline,
				   &sout,   /* standard output */
				   &errout, /* standard error */
				   &status, /* exit status */
				   &error);

    if (!ok) {
	gretl_errmsg_set(error->message);
	fprintf(stderr, "gretl_spawn: '%s'\n", error->message);
	g_error_free(error);
	ret = 1;
    } else if (errout && *errout) {
	fprintf(stderr, "stderr: '%s'\n", errout);
	if (!non_fatal(errout)) {
	    gretl_errmsg_set(errout);
	    fprintf(stderr, "gretl_errmsg: '%s'\n", gretl_errmsg_get());
	    ret = 1;
	}
    } else if (status != 0) {
	if (sout != NULL && *sout) {
	    gretl_errmsg_set(sout);
	    fprintf(stderr, "gretl_spawn: status = %d: '%s'\n", status, sout);
	} else {
	    gretl_errmsg_set(_("Command failed"));
	    fprintf(stderr, "gretl_spawn: status = %d\n", status);
	}
	ret = 1;
    }

    if (errout != NULL) g_free(errout);
    if (sout != NULL) g_free(sout);

    if (ret) {
	fprintf(stderr, "Failed command: '%s'\n", cmdline);
    } 

    return ret;
}
Exemple #4
0
static void urlinfo_init (urlinfo *u, 
			  const char *hostname,
			  int saveopt,
			  const char *localfile)
{
    u->url[0] = '\0';

    if (hostname != NULL) {
	sprintf(u->url, "http://%s", hostname);
    }

    u->localfile = localfile;
    u->saveopt = saveopt;

    u->getbuf = NULL;
    u->fp = NULL;

    u->buflen = 0;
    u->datalen = 0;
    u->err = 0;

    u->verbose = getenv("GRETL_WWW_VERBOSE") != NULL;

    u->progfunc = NULL;
    u->pstarted = 0;
    u->timeout = 0;

    gretl_error_clear();

#ifdef BUILD_DATE
    sprintf(u->agent, "gretl-%s-%s", GRETL_VERSION, BUILD_DATE);
#else
    sprintf(u->agent, "gretl-%s", GRETL_VERSION);
#endif

#ifdef WIN32
    strcat(u->agent, "w");
#endif
}
Exemple #5
0
int set_obs (const char *line, DATASET *dset, gretlopt opt)
{
    char pdstr[VNAMELEN];
    char stobs[OBSLEN];
    int structure = STRUCTURE_UNKNOWN;
    double sd0 = dset->sd0;
    int pd, dated = 0;
    int panel = 0;
    int err = 0;

    if (dset == NULL) {
	return E_NODATA;
    }

    if ((opt & (OPT_R | OPT_P)) && dset->Z == NULL) {
	return E_NODATA;
    }

    if ((opt & (OPT_G | OPT_I)) && !dataset_is_panel(dset)) {
	return E_DATA;
    }

    gretl_error_clear();

    if (opt & OPT_R) {
	/* restructure panel: "hidden" option */
	return switch_panel_orientation(dset);
    }    

    if (!strcmp(line, "setobs")) {
	/* we'll just print current obs info */
	return 0;
    }

    if (opt & OPT_P) {
	return set_panel_structure_from_line(line, dset);
    } else if (opt & OPT_G) {
	/* --panel-groups */
	return set_panel_group_strings(line, dset);
    }

    /* now we get down to business */

    if (sscanf(line, "%*s %15s %10s", pdstr, stobs) != 2) {
	gretl_errmsg_set(_("Failed to parse line as frequency, startobs"));
	return E_PARSE;
    }

    pd = gretl_int_from_string(pdstr, &err);
    if (!err && pd < 1) {
	gretl_errmsg_sprintf(_("frequency (%d) does not make seem to make sense"), pd);
	err = E_DATA;
    }
    if (err) {
	return err;
    }

    /* if an explicit structure option was passed in, respect it */
    if (opt == OPT_X) {
	structure = CROSS_SECTION;
    } else if (opt == OPT_T) {
	structure = TIME_SERIES;
    } else if (opt == OPT_S) {
	structure = STACKED_TIME_SERIES;
	panel = 1;
    } else if (opt == OPT_C) {
	structure = STACKED_CROSS_SECTION;
	panel = 1;
    } else if (opt == OPT_N) {
	structure = SPECIAL_TIME_SERIES;
    } else if (opt == OPT_I) {
	/* --panel-time */
	structure = TIME_SERIES;
    }

    if (panel && dset->n > 0 && pd > dset->n) {
	gretl_errmsg_sprintf(_("frequency (%d) does not make seem to make sense"), pd);
	return 1;
    }

    err = process_starting_obs(stobs, pd, &structure, &sd0, &dated);

    if (err) {
	return err;
    }

    if (opt == OPT_I) {
	dset->panel_pd = pd;
	dset->panel_sd0 = sd0;
	return 0;
    }   

    if (panel && dset->n % pd != 0) {
	int sts = structure == STACKED_TIME_SERIES;

	gretl_errmsg_sprintf(_("Panel datasets must be balanced.\n"
			       "The number of observations (%d) is not a multiple\n"
			       "of the number of %s (%d)."), 
			     dset->n, sts ? _("periods") : _("units"), pd);
	return E_DATA;
    }

    if (dated) {
	/* replace any existing markers with date strings */
	dataset_destroy_obs_markers(dset);
    } else if (structure == TIME_SERIES && (pd == 1 || pd == 4 || pd == 12)) {
	/* force use of regular time-series obs labels */
	dataset_destroy_obs_markers(dset);
    }

    dset->pd = pd;
    dset->structure = structure;
    dset->sd0 = sd0;

    ntodate(dset->stobs, 0, dset); 
    ntodate(dset->endobs, dset->n - 1, dset);

    /* pre-process stacked cross-sectional panels: put into canonical
       stacked time series form
    */
    if (dset->structure == STACKED_CROSS_SECTION) {
	if (dset->Z == NULL) {
	    err = E_NODATA;
	} else {
	    err = switch_panel_orientation(dset);
	}
    }	

    return err;
}