PROGRAM PIE C C Take up to 25 values and put them in a PIE chart C C The first value goes in a seperate wedge, the rest are part C of a large circle. The values and their calculated C percentages of the whole are listed on the left side C of the plot. C C This program uses the SFGL70 graphics library, with additions C for 4663 plotting by yours truly: C C B. Z. Lederman I.T.T. World Communications C 67 Broad St. C New York, N.Y. 10004 C (212) 797-8080 C REAL VALUE(25), X(101), Y(101), PER(25), TOTAL C C The coordinates of the center of the pie, and its size C PARAMETER CX=410., CY=310., DIAM=300. C C The coordinates of the wedge, and increment for circumference. C PARAMETER RX=510., RY=310., SCALE=6.2831853E-2 C EQUIVALENCE (X(1), X1), (Y(1), Y1), (X(2), X2), (Y(2), Y2) C N = 1 C C Get some data to plot C 100 WRITE (5,110) 110 FORMAT('$ Enter data (^Z to stop): ') READ (5,120, END=130) VALUE(N) 120 FORMAT(F14.7) C C Check to see we don't get too much data C IF (N .GE. 25) GOTO 130 N = N + 1 GOTO 100 130 TOTAL = 0 C C A PIE chart with only two values doesn't look good C IF (N .LT. 2) STOP ' Not enough data' C C Total up the values and get the percentage of each C DO 140 I = 1, N 140 TOTAL = VALUE(I) + TOTAL IF (VALUE(N).LE. 0.0) N = N - 1 DO 150 I = 1, N 150 PER(I) = VALUE(I) / TOTAL * 100. C C Turn on the plotter, reset graphics characteristics, and put in C the X and Y axis C CALL PLTRON CALL PLTRES CALL GRID( 'Pie Chart', 920., 0., 0., ' ', 740., 0., 0., -1) C C Get the rotation for the first element C E = PER(1)/2. * SCALE ROT = E C C Each radial line starts in the center of the circle C X1 = CX Y1 = CY C C First radial line C X2 = DIAM * COS(ROT) + CX Y2 = DIAM * SIN(ROT) + CY C C Plot first line C CALL PLOT( 2, X, Y) C C For each additional segment, plot line from center to circumference C DO 160 I = 2, N ROT = (PER(I) * SCALE) + ROT X2 = DIAM * COS(ROT) + CX Y2 = DIAM * SIN(ROT) + CY 160 CALL PLOT( 2, X, Y) C C Draw in circumference C Q = X2 R = Y2 I = 0 DO 170 W = E, ROT, SCALE I = I + 1 X(I) = DIAM * COS(W) + CX 170 Y(I) = DIAM * SIN(W) + CY I = I + 1 X(I) = Q Y(I) = R CALL PLOT( I, X, Y) C C Offset center of circle to right for seperate wedge C X1 = RX Y1 = RY X2 = DIAM * COS(E) + RX Y2 = DIAM * SIN(E) + RY CALL PLOT( 2, X, Y) Q = X2 R = Y2 X2 = DIAM * COS(-E) + RX Y2 = DIAM * SIN(-E) + RY CALL PLOT( 2, X, Y) I = 0 C C Do cicumference of wedge C DO 180 ROT = -E, E, SCALE I = I + 1 X(I) = DIAM * COS(ROT) + RX 180 Y(I) = DIAM * SIN(ROT) + RY I = I + 1 X(I) = Q Y(I) = R CALL PLOT( I, X, Y) C C Reset to alphanumerics, home cursor, set character size C CALL ALPHA CALL HOME CALL PLTSET(':') C C On some sizes of paper, the top will be missing, so move text down C CALL DOWN(6) C C Write in the data values C DO 190 I = 1, N 190 WRITE (5,200) VALUE(I), PER(I) 200 FORMAT(' ', F8.1, 1X, F6.1, '%') C C Restore plotter characteristics, move the pens off the paper, C and turn the plotter off C CALL PLTRES CALL PLTLOD CALL PLTROF C STOP ' Plotted' C END