/** * Converts HF broadcast station data file HF_BCD.txt to required data files * @author Robert J Morton * @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 frequencies = new FileWriter("freqs000.txt"), // create duplicates file dups = new FileWriter("duplicates.txt"); String old_frequency = "", // for capturing duplicates old_station = "", // for capturing duplicates STATION = "", // name of station currently being dealt with s; // to hold the current input line int sn = 0; // number of station within the list /* While there are more lines of text to be read in, read in the next line of text, find the position ofthe 'tab' character that separates the frequency from from the station name, get the new station name and strip from it any possible rogue spaces. */ while((s = r.readLine()) != null) { int x = s.indexOf('\t'); String frequency = (s.substring(0, x)); String station = (s.substring(x + 1, s.length())).trim(); // If this is a duplicate entry, write it to 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 stationand write the next frequency for this station. */ if(STATION.compareTo(station) == 0) { frequencies.write(frequency + "\n"); /* Otherwise, it is a new station, so make this station's name the current station name and write its name to stations file. */ } else { STATION = station; stations.write(station + "\n"); /* Provided the previous station actually had at least one frequency, close its frequencies file*/ if(sn > 0) frequencies.close(); String SN = "" + sn; // form string version of station number if(sn < 10) // if it is less than 10 SN = "00" + SN; // pad it out with 2 leading zeros else if(sn < 100) // else if it is less than 100 SN = "0" + SN; // pad it with just 1 leading zero /* Create a new frequencies file for this station and write first frequency for this station. */ frequencies = new FileWriter("freqs" + SN + ".txt"); frequencies.write(frequency + "\n"); sn++; // increment station number for next time } } // end of while loop dups.close(); stations.close(); frequencies.close(); r.close(); } }