want to use javascript as shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting want to use javascript as shell script
# 1  
Old 09-27-2011
want to use javascript as shell script

Code:
<html>

<head>
<title>Weather & Aviation Page - METAR decoder</title>
<meta name="Title" content="Weather & Aviation Page - METAR decoder">
<meta name="Keywords" content="METAR decoder">
<meta name="Publisher" content="SkyStef">
<meta name="Description" content="SkyStefs weather and aviation homepage">
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style type="text/css">
<!--
A {TEXT-DECORATION: none}
-->
</style>
</head>


<body topmargin="0" leftmargin="0" link="#CCCCCC" vlink="#CCCCCC" alink="#CCCCCC" bgcolor="#CCCCCC" style="font-family: Arial; font-size: 10 pt">

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" bgcolor="#660033" height="75">
  <tr>
    <td width="150" bgcolor="#000000">
    <p align="center"><img border="0" src="https://www.unix.com/images/1985-Kampenhout2.jpg" width="174" height="118"></td>
     <td>
    <p align="center"><font size="5" color="#FFFFFF" face="Times New Roman"><i>SkyStef's weather
    page</i></font></td>
  </tr>
  <tr>
    <td width="150" bgcolor="#111111" bordercolor="#C0C0C0">
    &nbsp;</td>
    <td bordercolor="#C0C0C0" bgcolor="#111111">
    <div align="right">
      <!--webbot bot="Include" U-Include="topmenu.htm" TAG="BODY" startspan -->

<p><font color="#FFFFFF" face="Verdana" size="1">
<a href="index.html"><font color="#FFFFFF">home</font></a>&nbsp; 
|&nbsp; <a href="mailto:skystef@mail.be"><font color="#FFFFFF">e-mail</font></a> &nbsp;&nbsp;&nbsp;</font></p>

<!--webbot bot="Include" i-checksum="10570" endspan --></div>
    </td>
  </tr>
</table>

<p>&nbsp;</p>

<center><!--** START NAVSTUDIO MENU TAGS (203337) **-->
<script language="JavaScript" vqptag="doc_level_settings" vqp_datafile0="new_menu1.js" vqp_uid0=203337>cdd__codebase = "";cdd__codebase203337 = "";</script>
<script language="JavaScript" vqptag="datafile" src="new_menu1.js"></script><script vqptag="placement" vqp_menuid="203337" language="JavaScript">create_menu(203337)</script>
<!--** END NAVSTUDIO MENU TAGS **-->
<br>

<br>
<br>
<br>

