]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/stardata.cxx
Attached patches remove BORLANDC, and hence SG_MATH_EXCEPTION_CLASH and SG_INCOM
[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/sg_path.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( const SGPath& path )
39 {
40     load(path);
41 }
42
43
44 // Destructor
45 SGStarData::~SGStarData() {
46 }
47
48
49 bool SGStarData::load( const SGPath& path ) {
50
51     _stars.clear();
52
53     // build the full path name to the stars data base file
54     SGPath tmp = path;
55     tmp.append( "stars" );
56     SG_LOG( SG_ASTRO, SG_INFO, "  Loading stars from " << tmp.str() );
57
58     sg_gzifstream in( tmp.str() );
59     if ( ! in.is_open() ) {
60         SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
61                 << tmp.str() );
62         return false;
63     }
64
65     double ra, dec, mag;
66     char c;
67     string name;
68
69     // read in each line of the file
70     while ( ! in.eof() ) {
71         in >> skipcomment;
72
73         getline( in, name, ',' );
74         // cout << "  data = " << name << endl;
75
76         // read name and first comma
77         while ( in.get(c) ) {
78             if ( (c != ' ') && (c != ',') ) {
79                 // push back on the stream
80                 in.putback(c);
81                 break;
82             }
83         }
84
85         in >> ra;
86
87         // read past optional comma
88         while ( in.get(c) ) {
89             if ( (c != ' ') && (c != ',') ) {
90                 // push back on the stream
91                 in.putback(c);
92                 break;
93             }
94         }
95
96         in >> dec;
97
98         // read past optional comma
99         while ( in.get(c) ) {
100             if ( (c != ' ') && (c != ',') ) {
101                 // push back on the stream
102                 in.putback(c);
103                 break;
104             }
105         }
106
107         in >> mag;
108
109         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
110         _stars.push_back(SGVec3d(ra, dec, mag));
111     }
112
113     SG_LOG( SG_ASTRO, SG_INFO, "  Loaded " << _stars.size() << " stars" );
114
115     return true;
116 }