#!/usr/local/bin/perl # joeys_dx_stations.pl # version 1.2, Dec. 21, 2005 # by David Rhett Baker, davebaker@benefitslink.com # This small script (with a large appended DATA section) was written in 2005 for # my 11-year-old son, who enjoys listening to AM radio late at night in bed. # He tries to find "DX" stations, meaning long-distance stations that are capable # of being received at night due to the "skip" off of the ionosphere. # This program shows which stations in the U.S. and Canada are broadcasting on a # given frequency, and conversely shows which frequency and how much power a given # station uses. It's about 5 megs in size due to the large database from the FCC. # This program does not use every field of the data; it could be improved to show # the direction in degrees to a particular broadcasting station from the reception # point, for example, or to show the distance between the broadcasting station and # the reception point, if one were to take advantage of all the fields of data. # History # 1.0 - initial release # 1.2 - added ability to enter c or f even when at prompt asking for upward or # downward adjustment of frequency to the next channel (10 kHz up or down), # so Joey will be able to get used to entering c to input a callsign no matter # where in the program he is (and same for f to input a frequency). use strict; use warnings; my @data_array; print "Christmas 2005: loading program for Joseph Rhett Baker... please stand by."; # We'll use an __END__ token at the end, which works like __DATA__, but in a program # rather than a module... while (my $line = ) { # Spinning bar in column 1, over the C in 'Christmas' print "\r/"; print "\r-"; print "\r\\"; print "\r|"; print "\r/"; print "\r-"; print "\r\\"; print "\r|"; print "\rC"; #TS print "\nLine is $line\n"; my @values = split /\|/, $line; foreach my $value (@values) { $value =~ s/^\s+//; $value =~ s/\s+$//; #TS print "\$value is $value\n"; } # Chop spaces and kHz following the numeric frequency... $values[2] =~ s/ //gi; $values[2] =~ s/khz//gi; # Chop extra spaces in the power column... $values[14] =~ tr/ //s; my $data_hashref = { callsign => $values[1], freq => $values[2], time => $values[6], town => $values[10], state => $values[11], country => $values[12], kw => $values[14], }; #TS print "Callsign is $values[1], freq is $values[2], time is $values[6], town is $values[10], state is $values[11], kw is $values[14].\n"; push @data_array, $data_hashref; } PROMPT: while (1) { print "\nJoey, allsign, requency or uit? (c, f or q): "; my $choice = <>; chomp $choice; unless ($choice eq 'c' || $choice eq 'C' || $choice eq 'f' || $choice eq 'F' || $choice eq 'q' || $choice eq 'Q' ) { next PROMPT; } if ($choice eq 'c' || $choice eq 'C') { CALLSIGN_PROMPT: print "\nWhat callsign? "; my $callsign = <>; chomp $callsign; $callsign = uc( $callsign ); foreach my $hashref (@data_array) { if ($hashref->{callsign} eq $callsign) { print $hashref->{callsign}, " broadcasts on ", $hashref->{freq}, " kHz (", $hashref->{time}, ") from ", $hashref->{town}, ", ", $hashref->{state}, ", running ", $hashref->{kw}, ".\n\n"; } } } elsif ($choice eq 'f' || $choice eq 'F') { FREQ_PROMPT: print "\nWhich frequency? "; my $frequency = <>; chomp $frequency; my %printed_already; FREQ_OUT: print "\nHere are the U.S. and Canada stations on $frequency kHz:\n"; # Initialize or re-initialize, in the case of a freq adjustment ordered later in the script... %printed_already = (); foreach my $hashref (@data_array) { if ( $hashref->{freq} == $frequency && ( $hashref->{country} eq 'US' || $hashref->{country} eq 'CA' ) ) { my $station = $hashref->{callsign}; unless ($printed_already{$station} ) { print "\n ", $hashref->{callsign}, ' in ', $hashref->{town}, ', ', $hashref->{state}; } # Instantiate and increment to non-zero value... $printed_already{$station}++; } } CHOICE: print "\n\np or own to next frequency, or uit? "; my $choice = <>; chomp $choice; goto CHOICE unless ( $choice eq 'u' || $choice eq 'U' || $choice eq 'd' || $choice eq 'D' || $choice eq 'q' || $choice eq 'Q' || $choice eq 'c' || $choice eq 'C' || $choice eq 'f' || $choice eq 'F' ); if ($choice eq 'u' || $choice eq 'U') { $frequency += 10; goto FREQ_OUT; } elsif ($choice eq 'd' || $choice eq 'D') { $frequency -= 10; goto FREQ_OUT; } elsif ($choice eq 'c' || $choice eq 'C') { goto CALLSIGN_PROMPT; } elsif ($choice eq 'f' || $choice eq 'F') { goto FREQ_PROMPT; } else { next PROMPT; } } else { print "\n\nI love you, son! --Dad\n\n"; sleep 5; last; } } __END__ #### |NEW |1190 kHz |AM |- |DA3 |Daytime |B |B |APP |NELLIS AFB |NV |US |BNP -20040130BOW |50.0 kW |- |- |- |161247 |N |35 |53 |53.00 |W |115 |17 |4.00 |RAMS III | 0.00 km | 0.00 mi | 0.00 deg | |WYNI |1190 kHz |AM |- |DA2 |Critical Hours |D |B |APP |HARAHAN |LA |US |BMJP -20040130AZP |11.0 kW |- |- |- |40900 |N |29 |52 |46.00 |W |89 |59 |51.00 |MCKISSICK ENTERPRISES | 0.00 km | 0.00 mi | 0.00 deg | |WYNI |1190 kHz |AM |- |DA2 |Daytime |D |B |APP |HARAHAN |LA |US |BMJP -20040130AZP |11.0 kW |- |- |- |40900 |N |29 |52 |46.00 |W |89 |59 |51.00 |MCKISSICK ENTERPRISES | 0.00 km | 0.00 mi | 0.00 deg | |NEW |1190 kHz |AM |- |DAN |Nighttime |B |B |APP |PINE BLUFF |AR |US |BNP -20040130ARB |0.25 kW |- |- |- |161393 |N |34 |15 |18.00 |W |92 |1 |44.00 |JOEL J. KINLOW | 0.00 km | 0.00 mi | 0.00 deg | |NEW |1190 kHz |AM |- |DAN |Daytime |B |B |APP |PINE BLUFF |AR |US |BNP -20040130ARB |10.0 kW |- |- |- |161393 |N |34 |15 |18.00 |W |92 |1 |44.00 |JOEL J. KINLOW | 0.00 km | 0.00 mi | 0.00 deg | |KRFT |1190 kHz |AM |- |DA2 |Nighttime |B |B |APP |UNIVERSITY CITY |MO |US |BMJP -20040130AQS |4.0 kW |- |- |- |5281 |N |38 |26 |13.00 |W |90 |16 |45.00 |ALL SPORTS RADIO, LLC | 0.00 km | 0.00 mi | 0.00 deg | |KRFT |1190 kHz |AM |- |DA2 |Daytime |B |B |APP |UNIVERSITY CITY |MO |US |BMJP -20040130AQS |10.0 kW |- |- |- |5281 |N |38 |42 |25.00 |W |90 |3 |10.00 |ALL SPORTS RADIO, LLC | 0.00 km | 0.00 mi | 0.00 deg | |WWNB |1190 kHz |AM |- |ND2 |Critical Hours |D |B |APP |NEW BERN |NC |US |BMJP -20040130AKH |2.5 kW |- |- |- |14672 |N |35 |6 |3.00 |W |77 |4 |33.00 |CTC MEDIA GROUP, INC. | 0.00 km | 0.00 mi | 0.00 deg |