<!--
(original script Manuel Heras (manuel@heras-gilsanz.com)
August 2002 -- modified by skystef 2004-2008 -->

<script language="Javascript1.2">
function add_output(text)
{
    document.encoded.decreport.value = document.encoded.decreport.value + text;
}

function is_num_digit(ch)
{
    return ( (ch == '0') || (ch == '1') || (ch == '2') || (ch == '3') ||
             (ch == '4') || (ch == '5') || (ch == '6') || (ch == '7') ||
             (ch == '8') || (ch == '9') );
}

function is_alphabetic_char(ch)
{
    return ( (ch >= 'A') && (ch <= 'Z') );
}

function decode_token(token)
{
    // Check if token is "calm wind"
    if(token == "00000KT")

    {
        add_output("Wind...............: calm\n");
        return;
        
    }
     // Check if token is "calm wind"
    if(token == "00000MPS")


    {
        add_output("Wind...............: calm\n");
        return;
        
    }
    // Check if token is "calm wind"
    if(token == "00000KMH")


    {
        add_output("Wind...............: calm\n");
        return;
        
    }


// Check if token is Wind indication
    var reWindKT  = /^(\d{3}|VRB)(\d{2,3})(G\d{2,3})?(KT|MPS|KMH)$/;
    if(reWindKT.test(token))
    {
        // Wind token: dddss(s){Gss(s)}KT -- ddd is true direction, ss(s) speed in knots
        var myArray = reWindKT.exec(token);
        var units = myArray[4];
        add_output("Wind...............: ");
        if(myArray[1]=="VRB")
          add_output(" variable in direction");
        else
          add_output("true direction = " + myArray[1] + " degrees");
        add_output("; speed = " + parseInt(myArray[2],10));
        if(units=="KT") add_output(" knots");
        else if(units=="KMH") add_output(" km/h");
        else if(units=="MPS") add_output(" m/s");
        if(myArray[3] != null)
        {
           
            if (myArray[3]!="")
            {
                add_output(" with gusts of " + parseInt(myArray[3].substr(1,myArray[3].length),10));
                if(units=="KT") add_output(" knots");
                else if(units=="KMH") add_output(" km/h");
                else if(units=="MPS") add_output(" m/s");
             }
        }

        add_output("\n");  return;
    }


    // Check if token is "variable wind direction"
    var reVariableWind = /^(\d{3})V(\d{3})$/;
    if(reVariableWind.test(token))
    {
        // Variable wind direction: aaaVbbb, aaa and bbb are directions in clockwise order
        add_output("Wind direction.....: variable between "+token.substr(0,3)+" and "+token.substr(4,3)+" degrees \n");
        return;
    }


    // Check if token is visibility
    var reVis = /^(\d{4})(N|S)?(E|W)?$/;
    if(reVis.test(token))
    {
        var myArray = reVis.exec(token);
        add_output("Visibility.........: ");
        if(myArray[1]=="9999")
          add_output("10 km or more");
        else if (myArray[1]=="0000")
          add_output("less than 50 m");
        else
          add_output(parseInt(myArray[1],10) + " m");

    var dir = "";
        if(typeof myArray[2] != "undefined")
        {
          dir=dir + myArray[2];
        }
        if(typeof myArray[3] != "undefined")
        {
          dir=dir + myArray[3];
        }
        if(dir != "")
        {
          add_output(" direction ");
          if(dir=="N") add_output("North");
          else if(dir=="NE") add_output("North East");
          else if(dir=="E") add_output("East");
          else if(dir=="SE") add_output("South East");
          else if(dir=="S") add_output("South");
          else if(dir=="SW") add_output("South West");
          else if(dir=="W") add_output("West");
          else if(dir=="NW") add_output("North West");
        }
        add_output("\n"); return;
    }

    // Check if token is Statute-Miles visibility
     var reVisUS = /(SM)$/;
     if(reVisUS.test(token))
     {
      add_output("Visibility: ");
      var myVisArray = token.split("S");
      add_output(myVisArray[0]);
      add_output(" Statute Miles\n");
    }
     

    // Check if token is QNH indication in mmHg or hPa
    var reQNHhPa = /Q\d{3,4}/;
    if(reQNHhPa.test(token))
    {
        // QNH token: Qpppp -- pppp is pressure hPa 
        add_output("QNH (msl pressure).: ");
        add_output(parseInt(token.substr(1,4),10) + " hPa"); 
        add_output("\n");  return;
    }

    // Check if token is QNH indication in mmHg: Annnn
    var reINHg = /A\d{4}/;
    if(reINHg.test(token))
    {
        add_output("QNH: ");
        add_output(token.substr(1,2) + "." + token.substr(3,4) + " inHg");
        add_output("\n");  return;
    } 


      // Check if token is NOSIG
      if(token == "NOSIG")
    {
        add_output("Next 2 hours.......: no significant changes\n");
        return;
    }



    // Check if token is runway visual range (RVR) indication
    var reRVR = /^R(\d{2})(R|C|L)?\/(M|P)?(\d{4})(V\d{4})?(U|D|N)?$/;
    if(reRVR.test(token))
    {
        var myArray = reRVR.exec(token);
        add_output("Runway visibilty...: on runway ");
        add_output(myArray[1]);
        if(typeof myArray[2] != "undefined")
        {
          if(myArray[2]=="L") add_output(" Left");
          else if(myArray[2]=="R") add_output(" Right");
          else if(myArray[2]=="C") add_output(" Central");
        }
        add_output(", touchdown zone visual range is ");
        if(typeof myArray[5] != "undefined")
        {
                 // Variable range
            add_output("variable from a minimum of ");
            if(myArray[3]=="P") add_output("more than ");
            else if(myArray[3]=="M") add_output("less than ");
            add_output(myArray[4]);
            add_output(" meters");
            add_output(" until a maximum of "+myArray[5].substr(1,myArray[5].length)+" meters");
            if(myArray[5]=="P") add_output("more than ");
       

        }
        else
        {
          // Single value
          if( (typeof myArray[3] != "undefined") &&
              (typeof myArray[4] != "undefined")    )
          {
            if(myArray[3]=="P") add_output("more than ");
            else if(myArray[3]=="M") add_output("less than ");
            add_output(myArray[4]);
            add_output(" meters");
          }

        }
        if( (myArray.length > 5) && (typeof myArray[6] != "undefined") )
        {
          if(myArray[6]=="U") add_output(", and increasing");
          else if(myArray[6]=="D") add_output(", and decreasing");
        }
        add_output("\n");
        return;
    }


    // Check if token is CAVOK
    if(token=="CAVOK")
    {
        add_output("CAVOK conditions...: Ceiling And Visibility OK, which means visibility 10 kilometers or more, no cloud below 5000 feet or below the minimum sector altitude (whichever is greater), no cumulonimbus, and no weather of significance to aviation at the aerodrome or its vicinity\n");
        return;
    }




    // Check if token is a present weather code - The regular expression is a bit
    // long, because several precipitation types can be joined in a token, and I
    // don't see a better way to get all the codes.
    var reWX = /^(\-|\+|)?(VC)?(MI|BC|DR|BL|SH|TS|FZ|PR)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(SH|TS|DZ|RA|SN|SG|IC|PL|GR|GS|BR|FG|FU|VA|DU|SA|HZ|PO|SQ|FC|SS|DS)$/;
    if(reWX.test(token))
    {
        add_output("Weather............: ");
        var myArray = reWX.exec(token);
        for(var i=1;i<myArray.length; i++)
        {
            if(myArray[i] == "-") add_output("light ");
            if(myArray[i] == "+") add_output("heavy ");
            if(myArray[i] == "VC") add_output("in the vicinity ");
            if(myArray[i] == "MI") add_output("shallow ");
            if(myArray[i] == "BC") add_output("patches of ");
            if(myArray[i] == "SH") add_output("shower(s) of ");
            if(myArray[i] == "TS") add_output("thunderstorm ");
            if(myArray[i] == "FZ") add_output("freezing ");
            if(myArray[i] == "PR") add_output("partial ");
            if(myArray[i] == "DZ") add_output("drizzle ");
            if(myArray[i] == "RA") add_output("rain ");
            if(myArray[i] == "SN") add_output("snow ");
            if(myArray[i] == "SG") add_output("snow grains ");
            if(myArray[i] == "IC") add_output("ice crystals ");
            if(myArray[i] == "PL") add_output("ice pellets ");
            if(myArray[i] == "GR") add_output("hail ");
            if(myArray[i] == "GS") add_output("small hail and/or snow pellets ");
            if(myArray[i] == "BR") add_output("mist ");
            if(myArray[i] == "FG") add_output("fog ");
            if(myArray[i] == "FU") add_output("smoke ");
            if(myArray[i] == "VA") add_output("volcanic ash ");
            if(myArray[i] == "DU") add_output("widespread dust ");
            if(myArray[i] == "SA") add_output("sand ");
            if(myArray[i] == "HZ") add_output("haze ");
            if(myArray[i] == "PO") add_output("dust/sand whirls (dust devils)");
            if(myArray[i] == "SQ") add_output("squall ");
            if(myArray[i] == "FC") add_output("funnel cloud(s) (tornado or waterspout) ");
            if(myArray[i] == "SS") add_output("sandstorm ");
            if(myArray[i] == "DS") add_output("duststorm ");
            if(myArray[i] == "DR") add_output("low drifting ");
            if(myArray[i] == "BL") add_output("blowing ");
        }
        add_output("\n");  return;
    }


    // Check if token is recent weather observation
    var reREWX = /^RE(\-|\+)?(VC)?(MI|BC|BL|DR|SH|TS|FZ|PR)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS|BR|FG|FU|VA|DU|SA|HZ|PO|SQ|FC|SS|DS)?$/;
    if(reREWX.test(token))
    {
        add_output("Since the previous observation (but not at present), the following\nmeteorological phenomena were observed: ");
        var myArray = reREWX.exec(token);
        for(var i=1;i<myArray.length; i++)
        {
            if(myArray[i] == "-") add_output("light ");
            if(myArray[i] == "+") add_output("heavy ");
            if(myArray[i] == "VC") add_output("in the vicinity ");
            if(myArray[i] == "MI") add_output("shallow ");
            if(myArray[i] == "BC") add_output("patches of ");
            if(myArray[i] == "SH") add_output("shower(s) of ");
            if(myArray[i] == "TS") add_output("thunderstorm ");
            if(myArray[i] == "FZ") add_output("freezing ");
            if(myArray[i] == "PR") add_output("partial ");
            if(myArray[i] == "DZ") add_output("drizzle ");
            if(myArray[i] == "RA") add_output("rain ");
            if(myArray[i] == "SN") add_output("snow ");
            if(myArray[i] == "SG") add_output("snow grains ");
            if(myArray[i] == "IC") add_output("ice crystals ");
            if(myArray[i] == "PL") add_output("ice pellets ");
            if(myArray[i] == "GR") add_output("hail ");
            if(myArray[i] == "GS") add_output("small hail and/or snow pellets ");
            if(myArray[i] == "BR") add_output("mist ");
            if(myArray[i] == "FG") add_output("fog ");
            if(myArray[i] == "FU") add_output("smoke ");
            if(myArray[i] == "VA") add_output("volcanic ash ");
            if(myArray[i] == "DU") add_output("widespread dust ");
            if(myArray[i] == "SA") add_output("sand ");
            if(myArray[i] == "HZ") add_output("haze ");
            if(myArray[i] == "PO") add_output("dust/Sand whirls (dust devils) ");
            if(myArray[i] == "SQ") add_output("squall ");
            if(myArray[i] == "FC") add_output("funnel cloud(s) (tornado or waterspout) ");
            if(myArray[i] == "SS") add_output("sandstorm ");
            if(myArray[i] == "DS") add_output("duststorm ");
            if(myArray[i] == "DR") add_output("low drifting ");
            if(myArray[i] == "BL") add_output("blowing ");

        }
        add_output("\n"); return;
    }


    // Check if token is temperature / dewpoint pair
    var reTempDew = /^(M?\d\d|\/\/)\/(M?\d\d)?$/;
    if(reTempDew.test(token))
    {
        var myArray = reTempDew.exec(token);

        if(myArray[1].charAt(0)=='M')
          add_output("Temperature........: -" + myArray[1].substr(1,2) + " degrees Celsius\n");
        else
          add_output("Temperature........: " + myArray[1].substr(0,2) + " degrees Celsius\n");

        if(myArray[2]!="")
        {
          if(myArray[2].charAt(0)=='M')
            add_output("Dewpoint...........: -" + myArray[2].substr(1,2) + " degrees Celsius\n");
          else
            add_output("Dewpoint...........: " + myArray[2].substr(0,2) + " degrees Celsius\n");
        }

        return;
    }


    // Check if token is "sky clear" indication
    if(token=="SKC")
    {
        add_output("no clouds and no restrictions on vertical visibility\n");
        return;
    }


    // Check if token is "vertical visibility" indication
    var reVV = /^VV(\d{3}|\/{3})$/;
    if(reVV.test(token))
    {
        // VVddd -- ddd is vertical distance, or /// if unspecified
        var myArray = reVV.exec(token);
        add_output("Vertical visibility");
        if(myArray[1] == "///")
          add_output(" has indefinite ceiling\n");
        else
          add_output(": " + (100*parseInt(myArray[1],10)) + " feet\n");

        return;
    }


    // Check if token is cloud indication
    var reCloud = /^(FEW|SCT|BKN|OVC)(\d{3})(CB|TCU)?$/;
    if(reCloud.test(token))
    {
        // Clouds: aaadddkk -- aaa indicates amount of sky covered, ddd distance over
        //                     aerodrome level, and kk the type of cloud.
        var myArray = reCloud.exec(token);
        add_output("Cloud coverage.....: ");
        if(myArray[1] == "FEW") add_output("few (1 to 2 oktas)");
        else if(myArray[1] == "SCT") add_output("scattered (3 to 4 oktas)");
        else if(myArray[1] == "BKN") add_output("broken (5 to 7 oktas)");
        else if(myArray[1] == "OVC") add_output("overcast (8 oktas)");
       
        add_output(" at " + (100*parseInt(myArray[2],10)) + " feet above aerodrome level");

        if(myArray[3] == "CB") add_output(" cumulonimbus");
        else if(myArray[3] == "TCU") add_output(" towering cumulus");

        add_output("\n"); return; 
    }


    // Check if token is part of a wind-shear indication
    var reRWY = /^RWY(\d{2})(L|C|R)?$/;
    if(token=="WS")       { add_output("there is wind-shear in "); return; }
    else if(token=="ALL") { add_output("all "); return; }
    else if(token=="RWY") { add_output("runways\n"); return; }
    else if (reRWY.test(token))
    {
        var myArray = reRWY.exec(token);
        add_output("runway "+myArray[1]);
        if(myArray[2]=="L")      add_output(" Left");
        else if(myArray[2]=="C") add_output(" Central");
        else if(myArray[2]=="R") add_output(" Right");
        add_output("\n");
        return;
    }
    

    // Check if token is no-significant-weather indication
    if(token=="NSW")
    {
        add_output("no significant weather\n");
        return;
    }


    // Check if token is no-significant-clouds indication
    if(token=="NSC")
    {
        add_output("Clouds.............: no significant clouds are observed below 5000 feet or below the minimum sector altitude (whichever is higher)\n");
        return;
    }


// Check if token is part of trend indication
    if(token=="BECMG")
    {
        add_output("Next 2hrs gradually:\n");
        return;
    }
    if(token=="TEMPO")
    {
        add_output("Next 2hrs temporary:\n");
        return;
    }
    var reFM = /^FM(\d{2})(\d{2})Z?$/;
    if(reFM.test(token))
    {
        var myArray = reFM.exec(token);
        add_output("From "+myArray[1]+":"+myArray[2]+" UTC.....:\n");
        return;
    }
    var reTL = /^TL(\d{2})(\d{2})Z?$/;
    if(reTL.test(token))
    {
        var myArray = reTL.exec(token);
        add_output("Until "+myArray[1]+":"+myArray[2]+" UTC....:\n");
        return;
    }
    var reAT = /^AT(\d{2})(\d{2})Z?$/;
    if(reAT.test(token))
    {
        var myArray = reAT.exec(token);
        add_output("At "+myArray[1]+":"+myArray[2]+" UTC.......:\n");
        return;
    }



    // Check if item is runway state group
    var reRSG = /^(\d\d)(\d|C|\/)(\d|L|\/)(\d\d|RD|\/)(\d\d)$/;
    if(reRSG.test(token))
    {
        var myArray = reRSG.exec(token);
        add_output("Runway state.......:");

        // Runway designator (first 2 digits)
        var r = parseInt(myArray[1],10);
        if(r < 50) add_output(" Runway " + myArray[1] + " (or "+myArray[1]+" Left): ");
        else if(r < 88) add_output(" Runway " + (r-50) + " Right: ");
        else if(r == 88) add_output(" All runways: ");

        // Check if "CLRD" occurs in digits 3-6
        if(token.substr(2,4)=="CLRD") add_output("clear, ");
        else
        {
          // Runway deposits (third digit)
          if(myArray[2]=="0") add_output("clear and dry, ");
          else if(myArray[2]=="1") add_output("damp, ");
          else if(myArray[2]=="2") add_output("wet or water patches, ");
          else if(myArray[2]=="3") add_output("rime or frost covered, ");
          else if(myArray[2]=="4") add_output("dry snow, ");
          else if(myArray[2]=="5") add_output("wet snow, ");
          else if(myArray[2]=="6") add_output("slush, ");
          else if(myArray[2]=="7") add_output("ice, ");
          else if(myArray[2]=="8") add_output("compacted or rolled snow, ");
          else if(myArray[2]=="9") add_output("frozen ruts or ridges, ");
          else if(myArray[2]=="/") add_output("deposit not reported, ");

          // Extent of runway contamination (fourth digit)
          if(myArray[3]=="1") add_output("contamination 10% or less, ");
          else if(myArray[3]=="2") add_output("contamination 11% to 25%, ");
          else if(myArray[3]=="5") add_output("contamination 26% to 50%, ");
          else if(myArray[3]=="9") add_output("contamination 51% to 100%, ");
          else if(myArray[3]=="/") add_output("contamination not reported, ");

          // Depth of deposit (fifth and sixth digits)
          if(myArray[4]=="//") add_output("depth of deposit not reported, ");
          else
          {
              var d = parseInt(myArray[4],10);
              if(d == 0) add_output("deposit less than 1 mm deep, ");
              else if ((d >  0) && (d < 91)) add_output("deposit is "+d+" mm deep, ");
              else if (d == 92) add_output("deposit is 10 cm deep, ");
              else if (d == 93) add_output("deposit is 15 cm deep, ");
              else if (d == 94) add_output("deposit is 20 cm deep, ");
              else if (d == 95) add_output("deposit is 25 cm deep, ");
              else if (d == 96) add_output("deposit is 30 cm deep, ");
              else if (d == 97) add_output("deposit is 35 cm deep, ");
              else if (d == 98) add_output("deposit is 40 cm or more deep, ");
              else if (d == 99) add_output("runway(s) is/are non-operational due to snow, slush, ice, large drifts or runway clearance, but depth of deposit is not reported, ");
          }
        }

        // Friction coefficient or braking action (seventh and eighth digit)
        if(myArray[5]=="//") add_output("braking action not reported");
        else
        {
            var b = parseInt(myArray[5],10);
            if(b<91) add_output("friction coefficient 0."+myArray[5]);
            else
            {
                 if(b == 91) add_output("braking action is poor");
                 else if(b == 92) add_output("braking action is medium/poor");
                 else if(b == 93) add_output("braking action is medium");
                 else if(b == 94) add_output("braking action is medium/good");
                 else if(b == 95) add_output("braking action is good");
                 else if(b == 99) add_output("braking action figures are unreliable");
            }
        }
        add_output("\n"); return;
    } 

    if(token=="SNOCLO")
    {
        add_output("Aerodrome is closed due to snow on runways\n");
        return;
    }

    // Check if item is sea status indication
    reSea = /^W(M)?(\d\d)\/S(\d)/;
    if(reSea.test(token))
    {
        var myArray = reSea.exec(token);
        add_output("Sea surface temperature: ");
        if(myArray[1]=="M")
            add_output("-");
        add_output(parseInt(myArray[2],10) + " degrees Celsius\n");

        add_output("Sea waves have height: ");
        if(myArray[3]=="0") add_output("0 m (calm)\n");
        else if(myArray[3]=="1") add_output("0-0,1 m\n");
        else if(myArray[3]=="2") add_output("0,1-0,5 m\n");
        else if(myArray[3]=="3") add_output("0,5-1,25 m\n");
        else if(myArray[3]=="4") add_output("1,25-2,5 m\n");
        else if(myArray[3]=="5") add_output("2,5-4 m\n");
        else if(myArray[3]=="6") add_output("4-6 m\n");
        else if(myArray[3]=="7") add_output("6-9 m\n");
        else if(myArray[3]=="8") add_output("9-14 m\n");
        else if(myArray[3]=="9") add_output("more than 14 m (huge!)\n");
        return;
    }
}

