{"id":569,"date":"2009-12-18T13:04:38","date_gmt":"2009-12-18T21:04:38","guid":{"rendered":"http:\/\/wellgolly.com\/?p=569"},"modified":"2010-02-17T13:23:36","modified_gmt":"2010-02-17T21:23:36","slug":"downloading-the-naco-afd","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=569","title":{"rendered":"Downloading the NACO A\/FD"},"content":{"rendered":"<p>NACO publishes terminal area charts and the Airport Facility Directory (A\/FD\u2014also known as the green book) and has an online version of the PDFs. The only obvious way to access them is through a map interface. The interface works fine for the terminal area charts but is broken for the A\/FD. It&#8217;s been broken for years and they don&#8217;t seem to have the expertise to fix it. The code is a bit convoluted and it&#8217;s on my list of things to decipher and fix. However, in the mean time I&#8217;ve provided a table by state to access the PDFs. It is located on the Touring Machine site at this <a href=\"http:\/\/www.touringmachine.com\/NACO-AFD\/index.php\">link<\/a>. The page provides links to the PDFs that are located on the NACO site. The NACO site uses an XML file to determine the page in the AF\/D for each airport. Since XML is a very structured format, it is fairly straightforward to parse the file and convert it to useable HTML. The exact methods I&#8217;m using are specific to this file but the general process works on any XML file.<\/p>\n<p>The first step in the process is to read the XML file. The address is http:\/\/naco.faa.gov\/afd\/afd_17DEC2009.xml, where the date changes every 56 days. Your browser won&#8217;t display the xml, but if you view the source and save it you can begin working with it. The first couple of times through I used BBEdit to convert the XML to HTML tables. There aren&#8217;t too many steps, but it makes sense to automate the process. Any program that supports regular expressions could be used and I chose sed because I&#8217;m familiar with it. <b>Make sure that the CR\/LF setting is changed to Unix or Mac<\/b> if you aren&#8217;t working on a Windows machine. Character encoding should probably be set to Western (ISO Latin 1), since that&#8217;s how it was originally encoded.<br \/>\n<pre class=\"preserve-code-formatting\">\n#### Script to convert NACO A\/FD to HTML tables\n## Remove the first five lines of XML and creator information\n1,5d\n\n## The opening and closing tags aren&#039;t needed\n\/.*airports&gt;\/d\n\n## Make each state a header tag\ns\/&lt;location state=&quot;\/&lt;h1&gt;\/\n\n## Set up the table for each state\ns\/&quot;&gt;\/&lt;\\\/h1&gt;\\\n&lt;table width=&quot;100%&quot; border=&quot;1&quot;&gt;&lt;tr&gt;&lt;th&gt;Airport Name&lt;\\\/th&gt;&lt;th&gt;\nCity Name&lt;\\\/th&gt;&lt;th&gt;ID&lt;\\\/th&gt;&lt;th&gt;Navaid&lt;\\\/th&gt;&lt;th&gt;pdf&lt;\\\/th&gt;&lt;\\\/tr&gt;\/\n\n## Location is the demarcation for each state.\n## Close the table and put an End of State line for splitting\ns\/&lt;\\\/location&gt;\/&lt;\\\/table&gt;\\\nEOS\/g\n\n## Open and close the row for each airport or navaid\ns\/&lt;airport&gt;\/&lt;tr&gt;\/\ns\/&lt;\\\/airport&gt;\/&lt;\\\/tr&gt;\/\n\n## Replace each of the following with td&gt; to open and close the columns\ns\/aptname&gt;\/td&gt;\/g\ns\/aptcity&gt;\/td&gt;\/g\ns\/aptid&gt;\/td&gt;\/g\ns\/navidname&gt;\/td&gt;\/g\n\n##The pdf tags are replaced with a link\ns\/&lt;pdf&gt;\/&lt;td&gt;&lt;a href=&quot;http:\\\/\\\/naco.faa.gov\\\/pdfs\\\/\/\ns\/&lt;\\\/pdf&gt;\/&quot;&gt;pdf&lt;\\\/a&gt;&lt;\\\/td&gt;\/\n\n## Change Tabs to spaces\ns\/&nbsp;&nbsp;\/&nbsp;&nbsp;\/g\n<\/pre><\/p>\n<p>Run this code on the raw XML file and then split it at the EOS line. I use a script to do it.<br \/>\n<pre class=\"preserve-code-formatting\">\n#!\/bin\/bash\nFILENAME=NACO_17DEC2009_\nINDEX=1\nwhile read\ndo\n if [[ &quot;$REPLY&quot; = &quot;EOS&quot; ]]\n then\n&nbsp;&nbsp;(( INDEX++ ))\n else\n&nbsp;&nbsp;echo &quot;$REPLY&quot; &gt;&gt; \/Users\/username\/Desktop\/DEC\/$FILENAME$INDEX\n fi\ndone\n<\/pre><\/p>\n<p>You could modify it to take an argument but I just feed the input file to it.<br \/>\n<pre class=\"preserve-code-formatting\">\n.\/SplitNaco.sh &lt; afd_17DEC2009.xml.html\n<\/pre><\/p>\n<p>You can download the scripts from <a href=\"http:\/\/www.touringmachine.com\/NACO-AFD\/NACO_Scripts.zip\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NACO publishes terminal area charts and the Airport Facility Directory (A\/FD\u2014also known as the green book) and has an online version of the PDFs. The only obvious way to access them is through a map interface. The interface works fine for the terminal area charts but is broken for the A\/FD. It&#8217;s been broken for &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=569\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Downloading the NACO A\/FD<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-569","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=569"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/569\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}