/* Program: Ratio.c Revision: 19-NOV-1995 This program ask for you to enter a number of parameters: The compression ratio stroke connecting rod length center to center The program then shows you, in increments of 10 degrees as the crankshaft moves from 180 degrees BTDC to TDC, the compression already achieved, the compression yet to take place, and the distance the piston is from the top of its travel. I'm not sure of the definition of compression ratio but for now let's use: Ratio of the total volume when the piston is at the bottom of its stroke, i.e. volume of the cylinder + combustion chamber, to the volume that the gas currently occupies, i.e. the current volume in the cylinder (if any) + any volume left in the combustion chamber. */ #include #include #define PI 3.1415926 #define INC_DEGREES -10.0 #define MAXLINE 80 main () { float degrees, comp_ratio, stroke, con_rod_length ; float comp_achieved, comp_to_go, distance_below_top ; float crank_part, con_rod_part, piston_location ; float radians, pist_loc_180, pist_loc_0 ; float delta_pist_loc, cur_comp_ratio, Vcy, Vhd ; float cur_vol, crank_throw, piston_btdc ; char filename[MAXLINE] ; FILE *fpout ; printf(" \n "); printf(" " ); printf(" " ); printf(" \n "); printf("Enter the Compression Ratio for this engine: ") ; scanf( "%f", &comp_ratio ) ; printf(" \n ") ; printf("Enter the Stroke for this engine: ") ; scanf( "%f", &stroke ) ; printf(" \n ") ; printf("Enter the Connecting Rod Length for this engine: ") ; scanf( "%f", &con_rod_length ) ; printf(" \n ") ; /* Get the filename of the output file */ printf("Enter the filename of the TopDrawer output file: "); scanf("%s", filename); if ((fpout = fopen(filename, "w", "rat=cr", "rfm=var")) == NULL) { printf("\nERROR: Can't open output file %s\n", filename); exit (1); } /* Calculate some values that we will needed values */ crank_throw = stroke / 2.0 ; degrees = 180.0 ; radians = (degrees / 360.0) * 2 * PI ; crank_part = crank_throw * cos(radians) ; con_rod_part = sqrt( (con_rod_length * con_rod_length) - ( (crank_throw * sin(radians)) * (crank_throw * sin(radians)) ) ) ; pist_loc_180 = crank_part + con_rod_part ; degrees = 0.0 ; radians = (degrees / 360.0) * 2 * PI ; crank_part = crank_throw * cos(radians) ; con_rod_part = sqrt( (con_rod_length * con_rod_length) - ( (crank_throw * sin(radians)) * (crank_throw * sin(radians)) ) ) ; pist_loc_0 = crank_part + con_rod_part ; delta_pist_loc = pist_loc_0 - pist_loc_180 ; Vcy = delta_pist_loc ; Vhd = Vcy / (comp_ratio - 1.0) ; /* Calculate and display the table. */ printf( "\n " ); printf( "\n Crankshaft Pistion " ); printf( "\n Degrees Compression Volume Left Location " ); printf( "\n BTDC Achieved To Compress BTDC " ); printf( "\n ---------- ----------- ----------- --------- " ); for (degrees = 180.0; degrees >= 0.0; degrees += INC_DEGREES ) { radians = (degrees / 360.0) * 2 * PI ; crank_part = crank_throw * cos(radians) ; con_rod_part = sqrt( (con_rod_length * con_rod_length) - ( (crank_throw * sin(radians)) * (crank_throw * sin(radians)) ) ) ; piston_location = crank_part + con_rod_part ; cur_vol = pist_loc_0 - piston_location + Vhd ; cur_comp_ratio = ( Vcy + Vhd ) / cur_vol ; piston_btdc = pist_loc_0 - piston_location ; printf( "\n %4.1f %4.2f %4.2f %4.1f ", degrees, cur_comp_ratio, cur_vol, piston_btdc ) ; } /* Now Calculate and Write the TopDrawer Command File */ /* First the Compression Ration Graph */ fprintf(fpout, "\n $ TopDrawer" ) ; fprintf(fpout, "\n SET DEVICE POSTSCR") ; fprintf(fpout, "\n TITLE TOP 'Compression Ratio'"); fprintf(fpout, "\n TITLE LEFT 'Compression Ratio no units'"); fprintf(fpout, "\n TITLE BOTTOM 'Crankshaft Rotation in Degrees BTDC'"); fprintf(fpout, "\n SET LIMITS X 0 TO 180"); fprintf(fpout, "\n SET ORDER X Y"); for (degrees = 180.0; degrees >= 0.0; degrees += (INC_DEGREES / 5) ) { radians = (degrees / 360.0) * 2 * PI ; crank_part = crank_throw * cos(radians) ; con_rod_part = sqrt( (con_rod_length * con_rod_length) - ( (crank_throw * sin(radians)) * (crank_throw * sin(radians)) ) ) ; piston_location = crank_part + con_rod_part ; cur_vol = pist_loc_0 - piston_location + Vhd ; cur_comp_ratio = ( Vcy + Vhd ) / cur_vol ; piston_btdc = pist_loc_0 - piston_location ; fprintf(fpout, "\n %4.1f %4.3f ", degrees, cur_comp_ratio ) ; } fprintf(fpout, "\n PLOT"); fprintf(fpout, "\n JOIN SPLINE"); /* Now the Piston Location Graph */ fprintf(fpout, "\n NEW PLOT") ; fprintf(fpout, "\n SET DEVICE POSTSCR") ; fprintf(fpout, "\n TITLE TOP 'Piston Location'"); fprintf(fpout, "\n TITLE LEFT 'Piston Location from TDC in mm'"); fprintf(fpout, "\n TITLE BOTTOM 'Crankshaft Rotation in Degrees BTDC'"); fprintf(fpout, "\n SET LIMITS X 0 TO 180"); fprintf(fpout, "\n SET ORDER X Y"); for (degrees = 180.0; degrees >= 0.0; degrees += (INC_DEGREES / 5) ) { radians = (degrees / 360.0) * 2 * PI ; crank_part = crank_throw * cos(radians) ; con_rod_part = sqrt( (con_rod_length * con_rod_length) - ( (crank_throw * sin(radians)) * (crank_throw * sin(radians)) ) ) ; piston_location = crank_part + con_rod_part ; cur_vol = pist_loc_0 - piston_location + Vhd ; cur_comp_ratio = ( Vcy + Vhd ) / cur_vol ; piston_btdc = pist_loc_0 - piston_location ; fprintf(fpout, "\n %4.1f %4.2f ", degrees, piston_btdc ) ; } fprintf(fpout, "\n PLOT"); fprintf(fpout, "\n JOIN SPLINE"); fprintf(fpout, "\n EXIT"); fprintf(fpout, "\n $!"); }