]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/stars.cxx
MSVC5 portability changes contributed by Bruce Finney.
[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/debug/logstream.hxx>
25 #include <simgear/misc/fgstream.hxx>
26
27 #include "stars.hxx"
28
29 #ifdef _MSC_VER
30   FG_USING_STD(getline);
31 #endif
32
33 // Constructor
34 FGStars::FGStars() {
35 }
36
37 FGStars::FGStars( FGPath path ) {
38     data_path = FGPath( path );
39     load();
40 }
41
42
43 // Destructor
44 FGStars::~FGStars() {
45 }
46
47
48 bool FGStars::load() {
49
50     // -dw- avoid local data > 32k error by dynamic allocation of the
51     // array, problem for some compilers
52     stars = new sgdVec3[FG_MAX_STARS];
53
54      // build the full path name to the stars data base file
55     data_path.append( "stars" );
56     FG_LOG( FG_ASTRO, FG_INFO, "  Loading stars from " << data_path.str() );
57
58     fg_gzifstream in( data_path.str() );
59     if ( ! in.is_open() ) {
60         FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: "
61                 << data_path.str() );
62         exit(-1);
63     }
64
65     double ra, dec, mag;
66     char c;
67     string name;
68
69     nstars = 0;
70
71     // read in each line of the file
72     while ( ! in.eof() && nstars < FG_MAX_STARS ) {
73         in >> skipcomment;
74
75         getline( in, name, ',' );
76         // cout << "  data = " << name << endl;
77
78         // read name and first comma
79         while ( in.get(c) ) {
80             if ( (c != ' ') && (c != ',') ) {
81                 // push back on the stream
82                 in.putback(c);
83                 break;
84             }
85         }
86
87         in >> ra;
88
89         // read past optional comma
90         while ( in.get(c) ) {
91             if ( (c != ' ') && (c != ',') ) {
92                 // push back on the stream
93                 in.putback(c);
94                 break;
95             }
96         }
97
98         in >> dec;
99
100         // read past optional comma
101         while ( in.get(c) ) {
102             if ( (c != ' ') && (c != ',') ) {
103                 // push back on the stream
104                 in.putback(c);
105                 break;
106             }
107         }
108
109         in >> mag;
110
111         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
112
113         sgdSetVec3( stars[nstars], ra, dec, mag );
114
115         ++nstars;
116     }
117
118     FG_LOG( FG_ASTRO, FG_INFO, "  Loaded " << nstars << " stars" );
119
120     return true;
121 }