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 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/sgstream.hxx>
28 #include "stardata.hxx"
30 #if defined (_MSC_VER)
31 SG_USING_STD(getline);
35 SGStarData::SGStarData() :
40 SGStarData::SGStarData( SGPath path ) :
43 data_path = SGPath( path );
49 SGStarData::~SGStarData() {
53 bool SGStarData::load() {
55 // -dw- avoid local data > 32k error by dynamic allocation of the
56 // array, problem for some compilers
57 stars = new sgdVec3[SG_MAX_STARS];
59 // build the full path name to the stars data base file
60 data_path.append( "stars" );
61 SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << data_path.str() );
63 sg_gzifstream in( data_path.str() );
64 if ( ! in.is_open() ) {
65 SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
76 // read in each line of the file
77 while ( ! in.eof() && nstars < SG_MAX_STARS ) {
80 getline( in, name, ',' );
81 // cout << " data = " << name << endl;
83 // read name and first comma
85 if ( (c != ' ') && (c != ',') ) {
86 // push back on the stream
94 // read past optional comma
96 if ( (c != ' ') && (c != ',') ) {
97 // push back on the stream
105 // read past optional comma
106 while ( in.get(c) ) {
107 if ( (c != ' ') && (c != ',') ) {
108 // push back on the stream
116 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
118 sgdSetVec3( stars[nstars], ra, dec, mag );
123 SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << nstars << " stars" );