/* With no command line arguments, it outputs a drawing of the current phase of the moon. Or you can specify three arguments in decimal to see the phase of the moon at midnight on that date: first argument, day: 1 to 31 inclusive second argument, month: 1 to 12 inclusive third argument, year: don't forget the leading 19. Translated from the BASIC version in Celestial Basic: Astronomy on your Computer by Eric Burgess; Sybex, 1982; pp. 65-71. This file is moonmain.c. It is one of the three .c files that must be compiled to create the executable program moon. Give the -lm argument (for "math library") to cc at the end of the command line. */ #include #include /* declaration for exit function */ #include #include #include "moon.h" main (int argc, char **argv) { int year; int month; int day; int hour; int minute; int second; double radians; if (argc == 1) { time_t clock = time((time_t *)NULL); struct tm *p = localtime(&clock); year = p->tm_year + 1900; month = p->tm_mon + 1; day = p->tm_mday; hour = p->tm_hour; minute = p->tm_min; second = p->tm_sec; } else if (argc == 4) { day = atoi(argv[1]); month = atoi(argv[2]); year = atoi(argv[3]); hour = minute = second = 0; /* midnight */ } else { fprintf (stderr, "%s: arguments (if any): day month year\n", argv[0]); exit (1); } #ifdef DEBUG printf ("clock, year, month, day, hour, min, sec: " "%d %d %d %d %d %d %d\n", clock, year, month, day, hour, minute, second); #endif radians = phase(year, month, day, hour, minute, second); #ifdef DEBUG printf ("radians == %f\n", radians); #endif draw (radians); exit (0); }