<% Function DateTime(Epoch) dateResult = CDate(#12/31/1969 06:00:00PM#) ' Adjust Epoch UCT time to Houston by subtracting 6 hours. dateResult = DateAdd("s", Epoch, dateResult) DateTime = FormatDateTime(dateResult, vbGeneralDate) End Function ' Get weather report from http://zowie.metnet.navy.mil/cgi-bin/oleg/get-obs ' with the Post method with the parameter name=KHOU, etc. KHOU is the name ' of the weather station. Other stations: ' KHOU: Houston/Hobby ' KEFD: Houston/Ellington ' KSGR: Houston/Sugarland ' KRPE: Sabine Pass ' KRSP2: Sabine ' KBAZ: New Braunfels ' Global constants WEATHER_SOURCE_URL = "http://zowie.metnet.navy.mil/cgi-bin/oleg/get-obs" DEFAULT_STATION = "KHOU" LFCR = chr (013) ' Get user Station parameter. If (Request.Form("station") <> "") Then strStation = Request.Form("station") Else If (Request.QueryString("station") <> "") Then strStation = Request.QueryString("station") Else strStation = DEFAULT_STATION End If End If ' Get Weather XML file: Weather Observation Definition Format (OMF) ' Description of OMF: ' http://zowie.metnet.navy.mil/~spawar/JMV-TNG/XML/OMF.html ' Description of the SYG element: ' http://zowie.metnet.navy.mil/~spawar/JMV-TNG/XML/OMF-SYNOP.html#Elem.SYN.SYG Set xobj = CreateObject("SOFTWING.ASPtear") On Error Resume Next ' URL, action:1 Post, payload, username, password strRetval = xobj.Retrieve(WEATHER_SOURCE_URL, 1, "call_id=" & strStation & "&do-retrieve=Retrieve", "", "") strRetval = "" & LFCR & strRetval If Err.Number <> 0 Then Response.write "Sorry, the server cannot get weather information." Response.End End If ' Invoke XML DOM Parser Set objXML = Server.CreateObject("Microsoft.XMLDOM") objXML.async = False objXML.validateOnParse = False ' Set objFSO = Server.CreateObject("Scripting.FileSystemObject") ' Set objTStream = objFSO.OpenTextFIle(Server.MapPath("/courses/csci4230/asp/xml/weather/data1.xml")) ' strRetval = objTStream.readAll ' ' For some reasons, the Load function does not work. ' ' if objXML.Load(Server.MapPath("/courses/csci4230/asp/xml/weather/scriptingNews.xml")) Then ' Response.write "Successful loading" ' end if ' Use load to load a file or url; loadXML to load a string. objXML.LoadXML(strRetval) If objXML.parseError.errorCode <> 0 Then Response.write "Sorry, no weather information for " & Station & "." ' Response.write "XML Parse Error: " & objXML.parseError.line & ", " & objXML.parseError.reason & "==> " & objXML.parseError.filepos End If strResult = "" ' Loop through all SYN elements Set objLst = objXML.getElementsByTagName("SYN") For i = 0 to (objLst.length - 1) ' Get timestamp. strTimeStamp = objLst.item(i).attributes.getNamedItem("TStamp").nodeValue Set objSYGNode = objLst.item(i).getElementsByTagName("SYG").item(0) strTemperature = objSYGNode.attributes.getNamedItem("T").nodeValue strDewPoint = objSYGNode.attributes.getNamedItem("TD").nodeValue strPressure = objSYGNode.attributes.getNamedItem("P").nodeValue strVisibility = objSYGNode.attributes.getNamedItem("Vis").nodeValue strWind = objSYGNode.attributes.getNamedItem("Wind").nodeValue strResult = strResult & "" & DateTime(CLng(strTimeStamp)) & "" _ & strTemperature & "" _ & strDewPoint & "" _ & strPressure & "" _ & strVisibility & "" _ & strWind & "" & LFCR Next If strResult = "" Then Response.write "Sorry, no weather information for station " & strStation Else Response.write "Weather information for station " & strStation & ":

" Response.write "" _ & strResult _ & "
Time (Houston)Temperature (C)Dew Point (C)Pressure (hPA)Visibility (m)Wind (direction, speed in m/s)
" End If %>