/* * This program calculates the actual size of a tire given its size * specification. Any number of tire sizes may be specified on the command * line. * * For each size specified, the percentage difference from the first size * specified is also given. This is useful for the difference in speedometer * reading or gearing. * * Tires are specified in the form "185/60R14", for instance. The delimiter * characters are not important. Specifications containing speed ratings (as * in "185/60HR14" are handled correctly. * * TRX wheel sizes (which are measured in millimeters instead of inches) * are handled correctly. * * Note that the output of this program assumes that the size figures in the * specifications are extremely accurate. As this is seldom the case, it is * best to check with each tire manufacturer for more precise information. * * Mark Sirota - University of Rochester, Rochester, NY * Internet: msir_ltd@uhura.cc.rochester.edu * UUCP: {decvax,harvard,ames,rutgers}!rochester!ur-cc!msir_ltd * Now at: mark@greenwich.com (Mark Sirota) * * This program has been tested under SunOS 3.5 and 4.0, BSD4.3, * Ultrix 3.0, Symbolics Genera 7.2, and MSDOS 3.2 (MicroSoft C 5.1). * Thanks to Richard Welty for the Symbolics port; it was quite a learning * experience. * * This program uses getopt() to parse the command line arguments. getopt() * is a part of the standard C library for many implementations; if you don't * have it, it is available for free from numerous archive sites. * * From: Neville D. Newman (neville@ads.com) Oct 2, 1989 * - made default output in English units, added switch to select metric * - use sscanf() for a more robust input format * - output diameter to parallel manufacturers' charts */ #include #define M_PI 3.14159265358979323846 #define ENGLISH 0 #define METRIC 1 /* * Place to store argv[0] */ char *progname = (char *) NULL; void usage() { fprintf(stderr, "Usage: %s [-me] tirespec ...\n", progname); } main(argc, argv) int argc; char **argv; { int c; extern int optind; extern char *optarg; int system = ENGLISH; /* * Store the program name for error messages */ progname = *argv; /* * Parse the arguments. */ while ((c = getopt(argc, argv, "me")) != EOF) switch (c) { case 'm': system = METRIC; break; case 'e': system = ENGLISH; break; case '?': default: usage(); exit(1); } /* * If there are no specifications to process, give the usage message. */ if (optind == argc) { usage(); exit(2); } /* * For each argument, print the parameters of a tire of the given * specification. */ for (; optind < argc; optind++) printparams(argv[optind], system); } /* * Print the parameters for the given tire specification. All internal * storage is done in metric. */ printparams(spec, system) char *spec; int system; { int section, profile, wheel; float wheeldiameter; float sidewall, radius, circumference, revspermile; static float controlradius = -1.0; /* * Parse out the numeric sections of specification */ if (sscanf(spec, "%d%*[^0-9]%d%*[^0-9]%d", §ion, &profile, &wheel) != 3) { fprintf(stderr, "%s: \"%s\": Incorrect tire specification.\n", progname, spec); return; } /* * If the wheel diameter is more than 100, assume it's already * in millimeters. Otherwise, convert it. */ wheeldiameter = (float) wheel; if (wheeldiameter < 100.0) wheeldiameter *= 25.4; /* * Calculate the parameters in question */ sidewall = ((float) profile / 100.0) * (float) section; radius = sidewall + wheeldiameter / 2.0; circumference = 2.0 * radius * M_PI; revspermile = 1609344.0 / circumference; /* * If this is the first size, remember it so we can make comparisons * later. Also, print a header for the chart. */ if (controlradius == -1.0) { controlradius = radius; printf("Specification Sidewall Radius Diameter Circumference Revs/Mile Difference\n"); } /* * Display the results */ if (system == METRIC) printf("%d/%d-%-3d %6.0fmm %4.0fmm %6.0fmm %11.0fmm %9.0f %9.1f%%\n", section, profile, wheel, sidewall, radius, radius * 2.0, circumference, revspermile, ((radius - controlradius) / controlradius) * 100.0); else printf("%d/%d-%-3d %6.1fin %4.1fin %6.1fin %11.1fin %9.0f %9.1f%%\n", section, profile, wheel, sidewall / 25.4, radius / 25.4, (radius * 2.0) / 25.4, circumference / 25.4, revspermile, ((radius - controlradius) / controlradius) * 100.0); }