function metar_decode(text)
{
    document.encoded.decreport.value = "";

    // Join newline-separated pieces...
    var newlineJoined = text.replace(/\n/, " ");

    // An '=' finishes the report
    var equalPosition = newlineJoined.indexOf("=");
    if (equalPosition > -1)
    {
        alert("End of a METAR report is indicated by '='. We only decode until the first '='!!");
        newlineJoined = newlineJoined.substr(0,equalPosition);
    }
    

    arrayOfTokens = newlineJoined.split(" ");
    var numToken = 0;

    // Check if initial token is non-METAR date
    var reDate = /^\d\d\d\d\/\d\d\/\d\d/;
    if (reDate.test(arrayOfTokens[numToken]))
        numToken++;

    // Check if initial token is non-METAR time
    var reTime = /^\d\d:\d\d/;
    if (reTime.test(arrayOfTokens[numToken]))
        numToken++;

    // Check if initial token indicates type of report
    if(arrayOfTokens[numToken] == "METAR")
        numToken++;
    else if(arrayOfTokens[numToken] == "SPECI")
    {
        add_output("Report is a SPECIAL report\n");
        numToken++;
    }
    

    // Parse location token
    if (arrayOfTokens[numToken].length == 4)
    {
        add_output("Location...........: " + arrayOfTokens[numToken] + "\n");
        numToken++;
    }
    else
    {
        add_output("Invalid report: malformed location token '" + arrayOfTokens[numToken] + "' \n-- it should be 4 characters long!");
        return;
    }


    // Parse date-time token -- we allow time specifications without final 'Z'
    if ( (
           ( (arrayOfTokens[numToken].length == 7) &&
             (arrayOfTokens[numToken].charAt(6) == 'Z') ) ||
           ( arrayOfTokens[numToken].length == 6 )
         ) &&
         is_num_digit(arrayOfTokens[numToken].charAt(0)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(1)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(2)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(3)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(4)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(5))    )
    {
        add_output("Day of month.......: " + arrayOfTokens[numToken].substr(0,2) + "\n");
        add_output("Time...............: " + arrayOfTokens[numToken].substr(2,2) +":" +
                              arrayOfTokens[numToken].substr(4,2) + " UTC");

        if(arrayOfTokens[numToken].length == 6)
            add_output(" (Time specification is non-compliant!)");

        add_output("\n");
        numToken++;
    }
    else
    {
        add_output("Time token not found or with wrong format!");
        return;
    }
    

    // Check if "AUTO" or "COR" token comes next.
    if (arrayOfTokens[numToken] == "AUTO")
    {
        add_output("Report is fully automated, with no human intervention or oversight\n");
        numToken++;
    }
    else if (arrayOfTokens[numToken] == "COR")
    {
        add_output("Report is a correction over a METAR or SPECI report\n");
        numToken++;
    }

    // Parse remaining tokens
    for (var i=numToken; i<arrayOfTokens.length; i++)
    {
        if(arrayOfTokens[i].length > 0)
        {
            decode_token(arrayOfTokens[i].toUpperCase());
        }
    }
}

