simgear/simgear/ephemeris/stardata.cxx
Florent Rougon 79f869a7f3 Move IOStreams-related files to simgear/io/iostreams; rename zfstream.[ch]xx to gzfstream.[ch]xx
- Rename zfstream.cxx (resp. zfstream.hxx) to gzfstream.cxx (resp.
  gzfstream.hxx)

  This is because these files only deal with the gzip format (RFC 1952),
  while zlib can actually read and write two slightly different formats:
  this one and the "ZLIB Compressed Data Format" (RFC 1950). Since I am
  going to add std::streambuf and std::istream subclasses able to deal
  with both formats (and supporting data sources that are general
  std::istream instances, not just files), this renaming will make
  things a bit clearer, I hope.

- Add new folder simgear/io/iostreams and move the following files to
  this folder:

    simgear/misc/gzcontainerfile.cxx
    simgear/misc/gzcontainerfile.hxx
    simgear/misc/gzfstream.cxx
    simgear/misc/gzfstream.hxx
    simgear/misc/sgstream.cxx
    simgear/misc/sgstream.hxx
    simgear/misc/sgstream_test.cxx

- Adapt other files accordingly (mainly #includes and CMakeLists.txt
  files).
2017-02-12 21:18:52 +01:00

118 lines
2.6 KiB
C++

// stardata.cxx -- manage star data
//
// Written by Curtis Olson, started March 2000.
//
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <simgear_config.h>
#endif
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/io/iostreams/sgstream.hxx>
#include "stardata.hxx"
#if defined (_MSC_VER)
using std::getline;
#endif
using std::string;
// Constructor
SGStarData::SGStarData( const SGPath& path )
{
load(path);
}
// Destructor
SGStarData::~SGStarData() {
}
bool SGStarData::load( const SGPath& path ) {
_stars.clear();
// build the full path name to the stars data base file
SGPath tmp = path;
tmp.append( "stars" );
SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << tmp );
sg_gzifstream in( tmp );
if ( ! in.is_open() ) {
SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: " << tmp );
return false;
}
double ra, dec, mag;
char c;
string name;
// read in each line of the file
while ( ! in.eof() ) {
in >> skipcomment;
getline( in, name, ',' );
// cout << " data = " << name << endl;
// read name and first comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> ra;
// read past optional comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> dec;
// read past optional comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> mag;
// cout << " star data = " << ra << " " << dec << " " << mag << endl;
_stars.push_back(SGVec3d(ra, dec, mag));
}
SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << _stars.size() << " stars" );
return true;
}