コード例 #1
0
ファイル: tabulate.c プロジェクト: confide423/gnuplot
static void
print_line(const char *str)
{
    if (table_var == NULL) {
	fputs(str, outfile);
	fputc('\n', outfile);
    } else {
	append_to_datablock(&table_var->udv_value, strdup(str));
    }
}
コード例 #2
0
ファイル: tabulate.c プロジェクト: gnuplot/gnuplot
/*
 * Called from plot2d.c (get_data) for "plot with table"
 */
TBOOLEAN
tabulate_one_line(double v[MAXDATACOLS], struct value str[MAXDATACOLS], int ncols)
{
    int col;
    FILE *outfile = (table_outfile) ? table_outfile : gpoutfile;
    struct value keep;

    if (table_filter_at) {
	evaluate_inside_using = TRUE;
	evaluate_at(table_filter_at, &keep);
	evaluate_inside_using = FALSE;
	if (undefined || isnan(real(&keep)) || real(&keep) == 0)
	    return FALSE;
    }

    if (table_var == NULL) {
	char sep = (table_sep && *table_sep) ? *table_sep : '\t';
	for (col = 0; col < ncols; col++) {
	    if (str[col].type == STRING)
		fprintf(outfile, " %s", str[col].v.string_val);
	    else
		fprintf(outfile, " %g", v[col]);
	    if (col < ncols-1)
		fprintf(outfile, "%c", sep);
	}
	fprintf(outfile, "\n");
    } else {
	char buf[64]; /* buffer large enough to hold %g + 2 extra chars */
	char sep = (table_sep && *table_sep) ? *table_sep : '\t';
	size_t size = sizeof(buf);
	char *line = (char *) gp_alloc(size, "");
	size_t len = 0;

	line[0] = NUL;
	for (col = 0; col < ncols; col++) {
	    if (str[col].type == STRING) {
		len = strappend(&line, &size, 0, str[col].v.string_val);
	    } else {
		snprintf(buf, sizeof(buf), " %g", v[col]);
		len = strappend(&line, &size, len, buf);
	    }
	    if (col < ncols-1) {
		snprintf(buf, sizeof(buf), " %c", sep);
		len = strappend(&line, &size, len, buf);
	    }
	}
	append_to_datablock(&table_var->udv_value, line);
    }
 
    return TRUE;
}