function ejem(text)
{
    alert(text);
}

</script>
<h1><center>METAR Decoder</center> </h1>
<p>&nbsp;</p>
<p>&nbsp;</p>
<center><table border="0" width="88%">
  <tr>
    <td width="93%">
<center><font size="3">
Type or copy-paste a METAR report in the text box, press &quot;Decode&quot; and the report will be
decoded into plain language.</font></center></td>
  </tr>
</table>
<center>
<p>&nbsp;</p>
<table>
<tr>
<td>
<p>
&nbsp;
</p>

<center><form NAME="encoded" align="center">
        Encoded report in METAR format:
  <br>
  <textarea name="report" cols="80" rows="5"></textarea>
  <br>
    <input type="button" name="decode" value="Decode" onClick="metar_decode(this.form.report.value);">
    <input type="button" name="reset" value="Clear" onClick="this.form.report.value=''; this.form.decreport.value='';">
    <input type="button" name="example" value="Example " onClick="this.form.report.value='EBBR 212320Z 19020KT 5000 TSGSRA SCT015TCU BKN022CB 07/06 Q0993 BECMG 9999 NSW'; metar_decode(this.form.report.value);">
<br><br>
Decoded report:
<br>
<textarea name="decreport" cols="80" rows="30"></textarea>
</form>
<p>
<left><p>Real time METARS &amp; TAFS can&nbsp;be found via:<p><A HREF="http://www.skystef.be/metar-taf.htm"><IMG SRC="https://www.unix.com/images/Mini/taf.jpg" width="218" height="23"></a>
</center>
</td>
</tr>
</table>
<p>&nbsp;
</p>



<table border="0" width="80%">
  <tr>
    <td width="80%"><b>Note 1</b>: Javascript must be enabled.<br>
      <br>
      <b>
      Note 2</b>: US-specific METAR format is not supported.<br>
      <br>
      <b>Note 3</b>:
<font size="3">
When copy-paste: in some cases add one space
behind the METAR, otherwise the last part called &quot;TREND&quot; will not, or
only partly, decoded.</font><br>
      <br>
      <b>
      Note 4</b>: METARS of military airfields contain behind the QNH a colour state.
      The first colour mean the actual condition, if a second colour is given
      this means an outlook for the next 2 hours. The colour state decoding: &nbsp;<br>
      <br>
      <table border="1" width="100%">
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0"><b><font size="2">&nbsp;
            <!--[if supportFields]><span
  style='mso-element:field-end'></span><![endif]-->Visibility / lowest cloudbase
            (3 oktas or more)</font></b></td>
          <td width="14%" align="center" bgcolor="#C0C0C0">&gt;= 2500 ft</td>
          <td width="14%" align="center" bgcolor="#C0C0C0">1500-2499 ft</td>
          <td width="14%" align="center" bgcolor="#C0C0C0">700-1499 ft</td>
          <td width="14%" align="center" bgcolor="#C0C0C0">300-699 ft</td>
          <td width="15%" align="center" bgcolor="#C0C0C0">200-299 ft</td>
          <td width="15%" align="center" bgcolor="#C0C0C0">&lt; 200 ft</td>
        </tr>
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0">&gt;=
            8 km<o:p>
            &nbsp;</td>
          <td width="14%" align="center" bgcolor="#00FFFF">BLU</td>
          <td width="14%" align="center" bgcolor="#FFFFFF">WHT</td>
          <td width="14%" align="center" bgcolor="#00FF00">GRN</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="15%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
        </tr>
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0">5000-7999 m</td>
          <td width="14%" align="center" bgcolor="#FFFFFF">WHT</td>
          <td width="14%" align="center" bgcolor="#FFFFFF">WHT</td>
          <td width="14%" align="center" bgcolor="#00FF00">GRN</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="15%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
        </tr>
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0">3700-4999 m</td>
          <td width="14%" align="center" bgcolor="#00FF00">GRN</td>
          <td width="14%" align="center" bgcolor="#00FF00">GRN</td>
          <td width="14%" align="center" bgcolor="#00FF00">GRN</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="15%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
        </tr>
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0">1600-3699 m</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="14%" align="center" bgcolor="#FFFF00">YLO</td>
          <td width="15%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
        </tr>
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0">800-1599 m</td>
          <td width="14%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="14%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="14%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="14%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="15%" align="center" bgcolor="#FF9900">AMB</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
        </tr>
        <tr>
          <td width="14%" align="center" bgcolor="#C0C0C0">&lt; 800 m</td>
          <td width="14%" align="center" bgcolor="#FF0000">RED</td>
          <td width="14%" align="center" bgcolor="#FF0000">RED</td>
          <td width="14%" align="center" bgcolor="#FF0000">RED</td>
          <td width="14%" align="center" bgcolor="#FF0000">RED</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
          <td width="15%" align="center" bgcolor="#FF0000">RED</td>
        </tr>
      </table>
      

       </center></center>
  <p>&nbsp;</p>

  <p><b>Note 5</b>: Although the decoder has been tested it still might contain some
      erros. If you find some of them please contact me.</p>

    </td>
  </tr>
</table>
<p>&nbsp;
</p>



<p>&nbsp;
</p>

<hr>

<p>&nbsp;
</p>



