/** * Converts HF broadcast station data file HF_BCD.txt to required data files * @author Robert J Morton YE572246C * @version 22 November 2001 */ // This program uses the Java 1.1.8 API. import java.io.*; class hfbdp { public static void main(String args[]) throws IOException { BufferedReader r = new BufferedReader( new InputStreamReader(new FileInputStream("hfbsn.txt")) ); Writer stations = new FileWriter("stations.txt"); // create frequencies file for first station Writer frequencies = new FileWriter("freqs000.txt"); // create duplicates file Writer dups = new FileWriter("duplicates.txt"); String old_frequency = ""; // for capturing duplicates String old_station = ""; // for capturing duplicates String STATION = ""; // name of station currently being dealt with int sn = 0; // number of station within the list String s; //to hold the current input line while((s = r.readLine()) != null) { // read in the next line of text // find position of tab that separates freq from station name int x = s.indexOf('\t'); String frequency = (s.substring(0, x)); // get the new frequency // get the new name and strip possible rogue spaces from it String station = (s.substring(x + 1, s.length())).trim(); // If a duplicate entry is found, write it to the duplicates file. if(frequency.equals(old_frequency) && station.equals(old_station)) dups.write(frequency + '\t' + station + "\n"); old_frequency = frequency; old_station = station; /* If we are still dealing with the same station, write the next frequency for this station. */ if(STATION.compareTo(station) == 0) { frequencies.write(frequency + "\n"); } else { // else it is a new station, so /* Make this station's name the current station name and write it to the stations file. */ STATION = station; stations.write(station + "\n"); /* If there are no stations within the list, close the station's frequencies file. */ if(sn > 0) frequencies.close(); String SN = "" + sn; // form string version of station number /* If there are less than 10 stations in the list, pad the number of stations with two leading zeros; else if there are less than a hundred, pad it out with just one leading zero. */ if(sn < 10) SN = "00" + SN; else if(sn < 100) SN = "0" + SN; // create a new frequencies file for this station frequencies = new FileWriter("freqs" + SN + ".txt"); /* Write the first frequency for this station and increment the station number ready for the next pass. */ frequencies.write(frequency + "\n"); sn++; } } dups.close(); stations.close(); frequencies.close(); r.close(); } }