]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/stars.cxx
Removed solarsystem.* replaced mostly with ephemeris.* which is similar
[simgear.git] / simgear / ephemeris / stars.cxx
1 // stars.cxx -- manage star data
2 //
3 // Written by Curtis Olson, started March 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include <simgear/misc/fgstream.hxx>
25
26 #include "stars.hxx"
27
28
29 // Constructor
30 FGStars::FGStars() {
31 }
32
33 FGStars::FGStars( FGPath path ) {
34     data_path = FGPath( path );
35     load();
36 }
37
38
39 // Destructor
40 FGStars::~FGStars() {
41 }
42
43
44 bool FGStars::load() {
45
46     // -dw- avoid local data > 32k error by dynamic allocation of the
47     // array, problem for some compilers
48     stars = new sgdVec3[FG_MAX_STARS];
49
50      // build the full path name to the stars data base file
51     data_path.append( "stars" );
52     cout << "  Loading stars from " << data_path.str() << endl;
53
54     fg_gzifstream in( data_path.str() );
55     if ( ! in.is_open() ) {
56         cout << "Cannot open star file: " << data_path.str() << endl;
57         exit(-1);
58     }
59
60     double ra, dec, mag;
61     char c;
62     string name;
63
64     nstars = 0;
65
66     // read in each line of the file
67     while ( ! in.eof() && nstars < FG_MAX_STARS ) {
68         in >> skipcomment;
69
70         getline( in, name, ',' );
71         // cout << "  data = " << name << endl;
72
73         // read name and first comma
74         while ( in.get(c) ) {
75             if ( (c != ' ') && (c != ',') ) {
76                 // push back on the stream
77                 in.putback(c);
78                 break;
79             }
80         }
81
82         in >> ra;
83
84         // read past optional comma
85         while ( in.get(c) ) {
86             if ( (c != ' ') && (c != ',') ) {
87                 // push back on the stream
88                 in.putback(c);
89                 break;
90             }
91         }
92
93         in >> dec;
94
95         // read past optional comma
96         while ( in.get(c) ) {
97             if ( (c != ' ') && (c != ',') ) {
98                 // push back on the stream
99                 in.putback(c);
100                 break;
101             }
102         }
103
104         in >> mag;
105
106         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
107
108         sgdSetVec3( stars[nstars], ra, dec, mag );
109
110         ++nstars;
111     }
112
113     cout << "  Loaded " << nstars << " stars" << endl;
114
115     return true;
116 }