home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume11 / starchart / part11 < prev    next >
Text File  |  1990-03-15  |  44KB  |  1,665 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v11i039: starchart 3.2 Part 11/32
  3. from: ccount@ATHENA.MIT.EDU
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 11, Issue 39
  7. Submitted-by: ccount@ATHENA.MIT.EDU
  8. Archive-name: starchart/part11
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 11 (of 32)."
  17. # Contents:  dataconv/sif_to_text.c observe/main.c
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'dataconv/sif_to_text.c' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'dataconv/sif_to_text.c'\"
  21. else
  22. echo shar: Extracting \"'dataconv/sif_to_text.c'\" \(18386 characters\)
  23. sed "s/^X//" >'dataconv/sif_to_text.c' <<'END_OF_FILE'
  24. X/*
  25. X * sif_to_text -- Produce plain text discriptions
  26. X *                from `sif' format starchart data.
  27. X *
  28. X * Copyright (c) 1990 by Craig Counterman. All rights reserved.
  29. X *
  30. X * This software may be redistributed freely, not sold.
  31. X * This copyright notice and disclaimer of warranty must remain
  32. X *    unchanged. 
  33. X *
  34. X * No representation is made about the suitability of this
  35. X * software for any purpose.  It is provided "as is" without express or
  36. X * implied warranty, to the extent permitted by applicable law.
  37. X *
  38. X * DISCLAIMER OF WARRANTY
  39. X * ----------------------
  40. X * The author  disclaims all warranties  with regard to  this software to
  41. X * the   extent  permitted  by applicable   law,  including all   implied
  42. X * warranties  of merchantability  and  fitness. In  no event shall   the
  43. X * author be liable for any special, indirect or consequential damages or
  44. X * any  damages whatsoever resulting from  loss of use, data or  profits,
  45. X * whether in an action of contract, negligence or other tortious action,
  46. X * arising  out of  or in connection with the  use or performance of this
  47. X * software.
  48. X *
  49. X */
  50. X
  51. Xstatic char rcsid[]="$Header: sif_to_text.c,v 2.6 90/02/19 16:59:29 ccount Exp $";
  52. X
  53. X
  54. X
  55. X#include <stdio.h>
  56. X#include <math.h>
  57. X#include <ctype.h>
  58. X
  59. X#define SEPCHAR ';'
  60. X
  61. X#define LINELEN 82
  62. X#define MAX(a,b) ((a)>(b)?(a):(b))
  63. X#define MIN(a,b) ((a)<(b)?(a):(b))
  64. X#define FALSE 0
  65. X#define TRUE 1
  66. X
  67. X
  68. X/* variables for data, filled by readstar and readsif */
  69. Xdouble obj_lat, obj_lon, obj_mag;
  70. Xchar obj_type[] ="SS", obj_color[3], obj_label[3];
  71. Xchar obj_constell[4], obj_name[LINELEN];
  72. Xchar *obj_commnt;
  73. X
  74. X/* Special for readsif in this program */
  75. Xint line_no=0;
  76. X   
  77. Xchar *usage =
  78. X"%s: [-i infile] [-sc]\n";
  79. X
  80. Xint to_consindx();
  81. X
  82. Xmain(argc, argv)
  83. X     int argc;
  84. X     char *argv[];
  85. X{
  86. X  char *inname = "";
  87. X  FILE *infile = stdin;
  88. X  char sepchar = SEPCHAR;
  89. X  int i;
  90. X
  91. X  i = 0;
  92. X  while (i < argc)
  93. X    if (argv[i][0] != '-') i++;
  94. X  else switch (argv[i][1]) {
  95. X  case 'i':
  96. X    inname = argv[i+1];
  97. X    i += 2;
  98. X    break;
  99. X  case 's':
  100. X    if (argv[i][2]) sepchar = argv[i][2];
  101. X    i++;
  102. X    break;
  103. X  default:
  104. X    fprintf(stderr, usage, argv[0]);
  105. X    exit(4);
  106. X  }
  107. X
  108. X  if (inname[0])
  109. X    if ((infile = fopen(inname, "r")) == NULL) {
  110. X      fprintf(stderr, "%s: Can't open input file %s\n", argv[0], inname);
  111. X      exit(6);
  112. X    }
  113. X
  114. X  for (;;) {
  115. X    if (readsif(infile, sepchar)) break;
  116. X    check_data();
  117. X    write_text();
  118. X  }
  119. X
  120. X  exit(0);
  121. X}
  122. X
  123. X
  124. X/* readsif reads standard starchart interchange format files,
  125. X   extracting the same data as readstar, if possible, and loading
  126. X   the same variables */
  127. Xreadsif(file, sepchar)
  128. XFILE *file;
  129. Xchar sepchar;
  130. X{
  131. X  static char inp_line[10*LINELEN];
  132. X  int i;
  133. X  char *cp;
  134. X  char *parsed_line[9];
  135. X  int num_parsed;
  136. X  double ra_h, ra_m, ra_s, de_d, de_m, de_s;
  137. X
  138. X  /* Get line */
  139. X  if (fgets(inp_line, 10*LINELEN, file) == NULL) return TRUE;
  140. X  line_no++;
  141. X
  142. X  /* Remove newline */
  143. X  inp_line[strlen(inp_line)-1] = '\0';
  144. X
  145. X  /* split line into tokens */
  146. X  for (i = 0; i < 9; i++) parsed_line[i] = "";
  147. X
  148. X  i = 0;
  149. X  cp = inp_line;
  150. X  parsed_line[i++] = cp;
  151. X  while (*cp)
  152. X    if (*cp != sepchar) cp++;
  153. X    else if (i < 9) {
  154. X      *cp++ = '\0';
  155. X      parsed_line[i++] = cp;
  156. X    };
  157. X  num_parsed = i;
  158. X
  159. X  /* parse ra and dec */
  160. X  ra_h = ra_m = ra_s = 0.0;
  161. X  de_d = de_m = de_s = 0.0;
  162. X  sscanf(parsed_line[0], "%lf %lf %lf", &ra_h, &ra_m, &ra_s);
  163. X  sscanf(parsed_line[1], "%lf %lf %lf", &de_d, &de_m, &de_s);
  164. X
  165. X  /* set obj_ values */
  166. X  obj_lon = ra_h * 15.0 + ra_m / 4.0 + ra_s / (4.0 * 60.0);
  167. X  obj_lat = fabs(de_d) + de_m / 60.0 + de_s / 3600.0;
  168. X
  169. X  /* In order to assign the sign properly if de_d == 0,
  170. X     we must see if there is a negative sign before the first digit */
  171. X  if (de_d < 0.0) obj_lat = -obj_lat;
  172. X  else if (de_d == 0.0) {
  173. X    i = 0;
  174. X    while ((parsed_line[1][i] != '-') && (!isdigit(parsed_line[1][i]))) i++;
  175. X    if (parsed_line[1][i] == '-') obj_lat = -obj_lat;
  176. X  };
  177. X
  178. X  sscanf(parsed_line[2], "%lf", &obj_mag);
  179. X
  180. X  if (sscanf(parsed_line[3], "%2s", obj_type) == EOF) strcpy(obj_type, "SS");
  181. X  if (sscanf(parsed_line[4], "%2s", obj_color) == EOF) strcpy(obj_color, "  ");
  182. X  if (sscanf(parsed_line[5], "%2s", obj_label) == EOF) strcpy(obj_label, "  ");
  183. X  if (sscanf(parsed_line[6], "%3s", obj_constell) == EOF)
  184. X    strcpy(obj_constell, "   ");
  185. X
  186. X  if (!obj_type[1]) obj_type[1] = ' ';
  187. X  if (!obj_color[1]) obj_color[1] = ' ';
  188. X  if (!obj_label[1]) obj_label[1] = ' ';
  189. X  if (!obj_constell[1]) obj_constell[1] = ' ';
  190. X  if (!obj_constell[2]) obj_constell[2] = ' ';
  191. X
  192. X  obj_type[2] = '\0';
  193. X  obj_color[2] = '\0';
  194. X  obj_label[2] = '\0';
  195. X  obj_constell[3] = '\0';
  196. X
  197. X/* Magic for label:
  198. X   type and color should be left justified, constellation is 3 chars if valid,
  199. X   but label could be " X" or "X " with equal validity.
  200. X   If the label field is exactly two characters long including whitespace,
  201. X   and both characters are printable, use it verbatum. */
  202. X  if ((strlen(parsed_line[5]) == 2)  && isprint(parsed_line[5][0]) &&
  203. X       isprint(parsed_line[5][1])) strcpy(obj_label, parsed_line[5]);
  204. X
  205. X  /* Trim whitespace before and after name */
  206. X  while ((*parsed_line[7] == ' ') || (*parsed_line[7] == '\t'))
  207. X    parsed_line[7]++;
  208. X  i = strlen(parsed_line[7]) -1 ;
  209. X  while ((parsed_line[7][i]  == ' ') || (parsed_line[7][i] == '\t'))
  210. X    parsed_line[7][i] = '\0';
  211. X  if (!parsed_line[7][0]) strcpy(obj_name,"");
  212. X  else strcpy(obj_name,parsed_line[7]);
  213. X
  214. X  obj_commnt = parsed_line[8];
  215. X
  216. X  if (to_consindx(obj_constell) == -1) strcpy(obj_constell,"   ");
  217. X
  218. X  /* Commas should not appear in name field */
  219. X  i = 0;
  220. X  while (obj_name[i])
  221. X    if (obj_name[i++] == ',')
  222. X      fprintf(stderr, "Warning: comma in name field:\"%s\"\n", obj_name);
  223. X
  224. X  return FALSE;
  225. X}
  226. X
  227. X
  228. X/* write text discription of object */
  229. Xwrite_text()
  230. X{
  231. X  int ra_h, ra_m, ra_s;
  232. X  int de_d, de_m, de_s;
  233. X  char dsign;
  234. X
  235. X  char *starid(), *objid();
  236. X
  237. X  ra_h = obj_lon/15.0;
  238. X  ra_m = ((obj_lon/15.0) - ra_h) * 60 + (0.5 / 60);
  239. X  ra_s = ((((obj_lon/15.0) - ra_h) * 60) - ra_m) * 60 + 0.5;
  240. X
  241. X  if (ra_s >= 60) {ra_s -= 60; ra_m++;};
  242. X  if (ra_m >= 60) {ra_m -= 60; ra_h++;};
  243. X
  244. X
  245. X  if (obj_lat < 0.0) {
  246. X    obj_lat = -obj_lat;
  247. X    dsign = '-';
  248. X  } else dsign = '+';
  249. X
  250. X  de_d = obj_lat;
  251. X  de_m = (obj_lat - de_d) * 60 + (0.5 / 60);
  252. X  de_s = (((obj_lat - de_d) * 60) - de_m) * 60 + 0.5;
  253. X
  254. X  if (de_s >= 60) {de_s -= 60; de_m++;};
  255. X  if (de_m >= 60) {de_m -= 60; de_d++;};
  256. X
  257. X
  258. X  if ((obj_type[0] == 'S') || (obj_type[0] == 'I'))
  259. X    printf("%70s ", starid());
  260. X        /* starid supplies label, constellation, subtype, and name */
  261. X  else
  262. X    printf("%70s ", objid());
  263. X        /* objid supplies constellation, type, size, and name */
  264. X
  265. X  printf("%2dh%2dm%2ds %c%02dd%2dm%2ds %5.2f %s",
  266. X     ra_h, ra_m, ra_s, dsign, de_d, de_m, de_s, obj_mag, obj_color);
  267. X
  268. X
  269. X  if (obj_commnt[0])
  270. X    printf(" %s", obj_commnt);
  271. X
  272. X  printf("\n");
  273. X}
  274. X
  275. Xstruct {
  276. X  char *abbrev;
  277. X  char *name;
  278. X  char *genetive;
  279. X} constellations[] = {
  280. X  {"AND",    "Andromeda",    "Andromedae"},
  281. X  {"ANT",    "Antlia",    "Antliae"},
  282. X  {"APS",    "Apus",        "Apodis"},
  283. X  {"AQL",    "Aquila",    "Aquilae"},
  284. X  {"AQR",    "Aquarius",    "Aquarii"},
  285. X  {"ARA",    "Ara",        "Arae"},
  286. X  {"ARI",    "Aries",    "Arietis"},
  287. X  {"AUR",    "Auriga",    "Aurigae"},
  288. X  {"BOO",    "Bootes",    "Bootis"},
  289. X  {"CAE",    "Caelum",    "Caeli"},
  290. X  {"CAM",    "Camelopardalis",    "Camelopardalis"},
  291. X  {"CAP",    "Capricornus",    "Capricorni"},
  292. X  {"CAR",    "Carina",    "Carinae"},
  293. X  {"CAS",    "Cassiopeia",    "Cassiopeiae"},
  294. X  {"CEN",    "Centaurus",    "Centauri"},
  295. X  {"CEP",    "Cepheus",    "Cephei"},
  296. X  {"CET",    "Cetus",    "Ceti"},
  297. X  {"CHA",    "Chamaeleon",    "Chamaeleonis"},
  298. X  {"CIR",    "Circinus",    "Circini"},
  299. X  {"CMA",    "Canis Major",    "Canis Majoris"},
  300. X  {"CMI",    "Canis Minor",    "Canis Minoris"},
  301. X  {"CNC",    "Cancer",    "Cancri"},
  302. X  {"COL",    "Columba",    "Columbae"},
  303. X  {"COM",    "Coma Berenices",    "Comae Berenices"},
  304. X  {"CRA",    "Corona Australis",    "Coronae Australis"},
  305. X  {"CRB",    "Corona Borealis",    "Corona Borealis"},
  306. X  {"CRT",    "Crater",    "Crateris"},
  307. X  {"CRU",    "Crux",    "Cruxis"},
  308. X  {"CRV",    "Corvus",    "Corvi"},
  309. X  {"CVN",    "Canes Venatici",    "Canum Venaticorum"},
  310. X  {"CYG",    "Cygnus",    "Cygni"},
  311. X  {"DEL",    "Delphinus",    "Delphini"},
  312. X  {"DOR",    "Dorado",    "Doradus"},
  313. X  {"DRA",    "Draco",    "Draconis"},
  314. X  {"EQU",    "Equuleus",    "Equulei"},
  315. X  {"ERI",    "Eridanus",    "Eridani"},
  316. X  {"FOR",    "Fornax",    "Fornacis"},
  317. X  {"GEM",    "Gemini",    "Geminorum"},
  318. X  {"GRU",    "Grus",    "Gruis"},
  319. X  {"HER",    "Hercules",    "Herculis"},
  320. X  {"HOR",    "Horologium",    "Horologii"},
  321. X  {"HYA",    "Hydra",    "Hydrae"},
  322. X  {"HYI",    "Hydrus",    "Hydri"},
  323. X  {"IND",    "Indus",    "Indi"},
  324. X  {"LAC",    "Lacerta",    "Lacertae"},
  325. X  {"LEO",    "Leo",    "Leonis"},
  326. X  {"LEP",    "Lepus",    "Leporis"},
  327. X  {"LIB",    "Libra",    "Librae"},
  328. X  {"LMI",    "Leo Minor",    "Leonis Minoris"},
  329. X  {"LUP",    "Lupus",    "Lupi"},
  330. X  {"LYN",    "Lynx",        "Lyncis"},
  331. X  {"LYR",    "Lyra",    "Lyrae"},
  332. X  {"MEN",    "Mensa",    "Mensae"},
  333. X  {"MIC",    "Microscopium",    "Microscopii"},
  334. X  {"MON",    "Monoceros",    "Monocerotis"},
  335. X  {"MUS",    "Musca",    "Muscae"},
  336. X  {"NOR",    "Norma",    "Normae"},
  337. X  {"OCT",    "Octans",    "Octantis"},
  338. X  {"OPH",    "Ophiuchus",    "Ophiuchi"},
  339. X  {"ORI",    "Orion",    "Orionis"},
  340. X  {"PAV",    "Pavo",    "Pavonis"},
  341. X  {"PEG",    "Pegasus",    "Pegasi"},
  342. X  {"PER",    "Perseus",    "Persei"},
  343. X  {"PHE",    "Phoenix",    "Phoenicis"},
  344. X  {"PIC",    "Pictor",    "Pictoris"},
  345. X  {"PSA",    "Piscis Astrinus",    "Piscis Austrini"},
  346. X  {"PSC",    "Pisces",    "Piscium"},
  347. X  {"PUP",    "Puppis",    "Puppis"},
  348. X  {"PYX",    "Pyxis",    "Pyxidis"},
  349. X  {"RET",    "Reticulum",    "Reticuli"},
  350. X  {"SCL",    "Sculptor",    "Sculptoris"},
  351. X  {"SCO",    "Scorpius",    "Scorpii"},
  352. X  {"SCT",    "Scutum",    "Scuti"},
  353. X  {"SER",    "Serpens",    "Serpentis"},
  354. X  {"SEX",    "Sextans",    "Sextantis"},
  355. X  {"SGE",    "Sagitta",    "Sagittae"},
  356. X  {"SGR",    "Sagittarius",    "Sagittarii"},
  357. X  {"TAU",    "Taurus",    "Tauri"},
  358. X  {"TEL",    "Telescopium",    "Telescopii"},
  359. X  {"TRA",    "Triangulum Astrale",    "Trianguli Astralis"},
  360. X  {"TRI",    "Triangulum",    "Trianguli"},
  361. X  {"TUC",    "Tucana",    "Tucanae"},
  362. X  {"UMA",    "Ursa Major",    "Ursae Majoris"},
  363. X  {"UMI",    "Ursa Minor",    "Ursae Minoris"},
  364. X  {"VEL",    "Vela",    "Velorum"},
  365. X  {"VIR",    "Virgo",    "Virginis"},
  366. X  {"VOL",    "Volans",    "Volantis"},
  367. X  {"VUL",    "Vulpecula",    "Vulpeculae"},
  368. X  {"   ",    "",    ""},
  369. X  {"",    "",    ""}
  370. X};
  371. X
  372. Xint to_consindx(cons)
  373. Xchar *cons;
  374. X{
  375. X  int i;
  376. X
  377. X  if (!cons[0]) return -1;
  378. X
  379. X  i = -1;
  380. X  while (constellations[++i].abbrev[0])
  381. X    if (!strcmp(cons, constellations[i].abbrev)) break;
  382. X
  383. X  return (constellations[i].abbrev[0] ? i : 0);
  384. X}
  385. X
  386. X
  387. Xchar ret_star[100];
  388. X
  389. X/* return pointer to ret_star, which contains the label and constellation,
  390. X   name, and subtype */
  391. Xchar *starid()
  392. X{
  393. X  char *grk_str;
  394. X  char *to_greek();
  395. X
  396. X  grk_str = to_greek(obj_label);
  397. X
  398. X  if (grk_str[0])
  399. X    if ((obj_type[1] != 'S') && (obj_type[1] != ' '))
  400. X      sprintf(ret_star, "%8s %-18s (%c) %-35.35s",
  401. X          grk_str,
  402. X          constellations[to_consindx(obj_constell)].genetive,
  403. X          obj_type[1],
  404. X          obj_name);
  405. X    else
  406. X      sprintf(ret_star, "%8s %-18s     %-35.-35s", grk_str,
  407. X          constellations[to_consindx(obj_constell)].genetive,
  408. X          obj_name);
  409. X  else
  410. X    if ((obj_type[1] != 'S') && (obj_type[1] != ' '))
  411. X      sprintf(ret_star, "         %-18s (%c) %35.35s", 
  412. X          constellations[to_consindx(obj_constell)].name,
  413. X          obj_type[1],
  414. X          obj_name);
  415. X    else
  416. X      sprintf(ret_star, "         %-18s     %35.35s",
  417. X          constellations[to_consindx(obj_constell)].name,
  418. X          obj_name);
  419. X  if (obj_type[0] == 'I') strcat(ret_star, "I ");
  420. X  else strcat(ret_star, "  ");
  421. X
  422. X  return ret_star;
  423. X}
  424. X
  425. Xstruct {
  426. X  char roman;
  427. X  char *greek_name;
  428. X} grk_tr_tab[] = {
  429. X  {'a',    "Alpha"},
  430. X  {'b', "Beta"},
  431. X  {'g', "Gamma"},
  432. X  {'d', "Delta"},
  433. X  {'e', "Epsilon"},
  434. X  {'z', "Zeta"},
  435. X  {'h', "Eta"},
  436. X  {'q', "Theta"},
  437. X  {'i', "Iota"},
  438. X  {'k', "Kappa"},
  439. X  {'l', "Lambda"},
  440. X  {'m', "Mu"},
  441. X  {'n', "Nu"},
  442. X  {'x', "Xi"},
  443. X  {'o', "Omicron"},
  444. X  {'p', "Pi"},
  445. X  {'r', "Rho"},
  446. X  {'s', "Sigma"},
  447. X  {'t', "Tau"},
  448. X  {'u', "Upsilon"},
  449. X  {'f', "Phi"},
  450. X  {'j', "Phi"},
  451. X  {'c', "Chi"},
  452. X  {'y', "Psi"},
  453. X  {'w', "Omega"},
  454. X  {' ', ""}
  455. X};
  456. X
  457. Xchar grk_ret[12];
  458. X
  459. Xchar *to_greek(label)
  460. Xchar *label;
  461. X{
  462. X  int i;
  463. X
  464. X  if (isgreek(label[0]) && (isdigit(label[1]) || (label[1] == ' '))) {
  465. X    /* Greek if first character is greek encoded,
  466. X       and the second is space or a digit */
  467. X    i = 0;
  468. X    while ((grk_tr_tab[i].greek_name[0])
  469. X       && (grk_tr_tab[i].roman != label[0])) i++;
  470. X    if (grk_tr_tab[i].greek_name[0])
  471. X      sprintf(grk_ret, "%s%c", grk_tr_tab[i].greek_name, label[1]);
  472. X    else { /* Error */
  473. X      fprintf(stderr, "Report bug in greek coding\n");
  474. X      exit(1);
  475. X    }
  476. X  } else {            /* Not greek */
  477. X    if ((label[0] != ' ') || (label[1] != ' '))
  478. X      sprintf(grk_ret, "%s", label);
  479. X    else
  480. X      grk_ret[0] = '\0';
  481. X  }
  482. X
  483. X  return grk_ret;
  484. X}
  485. X
  486. X
  487. X
  488. Xisgreek(c)
  489. Xchar c;
  490. X{
  491. X  char *cp;
  492. X
  493. X  cp = "abgdezhqiklmnxoprstufcywj";
  494. X
  495. X  while (*cp && (*cp != c)) cp++;
  496. X  return (*cp != '\0'); /* True if letter was in greek string */
  497. X}
  498. X
  499. X
  500. X
  501. X
  502. X
  503. X
  504. Xchar ret_obj[100];
  505. X
  506. X/* return pointer to ret_obj, which contains the constellation,
  507. X   type, size and name */
  508. Xchar *objid()
  509. X{
  510. X  long int size_obj();
  511. X  long int sze;
  512. X  char *obj_ty();
  513. X  char sze_str[10];
  514. X
  515. X  sze = size_obj(obj_label);
  516. X  if (sze > 4800)
  517. X    sprintf(sze_str, "%.2fd", sze/3600.0);
  518. X  else if (sze > 120)
  519. X    sprintf(sze_str, "%.2fm", sze/60.0);
  520. X  else
  521. X    sprintf(sze_str, "%ds", sze);
  522. X
  523. X  if (sze != -1)
  524. X    sprintf(ret_obj, "%-18s %-19.19s %-24s %6s",
  525. X        constellations[to_consindx(obj_constell)].name,
  526. X        obj_name,
  527. X        obj_ty(obj_type),
  528. X        sze_str);
  529. X  else
  530. X    sprintf(ret_obj, "%-18s %-19.19s %-24s       ",
  531. X        constellations[to_consindx(obj_constell)].name,
  532. X        obj_name,
  533. X        obj_ty(obj_type));
  534. X
  535. X  return ret_obj;
  536. X}
  537. X
  538. X
  539. X
  540. X/* Translate two digit encoded size string */
  541. X/* Maximum parsed: 89000 secs of arc = 24.666 degrees */
  542. X/* Warning, should use 32 bit integers to allow this value */
  543. Xlong size_obj(size_str)
  544. X     char *size_str;
  545. X{
  546. X    char chr1, chr2;
  547. X
  548. X    chr1 = islower(size_str[0]) ? toupper(size_str[0]) : size_str[0];
  549. X    chr2 = islower(size_str[1]) ? toupper(size_str[1]) : size_str[1];
  550. X
  551. X    if ((chr1 == ' ') && (chr2 == ' ')) return -1;
  552. X    if (chr1 == ' ') return chr2 - '0';
  553. X    if (isdigit(chr1)) return ((chr1-'0')*10L + (chr2-'0'));
  554. X    if (chr1 < 'J') return ((chr1-'A'+1)*100L + (chr2-'0')*10L);
  555. X    if (chr1 < 'S') return ((chr1-'I')*1000L + (chr2-'0')*100L);
  556. X    if (chr1 <= 'Z') return ((chr1-'R')*10000L + (chr2-'0')*1000L);
  557. X    return -1;
  558. X}
  559. X
  560. X/*
  561. XExamples:
  562. X
  563. X"  "        -1
  564. X" 6"        6
  565. X"09"        9
  566. X"73"        73
  567. X"A0"        100
  568. X"C3"        330
  569. X"D5"        450
  570. X"I6"        960
  571. X"J2"        1200
  572. X"R3"        9300
  573. X"S6"        16000
  574. X"Z0"        80000
  575. X"Z9"        89000
  576. X*/
  577. X
  578. X
  579. X
  580. Xstruct subtytab {
  581. X  char ch;
  582. X  char *str;
  583. X};
  584. X
  585. Xstruct tytab {
  586. X  char ch;
  587. X  char *str;
  588. X  struct subtytab *subtab;
  589. X};
  590. X
  591. Xstruct subtytab st_subty[] = {
  592. X  {'S',    "Single"},
  593. X  {'D',    "Double"},
  594. X  {'V',    "Variable"},
  595. X  {'?',    ""}
  596. X};
  597. X
  598. Xstruct subtytab pl_subty[] = {
  599. X  {'M',    "Mercury"},
  600. X  {'V',    "Venus"},
  601. X  {'m',    "Mars"},
  602. X  {'J',    "Jupiter"},
  603. X  {'s',    "Saturn"},
  604. X  {'U',    "Uranus"},
  605. X  {'N',    "Neptune"},
  606. X  {'P',    "Pluto"},
  607. X  {'A',    "Asteroid"},
  608. X  {'C',    "Comet"},
  609. X  {'S',    "Sun"},
  610. X  {'L',    "Moon"},
  611. X  {'?',    ""}
  612. X};
  613. X
  614. Xstruct subtytab cl_subty[] = {
  615. X  {'O',    "Open Cluster"},
  616. X  {'G',    "Globular"},
  617. X  {'?',    ""}
  618. X};
  619. X
  620. Xstruct subtytab nb_subty[] = {
  621. X  {'D',    "Diffuse Nebula"},
  622. X  {'P',    "Planetary Nebula"},
  623. X  {'?',    ""}
  624. X};
  625. X
  626. Xstruct subtytab gx_subty[] = {
  627. X  {'a',    "Spiral Galaxy Sa"},
  628. X  {'b',    "Spiral Galaxy Sb"},
  629. X  {'c',    "Spiral Galaxy Sc"},
  630. X  {'d',    "Spiral Galaxy Sd"},
  631. X  {'p',    "Spiral Galaxy Sp"},
  632. X  {'Z',    "Spiral Galaxy S0"},
  633. X  {'s',    "Spiral Galaxy"},
  634. X  {'A',    "Barred Spiral Galaxy SBa"},
  635. X  {'B',    "Barred Spiral Galaxy SBb"},
  636. X  {'C',    "Barred Spiral Galaxy SBc"},
  637. X  {'D',    "Barred Spiral Galaxy SBd"},
  638. X  {'P',    "Barred Spiral Galaxy SBp"},
  639. X  {'S',    "Barred Spiral Galaxy"},
  640. X  {'0',    "Elliptical Galaxy E0"},
  641. X  {'1',    "Elliptical Galaxy E1"},
  642. X  {'2',    "Elliptical Galaxy E2"},
  643. X  {'3',    "Elliptical Galaxy E3"},
  644. X  {'4',    "Elliptical Galaxy E4"},
  645. X  {'5',    "Elliptical Galaxy E5"},
  646. X  {'6',    "Elliptical Galaxy E6"},
  647. X  {'7',    "Elliptical Galaxy E7"},
  648. X  {'E',    "Elliptical Galaxy"},
  649. X  {'I',    "Irregular Galaxy"},
  650. X  {'Q',    "Quasar"},
  651. X  {'U',    "Unknown Galaxy"},
  652. X  {'!',    "Pecular Galaxy"},
  653. X  {'?',    ""}
  654. X};
  655. X
  656. Xstruct subtytab ve_subty[] = {
  657. X  {'M',    "Vector Move to"},
  658. X  {'S',    "Solid Line"},
  659. X  {'D',    "Dotted Line"},
  660. X  {'H',    "Dashed Line"},
  661. X  {'?',    ""}
  662. X};
  663. X
  664. Xstruct subtytab ar_subty[] = {
  665. X  {'M',    "Area move to"},
  666. X  {'A',    "Area border"},
  667. X  {'F',    "Area fill"},
  668. X  {'?',    ""}
  669. X};
  670. X
  671. X
  672. Xstruct subtytab nul_subty[] = {
  673. X  {'?',    ""}
  674. X};
  675. X
  676. X
  677. X
  678. Xstruct tytab tytop[] = {
  679. X  {'S',    "? Star", st_subty},
  680. X  {'P',    "? Planet", pl_subty},
  681. X  {'C',    "? Cluster", cl_subty},
  682. X  {'N',    "? Nebula", nb_subty},
  683. X  {'G',    "? Galaxy", gx_subty},
  684. X  {'V',    "ERROR Vector", ve_subty},
  685. X  {'O',    "Other", nul_subty},
  686. X  {'U',    "Unknown", nul_subty},
  687. X  {'I',    "Invisible", nul_subty},
  688. X  {'#',    "Comment", nul_subty},
  689. X  {'A',    "ERROR Area", ar_subty},
  690. X  {'U',    "Unknown", nul_subty},
  691. X  {'?',    "", nul_subty}
  692. X};
  693. X
  694. X
  695. X
  696. Xchar ty_ret[100];
  697. Xchar *obj_ty(typ)
  698. Xchar *typ;
  699. X{
  700. X  int i, j;
  701. X
  702. X
  703. X  i = 0;
  704. X  while ((tytop[i].str[0]) && (tytop[i].ch != typ[0])) i++;
  705. X  if (tytop[i].str[0]) {
  706. X    j = 0;
  707. X    while ((tytop[i].subtab[j].str[0])
  708. X        && (tytop[i].subtab[j].ch != typ[1])) j++;
  709. X    if (tytop[i].subtab[j].str[0])
  710. X      sprintf(ty_ret, "%s", tytop[i].subtab[j].str);
  711. X    else
  712. X      sprintf(ty_ret, "%s", tytop[i].str);
  713. X  } else
  714. X      sprintf(ty_ret, "%s", "Unknown Type");
  715. X
  716. X  return ty_ret;
  717. X}
  718. X
  719. X
  720. Xcheck_data()
  721. X{
  722. X  int i, j;
  723. X
  724. X  if ((obj_lon < 0.0) || (obj_lon > 360.0))
  725. X    fprintf(stderr, "Warning: RA out of range: line %d: %f\n",
  726. X        line_no, obj_lon);
  727. X
  728. X  if ((obj_lat < -90.0) || (obj_lat > 90.0))
  729. X    fprintf(stderr, "Warning: declination out of range: line %d: %f\n",
  730. X        line_no, obj_lat);
  731. X
  732. X  if ((obj_mag < -30.0) || (obj_mag > 30.0))
  733. X    fprintf(stderr, "Warning: abnormal magnitude: line %d: %f\n",
  734. X        line_no, obj_mag);
  735. X
  736. X  i = 0;
  737. X  while ((tytop[i].str[0]) && (tytop[i].ch != obj_type[0])) i++;
  738. X  if (tytop[i].str[0]) {
  739. X    j = 0;
  740. X    while ((tytop[i].subtab[j].str[0])
  741. X        && (tytop[i].subtab[j].ch != obj_type[1])) j++;
  742. X    if ((!tytop[i].subtab[j].str[0])
  743. X    && (obj_type[1] != ' '))
  744. X      fprintf(stderr,
  745. X          "Warning: unknown subtype: line %d: type %c subtype %c\n",
  746. X        line_no, obj_type[0], obj_type[1]);
  747. X  } else
  748. X    fprintf(stderr, "Warning: unknown type: line %d: %c\n",
  749. X        line_no, obj_type[0]);
  750. X
  751. X  if (obj_type[0] == 'S') {
  752. X    if ((!isgreek(obj_label[0]))       /* letter is not greek, */
  753. X    && islower(obj_label[0])       /* but is lowercase */
  754. X    && (isdigit(obj_label[1]) || (obj_label[1] == ' ')))
  755. X                       /* and is followed by space or digit */
  756. X      fprintf(stderr, "Warning: not greek encoding: line %d: %s\n",
  757. X          line_no, obj_label);
  758. X  }
  759. X
  760. X  if (to_consindx(obj_constell) == -1)
  761. X    fprintf(stderr, "Warning: unknown constellation: line %d: %s\n",
  762. X        line_no, obj_constell);
  763. X    
  764. X
  765. X}
  766. END_OF_FILE
  767. if test 18386 -ne `wc -c <'dataconv/sif_to_text.c'`; then
  768.     echo shar: \"'dataconv/sif_to_text.c'\" unpacked with wrong size!
  769. fi
  770. # end of 'dataconv/sif_to_text.c'
  771. fi
  772. if test -f 'observe/main.c' -a "${1}" != "-c" ; then 
  773.   echo shar: Will not clobber existing file \"'observe/main.c'\"
  774. else
  775. echo shar: Extracting \"'observe/main.c'\" \(21792 characters\)
  776. sed "s/^X//" >'observe/main.c' <<'END_OF_FILE'
  777. X/*
  778. X * main.c
  779. X * main() for combined planet, precession, ephemeris, asteroid, comet program
  780. X *
  781. X * Copyright (c) 1990 by Craig Counterman. All rights reserved.
  782. X *
  783. X * This software may be redistributed freely, not sold.
  784. X * This copyright notice and disclaimer of warranty must remain
  785. X *    unchanged. 
  786. X *
  787. X * No representation is made about the suitability of this
  788. X * software for any purpose.  It is provided "as is" without express or
  789. X * implied warranty, to the extent permitted by applicable law.
  790. X *
  791. X * DISCLAIMER OF WARRANTY
  792. X * ----------------------
  793. X * The author  disclaims all warranties  with regard to  this software to
  794. X * the   extent  permitted  by applicable   law,  including all   implied
  795. X * warranties  of merchantability  and  fitness. In  no event shall   the
  796. X * author be liable for any special, indirect or consequential damages or
  797. X * any  damages whatsoever resulting from  loss of use, data or  profits,
  798. X * whether in an action of contract, negligence or other tortious action,
  799. X * arising  out of  or in connection with the  use or performance of this
  800. X * software.
  801. X *
  802. X * email: ccount@athena.mit.edu
  803. X */
  804. X
  805. X#ifndef  lint
  806. Xstatic char rcsid[] =
  807. X  "$Header: main.c,v 1.13 90/02/23 18:44:16 ccount Exp $";
  808. X#endif
  809. X
  810. X
  811. X#include <stdio.h>
  812. X#include <math.h>
  813. X#ifndef SYSV
  814. X#include <strings.h>
  815. X#else
  816. X#include <string.h>
  817. X#endif
  818. X#include <ctype.h>
  819. X
  820. X#include <time.h>
  821. X#ifndef ATARI_ST
  822. X#include <sys/types.h>
  823. X#include <sys/timeb.h>
  824. X#else
  825. X#include <types.h>
  826. X#include <time.h>
  827. X#endif
  828. X
  829. X#include "observe.h"
  830. X#include "date.h"
  831. X
  832. X
  833. X#ifndef FALSE
  834. X#define FALSE 0
  835. X#endif
  836. X#ifndef TRUE
  837. X#define TRUE 1
  838. X#endif
  839. X#ifndef MAXPATHLEN
  840. X#define MAXPATHLEN 1025
  841. X#endif
  842. X
  843. X
  844. Xvoid parse_command();
  845. X
  846. X
  847. X
  848. Xchar *progname;
  849. X
  850. X/* Time */
  851. Xdouble start_date;        /* JD of start */
  852. Xint start_month, start_year;
  853. Xdouble start_day;
  854. Xdouble end_date;        /* JD of end */
  855. Xint end_month, end_year;
  856. Xdouble end_day;
  857. Xdouble interval_days = 1.0;
  858. X
  859. X/* Place */
  860. Xdouble obs_lon = -71.0;
  861. Xdouble obs_lat = 42.0;
  862. Xdouble obs_zone = -4.0;
  863. Xdouble obs_height = 50.0;    /* Meters */
  864. X
  865. X/* files */
  866. Xchar *outfile_root = "planet";
  867. XFILE *o_sif, *o_star, *o_eph, *o_obs, *o_sat, *o_sat_PS, *o_altaz;
  868. Xint do_sif = TRUE, do_star = TRUE, do_eph = TRUE, do_obs = TRUE,
  869. X    do_altaz = TRUE;
  870. X
  871. X/* input file Formats */
  872. X
  873. Xint file_input = FALSE;
  874. Xfformat_t tr_format();
  875. Xchar *infile_name = "";
  876. XFILE *infile;
  877. Xfformat_t in_type;
  878. X
  879. X
  880. X
  881. X/* objects */
  882. Xint planet_list[] = {
  883. X  FALSE,            /* Mercury */
  884. X  FALSE,            /* Venus */
  885. X  FALSE,            /* Mars */
  886. X  FALSE,            /* Jupiter */
  887. X  FALSE,            /* Saturn */
  888. X  FALSE,            /* Uranus */
  889. X  FALSE                /* Neptune */
  890. X};
  891. X
  892. Xchar *obj_name = "";
  893. X
  894. X#ifndef MAXOBJECTS
  895. X#define MAXOBJECTS 1500
  896. X#endif
  897. X
  898. X
  899. Xplanet_data_t planets[7];
  900. X#ifndef ATARI_ST
  901. Xwanderer_data_t bodies[MAXOBJECTS];
  902. X#else
  903. Xwanderer_data_t *bodies;
  904. X#endif
  905. X
  906. Xint nbodies;
  907. Xsun_data_t sun_data;
  908. Xmoon_data_t moon_data;
  909. X
  910. X#ifndef ATARI_ST
  911. Xobj_data_t objects[MAXOBJECTS];
  912. X#else
  913. Xobj_data_t *objects;
  914. X#endif
  915. Xint nobjects;
  916. X
  917. X
  918. X/* (7 planets + objects) each  rise rise20 rise30 transit set30 set20 set
  919. X   + sunrise sunset moonrise moonset and twilights */
  920. X#define EVENTSSIZE ((7+MAXOBJECTS)*MAXEVENTS+6)
  921. Xobserve_t events[EVENTSSIZE];
  922. Xint nevents;
  923. X
  924. Xint index_events[EVENTSSIZE];
  925. Xdouble event_times[EVENTSSIZE];
  926. X
  927. X/* Controls */
  928. Xint satellites = FALSE;
  929. Xint invert_sats = FALSE;
  930. X
  931. Xdouble morntwil(), evetwil(), sunrise(), sunset(), moonrise(), moonset(),
  932. X  objrise(), objset(), objrise20(), objset20(), objrise30(), objset30();
  933. X
  934. Xmain(argc, argv)
  935. X     int argc;
  936. X     char **argv;
  937. X{
  938. X  int i;
  939. X  char filename[MAXPATHLEN];
  940. X  double jd;
  941. X  char datestr[15];
  942. X  int one_day;
  943. X
  944. X#ifdef ATARI_ST
  945. X  if ((bodies = (wanderer_data_t *)
  946. X       lmalloc((long)MAXOBJECTS * (long)sizeof(wanderer_data_t))
  947. X       ) == (wanderer_data_t *)0)
  948. X    {
  949. X      perror("malloc");
  950. X      exit(1);
  951. X    }
  952. X  if ((objects = (obj_data_t *)
  953. X       lmalloc((long)MAXOBJECTS * (long)sizeof(obj_data_t))
  954. X       ) == (wanderer_data_t *)0)
  955. X    {
  956. X      perror("malloc");
  957. X      exit(1);
  958. X    }
  959. X#endif
  960. X
  961. X
  962. X  get_time();
  963. X  obs_zone = now_zone();
  964. X  jd_to_cal(start_date, &start_day, &start_month, &start_year);
  965. X  end_date = start_date;
  966. X  end_day = start_day;
  967. X  end_month = start_month;
  968. X  end_year = start_year;
  969. X
  970. X  parse_command(argc, argv);
  971. X
  972. X
  973. X  one_day = (start_date == end_date);
  974. X
  975. X  jd_to_str(start_date, datestr);
  976. X
  977. X  if (file_input) {
  978. X    if ((infile = fopen(infile_name, "r")) == NULL) {
  979. X      fprintf(stderr, "%s: could not open file %s for reading\n",
  980. X          progname, infile_name);
  981. X      exit(1);
  982. X    };
  983. X
  984. X    /* input data from infile */
  985. X    switch (in_type) {
  986. X    case emp:
  987. X    case empb:
  988. X    case aa:
  989. X    case st:
  990. X    case iau:
  991. X      read_table(infile, in_type);
  992. X      nbodies = 1;
  993. X      bodies[0].name = obj_name;
  994. X      bodies[0].orbit_type = tabulated;
  995. X      break;
  996. X    case ell_e:
  997. X      read_elliptical(infile, bodies, &nbodies, MAXOBJECTS);
  998. X      break;
  999. X    case par_e:
  1000. X      read_parabolic(infile, bodies, &nbodies, MAXOBJECTS);
  1001. X      break;
  1002. X    case obj:
  1003. X      read_objects(infile, objects, &nobjects, MAXOBJECTS);
  1004. X      break;
  1005. X    default:
  1006. X      break;
  1007. X    };
  1008. X  };
  1009. X
  1010. X  /* open output files */
  1011. X  strncpy(filename, outfile_root, MAXPATHLEN-5);
  1012. X#ifndef ATARI_ST
  1013. X  strcat(filename, ".star");
  1014. X#else
  1015. X  strcat(filename, ".str");
  1016. X#endif
  1017. X  if (do_star)
  1018. X    if ((o_star = fopen(filename, "w")) == NULL) {
  1019. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1020. X          progname, filename);
  1021. X      exit(1);
  1022. X    };
  1023. X  strncpy(filename, outfile_root, MAXPATHLEN-5);
  1024. X  strcat(filename, ".sif");
  1025. X  if (do_sif)
  1026. X    if ((o_sif = fopen(filename, "w")) == NULL) {
  1027. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1028. X          progname, filename);
  1029. X      exit(1);
  1030. X    };
  1031. X  strncpy(filename, outfile_root, MAXPATHLEN-5);
  1032. X  strcat(filename, ".eph");
  1033. X  if (do_eph)
  1034. X    if ((o_eph = fopen(filename, "w")) == NULL) {
  1035. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1036. X          progname, filename);
  1037. X      exit(1);
  1038. X    };
  1039. X  strncpy(filename, outfile_root, MAXPATHLEN-5);
  1040. X  strcat(filename, ".obs");
  1041. X  if (do_obs)
  1042. X    if ((o_obs = fopen(filename, "w")) == NULL) {
  1043. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1044. X          progname, filename);
  1045. X      exit(1);
  1046. X    };
  1047. X  strncpy(filename, outfile_root, MAXPATHLEN-5);
  1048. X#ifndef ATARI_ST
  1049. X  strcat(filename, ".altaz");
  1050. X#else
  1051. X  strcat(filename, ".alt");
  1052. X#endif
  1053. X  if (do_altaz)
  1054. X    if ((o_altaz = fopen(filename, "w")) == NULL) {
  1055. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1056. X          progname, filename);
  1057. X      exit(1);
  1058. X    };
  1059. X  if (satellites) {
  1060. X    strncpy(filename, outfile_root, MAXPATHLEN-5);
  1061. X    strcat(filename, ".sat");
  1062. X    if ((o_sat = fopen(filename, "w")) == NULL) {
  1063. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1064. X          progname, filename);
  1065. X      exit(1);
  1066. X    };
  1067. X    strncpy(filename, outfile_root, MAXPATHLEN-7);
  1068. X#ifdef MSDOS
  1069. X    strcat(filename, ".sPS");
  1070. X#else
  1071. X#ifdef ATARI_ST
  1072. X    strcat(filename, ".sps");
  1073. X#else
  1074. X    strcat(filename, ".sat_PS");
  1075. X#endif /* Atari */
  1076. X#endif /* msdos */
  1077. X
  1078. X    if ((o_sat_PS = fopen(filename, "w")) == NULL) {
  1079. X      fprintf(stderr, "%s: could not open file %s for writing\n",
  1080. X          progname, filename);
  1081. X      exit(1);
  1082. X    };
  1083. X  };
  1084. X
  1085. X
  1086. X  /* for each time */
  1087. X  for (jd = start_date; jd <= end_date; jd += interval_days) {
  1088. X    /* Calculate sun position, moon position */
  1089. X    sun_pos(jd, &sun_data);
  1090. X    moon_pos(jd, sun_data, &moon_data);
  1091. X
  1092. X    /* Calculate special events in the day */
  1093. X    sun_data.rise_hour =
  1094. X      events[0].hour = sunrise(jd, obs_lon, obs_lat, obs_zone, obs_height,
  1095. X                   sun_data);
  1096. X    events[0].object = "sun";
  1097. X    events[0].event = rise;
  1098. X    events[0].special = rise_special;
  1099. X    sun_data.transit_hour =
  1100. X      suntransit(jd, obs_lon, obs_lat, obs_zone, obs_height, sun_data);
  1101. X    sun_data.set_hour =
  1102. X      events[1].hour = sunset(jd, obs_lon, obs_lat, obs_zone, obs_height,
  1103. X                  sun_data);
  1104. X    events[1].object = "sun";
  1105. X    events[1].event = set;
  1106. X    events[1].special = set_special;
  1107. X    events[2].hour = morntwil(jd, obs_lon, obs_lat, obs_zone, obs_height,
  1108. X                  sun_data);
  1109. X    events[2].object = "morning twilight";
  1110. X    events[2].event = special;
  1111. X    events[2].special = morning_twilight;
  1112. X    events[3].hour = evetwil(jd, obs_lon, obs_lat, obs_zone, obs_height,
  1113. X                 sun_data);
  1114. X    events[3].object = "evening twilight";
  1115. X    events[3].event = special;
  1116. X    events[3].special = evening_twilight;
  1117. X
  1118. X    moon_data.rise_hour =
  1119. X      events[4].hour = moonrise(jd, obs_lon, obs_lat, obs_zone, obs_height,
  1120. X                moon_data);
  1121. X    events[4].object = "moon";
  1122. X    events[4].event = rise;
  1123. X    events[4].special = rise_special;
  1124. X    moon_data.transit_hour =
  1125. X      moontransit(jd, obs_lon, obs_lat, obs_zone, obs_height, moon_data);
  1126. X    moon_data.set_hour =
  1127. X      events[5].hour = moonset(jd, obs_lon, obs_lat, obs_zone, obs_height,
  1128. X                   moon_data);
  1129. X    events[5].object = "moon";
  1130. X    events[5].event = set;
  1131. X    events[5].special = set_special;
  1132. X    nevents = 6;
  1133. X
  1134. X    /* for each planet, calculate position and events */
  1135. X    for (i = 0; i < 7; i++)
  1136. X      if (planet_list[i]) {
  1137. X    planet_pos(jd, sun_data, i, &planets[i]);
  1138. X    calc_events(planets[i].eventlist,
  1139. X            &planets[i].rise_hour, &planets[i].transit_hour,
  1140. X            &planets[i].set_hour,
  1141. X            jd, obs_lon, obs_lat, obs_zone, obs_height,
  1142. X            planets[i].name, planets[i].alpha, planets[i].delta);
  1143. X    add_events(events, &nevents, planets[i].eventlist);
  1144. X      } else {
  1145. X    planets[i].name = "";
  1146. X      };
  1147. X
  1148. X    /* for each object, calculate position and events */
  1149. X    for (i = 0; i < nobjects; i++) {
  1150. X      obj_pos(jd, &objects[i]);    /* calculates alpha and delta
  1151. X                   alpha2000 and delta2000 */
  1152. X      calc_events(objects[i].eventlist,
  1153. X          &objects[i].rise_hour, &objects[i].transit_hour,
  1154. X          &objects[i].set_hour,
  1155. X          jd, obs_lon, obs_lat, obs_zone, obs_height,
  1156. X          objects[i].name, objects[i].alpha, objects[i].delta);
  1157. X      add_events(events, &nevents, objects[i].eventlist);
  1158. X    };
  1159. X
  1160. X    /* for each body, calculate position and events */
  1161. X    for (i = 0; i < nbodies; i++) {
  1162. X      if (bodies[i].orbit_type == elliptical_orbit)
  1163. X    elliptical_pos(jd, sun_data, &bodies[i]);
  1164. X      else if (bodies[i].orbit_type == parabolic_orbit)
  1165. X    parabolic_pos(jd, sun_data, &bodies[i]);
  1166. X      else if (bodies[i].orbit_type == tabulated)
  1167. X    tabulated_pos(jd, sun_data, &bodies[i]);
  1168. X
  1169. X      calc_events(bodies[i].eventlist,
  1170. X          &bodies[i].rise_hour, &bodies[i].transit_hour,
  1171. X          &bodies[i].set_hour,
  1172. X          jd, obs_lon, obs_lat, obs_zone, obs_height,
  1173. X          bodies[i].name, bodies[i].alpha, bodies[i].delta);
  1174. X      add_events(events, &nevents, bodies[i].eventlist);
  1175. X    };
  1176. X
  1177. X    /* Sort event list */
  1178. X    for (i = 0; i < nevents; i++)
  1179. X      if (events[i].hour > 12.0)
  1180. X    event_times[i] = events[i].hour;
  1181. X      else {
  1182. X    events[i].hour += 3.94 / 60; /* add a day */
  1183. X    event_times[i] = events[i].hour + 24;
  1184. X      };
  1185. X    HeapSort0(event_times, index_events, nevents);
  1186. X
  1187. X    if (do_sif || do_star)
  1188. X      out_sif(o_sif, o_star, do_sif, do_star, one_day,
  1189. X          sun_data, moon_data,
  1190. X          planets, bodies, nbodies, objects, nobjects);
  1191. X                /* Output .sif and .star files for object(s) */
  1192. X
  1193. X    if (do_obs)
  1194. X      out_obs(o_obs, one_day, jd, events, index_events, nevents);
  1195. X                /* Output observability file for object(s) */
  1196. X
  1197. X    if (do_eph)
  1198. X      out_eph(o_eph, one_day, jd,
  1199. X          sun_data, moon_data,
  1200. X          planets, bodies, nbodies, objects, nobjects);
  1201. X                /* Output ephemeris file for object(s) */
  1202. X
  1203. X    if (do_altaz)
  1204. X      out_altaz(o_altaz, one_day, jd,
  1205. X        obs_lon, obs_lat, obs_zone, obs_height,
  1206. X        sun_data, moon_data,
  1207. X        planets, bodies, nbodies, objects, nobjects);
  1208. X                /* Output altaz file for object(s) */
  1209. X
  1210. X    if (satellites)
  1211. X      if (one_day)
  1212. X    out_sat(o_sat, o_sat_PS, one_day, invert_sats, jd, moon_data, planets);
  1213. X                /* Output satellite, .PS file for satellites */
  1214. X  };
  1215. X  if (!one_day) {        /* need to calculate moving objects for each
  1216. X                 object for each day */
  1217. X    /* Sun */
  1218. X    for (jd = start_date; jd <= end_date; jd += interval_days) {
  1219. X      /* Calculate sun position, moon position */
  1220. X      sun_pos(jd, &sun_data);
  1221. X      if (do_sif || do_star)
  1222. X    out_sif_sun(o_sif, o_star, do_sif, do_star, one_day,
  1223. X            sun_data, jd);
  1224. X      /* Output .sif and .star files for sun */
  1225. X    };
  1226. X    /* Moon */
  1227. X    for (jd = start_date; jd <= end_date; jd += interval_days) {
  1228. X      /* Calculate sun position, moon position */
  1229. X      sun_pos(jd, &sun_data);
  1230. X      moon_pos(jd, sun_data, &moon_data);
  1231. X      if (do_sif || do_star)
  1232. X    out_sif_moon(o_sif, o_star, do_sif, do_star, one_day,
  1233. X             moon_data, jd);
  1234. X      /* Output .sif and .star files for moon */
  1235. X    };
  1236. X
  1237. X
  1238. X    /* for each planet, calculate position and events */
  1239. X    for (i = 0; i < 7; i++)
  1240. X      if (planet_list[i]) {
  1241. X    for (jd = start_date; jd <= end_date; jd += interval_days) {
  1242. X      /* Calculate sun position */
  1243. X      sun_pos(jd, &sun_data);
  1244. X
  1245. X      planet_pos(jd, sun_data, i, &planets[i]);
  1246. X      /* Output .sif and .star files for planet */
  1247. X      if (do_sif || do_star)
  1248. X        out_sif_planet(o_sif, o_star, do_sif, do_star, one_day,
  1249. X               planets[i], jd);
  1250. X    }
  1251. X      };
  1252. X
  1253. X    /* Output satellite positions for each day */
  1254. X    if (satellites) {
  1255. X      /* Jupiter */
  1256. X      for (jd = start_date; jd <= end_date; jd += interval_days) {
  1257. X    sun_pos(jd, &sun_data);
  1258. X    moon_pos(jd, sun_data, &moon_data);
  1259. X    planet_pos(jd, sun_data, 3, &planets[3]);
  1260. X    out_sat(o_sat, o_sat_PS, one_day, invert_sats, jd,
  1261. X        moon_data, planets);
  1262. X    /* Output satellite, .PS file for satellites */
  1263. X      };
  1264. X
  1265. X      /* Saturn */
  1266. X      for (jd = start_date; jd <= end_date; jd += interval_days) {
  1267. X    sun_pos(jd, &sun_data);
  1268. X    moon_pos(jd, sun_data, &moon_data);
  1269. X    planet_pos(jd, sun_data, 4, &planets[4]);
  1270. X    out_sat(o_sat, o_sat_PS, one_day, invert_sats, jd,
  1271. X        moon_data, planets);
  1272. X    /* Output satellite, .PS file for satellites */
  1273. X      };
  1274. X      out_sat_end(o_sat, o_sat_PS, invert_sats, start_date, interval_days);
  1275. X                /* Close the postscript (showpage) */
  1276. X    };
  1277. X
  1278. X    /* for each body, calculate position and events */
  1279. X    for (i = 0; i < nbodies; i++) {
  1280. X      for (jd = start_date; jd <= end_date; jd += interval_days) {
  1281. X    /* Calculate sun position */
  1282. X    sun_pos(jd, &sun_data);
  1283. X    
  1284. X    if (bodies[i].orbit_type == elliptical_orbit)
  1285. X      elliptical_pos(jd, sun_data, &bodies[i]);
  1286. X    else if (bodies[i].orbit_type == parabolic_orbit)
  1287. X      parabolic_pos(jd, sun_data, &bodies[i]);
  1288. X    else if (bodies[i].orbit_type == tabulated)
  1289. X      tabulated_pos(jd, sun_data, &bodies[i]);
  1290. X
  1291. X    if (do_sif || do_star)
  1292. X      out_sif_body(o_sif, o_star, do_sif, do_star, one_day,
  1293. X               bodies[i], jd);
  1294. X    /* Output .sif and .star files for planet */
  1295. X      };
  1296. X    };
  1297. X  };
  1298. X  exit(0);
  1299. X}
  1300. X
  1301. X
  1302. X#define GMT1970 2440587.5
  1303. X/*
  1304. X  Get current time
  1305. X  set start_date, start_day, start_month, start_year, start_hour;
  1306. X*/
  1307. Xvoid get_time()
  1308. X{
  1309. X  time_t timeofday;        /* time_t is usually "long" */
  1310. X#ifndef ATARI_ST
  1311. X  struct timeb tp;
  1312. X
  1313. X  ftime(&tp);
  1314. X
  1315. X  timeofday = tp.time;
  1316. X#else
  1317. X  time(&timeofday);
  1318. X#endif
  1319. X
  1320. X  start_date = timeofday / 86400.0 + 2440587.5; /* this is now the true JD */
  1321. X}
  1322. X
  1323. X
  1324. X
  1325. X/* rather system dependent */
  1326. X
  1327. X/* Method 1 subtract local time from gmt */
  1328. Xdouble now_zone()
  1329. X{
  1330. X  time_t timeofday;
  1331. X  struct timeb tp;
  1332. X  struct tm *localtm, *gmttm;
  1333. X  double local_hour, gmt_hour;
  1334. X  ftime(&tp);
  1335. X
  1336. X  timeofday = tp.time;
  1337. X
  1338. X  localtm = localtime(&timeofday);
  1339. X  local_hour = localtm->tm_sec/3600.0 + localtm->tm_min/60.0
  1340. X    + localtm->tm_hour;
  1341. X  gmttm = gmtime(&timeofday);
  1342. X  gmt_hour = gmttm->tm_sec/3600.0 + gmttm->tm_min/60.0
  1343. X    + gmttm->tm_hour;
  1344. X
  1345. X  return (local_hour - gmt_hour);
  1346. X}
  1347. X
  1348. X/* Method 2, for SYSV?
  1349. Xdouble now_zone()
  1350. X{
  1351. X  extern long timezone;
  1352. X
  1353. X  return (-timezone/3600.0);
  1354. X}
  1355. X*/
  1356. X/* Method 3, for non SYSV?
  1357. Xdouble now_zone()
  1358. X{
  1359. X  struct timeval tp;
  1360. X  struct timezone tzp;
  1361. X
  1362. X  gettimeofday(&tp, &tzp);
  1363. X
  1364. X  return (-tzp.tz_minuteswest/60.0 + tzp.tz_dsttime);
  1365. X}
  1366. X*/
  1367. X/* For ATARI_ST */
  1368. X/*double now_zone()
  1369. X{
  1370. X  extern long timezone;
  1371. X  tm_t *tp;
  1372. X  localtime(&tp);
  1373. X
  1374. X  return (-timezone/3600.0);
  1375. X}
  1376. X*/
  1377. X
  1378. X
  1379. Xint now_year()
  1380. X{
  1381. X  time_t timeofday;        /* time_t is usually "long" */
  1382. X#ifndef ATARI_ST
  1383. X  struct timeb tp;
  1384. X  double jd;
  1385. X  double day;
  1386. X  int month, year;
  1387. X
  1388. X  ftime(&tp);
  1389. X
  1390. X  timeofday = tp.time;
  1391. X
  1392. X  jd = timeofday / 86400.0 + 2440587.5; /* this is now the true JD */
  1393. X
  1394. X  jd_to_cal(jd, &day, &month, &year);
  1395. X#else /* Atari */
  1396. X  int year;
  1397. X  tm_t *tp;
  1398. X  time(&timeofday);
  1399. X  tp=localtime(&timeofday);
  1400. X  year=tp->tm_year;
  1401. X#endif
  1402. X  return year;
  1403. X}
  1404. X
  1405. X
  1406. X/* is not an argument switch, i.e. not "-[a-Z]" */
  1407. Xint notarg(s)
  1408. Xchar *s;
  1409. X{
  1410. X  return (!((s[0] == '-') && (isalpha(s[1]))));
  1411. X}
  1412. X
  1413. Xvoid usage()
  1414. X{
  1415. X  fprintf(stderr,
  1416. X "%s: -o[aeios] outfile_root -p [MVmJsUN] -s[i] -n name -f filename filetype\n\
  1417. X      -d \"start date\" \"end date\" -z time_zone_value -l latitude -m meridian\n",
  1418. X      progname);
  1419. X}
  1420. X
  1421. Xvoid parse_command(argc, argv)
  1422. Xint argc;
  1423. Xchar **argv;
  1424. X{
  1425. X  int i, j;
  1426. X  char *cp1;
  1427. X  int mo, yr;
  1428. X  double dy;
  1429. X
  1430. X  progname = argv[0];
  1431. X
  1432. X  for (i = 1; i < argc; i++)
  1433. X    if (argv[i][0] == '-')
  1434. X      switch (argv[i][1]) {
  1435. X      case 'm':
  1436. X                /* Meridian */
  1437. X                /* One to three arguments, floating point */
  1438. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1439. X      obs_lon = atof(argv[i+1]);
  1440. X      i++;
  1441. X      if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1442. X        if (obs_lon > 0)
  1443. X          obs_lon += atof(argv[i+1]) / 60.0;
  1444. X        else
  1445. X          obs_lon -= atof(argv[i+1]) / 60.0;
  1446. X        i++;
  1447. X        if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1448. X          if (obs_lon > 0)
  1449. X        obs_lon += atof(argv[i+1]) / 3600.0;
  1450. X          else
  1451. X        obs_lon -= atof(argv[i+1]) / 3600.0;
  1452. X          i++;
  1453. X        };
  1454. X      };
  1455. X    };
  1456. X    break;
  1457. X      case 'l':
  1458. X                /* Latitude */
  1459. X                /* One to three arguments, floating point */
  1460. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1461. X      obs_lat = atof(argv[i+1]);
  1462. X      i++;
  1463. X      if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1464. X        if (obs_lat > 0)
  1465. X          obs_lat += atof(argv[i+1]) / 60.0;
  1466. X        else
  1467. X          obs_lat -= atof(argv[i+1]) / 60.0;
  1468. X        i++;
  1469. X        if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1470. X          if (obs_lat > 0)
  1471. X        obs_lat += atof(argv[i+1]) / 3600.0;
  1472. X          else
  1473. X        obs_lat -= atof(argv[i+1]) / 3600.0;
  1474. X          i++;
  1475. X        };
  1476. X      };
  1477. X    };
  1478. X    break;
  1479. X      case 'z':            /* time Zone */
  1480. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1481. X      i++;
  1482. X      obs_zone = atof(argv[i]);
  1483. X    };
  1484. X    break;
  1485. X      case 'a':            /* altitude, meters */
  1486. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1487. X      i++;
  1488. X      obs_height = atof(argv[i]);
  1489. X    };
  1490. X    break;
  1491. X      case 'd':
  1492. X                /* start_day [end_day [interval]] */
  1493. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1494. X      str_to_cal(argv[i+1], &dy, &mo, &yr);
  1495. X      if (yr == 0) yr = start_year;
  1496. X      start_day = dy;
  1497. X      start_month = mo;
  1498. X      start_year = yr;
  1499. X      cal_to_jd(start_day, start_month, start_year, &start_date);
  1500. X      i++;
  1501. X      if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1502. X        str_to_cal(argv[i+1], &dy, &mo, &yr);
  1503. X        if (yr == 0) yr = end_year;
  1504. X        end_day = dy;
  1505. X        end_month = mo;
  1506. X        end_year = yr;
  1507. X        cal_to_jd(end_day, end_month, end_year, &end_date);
  1508. X        i++;
  1509. X        if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1510. X          interval_days = atof(argv[i+1]);
  1511. X          i++;
  1512. X        };
  1513. X      } else {
  1514. X        end_date = start_date;
  1515. X        end_day = start_day;
  1516. X        end_month = start_month;
  1517. X        end_year = start_year;
  1518. X      };
  1519. X    };
  1520. X    break;
  1521. X      case 'o':
  1522. X    cp1 = &argv[i][2];
  1523. X    if (*cp1) {
  1524. X      /* Select output files */
  1525. X      do_sif = do_star = do_eph = do_obs = do_altaz = FALSE;
  1526. X      while (*cp1)
  1527. X        switch (*cp1++) {
  1528. X        case 'a':
  1529. X          do_altaz = TRUE;
  1530. X          break;
  1531. X        case 'e':
  1532. X          do_eph = TRUE;
  1533. X          break;
  1534. X        case 'i':
  1535. X          do_sif = TRUE;
  1536. X          break;
  1537. X        case 'o':
  1538. X          do_obs = TRUE;
  1539. X          break;
  1540. X        case 's':
  1541. X          do_star = TRUE;
  1542. X          break;
  1543. X        default:
  1544. X          break;
  1545. X        };
  1546. X    } else
  1547. X      do_sif = do_star = do_eph = do_obs = do_altaz = TRUE;
  1548. X
  1549. X                /* outfile_root */
  1550. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1551. X      outfile_root = argv[i+1];
  1552. X      i++;
  1553. X    };
  1554. X    break;
  1555. X      case 'p':
  1556. X                /* [planetlist_string] */
  1557. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1558. X      j = 0;
  1559. X      i++;
  1560. X#ifdef SYSV
  1561. X      if (strchr(argv[i], 'M')) planet_list[0] = TRUE; 
  1562. X      if (strchr(argv[i], 'V')) planet_list[1] = TRUE; 
  1563. X      if (strchr(argv[i], 'm')) planet_list[2] = TRUE; 
  1564. X      if (strchr(argv[i], 'J')) planet_list[3] = TRUE; 
  1565. X      if (strchr(argv[i], 's')) planet_list[4] = TRUE; 
  1566. X      if (strchr(argv[i], 'U')) planet_list[5] = TRUE; 
  1567. X      if (strchr(argv[i], 'N')) planet_list[6] = TRUE; 
  1568. X#else
  1569. X      if (index(argv[i], 'M')) planet_list[0] = TRUE; 
  1570. X      if (index(argv[i], 'V')) planet_list[1] = TRUE; 
  1571. X      if (index(argv[i], 'm')) planet_list[2] = TRUE; 
  1572. X      if (index(argv[i], 'J')) planet_list[3] = TRUE; 
  1573. X      if (index(argv[i], 's')) planet_list[4] = TRUE; 
  1574. X      if (index(argv[i], 'U')) planet_list[5] = TRUE; 
  1575. X      if (index(argv[i], 'N')) planet_list[6] = TRUE; 
  1576. X#endif
  1577. X    } else {
  1578. X      for (j = 0; j < 7; j++)
  1579. X        planet_list[j] = TRUE;
  1580. X    };
  1581. X    break;
  1582. X      case 's':
  1583. X                /* either -s or -si */
  1584. X    satellites = TRUE;
  1585. X    for (j = 0; j < 7; j++)
  1586. X      planet_list[j] = TRUE;
  1587. X    if (argv[i][2] == 'i')
  1588. X      invert_sats = TRUE;
  1589. X    break;
  1590. X      case 'n':
  1591. X    if (((i+1) < argc) && (notarg(argv[i+1]))) {
  1592. X      i++;
  1593. X      obj_name = argv[i];
  1594. X    };
  1595. X                /* name */
  1596. X    break;
  1597. X      case 'f':
  1598. X                /* file format */
  1599. X    if (((i+2) < argc) && (notarg(argv[i+1])) && (notarg(argv[i+2]))) {
  1600. X      infile_name = argv[i+1];
  1601. X      in_type = tr_format(argv[i+2]);
  1602. X      if (in_type == no_format) {
  1603. X        fprintf(stderr, "%s: format %s not recognized.\n", progname, 
  1604. X            argv[i+2]);
  1605. X        exit(1);
  1606. X      };
  1607. X      i += 2;
  1608. X      file_input = TRUE;
  1609. X    };
  1610. X    break;
  1611. X      case 'h':
  1612. X    usage();
  1613. X    break;
  1614. X      default:
  1615. X    fprintf(stderr, "%s: error, unrecognized command line argument %s\n",
  1616. X        progname, argv[i]);
  1617. X    usage();
  1618. X    break;
  1619. X      };
  1620. X}
  1621. X
  1622. X
  1623. X/* translate string to format */
  1624. Xfformat_t tr_format(s)
  1625. Xchar *s;
  1626. X{
  1627. X  int i = -1;
  1628. X  while (s[++i]) if (isupper(s[i])) s[i] = tolower(s[i]);
  1629. X
  1630. X  if (!strcmp(s, "emp")) return emp;
  1631. X  else if (!strcmp(s, "empb")) return empb;
  1632. X  else if (!strcmp(s, "aa")) return aa;
  1633. X  else if (!strcmp(s, "st")) return st;
  1634. X  else if (!strcmp(s, "iau")) return iau;
  1635. X  else if (!strcmp(s, "ell_e")) return ell_e;
  1636. X  else if (!strcmp(s, "par_e")) return par_e;
  1637. X  else if (!strcmp(s, "obj")) return obj;
  1638. X  else return no_format;
  1639. X}
  1640. X
  1641. END_OF_FILE
  1642. if test 21792 -ne `wc -c <'observe/main.c'`; then
  1643.     echo shar: \"'observe/main.c'\" unpacked with wrong size!
  1644. fi
  1645. # end of 'observe/main.c'
  1646. fi
  1647. echo shar: End of archive 11 \(of 32\).
  1648. cp /dev/null ark11isdone
  1649. MISSING=""
  1650. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ; do
  1651.     if test ! -f ark${I}isdone ; then
  1652.     MISSING="${MISSING} ${I}"
  1653.     fi
  1654. done
  1655. if test "${MISSING}" = "" ; then
  1656.     echo You have unpacked all 32 archives.
  1657.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1658. else
  1659.     echo You still need to unpack the following archives:
  1660.     echo "        " ${MISSING}
  1661. fi
  1662. ##  End of shell archive.
  1663. exit 0
  1664.  
  1665.