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_config.h>
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
31 #include "stardata.hxx"
33 #if defined (_MSC_VER)
34 SG_USING_STD(getline);
38 SGStarData::SGStarData() :
43 SGStarData::SGStarData( SGPath path ) :
46 data_path = SGPath( path );
52 SGStarData::~SGStarData() {
56 bool SGStarData::load() {
58 // -dw- avoid local data > 32k error by dynamic allocation of the
59 // array, problem for some compilers
60 stars = new sgdVec3[SG_MAX_STARS];
62 // build the full path name to the stars data base file
63 data_path.append( "stars" );
64 SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << data_path.str() );
66 sg_gzifstream in( data_path.str() );
67 if ( ! in.is_open() ) {
68 SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
79 // read in each line of the file
80 while ( ! in.eof() && nstars < SG_MAX_STARS ) {
83 getline( in, name, ',' );
84 // cout << " data = " << name << endl;
86 // read name and first 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 // read past optional comma
109 while ( in.get(c) ) {
110 if ( (c != ' ') && (c != ',') ) {
111 // push back on the stream
119 // cout << " star data = " << ra << " " << dec << " " << mag << endl;
121 sgdSetVec3( stars[nstars], ra, dec, mag );
126 SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << nstars << " stars" );