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 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 Library General Public
18 // License along with this library; if not, write to the
19 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 // Boston, MA 02111-1307, USA.
25 #include <simgear/debug/logstream.hxx>
26 #include <simgear/misc/fgstream.hxx>
31 FG_USING_STD(getline);
35 SGStarData::SGStarData() {
38 SGStarData::SGStarData( FGPath path ) {
39 data_path = FGPath( path );
45 SGStarData::~SGStarData() {
49 bool SGStarData::load() {
51 // -dw- avoid local data > 32k error by dynamic allocation of the
52 // array, problem for some compilers
53 stars = new sgdVec3[SG_MAX_STARS];
55 // build the full path name to the stars data base file
56 data_path.append( "stars" );
57 FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << data_path.str() );
59 fg_gzifstream in( data_path.str() );
60 if ( ! in.is_open() ) {
61 FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: "
72 // read in each line of the file
73 while ( ! in.eof() && nstars < SG_MAX_STARS ) {
76 getline( in, name, ',' );
77 // cout << " data = " << name << endl;
79 // read name and first comma
81 if ( (c != ' ') && (c != ',') ) {
82 // push back on the stream
90 // read past optional comma
92 if ( (c != ' ') && (c != ',') ) {
93 // push back on the stream
101 // read past optional comma
102 while ( in.get(c) ) {
103 if ( (c != ' ') && (c != ',') ) {
104 // push back on the stream
112 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
114 sgdSetVec3( stars[nstars], ra, dec, mag );
119 FG_LOG( FG_ASTRO, FG_INFO, " Loaded " << nstars << " stars" );