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

  1. Newsgroups: comp.sources.misc
  2. subject: v11i053: starchart 3.2 Part 25/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 53
  7. Submitted-by: ccount@ATHENA.MIT.EDU
  8. Archive-name: starchart/part25
  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 25 (of 32)."
  17. # Contents:  dataconv/dataconv.c
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'dataconv/dataconv.c' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'dataconv/dataconv.c'\"
  21. else
  22. echo shar: Extracting \"'dataconv/dataconv.c'\" \(34330 characters\)
  23. sed "s/^X//" >'dataconv/dataconv.c' <<'END_OF_FILE'
  24. X/*
  25. X * dataconv.c/precess -- convert between starchart data formats,
  26. X *                precess to other equator and equinox.
  27. X *              precession based formulae from
  28. X *                Astronomical Almanac, 1988, p B19
  29. X *
  30. X * Copyright (c) 1990 by Craig Counterman. All rights reserved.
  31. X *
  32. X * This software may be redistributed freely, not sold.
  33. X * This copyright notice and disclaimer of warranty must remain
  34. X *    unchanged. 
  35. X *
  36. X * No representation is made about the suitability of this
  37. X * software for any purpose.  It is provided "as is" without express or
  38. X * implied warranty, to the extent permitted by applicable law.
  39. X *
  40. X * DISCLAIMER OF WARRANTY
  41. X * ----------------------
  42. X * The author  disclaims all warranties  with regard to  this software to
  43. X * the   extent  permitted  by applicable   law,  including all   implied
  44. X * warranties  of merchantability  and  fitness. In  no event shall   the
  45. X * author be liable for any special, indirect or consequential damages or
  46. X * any  damages whatsoever resulting from  loss of use, data or  profits,
  47. X * whether in an action of contract, negligence or other tortious action,
  48. X * arising  out of  or in connection with the  use or performance of this
  49. X * software.
  50. X *
  51. X */
  52. X
  53. X
  54. Xstatic char rcsid[]="$Header: dataconv.c,v 2.12 90/02/25 16:13:50 ccount Exp $";
  55. X
  56. X
  57. X
  58. X#include <stdio.h>
  59. X#include <math.h>
  60. X#include <ctype.h>
  61. X
  62. X/* Defines for equinox */
  63. X#define EQLOW 1850.0
  64. X#define EQHI  2100.0
  65. X#define DEFEIN 1950.0
  66. X#define DEFEOUT 2000.0
  67. X
  68. X
  69. X/* other defines */
  70. X#define LINELEN 82
  71. X#define MAX(a,b) ((a)>(b)?(a):(b))
  72. X#define MIN(a,b) ((a)<(b)?(a):(b))
  73. X#define FALSE 0
  74. X#define TRUE 1
  75. X#define DEG_TO_RAD 0.01745329251994329600
  76. X#define RAD_TO_DEG 57.29577951308232
  77. X#define DSIN(x) (sin((x)*DEG_TO_RAD))
  78. X#define DCOS(x) (cos((x)*DEG_TO_RAD))
  79. X#define DTAN(x) (tan((x)*DEG_TO_RAD))
  80. X#define DASIN(x) (asin(x)*RAD_TO_DEG)
  81. X#define DACOS(x) (acos(x)*RAD_TO_DEG)
  82. X#define DATAN(x) (atan(x)*RAD_TO_DEG)
  83. X#define DATAN2(x,y) (atan2(x,y)*RAD_TO_DEG)
  84. X
  85. X/* File types */
  86. X#define LINEREAD 1
  87. X#define INDEXTYPE 2
  88. X#define BINFULL 3
  89. X#define BINOBJ 4
  90. X#define BINSTAR 5
  91. X#define SAOTYPE 6
  92. X#define SIFTYPE 7
  93. X#define GSCTYPE 8
  94. X
  95. X#define SEPCHAR ';'
  96. X
  97. X/* variables for data, filled by readstar and readsif */
  98. Xdouble obj_lat, obj_lon, obj_mag;
  99. Xchar obj_type[] ="SS", obj_color[3], obj_label[3];
  100. Xchar obj_constell[4], obj_name[LINELEN];
  101. Xchar *obj_commnt, fileline[LINELEN];
  102. X
  103. Xchar *usage =
  104. X"%s:\nargs: -i inname intype -o outname outtype\n\t[-sc] [-f from_equinox -t to_equinox]\n";
  105. X
  106. X
  107. Xint tr_type();
  108. Xint readstar();
  109. Xint readsif();
  110. Xvoid writelr();
  111. Xvoid wrbinfull();
  112. Xvoid wrbinstar();
  113. Xvoid wrbinobj();
  114. Xvoid writesif();
  115. Xint to_consindx();
  116. Xvoid initxform(), xform();
  117. X
  118. Xdouble into_range();
  119. Xvoid precess_f();
  120. X
  121. Xmain(argc, argv)
  122. X     int argc;
  123. X     char *argv[];
  124. X{
  125. X  char *inname = "", *outname = "";
  126. X  char *intypestr = "", *outtypestr = "";
  127. X  FILE *infile, *outfile;
  128. X  int intype, outtype;
  129. X  char sepchar = SEPCHAR;
  130. X  int i;
  131. X  double ein=0.0, eout=0.0, ra_out, de_out;
  132. X  int precess = FALSE;
  133. X
  134. X  if ((argc <  7)) {
  135. X    fprintf(stderr, usage, argv[0]);
  136. X    exit(1);
  137. X  }
  138. X
  139. X  i = 0;
  140. X  while (i < argc)
  141. X    if (argv[i][0] != '-') i++;
  142. X  else switch (argv[i][1]) {
  143. X  case 'f':
  144. X    ein=atof(argv[i+1]);
  145. X    precess = TRUE;
  146. X    i += 2;
  147. X    break;
  148. X  case 't':
  149. X    eout=atof(argv[i+1]);
  150. X    precess = TRUE;
  151. X    i += 2;
  152. X    break;
  153. X  case 'i':
  154. X    inname = argv[i+1];
  155. X    intypestr = argv[i+2];
  156. X    if (!(intype = tr_type(argv[i+2]))) {
  157. X      fprintf(stderr, usage, argv[0]);
  158. X      fprintf(stderr, "Invalid intype %s\n", argv[i+2]);
  159. X      exit(2);
  160. X    }
  161. X    i += 3;
  162. X    break;
  163. X  case 'o':
  164. X    outname = argv[i+1];
  165. X    outtypestr = argv[i+2];
  166. X    if (!(outtype = tr_type(argv[i+2]))) {
  167. X      fprintf(stderr, usage, argv[0]);
  168. X      fprintf(stderr, "Invalid outtype %s\n", argv[i+2]);
  169. X      exit(3);
  170. X    }
  171. X    if (outtype == GSCTYPE) {
  172. X      fprintf(stderr, "%s: cannot write gsc format files.\n", argv[0]);
  173. X      exit(3);
  174. X    }
  175. X    i += 3;
  176. X    break;
  177. X  case 's':
  178. X    if (argv[i][2]) sepchar = argv[i][2];
  179. X    i++;
  180. X    break;
  181. X  default:
  182. X    fprintf(stderr, usage, argv[0]);
  183. X    exit(4);
  184. X  }
  185. X
  186. X  if (precess && 
  187. X      ((ein < EQLOW) || (ein > EQHI) || (eout  < EQLOW) || (eout > EQHI))) {
  188. X    fprintf(stderr, usage, argv[0]);
  189. X    if ((ein > 0.0) || (eout > 0.0))
  190. X      fprintf(stderr, "equinox not in range [%.1f..%.1f]\n", EQLOW, EQHI);
  191. X    exit(5);
  192. X  }
  193. X
  194. X
  195. X#ifdef ATARI_ST
  196. X  if ((infile = fopen(inname, (intype == LINEREAD)?"r":"rb")) == NULL) {
  197. X    fprintf(stderr, "%s: Can't open input file %s\n", argv[0], inname);
  198. X    exit(6);
  199. X  }
  200. X
  201. X  if ((outfile = fopen(outname, "wb")) == NULL) {
  202. X    fprintf(stderr, "%s: Can't open output file %s\n", argv[0], outname);
  203. X    exit(7);
  204. X  }
  205. X#else
  206. X  if ((infile = fopen(inname, "r")) == NULL) {
  207. X    fprintf(stderr, "%s: Can't open input file %s\n", argv[0], inname);
  208. X    exit(6);
  209. X  }
  210. X
  211. X  if ((outfile = fopen(outname, "w")) == NULL) {
  212. X    fprintf(stderr, "%s: Can't open output file %s\n", argv[0], outname);
  213. X    exit(7);
  214. X  }
  215. X#endif
  216. X
  217. X
  218. X  fprintf(stderr,
  219. X      "%s:\n converting %s format file %s\n to %s format file %s\n",
  220. X      argv[0], intypestr, inname, outtypestr, outname);
  221. X  if ((intype == SIFTYPE) || (outtype == SIFTYPE))
  222. X    fprintf(stderr, "Separation character %c\n", sepchar);
  223. X
  224. X  if (precess)
  225. X    fprintf(stderr, "Precessing from equinox %.3f to %.3f\n",
  226. X        ein, eout);
  227. X
  228. X
  229. X  /* SIF must be read with readsif
  230. X     All others should be read with readstar
  231. X     */
  232. X  if (precess) {
  233. X    if (intype == SIFTYPE)
  234. X      switch (outtype) {
  235. X      case LINEREAD:
  236. X    for (;;) {
  237. X      if (readsif(infile, sepchar)) break;
  238. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  239. X      obj_lon = ra_out;
  240. X      obj_lat = de_out;
  241. X      writelr(outfile);
  242. X    }
  243. X    break;
  244. X      case BINFULL:
  245. X    for (;;) {
  246. X      if (readsif(infile, sepchar)) break;
  247. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  248. X      obj_lon = ra_out;
  249. X      obj_lat = de_out;
  250. X      wrbinfull(outfile);
  251. X    }
  252. X    break;
  253. X      case BINOBJ:
  254. X    for (;;) {
  255. X      if (readsif(infile, sepchar)) break;
  256. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  257. X      obj_lon = ra_out;
  258. X      obj_lat = de_out;
  259. X      wrbinobj(outfile);
  260. X    }
  261. X    break;
  262. X      case BINSTAR:
  263. X    for (;;) {
  264. X      if (readsif(infile, sepchar)) break;
  265. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  266. X      obj_lon = ra_out;
  267. X      obj_lat = de_out;
  268. X      wrbinstar(outfile);
  269. X    }
  270. X    break;
  271. X      }
  272. X    else /* Not SIF in */ 
  273. X      switch (outtype) {
  274. X      case LINEREAD:
  275. X    for (;;) {
  276. X      if (readstar(infile, intype)) break;
  277. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  278. X      obj_lon = ra_out;
  279. X      obj_lat = de_out;
  280. X      writelr(outfile);
  281. X    }
  282. X    break;
  283. X      case BINFULL:
  284. X    for (;;) {
  285. X      if (readstar(infile, intype)) break;
  286. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  287. X      obj_lon = ra_out;
  288. X      obj_lat = de_out;
  289. X      wrbinfull(outfile);
  290. X    }
  291. X    break;
  292. X      case BINOBJ:
  293. X    for (;;) {
  294. X      if (readstar(infile, intype)) break;
  295. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  296. X      obj_lon = ra_out;
  297. X      obj_lat = de_out;
  298. X      wrbinobj(outfile);
  299. X    }
  300. X    break;
  301. X      case BINSTAR:
  302. X    for (;;) {
  303. X      if (readstar(infile, intype)) break;
  304. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  305. X      obj_lon = ra_out;
  306. X      obj_lat = de_out;
  307. X      wrbinstar(outfile);
  308. X    }
  309. X    break;
  310. X      case SIFTYPE:
  311. X    for (;;) {
  312. X      if (readstar(infile, intype)) break;
  313. X      precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
  314. X      obj_lon = ra_out;
  315. X      obj_lat = de_out;
  316. X      writesif(outfile, sepchar);
  317. X    }
  318. X    break;
  319. X      }
  320. X  } else { /* not precess */
  321. X    if (intype == SIFTYPE)
  322. X      switch (outtype) {
  323. X      case LINEREAD:
  324. X    for (;;) {
  325. X      if (readsif(infile, sepchar)) break;
  326. X      writelr(outfile);
  327. X    }
  328. X    break;
  329. X      case BINFULL:
  330. X    for (;;) {
  331. X      if (readsif(infile, sepchar)) break;
  332. X      wrbinfull(outfile);
  333. X    }
  334. X    break;
  335. X      case BINOBJ:
  336. X    for (;;) {
  337. X      if (readsif(infile, sepchar)) break;
  338. X      wrbinobj(outfile);
  339. X    }
  340. X    break;
  341. X      case BINSTAR:
  342. X    for (;;) {
  343. X      if (readsif(infile, sepchar)) break;
  344. X      wrbinstar(outfile);
  345. X    }
  346. X    break;
  347. X      }
  348. X    else /* Not SIF in */ 
  349. X      switch (outtype) {
  350. X      case LINEREAD:
  351. X    for (;;) {
  352. X      if (readstar(infile, intype)) break;
  353. X      writelr(outfile);
  354. X    }
  355. X    break;
  356. X      case BINFULL:
  357. X    for (;;) {
  358. X      if (readstar(infile, intype)) break;
  359. X      wrbinfull(outfile);
  360. X    }
  361. X    break;
  362. X      case BINOBJ:
  363. X    for (;;) {
  364. X      if (readstar(infile, intype)) break;
  365. X      wrbinobj(outfile);
  366. X    }
  367. X    break;
  368. X      case BINSTAR:
  369. X    for (;;) {
  370. X      if (readstar(infile, intype)) break;
  371. X      wrbinstar(outfile);
  372. X    }
  373. X    break;
  374. X      case SIFTYPE:
  375. X    for (;;) {
  376. X      if (readstar(infile, intype)) break;
  377. X      writesif(outfile, sepchar);
  378. X    }
  379. X    break;
  380. X      }
  381. X  }
  382. X
  383. X  exit(0);
  384. X}
  385. X
  386. X
  387. X
  388. X
  389. X
  390. Xint tr_type(s)
  391. X     char *s;
  392. X{
  393. X  int i;
  394. X
  395. X  for (i = 0; s[i]; i++)
  396. X    if (isupper(s[i]))
  397. X      s[i] = tolower(s[i]);
  398. X
  399. X  if(!strcmp(s, "lineread")) return LINEREAD;
  400. X/*  else if (!strcmp(s, "indextype")) return INDEXTYPE;*/
  401. X  else if (!strcmp(s, "binfull")) return BINFULL;
  402. X  else if (!strcmp(s, "binobj")) return BINOBJ;
  403. X  else if (!strcmp(s, "binstar")) return BINSTAR;
  404. X  else if (!strcmp(s, "sif")) return SIFTYPE;
  405. X  else if (!strcmp(s, "gsc")) return GSCTYPE;
  406. X/*  else if (!strcmp(s, "saoformat")) return SAOFORMAT;*/
  407. X  else return 0;
  408. X}
  409. X
  410. X
  411. X/* constellation abbreviations */
  412. Xchar *con_table[] = {
  413. X  "   ",
  414. X  "AND",
  415. X  "ANT",
  416. X  "APS",
  417. X  "AQL",
  418. X  "AQR",
  419. X  "ARA",
  420. X  "ARI",
  421. X  "AUR",
  422. X  "BOO",
  423. X  "CAE",
  424. X  "CAM",
  425. X  "CAP",
  426. X  "CAR",
  427. X  "CAS",
  428. X  "CEN",
  429. X  "CEP",
  430. X  "CET",
  431. X  "CHA",
  432. X  "CIR",
  433. X  "CMA",
  434. X  "CMI",
  435. X  "CNC",
  436. X  "COL",
  437. X  "COM",
  438. X  "CRA",
  439. X  "CRB",
  440. X  "CRT",
  441. X  "CRU",
  442. X  "CRV",
  443. X  "CVN",
  444. X  "CYG",
  445. X  "DEL",
  446. X  "DOR",
  447. X  "DRA",
  448. X  "EQU",
  449. X  "ERI",
  450. X  "FOR",
  451. X  "GEM",
  452. X  "GRU",
  453. X  "HER",
  454. X  "HOR",
  455. X  "HYA",
  456. X  "HYI",
  457. X  "IND",
  458. X  "LAC",
  459. X  "LEO",
  460. X  "LEP",
  461. X  "LIB",
  462. X  "LMI",
  463. X  "LUP",
  464. X  "LYN",
  465. X  "LYR",
  466. X  "MEN",
  467. X  "MIC",
  468. X  "MON",
  469. X  "MUS",
  470. X  "NOR",
  471. X  "OCT",
  472. X  "OPH",
  473. X  "ORI",
  474. X  "PAV",
  475. X  "PEG",
  476. X  "PER",
  477. X  "PHE",
  478. X  "PIC",
  479. X  "PSA",
  480. X  "PSC",
  481. X  "PUP",
  482. X  "PYX",
  483. X  "RET",
  484. X  "SCL",
  485. X  "SCO",
  486. X  "SCT",
  487. X  "SER",
  488. X  "SEX",
  489. X  "SGE",
  490. X  "SGR",
  491. X  "TAU",
  492. X  "TEL",
  493. X  "TRA",
  494. X  "TRI",
  495. X  "TUC",
  496. X  "UMA",
  497. X  "UMI",
  498. X  "VEL",
  499. X  "VIR",
  500. X  "VOL",
  501. X  "VUL",
  502. X  ""
  503. X  };
  504. X
  505. X
  506. X/* typedefs for exact sizes of int */
  507. Xtypedef char int_8;
  508. Xtypedef short int int_16;
  509. Xtypedef long int int_32;
  510. X
  511. X/* BINFULL structure */
  512. Xstruct bfull_struct {
  513. X  int_32 lat;            /* RA in seconds * 1000 */
  514. X  int_32 lon;            /* Dec in seconds * 1000 */
  515. X  int_16 mag;            /* Mag * 1000 */
  516. X  char tycolb[6];        /* Type, color, label fields */
  517. X  int_8 consindx;        /* Index number of constellation */
  518. X  int_16 strlen;        /* length of name and comment field */
  519. X} binfull_in, binfull_out;
  520. X
  521. Xchar name_comment[LINELEN];
  522. X
  523. X/* BINOBJ structure */
  524. Xstruct bobj_struct {
  525. X  int_32 lat;            /* RA in seconds * 1000 */
  526. X  int_32 lon;            /* Dec in seconds * 1000 */
  527. X  int_16 mag;            /* Mag * 1000 */
  528. X  char type[2];            /* e.g. 'SD', 'CO' */
  529. X} binobj_in, binobj_out;
  530. X
  531. X/* BINSTAR structure */
  532. Xstruct bstar_struct {
  533. X  int_32 lat;            /* RA in seconds * 1000 */
  534. X  int_32 lon;            /* Dec in seconds * 1000 */
  535. X  int_16 mag;            /* Mag * 1000 */
  536. X} binstar_in, binstar_out;
  537. X
  538. X
  539. X/* readstar reads from the file the information for one object, and
  540. X   loads the following variables:
  541. Xdouble obj_lat, obj_lon, obj_mag;
  542. Xchar obj_type[] ="SS", obj_color[3], obj_label[3];
  543. Xchar obj_constell[4], obj_name[LINELEN];
  544. Xchar *obj_commnt, fileline[LINELEN];
  545. X
  546. Xonly lat, lon, and mag are required.  type should default to 'SS',
  547. Xcolor, label, constell default to "  ", and the rest default to ""
  548. X*/
  549. Xint readstar(file, ftype)
  550. X     FILE *file;
  551. X     int ftype;
  552. X{
  553. X  char *ptr;
  554. X  double rah, ram, ras, dld, dlm, dl, inten;
  555. X  int i, j;
  556. X  int nchars;
  557. X  char m1;
  558. X  static int GSC_seeked = FALSE;
  559. X  static int GSC_skip = FALSE;
  560. X  struct {
  561. X    double ra_deg, dec_deg, mag;
  562. X    int mag_band, class;
  563. X  } GSC[10];
  564. X  int GSC_nlines;
  565. X  static int GSC_ID = 0;
  566. X  char id_str[5];
  567. X
  568. X  if ((ftype != LINEREAD) && (ftype != BINFULL)
  569. X      && (ftype != BINOBJ) && (ftype != BINSTAR) && (ftype != GSCTYPE))
  570. X    return (TRUE);
  571. X  /* only LINEREAD, BINFULL, BINOBJ and BINSTAR and GSCTYPE
  572. X     supported at this time */
  573. X
  574. X  if (ftype == BINSTAR) {
  575. X    if (fread((char *) &binstar_in, sizeof(binstar_in), 1, file) != 1) {
  576. X      if (feof(file)) return TRUE;
  577. X      perror("Error reading input file");
  578. X      exit(2);
  579. X    }
  580. X
  581. X    obj_lat = ((double) binstar_in.lat) / 3600000L;
  582. X    obj_lon = ((double) binstar_in.lon) / 3600000L;
  583. X    obj_mag = ((double) binstar_in.mag) / 1000L;
  584. X    obj_type[0] = 'S';
  585. X    obj_type[1] = 'S';
  586. X    obj_color[0] = ' ';
  587. X    obj_color[1] = ' ';
  588. X    obj_label[0] = ' ';
  589. X    obj_label[1] = ' ';
  590. X    obj_constell[0] = ' ';
  591. X    obj_constell[1] = ' ';
  592. X    obj_constell[2] = ' ';
  593. X    obj_name[0] = '\0';
  594. X    obj_commnt = "";
  595. X
  596. X    strcpy(fileline, "");
  597. X  } else if (ftype == BINOBJ) {
  598. X    if (fread((char *) &binobj_in, sizeof(binobj_in), 1, file) != 1) {
  599. X      if (feof(file)) return TRUE;
  600. X      perror("Error reading input file");
  601. X      exit(2);
  602. X    }
  603. X
  604. X    obj_lat = ((double) binobj_in.lat) / 3600000L;
  605. X    obj_lon = ((double) binobj_in.lon) / 3600000L;
  606. X    obj_mag = ((double) binobj_in.mag) / 1000L;
  607. X    obj_type[0] = binobj_in.type[0];
  608. X    obj_type[1] = binobj_in.type[1];
  609. X    obj_color[0] = ' ';
  610. X    obj_color[1] = ' ';
  611. X    obj_label[0] = ' ';
  612. X    obj_label[1] = ' ';
  613. X    obj_constell[0] = ' ';
  614. X    obj_constell[1] = ' ';
  615. X    obj_constell[2] = ' ';
  616. X    obj_name[0] = '\0';
  617. X    obj_commnt = "";
  618. X
  619. X    strcpy(fileline, "");
  620. X  } else if (ftype == BINFULL) {
  621. X    if (fread((char *) &binfull_in, sizeof(binfull_in), 1, file) != 1) {
  622. X      if (feof(file)) return TRUE;
  623. X      perror("Error reading input file");
  624. X      exit(2);
  625. X    }
  626. X
  627. X    if (binfull_in.strlen == 0)
  628. X      strcpy(name_comment, "");
  629. X    else {
  630. X      if (fread((char *) name_comment, binfull_in.strlen, 1, file) != 1) {
  631. X    perror("Error reading input file");
  632. X    exit(2);
  633. X      }
  634. X      name_comment[binfull_in.strlen] = '\0';
  635. X    }
  636. X
  637. X    obj_lat = ((double) binfull_in.lat) / 3600000L;
  638. X    obj_lon = ((double) binfull_in.lon) / 3600000L;
  639. X    obj_mag = ((double) binfull_in.mag) / 1000L;
  640. X    obj_type[0] = binfull_in.tycolb[0];
  641. X    obj_type[1] = binfull_in.tycolb[1];
  642. X    obj_color[0] = binfull_in.tycolb[2];
  643. X    obj_color[1] = binfull_in.tycolb[3];
  644. X    obj_label[0] = binfull_in.tycolb[4];
  645. X    obj_label[1] = binfull_in.tycolb[5];
  646. X    strcpy(obj_constell,con_table[binfull_in.consindx]);
  647. X
  648. X    ptr = name_comment;
  649. X    i = 0;
  650. X    while (*ptr == ' ') ptr++;
  651. X    while (*ptr != ',' && *ptr != '\n' && *ptr)
  652. X      obj_name[i++] = *ptr++;
  653. X    obj_name[i] = '\0';
  654. X    if ((*ptr == ',') && (*++ptr) && name_comment[0]) obj_commnt = ptr;
  655. X    else obj_commnt = "";
  656. X
  657. X    strcpy(fileline, "");
  658. X  } else if (ftype == GSCTYPE) {
  659. X#define Val(ch) (ch - '0')
  660. X    if (!GSC_seeked) {
  661. X      fseek(file, 8640L, 0);
  662. X      GSC_seeked = TRUE;
  663. X      if (fread((char *) id_str, 5, 1, file) != 1) {
  664. X    if (feof(file)) return TRUE;
  665. X    perror("Error reading input file");
  666. X    exit(2);
  667. X      };
  668. X      GSC_ID = Val(id_str[0])*10000 +
  669. X    Val(id_str[1])*1000 +
  670. X    Val(id_str[2])*100 +
  671. X    Val(id_str[3])*10 +
  672. X    Val(id_str[4]);
  673. X    };
  674. X    GSC_skip = FALSE;
  675. X    do {
  676. X      if (id_str[0] == ' ') return TRUE;
  677. X      i = 0;
  678. X      do {
  679. X    if (fread((char *) fileline, 40, 1, file) != 1) {
  680. X      if (feof(file)) return TRUE;
  681. X      perror("Error reading input file");
  682. X      exit(2);
  683. X    };
  684. X    for (j = 0; j < 40; j++) if (fileline[j] == ' ') fileline[j] = '0';
  685. X    /* We care about RA_DEG, DEC_DEG, MAG, MAG_BAND, CLASS, MULTIPLE */
  686. X    /* We read the GSC_ID already to see if it is a continuation */
  687. X    GSC[i].ra_deg = Val(fileline[0]) * 100.0 +
  688. X      Val(fileline[1]) * 10.0 +
  689. X      Val(fileline[2]) +
  690. X      Val(fileline[4]) / 10.0 +
  691. X      Val(fileline[5]) / 100.0 +
  692. X      Val(fileline[6]) / 1000.0 +
  693. X      Val(fileline[7]) / 10000.0 +
  694. X      Val(fileline[8]) / 100000.0;
  695. X    if (fileline[10] == '-')
  696. X      GSC[i].dec_deg = -1 *
  697. X        (Val(fileline[11]) +
  698. X         Val(fileline[13]) / 10.0 +
  699. X         Val(fileline[14]) / 100.0 +
  700. X         Val(fileline[15]) / 1000.0 +
  701. X         Val(fileline[16]) / 10000.0 +
  702. X         Val(fileline[17]) / 100000.0);
  703. X    else
  704. X      GSC[i].dec_deg =  ((fileline[9] == '-') ? -1 : 1) *
  705. X        (Val(fileline[10]) * 10.0 +
  706. X         Val(fileline[11]) +
  707. X         Val(fileline[13]) / 10.0 +
  708. X         Val(fileline[14]) / 100.0 +
  709. X         Val(fileline[15]) / 1000.0 +
  710. X         Val(fileline[16]) / 10000.0 +
  711. X         Val(fileline[17]) / 100000.0);
  712. X    GSC[i].mag = Val(fileline[23]) * 10.0 +
  713. X      Val(fileline[24]) +
  714. X      Val(fileline[26]) / 10.0 +
  715. X      Val(fileline[27]) / 100.0;
  716. X    GSC[i].mag_band = Val(fileline[32])*10 + Val(fileline[33]);
  717. X    GSC[i].class = Val(fileline[34]);
  718. X    i++;
  719. X    if (fread((char *) id_str, 5, 1, file) != 1) {
  720. X      if (!feof(file)) {
  721. X        perror("Error reading input file");
  722. X        exit(2);
  723. X      };
  724. X    };
  725. X    if (!feof(file)) {
  726. X      j = Val(id_str[0])*10000 +
  727. X        Val(id_str[1])*1000 +
  728. X        Val(id_str[2])*100 +
  729. X        Val(id_str[3])*10 +
  730. X        Val(id_str[4]);
  731. X    };
  732. X      } while ((j == GSC_ID) && (!feof(file)) && (id_str[0] != ' '));
  733. X      GSC_nlines = i;
  734. X      GSC_ID = j;
  735. X      /* for now just use first */
  736. X/* There are many stars with class == 3, so we'll ignore class */
  737. X/*      if (GSC[0].class == 0) {*/    /* is a star if class == 0 */
  738. X    obj_lon = GSC[0].ra_deg;
  739. X    obj_lat = GSC[0].dec_deg;
  740. X    obj_mag = GSC[0].mag;
  741. X    obj_type[0] = 'S';
  742. X    obj_type[1] = 'S';
  743. X    obj_color[0] = ' ';
  744. X    obj_color[1] = ' ';
  745. X    obj_label[0] = ' ';
  746. X    obj_label[1] = ' ';
  747. X    obj_constell[0] = ' ';
  748. X    obj_constell[1] = ' ';
  749. X    obj_constell[2] = ' ';
  750. X    obj_name[0] = '\0';
  751. X/*    obj_commnt = &fileline[28];*/
  752. X    obj_commnt = "";
  753. X    fileline[0] = '\0';
  754. X    GSC_skip = FALSE;
  755. X/* Ignoring class seems to be the right thing */
  756. X/*      } else {*/            /* not a star, skip */
  757. X/*    GSC_skip = TRUE;
  758. X      };*/
  759. X    } while (GSC_skip);
  760. X  } else { /* LINEREAD */
  761. X
  762. X/*
  763. X * file formats:
  764. X * new
  765. X064509-1643-14SDA1a CMASirius
  766. X051432-0812015SDB8b ORIRigel
  767. X * old
  768. X064509-1643-146SSSirius
  769. X051432-08120015SSRigel
  770. X */
  771. X
  772. X    fgets(fileline, LINELEN, file);
  773. X    if (feof(file)) return(TRUE);    /* IS AN ERROR or eof */
  774. X    nchars = 0;
  775. X    while (fileline[nchars++]);
  776. X    nchars--;
  777. X    nchars--;
  778. X
  779. X/*
  780. X * sscanf of floats is TOOO slow:
  781. X *     sscanf(fileline, "%2f%2f%2f%c%2f%2f ... );
  782. X * use alternate:
  783. X */
  784. X#define F2(i) (((fileline[i]-'0')*10.0+fileline[i+1]-'0'))
  785. X#define F3(i) (((fileline[i]-'0')*100.0+(fileline[i+1]-'0')*10+fileline[i+2]-'0'))
  786. X#define F4(i) (((fileline[i]-'0')*1000.0+(fileline[i+1]-'0')*100+(fileline[i+2])-'0')*10+fileline[i+3]-'0')
  787. X#define F3M(i) (((fileline[i]-'A'+10.0)*100+(fileline[i+1]-'0')*10+fileline[i+2]-'0'))
  788. X    rah = F2(0);
  789. X    ram = F2(2);
  790. X    ras = F2(4);
  791. X    dld = F2(7);
  792. X    dlm = F2(9);
  793. X/*
  794. X * common code
  795. X */
  796. X#define DLDEGSEC 3600.0
  797. X#define DLMINSEC 60.0
  798. X#define RAHRSSEC 54000.0
  799. X#define RAMINSEC 900.0
  800. X#define RASECSEC 15.0
  801. X
  802. X
  803. X    obj_lon = (RAHRSSEC*rah + RAMINSEC*ram + RASECSEC*ras)/DLDEGSEC;
  804. X    dl = (DLDEGSEC*dld + DLMINSEC*dlm)/DLDEGSEC;
  805. X    obj_lat = (fileline[6]  == '-') ? -dl : dl;
  806. X    
  807. X    /* set unknowns to blanks */
  808. X    obj_color[0] = ' ';
  809. X    obj_color[1] = ' ';
  810. X    obj_color[2] = '\0';
  811. X    obj_label[0] = ' ';
  812. X    obj_label[1] = ' ';
  813. X    obj_label[2] = '\0';
  814. X    obj_constell[0] = ' ';
  815. X    obj_constell[1] = ' ';
  816. X    obj_constell[2] = ' ';
  817. X    obj_constell[3] = '\0';
  818. X    
  819. X    if  (isdigit(fileline[14])) {
  820. X    /*
  821. X     * old reduced Yale catalog
  822. X     */
  823. X      inten = F3(12);
  824. X      if (fileline[11] == '0' || fileline[11] == '+') obj_mag = inten/100.0;
  825. X      else if (fileline[11] == '-') obj_mag = -inten/100.0;
  826. X      else obj_mag = F4(11)/1000.0;    /* new feature for stars >= 10.0 mag */
  827. X      
  828. X      if (nchars > 15) {
  829. X    obj_type[0] = fileline[15];
  830. X    obj_type[1] = fileline[16];
  831. X    ptr = &fileline[MIN(17,nchars)];
  832. X    i = 0;
  833. X    while (*ptr == ' ') ptr++;
  834. X    while (*ptr != ',' && *ptr != '\n' && *ptr)
  835. X      obj_name[i++] = *ptr++;
  836. X    obj_name[i] = '\0';
  837. X    if (*++ptr) obj_commnt = ptr;
  838. X    else obj_commnt = "";
  839. X/* Next 2 lines Not in readfile.c readstar, not needed there */
  840. X    if (obj_commnt[strlen(obj_commnt) -1] == '\n')
  841. X      obj_commnt[strlen(obj_commnt) -1] = '\0';
  842. X      } else {
  843. X    obj_type[0] = obj_type[1] = 'S'; /* Default SS single star */
  844. X    obj_name[0] = '\0';
  845. X    obj_commnt = "";
  846. X      }
  847. X    } else {
  848. X      /*
  849. X       * new reduced Yale catalog
  850. X       */
  851. X      m1 = fileline[11];
  852. X      obj_mag = ((m1 == '-') ? -F2(12)/10.0 :
  853. X         (m1 <= '9') ? F3(11)/100.0 : F3M(11)/100.0);
  854. X      /* let's get Sirius */
  855. X    
  856. X      /*
  857. X       * extract color, label, constellation, name, and comment
  858. X       * Would be faster to just guarentee that the data file is correct
  859. X       */
  860. X      if (nchars > 22) {
  861. X    obj_constell[0] = fileline[20];
  862. X    obj_constell[1] = fileline[21];
  863. X    obj_constell[2] = fileline[22];
  864. X    obj_constell[3] = '\0';
  865. X      }
  866. X      if (nchars > 19) {
  867. X    obj_label[0] = fileline[18];
  868. X    obj_label[1] = fileline[19];
  869. X    obj_label[2] = '\0';
  870. X      }
  871. X      if (nchars > 17) {
  872. X    obj_color[0] = fileline[16]; 
  873. X    obj_color[1] = fileline[17];
  874. X    obj_color[2] = '\0';
  875. X      }
  876. X      if (nchars > 15) {
  877. X    obj_type[0] = fileline[14];
  878. X    obj_type[1] = fileline[15];
  879. X      }
  880. X
  881. X      ptr = &fileline[MIN(23,nchars)];
  882. X      i = 0;
  883. X      while (*ptr == ' ') ptr++;
  884. X      while (*ptr != ',' && *ptr != '\n' && *ptr)
  885. X    obj_name[i++] = *ptr++;
  886. X      obj_name[i] = '\0';
  887. X      if (*++ptr) obj_commnt = ptr;
  888. X      else obj_commnt = "";
  889. X/* Next 2 lines Not in readfile.c readstar, not needed there */
  890. X      if (obj_commnt[strlen(obj_commnt) -1] == '\n')
  891. X    obj_commnt[strlen(obj_commnt) -1] = '\0';
  892. X    }
  893. X  }
  894. X
  895. X  return(FALSE); /* NO error */
  896. X}
  897. X
  898. X
  899. X/* readsif reads standard starchart interchange format files,
  900. X   extracting the same data as readstar, if possible, and loading
  901. X   the same variables */
  902. Xint readsif(file, sepchar)
  903. X     FILE *file;
  904. X     char sepchar;
  905. X{
  906. X  static char inp_line[10*LINELEN];
  907. X  int i;
  908. X  char *cp;
  909. X  char *parsed_line[9];
  910. X  int num_parsed;
  911. X  double ra_h, ra_m, ra_s, de_d, de_m, de_s;
  912. X
  913. X  /* Get line */
  914. X  if (fgets(inp_line, 10*LINELEN, file) == NULL) return TRUE;
  915. X
  916. X  /* Remove newline */
  917. X  inp_line[strlen(inp_line)-1] = '\0';
  918. X
  919. X  /* split line into tokens */
  920. X  for (i = 0; i < 9; i++) parsed_line[i] = "";
  921. X
  922. X  i = 0;
  923. X  cp = inp_line;
  924. X  parsed_line[i++] = cp;
  925. X  while (*cp)
  926. X    if (*cp != sepchar) cp++;
  927. X    else if (i < 9) {
  928. X      *cp++ = '\0';
  929. X      parsed_line[i++] = cp;
  930. X    };
  931. X  num_parsed = i;
  932. X
  933. X  /* parse ra and dec */
  934. X  ra_h = ra_m = ra_s = 0.0;
  935. X  de_d = de_m = de_s = 0.0;
  936. X  sscanf(parsed_line[0], "%lf %lf %lf", &ra_h, &ra_m, &ra_s);
  937. X  i = 0; 
  938. X  while (i < strlen(parsed_line[1])) {
  939. X    if ((parsed_line[1][i] == '+') || (parsed_line[1][i] == '-')) {
  940. X      i++;
  941. X      while ((i < strlen(parsed_line[1])) && (parsed_line[1][i] == ' '))
  942. X    parsed_line[1][i++] = '0';
  943. X    } else i++;
  944. X  };
  945. X  sscanf(parsed_line[1], "%lf %lf %lf", &de_d, &de_m, &de_s);
  946. X
  947. X  /* set obj_ values */
  948. X  obj_lon = ra_h * 15.0 + ra_m / 4.0 + ra_s / (4.0 * 60.0);
  949. X  obj_lat = fabs(de_d) + de_m / 60.0 + de_s / 3600.0;
  950. X
  951. X  /* In order to assign the sign properly if de_d == 0,
  952. X     we must see if there is a negative sign before the first digit */
  953. X  if (de_d < 0.0) obj_lat = -obj_lat;
  954. X  else if (de_d == 0.0) {
  955. X    i = 0;
  956. X    while ((parsed_line[1][i] != '-') && (!isdigit(parsed_line[1][i]))) i++;
  957. X    if (parsed_line[1][i] == '-') obj_lat = -obj_lat;
  958. X  };
  959. X
  960. X  sscanf(parsed_line[2], "%lf", &obj_mag);
  961. X
  962. X  if (sscanf(parsed_line[3], "%2s", obj_type) == EOF) strcpy(obj_type, "SS");
  963. X  if (sscanf(parsed_line[4], "%2s", obj_color) == EOF) strcpy(obj_color, "  ");
  964. X  if (sscanf(parsed_line[5], "%2s", obj_label) == EOF) strcpy(obj_label, "  ");
  965. X  if (sscanf(parsed_line[6], "%3s", obj_constell) == EOF)
  966. X    strcpy(obj_constell, "   ");
  967. X
  968. X  if (!obj_type[1]) obj_type[1] = ' ';
  969. X  if (!obj_color[1]) obj_color[1] = ' ';
  970. X  if (!obj_label[1]) obj_label[1] = ' ';
  971. X  if (!obj_constell[1]) obj_constell[1] = ' ';
  972. X  if (!obj_constell[2]) obj_constell[2] = ' ';
  973. X
  974. X  obj_type[2] = '\0';
  975. X  obj_color[2] = '\0';
  976. X  obj_label[2] = '\0';
  977. X  obj_constell[3] = '\0';
  978. X
  979. X/* Magic for label:
  980. X   type and color should be left justified, constellation is 3 chars if valid,
  981. X   but label could be " X" or "X " with equal validity.
  982. X   If the label field is exactly two characters long including whitespace,
  983. X   and both characters are printable, use it verbatum. */
  984. X  if ((strlen(parsed_line[5]) == 2)  && isprint(parsed_line[5][0]) &&
  985. X       isprint(parsed_line[5][1])) strcpy(obj_label, parsed_line[5]);
  986. X
  987. X  /* Trim whitespace before and after name */
  988. X  while ((*parsed_line[7] == ' ') || (*parsed_line[7] == '\t'))
  989. X    parsed_line[7]++;
  990. X  i = strlen(parsed_line[7]) -1 ;
  991. X  while ((parsed_line[7][i]  == ' ') || (parsed_line[7][i] == '\t'))
  992. X    parsed_line[7][i] = '\0';
  993. X  if (!parsed_line[7][0]) strcpy(obj_name,"");
  994. X  else strcpy(obj_name,parsed_line[7]);
  995. X
  996. X  obj_commnt = parsed_line[8];
  997. X
  998. X  if (!to_consindx(obj_constell)) strcpy(obj_constell,"   ");
  999. X
  1000. X  /* Commas should not appear in name field */
  1001. X  i = 0;
  1002. X  while (obj_name[i])
  1003. X    if (obj_name[i++] == ',')
  1004. X      fprintf(stderr, "Warning: comma in name field:\"%s\"\n", obj_name);
  1005. X
  1006. X  return FALSE;
  1007. X}
  1008. X
  1009. X
  1010. X/* write lineread format */
  1011. Xvoid writelr(outfile)
  1012. X     FILE *outfile;
  1013. X{
  1014. X  int ra_h, ra_m, ra_s;
  1015. X  int de_d, de_m;
  1016. X  char outline[LINELEN];
  1017. X  char dsign;
  1018. X  char mstr[4];
  1019. X  int imag;
  1020. X
  1021. X  if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
  1022. X    fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
  1023. X    obj_lon = 0.0;
  1024. X    obj_mag = 35.0;
  1025. X  };
  1026. X  if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
  1027. X    fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
  1028. X    obj_lat = 0.0;
  1029. X    obj_mag = 35.0;
  1030. X  };
  1031. X  if (obj_mag > 35.0)
  1032. X    fprintf(stderr, "Warning: magnitude out of range:\"%f\"\n", obj_mag);
  1033. X  
  1034. X
  1035. X  ra_h = obj_lon/15.0;
  1036. X  ra_m = ((obj_lon/15.0) - ra_h) * 60 + (0.5 / 60);
  1037. X  ra_s = ((((obj_lon/15.0) - ra_h) * 60) - ra_m) * 60 + 0.5;
  1038. X
  1039. X  if (ra_s >= 60) {ra_s -= 60; ra_m++;};
  1040. X  if (ra_m >= 60) {ra_m -= 60; ra_h++;};
  1041. X
  1042. X
  1043. X  if (obj_lat < 0.0) {
  1044. X    obj_lat = -obj_lat;
  1045. X    dsign = '-';
  1046. X  } else dsign = '+';
  1047. X
  1048. X  de_d = obj_lat;
  1049. X  de_m = (obj_lat - de_d) * 60 + 0.5;
  1050. X
  1051. X  if (de_m >= 60) {de_m -= 60; de_d++;};
  1052. X
  1053. X  imag = fabs(obj_mag);
  1054. X  if (obj_mag <= -10.0)
  1055. X    sprintf(mstr, "-99");
  1056. X  else if (obj_mag < 0.0)
  1057. X    sprintf(mstr, "-%02d", (int) (-obj_mag * 10 + 0.5));
  1058. X  else if (imag >= 10) {
  1059. X    /* Hex+ format for stars dimmer than 9th mag */
  1060. X    sprintf(mstr, "%03d", (int) ((obj_mag - imag) * 100 + 0.5));
  1061. X    mstr[0] = 'A' - 10 + imag;
  1062. X    if (imag > 35)
  1063. X      mstr[0] = 'Z';
  1064. X  } else {
  1065. X    sprintf(mstr, "%03d", (int) (obj_mag * 100 + 0.5));
  1066. X  }
  1067. X
  1068. X  /* Try to trim off excess spaces */
  1069. X  if (!obj_commnt[0] && !obj_name[0] && !strcmp(obj_constell, "   "))
  1070. X    /* can trim constellation */
  1071. X    obj_constell[0] = '\0';
  1072. X
  1073. X  if (!obj_constell[0] && !strcmp(obj_label, "  "))
  1074. X    /* can trim label */
  1075. X    obj_label[0] = '\0';
  1076. X
  1077. X  if (!obj_label[0] && !strcmp(obj_color, "  "))
  1078. X    /* can trim color */
  1079. X    obj_color[0] = '\0';
  1080. X
  1081. X
  1082. X
  1083. X
  1084. X
  1085. X  if (obj_commnt[0])
  1086. X    sprintf(outline, "%02d%02d%02d%c%02d%02d%s%s%s%s%s%s,%s",
  1087. X        ra_h, ra_m, ra_s, dsign, de_d, de_m,
  1088. X        mstr,
  1089. X        obj_type, obj_color, obj_label, obj_constell,
  1090. X        obj_name, obj_commnt);
  1091. X  else
  1092. X    sprintf(outline, "%02d%02d%02d%c%02d%02d%s%s%s%s%s%s",
  1093. X        ra_h, ra_m, ra_s, dsign, de_d, de_m,
  1094. X        mstr,
  1095. X        obj_type, obj_color, obj_label, obj_constell, obj_name);
  1096. X
  1097. X  fprintf(outfile, "%s\n", outline);
  1098. X}
  1099. X
  1100. X
  1101. X/* write binfull format */
  1102. Xvoid wrbinfull(file)
  1103. X     FILE *file;
  1104. X{
  1105. X  int to_consindx();
  1106. X
  1107. X  if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
  1108. X    fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
  1109. X    obj_lon = 0.0;
  1110. X    obj_mag = 35.0;
  1111. X  };
  1112. X  if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
  1113. X    fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
  1114. X    obj_lat = 0.0;
  1115. X    obj_mag = 35.0;
  1116. X  };
  1117. X
  1118. X  strcpy(name_comment, obj_name);
  1119. X  if (obj_commnt[0]) {
  1120. X    strcat(name_comment, ",");
  1121. X    strcat(name_comment, obj_commnt);
  1122. X    if (name_comment[strlen(name_comment)-1] == '\n')
  1123. X      name_comment[strlen(name_comment)-1] = '\0';
  1124. X  }
  1125. X
  1126. X  binfull_out.lat = obj_lat * 3600 * 1000L;
  1127. X  binfull_out.lon = obj_lon * 3600 * 1000L;
  1128. X  binfull_out.mag = obj_mag * 1000L;
  1129. X  binfull_out.tycolb[0] = obj_type[0];
  1130. X  binfull_out.tycolb[1] = obj_type[1];
  1131. X  binfull_out.tycolb[2] = obj_color[0];
  1132. X  binfull_out.tycolb[3] = obj_color[1];
  1133. X  binfull_out.tycolb[4] = obj_label[0];
  1134. X  binfull_out.tycolb[5] = obj_label[1];
  1135. X  binfull_out.consindx = to_consindx(obj_constell);
  1136. X  binfull_out.strlen = strlen(name_comment);
  1137. X
  1138. X  if (fwrite((char *) &binfull_out, sizeof(binfull_out), 1, file) != 1) {
  1139. X    perror("Error writing output file");
  1140. X    exit(2);
  1141. X  }
  1142. X
  1143. X  if (name_comment[0] &&
  1144. X      (fwrite((char *) name_comment, binfull_out.strlen, 1, file) != 1)) {
  1145. X    perror("Error writing output file");
  1146. X    exit(2);
  1147. X  }
  1148. X}
  1149. X
  1150. Xint to_consindx(cons)
  1151. X     char *cons;
  1152. X{
  1153. X  int i;
  1154. X
  1155. X  if (!cons[0]) return 0;
  1156. X
  1157. X  i = -1;
  1158. X  while (con_table[++i][0])
  1159. X    if (!strcmp(cons, con_table[i])) break;
  1160. X
  1161. X  return (con_table[i][0] ? i : 0);
  1162. X}
  1163. X
  1164. X/* write binstar format */
  1165. Xvoid wrbinstar(file)
  1166. X     FILE *file;
  1167. X{
  1168. X  int to_consindx();
  1169. X
  1170. X  if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
  1171. X    fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
  1172. X    obj_lon = 0.0;
  1173. X    obj_mag = 35.0;
  1174. X  };
  1175. X  if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
  1176. X    fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
  1177. X    obj_lat = 0.0;
  1178. X    obj_mag = 35.0;
  1179. X  };
  1180. X
  1181. X  binstar_out.lat = obj_lat * 3600 * 1000L;
  1182. X  binstar_out.lon = obj_lon * 3600 * 1000L;
  1183. X  binstar_out.mag = obj_mag * 1000L;
  1184. X
  1185. X  if (fwrite((char *) &binstar_out, sizeof(binstar_out), 1, file) != 1) {
  1186. X    perror("Error writing output file");
  1187. X    exit(2);
  1188. X  }
  1189. X}
  1190. X
  1191. Xvoid wrbinobj(file)
  1192. X     FILE *file;
  1193. X{
  1194. X  int to_consindx();
  1195. X
  1196. X  if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
  1197. X    fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
  1198. X    obj_lon = 0.0;
  1199. X    obj_mag = 35.0;
  1200. X  };
  1201. X  if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
  1202. X    fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
  1203. X    obj_lat = 0.0;
  1204. X    obj_mag = 35.0;
  1205. X  };
  1206. X
  1207. X  binobj_out.lat = obj_lat * 3600 * 1000L;
  1208. X  binobj_out.lon = obj_lon * 3600 * 1000L;
  1209. X  binobj_out.mag = obj_mag * 1000L;
  1210. X  binobj_out.type[0] = obj_type[0];
  1211. X  binobj_out.type[1] = obj_type[1];
  1212. X
  1213. X  if (fwrite((char *) &binobj_out, sizeof(binobj_out), 1, file) != 1) {
  1214. X    perror("Error writing output file");
  1215. X    exit(2);
  1216. X  }
  1217. X}
  1218. X
  1219. X
  1220. X/* write sif format */
  1221. Xvoid writesif(file, sepchar)
  1222. X     FILE *file;
  1223. X     char sepchar;
  1224. X{
  1225. X  if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
  1226. X    fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
  1227. X    obj_lon = 0.0;
  1228. X    obj_mag = 35.0;
  1229. X  };
  1230. X  if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
  1231. X    fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
  1232. X    obj_lat = 0.0;
  1233. X    obj_mag = 35.0;
  1234. X  };
  1235. X
  1236. X  fprintf(file, "%.10f%c%.10f%c%f%c%s%c%s%c%s%c%3s%c%s%c%s\n",
  1237. X      obj_lon/15.0, sepchar,
  1238. X      obj_lat, sepchar,
  1239. X      obj_mag, sepchar,
  1240. X      obj_type, sepchar,
  1241. X      obj_color, sepchar,
  1242. X      obj_label, sepchar,
  1243. X      obj_constell, sepchar,
  1244. X      obj_name, sepchar,
  1245. X      obj_commnt);
  1246. X}
  1247. X
  1248. X
  1249. X/*  Old precession formula */
  1250. Xdouble M, N;
  1251. Xvoid initxform(ein, eout)
  1252. X     double ein, eout;
  1253. X{
  1254. X  double T;
  1255. X
  1256. X  T = (eout - ein) / 100.0;
  1257. X  M = (1.2812323 + (0.0003879 + 0.0000101 * T) * T) * T;
  1258. X  N = (0.5567530 - (0.0001185 - 0.0000116 * T) * T) * T;
  1259. X}
  1260. X
  1261. Xvoid xform(rin, din, rout, dout)
  1262. X     double rin, din, *rout, *dout;
  1263. X{
  1264. X  double am, dm, a2, d2;
  1265. X
  1266. X/* am = /alpha_m, dm = /delta_m */
  1267. X
  1268. X  am = rin + (M + N * DSIN(rin) * DTAN(din))/2.0;
  1269. X  dm = din + N*DCOS(am)/2.0;
  1270. X  a2 = rin + M + N*DSIN(am)*DTAN(dm);
  1271. X  d2 = din + N * DCOS(am);
  1272. X  
  1273. X  if (a2 >= 360.0) a2 -= 360.0;
  1274. X  if (a2 < 0.0) a2 += 360.0;
  1275. X
  1276. X  *rout = a2;
  1277. X  *dout = d2;
  1278. X}
  1279. X
  1280. X/* Rigorous precession */
  1281. X/* From Astronomical Ephemeris 1989, p. B18 */
  1282. X/*
  1283. Xfrom t_0 to t:
  1284. X
  1285. XA = 
  1286. Xsin(alpha - z_A) cos(delta) = sin(alpha_0 + zeta_A) cos(delta_0);
  1287. XB =
  1288. Xcos(alpha - z_A) cos(delta) = cos(alpha_0 + zeta_A) cos(theta_A) cos(delta_0)
  1289. X                - sin(theta_A) sin(delta_0);
  1290. XC =
  1291. X                 sin(delta) = cos(alpha_0 + zeta_A) sin(theta_A) cos(delta_0)
  1292. X                + cos(theta_A) sin(delta_0);
  1293. X
  1294. Xdelta = asin(C);
  1295. Xalpha = atan2(A/B) + z_A;
  1296. X
  1297. X
  1298. X
  1299. Xfrom t to t_0:
  1300. X
  1301. XA =
  1302. Xsin(alpha_0 + zeta_A) cos(delta_0) = sin(alpha - z_A) cos(delta);
  1303. X
  1304. XB =
  1305. Xcos(alpha_0 + zeta_A) cos(delta_0) = cos(alpha - z_A) cos(theta_A) cos(delta)
  1306. X                + sin(theta_A) sin(delta);
  1307. XC =
  1308. X                      sin(delta_0) = -cos(alpha - z_A) sin(theta_A) cos(delta)
  1309. X                + cos(theta_A) sin(delta)
  1310. X
  1311. Xdelta_0 = asin(C);
  1312. Xalpha_0 = atan2(A,B) - zeta_A;
  1313. X*/
  1314. X
  1315. X
  1316. X
  1317. X/* For reduction with respect to the standard epoch t_0 = J2000.0
  1318. Xzeta_A  = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T
  1319. X   Z_A  = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T
  1320. Xtheta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T
  1321. X
  1322. Xin degrees.
  1323. X
  1324. XT = (jd - 2451545.0)/36525.0;
  1325. X
  1326. Xalpha2000 = alpha_0;
  1327. Xdelta2000 = delta_0;
  1328. X*/
  1329. X
  1330. X
  1331. Xvoid precess_f(from_equinox, to_equinox,
  1332. X         alpha_in, delta_in, alpha_out, delta_out)
  1333. X     double from_equinox, to_equinox,
  1334. X       alpha_in, delta_in, *alpha_out, *delta_out;
  1335. X{
  1336. X  double zeta_A, z_A, theta_A;
  1337. X  double T;
  1338. X  double A, B, C;
  1339. X  double alpha, delta;
  1340. X  double alpha2000, delta2000;
  1341. X  double into_range();
  1342. X
  1343. X
  1344. X  /* From from_equinox to 2000.0 */
  1345. X  if (from_equinox != 2000.0) {
  1346. X    T = (from_equinox - 2000.0)/100.0;
  1347. X    zeta_A  = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
  1348. X    z_A     = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
  1349. X    theta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T;
  1350. X
  1351. X    A = DSIN(alpha_in - z_A) * DCOS(delta_in);
  1352. X    B = DCOS(alpha_in - z_A) * DCOS(theta_A) * DCOS(delta_in)
  1353. X      + DSIN(theta_A) * DSIN(delta_in);
  1354. X    C = -DCOS(alpha_in - z_A) * DSIN(theta_A) * DCOS(delta_in)
  1355. X      + DCOS(theta_A) * DSIN(delta_in);
  1356. X
  1357. X    alpha2000 = into_range(DATAN2(A,B) - zeta_A);
  1358. X    delta2000 = DASIN(C);
  1359. X  } else {
  1360. X    /* should get the same answer, but this could improve accruacy */
  1361. X    alpha2000 = alpha_in;
  1362. X    delta2000 = delta_in;
  1363. X  };
  1364. X
  1365. X
  1366. X  /* From 2000.0 to to_equinox */
  1367. X  if (to_equinox != 2000.0) {
  1368. X    T = (to_equinox - 2000.0)/100.0;
  1369. X    zeta_A  = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
  1370. X    z_A     = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
  1371. X    theta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T;
  1372. X
  1373. X    A = DSIN(alpha2000 + zeta_A) * DCOS(delta2000);
  1374. X    B = DCOS(alpha2000 + zeta_A) * DCOS(theta_A) * DCOS(delta2000)
  1375. X      - DSIN(theta_A) * DSIN(delta2000);
  1376. X    C = DCOS(alpha2000 + zeta_A) * DSIN(theta_A) * DCOS(delta2000)
  1377. X      + DCOS(theta_A) * DSIN(delta2000);
  1378. X
  1379. X    alpha = into_range(DATAN2(A,B) + z_A);
  1380. X    delta = DASIN(C);
  1381. X  } else {
  1382. X    /* should get the same answer, but this could improve accruacy */
  1383. X    alpha = alpha2000;
  1384. X    delta = delta2000;
  1385. X  };
  1386. X
  1387. X  *alpha_out = alpha;
  1388. X  *delta_out = delta;
  1389. X}
  1390. X
  1391. X
  1392. Xdouble into_range(ang)
  1393. X     double ang;
  1394. X{
  1395. X  int i;
  1396. X
  1397. X  while (ang < 0.0) ang += 360.0;
  1398. X  /* Shouldn't be more than once */
  1399. X
  1400. X  i = ang/360.0;
  1401. X
  1402. X  ang = ang - i * 360;
  1403. X
  1404. X  return(ang);
  1405. X}
  1406. X
  1407. X
  1408. END_OF_FILE
  1409. if test 34330 -ne `wc -c <'dataconv/dataconv.c'`; then
  1410.     echo shar: \"'dataconv/dataconv.c'\" unpacked with wrong size!
  1411. fi
  1412. # end of 'dataconv/dataconv.c'
  1413. fi
  1414. echo shar: End of archive 25 \(of 32\).
  1415. cp /dev/null ark25isdone
  1416. MISSING=""
  1417. 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
  1418.     if test ! -f ark${I}isdone ; then
  1419.     MISSING="${MISSING} ${I}"
  1420.     fi
  1421. done
  1422. if test "${MISSING}" = "" ; then
  1423.     echo You have unpacked all 32 archives.
  1424.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1425. else
  1426.     echo You still need to unpack the following archives:
  1427.     echo "        " ${MISSING}
  1428. fi
  1429. ##  End of shell archive.
  1430. exit 0
  1431.  
  1432.