http://iel.ucdavis.edu/projects/autolev/ Headers #include <ctype.h> #include <math.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* Header Files Added */ #include <array.h> #include <chplot.h> /* Header Files Added */ Macros #define _NAN 9.99999999999999E+305 /* Constant Definitions Added */ #define POINTS 51 // Number of data points /* Constant Definitions Added */ Variables double Pi,DEGtoRAD,RADtoDEG,z[189],_COEF[4][4],*COEF[4],RHS[4]; /* variables added */ class CPlot plot1; class CPlot plot2; class CPlot plot3; class CPlot plot4; int count = 0; double time[POINTS]; double angles[4][POINTS]; double angvel[4][POINTS]; double alpha[4][POINTS]; double torques[4][POINTS]; /* variables added */ Closing Files /* Inform user of input and output filename(s) */ puts( "\n Input is in the file punt.in" ); puts( "\n Output is in the file(s) punt.i (i=1, ..., 9)" ); puts( "\n The output quantities and associated "files are listed in file punt.dir\n" ); /* Added to Close file and plot results */ fclose(Fptr[1]); fclose(Fptr[2]); etc... /* Added to Close file and plot results */ return 0; } Plotting Setup /* Inform user of input and output filename(s) */ puts( "\n Input is in the file punt.in" ); puts( "\n Output is in the file(s) punt.i (i=1, ..., 9)" ); puts( "\n The output quantities and associated files "are listed in file punt.dir\n" ); /* Added to Close file and plot results */ fclose(Fptr[1]); fclose(Fptr[2]); etc... plotxy(time, angles, "Angles", "t", "angle"); plotxy(time, angles, "Angles", "t (s)", "Angle (deg)", &plot1); plot1.legend("tang ", 0); plot1.legend("lang1", 1); plot1.legend("fang ", 2); plot1.legend("lang2", 3); plot1.legendLocation(0.2,240); plot1.outputType(PLOT_OUTPUTTYPE_FILE, "png color", "plot_1.png"); plot1.plotting(); /* Added to Close file and plot results */ return 0; } Saving Data /* Write output to screen and to output file(s) */ writef(stdout, " %- 14.6E", T,... writef(Fptr[1]," %- 14.6E", T,... /* Added arrays for plotting */ time[count] = T; angles[0][count] = (TANG*RADtoDEG); angles[1][count] = (LANG1*RADtoDEG); angles[2][count] = (FANG*RADtoDEG); angles[3][count] = (LANG2*RADtoDEG); angvel[0][count] = U1; angvel[1][count] = U2; angvel[2][count] = U3; angvel[3][count] = U4; alpha[0][count] = U1p; alpha[1][count] = U2p; alpha[2][count] = U3p; alpha[3][count] = U4p; torques[0][count] = TA; torques[1][count] = TH; torques[2][count] = TK1; torques[3][count] = TK2; count++; /* Added arrays for plotting */ Quick Code Modification /* Write heading(s) to output file(s) */ fprintf(stdout, " FILE: p-13-10.1\n\n *** %s\n\n", string); fprintf(stdout, " T Q2\n" " (UNITS) (DEG)\n\n" ); fprintf(Fptr[1], "# FILE: p-13-10.1\n#\n# *** %s#\n#\n", string); fprintf(Fptr[1], "# T Q2\n" "# (UNITS) (DEG)\n#\n" ); /* # at each line of heading */ External Plot File /* p-13-10-plotab.ch */ /* Plotting the output of p-13-10.ch for Dynamics */ /* Initial values: q1(0) = 45 & q2(0) = 1, 0.5 */ #include #include int main() { class CPlot plot; char *title = "q2 vs. t w/ q1(0) = 45"; char *xlabel = "time (s)"; char *ylabel = "q2 (deg)"; plot.dataFile("p-13-10.1(a)"); /* input file */ plot.dataFile("p-13-10.1(b)"); /* input file */ plot.legend("q2(0) = 1.0", 0); plot.legend("q2(0) = 0.5", 1); plot.legendLocation(9,1.5); plot.title(title); plot.label(PLOT_AXIS_X, xlabel); plot.label(PLOT_AXIS_Y, ylabel); plot.plotting(); plot.outputType(PLOT_OUTPUTTYPE_FILE, "png color", "plot.png"); plot.plotting(); return 0; }