main.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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* herefile = "/lib/sky/here";
  11. void
  12. main(int argc, char *argv[])
  13. {
  14. int i, j;
  15. double d;
  16. pi = atan(1.0)*4;
  17. pipi = pi*2;
  18. radian = pi/180;
  19. radsec = radian/3600;
  20. converge = 1.0e-14;
  21. fmtinstall('R', Rconv);
  22. fmtinstall('D', Dconv);
  23. per = PER;
  24. deld = PER/NPTS;
  25. init();
  26. args(argc, argv);
  27. init();
  28. loop:
  29. d = day;
  30. pdate(d);
  31. if(flags['p'] || flags['e']) {
  32. print(" ");
  33. ptime(d);
  34. pstime(d);
  35. }
  36. print("\n");
  37. for(i=0; i<=NPTS+1; i++) {
  38. setime(d);
  39. for(j=0; objlst[j]; j++) {
  40. (*objlst[j]->obj)();
  41. setobj(&objlst[j]->point[i]);
  42. if(flags['p']) {
  43. if(flags['m'])
  44. if(strcmp(objlst[j]->name, "Comet"))
  45. continue;
  46. output(objlst[j]->name, &objlst[j]->point[i]);
  47. }
  48. }
  49. if(flags['e']) {
  50. d = dist(&eobj1->point[i], &eobj2->point[i]);
  51. print("dist %s to %s = %.4f\n", eobj1->name, eobj2->name, d);
  52. }
  53. // if(flags['p']) {
  54. // pdate(d);
  55. // print(" ");
  56. // ptime(d);
  57. // print("\n");
  58. // }
  59. if(flags['p'] || flags['e'])
  60. break;
  61. d += deld;
  62. }
  63. if(!(flags['p'] || flags['e']))
  64. search();
  65. day += per;
  66. nperiods -= 1;
  67. if(nperiods > 0)
  68. goto loop;
  69. exits(0);
  70. }
  71. void
  72. args(int argc, char *argv[])
  73. {
  74. char *p;
  75. long t;
  76. int f, i;
  77. Obj2 *q;
  78. memset(flags, 0, sizeof(flags));
  79. ARGBEGIN {
  80. default:
  81. fprint(2, "astro [-adeklmopst] [-c nperiod] [-C tperiod]\n");
  82. exits(0);
  83. case 'c':
  84. nperiods = 1;
  85. p = ARGF();
  86. if(p)
  87. nperiods = atol(p);
  88. flags['c']++;
  89. break;
  90. case 'C':
  91. p = ARGF();
  92. if(p)
  93. per = atof(p);
  94. break;
  95. case 'e':
  96. eobj1 = nil;
  97. eobj2 = nil;
  98. p = ARGF();
  99. if(p) {
  100. for(i=0; (q=objlst[i]) != nil; i++) {
  101. if(strcmp(q->name, p) == 0)
  102. eobj1 = q;
  103. if(strcmp(q->name1, p) == 0)
  104. eobj1 = q;
  105. }
  106. p = ARGF();
  107. if(p) {
  108. for(i=0; (q=objlst[i]) != nil; i++) {
  109. if(strcmp(q->name, p) == 0)
  110. eobj2 = q;
  111. if(strcmp(q->name1, p) == 0)
  112. eobj2 = q;
  113. }
  114. }
  115. }
  116. if(eobj1 && eobj2) {
  117. flags['e']++;
  118. break;
  119. }
  120. fprint(2, "cant recognize eclipse objects\n");
  121. exits("eflag");
  122. case 'a':
  123. case 'd':
  124. case 'j':
  125. case 'k':
  126. case 'l':
  127. case 'm':
  128. case 'o':
  129. case 'p':
  130. case 's':
  131. case 't':
  132. flags[ARGC()]++;
  133. break;
  134. } ARGEND
  135. if(*argv){
  136. fprint(2, "usage: astro [-dlpsatokm] [-c nday] [-e obj1 obj2]\n");
  137. exits("usage");
  138. }
  139. t = time(0);
  140. day = t/86400. + 25567.5;
  141. if(flags['d'])
  142. day = readate();
  143. if(flags['j'])
  144. print("jday = %.4f\n", day);
  145. deltat = day * .001704;
  146. if(deltat > 32.184) // assume date is utc1
  147. deltat = 32.184; // correct by leap sec
  148. if(flags['t'])
  149. deltat = readdt();
  150. if(flags['l']) {
  151. fprint(2, "nlat wlong elev\n");
  152. readlat(0);
  153. } else {
  154. f = open(herefile, OREAD);
  155. if(f < 0) {
  156. fprint(2, "%s?\n", herefile);
  157. /* btl mh */
  158. nlat = (40 + 41.06/60)*radian;
  159. awlong = (74 + 23.98/60)*radian;
  160. elev = 150 * 3.28084;
  161. } else {
  162. readlat(f);
  163. close(f);
  164. }
  165. }
  166. }
  167. double
  168. readate(void)
  169. {
  170. int i;
  171. Tim t;
  172. fprint(2, "year mo da hr min\n");
  173. rline(0);
  174. for(i=0; i<5; i++)
  175. t.ifa[i] = atof(skip(i));
  176. return convdate(&t);
  177. }
  178. double
  179. readdt(void)
  180. {
  181. fprint(2, "ΔT (sec) (%.3f)\n", deltat);
  182. rline(0);
  183. return atof(skip(0));
  184. }
  185. double
  186. etdate(int32_t year, int mo, double day)
  187. {
  188. Tim t;
  189. t.ifa[0] = year;
  190. t.ifa[1] = mo;
  191. t.ifa[2] = day;
  192. t.ifa[3] = 0;
  193. t.ifa[4] = 0;
  194. return convdate(&t) + 2415020;
  195. }
  196. void
  197. readlat(int f)
  198. {
  199. rline(f);
  200. nlat = atof(skip(0)) * radian;
  201. awlong = atof(skip(1)) * radian;
  202. elev = atof(skip(2)) * 3.28084;
  203. }
  204. double
  205. fmod(double a, double b)
  206. {
  207. return a - floor(a/b)*b;
  208. }