/* * $Id: GN.c,v 1.3 2014/11/17 01:09:02 grog Exp $ * * Compare guide numbers. * * Read in lines in format: * * Fraction Aperture:tenths * * Aperture:tenths is the standard exposure meter format where a base aperture * is augmented by units of 0.1 EV. * * Output: Real aperture ("guide number"), calculated aperture, deviation. */ #include #include #include #include #include #include #include #include int main (int argc, char *argv []) { int print_proportions = 0; /* print deviations, not proportions */ char fraction [10]; float frac; /* fraction as float */ float base_aperture; /* as represented in input */ int aperture_fraction; /* as represented in input */ float aperture; /* calculated from preceding 2 */ float expected_aperture; /* calculated from base reading */ float aperture_difference; /* difference between calculated and observed aperture */ float base_gn = 1; /* calculated from power == 1 */ if (argc > 1) { if (strcmp (argv [1], "-p")) { fprintf (stderr, "Only option must be -p (print proportions, not deviations\n"); exit (1); } print_proportions = 1; } printf ("Power ratio\tRaw GN\tReal GN \tExpected Deviation\n\n"); while (scanf ("%s %f:%d\n", fraction, &base_aperture, &aperture_fraction) == 3) { aperture = base_aperture * pow (M_SQRT2, aperture_fraction / 10.); if (! strcmp (fraction, "1")) /* 1 is special, should be first */ { printf ("1\t1\t\%2.0f:%d\t%4.2f\n", base_aperture, aperture_fraction, aperture); base_gn = aperture; } else /* fractional power */ { frac = 1. / atof (&fraction [2]); /* admire the error checking */ expected_aperture = base_gn * sqrt (frac); /* this is what it should be */ if (print_proportions) aperture_difference = pow (aperture, 2) / pow (expected_aperture, 2); else aperture_difference = pow (aperture, 2) / pow (expected_aperture, 2) - 1.; printf ("%s\t%6.5f\t %2.1f:%d \t%4.2f \t%4.2f \t%3.0f\n", fraction, /* as text */ frac, /* numeric fraction */ base_aperture, aperture_fraction, aperture, expected_aperture, aperture_difference * 100.); } } return 0; }