1 // stars.cxx -- manage star data
3 // Written by Curtis Olson, started March 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
24 #include <simgear/debug/logstream.hxx>
25 #include <simgear/misc/fgstream.hxx>
30 FG_USING_STD(getline);
34 SGStarData::SGStarData() {
37 SGStarData::SGStarData( FGPath path ) {
38 data_path = FGPath( path );
44 SGStarData::~SGStarData() {
48 bool SGStarData::load() {
50 // -dw- avoid local data > 32k error by dynamic allocation of the
51 // array, problem for some compilers
52 stars = new sgdVec3[SG_MAX_STARS];
54 // build the full path name to the stars data base file
55 data_path.append( "stars" );
56 FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << data_path.str() );
58 fg_gzifstream in( data_path.str() );
59 if ( ! in.is_open() ) {
60 FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: "
71 // read in each line of the file
72 while ( ! in.eof() && nstars < SG_MAX_STARS ) {
75 getline( in, name, ',' );
76 // cout << " data = " << name << endl;
78 // read name and first comma
80 if ( (c != ' ') && (c != ',') ) {
81 // push back on the stream
89 // read past optional comma
91 if ( (c != ' ') && (c != ',') ) {
92 // push back on the stream
100 // read past optional comma
101 while ( in.get(c) ) {
102 if ( (c != ' ') && (c != ',') ) {
103 // push back on the stream
111 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
113 sgdSetVec3( stars[nstars], ra, dec, mag );
118 FG_LOG( FG_ASTRO, FG_INFO, " Loaded " << nstars << " stars" );