/*
The Source to my Personal Gear Chart Program
For What It's Worth
I'm not sure why it has absolutely no comments
Besides UNIX, and MS-DOS, it has been compiled on a Commodore 64
I think it was originally written in the B language, under
the G-COS Operating System on an old Honeywell machine.
I will not swear yet that this version compiles under MS-DOS,
but it does contain telltale signs of C64 compilation.
This program was written by:
Adrian Pepper.
*/
#define MAXCW 5
#define MAXSPROCK 10
#define WHEELSIZE (27.)
double wheelsize = WHEELSIZE;
int cw[MAXCW], sprock[MAXSPROCK];
int ncw, nsprock;
char *
eatnum(p, pnum)
char *p;
int *pnum;
{
auto int num;
while (*p != '\0' && !('0' <= *p && *p <= '9'))
++p;
for (num = 0; '0' <= *p && *p <= '9'; ++p)
num = num*10 + *p-'0';
*pnum = num;
return p;
}
main(argc, argv)
int argc;
char **argv;
{
init(argc, argv);
chart();
ordered();
}
init(argc, argv)
int argc;
char **argv;
{
auto int i, n;
auto char *p;
if (argc < 3) {
printf("usage %s cw/cw s-s-s-s-s\n", argv[0]);
exit(0);
}
ncw = 0;
nsprock = 0;
for (p = argv[1]; *p != '\0'; ) {
p = eatnum(p, &n);
if (ncw >= MAXCW) {
printf("> %d chainwheels\n", MAXCW);
exit(0);
}
for (i = ncw++; i > 0 && cw[i-1] >= n; --i)
cw[i] = cw[i-1];
cw[i] = n;
}
for (p = argv[2]; *p != '\0'; ) {
p = eatnum(p, &n);
if (nsprock >= MAXSPROCK) {
printf("> %d sprockets\n", MAXSPROCK);
exit(0);
}
for (i = nsprock++; i > 0 && sprock[i-1] >= n; --i)
sprock[i] = sprock[i-1];
sprock[i] = n;
}
}
chart()
{
auto int i, j;
auto float gear;
printf("%11s Chainwheels\n\n%11s", "", "Sprockets");
for (i = 0; i < ncw; ++i)
printf("%5d ", cw[i]);
printf("\n\n");
for (i = 0; i < nsprock; ++i) {
printf("%8d ", sprock[i]);
for (j = 0; j < ncw; ++j) {
gear = cw[j];
gear /= sprock[i];
gear *= wheelsize;
printf("%6.1f", gear+0.05);
}
printf("\n");
}
printf("\n");
}
ordered()
{
auto int sptr[MAXCW];
auto int i;
auto int imax, ngears;
auto float a, maxg;
for (i = 0; i < ncw; ++i)
sptr[i] = nsprock-1;
ngears = 0;
printf("%17s MPH for Cadence in RPM\n","");
printf("No. Comb. Inches");
for (i = 30; i <= 150; i+=30)
printf("%6d",i);
printf("\n\n");
imax = 0;
for ( ; ; ) {
maxg = 10000.;
for (i = 0; i < ncw; ++i) {
if (sptr[i] >= 0) {
a = cw[i];
a /= sprock[sptr[i]];
if (a < maxg) {
maxg = a;
imax = i;
}
}
}
if (maxg >= 10000.) break;
++ngears;
maxg *= wheelsize;
printf("%3d %3d/%2d %5.1f",
ngears, cw[imax], sprock[sptr[imax]], maxg+0.05);
--sptr[imax];
maxg *= 3.14159265 * 60. / (12.*5280.);
for (i = 30; i <= 150; i+=30)
printf("%6.1f", maxg*i + 0.05);
printf("\n");
}
}