6 #include "postscript.h"
9 /** Draw likelihood line l(x)=ax+b from low_score to high_score**/
10 void post_script_like_line(FILE *foutps, double a, double b,
11 double low_score, double high_score)
13 fprintf(foutps,"\n\n%%%% Plot a least square fit line l(x)=ax+b from x1,like(x1) to x2,like(x2)\n");
14 fprintf(foutps,"/a %lf def\n",a);
15 fprintf(foutps,"/b %lf def\n",b);
16 fprintf(foutps,"/x1 %lf def\n",low_score);
17 fprintf(foutps,"/x2 %lf def\n", high_score);
18 fprintf(foutps,"/like {a mul b add .02 mul} def %%.02 scales it to the picture\n");
19 fprintf(foutps,"/likeline {exch dup like vy mul exch vx mul exch moveto\n");
21 " dup like vy mul exch vx mul exch lineto stroke} def\n");
23 fprintf(foutps,"\n1 setlinewidth 0 setgray\n");
24 fprintf(foutps,"x1 x2 likeline\n");
30 void post_script_header(FILE *foutps)
32 fprintf(foutps, "%%!\n");
33 fprintf(foutps, "/num { /Times-Roman findfont cell-y 16 div scalefont setfont } def\n");
34 fprintf(foutps, "/title { /Times-Roman findfont cell-y 8 div scalefont setfont 0 setgray } def\n");
35 fprintf(foutps, "%% These, and the built-in 'show' are text printing procedures:\n");
36 fprintf(foutps, "/cshow {dup stringwidth pop -2 div 0 rmoveto show}def\n");
37 fprintf(foutps, "/lshow {dup stringwidth pop neg 0 rmoveto show}def\n\n\n");
40 fprintf(foutps, "/boxpath { %% x0 y0 x1 y1 boxpath - <rectangular path>\n");
41 fprintf(foutps, " /y1 exch def /x1 exch def\n");
42 fprintf(foutps, " /y0 exch def /x0 exch def\n");
43 fprintf(foutps, " x0 y0 moveto x1 y0 lineto x1 y1 lineto x0 y1 lineto closepath\n");
44 fprintf(foutps, "} def\n\n\n");
48 fprintf(foutps, "/start-figure { \n");
49 fprintf(foutps, " gsave 20 dict begin exch translate %% Translate to the cell origin.\n");
50 fprintf(foutps, " title -30 cell-y .90 mul moveto show %% Print the label.\n");
51 fprintf(foutps, " 0 0 cell-x cell-y boxpath clip newpath\n");
52 fprintf(foutps, " /xmax exch def\n");
53 fprintf(foutps, " /xmin exch def\n");
54 fprintf(foutps, " /vx cell-x xmax xmin sub div def %% Horizontal scale\n");
55 fprintf(foutps, " /vy exch cell-y 20 mul mul def\n");
56 fprintf(foutps, " vy 0 le { /vy vy neg def } %% Vertical scale (don't stretch if neg)\n");
57 fprintf(foutps, " { /vy vy xmax xmin sub 285 div mul def } ifelse\n");
58 fprintf(foutps, " /adjust {exch vx mul exch vy mul} def\n");
59 fprintf(foutps, " gsave vx xmin mul neg cell-y 4 div translate %% Translate to fig's origin.\n");
60 fprintf(foutps, " 200 dict begin\n");
61 fprintf(foutps, " gsave\n");
62 fprintf(foutps, "} def\n\n\n");
65 fprintf(foutps, "/finish-figure { %% - finish-figure - [need axes defined and labeled]\n");
66 fprintf(foutps, " grestore %% Still using figure coordinates.\n");
67 fprintf(foutps, " axes\n");
68 fprintf(foutps, " end grestore %% Pop to cell coordinates.\n");
69 fprintf(foutps, " num cell-x 2 div 0 moveto (Score) cshow %% Label X axis\n");
70 fprintf(foutps, " cell-x 20 div cell-y 1.8 div moveto gsave num 90 rotate label-y cshow grestore\n");
71 fprintf(foutps, " end grestore %% Pop to page coordinates.\n");
72 fprintf(foutps, "} def\n\n");
74 fprintf(foutps, "\n%%%%Height/Width of page.\n");
75 fprintf(foutps, "/total-y 792 def\n");
76 fprintf(foutps, "/total-x 612 def\n");
78 fprintf(foutps, "\n%%%%Space at top and bottom of page.\n");
79 fprintf(foutps, "/margin-top 116 def\n");
80 fprintf(foutps, "/margin-bottom 54 def\n");
81 fprintf(foutps, "\n%%%%Total space at top+bottom of page.\n");
82 fprintf(foutps, "/margins-y margin-top margin-bottom add def\n");
84 fprintf(foutps, "\n%%%%Space at left/right of page.\n");
85 fprintf(foutps, "/margin-left 50 def\n");
86 fprintf(foutps, "/margin-right 30 def\n");
87 fprintf(foutps, "\n%%%%Total space at sides of page.\n");
88 fprintf(foutps, "/margins-x margin-left margin-right add def\n");
90 fprintf(foutps, "\n%%%%Space between panels of composite.ps.\n");
91 fprintf(foutps, "/cell-margin-y 24 def\n");
92 fprintf(foutps, "/cell-margin-x 24 def\n");
93 fprintf(foutps, "%%%%Number of columnn and rows of panels in composite.ps\n");
94 fprintf(foutps, "%/ncells-y 3 def\n");
95 fprintf(foutps, "%/ncells-x 2 def\n");
96 fprintf(foutps, "/ncells-y 1 def\n");
97 fprintf(foutps, "/ncells-x 1 def\n\n");
99 fprintf(foutps, "%%%%Cell=[ (total-margins/#cells) - 2*cell-margin]= size of panel\n");
100 fprintf(foutps, "/cell-y total-y margins-y sub ncells-y div cell-margin-y 2 mul sub def\n");
101 fprintf(foutps, "/cell-x total-x margins-x sub ncells-x div cell-margin-x 2 mul sub def\n\n");
103 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");
104 fprintf(foutps, "/left margin-left cell-margin-x add def\n");
105 fprintf(foutps, "/right total-x ncells-x div cell-margin-x add def\n");
106 fprintf(foutps, "%% Y-coordinates of histogram cells.\n");
107 fprintf(foutps, "%% If not all are used, then the order of use is /top to /bottom. This depends on #cells.\n");
108 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");
109 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");
110 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");
111 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");
112 fprintf(foutps, "/bottom lower def\n");
113 fprintf(foutps, "/lower lower 1000 sub def\n\n");
115 fprintf(foutps, "/prep-x-axis {\n");
116 fprintf(foutps, " 0.5 setlinewidth 0 setgray\n");
117 fprintf(foutps, " num %% set up font for numbering\n");
118 fprintf(foutps, " xmax xmin sub 2 div xmin add 0 moveto %% centered on X axis\n");
119 fprintf(foutps, "} def\n");
120 fprintf(foutps, "\n");
122 fprintf(foutps, "/x-axis {\n");
123 fprintf(foutps, " prep-x-axis\n");
124 fprintf(foutps, " xmin max %% number no lower than the cutoff arg\n");
125 fprintf(foutps, " dup 10 mod sub %% min to next highest 10x (assuming negative)\n");
126 fprintf(foutps, " 10 xmax {\n");
127 fprintf(foutps, " dup vx mul 0 moveto 0 cell-y -36 div rlineto stroke dup vx mul\n");
128 fprintf(foutps, " cell-y -8 div moveto temp-string cvs cshow\n");
129 fprintf(foutps, " %% move down and show the x-axis number\n");
130 fprintf(foutps, " } for\n");
131 fprintf(foutps, " 0 0 moveto 0 cell-y -18 div rlineto stroke\n");
132 fprintf(foutps, "} def\n\n");
135 fprintf(foutps, "/min {1 index 1 index lt {pop} {exch pop} ifelse} def\n");
136 fprintf(foutps, "/max {1 index 1 index gt {pop} {exch pop} ifelse} def\n\n");
138 fprintf(foutps, "/temp-string 20 string def\n\n");
140 fprintf(foutps, "/hlines { \n");
141 fprintf(foutps, " 0.2 setlinewidth 0 setgray\n");
142 fprintf(foutps, " xmin 0 adj2 moveto xmin 1 adj2 lineto stroke\n");
143 fprintf(foutps, " xmin 0 adj2 moveto xmax 0 adj2 lineto stroke\n");
144 fprintf(foutps, " [3] 12 setdash\n");
145 fprintf(foutps, " 0.2 0.2 1.0 {dup xmin exch adj2 moveto xmax exch adj2 lineto stroke} for\n");
146 fprintf(foutps, " [] 0 setdash\n");
147 fprintf(foutps, " 0 0.1 1 {xmin exch adj2 moveto -3 0 rlineto stroke} for num\n");
148 fprintf(foutps, "%%%%Now print out the cooridinates on the y-axis.\n");
149 fprintf(foutps, " 0 0.2 1.0 {dup xmin exch adj2 moveto -5 -3 rmoveto temp-string cvs lshow}for\n");
150 fprintf(foutps, "} def\n\n\n");
153 fprintf(foutps, "/adj2 { exch vx mul cell-x 4.5 div add exch ystretch mul } def\n\n");
155 fprintf(foutps, "/ystretch { vy 50 div } def\n\n");
157 fprintf(foutps, "/label-y (Likelihood) def\n");
158 fprintf(foutps, "%% -1.5 1 mul -65 35 () bottom right start-figure\n");
159 fprintf(foutps, " -1.5 1 mul -65 35 () top left start-figure\n");
160 fprintf(foutps, "/axes { hlines xmin 20 add x-axis } def\n");
161 fprintf(foutps, " -42 0 adjust cell-x cell-y boxpath clip newpath\n\n\n");
165 fprintf(foutps, "vx .5 mul setlinewidth 0.5 setgray\n");
166 fprintf(foutps, "/bar {exch vx mul 0 moveto 0 exch vy mul .02 mul rlineto stroke} def\n");
167 fprintf(foutps, "/adjust {exch vx mul exch vy mul} def\n");
168 fprintf(foutps, "\n");
172 void post_script_trailer(FILE *foutps)
174 fprintf(foutps, "\nfinish-figure\n");
175 fprintf(foutps, "showpage\n");
176 fprintf(foutps, "%%%%Trailer\n");