head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.40; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.58; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.04; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.01; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# stardata.cxx

    00001 // stardata.cxx -- manage star data
    00002 //
    00003 // Written by Curtis Olson, started March 2000.
    00004 //
    00005 // Copyright (C) 2000  Curtis L. Olson - curt@@flightgear.org
    00006 //
    00007 // This library is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU Library General Public
    00009 // License as published by the Free Software Foundation; either
    00010 // version 2 of the License, or (at your option) any later version.
    00011 //
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015 // Library General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Library General Public
    00018 // License along with this library; if not, write to the
    00019 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020 // Boston, MA  02111-1307, USA.
    00021 //
    00022 // $Id: stardata.cxx,v 1.6 2001/12/28 23:37:34 curt Exp $
    00023
    00024
    00025 #include <simgear/debug/logstream.hxx>
    00026 #include <simgear/misc/sgstream.hxx>
    00027
    00028 #include "stardata.hxx"
    00029
    00030 #if defined (_MSC_VER) || defined (SG_HAVE_NATIVE_SGI_COMPILERS)
    00031   SG_USING_STD(getline);
    00032 #endif
    00033
    00034 // Constructor
    00035 SGStarData::SGStarData() :
    00036     nstars(0)
    00037 {
    00038 }
    00039
    00040 SGStarData::SGStarData( SGPath path ) :
    00041     nstars(0)
    00042 {
    00043     data_path = SGPath( path );
    00044     load();
    00045 }
    00046
    00047
    00048 // Destructor
    00049 SGStarData::~SGStarData() {
    00050 }
    00051
    00052
    00053 bool SGStarData::load() {
    00054
    00055     // -dw- avoid local data > 32k error by dynamic allocation of the
    00056     // array, problem for some compilers
    00057     stars = new sgdVec3[SG_MAX_STARS];
    00058
    00059      // build the full path name to the stars data base file
    00060     data_path.append( "stars" );
    00061     SG_LOG( SG_ASTRO, SG_INFO, "  Loading stars from " << data_path.str() );
    00062
    00063     sg_gzifstream in( data_path.str() );
    00064     if ( ! in.is_open() ) {
    00065         SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
    00066                 << data_path.str() );
    00067         exit(-1);
    00068     }
    00069
    00070     double ra, dec, mag;
    00071     char c;
    00072     string name;
    00073
    00074     nstars = 0;
    00075
    00076     // read in each line of the file
    00077     while ( ! in.eof() && nstars < SG_MAX_STARS ) {
    00078         in >> skipcomment;
    00079
    00080         getline( in, name, ',' );
    00081         // cout << "  data = " << name << endl;
    00082
    00083         // read name and first comma
    00084         while ( in.get(c) ) {
    00085             if ( (c != ' ') && (c != ',') ) {
    00086                 // push back on the stream
    00087                 in.putback(c);
    00088                 break;
    00089             }
    00090         }
    00091
    00092         in >> ra;
    00093
    00094         // read past optional comma
    00095         while ( in.get(c) ) {
    00096             if ( (c != ' ') && (c != ',') ) {
    00097                 // push back on the stream
    00098                 in.putback(c);
    00099                 break;
    00100             }
    00101         }
    00102
    00103         in >> dec;
    00104
    00105         // read past optional comma
    00106         while ( in.get(c) ) {
    00107             if ( (c != ' ') && (c != ',') ) {
    00108                 // push back on the stream
    00109                 in.putback(c);
    00110                 break;
    00111             }
    00112         }
    00113
    00114         in >> mag;
    00115
    00116         // cout << " star data = " << ra << " " << dec << " " << mag << endl;
    00117
    00118         sgdSetVec3( stars[nstars], ra, dec, mag );
    00119
    00120         ++nstars;
    00121     }
    00122
    00123     SG_LOG( SG_ASTRO, SG_INFO, "  Loaded " << nstars << " stars" );
    00124
    00125     return true;
    00126 }

@ 1.3 log @Oops, try again. @ text @d135 1 a135 1