]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/stardata.cxx
Fix a small typo.
[simgear.git] / simgear / ephemeris / stardata.cxx
1 // stardata.cxx -- manage star data
2 //
3 // Written by Curtis Olson, started March 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
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.
11 //
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.
16 //
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.
21 //
22 // $Id$
23
24 #ifdef HAVE_CONFIG_H
25 #  include <simgear_config.h>
26 #endif
27
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
30
31 #include "stardata.hxx"
32
33 #if defined (_MSC_VER)
34   SG_USING_STD(getline);
35 #endif
36
37 // Constructor
38 SGStarData::SGStarData() :
39     nstars(0)
40 {
41 }
42
43 SGStarData::SGStarData( SGPath path ) :
44     nstars(0)
45 {
46     data_path = SGPath( path );
47     load();
48 }
49
50
51 // Destructor
52 SGStarData::~SGStarData() {
53 }
54
55
56 bool SGStarData::load() {
57
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];
61
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() );
65
66     sg_gzifstream in( data_path.str() );
67     if ( ! in.is_open() ) {
68         SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
69                 << data_path.str() );
70         exit(-1);
71     }
72
73     double ra, dec, mag;
74     char c;
75     string name;
76
77     nstars = 0;
78
79     // read in each line of the file
80     while ( ! in.eof() && nstars < SG_MAX_STARS ) {
81         in >> skipcomment;
82
83         getline( in, name, ',' );
84         // cout << "  data = " << name << endl;
85
86         // read name and first comma
87         while ( in.get(c) ) {
88             if ( (c != ' ') && (c != ',') ) {
89                 // push back on the stream
90                 in.putback(c);
91                 break;
92             }
93         }
94
95         in >> ra;
96
97         // read past optional comma
98         while ( in.get(c) ) {
99             if ( (c != ' ') && (c != ',') ) {
100                 // push back on the stream
101                 in.putback(c);
102                 break;
103             }
104         }
105
106         in >> dec;
107
108         // read past optional comma
109         while ( in.get(c) ) {
110             if ( (c != ' ') && (c != ',') ) {
111                 // push back on the stream
112                 in.putback(c);
113                 break;
114             }
115         }
116
117         in >> mag;
118
119         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
120
121         sgdSetVec3( stars[nstars], ra, dec, mag );
122
123         ++nstars;
124     }
125
126     SG_LOG( SG_ASTRO, SG_INFO, "  Loaded " << nstars << " stars" );
127
128     return true;
129 }