#!/afs/isis/pkg/isis/bin/perl # Last modified: Time-stamp: <2005-01-19 15:17:44 haines> # # Abstract: get and read station data from stations.txt # # Usage: parse_stations.pl > stations_seacoos.txt # parse_stations.pl debug # # Author: Sara Haines (2003-06-19) # # processing steps # (1) create list of stations # a. find which stations in NC, SC, GA, FL, PR (?) and which are METAR stations # b. parse station_id, descrip, lat, lon, elevation, state, metar(X) # c. pair-down to ones that are metar # d. save data to output file $delimiter = "\n"; # if debugging requested print messages to STDOUT if (grep /[debug|DEBUG|d]/, @ARGV) { $debug = 1; } # add libraries needed for this function use Date::Manip; use Time::Local; use LWP::Simple; # print Date and Time and version of perl + patchlevel /1000 # way to do date/time manip through Date::Manip $now=&UnixDate(&ParseDate("today"), "%Y:%m:%d %H:%M:%S"); if ($debug) { print "\n==== Starting: $now ==== Perl Version: $]\n"; } # get station data # $doc = get("http://www.rap.ucar.edu/weather/surface/stations.txt"); $doc = get("file:/afs/isis.unc.edu/depts/marine/workspace/haines/seacoos/metar/archiving/stations.txt"); # splitting a new line drops new lines. @station_data = split(/$delimiter/, $doc); # list of station ids to search for in metar cycle file # line starts with 2 character state or province code (e.g. North Carolina = NC) # line ends with country code (e.g. US, or Bahamas = BS) # stations for nc-coos (NC, VA, SC) # @state_list = ("\^VA ", "\^NC ", "\^SC "); # station list for seacoos # @state_list = ("\^NJ ", "\^DE ", "\^MD ", "\^VA ", # "\^NC ", "\^SC ", "\^GA ", "\^FL ", # "\^TN ", "\^MS ", "\^AL ", "\^LA ", # " BS\$", " CU\$"); # station list with seacoos and carib # @state_list = ("\^NJ ", "\^DE ", "\^MD ", "\^VA ", # "\^NC ", "\^SC ", "\^GA ", "\^FL ", # "\^TN ", "\^MS ", "\^AL ", "\^LA ", # " BS\$", " CU\$", # " HT\$", " DO\$", " JM\$", " BB\$", " BS\$", " TT\$", # " KY\$", " GD\$", "\^PR", " VI\$", " AG\$", " MQ\$", # " GP\$", " KN\$", " LC\$", " AW\$", " AN\$", " VC\$", # " VE\$", " CO\$", " PA\$", " CR\$", " NI\$", " HN\$", # " GT\$", " BZ\$", " MX\$", " SV\$", " SR\$", " BR\$"); # station list with seacoos and carib and Alaska @state_list = ("\^NJ ", "\^DE ", "\^MD ", "\^VA ", "\^NC ", "\^SC ", "\^GA ", "\^FL ", "\^TN ", "\^MS ", "\^AL ", "\^LA ", " BS\$", " CU\$", " HT\$", " DO\$", " JM\$", " BB\$", " BS\$", " TT\$", " KY\$", " GD\$", "\^PR", " VI\$", " AG\$", " MQ\$", " GP\$", " KN\$", " LC\$", " AW\$", " AN\$", " VC\$", " VE\$", " CO\$", " PA\$", " CR\$", " NI\$", " HN\$", " GT\$", " BZ\$", " MX\$", " SV\$", " SR\$", " BR\$", "\^AK "); # @state_list = ("\^NS ", " AR\$"); $pattern = '(' . join('|', @state_list) . ')'; if ($debug) { print($pattern, "\n"); } # match lines in @station_data that contain state abbrev. # plus one whitespace at beginning of line (^) # (e.g.) @station_data_subset = grep /(^NC |^SC )/, @station_data; @stations = grep /$pattern/, @station_data; # narrow down list to just the metar stations foreach $_ (@stations) { if (index($_, "X", 62)==62) { push @metar_stations, $_; } } # print what was found # for ($i=0; $i<=$#metar_stations; $i++) { # print ($metar_stations[$i], "\n"); # } if (1) { # print ICA0 STATION CD LAT LON ELEV foreach $_ (@metar_stations) { print(substr($_, 20, 4), " "); #ICAO print(substr($_, 3, 16), " "); #STATION if (substr($_, 81, 2) eq 'US') { # if (debug) { print "in US";} # if the US then print the state id print(substr($_, 0, 2), " "); #CD } else { # if (debug) { print "not in US ";} # else print the country id print(substr($_, 81, 2), " "); #country code } print(substr($_, 39, 20), " "); #LAT LON ELEV print("\n"); } } if (0) { # print ICAO declat declon STATION CD ELEV foreach $_ (@metar_stations) { print(substr($_, 20, 4), " "); #ICAO $latdeg = substr($_, 39, 2); #LAT $latmin = substr($_, 42, 2); $lathem = substr($_, 43, 1); $lat = $latdeg + ($latmin/60); printf "%5.2f ", $lat; $londeg = substr($_, 47, 3); #LON $lonmin = substr($_, 51, 2); $lonhem = substr($_, 53, 1); $lon = $londeg + ($lonmin/60); printf "%5.2f ", $lon; print(substr($_, 3, 16), " "); #STATION if (substr($_, 81, 2) eq 'US') { # if (debug) { print "in US";} # if the US then print the state id print(substr($_, 0, 2), " "); #CD } else { # if (debug) { print "not in US ";} # else print the country id print(substr($_, 81, 2), " "); #country code } print(substr($_, 55, 4), " "); # ELEV print("\n"); } } #! CD = 2 letter state (province) abbreviation #! STATION = 16 character station long name #! ICAO = 4-character international id #! IATA = 3-character (FAA) id #! SYNOP = 5-digit international synoptic number #! LAT = Latitude (degrees minutes) #! LON = Longitude (degree minutes) #! ELEV = Station elevation (meters) #! M = METAR reporting station. Also Z=obsolete? site #! N = NEXRAD (WSR-88D) Radar site #! V = Aviation-specific flag (V=AIRMET/SIGMET end point, A=ARTCC T=TAF U=T+V) #! U = Upper air (rawinsonde=X) or Wind Profiler (W) site #! A = Auto (A=ASOS, W=AWOS, M=Meso, H=Human, G=Augmented) (H/G not yet impl.) #! C = Office type F=WFO/R=RFC/C=NCEP Center #! # # #ALASKA 26-DEC-00 #CD STATION ICAO IATA SYNOP LAT LONG ELEV M N V U A C #AK ADAK NAS PADK ADK 70454 51 53N 176 39W 4 X 7 US #AK AMBLER PAFM AFM 67 06N 157 51W 88 X 7 US #AK ANAKTUVUK PASS PAKP AKP 68 08N 151 44W 642 X 7 US #AK ANCHORAGE INTL PANC ANC 70273 61 10N 150 01W 38 X T X A 5 US #AK ANCHORAGE/WFO PAFC AFC 61 10N 150 02W 48 F 8 US # #0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 #0 1 2 3 4 5 6 7 8 9