All pastes #222817 Raw Edit

Untitled

public text v1 · immutable
#222817 ·published 2006-10-26 15:37 UTC
rendered paste body
/ Load star data from disk 
bool Galaxy::Load_Systems (const std::string& file_name ) {

	std::ifstream inFile;	
	std::string data;
	System* system; 

	// Temp var for System data
	int id;
	std::string name;
	long ra; 
	long dec;
	long distance; 
	std::ostringstream myStream;

	// Temp var for Star data
	std::string SpectralType; 
	long AbsMag;  
	

	inFile.open(  (SOL_DATA_DIR + file_name).c_str() );
	if (!inFile) {
		printf ( "Galaxy::Load_Systems -> Unable to open %s\n" ,  file_name.c_str() );
		return (false);
	}
	inFile >> data;  // Skip first entry, Total # stars
	while ( inFile >> data) {
	// Data Format
	// ID RA         DEC       Distance  AbsMag  Star_Type/s
	// 1  0.00091185 1.0890133 921.37572 9.09766 F5
		// Get data 
		id = std::atoi(data.c_str()); 

		inFile >> data; // RA
		ra  = std::atol (data.c_str() );
		inFile >> data; // DEC
		dec = std::atol (data.c_str() );
		inFile >> data; // Distance
		distance = std::atol (data.c_str() );
		inFile >> data; // AbsMag // Think it's actual the apparent mag from rading cel docs
		AbsMag = std::atol (data.c_str());
		inFile >> data; // StarType
		SpectralType = data;
		// No System name yet, will do later 
		
		myStream.clear();
		myStream << id ;
		name = "sys:" + myStream.str() ;


		system = new System;
		system->Init ( id , name , ra , dec , distance );
		if (id==0) {	current_sys = system; } // Keep a pointer to the start system
		// Loop through the systems Stars and create the star's
		// Note, only adding one star per system to start
		// Use the sys name + star type as temp name
		std::string tempName = name + ":" + SpectralType;
		system->Add_Star ( name  , SpectralType ,AbsMag );
		systems.push_back(system); 
		printf ("Loading System ID:%i\n" , id );
	}
    inFile.close();
     return 0;
}