/* See allgraphs.h */ /* Last edited on 2003-07-29 22:28:31 by stolfi */ #include "allgraphs.h" #include #include #include #include #include #include #include #include #include #include #include #include /*** INTERNAL PROTOTYPES ***/ char *allgraphs_format_parms( Float xmin, Float xmax, Float ymin, Float ymax, int n ); char *allgraphs_format_parms( Float xmin, Float xmax, Float ymin, Float ymax, int n ) { char *s = (char *) malloc(300); sprintf(s, "x in [%f _ %f] y in [%f _ %f] %d intervals", xmin, xmax, ymin, ymax, n ); return(s); } void allgraphs_plot( char *fileprefix, int epsformat, char *title, Float f(Float x), Interval fv(Interval x), AAP ff(AAP x), Float xmin, Float xmax, Float ymin, Float ymax, int n, int m ) { char *parmstr = allgraphs_format_parms(xmin, xmax, ymin, ymax, n); FILE *psfile; Float wx = xmax - xmin; Float wy = ymax - ymin; Float wm = FMAX(wx, wy); double scale = 6.0 * 72.0 / wm; double xc = 4.25 * 72.0; double hmin = xc - scale * wx / 2.0; double hmax = xc + scale * wx / 2.0; double yc = 6.50 *72.0; double vmin = yc - scale * wy / 2.0; double vmax = yc + scale * wy / 2.0; Interval xd = (Interval){xmin, xmax}; Interval yd = (Interval){ymin, ymax}; /*** Ordinary interval arithmetic plot ***/ if (epsformat) { psfile = open_write(txtcat(fileprefix, "-ia.eps")); ps_begin_figure(psfile, 0.0, hmax-hmin, 0.0, vmax-vmin); ps_set_window(psfile, xmin, xmax, ymin, ymax, 0.0, hmax-hmin, 0.0, vmax-vmin, n, 1 ); } else { psfile = open_write(txtcat(fileprefix, ".ps")); ps_begin_document(psfile, "letter"); ps_begin_page(psfile, "1"); ps_set_window(psfile, xmin, xmax, ymin, ymax, hmin, hmax, vmin, vmax, n, 1 ); ps_add_caption(psfile, title); ps_add_caption(psfile, ""); ps_add_caption(psfile, parmstr); ps_add_caption(psfile, ""); ps_add_caption(psfile, "Ordinary interval arithmetic"); } ps_set_pen(psfile, 0.0,0.0,0.0, 0.10, 0.0, 0.0); iagraph_plot(psfile, fv, xd, yd, n); ps_set_pen(psfile, 0.5,0.0,0.0, 0.10, 0.0, 0.0); fltgraph_plot(psfile, f, xd, yd, m); ps_set_pen(psfile, 0.0,0.0,0.0, 0.10, 0.0, 0.0); fltgraph_draw_axes(psfile, xd, yd); ps_set_pen(psfile, 0.0,0.0,0.0, 0.25, 0.0, 0.0); ps_draw_frame(psfile); if (epsformat) { ps_end_figure(psfile); fclose(psfile); } else { ps_end_page(psfile); } /*** Affine arithmetic plot ***/ if (epsformat) { psfile = open_write(txtcat(fileprefix, "-aa.eps")); ps_begin_figure(psfile, 0.0, hmax-hmin, 0.0, vmax-vmin); ps_set_window(psfile, xmin, xmax, ymin, ymax, 0.0, hmax-hmin, 0.0, vmax-vmin, n, 1 ); } else { ps_begin_page(psfile, "2"); ps_set_window(psfile, xmin, xmax, ymin, ymax, hmin, hmax, vmin, vmax, n, 1 ); ps_add_caption(psfile, title); ps_add_caption(psfile, ""); ps_add_caption(psfile, parmstr); ps_add_caption(psfile, ""); ps_add_caption(psfile, "Affine arithmetic"); } aagraph_plot_paralelograms(psfile, ff, xd, yd, n); fltgraph_draw_axes(psfile, xd, yd); fltgraph_plot(psfile, f, xd, yd, m); ps_draw_frame(psfile); if (epsformat) { ps_end_figure(psfile); fclose(psfile); } else { ps_end_page(psfile); } /*** Affine arithmetic range plot ***/ if (epsformat) { psfile = open_write(txtcat(fileprefix, "-ar.eps")); ps_begin_figure(psfile, 0.0, hmax-hmin, 0.0, vmax-vmin); ps_set_window(psfile, xmin, xmax, ymin, ymax, 0.0, hmax-hmin, 0.0, vmax-vmin, n, 1 ); } else { ps_begin_page(psfile, "3"); ps_set_window(psfile, xmin, xmax, ymin, ymax, hmin, hmax, vmin, vmax, n, 1 ); ps_add_caption(psfile, title); ps_add_caption(psfile, ""); ps_add_caption(psfile, parmstr); ps_add_caption(psfile, ""); ps_add_caption(psfile, "Affine arithmetic (converted to intervals)"); } aagraph_plot_boxes(psfile, ff, xd, yd, n); fltgraph_draw_axes(psfile, xd, yd); fltgraph_plot(psfile, f, xd, yd, m); ps_draw_frame(psfile); if (epsformat) { ps_end_figure(psfile); fclose(psfile); } else { ps_end_page(psfile); ps_end_document(psfile); fclose(psfile); } }