home *** CD-ROM | disk | FTP | other *** search
- /* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
- #include <stdio.h>
- #define EXTERN extern
- #include <typedef.h>
-
-
- static double s, Fract;
-
-
- static int Balance()
- {
- int Bal;
-
- Bal = 0;
- s = s + Fract;
- if (s >= 0.0) {
- s = s - 1.0;
- Bal = 1;
- }
- return(Bal);
- }
-
-
- void DrawHistogram(A, NPoints, Hatching, HatchStyle)
- double *A;
- int NPoints, Hatching, HatchStyle;
- {
- extern double fabs();
-
- int x1, x2, y2, NPixels, Delta, NDiff, YRef;
- int LineStyleLoc, i;
- int YAxis;
- double y;
- int DirectModeLoc, Negative;
- WindowType wtemp;
- int X1Loc, Y1Loc, X2Loc, Y2Loc;
-
- if (iabs(NPoints) < 2) {
- error(19,4);
- return;
- }
-
- X1Loc = X1Glb;
- Y1Loc = Y1Glb;
- X2Loc = X2Glb;
- Y2Loc = Y2Glb;
- LineStyleLoc = LineStyleGlb;
- SetLineStyle(0);
- if (AxisGlb) {
- memcpy(&wtemp, &window[WindowNdxGlb], sizeof(WindowType));
- ReDefineWindow(WindowNdxGlb, (int)(X1RefGlb + 4 + X1Glb),
- (int)(Y1RefGlb + 6 + Y1Glb), (int)(X2RefGlb - 2 - X2Glb),
- (int)(Y2RefGlb - 14 - Y2Glb));
- SelectWindow(WindowNdxGlb);
- AxisGlb = TRUE;
- }
- DirectModeLoc = DirectModeGlb;
- DirectModeGlb = TRUE;
- Negative = NPoints < 0;
- NPoints = iabs(NPoints);
- NPixels = (X2RefGlb-X1RefGlb) * 8 + 7;
- Delta = NPixels / NPoints;
- NDiff = NPixels - Delta * NPoints;
- Fract = NDiff / NPoints;
- s = -Fract;
- x1 = X1RefGlb * 8;
- YRef = (int)(Y2RefGlb+Y1RefGlb-AyGlb);
- if (Negative)
- DrawStraight(x1,X2RefGlb * 8 + 7,YRef);
- YAxis = Y1RefGlb;
- if (ByGlb > 0)
- YAxis = Y2RefGlb;
-
- for (i = 0; i < 2 * NPoints; i+=2) {
- x2 = x1 + Delta + Balance();
- y = A[1 + i];
- if (!Negative)
- y = fabs(y);
- /*
- if (AxisGlb)
- y2 = (int)(AyGlb+ByGlb*y);
- else
- y2 = (int)((AyGlb+ByGlb*y)*0.99);
- y2 = Y2RefGlb+Y1RefGlb-y2;
- */
- y2 = Y2RefGlb + Y1RefGlb - (int)(AyGlb + ByGlb * y);
-
- if (!Negative) {
- DrawLineDirect(x1, YAxis, x1, y2);
- DrawStraight(x1,x2,y2);
- DrawLineDirect(x2, y2, x2, YAxis);
- if (Hatching) {
- if (i % 4)
- HatchDirect(x1, y2, x2, YAxis, HatchStyle);
- else
- HatchDirect(x1, y2, x2, YAxis, -HatchStyle);
- }
- }
- else {
- DrawLineDirect(x1, YRef, x1, y2);
- DrawStraight(x1,x2,y2);
- DrawLineDirect(x2, y2, x2, YRef);
- if (Hatching) {
- if (YRef-y2 < 0) {
- if (i % 4)
- HatchDirect(x1, YRef, x2, y2, HatchStyle);
- else {
- HatchDirect(x1, YRef, x2, y2, -HatchStyle);
- }
- }
- else {
- if (i % 4)
- HatchDirect(x1, y2, x2, YRef, HatchStyle);
- else
- HatchDirect(x1, y2, x2, YRef, -HatchStyle);
- }
- }
- else
- HatchDirect(x1, y2, x2, YRef, -HatchStyle);
- }
- x1 = x2;
- }
- if (AxisGlb) {
- memcpy(&window[WindowNdxGlb], &wtemp, sizeof(WindowType));
- SelectWindow(WindowNdxGlb);
- X1Glb = X1Loc;
- Y1Glb = Y1Loc;
- X2Glb = X2Loc;
- Y2Glb = Y2Loc;
- AxisGlb = FALSE;
- }
- DirectModeGlb = DirectModeLoc;
- SetLineStyle(LineStyleLoc);
- }
-