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/sgstream.hxx>
30 #include "stardata.hxx"
32 #if defined (_MSC_VER)
33 SG_USING_STD(getline);
37 SGStarData::SGStarData() :
42 SGStarData::SGStarData( SGPath path ) :
45 data_path = SGPath( path );
51 SGStarData::~SGStarData() {
55 bool SGStarData::load() {
57 // -dw- avoid local data > 32k error by dynamic allocation of the
58 // array, problem for some compilers
59 stars = new sgdVec3[SG_MAX_STARS];
61 // build the full path name to the stars data base file
62 data_path.append( "stars" );
63 SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << data_path.str() );
65 sg_gzifstream in( data_path.str() );
66 if ( ! in.is_open() ) {
67 SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
78 // read in each line of the file
79 while ( ! in.eof() && nstars < SG_MAX_STARS ) {
82 getline( in, name, ',' );
83 // cout << " data = " << name << endl;
85 // read name and first comma
87 if ( (c != ' ') && (c != ',') ) {
88 // push back on the stream
96 // read past optional comma
98 if ( (c != ' ') && (c != ',') ) {
99 // push back on the stream
107 // read past optional comma
108 while ( in.get(c) ) {
109 if ( (c != ' ') && (c != ',') ) {
110 // push back on the stream
118 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
120 sgdSetVec3( stars[nstars], ra, dec, mag );
125 SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << nstars << " stars" );