package crush.sourcemodel;

import java.io.*;
import java.util.Vector;
import java.text.*;

public class SourceCatalog extends Vector<GaussianSource> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7728245572373531025L;

	public void insert(AstroImage image) {
		for(GaussianSource source : this) source.add(image);
	}
	
	public void remove(AstroImage image) {
		for(GaussianSource source : this) source.subtract(image);
	}
	
	public void read(String fileName, AstroImage image) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
		String line = null;
		while((line = in.readLine()) != null) if(line.length() > 0) if(line.charAt(0) != '#') {
			try { add(new GaussianSource(line, image)); }
			catch(ParseException e) { System.err.println("WARNING! Cannot parse: " + line); }
		}
		System.err.println(" Source catalog loaded: " + size() + " source(s).");
	}
}
