Created
November 14, 2011 23:23
-
-
Save Nub/1365555 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // main.m | |
| // fccRadioListParser | |
| // | |
| // Created by Zachry Thayer on 11/14/11. | |
| // Copyright (c) 2011 Zachry Thayer. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| #import "JSONKit.h" | |
| #define kFCCStationsFile @"FCCStations.txt" | |
| #define kCountryCodesToNamesFile @"countryCodesToNames.json" | |
| #define kStateCodesToNamesFile @"stateCodesToNames.json" | |
| enum FCCIndexes{ | |
| Callsign = 0, | |
| Frequency, | |
| Service, | |
| Channel, | |
| DirectionalAntennaDAorNonDirectionalND, | |
| NotUsedforFM, | |
| FMStationClass, | |
| NotUsedforFM2, | |
| FMStatus, | |
| City, | |
| State, | |
| Country, | |
| FileNumberApplicationConstructionPermitorLicenseorDocketNumberRulemaking, | |
| EffectiveRadiatedPower__horizontallypolarizedmaximum, | |
| EffectiveRadiatedPower__verticallypolarizedmaximum, | |
| AntennaHeightAboveAverageTerrainHAAT__horizontalpolarization, | |
| AntennaHeightAboveAverageTerrainHAAT__verticalpolarization, | |
| FacilityIDNumberuniquetoeachstation, | |
| NorthOrSouthLatitude, | |
| DegreesLatitude, | |
| MinutesLatitude, | |
| SecondsLatitude, | |
| WestOrEastLongitude, | |
| DegreesLongitude, | |
| MinutesLongitude, | |
| SecondsLongitude, | |
| LicenseeorPermittee, | |
| Kilometersdistantradiusfromenteredlatitude,longitude, | |
| MilesDistantRadius, | |
| Azimuth, | |
| AntennaRadiationCenterAboveMeanSeaLevelRCAMSL_HorizontallyPolarized_meters, | |
| AntennaRadiationCenterAboveMeanSeaLevelRCAMSL_VerticallyPolarized_meters, | |
| DirectionalAntennaIDNumber, | |
| DirectionalAntennaPatternRotation, | |
| AntennaStructureRegistrationNumber, | |
| ApplicationID, | |
| FCCComponentsCount | |
| }; | |
| inline double decimalDegrees(double degrees, double minutes, double seconds){ | |
| return degrees + minutes/60.f + seconds/3600.f; | |
| } | |
| NSDictionary *countryCodesToNames = nil; | |
| NSDictionary *stateCodesToNames = nil; | |
| NSString *getCountryNameFromCode(NSString* countryCode); | |
| NSString *getCountryNameFromCode(NSString* countryCode){ | |
| // if first lookup load DB | |
| if (!countryCodesToNames) { | |
| NSData *countryCodesToNamesData = [NSData dataWithContentsOfFile:kCountryCodesToNamesFile]; | |
| countryCodesToNames = [countryCodesToNamesData objectFromJSONData]; | |
| } | |
| return [countryCodesToNames objectForKey:countryCode]; | |
| } | |
| NSString *getStateNameFromCode(NSString* stateCode); | |
| NSString *getStateNameFromCode(NSString* stateCode){ | |
| // if first lookup load DB | |
| if (!stateCodesToNames) { | |
| NSData *stateCodesToNames = [NSData dataWithContentsOfFile:kStateCodesToNamesFile]; | |
| stateCodesToNames = [stateCodesToNames objectFromJSONData]; | |
| } | |
| return [stateCodesToNames objectForKey:stateCode]; | |
| } | |
| void cleanup(); | |
| void cleanup(){ | |
| if (countryCodesToNames) { | |
| countryCodesToNames = nil;//let arc cleanup | |
| } | |
| } | |
| int main (int argc, const char * argv[]) | |
| { | |
| @autoreleasepool { | |
| NSString *fccStationsText = [NSString stringWithContentsOfFile:kFCCStationsFile encoding:NSUTF8StringEncoding error:nil]; | |
| if (!fccStationsText) { | |
| return -1;//Fail | |
| } | |
| NSMutableDictionary *fccStations = [NSMutableDictionary dictionary]; | |
| NSMutableDictionary *currentCountry = nil; | |
| [fccStationsText enumerateLinesUsingBlock:^(NSString *line, BOOL *stop){ | |
| NSArray *lineComponents = [line componentsSeparatedByString:@"|"]; | |
| if (!lineComponents && [lineComponents count] == FCCComponentsCount) { | |
| return;//Skip to next line, this one is invalid | |
| } | |
| NSMutableDictionary *thisStation = [NSDictionary dictionary]; | |
| [thisStation setObject:[lineComponents objectAtIndex:Callsign] forKey:@""]; | |
| currentCountry = [fccStations | |
| }]; | |
| } | |
| cleanup(); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment