/****************************************************************************/ /* (C) Copyright 1993 Universidade Estadual de Campinas (UNICAMP) */ /* Campinas, SP, Brazil */ /* */ /* This file can be freely distributed, modified, and used for any */ /* non-commercial purpose, provided that this copyright and authorship */ /* notice be included in any copy or derived version of this file. */ /* */ /* DISCLAIMER: This software is offered ``as is'', without any guarantee */ /* as to fitness for any particular purpose. Neither the copyright */ /* holder nor the authors or their employers can be held responsible for */ /* any damages that may result from its use. */ /****************************************************************************/ /* See aagrid.h */ #include "aagrid.h" #include "fltzeros2.h" #include #include #include #include #include #include #include #include #include /*** PROTOTYPES FOR INTERNAL PROCEDURES ***/ char *aagrid_format_parms( Interval xd, Interval yd, int n ); /* Formats the arguments into a sctring */ void aagrid_report_stats( FILE *psfile, int epsformat, char *arith, /* "IA" or "AA" */ int nevals, int ncells ); /* Prints evaluation report, and adds caption lines if not $epsformat$ */ void aagrid_plot_aa_zeros(FILE *psfile, int epsformat, AAP ff (AAP x, AAP y), Interval xd, Interval yd, int n ); void aagrid_plot_ia_zeros( FILE *psfile, int epsformat, Interval fv (Interval x, Interval y), Interval xd, Interval yd, int n ); /*** IMPLEMENTATIONS ***/ void aagrid_plots( char *fileprefix, int epsformat, char *title, Float f (Float x, Float y), Interval fv (Interval x, Interval y), AAP ff (AAP x, AAP y), Interval xd, Interval yd, int n, int m ) { char *parmstr = aagrid_format_parms(xd, yd, n); FILE *psfile; Float wx = xd.hi - xd.lo; Float wy = yd.hi - yd.lo; 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; /*** Ordinary interval arithmetic plot ***/ if (epsformat) { psfile = open_write(txtcat(fileprefix, "-ia.eps")); if (psfile == NULL) { error ("aagrid_plots: can't open PostScript file"); } ps_begin_figure( psfile, xd.lo, xd.hi, yd.lo, yd.hi, hmin, hmax, vmin, vmax, n, n ); } else { psfile = open_write(txtcat(fileprefix, ".ps")); if (psfile == NULL) { error ("aagrid_plots: can't open PostScript file"); } ps_begin_document(psfile); ps_begin_page( psfile, 1, xd.lo, xd.hi, yd.lo, yd.hi, hmin, hmax, vmin, vmax, n, n ); 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"); } aagrid_plot_ia_zeros(psfile, epsformat, fv, xd, yd, n); fltzeros2_plot(psfile, f, xd, yd, m); ps_draw_grid_lines(psfile); 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")); if (psfile == NULL) { error ("aagrid_plots: can't open PostScript file"); } ps_begin_figure( psfile, xd.lo, xd.hi, yd.lo, yd.hi, hmin, hmax, vmin, vmax, n, n ); } else { ps_begin_page( psfile, 2, xd.lo, xd.hi, yd.lo, yd.hi, hmin, hmax, vmin, vmax, n, n ); ps_add_caption(psfile, title); ps_add_caption(psfile, ""); ps_add_caption(psfile, parmstr); ps_add_caption(psfile, ""); ps_add_caption(psfile, "Affine arithmetic"); } aagrid_plot_aa_zeros(psfile, epsformat, ff, xd, yd, n); fltzeros2_plot(psfile, f, xd, yd, m); ps_draw_grid_lines(psfile); ps_draw_frame(psfile); ps_end_page(psfile); if (epsformat) { ps_end_figure(psfile); fclose(psfile); } else { ps_end_page(psfile); ps_end_document(psfile, 2); fclose(psfile); } } char *aagrid_format_parms( Interval xd, Interval yd, int n ) { char *s = (char *) malloc(100); sprintf(s, "x in [%f _ %f] y in [%f _ %f] %d intervals", xd.lo, xd.hi, yd.lo, yd.hi, n ); return(s); } void aagrid_plot_aa_zeros( FILE *psfile, int epsformat, AAP ff (AAP x, AAP y), Interval xd, Interval yd, int n ) { Interval xv, yv, zv; int xi, yi; AAP xf, yf, zf; double gray = 0.75; int ncells = 0; char sevals[80]; fprintf(stderr, "\nenter aagrid_plot_aa_zeros...\n"); ps_begin_section(psfile, "Plot of AA-arithmetic zeros"); for (yi=0; yi= Zero)) { ps_fill_grid_cell(psfile, xi, yi, gray); ncells++; } aa_flush(frame); } } ps_end_section(psfile); fprintf(stderr, " done\n"); fprintf(stderr, "%d unresolved cells\n", ncells); if (! epsformat) { sprintf(sevals, "%d unresolved cells", ncells); ps_add_caption(psfile, sevals); } fprintf(stderr, "exit aagrid_plot_aa_zeros.\n"); } void aagrid_plot_ia_zeros( FILE *psfile, int epsformat, Interval fv (Interval x, Interval y), Interval xd, Interval yd, int n ) { Interval xv, yv, zv; int xi, yi; double gray = 0.75; int ncells = 0; char sevals[80]; fprintf(stderr, "\nenter aagrid_plot_ia_zeros...\n"); ps_begin_section(psfile, "Plot of interval-arithmetic zeros"); for (yi=0; yi= Zero)) { ps_fill_grid_cell(psfile, xi, yi, gray); ncells++; } } } ps_end_section(psfile); fprintf(stderr, " done\n"); fprintf(stderr, "%d unresolved cells\n", ncells); if (! epsformat) { sprintf(sevals, "%d unresolved cells", ncells); ps_add_caption(psfile, sevals); } fprintf(stderr, "exit aagrid_plot_ia_zeros.\n"); }