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