]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/stardata.cxx
Modified Files:
[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 General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <simgear_config.h>
25 #endif
26
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/misc/sgstream.hxx>
29
30 #include "stardata.hxx"
31
32 #if defined (_MSC_VER)
33   SG_USING_STD(getline);
34 #endif
35
36 // Constructor
37 SGStarData::SGStarData() :
38     nstars(0)
39 {
40 }
41
42 SGStarData::SGStarData( SGPath path ) :
43     nstars(0)
44 {
45     data_path = SGPath( path );
46     load();
47 }
48
49
50 // Destructor
51 SGStarData::~SGStarData() {
52 }
53
54
55 bool SGStarData::load() {
56
57     // -dw- avoid local data > 32k error by dynamic allocation of the
58     // array, problem for some compilers
59     stars = new SGVec3d[SG_MAX_STARS];
60
61      // build the full path name to the stars data base file
62     data_path.append( "stars" );
63     SG_LOG( SG_ASTRO, SG_INFO, "  Loading stars from " << data_path.str() );
64
65     sg_gzifstream in( data_path.str() );
66     if ( ! in.is_open() ) {
67         SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
68                 << data_path.str() );
69         exit(-1);
70     }
71
72     double ra, dec, mag;
73     char c;
74     string name;
75
76     nstars = 0;
77
78     // read in each line of the file
79     while ( ! in.eof() && nstars < SG_MAX_STARS ) {
80         in >> skipcomment;
81
82         getline( in, name, ',' );
83         // cout << "  data = " << name << endl;
84
85         // read name and first comma
86         while ( in.get(c) ) {
87             if ( (c != ' ') && (c != ',') ) {
88                 // push back on the stream
89                 in.putback(c);
90                 break;
91             }
92         }
93
94         in >> ra;
95
96         // read past optional comma
97         while ( in.get(c) ) {
98             if ( (c != ' ') && (c != ',') ) {
99                 // push back on the stream
100                 in.putback(c);
101                 break;
102             }
103         }
104
105         in >> dec;
106
107         // read past optional comma
108         while ( in.get(c) ) {
109             if ( (c != ' ') && (c != ',') ) {
110                 // push back on the stream
111                 in.putback(c);
112                 break;
113             }
114         }
115
116         in >> mag;
117
118         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
119
120         sgdSetVec3( stars[nstars].sg(), ra, dec, mag );
121
122         ++nstars;
123     }
124
125     SG_LOG( SG_ASTRO, SG_INFO, "  Loaded " << nstars << " stars" );
126
127     return true;
128 }