Пример #1
0
static int graph_page_set_font_scale (const char *s)
{
    double x;

    s += strspn(s, " ");
    x = dot_atof(s);

    if (x > 0.0 && x < 4.0) {
	gp_fontscale = x;
	return 0;
    } else {
	gretl_errmsg_sprintf("'%s': invalid fontscale", s);
	return E_DATA;
    }
}
Пример #2
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
    }
}
Пример #3
0
static int process_starting_obs (char *stobs, int pd, int *pstructure,
				 double *psd0, int *pdated)
{
    int structure = *pstructure;
    double sd0 = 0.0;
    int maybe_tseries = 1;
    int dated = 0;
    int err = 0;

    if (structure == CROSS_SECTION || 
	structure == STACKED_TIME_SERIES || 
	structure == STACKED_CROSS_SECTION) {
	maybe_tseries = 0;
    }

    /* truncate stobs if not a calendar date */

    if (likely_calendar_obs_string(stobs)) {
	if (maybe_tseries) {
	    dated = 1;
	} else {
	    return invalid_stobs(stobs);
	}
    } else {
	stobs[8] = '\0';
    }

    if (dated) {
	if (pd == 5 || pd == 6 || pd == 7 || pd == 52) {
	    /* calendar-dated data, daily or weekly */
	    long ed0 = get_epoch_day(stobs);

	    if (ed0 < 0) {
		return invalid_stobs(stobs);
	    } else {
		if (pd < 7) {
		    maybe_fix_daily_start(&ed0, pd);
		}
		sd0 = ed0;
		structure = TIME_SERIES;
	    }
	} else {
	    return invalid_stobs(stobs);
	}
    } else if (structure == TIME_SERIES && pd == 10) {
	/* decennial data */
	sd0 = (double) atoi(stobs);
    } else {
	int maj = 0, min = 0;

	if (get_stobs_maj_min(stobs, structure, &maj, &min)) {
	    return invalid_stobs(stobs);
	}

	if ((pd == 5 || pd == 6 || pd == 7 || pd == 52) && 
	    min == 0 && maybe_tseries) {  
	    /* catch undated daily or weekly data */
	    structure = TIME_SERIES;
	} else {
	    if (catch_setobs_errors(stobs, pd, min, structure)) {
		return E_DATA;
	    } else if (pd == 1) {
		sprintf(stobs, "%d", maj);
		if (structure == STRUCTURE_UNKNOWN) {
		    if (maj > 1) {
			structure = TIME_SERIES; /* annual? */
		    } else {
			structure = CROSS_SECTION;
		    }
		}
	    } else {
		if (structure == TIME_SERIES && min > 0 &&
		    !recognized_ts_frequency(pd)) {
		    structure = SPECIAL_TIME_SERIES;
		}
		real_format_obs(stobs, maj, min, pd, '.');
		if (structure == STRUCTURE_UNKNOWN && 
		    recognized_ts_frequency(pd)) {
		    structure = TIME_SERIES;
		}
	    }
	}

	/* for non-calendar data */
	sd0 = dot_atof(stobs);
    }

    if (!err) {
	*pstructure = structure;
	*psd0 = sd0;
	*pdated = dated;
    }

    return err;
}