package hirondelle.starfield.physics;
import hirondelle.starfield.util.Util;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public final class Starfield {
public Starfield(InputParameters aInput){
fInput = aInput;
fDirOfMotion = new DirectionOfMotion(aInput.getDirectionOfMotionRA(), aInput.getDirectionOfMotionDec(), aInput.getRotation());
}
public StarfieldStats calculate() {
StarfieldStats result = new StarfieldStats();
StarfieldImage image = null;
if (fInput.getOutputFile() != null){
image = new StarfieldImage(fInput.getProjector(), fInput.getOutputFile(), fInput.getImageSize(), fInput.getMagnification());
}
boolean didFirstLine = false;
for(File catalogFile : fInput.getCatalogDirectory().listFiles()){
if (catalogFile.isFile()){
if (catalogFile.getName().endsWith(".ignore")) continue;
Util.logVerbose("Scanning catalog file. Name: " + catalogFile.getName());
try (Scanner scanner = new Scanner(catalogFile) ){
while (scanner.hasNextLine()){
String starRecord = scanner.nextLine();
Star star = fInput.getCatalog().getRecordParser().parse(starRecord);
process(star, result, image);
if(!didFirstLine){
Util.logVerbose("First Record: " + starRecord);
Util.logVerbose("Parsed as " + star);
didFirstLine = true;
}
}
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
}
if (image != null){
image.generateFile();
}
return result;
}
public InputParameters getInputParams(){ return fInput; }
private InputParameters fInput;
private Boost fBoost = new Boost();
private DirectionOfMotion fDirOfMotion;
private void process(Star aStar, StarfieldStats aStats, StarfieldImage aImage){
if (aStar != null){
++aStats.NumStarsInSimulation;
if (fDirOfMotion.isNotDefault()){
fDirOfMotion.changeCoordsOfThe(aStar);
}
BoostedStar boostedStar = fBoost.applyBoostTo(aStar, fInput.getBeta());
if (boostedStar.Magnitude <= fInput.getLimitingMagnitude()){
++aStats.NumStarsVisible;
aStats.BrightnessIndex = aStats.BrightnessIndex + Math.pow(2.512,0-boostedStar.Magnitude); aImage.add(boostedStar, aStar.RightAscension);
}
}
else {
++aStats.NumRecordsRejected;
}
}
}