=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/Attic/plot2d.c,v retrieving revision 1.1.1.2 retrieving revision 1.1.1.3 diff -u -p -r1.1.1.2 -r1.1.1.3 --- OpenXM_contrib/gnuplot/Attic/plot2d.c 2000/01/22 14:15:59 1.1.1.2 +++ OpenXM_contrib/gnuplot/Attic/plot2d.c 2003/09/15 07:09:25 1.1.1.3 @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid = "$Id: plot2d.c,v 1.1.1.2 2000/01/22 14:15:59 maekawa Exp $"; +static char *RCSid = "$Id: plot2d.c,v 1.1.1.3 2003/09/15 07:09:25 ohara Exp $"; #endif /* GNUPLOT - plot2d.c */ @@ -120,12 +120,21 @@ extern TBOOLEAN df_binary; * dont know we have to support ranges [10:-10] - lets reverse * it for now, then fix it at the end. */ -#define INIT_ARRAYS(axis, min, max, auto, is_log, base, log_base, infinite) \ -do{auto_array[axis] = auto; \ - min_array[axis] = (infinite && (auto&1)) ? VERYLARGE : min; \ - max_array[axis] = (infinite && (auto&2)) ? -VERYLARGE : max; \ - log_array[axis] = is_log; base_array[axis] = base; log_base_array[axis] = log_base;\ -}while(0) + +/* HBB 20021103: try to circumvent BC31 bug by turning this macro into + * a function... */ +static GP_INLINE void +init_arrays(int axis, double min, double max, int autosc, int is_log, double base, double log_base, TBOOLEAN infinite) +{ + auto_array[axis] = autosc; + min_array[axis] = (infinite && (autosc & 1)) ? VERYLARGE : min; + max_array[axis] = (infinite && (autosc & 2)) ? -VERYLARGE : max; + log_array[axis] = is_log; + base_array[axis] = base; + log_base_array[axis] = log_base; +} +#define INIT_ARRAYS init_arrays + /* handle reversed ranges */ #define CHECK_REVERSE(axis) \ do{\ @@ -248,11 +257,10 @@ void plotrequest() } /* first '[' */ if (parametric || polar) /* set optional x ranges */ LOAD_RANGE(FIRST_X_AXIS); - else { - /* order of t doesn't matter, but x does */ - CHECK_REVERSE(FIRST_X_AXIS); - } + /* order of x range does matter, even if we're in parametric mode */ + CHECK_REVERSE(FIRST_X_AXIS); + LOAD_RANGE(FIRST_Y_AXIS); CHECK_REVERSE(FIRST_Y_AXIS); LOAD_RANGE(SECOND_X_AXIS); @@ -325,6 +333,7 @@ struct curve_points *this_plot; case BOXES: min_cols = 2; max_cols = 4; + break; default: min_cols = 1; @@ -718,23 +727,87 @@ struct curve_points *this_plot; int plot_num; { int i, curve; + char *table_format = NULL; + /* The data format is determined by the format of the axis labels. + * See 'set format'. Patch by Don Taber + */ + table_format = gp_alloc(strlen(xformat)+strlen(yformat)+5, "table format"); + strcpy(table_format, xformat); + strcat(table_format, " "); + strcat(table_format, yformat); + strcat(table_format, " %c\n"); + /* Not sure whether the missing plot styles require special treatment. + * They all fall under the "default" case right now. Lars + */ for (curve = 0; curve < plot_num; curve++, this_plot = this_plot->next_cp) { - fprintf(gpoutfile, "#Curve %d, %d points\n#x y type\n", curve, this_plot->p_count); + fprintf(gpoutfile, "#Curve %d, %d points\n#x y", curve, this_plot->p_count); + switch (this_plot->plot_style) { + case BOXES: + case XERRORBARS: + fprintf(gpoutfile, " xlow xhigh"); + break; + case BOXERROR: + case YERRORBARS: + fprintf(gpoutfile, " ylow yhigh"); + break; + case BOXXYERROR: + case XYERRORBARS: + fprintf(gpoutfile, " xlow xhigh ylow yhigh"); + break; + case FINANCEBARS: + case CANDLESTICKS: + default: + /* ? */ + break; + } + + fprintf(gpoutfile, " type\n"); for (i = 0; i < this_plot->p_count; i++) { - fprintf(gpoutfile, "%g %g %c\n", + fprintf(gpoutfile, "%g %g", this_plot->points[i].x, - this_plot->points[i].y, + this_plot->points[i].y); + switch (this_plot->plot_style) { + case BOXES: + case XERRORBARS: + fprintf(gpoutfile, " %g %g", + this_plot->points[i].xlow, + this_plot->points[i].xhigh); + break; + case BOXERROR: + case YERRORBARS: + fprintf(gpoutfile, " %g %g", + this_plot->points[i].ylow, + this_plot->points[i].yhigh); + break; + case BOXXYERROR: + case XYERRORBARS: + fprintf(gpoutfile, " %g %g %g %g", + this_plot->points[i].xlow, + this_plot->points[i].xhigh, + this_plot->points[i].ylow, + this_plot->points[i].yhigh); + break; + case FINANCEBARS: + case CANDLESTICKS: + default: + /* ? */ + break; + } + fprintf(gpoutfile, " %c\n", this_plot->points[i].type == INRANGE ? 'i' : this_plot->points[i].type == OUTRANGE ? 'o' : 'u'); } fputc('\n', gpoutfile); } -/* two blank lines between plots in table output */ + + /* two blank lines between plots in table output */ fputc('\n', gpoutfile); fflush(gpoutfile); + + free(table_format); } /* @@ -1212,14 +1285,20 @@ do{ assert(!polar && !parametric); \ if (uses_axis[FIRST_X_AXIS]) { if (max_array[FIRST_X_AXIS] == -VERYLARGE || - min_array[FIRST_X_AXIS] == VERYLARGE) + min_array[FIRST_X_AXIS] == VERYLARGE) { + cp_free(first_plot); + first_plot = NULL; int_error("all points undefined!", NO_CARET); + } FIXUP_RANGE_FOR_LOG(FIRST_X_AXIS, x); } if (uses_axis[SECOND_X_AXIS]) { if (max_array[SECOND_X_AXIS] == -VERYLARGE || - min_array[SECOND_X_AXIS] == VERYLARGE) + min_array[SECOND_X_AXIS] == VERYLARGE) { + cp_free(first_plot); + first_plot = NULL; int_error("all points undefined!", NO_CARET); + } FIXUP_RANGE_FOR_LOG(SECOND_X_AXIS, x2); } else { assert(uses_axis[FIRST_X_AXIS]); @@ -1241,15 +1320,21 @@ do{ assert(!polar && !parametric); \ if (uses_axis[FIRST_Y_AXIS]) { if (max_array[FIRST_Y_AXIS] == -VERYLARGE || - min_array[FIRST_Y_AXIS] == VERYLARGE) + min_array[FIRST_Y_AXIS] == VERYLARGE) { + cp_free(first_plot); + first_plot = NULL; int_error("all points undefined!", NO_CARET); + } fixup_range(FIRST_Y_AXIS, "y"); FIXUP_RANGE_FOR_LOG(FIRST_Y_AXIS, y); } if (uses_axis[SECOND_Y_AXIS]) { if (max_array[SECOND_Y_AXIS] == -VERYLARGE || - min_array[SECOND_Y_AXIS] == VERYLARGE) + min_array[SECOND_Y_AXIS] == VERYLARGE) { + cp_free(first_plot); + first_plot = NULL; int_error("all points undefined!", NO_CARET); + } fixup_range(SECOND_Y_AXIS, "y2"); FIXUP_RANGE_FOR_LOG(SECOND_Y_AXIS, y2); } else { @@ -1272,17 +1357,6 @@ do{ assert(!polar && !parametric); \ max_array[FIRST_Y_AXIS] = max_array[SECOND_Y_AXIS]; } -#define WRITEBACK(axis,min,max) \ -if(range_flags[axis]&RANGE_WRITEBACK) \ - {if (auto_array[axis]&1) min = min_array[axis]; \ - if (auto_array[axis]&2) max = max_array[axis]; \ - } - - WRITEBACK(FIRST_X_AXIS, xmin, xmax) - WRITEBACK(FIRST_Y_AXIS, ymin, ymax) - WRITEBACK(SECOND_X_AXIS, x2min, x2max) - WRITEBACK(SECOND_Y_AXIS, y2min, y2max) - if (strcmp(term->name, "table") == 0) print_table(first_plot, plot_num); else { @@ -1292,6 +1366,27 @@ if(range_flags[axis]&RANGE_WRITEBACK) \ do_plot(first_plot, plot_num); END_LEAK_CHECK(); + + /* after do_plot(), min_array[] and max_array[] + contain the plotting range actually used (rounded + to tic marks, not only the min/max data values) + --> save them now for writeback if requested */ + +#define SAVE_WRITEBACK(axis) /* ULIG */ \ + if(range_flags[axis]&RANGE_WRITEBACK) { \ + set_writeback_min(axis,min_array[axis]); \ + set_writeback_max(axis,max_array[axis]); \ + } + SAVE_WRITEBACK(FIRST_X_AXIS) + SAVE_WRITEBACK(FIRST_Y_AXIS) + SAVE_WRITEBACK(FIRST_Z_AXIS) + SAVE_WRITEBACK(SECOND_X_AXIS) + SAVE_WRITEBACK(SECOND_Y_AXIS) + SAVE_WRITEBACK(SECOND_Z_AXIS) + SAVE_WRITEBACK(T_AXIS) + SAVE_WRITEBACK(R_AXIS) + SAVE_WRITEBACK(U_AXIS) + SAVE_WRITEBACK(V_AXIS) } /* if we get here, all went well, so record this line for replot */ @@ -1390,7 +1485,7 @@ int *plot_num; /* Ok, fix up the title to include both the xp and yp plots. */ if (xp->title && xp->title[0] != '\0' && yp->title) { tlen = strlen(yp->title) + strlen(xp->title) + 3; - new_title = gp_alloc((unsigned long) tlen, "string"); + new_title = gp_alloc(tlen, "string"); strcpy(new_title, xp->title); strcat(new_title, ", "); /* + 2 */ strcat(new_title, yp->title); /* + 1 = + 3 */