home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume11
/
starchart
/
part25
< prev
next >
Wrap
Text File
|
1990-03-25
|
37KB
|
1,432 lines
Newsgroups: comp.sources.misc
subject: v11i053: starchart 3.2 Part 25/32
from: ccount@ATHENA.MIT.EDU
Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Posting-number: Volume 11, Issue 53
Submitted-by: ccount@ATHENA.MIT.EDU
Archive-name: starchart/part25
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 25 (of 32)."
# Contents: dataconv/dataconv.c
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'dataconv/dataconv.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'dataconv/dataconv.c'\"
else
echo shar: Extracting \"'dataconv/dataconv.c'\" \(34330 characters\)
sed "s/^X//" >'dataconv/dataconv.c' <<'END_OF_FILE'
X/*
X * dataconv.c/precess -- convert between starchart data formats,
X * precess to other equator and equinox.
X * precession based formulae from
X * Astronomical Almanac, 1988, p B19
X *
X * Copyright (c) 1990 by Craig Counterman. All rights reserved.
X *
X * This software may be redistributed freely, not sold.
X * This copyright notice and disclaimer of warranty must remain
X * unchanged.
X *
X * No representation is made about the suitability of this
X * software for any purpose. It is provided "as is" without express or
X * implied warranty, to the extent permitted by applicable law.
X *
X * DISCLAIMER OF WARRANTY
X * ----------------------
X * The author disclaims all warranties with regard to this software to
X * the extent permitted by applicable law, including all implied
X * warranties of merchantability and fitness. In no event shall the
X * author be liable for any special, indirect or consequential damages or
X * any damages whatsoever resulting from loss of use, data or profits,
X * whether in an action of contract, negligence or other tortious action,
X * arising out of or in connection with the use or performance of this
X * software.
X *
X */
X
X
Xstatic char rcsid[]="$Header: dataconv.c,v 2.12 90/02/25 16:13:50 ccount Exp $";
X
X
X
X#include <stdio.h>
X#include <math.h>
X#include <ctype.h>
X
X/* Defines for equinox */
X#define EQLOW 1850.0
X#define EQHI 2100.0
X#define DEFEIN 1950.0
X#define DEFEOUT 2000.0
X
X
X/* other defines */
X#define LINELEN 82
X#define MAX(a,b) ((a)>(b)?(a):(b))
X#define MIN(a,b) ((a)<(b)?(a):(b))
X#define FALSE 0
X#define TRUE 1
X#define DEG_TO_RAD 0.01745329251994329600
X#define RAD_TO_DEG 57.29577951308232
X#define DSIN(x) (sin((x)*DEG_TO_RAD))
X#define DCOS(x) (cos((x)*DEG_TO_RAD))
X#define DTAN(x) (tan((x)*DEG_TO_RAD))
X#define DASIN(x) (asin(x)*RAD_TO_DEG)
X#define DACOS(x) (acos(x)*RAD_TO_DEG)
X#define DATAN(x) (atan(x)*RAD_TO_DEG)
X#define DATAN2(x,y) (atan2(x,y)*RAD_TO_DEG)
X
X/* File types */
X#define LINEREAD 1
X#define INDEXTYPE 2
X#define BINFULL 3
X#define BINOBJ 4
X#define BINSTAR 5
X#define SAOTYPE 6
X#define SIFTYPE 7
X#define GSCTYPE 8
X
X#define SEPCHAR ';'
X
X/* variables for data, filled by readstar and readsif */
Xdouble obj_lat, obj_lon, obj_mag;
Xchar obj_type[] ="SS", obj_color[3], obj_label[3];
Xchar obj_constell[4], obj_name[LINELEN];
Xchar *obj_commnt, fileline[LINELEN];
X
Xchar *usage =
X"%s:\nargs: -i inname intype -o outname outtype\n\t[-sc] [-f from_equinox -t to_equinox]\n";
X
X
Xint tr_type();
Xint readstar();
Xint readsif();
Xvoid writelr();
Xvoid wrbinfull();
Xvoid wrbinstar();
Xvoid wrbinobj();
Xvoid writesif();
Xint to_consindx();
Xvoid initxform(), xform();
X
Xdouble into_range();
Xvoid precess_f();
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X char *inname = "", *outname = "";
X char *intypestr = "", *outtypestr = "";
X FILE *infile, *outfile;
X int intype, outtype;
X char sepchar = SEPCHAR;
X int i;
X double ein=0.0, eout=0.0, ra_out, de_out;
X int precess = FALSE;
X
X if ((argc < 7)) {
X fprintf(stderr, usage, argv[0]);
X exit(1);
X }
X
X i = 0;
X while (i < argc)
X if (argv[i][0] != '-') i++;
X else switch (argv[i][1]) {
X case 'f':
X ein=atof(argv[i+1]);
X precess = TRUE;
X i += 2;
X break;
X case 't':
X eout=atof(argv[i+1]);
X precess = TRUE;
X i += 2;
X break;
X case 'i':
X inname = argv[i+1];
X intypestr = argv[i+2];
X if (!(intype = tr_type(argv[i+2]))) {
X fprintf(stderr, usage, argv[0]);
X fprintf(stderr, "Invalid intype %s\n", argv[i+2]);
X exit(2);
X }
X i += 3;
X break;
X case 'o':
X outname = argv[i+1];
X outtypestr = argv[i+2];
X if (!(outtype = tr_type(argv[i+2]))) {
X fprintf(stderr, usage, argv[0]);
X fprintf(stderr, "Invalid outtype %s\n", argv[i+2]);
X exit(3);
X }
X if (outtype == GSCTYPE) {
X fprintf(stderr, "%s: cannot write gsc format files.\n", argv[0]);
X exit(3);
X }
X i += 3;
X break;
X case 's':
X if (argv[i][2]) sepchar = argv[i][2];
X i++;
X break;
X default:
X fprintf(stderr, usage, argv[0]);
X exit(4);
X }
X
X if (precess &&
X ((ein < EQLOW) || (ein > EQHI) || (eout < EQLOW) || (eout > EQHI))) {
X fprintf(stderr, usage, argv[0]);
X if ((ein > 0.0) || (eout > 0.0))
X fprintf(stderr, "equinox not in range [%.1f..%.1f]\n", EQLOW, EQHI);
X exit(5);
X }
X
X
X#ifdef ATARI_ST
X if ((infile = fopen(inname, (intype == LINEREAD)?"r":"rb")) == NULL) {
X fprintf(stderr, "%s: Can't open input file %s\n", argv[0], inname);
X exit(6);
X }
X
X if ((outfile = fopen(outname, "wb")) == NULL) {
X fprintf(stderr, "%s: Can't open output file %s\n", argv[0], outname);
X exit(7);
X }
X#else
X if ((infile = fopen(inname, "r")) == NULL) {
X fprintf(stderr, "%s: Can't open input file %s\n", argv[0], inname);
X exit(6);
X }
X
X if ((outfile = fopen(outname, "w")) == NULL) {
X fprintf(stderr, "%s: Can't open output file %s\n", argv[0], outname);
X exit(7);
X }
X#endif
X
X
X fprintf(stderr,
X "%s:\n converting %s format file %s\n to %s format file %s\n",
X argv[0], intypestr, inname, outtypestr, outname);
X if ((intype == SIFTYPE) || (outtype == SIFTYPE))
X fprintf(stderr, "Separation character %c\n", sepchar);
X
X if (precess)
X fprintf(stderr, "Precessing from equinox %.3f to %.3f\n",
X ein, eout);
X
X
X /* SIF must be read with readsif
X All others should be read with readstar
X */
X if (precess) {
X if (intype == SIFTYPE)
X switch (outtype) {
X case LINEREAD:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X writelr(outfile);
X }
X break;
X case BINFULL:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X wrbinfull(outfile);
X }
X break;
X case BINOBJ:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X wrbinobj(outfile);
X }
X break;
X case BINSTAR:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X wrbinstar(outfile);
X }
X break;
X }
X else /* Not SIF in */
X switch (outtype) {
X case LINEREAD:
X for (;;) {
X if (readstar(infile, intype)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X writelr(outfile);
X }
X break;
X case BINFULL:
X for (;;) {
X if (readstar(infile, intype)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X wrbinfull(outfile);
X }
X break;
X case BINOBJ:
X for (;;) {
X if (readstar(infile, intype)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X wrbinobj(outfile);
X }
X break;
X case BINSTAR:
X for (;;) {
X if (readstar(infile, intype)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X wrbinstar(outfile);
X }
X break;
X case SIFTYPE:
X for (;;) {
X if (readstar(infile, intype)) break;
X precess_f(ein, eout, obj_lon, obj_lat, &ra_out, &de_out);
X obj_lon = ra_out;
X obj_lat = de_out;
X writesif(outfile, sepchar);
X }
X break;
X }
X } else { /* not precess */
X if (intype == SIFTYPE)
X switch (outtype) {
X case LINEREAD:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X writelr(outfile);
X }
X break;
X case BINFULL:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X wrbinfull(outfile);
X }
X break;
X case BINOBJ:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X wrbinobj(outfile);
X }
X break;
X case BINSTAR:
X for (;;) {
X if (readsif(infile, sepchar)) break;
X wrbinstar(outfile);
X }
X break;
X }
X else /* Not SIF in */
X switch (outtype) {
X case LINEREAD:
X for (;;) {
X if (readstar(infile, intype)) break;
X writelr(outfile);
X }
X break;
X case BINFULL:
X for (;;) {
X if (readstar(infile, intype)) break;
X wrbinfull(outfile);
X }
X break;
X case BINOBJ:
X for (;;) {
X if (readstar(infile, intype)) break;
X wrbinobj(outfile);
X }
X break;
X case BINSTAR:
X for (;;) {
X if (readstar(infile, intype)) break;
X wrbinstar(outfile);
X }
X break;
X case SIFTYPE:
X for (;;) {
X if (readstar(infile, intype)) break;
X writesif(outfile, sepchar);
X }
X break;
X }
X }
X
X exit(0);
X}
X
X
X
X
X
Xint tr_type(s)
X char *s;
X{
X int i;
X
X for (i = 0; s[i]; i++)
X if (isupper(s[i]))
X s[i] = tolower(s[i]);
X
X if(!strcmp(s, "lineread")) return LINEREAD;
X/* else if (!strcmp(s, "indextype")) return INDEXTYPE;*/
X else if (!strcmp(s, "binfull")) return BINFULL;
X else if (!strcmp(s, "binobj")) return BINOBJ;
X else if (!strcmp(s, "binstar")) return BINSTAR;
X else if (!strcmp(s, "sif")) return SIFTYPE;
X else if (!strcmp(s, "gsc")) return GSCTYPE;
X/* else if (!strcmp(s, "saoformat")) return SAOFORMAT;*/
X else return 0;
X}
X
X
X/* constellation abbreviations */
Xchar *con_table[] = {
X " ",
X "AND",
X "ANT",
X "APS",
X "AQL",
X "AQR",
X "ARA",
X "ARI",
X "AUR",
X "BOO",
X "CAE",
X "CAM",
X "CAP",
X "CAR",
X "CAS",
X "CEN",
X "CEP",
X "CET",
X "CHA",
X "CIR",
X "CMA",
X "CMI",
X "CNC",
X "COL",
X "COM",
X "CRA",
X "CRB",
X "CRT",
X "CRU",
X "CRV",
X "CVN",
X "CYG",
X "DEL",
X "DOR",
X "DRA",
X "EQU",
X "ERI",
X "FOR",
X "GEM",
X "GRU",
X "HER",
X "HOR",
X "HYA",
X "HYI",
X "IND",
X "LAC",
X "LEO",
X "LEP",
X "LIB",
X "LMI",
X "LUP",
X "LYN",
X "LYR",
X "MEN",
X "MIC",
X "MON",
X "MUS",
X "NOR",
X "OCT",
X "OPH",
X "ORI",
X "PAV",
X "PEG",
X "PER",
X "PHE",
X "PIC",
X "PSA",
X "PSC",
X "PUP",
X "PYX",
X "RET",
X "SCL",
X "SCO",
X "SCT",
X "SER",
X "SEX",
X "SGE",
X "SGR",
X "TAU",
X "TEL",
X "TRA",
X "TRI",
X "TUC",
X "UMA",
X "UMI",
X "VEL",
X "VIR",
X "VOL",
X "VUL",
X ""
X };
X
X
X/* typedefs for exact sizes of int */
Xtypedef char int_8;
Xtypedef short int int_16;
Xtypedef long int int_32;
X
X/* BINFULL structure */
Xstruct bfull_struct {
X int_32 lat; /* RA in seconds * 1000 */
X int_32 lon; /* Dec in seconds * 1000 */
X int_16 mag; /* Mag * 1000 */
X char tycolb[6]; /* Type, color, label fields */
X int_8 consindx; /* Index number of constellation */
X int_16 strlen; /* length of name and comment field */
X} binfull_in, binfull_out;
X
Xchar name_comment[LINELEN];
X
X/* BINOBJ structure */
Xstruct bobj_struct {
X int_32 lat; /* RA in seconds * 1000 */
X int_32 lon; /* Dec in seconds * 1000 */
X int_16 mag; /* Mag * 1000 */
X char type[2]; /* e.g. 'SD', 'CO' */
X} binobj_in, binobj_out;
X
X/* BINSTAR structure */
Xstruct bstar_struct {
X int_32 lat; /* RA in seconds * 1000 */
X int_32 lon; /* Dec in seconds * 1000 */
X int_16 mag; /* Mag * 1000 */
X} binstar_in, binstar_out;
X
X
X/* readstar reads from the file the information for one object, and
X loads the following variables:
Xdouble obj_lat, obj_lon, obj_mag;
Xchar obj_type[] ="SS", obj_color[3], obj_label[3];
Xchar obj_constell[4], obj_name[LINELEN];
Xchar *obj_commnt, fileline[LINELEN];
X
Xonly lat, lon, and mag are required. type should default to 'SS',
Xcolor, label, constell default to " ", and the rest default to ""
X*/
Xint readstar(file, ftype)
X FILE *file;
X int ftype;
X{
X char *ptr;
X double rah, ram, ras, dld, dlm, dl, inten;
X int i, j;
X int nchars;
X char m1;
X static int GSC_seeked = FALSE;
X static int GSC_skip = FALSE;
X struct {
X double ra_deg, dec_deg, mag;
X int mag_band, class;
X } GSC[10];
X int GSC_nlines;
X static int GSC_ID = 0;
X char id_str[5];
X
X if ((ftype != LINEREAD) && (ftype != BINFULL)
X && (ftype != BINOBJ) && (ftype != BINSTAR) && (ftype != GSCTYPE))
X return (TRUE);
X /* only LINEREAD, BINFULL, BINOBJ and BINSTAR and GSCTYPE
X supported at this time */
X
X if (ftype == BINSTAR) {
X if (fread((char *) &binstar_in, sizeof(binstar_in), 1, file) != 1) {
X if (feof(file)) return TRUE;
X perror("Error reading input file");
X exit(2);
X }
X
X obj_lat = ((double) binstar_in.lat) / 3600000L;
X obj_lon = ((double) binstar_in.lon) / 3600000L;
X obj_mag = ((double) binstar_in.mag) / 1000L;
X obj_type[0] = 'S';
X obj_type[1] = 'S';
X obj_color[0] = ' ';
X obj_color[1] = ' ';
X obj_label[0] = ' ';
X obj_label[1] = ' ';
X obj_constell[0] = ' ';
X obj_constell[1] = ' ';
X obj_constell[2] = ' ';
X obj_name[0] = '\0';
X obj_commnt = "";
X
X strcpy(fileline, "");
X } else if (ftype == BINOBJ) {
X if (fread((char *) &binobj_in, sizeof(binobj_in), 1, file) != 1) {
X if (feof(file)) return TRUE;
X perror("Error reading input file");
X exit(2);
X }
X
X obj_lat = ((double) binobj_in.lat) / 3600000L;
X obj_lon = ((double) binobj_in.lon) / 3600000L;
X obj_mag = ((double) binobj_in.mag) / 1000L;
X obj_type[0] = binobj_in.type[0];
X obj_type[1] = binobj_in.type[1];
X obj_color[0] = ' ';
X obj_color[1] = ' ';
X obj_label[0] = ' ';
X obj_label[1] = ' ';
X obj_constell[0] = ' ';
X obj_constell[1] = ' ';
X obj_constell[2] = ' ';
X obj_name[0] = '\0';
X obj_commnt = "";
X
X strcpy(fileline, "");
X } else if (ftype == BINFULL) {
X if (fread((char *) &binfull_in, sizeof(binfull_in), 1, file) != 1) {
X if (feof(file)) return TRUE;
X perror("Error reading input file");
X exit(2);
X }
X
X if (binfull_in.strlen == 0)
X strcpy(name_comment, "");
X else {
X if (fread((char *) name_comment, binfull_in.strlen, 1, file) != 1) {
X perror("Error reading input file");
X exit(2);
X }
X name_comment[binfull_in.strlen] = '\0';
X }
X
X obj_lat = ((double) binfull_in.lat) / 3600000L;
X obj_lon = ((double) binfull_in.lon) / 3600000L;
X obj_mag = ((double) binfull_in.mag) / 1000L;
X obj_type[0] = binfull_in.tycolb[0];
X obj_type[1] = binfull_in.tycolb[1];
X obj_color[0] = binfull_in.tycolb[2];
X obj_color[1] = binfull_in.tycolb[3];
X obj_label[0] = binfull_in.tycolb[4];
X obj_label[1] = binfull_in.tycolb[5];
X strcpy(obj_constell,con_table[binfull_in.consindx]);
X
X ptr = name_comment;
X i = 0;
X while (*ptr == ' ') ptr++;
X while (*ptr != ',' && *ptr != '\n' && *ptr)
X obj_name[i++] = *ptr++;
X obj_name[i] = '\0';
X if ((*ptr == ',') && (*++ptr) && name_comment[0]) obj_commnt = ptr;
X else obj_commnt = "";
X
X strcpy(fileline, "");
X } else if (ftype == GSCTYPE) {
X#define Val(ch) (ch - '0')
X if (!GSC_seeked) {
X fseek(file, 8640L, 0);
X GSC_seeked = TRUE;
X if (fread((char *) id_str, 5, 1, file) != 1) {
X if (feof(file)) return TRUE;
X perror("Error reading input file");
X exit(2);
X };
X GSC_ID = Val(id_str[0])*10000 +
X Val(id_str[1])*1000 +
X Val(id_str[2])*100 +
X Val(id_str[3])*10 +
X Val(id_str[4]);
X };
X GSC_skip = FALSE;
X do {
X if (id_str[0] == ' ') return TRUE;
X i = 0;
X do {
X if (fread((char *) fileline, 40, 1, file) != 1) {
X if (feof(file)) return TRUE;
X perror("Error reading input file");
X exit(2);
X };
X for (j = 0; j < 40; j++) if (fileline[j] == ' ') fileline[j] = '0';
X /* We care about RA_DEG, DEC_DEG, MAG, MAG_BAND, CLASS, MULTIPLE */
X /* We read the GSC_ID already to see if it is a continuation */
X GSC[i].ra_deg = Val(fileline[0]) * 100.0 +
X Val(fileline[1]) * 10.0 +
X Val(fileline[2]) +
X Val(fileline[4]) / 10.0 +
X Val(fileline[5]) / 100.0 +
X Val(fileline[6]) / 1000.0 +
X Val(fileline[7]) / 10000.0 +
X Val(fileline[8]) / 100000.0;
X if (fileline[10] == '-')
X GSC[i].dec_deg = -1 *
X (Val(fileline[11]) +
X Val(fileline[13]) / 10.0 +
X Val(fileline[14]) / 100.0 +
X Val(fileline[15]) / 1000.0 +
X Val(fileline[16]) / 10000.0 +
X Val(fileline[17]) / 100000.0);
X else
X GSC[i].dec_deg = ((fileline[9] == '-') ? -1 : 1) *
X (Val(fileline[10]) * 10.0 +
X Val(fileline[11]) +
X Val(fileline[13]) / 10.0 +
X Val(fileline[14]) / 100.0 +
X Val(fileline[15]) / 1000.0 +
X Val(fileline[16]) / 10000.0 +
X Val(fileline[17]) / 100000.0);
X GSC[i].mag = Val(fileline[23]) * 10.0 +
X Val(fileline[24]) +
X Val(fileline[26]) / 10.0 +
X Val(fileline[27]) / 100.0;
X GSC[i].mag_band = Val(fileline[32])*10 + Val(fileline[33]);
X GSC[i].class = Val(fileline[34]);
X i++;
X if (fread((char *) id_str, 5, 1, file) != 1) {
X if (!feof(file)) {
X perror("Error reading input file");
X exit(2);
X };
X };
X if (!feof(file)) {
X j = Val(id_str[0])*10000 +
X Val(id_str[1])*1000 +
X Val(id_str[2])*100 +
X Val(id_str[3])*10 +
X Val(id_str[4]);
X };
X } while ((j == GSC_ID) && (!feof(file)) && (id_str[0] != ' '));
X GSC_nlines = i;
X GSC_ID = j;
X /* for now just use first */
X/* There are many stars with class == 3, so we'll ignore class */
X/* if (GSC[0].class == 0) {*/ /* is a star if class == 0 */
X obj_lon = GSC[0].ra_deg;
X obj_lat = GSC[0].dec_deg;
X obj_mag = GSC[0].mag;
X obj_type[0] = 'S';
X obj_type[1] = 'S';
X obj_color[0] = ' ';
X obj_color[1] = ' ';
X obj_label[0] = ' ';
X obj_label[1] = ' ';
X obj_constell[0] = ' ';
X obj_constell[1] = ' ';
X obj_constell[2] = ' ';
X obj_name[0] = '\0';
X/* obj_commnt = &fileline[28];*/
X obj_commnt = "";
X fileline[0] = '\0';
X GSC_skip = FALSE;
X/* Ignoring class seems to be the right thing */
X/* } else {*/ /* not a star, skip */
X/* GSC_skip = TRUE;
X };*/
X } while (GSC_skip);
X } else { /* LINEREAD */
X
X/*
X * file formats:
X * new
X064509-1643-14SDA1a CMASirius
X051432-0812015SDB8b ORIRigel
X * old
X064509-1643-146SSSirius
X051432-08120015SSRigel
X */
X
X fgets(fileline, LINELEN, file);
X if (feof(file)) return(TRUE); /* IS AN ERROR or eof */
X nchars = 0;
X while (fileline[nchars++]);
X nchars--;
X nchars--;
X
X/*
X * sscanf of floats is TOOO slow:
X * sscanf(fileline, "%2f%2f%2f%c%2f%2f ... );
X * use alternate:
X */
X#define F2(i) (((fileline[i]-'0')*10.0+fileline[i+1]-'0'))
X#define F3(i) (((fileline[i]-'0')*100.0+(fileline[i+1]-'0')*10+fileline[i+2]-'0'))
X#define F4(i) (((fileline[i]-'0')*1000.0+(fileline[i+1]-'0')*100+(fileline[i+2])-'0')*10+fileline[i+3]-'0')
X#define F3M(i) (((fileline[i]-'A'+10.0)*100+(fileline[i+1]-'0')*10+fileline[i+2]-'0'))
X rah = F2(0);
X ram = F2(2);
X ras = F2(4);
X dld = F2(7);
X dlm = F2(9);
X/*
X * common code
X */
X#define DLDEGSEC 3600.0
X#define DLMINSEC 60.0
X#define RAHRSSEC 54000.0
X#define RAMINSEC 900.0
X#define RASECSEC 15.0
X
X
X obj_lon = (RAHRSSEC*rah + RAMINSEC*ram + RASECSEC*ras)/DLDEGSEC;
X dl = (DLDEGSEC*dld + DLMINSEC*dlm)/DLDEGSEC;
X obj_lat = (fileline[6] == '-') ? -dl : dl;
X
X /* set unknowns to blanks */
X obj_color[0] = ' ';
X obj_color[1] = ' ';
X obj_color[2] = '\0';
X obj_label[0] = ' ';
X obj_label[1] = ' ';
X obj_label[2] = '\0';
X obj_constell[0] = ' ';
X obj_constell[1] = ' ';
X obj_constell[2] = ' ';
X obj_constell[3] = '\0';
X
X if (isdigit(fileline[14])) {
X /*
X * old reduced Yale catalog
X */
X inten = F3(12);
X if (fileline[11] == '0' || fileline[11] == '+') obj_mag = inten/100.0;
X else if (fileline[11] == '-') obj_mag = -inten/100.0;
X else obj_mag = F4(11)/1000.0; /* new feature for stars >= 10.0 mag */
X
X if (nchars > 15) {
X obj_type[0] = fileline[15];
X obj_type[1] = fileline[16];
X ptr = &fileline[MIN(17,nchars)];
X i = 0;
X while (*ptr == ' ') ptr++;
X while (*ptr != ',' && *ptr != '\n' && *ptr)
X obj_name[i++] = *ptr++;
X obj_name[i] = '\0';
X if (*++ptr) obj_commnt = ptr;
X else obj_commnt = "";
X/* Next 2 lines Not in readfile.c readstar, not needed there */
X if (obj_commnt[strlen(obj_commnt) -1] == '\n')
X obj_commnt[strlen(obj_commnt) -1] = '\0';
X } else {
X obj_type[0] = obj_type[1] = 'S'; /* Default SS single star */
X obj_name[0] = '\0';
X obj_commnt = "";
X }
X } else {
X /*
X * new reduced Yale catalog
X */
X m1 = fileline[11];
X obj_mag = ((m1 == '-') ? -F2(12)/10.0 :
X (m1 <= '9') ? F3(11)/100.0 : F3M(11)/100.0);
X /* let's get Sirius */
X
X /*
X * extract color, label, constellation, name, and comment
X * Would be faster to just guarentee that the data file is correct
X */
X if (nchars > 22) {
X obj_constell[0] = fileline[20];
X obj_constell[1] = fileline[21];
X obj_constell[2] = fileline[22];
X obj_constell[3] = '\0';
X }
X if (nchars > 19) {
X obj_label[0] = fileline[18];
X obj_label[1] = fileline[19];
X obj_label[2] = '\0';
X }
X if (nchars > 17) {
X obj_color[0] = fileline[16];
X obj_color[1] = fileline[17];
X obj_color[2] = '\0';
X }
X if (nchars > 15) {
X obj_type[0] = fileline[14];
X obj_type[1] = fileline[15];
X }
X
X ptr = &fileline[MIN(23,nchars)];
X i = 0;
X while (*ptr == ' ') ptr++;
X while (*ptr != ',' && *ptr != '\n' && *ptr)
X obj_name[i++] = *ptr++;
X obj_name[i] = '\0';
X if (*++ptr) obj_commnt = ptr;
X else obj_commnt = "";
X/* Next 2 lines Not in readfile.c readstar, not needed there */
X if (obj_commnt[strlen(obj_commnt) -1] == '\n')
X obj_commnt[strlen(obj_commnt) -1] = '\0';
X }
X }
X
X return(FALSE); /* NO error */
X}
X
X
X/* readsif reads standard starchart interchange format files,
X extracting the same data as readstar, if possible, and loading
X the same variables */
Xint readsif(file, sepchar)
X FILE *file;
X char sepchar;
X{
X static char inp_line[10*LINELEN];
X int i;
X char *cp;
X char *parsed_line[9];
X int num_parsed;
X double ra_h, ra_m, ra_s, de_d, de_m, de_s;
X
X /* Get line */
X if (fgets(inp_line, 10*LINELEN, file) == NULL) return TRUE;
X
X /* Remove newline */
X inp_line[strlen(inp_line)-1] = '\0';
X
X /* split line into tokens */
X for (i = 0; i < 9; i++) parsed_line[i] = "";
X
X i = 0;
X cp = inp_line;
X parsed_line[i++] = cp;
X while (*cp)
X if (*cp != sepchar) cp++;
X else if (i < 9) {
X *cp++ = '\0';
X parsed_line[i++] = cp;
X };
X num_parsed = i;
X
X /* parse ra and dec */
X ra_h = ra_m = ra_s = 0.0;
X de_d = de_m = de_s = 0.0;
X sscanf(parsed_line[0], "%lf %lf %lf", &ra_h, &ra_m, &ra_s);
X i = 0;
X while (i < strlen(parsed_line[1])) {
X if ((parsed_line[1][i] == '+') || (parsed_line[1][i] == '-')) {
X i++;
X while ((i < strlen(parsed_line[1])) && (parsed_line[1][i] == ' '))
X parsed_line[1][i++] = '0';
X } else i++;
X };
X sscanf(parsed_line[1], "%lf %lf %lf", &de_d, &de_m, &de_s);
X
X /* set obj_ values */
X obj_lon = ra_h * 15.0 + ra_m / 4.0 + ra_s / (4.0 * 60.0);
X obj_lat = fabs(de_d) + de_m / 60.0 + de_s / 3600.0;
X
X /* In order to assign the sign properly if de_d == 0,
X we must see if there is a negative sign before the first digit */
X if (de_d < 0.0) obj_lat = -obj_lat;
X else if (de_d == 0.0) {
X i = 0;
X while ((parsed_line[1][i] != '-') && (!isdigit(parsed_line[1][i]))) i++;
X if (parsed_line[1][i] == '-') obj_lat = -obj_lat;
X };
X
X sscanf(parsed_line[2], "%lf", &obj_mag);
X
X if (sscanf(parsed_line[3], "%2s", obj_type) == EOF) strcpy(obj_type, "SS");
X if (sscanf(parsed_line[4], "%2s", obj_color) == EOF) strcpy(obj_color, " ");
X if (sscanf(parsed_line[5], "%2s", obj_label) == EOF) strcpy(obj_label, " ");
X if (sscanf(parsed_line[6], "%3s", obj_constell) == EOF)
X strcpy(obj_constell, " ");
X
X if (!obj_type[1]) obj_type[1] = ' ';
X if (!obj_color[1]) obj_color[1] = ' ';
X if (!obj_label[1]) obj_label[1] = ' ';
X if (!obj_constell[1]) obj_constell[1] = ' ';
X if (!obj_constell[2]) obj_constell[2] = ' ';
X
X obj_type[2] = '\0';
X obj_color[2] = '\0';
X obj_label[2] = '\0';
X obj_constell[3] = '\0';
X
X/* Magic for label:
X type and color should be left justified, constellation is 3 chars if valid,
X but label could be " X" or "X " with equal validity.
X If the label field is exactly two characters long including whitespace,
X and both characters are printable, use it verbatum. */
X if ((strlen(parsed_line[5]) == 2) && isprint(parsed_line[5][0]) &&
X isprint(parsed_line[5][1])) strcpy(obj_label, parsed_line[5]);
X
X /* Trim whitespace before and after name */
X while ((*parsed_line[7] == ' ') || (*parsed_line[7] == '\t'))
X parsed_line[7]++;
X i = strlen(parsed_line[7]) -1 ;
X while ((parsed_line[7][i] == ' ') || (parsed_line[7][i] == '\t'))
X parsed_line[7][i] = '\0';
X if (!parsed_line[7][0]) strcpy(obj_name,"");
X else strcpy(obj_name,parsed_line[7]);
X
X obj_commnt = parsed_line[8];
X
X if (!to_consindx(obj_constell)) strcpy(obj_constell," ");
X
X /* Commas should not appear in name field */
X i = 0;
X while (obj_name[i])
X if (obj_name[i++] == ',')
X fprintf(stderr, "Warning: comma in name field:\"%s\"\n", obj_name);
X
X return FALSE;
X}
X
X
X/* write lineread format */
Xvoid writelr(outfile)
X FILE *outfile;
X{
X int ra_h, ra_m, ra_s;
X int de_d, de_m;
X char outline[LINELEN];
X char dsign;
X char mstr[4];
X int imag;
X
X if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
X fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
X obj_lon = 0.0;
X obj_mag = 35.0;
X };
X if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
X fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
X obj_lat = 0.0;
X obj_mag = 35.0;
X };
X if (obj_mag > 35.0)
X fprintf(stderr, "Warning: magnitude out of range:\"%f\"\n", obj_mag);
X
X
X ra_h = obj_lon/15.0;
X ra_m = ((obj_lon/15.0) - ra_h) * 60 + (0.5 / 60);
X ra_s = ((((obj_lon/15.0) - ra_h) * 60) - ra_m) * 60 + 0.5;
X
X if (ra_s >= 60) {ra_s -= 60; ra_m++;};
X if (ra_m >= 60) {ra_m -= 60; ra_h++;};
X
X
X if (obj_lat < 0.0) {
X obj_lat = -obj_lat;
X dsign = '-';
X } else dsign = '+';
X
X de_d = obj_lat;
X de_m = (obj_lat - de_d) * 60 + 0.5;
X
X if (de_m >= 60) {de_m -= 60; de_d++;};
X
X imag = fabs(obj_mag);
X if (obj_mag <= -10.0)
X sprintf(mstr, "-99");
X else if (obj_mag < 0.0)
X sprintf(mstr, "-%02d", (int) (-obj_mag * 10 + 0.5));
X else if (imag >= 10) {
X /* Hex+ format for stars dimmer than 9th mag */
X sprintf(mstr, "%03d", (int) ((obj_mag - imag) * 100 + 0.5));
X mstr[0] = 'A' - 10 + imag;
X if (imag > 35)
X mstr[0] = 'Z';
X } else {
X sprintf(mstr, "%03d", (int) (obj_mag * 100 + 0.5));
X }
X
X /* Try to trim off excess spaces */
X if (!obj_commnt[0] && !obj_name[0] && !strcmp(obj_constell, " "))
X /* can trim constellation */
X obj_constell[0] = '\0';
X
X if (!obj_constell[0] && !strcmp(obj_label, " "))
X /* can trim label */
X obj_label[0] = '\0';
X
X if (!obj_label[0] && !strcmp(obj_color, " "))
X /* can trim color */
X obj_color[0] = '\0';
X
X
X
X
X
X if (obj_commnt[0])
X sprintf(outline, "%02d%02d%02d%c%02d%02d%s%s%s%s%s%s,%s",
X ra_h, ra_m, ra_s, dsign, de_d, de_m,
X mstr,
X obj_type, obj_color, obj_label, obj_constell,
X obj_name, obj_commnt);
X else
X sprintf(outline, "%02d%02d%02d%c%02d%02d%s%s%s%s%s%s",
X ra_h, ra_m, ra_s, dsign, de_d, de_m,
X mstr,
X obj_type, obj_color, obj_label, obj_constell, obj_name);
X
X fprintf(outfile, "%s\n", outline);
X}
X
X
X/* write binfull format */
Xvoid wrbinfull(file)
X FILE *file;
X{
X int to_consindx();
X
X if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
X fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
X obj_lon = 0.0;
X obj_mag = 35.0;
X };
X if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
X fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
X obj_lat = 0.0;
X obj_mag = 35.0;
X };
X
X strcpy(name_comment, obj_name);
X if (obj_commnt[0]) {
X strcat(name_comment, ",");
X strcat(name_comment, obj_commnt);
X if (name_comment[strlen(name_comment)-1] == '\n')
X name_comment[strlen(name_comment)-1] = '\0';
X }
X
X binfull_out.lat = obj_lat * 3600 * 1000L;
X binfull_out.lon = obj_lon * 3600 * 1000L;
X binfull_out.mag = obj_mag * 1000L;
X binfull_out.tycolb[0] = obj_type[0];
X binfull_out.tycolb[1] = obj_type[1];
X binfull_out.tycolb[2] = obj_color[0];
X binfull_out.tycolb[3] = obj_color[1];
X binfull_out.tycolb[4] = obj_label[0];
X binfull_out.tycolb[5] = obj_label[1];
X binfull_out.consindx = to_consindx(obj_constell);
X binfull_out.strlen = strlen(name_comment);
X
X if (fwrite((char *) &binfull_out, sizeof(binfull_out), 1, file) != 1) {
X perror("Error writing output file");
X exit(2);
X }
X
X if (name_comment[0] &&
X (fwrite((char *) name_comment, binfull_out.strlen, 1, file) != 1)) {
X perror("Error writing output file");
X exit(2);
X }
X}
X
Xint to_consindx(cons)
X char *cons;
X{
X int i;
X
X if (!cons[0]) return 0;
X
X i = -1;
X while (con_table[++i][0])
X if (!strcmp(cons, con_table[i])) break;
X
X return (con_table[i][0] ? i : 0);
X}
X
X/* write binstar format */
Xvoid wrbinstar(file)
X FILE *file;
X{
X int to_consindx();
X
X if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
X fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
X obj_lon = 0.0;
X obj_mag = 35.0;
X };
X if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
X fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
X obj_lat = 0.0;
X obj_mag = 35.0;
X };
X
X binstar_out.lat = obj_lat * 3600 * 1000L;
X binstar_out.lon = obj_lon * 3600 * 1000L;
X binstar_out.mag = obj_mag * 1000L;
X
X if (fwrite((char *) &binstar_out, sizeof(binstar_out), 1, file) != 1) {
X perror("Error writing output file");
X exit(2);
X }
X}
X
Xvoid wrbinobj(file)
X FILE *file;
X{
X int to_consindx();
X
X if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
X fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
X obj_lon = 0.0;
X obj_mag = 35.0;
X };
X if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
X fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
X obj_lat = 0.0;
X obj_mag = 35.0;
X };
X
X binobj_out.lat = obj_lat * 3600 * 1000L;
X binobj_out.lon = obj_lon * 3600 * 1000L;
X binobj_out.mag = obj_mag * 1000L;
X binobj_out.type[0] = obj_type[0];
X binobj_out.type[1] = obj_type[1];
X
X if (fwrite((char *) &binobj_out, sizeof(binobj_out), 1, file) != 1) {
X perror("Error writing output file");
X exit(2);
X }
X}
X
X
X/* write sif format */
Xvoid writesif(file, sepchar)
X FILE *file;
X char sepchar;
X{
X if ((obj_lon > 360.0) || (obj_lon < 0.0)) {
X fprintf(stderr, "Error: R.A. out of range:\"%f\"\n", obj_lon/15.0);
X obj_lon = 0.0;
X obj_mag = 35.0;
X };
X if ((obj_lat > 90.0) || (obj_lat < -90.0)) {
X fprintf(stderr, "Error: declination out of range:\"%f\"\n", obj_lat);
X obj_lat = 0.0;
X obj_mag = 35.0;
X };
X
X fprintf(file, "%.10f%c%.10f%c%f%c%s%c%s%c%s%c%3s%c%s%c%s\n",
X obj_lon/15.0, sepchar,
X obj_lat, sepchar,
X obj_mag, sepchar,
X obj_type, sepchar,
X obj_color, sepchar,
X obj_label, sepchar,
X obj_constell, sepchar,
X obj_name, sepchar,
X obj_commnt);
X}
X
X
X/* Old precession formula */
Xdouble M, N;
Xvoid initxform(ein, eout)
X double ein, eout;
X{
X double T;
X
X T = (eout - ein) / 100.0;
X M = (1.2812323 + (0.0003879 + 0.0000101 * T) * T) * T;
X N = (0.5567530 - (0.0001185 - 0.0000116 * T) * T) * T;
X}
X
Xvoid xform(rin, din, rout, dout)
X double rin, din, *rout, *dout;
X{
X double am, dm, a2, d2;
X
X/* am = /alpha_m, dm = /delta_m */
X
X am = rin + (M + N * DSIN(rin) * DTAN(din))/2.0;
X dm = din + N*DCOS(am)/2.0;
X a2 = rin + M + N*DSIN(am)*DTAN(dm);
X d2 = din + N * DCOS(am);
X
X if (a2 >= 360.0) a2 -= 360.0;
X if (a2 < 0.0) a2 += 360.0;
X
X *rout = a2;
X *dout = d2;
X}
X
X/* Rigorous precession */
X/* From Astronomical Ephemeris 1989, p. B18 */
X/*
Xfrom t_0 to t:
X
XA =
Xsin(alpha - z_A) cos(delta) = sin(alpha_0 + zeta_A) cos(delta_0);
XB =
Xcos(alpha - z_A) cos(delta) = cos(alpha_0 + zeta_A) cos(theta_A) cos(delta_0)
X - sin(theta_A) sin(delta_0);
XC =
X sin(delta) = cos(alpha_0 + zeta_A) sin(theta_A) cos(delta_0)
X + cos(theta_A) sin(delta_0);
X
Xdelta = asin(C);
Xalpha = atan2(A/B) + z_A;
X
X
X
Xfrom t to t_0:
X
XA =
Xsin(alpha_0 + zeta_A) cos(delta_0) = sin(alpha - z_A) cos(delta);
X
XB =
Xcos(alpha_0 + zeta_A) cos(delta_0) = cos(alpha - z_A) cos(theta_A) cos(delta)
X + sin(theta_A) sin(delta);
XC =
X sin(delta_0) = -cos(alpha - z_A) sin(theta_A) cos(delta)
X + cos(theta_A) sin(delta)
X
Xdelta_0 = asin(C);
Xalpha_0 = atan2(A,B) - zeta_A;
X*/
X
X
X
X/* For reduction with respect to the standard epoch t_0 = J2000.0
Xzeta_A = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T
X Z_A = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T
Xtheta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T
X
Xin degrees.
X
XT = (jd - 2451545.0)/36525.0;
X
Xalpha2000 = alpha_0;
Xdelta2000 = delta_0;
X*/
X
X
Xvoid precess_f(from_equinox, to_equinox,
X alpha_in, delta_in, alpha_out, delta_out)
X double from_equinox, to_equinox,
X alpha_in, delta_in, *alpha_out, *delta_out;
X{
X double zeta_A, z_A, theta_A;
X double T;
X double A, B, C;
X double alpha, delta;
X double alpha2000, delta2000;
X double into_range();
X
X
X /* From from_equinox to 2000.0 */
X if (from_equinox != 2000.0) {
X T = (from_equinox - 2000.0)/100.0;
X zeta_A = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
X z_A = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
X theta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T;
X
X A = DSIN(alpha_in - z_A) * DCOS(delta_in);
X B = DCOS(alpha_in - z_A) * DCOS(theta_A) * DCOS(delta_in)
X + DSIN(theta_A) * DSIN(delta_in);
X C = -DCOS(alpha_in - z_A) * DSIN(theta_A) * DCOS(delta_in)
X + DCOS(theta_A) * DSIN(delta_in);
X
X alpha2000 = into_range(DATAN2(A,B) - zeta_A);
X delta2000 = DASIN(C);
X } else {
X /* should get the same answer, but this could improve accruacy */
X alpha2000 = alpha_in;
X delta2000 = delta_in;
X };
X
X
X /* From 2000.0 to to_equinox */
X if (to_equinox != 2000.0) {
X T = (to_equinox - 2000.0)/100.0;
X zeta_A = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
X z_A = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
X theta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T;
X
X A = DSIN(alpha2000 + zeta_A) * DCOS(delta2000);
X B = DCOS(alpha2000 + zeta_A) * DCOS(theta_A) * DCOS(delta2000)
X - DSIN(theta_A) * DSIN(delta2000);
X C = DCOS(alpha2000 + zeta_A) * DSIN(theta_A) * DCOS(delta2000)
X + DCOS(theta_A) * DSIN(delta2000);
X
X alpha = into_range(DATAN2(A,B) + z_A);
X delta = DASIN(C);
X } else {
X /* should get the same answer, but this could improve accruacy */
X alpha = alpha2000;
X delta = delta2000;
X };
X
X *alpha_out = alpha;
X *delta_out = delta;
X}
X
X
Xdouble into_range(ang)
X double ang;
X{
X int i;
X
X while (ang < 0.0) ang += 360.0;
X /* Shouldn't be more than once */
X
X i = ang/360.0;
X
X ang = ang - i * 360;
X
X return(ang);
X}
X
X
END_OF_FILE
if test 34330 -ne `wc -c <'dataconv/dataconv.c'`; then
echo shar: \"'dataconv/dataconv.c'\" unpacked with wrong size!
fi
# end of 'dataconv/dataconv.c'
fi
echo shar: End of archive 25 \(of 32\).
cp /dev/null ark25isdone
MISSING=""
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
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 32 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0