<p>
<b><font size="6">TAF Decoder</font></b>
</p>



<p>
&nbsp;
</p>



<p><font size="3">The TAF code is essentially the same as the METAR code but with following
additions</font>
</p>



<p>
&nbsp;
</p>



<table border="1" width="80%">
  <tr>
    <td width="20%" bgcolor="#C0C0C0"><font size="3">Group</font></td>
    <td width="60%" bgcolor="#C0C0C0"><center>Explanation</td>
  </tr>
  <tr>
    <td width="20%"><code><font size="3"><strong>BECMG</strong>  </font><font size="2"> aabb</font></code></td>
    <td width="60%">A gradual change in weather between <code>aa</code> and <code>bb</code>
      hours.</td>
  </tr>
  <tr>
    <td width="20%"><code><font size="3"><strong>TEMPO</strong>  </font><font size="2"> aabb</font></code></td>
    <td width="60%">Temporary (less than half of period <font size="2">aabb</font>) changes in weather between <code>aa</code>
      and <code>bb</code> hours.</td>
  </tr>
  <tr>
    <td width="20%"><code><strong><font size="3">FM</font></strong><font size="2">hhmm</font></code></td>
    <td width="60%">A quick (in less than 60 min) change in weather occurring at
      <code>hh</code> hours and <code>mm</code> minutes</td>
  </tr>
  <tr>
    <td width="20%"><code><strong><font size="3">TL</font></strong><font size="2">hhmm</font></code></td>
    <td width="60%">A change in weather by <code>hh</code> hours and <code>mm</code>
      minutes.</td>
  </tr>
  <tr>
    <td width="20%"><code><strong><font size="3">AT</font></strong><font size="2">hhmm</font></code></td>
    <td width="60%">A change in weather occurring at <code>hh</code> hours and <code>mm</code>
      minutes.</td>
  </tr>
  <tr>
    <td width="20%"><code><font size="3"><strong>PROB</strong>  </font><font size="2"> pp
      aabb</font></code></td>
    <td width="60%">Following weather will take place with a probability of <code>pp</code>
      percent between aa and bb hours</td>
  </tr>
  <tr>
    <td width="20%"><code><strong><font size="3">NSW</font></strong></code></td>
    <td width="60%">No significant weather.</td>
  </tr>
  <tr>
    <td width="20%"><code><font size="3"><strong>T</strong></font><font size="2">tt/hh</font><strong><font size="3">Z</font></strong></code></td>
    <td width="60%">The temperature is predicted to be <code>tt</code> degrees
      Celsius at <code>hh</code> hours.</td>
  </tr>
  <tr>
    <td width="20%"><code><font size="3"><strong>TX</strong></font><font size="2">tt/hh</font><strong><font size="3">Z</font></strong></code></td>
    <td width="60%">The maximum temperature is predicted to be <code>tt</code>
      degrees Celsius at <code>hh</code> hours.</td>
  </tr>
  <tr>
    <td width="20%"><code><font size="3"><strong>TN</strong></font><font size="2">tt/hh</font><strong><font size="3">Z</font></strong></code></td>
    <td width="60%">The minimum temperature is predicted to be <code>tt</code>
      degrees Celsius at <code>hh</code> hours.</td>
  </tr>
</table>



<p>&nbsp;
</p>



<p>&nbsp;
</p>



<p>&nbsp;
</p>



<p>&nbsp;
</p>



<p>&nbsp;</p>

    <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


<CENTER>

<!-- Start of StatCounter Code -->
<script type="text/javascript" language="javascript">
var sc_project=846536; 
var sc_partition=6; 
var sc_security="841e6cfa"; 
</script>

<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img  src="http://c7.statcounter.com/counter.php?sc_project=846536&amp;java=0&amp;security=841e6cfa" alt="web page hit counter" border="0"></a> </noscript>
<!-- End of StatCounter Code -->



 <!-- Start of belstat.be Counter -->
<script type="text/javascript">
        <!--
        d=document;
        col="";scr=0;b=navigator.appName;
        scr=screen.width+"*"+screen.height;
        ref=parent==self ? escape(window.document.referrer) : escape(top.document.referrer);
        pag=escape(document.URL);
        if (b != "Netscape") {col=screen.colorDepth}
        else {col=screen.pixelDepth}
        if(col=="undefined"){col="";}
        d.write("<a href=http://www.belstat.be/viewstat.asp?UserID=skystef&lang=en target=_blank><img border=0 src=\"http://www.belstat.be/regstat.aspx?");
        d.write("UserID=skystef&BColor=blue&refer=" + ref + "&pag=" + pag + "&b=" + b + "&col=" + col + "&scr=" + scr);
        d.write("\" align=center width=16 height=16 alt=\"Monitored by BelStat - Your Site Counts\"><\/a>");
        // -->
</script>
<!-- End of belstat.be Counter -->


</body>

</html>


Last edited by Scott; 09-27-2011 at 06:14 AM.. Reason: Code tags
# 2  
Old 09-27-2011
??????????????????

whats your question ?
# 3  
Old 09-27-2011
i want that the work which is done by this html page (javascript) can be done by making a shell script....
# 4  
Old 09-27-2011
hmm, what you tried so far ?

please use [code] tag The UNIX and Linux Forums - BB Code List
# 5  
Old 09-27-2011
mainly i want to use the following script in linux (shell scriipt)

Code:
<script language="Javascript1.2">
function add_output(text)
{
    document.encoded.decreport.value = document.encoded.decreport.value + text;
}

function is_num_digit(ch)
{
    return ( (ch == '0') || (ch == '1') || (ch == '2') || (ch == '3') ||
             (ch == '4') || (ch == '5') || (ch == '6') || (ch == '7') ||
             (ch == '8') || (ch == '9') );
}

function is_alphabetic_char(ch)
{
    return ( (ch >= 'A') && (ch <= 'Z') );
}

