1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <strings.h>
4 #include <time.h>
5
6 int max_x=576, max_y=288;
7 extern float f_fx, f_fy;
8 #define SX(x) (int)(f_fx*(float)(x))
9
10 /* black blue cyan green lt_green */
11 float rlincol[]={0.0,0.0,0.0,0.45,0.0};
12 float glincol[]={0.0,0.0,0.5,0.30,1.0};
13 float blincol[]={0.0,0.8,0.5,0.15,0.0};
14
15 int *linarr;
16 int nlinarr=5;
17
18 float fxscal, fyscal, fxoff, fyoff;
19
20 void linetype(int);
21 void clsline();
22
23 void
openpl()24 openpl()
25 {
26 time_t tt;
27
28 tt = time(NULL);
29
30 printf("%%!PS-Adobe-2.0\n");
31 printf("%%%%Creator: plalign\n");
32 printf("%%%%CreationDate: %s",ctime(&tt));
33 printf("%%%%DocumentFonts: Courier\n");
34 printf("%%%%Pages: 1\n");
35 printf("%%%%BoundingBox: 18 0 594 306\n");
36 printf("%%%%EndComments\n");
37 printf("%%%%EndProlog\n");
38 printf("%%%%Page: 1 1\n");
39 printf("/Courier findfont 14 scalefont setfont\n");
40 printf("/vcprint { gsave 90 rotate dup stringwidth pop 2 div neg 0 rmoveto\n");
41 printf("show newpath stroke grestore } def\n");
42 printf("/hcprint { gsave dup stringwidth pop 2 div neg 0 rmoveto\n");
43 printf("show newpath stroke grestore } def\n");
44 printf("/hrprint { gsave dup stringwidth pop neg 0 rmoveto\n");
45 printf("show newpath stroke grestore } def\n");
46 printf("/hprint { gsave show newpath stroke grestore } def\n");
47 printf("18 0 translate\n");
48
49 linetype(0);
50 }
51
52 void
linetype(int type)53 linetype(int type)
54 {
55 printf("%5.3f %5.3f %5.3f setrgbcolor\n",
56 rlincol[type],glincol[type],blincol[type]);
57 }
58
59 void
closepl()60 closepl() {
61 printf("%%%%Trailer\n");
62 printf("showpage\n");
63 printf("%%%%EOF\n");
64 }
65
66 void
space(int x0,int y0,int x1,int y1)67 space(int x0, int y0, int x1, int y1) {
68 fxoff = (float)x0;
69 fyoff = (float)y0;
70 fxscal = (float)(max_x)/(float)(x1-x0);
71 fyscal = (float)(max_y)/(float)(y1-y0);
72 }
73
74 void
move(int x,int y)75 move(int x, int y)
76 {
77 int xx, yy;
78 xx = (int)(((float)(x)-fxoff)*fxscal);
79 yy = (int)(((float)(y)-fyoff)*fyscal);
80 printf("%d %d moveto\n",xx,yy);
81 }
82
83 void
cont(int x,int y)84 cont(int x, int y)
85 {
86 int xx, yy;
87 xx = (int)(((float)(x)-fxoff)*fxscal);
88 yy = (int)(((float)(y)-fyoff)*fyscal);
89 printf("%d %d lineto\n",xx,yy);
90 }
91
92 void
drawstr(char * str)93 drawstr(char *str)
94 {
95 char *bp;
96
97 for (bp = strchr(str,'('); (bp!=NULL); bp = strchr(bp+1,'(')) *bp=' ';
98 for (bp = strchr(str,')'); (bp!=NULL); bp = strchr(bp+1,')')) *bp=' ';
99
100 printf("(%s) show\n",str);
101 }
102
103 int tarr[] = {10,20,50,100,200,500,1000,2000,5000};
104 int ntarr = sizeof(tarr);
105
106 void
xaxis(int n,char * title)107 xaxis(int n, char *title)
108 {
109 int i, jm, tick;
110 int js;
111 char numstr[20];
112
113 tick = -10;
114
115 for (i=0; i<ntarr; i++) if ((jm = n/tarr[i])<21) goto found;
116 jm = n/5000l; i=ntarr-1;
117 found: js = tarr[i];
118
119 for (i=1; i<=jm; i++) {
120 move(SX(i*js),0);
121 cont(SX(i*js),tick);
122 clsline();
123 }
124
125 sprintf(numstr,"%d",js);
126 move(SX(js)-20,tick-40);
127 drawstr(numstr);
128 sprintf(numstr,"%d",jm*js);
129 move(SX(jm*js)-20,tick-40);
130 drawstr(numstr);
131 i = tick-80;
132 move(SX(n/2)-strlen(title)*8,i);
133 drawstr(title);
134 }
135
136 void
clsline()137 clsline()
138 {
139 printf("stroke\n");
140 }
141