/* Ethan Wolf 1995 */ #include #include #include "scio.h" #include "postscript.h" /** Draw likelihood line l(x)=ax+b from low_score to high_score**/ void post_script_like_line(FILE *foutps, double a, double b, double low_score, double high_score) { fprintf(foutps,"\n\n%%%% Plot a least square fit line l(x)=ax+b from x1,like(x1) to x2,like(x2)\n"); fprintf(foutps,"/a %lf def\n",a); fprintf(foutps,"/b %lf def\n",b); fprintf(foutps,"/x1 %lf def\n",low_score); fprintf(foutps,"/x2 %lf def\n", high_score); fprintf(foutps,"/like {a mul b add .02 mul} def %%.02 scales it to the picture\n"); fprintf(foutps,"/likeline {exch dup like vy mul exch vx mul exch moveto\n"); fprintf(foutps, " dup like vy mul exch vx mul exch lineto stroke} def\n"); fprintf(foutps,"\n1 setlinewidth 0 setgray\n"); fprintf(foutps,"x1 x2 likeline\n"); } void post_script_header(FILE *foutps) { fprintf(foutps, "%%!\n"); fprintf(foutps, "/num { /Times-Roman findfont cell-y 16 div scalefont setfont } def\n"); fprintf(foutps, "/title { /Times-Roman findfont cell-y 8 div scalefont setfont 0 setgray } def\n"); fprintf(foutps, "%% These, and the built-in 'show' are text printing procedures:\n"); fprintf(foutps, "/cshow {dup stringwidth pop -2 div 0 rmoveto show}def\n"); fprintf(foutps, "/lshow {dup stringwidth pop neg 0 rmoveto show}def\n\n\n"); fprintf(foutps, "/boxpath { %% x0 y0 x1 y1 boxpath - \n"); fprintf(foutps, " /y1 exch def /x1 exch def\n"); fprintf(foutps, " /y0 exch def /x0 exch def\n"); fprintf(foutps, " x0 y0 moveto x1 y0 lineto x1 y1 lineto x0 y1 lineto closepath\n"); fprintf(foutps, "} def\n\n\n"); fprintf(foutps, "/start-figure { \n"); fprintf(foutps, " gsave 20 dict begin exch translate %% Translate to the cell origin.\n"); fprintf(foutps, " title -30 cell-y .90 mul moveto show %% Print the label.\n"); fprintf(foutps, " 0 0 cell-x cell-y boxpath clip newpath\n"); fprintf(foutps, " /xmax exch def\n"); fprintf(foutps, " /xmin exch def\n"); fprintf(foutps, " /vx cell-x xmax xmin sub div def %% Horizontal scale\n"); fprintf(foutps, " /vy exch cell-y 20 mul mul def\n"); fprintf(foutps, " vy 0 le { /vy vy neg def } %% Vertical scale (don't stretch if neg)\n"); fprintf(foutps, " { /vy vy xmax xmin sub 285 div mul def } ifelse\n"); fprintf(foutps, " /adjust {exch vx mul exch vy mul} def\n"); fprintf(foutps, " gsave vx xmin mul neg cell-y 4 div translate %% Translate to fig's origin.\n"); fprintf(foutps, " 200 dict begin\n"); fprintf(foutps, " gsave\n"); fprintf(foutps, "} def\n\n\n"); fprintf(foutps, "/finish-figure { %% - finish-figure - [need axes defined and labeled]\n"); fprintf(foutps, " grestore %% Still using figure coordinates.\n"); fprintf(foutps, " axes\n"); fprintf(foutps, " end grestore %% Pop to cell coordinates.\n"); fprintf(foutps, " num cell-x 2 div 0 moveto (Score) cshow %% Label X axis\n"); fprintf(foutps, " cell-x 20 div cell-y 1.8 div moveto gsave num 90 rotate label-y cshow grestore\n"); fprintf(foutps, " end grestore %% Pop to page coordinates.\n"); fprintf(foutps, "} def\n\n"); fprintf(foutps, "\n%%%%Height/Width of page.\n"); fprintf(foutps, "/total-y 792 def\n"); fprintf(foutps, "/total-x 612 def\n"); fprintf(foutps, "\n%%%%Space at top and bottom of page.\n"); fprintf(foutps, "/margin-top 116 def\n"); fprintf(foutps, "/margin-bottom 54 def\n"); fprintf(foutps, "\n%%%%Total space at top+bottom of page.\n"); fprintf(foutps, "/margins-y margin-top margin-bottom add def\n"); fprintf(foutps, "\n%%%%Space at left/right of page.\n"); fprintf(foutps, "/margin-left 50 def\n"); fprintf(foutps, "/margin-right 30 def\n"); fprintf(foutps, "\n%%%%Total space at sides of page.\n"); fprintf(foutps, "/margins-x margin-left margin-right add def\n"); fprintf(foutps, "\n%%%%Space between panels of composite.ps.\n"); fprintf(foutps, "/cell-margin-y 24 def\n"); fprintf(foutps, "/cell-margin-x 24 def\n"); fprintf(foutps, "%%%%Number of columnn and rows of panels in composite.ps\n"); fprintf(foutps, "%/ncells-y 3 def\n"); fprintf(foutps, "%/ncells-x 2 def\n"); fprintf(foutps, "/ncells-y 1 def\n"); fprintf(foutps, "/ncells-x 1 def\n\n"); fprintf(foutps, "%%%%Cell=[ (total-margins/#cells) - 2*cell-margin]= size of panel\n"); fprintf(foutps, "/cell-y total-y margins-y sub ncells-y div cell-margin-y 2 mul sub def\n"); fprintf(foutps, "/cell-x total-x margins-x sub ncells-x div cell-margin-x 2 mul sub def\n\n"); fprintf(foutps, "%% X-coordinates of histogram cells.\n%% i.e. left is the coordinate to start panels in column 1, right is the coordinate for panels in column 2.\n"); fprintf(foutps, "/left margin-left cell-margin-x add def\n"); fprintf(foutps, "/right total-x ncells-x div cell-margin-x add def\n"); fprintf(foutps, "%% Y-coordinates of histogram cells.\n"); fprintf(foutps, "%% If not all are used, then the order of use is /top to /bottom. This depends on #cells.\n"); fprintf(foutps, "/top cell-y cell-margin-y 2 mul add ncells-y 1 sub mul cell-margin-y add margin-bottom add def\n"); fprintf(foutps, "/upper cell-y cell-margin-y 2 mul add ncells-y 2 sub mul cell-margin-y add margin-bottom add def\n"); fprintf(foutps, "/lower cell-y cell-margin-y 2 mul add ncells-y 3 sub mul cell-margin-y add margin-bottom add def\n"); fprintf(foutps, "/bottom cell-y cell-margin-y 2 mul add ncells-y 4 sub mul cell-margin-y add margin-bottom add def\n"); fprintf(foutps, "/bottom lower def\n"); fprintf(foutps, "/lower lower 1000 sub def\n\n"); fprintf(foutps, "/prep-x-axis {\n"); fprintf(foutps, " 0.5 setlinewidth 0 setgray\n"); fprintf(foutps, " num %% set up font for numbering\n"); fprintf(foutps, " xmax xmin sub 2 div xmin add 0 moveto %% centered on X axis\n"); fprintf(foutps, "} def\n"); fprintf(foutps, "\n"); fprintf(foutps, "/x-axis {\n"); fprintf(foutps, " prep-x-axis\n"); fprintf(foutps, " xmin max %% number no lower than the cutoff arg\n"); fprintf(foutps, " dup 10 mod sub %% min to next highest 10x (assuming negative)\n"); fprintf(foutps, " 10 xmax {\n"); fprintf(foutps, " dup vx mul 0 moveto 0 cell-y -36 div rlineto stroke dup vx mul\n"); fprintf(foutps, " cell-y -8 div moveto temp-string cvs cshow\n"); fprintf(foutps, " %% move down and show the x-axis number\n"); fprintf(foutps, " } for\n"); fprintf(foutps, " 0 0 moveto 0 cell-y -18 div rlineto stroke\n"); fprintf(foutps, "} def\n\n"); fprintf(foutps, "/min {1 index 1 index lt {pop} {exch pop} ifelse} def\n"); fprintf(foutps, "/max {1 index 1 index gt {pop} {exch pop} ifelse} def\n\n"); fprintf(foutps, "/temp-string 20 string def\n\n"); fprintf(foutps, "/hlines { \n"); fprintf(foutps, " 0.2 setlinewidth 0 setgray\n"); fprintf(foutps, " xmin 0 adj2 moveto xmin 1 adj2 lineto stroke\n"); fprintf(foutps, " xmin 0 adj2 moveto xmax 0 adj2 lineto stroke\n"); fprintf(foutps, " [3] 12 setdash\n"); fprintf(foutps, " 0.2 0.2 1.0 {dup xmin exch adj2 moveto xmax exch adj2 lineto stroke} for\n"); fprintf(foutps, " [] 0 setdash\n"); fprintf(foutps, " 0 0.1 1 {xmin exch adj2 moveto -3 0 rlineto stroke} for num\n"); fprintf(foutps, "%%%%Now print out the cooridinates on the y-axis.\n"); fprintf(foutps, " 0 0.2 1.0 {dup xmin exch adj2 moveto -5 -3 rmoveto temp-string cvs lshow}for\n"); fprintf(foutps, "} def\n\n\n"); fprintf(foutps, "/adj2 { exch vx mul cell-x 4.5 div add exch ystretch mul } def\n\n"); fprintf(foutps, "/ystretch { vy 50 div } def\n\n"); fprintf(foutps, "/label-y (Likelihood) def\n"); fprintf(foutps, "%% -1.5 1 mul -65 35 () bottom right start-figure\n"); fprintf(foutps, " -1.5 1 mul -65 35 () top left start-figure\n"); fprintf(foutps, "/axes { hlines xmin 20 add x-axis } def\n"); fprintf(foutps, " -42 0 adjust cell-x cell-y boxpath clip newpath\n\n\n"); fprintf(foutps, "vx .5 mul setlinewidth 0.5 setgray\n"); fprintf(foutps, "/bar {exch vx mul 0 moveto 0 exch vy mul .02 mul rlineto stroke} def\n"); fprintf(foutps, "/adjust {exch vx mul exch vy mul} def\n"); fprintf(foutps, "\n"); } void post_script_trailer(FILE *foutps) { fprintf(foutps, "\nfinish-figure\n"); fprintf(foutps, "showpage\n"); fprintf(foutps, "%%%%Trailer\n"); }