function decode_token(token)
{
    // Check if token is "calm wind"
    if(token == "00000KT")

    {
        add_output("Wind...............: calm\n");
        return;
        
    }
     // Check if token is "calm wind"
    if(token == "00000MPS")


    {
        add_output("Wind...............: calm\n");
        return;
        
    }
    // Check if token is "calm wind"
    if(token == "00000KMH")


    {
        add_output("Wind...............: calm\n");
        return;
        
    }


// Check if token is Wind indication
    var reWindKT  = /^(\d{3}|VRB)(\d{2,3})(G\d{2,3})?(KT|MPS|KMH)$/;
    if(reWindKT.test(token))
    {
        // Wind token: dddss(s){Gss(s)}KT -- ddd is true direction, ss(s) speed in knots
        var myArray = reWindKT.exec(token);
        var units = myArray[4];
        add_output("Wind...............: ");
        if(myArray[1]=="VRB")
          add_output(" variable in direction");
        else
          add_output("true direction = " + myArray[1] + " degrees");
        add_output("; speed = " + parseInt(myArray[2],10));
        if(units=="KT") add_output(" knots");
        else if(units=="KMH") add_output(" km/h");
        else if(units=="MPS") add_output(" m/s");
        if(myArray[3] != null)
        {
           
            if (myArray[3]!="")
            {
                add_output(" with gusts of " + parseInt(myArray[3].substr(1,myArray[3].length),10));
                if(units=="KT") add_output(" knots");
                else if(units=="KMH") add_output(" km/h");
                else if(units=="MPS") add_output(" m/s");
             }
        }

        add_output("\n");  return;
    }


    // Check if token is "variable wind direction"
    var reVariableWind = /^(\d{3})V(\d{3})$/;
    if(reVariableWind.test(token))
    {
        // Variable wind direction: aaaVbbb, aaa and bbb are directions in clockwise order
        add_output("Wind direction.....: variable between "+token.substr(0,3)+" and "+token.substr(4,3)+" degrees \n");
        return;
    }


    // Check if token is visibility
    var reVis = /^(\d{4})(N|S)?(E|W)?$/;
    if(reVis.test(token))
    {
        var myArray = reVis.exec(token);
        add_output("Visibility.........: ");
        if(myArray[1]=="9999")
          add_output("10 km or more");
        else if (myArray[1]=="0000")
          add_output("less than 50 m");
        else
          add_output(parseInt(myArray[1],10) + " m");

    var dir = "";
        if(typeof myArray[2] != "undefined")
        {
          dir=dir + myArray[2];
        }
        if(typeof myArray[3] != "undefined")
        {
          dir=dir + myArray[3];
        }
        if(dir != "")
        {
          add_output(" direction ");
          if(dir=="N") add_output("North");
          else if(dir=="NE") add_output("North East");
          else if(dir=="E") add_output("East");
          else if(dir=="SE") add_output("South East");
          else if(dir=="S") add_output("South");
          else if(dir=="SW") add_output("South West");
          else if(dir=="W") add_output("West");
          else if(dir=="NW") add_output("North West");
        }
        add_output("\n"); return;
    }

    // Check if token is Statute-Miles visibility
     var reVisUS = /(SM)$/;
     if(reVisUS.test(token))
     {
      add_output("Visibility: ");
      var myVisArray = token.split("S");
      add_output(myVisArray[0]);
      add_output(" Statute Miles\n");
    }
     

    // Check if token is QNH indication in mmHg or hPa
    var reQNHhPa = /Q\d{3,4}/;
    if(reQNHhPa.test(token))
    {
        // QNH token: Qpppp -- pppp is pressure hPa 
        add_output("QNH (msl pressure).: ");
        add_output(parseInt(token.substr(1,4),10) + " hPa"); 
        add_output("\n");  return;
    }

    // Check if token is QNH indication in mmHg: Annnn
    var reINHg = /A\d{4}/;
    if(reINHg.test(token))
    {
        add_output("QNH: ");
        add_output(token.substr(1,2) + "." + token.substr(3,4) + " inHg");
        add_output("\n");  return;
    } 


      // Check if token is NOSIG
      if(token == "NOSIG")
    {
        add_output("Next 2 hours.......: no significant changes\n");
        return;
    }



    // Check if token is runway visual range (RVR) indication
    var reRVR = /^R(\d{2})(R|C|L)?\/(M|P)?(\d{4})(V\d{4})?(U|D|N)?$/;
    if(reRVR.test(token))
    {
        var myArray = reRVR.exec(token);
        add_output("Runway visibilty...: on runway ");
        add_output(myArray[1]);
        if(typeof myArray[2] != "undefined")
        {
          if(myArray[2]=="L") add_output(" Left");
          else if(myArray[2]=="R") add_output(" Right");
          else if(myArray[2]=="C") add_output(" Central");
        }
        add_output(", touchdown zone visual range is ");
        if(typeof myArray[5] != "undefined")
        {
                 // Variable range
            add_output("variable from a minimum of ");
            if(myArray[3]=="P") add_output("more than ");
            else if(myArray[3]=="M") add_output("less than ");
            add_output(myArray[4]);
            add_output(" meters");
            add_output(" until a maximum of "+myArray[5].substr(1,myArray[5].length)+" meters");
            if(myArray[5]=="P") add_output("more than ");
       

        }
        else
        {
          // Single value
          if( (typeof myArray[3] != "undefined") &&
              (typeof myArray[4] != "undefined")    )
          {
            if(myArray[3]=="P") add_output("more than ");
            else if(myArray[3]=="M") add_output("less than ");
            add_output(myArray[4]);
            add_output(" meters");
          }

        }
        if( (myArray.length > 5) && (typeof myArray[6] != "undefined") )
        {
          if(myArray[6]=="U") add_output(", and increasing");
          else if(myArray[6]=="D") add_output(", and decreasing");
        }
        add_output("\n");
        return;
    }


    // Check if token is CAVOK
    if(token=="CAVOK")
    {
        add_output("CAVOK conditions...: Ceiling And Visibility OK, which means visibility 10 kilometers or more, no cloud below 5000 feet or below the minimum sector altitude (whichever is greater), no cumulonimbus, and no weather of significance to aviation at the aerodrome or its vicinity\n");
        return;
    }




    // Check if token is a present weather code - The regular expression is a bit
    // long, because several precipitation types can be joined in a token, and I
    // don't see a better way to get all the codes.
    var reWX = /^(\-|\+|)?(VC)?(MI|BC|DR|BL|SH|TS|FZ|PR)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(SH|TS|DZ|RA|SN|SG|IC|PL|GR|GS|BR|FG|FU|VA|DU|SA|HZ|PO|SQ|FC|SS|DS)$/;
    if(reWX.test(token))
    {
        add_output("Weather............: ");
        var myArray = reWX.exec(token);
        for(var i=1;i<myArray.length; i++)
        {
            if(myArray[i] == "-") add_output("light ");
            if(myArray[i] == "+") add_output("heavy ");
            if(myArray[i] == "VC") add_output("in the vicinity ");
            if(myArray[i] == "MI") add_output("shallow ");
            if(myArray[i] == "BC") add_output("patches of ");
            if(myArray[i] == "SH") add_output("shower(s) of ");
            if(myArray[i] == "TS") add_output("thunderstorm ");
            if(myArray[i] == "FZ") add_output("freezing ");
            if(myArray[i] == "PR") add_output("partial ");
            if(myArray[i] == "DZ") add_output("drizzle ");
            if(myArray[i] == "RA") add_output("rain ");
            if(myArray[i] == "SN") add_output("snow ");
            if(myArray[i] == "SG") add_output("snow grains ");
            if(myArray[i] == "IC") add_output("ice crystals ");
            if(myArray[i] == "PL") add_output("ice pellets ");
            if(myArray[i] == "GR") add_output("hail ");
            if(myArray[i] == "GS") add_output("small hail and/or snow pellets ");
            if(myArray[i] == "BR") add_output("mist ");
            if(myArray[i] == "FG") add_output("fog ");
            if(myArray[i] == "FU") add_output("smoke ");
            if(myArray[i] == "VA") add_output("volcanic ash ");
            if(myArray[i] == "DU") add_output("widespread dust ");
            if(myArray[i] == "SA") add_output("sand ");
            if(myArray[i] == "HZ") add_output("haze ");
            if(myArray[i] == "PO") add_output("dust/sand whirls (dust devils)");
            if(myArray[i] == "SQ") add_output("squall ");
            if(myArray[i] == "FC") add_output("funnel cloud(s) (tornado or waterspout) ");
            if(myArray[i] == "SS") add_output("sandstorm ");
            if(myArray[i] == "DS") add_output("duststorm ");
            if(myArray[i] == "DR") add_output("low drifting ");
            if(myArray[i] == "BL") add_output("blowing ");
        }
        add_output("\n");  return;
    }


    // Check if token is recent weather observation
    var reREWX = /^RE(\-|\+)?(VC)?(MI|BC|BL|DR|SH|TS|FZ|PR)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS)?(DZ|RA|SN|SG|IC|PL|GR|GS|BR|FG|FU|VA|DU|SA|HZ|PO|SQ|FC|SS|DS)?$/;
    if(reREWX.test(token))
    {
        add_output("Since the previous observation (but not at present), the following\nmeteorological phenomena were observed: ");
        var myArray = reREWX.exec(token);
        for(var i=1;i<myArray.length; i++)
        {
            if(myArray[i] == "-") add_output("light ");
            if(myArray[i] == "+") add_output("heavy ");
            if(myArray[i] == "VC") add_output("in the vicinity ");
            if(myArray[i] == "MI") add_output("shallow ");
            if(myArray[i] == "BC") add_output("patches of ");
            if(myArray[i] == "SH") add_output("shower(s) of ");
            if(myArray[i] == "TS") add_output("thunderstorm ");
            if(myArray[i] == "FZ") add_output("freezing ");
            if(myArray[i] == "PR") add_output("partial ");
            if(myArray[i] == "DZ") add_output("drizzle ");
            if(myArray[i] == "RA") add_output("rain ");
            if(myArray[i] == "SN") add_output("snow ");
            if(myArray[i] == "SG") add_output("snow grains ");
            if(myArray[i] == "IC") add_output("ice crystals ");
            if(myArray[i] == "PL") add_output("ice pellets ");
            if(myArray[i] == "GR") add_output("hail ");
            if(myArray[i] == "GS") add_output("small hail and/or snow pellets ");
            if(myArray[i] == "BR") add_output("mist ");
            if(myArray[i] == "FG") add_output("fog ");
            if(myArray[i] == "FU") add_output("smoke ");
            if(myArray[i] == "VA") add_output("volcanic ash ");
            if(myArray[i] == "DU") add_output("widespread dust ");
            if(myArray[i] == "SA") add_output("sand ");
            if(myArray[i] == "HZ") add_output("haze ");
            if(myArray[i] == "PO") add_output("dust/Sand whirls (dust devils) ");
            if(myArray[i] == "SQ") add_output("squall ");
            if(myArray[i] == "FC") add_output("funnel cloud(s) (tornado or waterspout) ");
            if(myArray[i] == "SS") add_output("sandstorm ");
            if(myArray[i] == "DS") add_output("duststorm ");
            if(myArray[i] == "DR") add_output("low drifting ");
            if(myArray[i] == "BL") add_output("blowing ");

        }
        add_output("\n"); return;
    }


    // Check if token is temperature / dewpoint pair
    var reTempDew = /^(M?\d\d|\/\/)\/(M?\d\d)?$/;
    if(reTempDew.test(token))
    {
        var myArray = reTempDew.exec(token);

        if(myArray[1].charAt(0)=='M')
          add_output("Temperature........: -" + myArray[1].substr(1,2) + " degrees Celsius\n");
        else
          add_output("Temperature........: " + myArray[1].substr(0,2) + " degrees Celsius\n");

        if(myArray[2]!="")
        {
          if(myArray[2].charAt(0)=='M')
            add_output("Dewpoint...........: -" + myArray[2].substr(1,2) + " degrees Celsius\n");
          else
            add_output("Dewpoint...........: " + myArray[2].substr(0,2) + " degrees Celsius\n");
        }

        return;
    }


    // Check if token is "sky clear" indication
    if(token=="SKC")
    {
        add_output("no clouds and no restrictions on vertical visibility\n");
        return;
    }


    // Check if token is "vertical visibility" indication
    var reVV = /^VV(\d{3}|\/{3})$/;
    if(reVV.test(token))
    {
        // VVddd -- ddd is vertical distance, or /// if unspecified
        var myArray = reVV.exec(token);
        add_output("Vertical visibility");
        if(myArray[1] == "///")
          add_output(" has indefinite ceiling\n");
        else
          add_output(": " + (100*parseInt(myArray[1],10)) + " feet\n");

        return;
    }


    // Check if token is cloud indication
    var reCloud = /^(FEW|SCT|BKN|OVC)(\d{3})(CB|TCU)?$/;
    if(reCloud.test(token))
    {
        // Clouds: aaadddkk -- aaa indicates amount of sky covered, ddd distance over
        //                     aerodrome level, and kk the type of cloud.
        var myArray = reCloud.exec(token);
        add_output("Cloud coverage.....: ");
        if(myArray[1] == "FEW") add_output("few (1 to 2 oktas)");
        else if(myArray[1] == "SCT") add_output("scattered (3 to 4 oktas)");
        else if(myArray[1] == "BKN") add_output("broken (5 to 7 oktas)");
        else if(myArray[1] == "OVC") add_output("overcast (8 oktas)");
       
        add_output(" at " + (100*parseInt(myArray[2],10)) + " feet above aerodrome level");

        if(myArray[3] == "CB") add_output(" cumulonimbus");
        else if(myArray[3] == "TCU") add_output(" towering cumulus");

        add_output("\n"); return; 
    }


    // Check if token is part of a wind-shear indication
    var reRWY = /^RWY(\d{2})(L|C|R)?$/;
    if(token=="WS")       { add_output("there is wind-shear in "); return; }
    else if(token=="ALL") { add_output("all "); return; }
    else if(token=="RWY") { add_output("runways\n"); return; }
    else if (reRWY.test(token))
    {
        var myArray = reRWY.exec(token);
        add_output("runway "+myArray[1]);
        if(myArray[2]=="L")      add_output(" Left");
        else if(myArray[2]=="C") add_output(" Central");
        else if(myArray[2]=="R") add_output(" Right");
        add_output("\n");
        return;
    }
    

    // Check if token is no-significant-weather indication
    if(token=="NSW")
    {
        add_output("no significant weather\n");
        return;
    }


    // Check if token is no-significant-clouds indication
    if(token=="NSC")
    {
        add_output("Clouds.............: no significant clouds are observed below 5000 feet or below the minimum sector altitude (whichever is higher)\n");
        return;
    }


