Ejemplo n.º 1
0
int chow_test_driver (const char *line, MODEL *pmod, DATASET *dset, 
		      gretlopt opt, PRN *prn)
{
    char chowstr[VNAMELEN];
    char fmt[16];
    int chowparm = 0;
    int err = 0;

    /* chowstr should hold either an observation at which to
       split the sample, or the name of a dummy variable
       to be used to divide the sample (if given OPT_D)
    */

    sprintf(fmt, "%%*s %%%ds", VNAMELEN-1);

    if (sscanf(line, fmt, chowstr) != 1) {
	err = E_PARSE;
    } else if (opt & OPT_D) {
	chowparm = get_chow_dummy(chowstr, dset, &err);
    } else {
	chowparm = dateton(chowstr, dset);
    }

    if (!err) {
	if (opt & OPT_D) {
	    err = chow_test_from_dummy(chowparm, pmod, dset, opt, prn);
	} else {
	    err = chow_test(chowparm, pmod, dset, opt, prn);
	}
    }

    return err;
}
Ejemplo n.º 2
0
static gboolean obs_button_input (GtkSpinButton *spin, 
				  gdouble *new_val,
				  gpointer p)
{
    const gchar *obs = gtk_entry_get_text(GTK_ENTRY(spin));
    int n;

    if (g_object_get_data(G_OBJECT(spin), "newdata")) {
	n = merge_dateton(obs, (DATASET *) p);
    } else {
	n = dateton(obs, (DATASET *) p);
    }

    *new_val = n;

    return TRUE;
}
Ejemplo n.º 3
0
static void parse_number (parser *p)
{
    char xstr[NUMLEN] = {0};
    int gotcol = 0;
    int i = 0;

    while (ok_dbl_char(p, xstr, i - 1) && i < NUMLEN - 1) {
	xstr[i++] = p->ch;
	if (p->ch == ':') {
	    gotcol = 1;
	}
	parser_getc(p);
    }  

    while (p->ch >= '0' && p->ch <= '9') {
	/* flush excess numeric characters */
	parser_getc(p);
    } 

#if LDEBUG
    fprintf(stderr, "parse_number: xstr = '%s'\n", xstr);
#endif
    
    if (gotcol) {
#if LDEBUG
	fprintf(stderr, " got colon: obs identifier?\n");
#endif
	if (p->dset == NULL || p->dset->n == 0) {
	    p->err = E_NODATA;
	} else if (p->dset->pd == 1) {
	    p->err = E_PDWRONG;
	} else if (dateton(xstr, p->dset) < 0) {
	    p->err = E_DATA;
	} else {
	    p->idstr = gretl_strdup(xstr);
	    p->sym = STR;
	}
    } else {
	p->xval = dot_atof(xstr);
	p->sym = NUM;
#if LDEBUG
	fprintf(stderr, " dot_atof gave %g\n", p->xval);
#endif
    }
}
Ejemplo n.º 4
0
static int x12_date_to_n (const char *s, const DATASET *dset)
{
    char date[12] = {0};

    if (non_yearly_frequency(dset->pd)) {
	int t, maj = 0, min = 0, n = strlen(s);
	char fmt[16];

	sprintf(fmt, "%%%dd%%2d", n - 2);
	if (sscanf(s, fmt, &maj, &min) == 2) {
	    t = (maj - 1) * dset->pd + min - 1;
	} else {
	    t = -1;
	}

	return t;
    }

    if (dset->pd > 1) {
	int len = strlen(s);

	if (len <= 4) {
	    strncat(date, s, len - 2);
	    strcat(date, ":");
	    strcat(date, s + len - 2);
	} else {
	    strncat(date, s, 4);
	    strcat(date, ":");
	    strncat(date, s + 4, 4);
	}
    } else {
	strncat(date, s, 4);
    }

    return dateton(date, dset);
}
Ejemplo n.º 5
0
static void compute_default_ts_info (DATASET *dwinfo)
{
#if DWDEBUG
    char obsstr[OBSLEN];

    fprintf(stderr, "compute_ts_info() called: pd=%d, structure=%d\n",
	    dwinfo->pd, dwinfo->structure);
    if (dwinfo->pd == PD_SPECIAL) {
	fprintf(stderr, "breakage: pd = PD_SPECIAL\n");
    }
#endif

    if (dwinfo->pd < 0) {
	dwinfo->pd = 1;
    }

    if (dwinfo->structure == SPECIAL_TIME_SERIES) {
	/* non-standard time series */
	dwinfo->n = 9999 * dwinfo->pd;
	dwinfo->t1 = 0;
	if (dwinfo->pd > 1) {
	    int p = dwinfo->pd;

	    strcpy(dwinfo->stobs, "1:");
	    while ((p = p / 10) > 0) {
		strcat(dwinfo->stobs, "0");
	    }
	    strcat(dwinfo->stobs, "1");
	} else {
	    strcpy(dwinfo->stobs, "1");
	}
    } else if (dwinfo->pd == 1) {
	strcpy(dwinfo->stobs, "1");
	dwinfo->n = 2100; 
	dwinfo->t1 = 1959; /* 1960 */
    } else if (dwinfo->pd == 10) {
	int dd = default_start_decade();

	sprintf(dwinfo->stobs, "%d", dd);
	if (dd > 1700) {
	    dwinfo->n = 30;
	    dwinfo->t1 = 0;
	} else {
	    dwinfo->n = 40;
	    dwinfo->t1 = 25;
	}
    } else if (dwinfo->pd == 4) {
	strcpy(dwinfo->stobs, "1700:1");
	dwinfo->n = 1400;
	dwinfo->t1 = 1040; /* 1960:1 */
    } else if (dwinfo->pd == 12) {
	strcpy(dwinfo->stobs, "1700:01");
	dwinfo->n = 4200;
	dwinfo->t1 = 3120; /* 1960:01 */
    } else if (dwinfo->pd == 24) {
	strcpy(dwinfo->stobs, "1:01");
	dwinfo->n = 1500;
	dwinfo->t1 = 0;
    } else if (dwinfo->pd == 52) {
	if (dwinfo->v >= 7) {
	    dwinfo->n = 500;
	    dwinfo->t1 = 0;
	    strcpy(dwinfo->stobs, "1");
	} else {
	    make_weekly_stobs(dwinfo);
	    dwinfo->n = 13000;
	    dwinfo->t1 = 7826;
	}
    } else if (dwinfo->pd == 5 ||
	       dwinfo->pd == 6 ||
	       dwinfo->pd == 7) {
	strcpy(dwinfo->stobs, "1900-01-01");
	dwinfo->n = 50000;
	/* set default start to 1960-01-01 (a Friday) */
	if (dwinfo->pd == 5) {
	    dwinfo->t1 = 15654;
	} else if (dwinfo->pd == 6) {
	    dwinfo->t1 = 18784;
	} else {
	    dwinfo->t1 = 21914;
	}
    }

    dwinfo->sd0 = get_date_x(dwinfo->pd, dwinfo->stobs);

    if (dataset->structure == TIME_SERIES && 
	dataset->pd == dwinfo->pd) {
	/* make the current start the default */
	dwinfo->t1 = dateton(dataset->stobs, dwinfo);
    }

    ntodate(dwinfo->endobs, dwinfo->n - 1, dwinfo);

#if DWDEBUG
    ntodate(obsstr, dwinfo->t1, dwinfo);
    fprintf(stderr, "dwinfo: v=%d, pd=%d, stobs='%s', endobs='%s', sd0=%g, t1=%d (%s)\n",
	    dwinfo->v, dwinfo->pd, dwinfo->stobs, dwinfo->endobs, dwinfo->sd0, 
	    dwinfo->t1, obsstr);

    ntodate(obsstr, dataset->t1, dataset);
    fprintf(stderr, "dataset: pd=%d, stobs='%s', sd0=%g, t1=%d (%s)\n",
	    dataset->pd, dataset->stobs, dataset->sd0, dataset->t1, obsstr);
#endif
}