output.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. void
  11. output(char *s, Obj1 *p)
  12. {
  13. if(s == 0)
  14. print(" SAO %5ld", sao);
  15. else
  16. print("%10s", s);
  17. print(" %R %D %9.4f %9.4f %9.4f",
  18. p->ra, p->decl2, p->az, p->el, p->semi2);
  19. if(s == osun.name || s == omoon.name)
  20. print(" %7.4f", p->mag);
  21. print("\n");
  22. }
  23. int
  24. Rconv(Fmt *f)
  25. {
  26. double v;
  27. int h, m, c;
  28. v = va_arg(f->args, double);
  29. v = fmod(v*12/pi, 24); /* now hours */
  30. h = floor(v);
  31. v = fmod((v-h)*60, 60); /* now leftover minutes */
  32. m = floor(v);
  33. v = fmod((v-m)*60, 60); /* now leftover seconds */
  34. c = floor(v);
  35. return fmtprint(f, "%2dh%.2dm%.2ds", h, m, c);
  36. }
  37. int
  38. Dconv(Fmt *f1)
  39. {
  40. double v;
  41. int h, m, c, f;
  42. v = va_arg(f1->args, double);
  43. v = fmod(v/radian, 360); /* now degrees */
  44. f = 0;
  45. if(v > 180) {
  46. v = 360 - v;
  47. f = 1;
  48. }
  49. h = floor(v);
  50. v = fmod((v-h)*60, 60); /* now leftover minutes */
  51. m = floor(v);
  52. v = fmod((v-m)*60, 60); /* now leftover seconds */
  53. c = floor(v);
  54. return fmtprint(f1, "%c%.2d°%.2d'%.2d\"", "+-"[f], h, m, c);
  55. }