]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/stardata.cxx
Merge branch 'next' of git.mxchange.org:/var/cache/git/repos/simgear into next
[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 - http://www.flightgear.org/~curt
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 General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <simgear_config.h>
25 #endif
26
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/misc/sg_path.hxx>
29 #include <simgear/misc/sgstream.hxx>
30
31 #include "stardata.hxx"
32
33 #if defined (_MSC_VER)
34   using std::getline;
35 #endif
36
37 using std::string;
38
39 // Constructor
40 SGStarData::SGStarData( const SGPath& path )
41 {
42     load(path);
43 }
44
45
46 // Destructor
47 SGStarData::~SGStarData() {
48 }
49
50
51 bool SGStarData::load( const SGPath& path ) {
52
53     _stars.clear();
54
55     // build the full path name to the stars data base file
56     SGPath tmp = path;
57     tmp.append( "stars" );
58     SG_LOG( SG_ASTRO, SG_INFO, "  Loading stars from " << tmp );
59
60     sg_gzifstream in( tmp );
61     if ( ! in.is_open() ) {
62         SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: " << tmp );
63         return false;
64     }
65
66     double ra, dec, mag;
67     char c;
68     string name;
69
70     // read in each line of the file
71     while ( ! in.eof() ) {
72         in >> skipcomment;
73
74         getline( in, name, ',' );
75         // cout << "  data = " << name << endl;
76
77         // read name and first comma
78         while ( in.get(c) ) {
79             if ( (c != ' ') && (c != ',') ) {
80                 // push back on the stream
81                 in.putback(c);
82                 break;
83             }
84         }
85
86         in >> ra;
87
88         // read past optional comma
89         while ( in.get(c) ) {
90             if ( (c != ' ') && (c != ',') ) {
91                 // push back on the stream
92                 in.putback(c);
93                 break;
94             }
95         }
96
97         in >> dec;
98
99         // read past optional comma
100         while ( in.get(c) ) {
101             if ( (c != ' ') && (c != ',') ) {
102                 // push back on the stream
103                 in.putback(c);
104                 break;
105             }
106         }
107
108         in >> mag;
109
110         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
111         _stars.push_back(SGVec3d(ra, dec, mag));
112     }
113
114     SG_LOG( SG_ASTRO, SG_INFO, "  Loaded " << _stars.size() << " stars" );
115
116     return true;
117 }