home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / star.lzh / star.11 < prev    next >
Encoding:
Text File  |  1990-03-27  |  42.6 KB  |  1,657 lines

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