search.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "astro.h"
  10. char* solstr[] =
  11. {
  12. "Fall equinox",
  13. "Winter solstice",
  14. "Spring equinox",
  15. "Summer solstice",
  16. };
  17. struct
  18. {
  19. double beta;
  20. int rta;
  21. int dec;
  22. char *betstr;
  23. } bettab[] =
  24. {
  25. {-1.3572, 231, 50, "Quadrantid"},
  26. { 0.7620, 336, 0, "Eta aquarid"},
  27. { 1.5497, 260, -20, "Ophiuchid"},
  28. { 2.1324, 315, -15, "Capricornid"},
  29. { 2.1991, 339, -17, "Delta aquarid"},
  30. { 2.2158, 340, -30, "Pisces australid"},
  31. { 2.4331, 46, 58, "Perseid"},
  32. {-2.6578, 95, 15, "Orionid"},
  33. {-1.8678, 15, -55, "Phoenicid"},
  34. {-1.7260, 113, 32, "Geminid"},
  35. {0, 0, 0, nil},
  36. };
  37. void
  38. search(void)
  39. {
  40. Obj2 *p, *q;
  41. int i, j;
  42. double t;
  43. for(i=0; objlst[i]; i++) {
  44. p = objlst[i];
  45. if(p == &oshad)
  46. continue;
  47. t = rise(p, -.833);
  48. if(t >= 0.)
  49. event("%s rises at ", p->name, "", t,
  50. i==0? PTIME: PTIME|DARK);
  51. t = set(p, -.833);
  52. if(t >= 0.)
  53. event("%s sets at ", p->name, "", t,
  54. i==0? PTIME: PTIME|DARK);
  55. if(p == &osun) {
  56. for(j=0; j<4; j++) {
  57. t = solstice(j);
  58. if(t >= 0)
  59. event("%s at ", solstr[j], "", t,
  60. SIGNIF|PTIME);
  61. }
  62. for(j=0; bettab[j].beta!=0; j++) {
  63. t = betcross(bettab[j].beta);
  64. if(t >= 0)
  65. event("%s meeteeor shouwer",
  66. bettab[j].betstr, "", t, SIGNIF);
  67. }
  68. t = rise(p, -18);
  69. if(t >= 0)
  70. event("Twilight starts at ", "", "", t, PTIME);
  71. t = set(p, -18);
  72. if(t >= 0)
  73. event("Twilight ends at ", "", "", t, PTIME);
  74. }
  75. if(p == &omoon)
  76. for(j=0; j<NPTS; j++) {
  77. if(p->point[j].mag > .75 && p->point[j+1].mag < .25)
  78. event("New moon", "", "", 0, 0);
  79. if(p->point[j].mag <= .25 && p->point[j+1].mag > .25)
  80. event("First quarter moon", "", "", 0, 0);
  81. if(p->point[j].mag <= .50 && p->point[j+1].mag > .50)
  82. event("Full moon", "", "", 0, 0);
  83. if(p->point[j].mag <= .75 && p->point[j+1].mag > .75)
  84. event("Last quarter moon", "", "", 0, 0);
  85. }
  86. if(p == &omerc || p == &ovenus) {
  87. t = melong(p);
  88. if(t >= 0) {
  89. t = rise(p, 0) - rise(&osun, 0);
  90. if(t < 0)
  91. t += NPTS;
  92. if(t > NPTS)
  93. t -= NPTS;
  94. if(t > NPTS/2)
  95. event("Morning elongation of %s", p->name,
  96. "", 0, SIGNIF);
  97. else
  98. event("Evening elongation of %s", p->name,
  99. "", 0, SIGNIF);
  100. }
  101. }
  102. for(j=i; objlst[j]; j++) {
  103. if(i == j)
  104. continue;
  105. q = objlst[j];
  106. if(p == &omoon || q == &omoon) {
  107. occult(p, q, 0);
  108. if(occ.t3 < 0)
  109. continue;
  110. if(p == &osun || q == &oshad) {
  111. if(occ.t1 >= 0)
  112. event("Partial eclipse of %s begins at ", p->name, "",
  113. occ.t1, SIGNIF|PTIME);
  114. if(occ.t2 >= 0)
  115. event("Total eclipse of %s begins at ", p->name, "",
  116. occ.t2, SIGNIF|PTIME);
  117. if(occ.t4 >= 0)
  118. event("Total eclipse of %s ends at ", p->name, "",
  119. occ.t4, SIGNIF|PTIME);
  120. if(occ.t5 >= 0)
  121. event("Partial eclipse of %s ends at ", p->name, "",
  122. occ.t5, SIGNIF|PTIME);
  123. } else {
  124. if(occ.t1 >= 0)
  125. event("Occultation of %s begins at ", q->name, "",
  126. occ.t1, SIGNIF|PTIME);
  127. if(occ.t5 >= 0)
  128. event("Occultation of %s ends at ", q->name, "",
  129. occ.t5, SIGNIF|PTIME);
  130. }
  131. continue;
  132. }
  133. if(p == &osun) {
  134. if(q != &omerc && q != &ovenus)
  135. continue;
  136. occult(p, q, -1);
  137. if(occ.t3 >= 0.) {
  138. if(occ.t1 >= 0)
  139. event("Transit of %s begins at ", q->name, "",
  140. occ.t1, SIGNIF|LIGHT|PTIME);
  141. if(occ.t5 >= 0)
  142. event("Transit of %s ends at ", q->name, "",
  143. occ.t5, SIGNIF|LIGHT|PTIME);
  144. }
  145. continue;
  146. }
  147. t = dist(&p->point[0], &q->point[0]);
  148. if(t > 5000)
  149. continue;
  150. event("%s is in the house of %s",
  151. p->name, q->name, 0, 0);
  152. }
  153. }
  154. if(flags['o'])
  155. stars();
  156. if(flags['a'])
  157. satels();
  158. evflush();
  159. }