#include <iostream>#include <fstream>#include <iomanip>#include <cctype>#include <cassert>#include <celutil/basictypes.h>#include <celutil/bytes.h>#include <celengine/astro.h>#include <celengine/star.h>Include dependency graph for makestardb.cpp:

Go to the source code of this file.
Functions | |
| int | main (int argc, char *argv[]) |
| bool | parseCommandLine (int argc, char *argv[]) |
| void | Usage () |
| static void | writeFloat (ostream &out, float f) |
| static void | writeShort (ostream &out, int16 n) |
| bool | WriteStarDatabase (istream &in, ostream &out, bool sphericalCoords) |
| static void | writeUint (ostream &out, uint32 n) |
| static void | writeUshort (ostream &out, uint16 n) |
Variables | |
| static string | inputFilename |
| static string | outputFilename |
| static bool | useSphericalCoords = false |
|
||||||||||||
|
Definition at line 218 of file makestardb.cpp. References inputFilename, outputFilename, parseCommandLine(), Usage(), useSphericalCoords, and WriteStarDatabase(). 00219 {
00220 if (!parseCommandLine(argc, argv) || inputFilename.empty())
00221 {
00222 Usage();
00223 return 1;
00224 }
00225
00226 ifstream inputFile(inputFilename.c_str(), ios::in);
00227 if (!inputFile.good())
00228 {
00229 cerr << "Error opening input file " << inputFilename << '\n';
00230 return 1;
00231 }
00232
00233 ofstream stardbFile(outputFilename.c_str(), ios::out | ios::binary);
00234 if (!stardbFile.good())
00235 {
00236 cerr << "Error opening star database file " << outputFilename << '\n';
00237 return 1;
00238 }
00239
00240 bool success = WriteStarDatabase(inputFile, stardbFile, useSphericalCoords);
00241
00242 return success ? 0 : 1;
00243 }
|
|
||||||||||||
|
Definition at line 38 of file makestardb.cpp. References inputFilename, outputFilename, and useSphericalCoords. 00039 {
00040 int i = 1;
00041 int fileCount = 0;
00042
00043 while (i < argc)
00044 {
00045 if (argv[i][0] == '-')
00046 {
00047 if (!strcmp(argv[i], "--spherical") || !strcmp(argv[i], "-s"))
00048 {
00049 useSphericalCoords = true;
00050 }
00051 else
00052 {
00053 cerr << "Unknown command line switch: " << argv[i] << '\n';
00054 return false;
00055 }
00056 i++;
00057 }
00058 else
00059 {
00060 if (fileCount == 0)
00061 {
00062 // input filename first
00063 inputFilename = string(argv[i]);
00064 fileCount++;
00065 }
00066 else if (fileCount == 1)
00067 {
00068 // output filename second
00069 outputFilename = string(argv[i]);
00070 fileCount++;
00071 }
00072 else
00073 {
00074 // more than two filenames on the command line is an error
00075 return false;
00076 }
00077 i++;
00078 }
00079 }
00080
00081 return true;
00082 }
|
|
|
Definition at line 30 of file makestardb.cpp. Referenced by CreateVertexAttributeMap(), and main(). 00031 {
00032 cerr << "Usage: makestardb [options] <input file> <output star database>\n";
00033 cerr << " Options:\n";
00034 cerr << " --spherical (or -s) : input file has spherical coords (RA/dec/distance\n";
00035 }
|
|
||||||||||||
|
Definition at line 91 of file makestardb.cpp. References LE_TO_CPU_FLOAT. 00092 {
00093 LE_TO_CPU_FLOAT(f, f);
00094 out.write(reinterpret_cast<char*>(&f), sizeof f);
00095 }
|
|
||||||||||||
|
Definition at line 103 of file makestardb.cpp. References LE_TO_CPU_INT16. Referenced by WriteCrossIndex(), and WriteStarDatabase(). 00104 {
00105 LE_TO_CPU_INT16(n, n);
00106 out.write(reinterpret_cast<char*>(&n), sizeof n);
00107 }
|
|
||||||||||||||||
|
Definition at line 110 of file makestardb.cpp. References distance(), astro::equatorialToCelestialCart(), StarDetails::getSpectralType(), StarDetails::GetStarDetails(), StellarClass::pack(), StellarClass::parse(), writeFloat(), writeShort(), writeUint(), writeUshort(), Point3< T >::x, Point3< T >::y, and Point3< T >::z. Referenced by main(). 00111 {
00112 unsigned int record = 0;
00113 unsigned int nStarsInFile = 0;
00114
00115 in >> nStarsInFile;
00116 if (!in.good())
00117 {
00118 cerr << "Error reading star count at beginning of input file.\n";
00119 return 1;
00120 }
00121
00122 // Write the header
00123 out.write("CELSTARS", 8);
00124
00125 // Write the version
00126 writeShort(out, 0x0100);
00127
00128 writeUint(out, nStarsInFile);
00129
00130 for (unsigned int record = 0; record < nStarsInFile; record++)
00131 {
00132 unsigned int catalogNumber;
00133 float x, y, z;
00134 float absMag;
00135
00136 in >> catalogNumber;
00137 if (in.eof())
00138 return true;
00139
00140 if (!in.good())
00141 {
00142 cerr << "Error parsing catalog number for record #" << record << '\n';
00143 return false;
00144 }
00145
00146 if (sphericalCoords)
00147 {
00148 float RA, dec, distance;
00149 float appMag;
00150
00151 in >> RA >> dec >> distance;
00152 if (!in.good())
00153 {
00154 cerr << "Error parsing position of star " << catalogNumber << '\n';
00155 return false;
00156 }
00157
00158 in >> appMag;
00159 if (!in.good())
00160 {
00161 cerr << "Error parsing magnitude of star " << catalogNumber << '\n';
00162 return false;
00163 }
00164
00165 Point3d pos =
00166 astro::equatorialToCelestialCart((double) RA * 24.0 / 360.0,
00167 (double) dec,
00168 (double) distance);
00169 x = (float) pos.x;
00170 y = (float) pos.y;
00171 z = (float) pos.z;
00172 absMag = (float) (appMag + 5 - 5 * log10(distance / 3.26));
00173 }
00174 else
00175 {
00176 in >> x >> y >> z;
00177 if (!in.good())
00178 {
00179 cerr << "Error parsing position of star " << catalogNumber << '\n';
00180 return false;
00181 }
00182
00183 in >> absMag;
00184 if (!in.good())
00185 {
00186 cerr << "Error parsing magnitude of star " << catalogNumber << '\n';
00187 return false;
00188 }
00189 }
00190
00191 string scString;
00192 in >> scString;
00193 StellarClass sc = StellarClass::parse(scString);
00194 #if 0
00195 StarDetails* details = StarDetails::GetStarDetails(sc);
00196 if (details == NULL)
00197 {
00198 cerr << "Error parsing spectral type of star " << catalogNumber << '\n';
00199 return false;
00200 }
00201
00202 // For spectral type parser debugging . . .
00203 cout << scString << ' ' << details->getSpectralType() << '\n';
00204 #endif
00205
00206 writeUint(out, catalogNumber);
00207 writeFloat(out, x);
00208 writeFloat(out, y);
00209 writeFloat(out, z);
00210 writeShort(out, (int16) (absMag * 256.0f));
00211 writeUshort(out, sc.pack());
00212 }
00213
00214 return true;
00215 }
|
|
||||||||||||
|
Definition at line 85 of file makestardb.cpp. References LE_TO_CPU_INT32. 00086 {
00087 LE_TO_CPU_INT32(n, n);
00088 out.write(reinterpret_cast<char*>(&n), sizeof n);
00089 }
|
|
||||||||||||
|
Definition at line 97 of file makestardb.cpp. References LE_TO_CPU_INT16. Referenced by WriteStarDatabase(). 00098 {
00099 LE_TO_CPU_INT16(n, n);
00100 out.write(reinterpret_cast<char*>(&n), sizeof n);
00101 }
|
|
|
Definition at line 25 of file makestardb.cpp. |
|
|
Definition at line 26 of file makestardb.cpp. |
|
|
Definition at line 27 of file makestardb.cpp. Referenced by main(), and parseCommandLine(). |
1.4.1