// Check if token is part of trend indication
    if(token=="BECMG")
    {
        add_output("Next 2hrs gradually:\n");
        return;
    }
    if(token=="TEMPO")
    {
        add_output("Next 2hrs temporary:\n");
        return;
    }
    var reFM = /^FM(\d{2})(\d{2})Z?$/;
    if(reFM.test(token))
    {
        var myArray = reFM.exec(token);
        add_output("From "+myArray[1]+":"+myArray[2]+" UTC.....:\n");
        return;
    }
    var reTL = /^TL(\d{2})(\d{2})Z?$/;
    if(reTL.test(token))
    {
        var myArray = reTL.exec(token);
        add_output("Until "+myArray[1]+":"+myArray[2]+" UTC....:\n");
        return;
    }
    var reAT = /^AT(\d{2})(\d{2})Z?$/;
    if(reAT.test(token))
    {
        var myArray = reAT.exec(token);
        add_output("At "+myArray[1]+":"+myArray[2]+" UTC.......:\n");
        return;
    }



    // Check if item is runway state group
    var reRSG = /^(\d\d)(\d|C|\/)(\d|L|\/)(\d\d|RD|\/)(\d\d)$/;
    if(reRSG.test(token))
    {
        var myArray = reRSG.exec(token);
        add_output("Runway state.......:");

        // Runway designator (first 2 digits)
        var r = parseInt(myArray[1],10);
        if(r < 50) add_output(" Runway " + myArray[1] + " (or "+myArray[1]+" Left): ");
        else if(r < 88) add_output(" Runway " + (r-50) + " Right: ");
        else if(r == 88) add_output(" All runways: ");

        // Check if "CLRD" occurs in digits 3-6
        if(token.substr(2,4)=="CLRD") add_output("clear, ");
        else
        {
          // Runway deposits (third digit)
          if(myArray[2]=="0") add_output("clear and dry, ");
          else if(myArray[2]=="1") add_output("damp, ");
          else if(myArray[2]=="2") add_output("wet or water patches, ");
          else if(myArray[2]=="3") add_output("rime or frost covered, ");
          else if(myArray[2]=="4") add_output("dry snow, ");
          else if(myArray[2]=="5") add_output("wet snow, ");
          else if(myArray[2]=="6") add_output("slush, ");
          else if(myArray[2]=="7") add_output("ice, ");
          else if(myArray[2]=="8") add_output("compacted or rolled snow, ");
          else if(myArray[2]=="9") add_output("frozen ruts or ridges, ");
          else if(myArray[2]=="/") add_output("deposit not reported, ");

          // Extent of runway contamination (fourth digit)
          if(myArray[3]=="1") add_output("contamination 10% or less, ");
          else if(myArray[3]=="2") add_output("contamination 11% to 25%, ");
          else if(myArray[3]=="5") add_output("contamination 26% to 50%, ");
          else if(myArray[3]=="9") add_output("contamination 51% to 100%, ");
          else if(myArray[3]=="/") add_output("contamination not reported, ");

          // Depth of deposit (fifth and sixth digits)
          if(myArray[4]=="//") add_output("depth of deposit not reported, ");
          else
          {
              var d = parseInt(myArray[4],10);
              if(d == 0) add_output("deposit less than 1 mm deep, ");
              else if ((d >  0) && (d < 91)) add_output("deposit is "+d+" mm deep, ");
              else if (d == 92) add_output("deposit is 10 cm deep, ");
              else if (d == 93) add_output("deposit is 15 cm deep, ");
              else if (d == 94) add_output("deposit is 20 cm deep, ");
              else if (d == 95) add_output("deposit is 25 cm deep, ");
              else if (d == 96) add_output("deposit is 30 cm deep, ");
              else if (d == 97) add_output("deposit is 35 cm deep, ");
              else if (d == 98) add_output("deposit is 40 cm or more deep, ");
              else if (d == 99) add_output("runway(s) is/are non-operational due to snow, slush, ice, large drifts or runway clearance, but depth of deposit is not reported, ");
          }
        }

        // Friction coefficient or braking action (seventh and eighth digit)
        if(myArray[5]=="//") add_output("braking action not reported");
        else
        {
            var b = parseInt(myArray[5],10);
            if(b<91) add_output("friction coefficient 0."+myArray[5]);
            else
            {
                 if(b == 91) add_output("braking action is poor");
                 else if(b == 92) add_output("braking action is medium/poor");
                 else if(b == 93) add_output("braking action is medium");
                 else if(b == 94) add_output("braking action is medium/good");
                 else if(b == 95) add_output("braking action is good");
                 else if(b == 99) add_output("braking action figures are unreliable");
            }
        }
        add_output("\n"); return;
    } 

    if(token=="SNOCLO")
    {
        add_output("Aerodrome is closed due to snow on runways\n");
        return;
    }

    // Check if item is sea status indication
    reSea = /^W(M)?(\d\d)\/S(\d)/;
    if(reSea.test(token))
    {
        var myArray = reSea.exec(token);
        add_output("Sea surface temperature: ");
        if(myArray[1]=="M")
            add_output("-");
        add_output(parseInt(myArray[2],10) + " degrees Celsius\n");

        add_output("Sea waves have height: ");
        if(myArray[3]=="0") add_output("0 m (calm)\n");
        else if(myArray[3]=="1") add_output("0-0,1 m\n");
        else if(myArray[3]=="2") add_output("0,1-0,5 m\n");
        else if(myArray[3]=="3") add_output("0,5-1,25 m\n");
        else if(myArray[3]=="4") add_output("1,25-2,5 m\n");
        else if(myArray[3]=="5") add_output("2,5-4 m\n");
        else if(myArray[3]=="6") add_output("4-6 m\n");
        else if(myArray[3]=="7") add_output("6-9 m\n");
        else if(myArray[3]=="8") add_output("9-14 m\n");
        else if(myArray[3]=="9") add_output("more than 14 m (huge!)\n");
        return;
    }
}

