home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / cgi-bin / Japan / Theme / moon.cgi.c < prev    next >
C/C++ Source or Header  |  2017-09-21  |  2KB  |  93 lines

  1. /*
  2.  * moon.cgi.c
  3.  * 96/12/29 by haruki@st.rim.or.jp
  4.  * original program is created by Christopher Osburn(chris@lunaroutreach.org)
  5.  *
  6.  */
  7. #include <stdio.h>
  8. #include <time.h>
  9. #include <fcntl.h>
  10.  
  11. #define LPERIOD  (2551442.9)   /* synodic period of the moon, seconds,
  12.                                   from astronomical almanac 1992 */
  13.  
  14. #define EPOCH    (811961700L)  /* commencement of lunation 900
  15.                                   1995 Sep 24 16:55 UT (assuming
  16.                                   16:55:00 for lack of better info) */
  17.  
  18. main()
  19. {
  20.     time_t now;
  21.     double qpom();
  22.     int age;
  23.     int per;
  24.     char *moonfile, file[80];
  25.     int fd;
  26.     char c, buf[80];
  27.  
  28.     now = time(NULL);
  29.     age = (int)(qpom(now) + 0.5);
  30.  
  31.     per = (int)(100.0 * (double)age / (LPERIOD / 86400.0));
  32.  
  33.     if (98 <= per || per < 4) {
  34.         moonfile = "moon0.gif";        /* new moon */
  35.     } else if (4 <= per && per < 10) {
  36.         moonfile = "moon1.gif";
  37.     } else if (10 <= per && per < 17) {
  38.         moonfile = "moon2.gif";
  39.     } else if (17 <= per && per < 23) {
  40.         moonfile = "moon3.gif";
  41.     } else if (23 <= per && per < 31) {
  42.         moonfile = "moon4.gif";        /* half moon */
  43.     } else if (31 <= per && per < 36) {
  44.         moonfile = "moon5.gif";
  45.     } else if (36 <= per && per < 41) {
  46.         moonfile = "moon6.gif";
  47.     } else if (41 <= per && per < 47) {
  48.         moonfile = "moon7.gif";
  49.     } else if (47 <= per && per < 55) {
  50.         moonfile = "moon8.gif";        /* full moon */
  51.     } else if (55 <= per && per < 59) {
  52.         moonfile = "moon9.gif";
  53.     } else if (59 <= per && per < 65) {
  54.         moonfile = "moon10.gif";
  55.     } else if (65 <= per && per < 71) {
  56.         moonfile = "moon11.gif";
  57.     } else if (71 <= per && per < 78) {
  58.         moonfile = "moon12.gif";    /* old half moon */
  59.     } else if (78 <= per && per < 85) {
  60.         moonfile = "moon13.gif";
  61.     } else if (85 <= per && per < 92) {
  62.         moonfile = "moon14.gif";
  63.     } else if (92 <= per && per < 98) {
  64.         moonfile = "moon15.gif";
  65.     }
  66.  
  67.     sprintf(file, "%s%s", "moon_gifs/", moonfile);
  68.  
  69.     /* print html */
  70.     printf("Content-type: image/gif\n\n");
  71.     fd = open(file, O_RDONLY);
  72.     while (read(fd, &c, 1) != 0) {
  73.         printf("%c", c);
  74.     }
  75.     close(fd);
  76.  
  77.     exit(0);
  78.     
  79. }
  80.  
  81. #include <math.h>
  82.  
  83. double qpom(now)
  84. time_t now;
  85. {
  86.     double diff, howfar;
  87.  
  88.     diff = (double) now - EPOCH;
  89.     howfar = diff / LPERIOD;
  90.     return LPERIOD * (howfar - (int) howfar) / 86400.0;
  91. }
  92.  
  93.