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>
34 FGStars::FGStars( FGPath path ) {
35 data_path = FGPath( path );
45 bool FGStars::load() {
47 // -dw- avoid local data > 32k error by dynamic allocation of the
48 // array, problem for some compilers
49 stars = new sgdVec3[FG_MAX_STARS];
51 // build the full path name to the stars data base file
52 data_path.append( "stars" );
53 FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << data_path.str() );
55 fg_gzifstream in( data_path.str() );
56 if ( ! in.is_open() ) {
57 FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: "
68 // read in each line of the file
69 while ( ! in.eof() && nstars < FG_MAX_STARS ) {
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;
110 sgdSetVec3( stars[nstars], ra, dec, mag );
115 FG_LOG( FG_ASTRO, FG_INFO, " Loaded " << nstars << " stars" );