/** * 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 // create reader for the station data file. r = new BufferedReader( new InputStreamReader( new FileInputStream("hfbsn.txt") ) ); /* Create writers for the separate stations and frequencies files. Also create a file in which to write duplicate entries. */ Writer stations = new FileWriter("stations.txt"), frequencies = new FileWriter("freqs000.txt"), 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 still more lines of text in the file, read in the next line and find the position of the tab character that separates the frequency from from station name. */ while((s = r.readLine()) != null) { int x = s.indexOf('\t'); /* Get the new frequency, then get the corresponding station name and strip off possible rogue space charaters from it.*/ String frequency = (s.substring(0,x)), station = (s.substring(x + 1,s.length())).trim(); /* If it is a duplicate entry, write this frequency and station name 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, then write the next frequency for this station. */ if(STATION.compareTo(station) == 0) frequencies.write(frequency + "\n"); /* Else, it must be a new station; so, make this station's name the current station name and wite it to the 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 the station number for the next pass } } dups.close(); stations.close(); frequencies.close(); r.close(); } }