function metar_decode(text)
{
    document.encoded.decreport.value = "";

    // Join newline-separated pieces...
    var newlineJoined = text.replace(/\n/, " ");

    // An '=' finishes the report
    var equalPosition = newlineJoined.indexOf("=");
    if (equalPosition > -1)
    {
        alert("End of a METAR report is indicated by '='. We only decode until the first '='!!");
        newlineJoined = newlineJoined.substr(0,equalPosition);
    }
    

    arrayOfTokens = newlineJoined.split(" ");
    var numToken = 0;

    // Check if initial token is non-METAR date
    var reDate = /^\d\d\d\d\/\d\d\/\d\d/;
    if (reDate.test(arrayOfTokens[numToken]))
        numToken++;

    // Check if initial token is non-METAR time
    var reTime = /^\d\d:\d\d/;
    if (reTime.test(arrayOfTokens[numToken]))
        numToken++;

    // Check if initial token indicates type of report
    if(arrayOfTokens[numToken] == "METAR")
        numToken++;
    else if(arrayOfTokens[numToken] == "SPECI")
    {
        add_output("Report is a SPECIAL report\n");
        numToken++;
    }
    

    // Parse location token
    if (arrayOfTokens[numToken].length == 4)
    {
        add_output("Location...........: " + arrayOfTokens[numToken] + "\n");
        numToken++;
    }
    else
    {
        add_output("Invalid report: malformed location token '" + arrayOfTokens[numToken] + "' \n-- it should be 4 characters long!");
        return;
    }


    // Parse date-time token -- we allow time specifications without final 'Z'
    if ( (
           ( (arrayOfTokens[numToken].length == 7) &&
             (arrayOfTokens[numToken].charAt(6) == 'Z') ) ||
           ( arrayOfTokens[numToken].length == 6 )
         ) &&
         is_num_digit(arrayOfTokens[numToken].charAt(0)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(1)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(2)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(3)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(4)) &&
         is_num_digit(arrayOfTokens[numToken].charAt(5))    )
    {
        add_output("Day of month.......: " + arrayOfTokens[numToken].substr(0,2) + "\n");
        add_output("Time...............: " + arrayOfTokens[numToken].substr(2,2) +":" +
                              arrayOfTokens[numToken].substr(4,2) + " UTC");

        if(arrayOfTokens[numToken].length == 6)
            add_output(" (Time specification is non-compliant!)");

        add_output("\n");
        numToken++;
    }
    else
    {
        add_output("Time token not found or with wrong format!");
        return;
    }
    

    // Check if "AUTO" or "COR" token comes next.
    if (arrayOfTokens[numToken] == "AUTO")
    {
        add_output("Report is fully automated, with no human intervention or oversight\n");
        numToken++;
    }
    else if (arrayOfTokens[numToken] == "COR")
    {
        add_output("Report is a correction over a METAR or SPECI report\n");
        numToken++;
    }

    // Parse remaining tokens
    for (var i=numToken; i<arrayOfTokens.length; i++)
    {
        if(arrayOfTokens[i].length > 0)
        {
            decode_token(arrayOfTokens[i].toUpperCase());
        }
    }
}

function ejem(text)
{
    alert(text);
}

</script>

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 09-27-2011 at 08:36 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use JavaScript in UNIX Shell scripting?

I want to navigate through a webpage and save that page in my system local automatically. How can I do that by using JavaScript in a Unix shell script. Any suggestions are welcome! (3 Replies)
Discussion started by: abhi3093
3 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. Web Development

Javascript to check field is empty then execute rest of script

I have found this bit of code that nearly does what I want. Basically 3 input fields, I want to copy t2 to t3 as it's typed but only if t1 contains data AND t3 is empty: <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="text" id="t3" /> <script> var t2 =... (4 Replies)
Discussion started by: barrydocks
4 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. Shell Programming and Scripting

How to use javascript code in unix shell?

Hi Need help...I have wrritten one code for html through shell scripting in that i am using java scripts to validate some condition and open the html page without clicking the button.... Code Details echo "<script type="text/javascript">" echo "function exec_refresh()" echo "{" ... (4 Replies)
Discussion started by: l_gshankar24
4 Replies

6. Web Development

Why using this kind of format in Web Development <script type="text/javascript"><!-- ...//--></scrip

I am just wondering why do programmers are using this when programming the web? When you making a joomla templates and the more focus in your mind is to target the search engines then java is very important.Not to use that. (2 Replies)
Discussion started by: Anna Hussie
2 Replies

7. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

8. Web Development

Javascript -> Shell Script

Hi all, I am trying to call a shell script from a javascript function. This works fine and the shell script returns everything I expected BUT I cannot figure out how to pass command line arguments to this shell script. Using GET, I assume the url being called needs to be one string with no... (7 Replies)
Discussion started by: mark007
7 Replies

9. Shell Programming and Scripting

Calling Shell script in javascript

All I want to call a KORN shell script inside a javascript. Is it possible ? Please help me to do this. I want to return or read from shell script in javascript. Thanx in advance Regards Deepak Xavier (1 Reply)
Discussion started by: DeepakXavier
1 Replies

10. Shell Programming and Scripting

Javascript: Edit a script ?

Hi, i got this script but when i hit reset i loose the times in the form box. Can someone please edit this script so when i hit reset i dont loose the times in the form box's and also have a button to reset everything, including the form boxs <script language="javascript"> // stopwatch... (1 Reply)
Discussion started by: perleo
1 Replies
Login or Register to Ask a Question