// // sr -- General Relativity (time dilation) calculator for low elevation. // // 30-Apr-2006 tvb www.LeapSecond.com/tools // #include #include #include #include #define INCH_TO_METER(x) ( (x) * 2.54 / 100.0 ) #define FOOT_TO_METER(x) ( INCH_TO_METER((x) * 12) ) #define ALL_UNITS "ft, m, km" void main (int argc, char *argv[]) { double c = 299792458.0; double g = 9.82; double height, h, df; char *units; if (argc < 3) { fprintf(stderr, "Usage: %s [height] [units]\n", argv[0]); fprintf(stderr, "(height units are one of: %s)\n", ALL_UNITS); exit(1); } height = atof(argv[1]); units = argv[2]; if (strcmp(units, "ft") == 0) { h = FOOT_TO_METER(height); } else if (strcmp(units, "m") == 0) { h = height; } else if (strcmp(units, "km") == 0) { h = height * 1000; } else { fprintf(stderr, "Unit %s unknown. Valid units: %s\n", units, ALL_UNITS); exit(1); } if (h < 0) { fprintf(stderr, "Height too low for this tool.\n"); exit(1); } printf("%16.6lf feet\n", 1/FOOT_TO_METER(1/h)); printf("%16.6lf km\n", h / 1000); printf("%16.6lf m\n", h); printf("%16.6lf g\n", g); // Stay close to earth. if (h > 10000) { fprintf(stderr, "Height too high for this tool.\n"); exit(1); } df = g * h / (c * c); printf("%16.6le g*h/c^2\n", df); printf("%16.6lf ps/hour\n", df * 1e12 * 3600); printf("%16.6lf ns/day\n", df * 1e9 * 86400); }