1 // readstars.cpp
2 //
3 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 
10 #include <cmath>
11 #include <iostream>
12 
13 #define MAX_STARS 120000
14 
15 #define PI 3.1415926535898
16 
17 #include "basictypes.h"
18 #include "stellarclass.h"
19 #include "star.h"
20 
21 
main(int argc,char * argv[])22 int main(int argc, char *argv[])
23 {
24     Star *stars = new Star[MAX_STARS];
25     int nStars = 0;
26     float brightest = 100000;
27 
28     while (nStars < MAX_STARS) {
29 	uint32 catNo = 0;
30 	float RA = 0, dec = 0, parallax = 0;
31 	int16 appMag;
32 	uint16 stellarClass;
33 
34 	cin.read((void *) &catNo, sizeof catNo);
35 	cin.read((void *) &RA, sizeof RA);
36 	cin.read((void *) &dec, sizeof dec);
37 	cin.read((void *) &parallax, sizeof parallax);
38 	cin.read((void *) &appMag, sizeof appMag);
39 	cin.read((void *) &stellarClass, sizeof stellarClass);
40 	if (!cin.good())
41 	    break;
42 
43 	Star *star = &stars[nStars];
44 
45 	// Compute distance based on parallax
46 	double distance = 3.26 / (parallax > 0.0 ? parallax / 1000.0 : 1e-6);
47 
48 	// Convert from RA, dec spherical to cartesian coordinates
49 	double theta = RA / 24.0 * PI * 2;
50 	double phi = (1.0 - dec / 90.0) * PI / 2;
51 	double x = cos(theta) * sin(phi) * distance;
52 	double y = cos(phi) * distance;
53 	double z = sin(theta) * sin(phi) * distance;
54 	star->setPosition((float) x, (float) y, (float) z);
55 
56 	// Use apparent magnitude and distance to determine the absolute
57 	// magnitude of the star.
58 	star->setAbsoluteMagnitude((float) (appMag / 256.0 + 5 -
59 					    5 * log10(distance / 3.26)));
60 
61 	StellarClass sc((StellarClass::StarType) (stellarClass >> 12),
62 			(StellarClass::SpectralClass)(stellarClass >> 8 & 0xf),
63 			(unsigned int) (stellarClass >> 4 & 0xf),
64 			(StellarClass::LuminosityClass) (stellarClass & 0xf));
65 	star->setStellarClass(sc);
66 
67 	star->setCatalogNumber(catNo);
68 
69 	if (parallax > 0.0 && star->getAbsoluteMagnitude() < brightest)
70         {
71 	    brightest = star->getAbsoluteMagnitude();
72 	    cout << brightest << ' ' << sc << '\n';
73 	}
74 
75 	nStars++;
76     }
77 
78     cout << nStars << '\n';
79     cout << sizeof(StellarClass) << '\n';
80     cout << sizeof(stars[0]) << '\n';
81 }
82