1 // stardata.cxx -- manage star data
3 // Written by Curtis Olson, started March 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
24 # include <simgear_config.h>
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/misc/sg_path.hxx>
29 #include <simgear/misc/sgstream.hxx>
31 #include "stardata.hxx"
33 #if defined (_MSC_VER)
34 SG_USING_STD(getline);
38 SGStarData::SGStarData( const SGPath& path )
45 SGStarData::~SGStarData() {
49 bool SGStarData::load( const SGPath& path ) {
53 // build the full path name to the stars data base file
54 path.append( "stars" );
55 SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << path.str() );
57 sg_gzifstream in( path.str() );
58 if ( ! in.is_open() ) {
59 SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
68 // read in each line of the file
69 while ( ! in.eof() ) {
72 getline( in, name, ',' );
73 // cout << " data = " << name << endl;
75 // read name and first comma
77 if ( (c != ' ') && (c != ',') ) {
78 // push back on the stream
86 // read past optional comma
88 if ( (c != ' ') && (c != ',') ) {
89 // push back on the stream
97 // read past optional comma
99 if ( (c != ' ') && (c != ',') ) {
100 // push back on the stream
108 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
109 _stars.push_back(SGVec3d(ra, dec, mag));
112 SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << _stars.size() << " stars" );