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