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/misc/fgstream.hxx>
33 FGStars::FGStars( FGPath path ) {
34 data_path = FGPath( path );
44 bool FGStars::load() {
46 // -dw- avoid local data > 32k error by dynamic allocation of the
47 // array, problem for some compilers
48 stars = new sgdVec3[FG_MAX_STARS];
50 // build the full path name to the stars data base file
51 data_path.append( "stars" );
52 cout << " Loading stars from " << data_path.str() << endl;
54 fg_gzifstream in( data_path.str() );
55 if ( ! in.is_open() ) {
56 cout << "Cannot open star file: " << data_path.str() << endl;
66 // read in each line of the file
67 while ( ! in.eof() && nstars < FG_MAX_STARS ) {
70 getline( in, name, ',' );
71 // cout << " data = " << name << endl;
73 // read name and first comma
75 if ( (c != ' ') && (c != ',') ) {
76 // push back on the stream
84 // read past optional comma
86 if ( (c != ' ') && (c != ',') ) {
87 // push back on the stream
95 // read past optional comma
97 if ( (c != ' ') && (c != ',') ) {
98 // push back on the stream
106 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
108 sgdSetVec3( stars[nstars], ra, dec, mag );
113 cout << " Loaded " << nstars << " stars" << endl;