
//=========================================================
//
// Routines to form character words for precis section
//
//=========================================================

function getPrecisWords(tempword) {
  PrecisWord = new Array(6)
  initPArray(tempword)
  getPSky(tempword)
  getPTemp(tempword)
  getPHum(tempword)
  getPWind(tempword)
  cleanPArray(tempword)
  return PrecisString} 
  
function initPArray(tempword) {
  i = 0
  
	while (i <= 5) {
    {PrecisWord[i] = " "}
  i++}
  
  return}  
          
function getPSky(tempword) {
  PctRad = (SolRadCurr/MaxPossSolarRad)
  if (MaxPossSolarRad <=200)
    {PrecisWord[1] = "fair"}
  else { if (PctRad >= 0.50) 
    {PrecisWord[1] = "fine"}
          else { if (PctRad >= 0.20)
                  {PrecisWord[1] = "cloudy"}
                  else {PrecisWord[1] = "dull"}
                }
        }

  TempRate = ""
  TempPrecip = ""
  
  if (PrecipRateCurr > 0)                
    {TempRate = "light "}
         
  if (PrecipRateCurr > 0.1)                
    {TempRate = "moderate "}
         
  if (PrecipRateCurr > 0.3)                
    {TempRate = "heavy "}
         
  if (OutTempCurr >= 39)
    {TempPrecip = "rain"}
  else { if (OutTempCurr >= 32.1)
            {TempPrecip = "rain/snow"}
          else { if (OutTempCurr >= 27.5)
                    {TempPrecip = "freezing rain/snow"}
                  else {TempPrecip = "snow"}  
         
                }
        }
                     
  if (PrecipRateCurr > 0)
    {PrecisWord[0] = (TempRate+" "+TempPrecip)}
    
  if (PrecipRateCurr == 0)
    {if (OutHumCurr > 94)
      {PrecisWord[2] = "mist"}
          else { if (OutHumCurr > 98)
                  {PrecisWord[2] = "fog"}
                }
      }
             
  return}
    
function getPTemp(tempwork) {
  if (OutTempCurr <0)
    {PrecisWord[4] = "bitter"}
  else { if (OutTempCurr <20)
    {PrecisWord[4] = "very cold"}
          else { if (OutTempCurr <40)
                  {PrecisWord[4] = "cold"}
                  else { if (OutTempCurr <60)
                  {PrecisWord[4] = "cool"}
                          else { if (OutTempCurr <70)
                                    {PrecisWord[4] = "mild"}
                                  else { if (OutTempCurr <80)
                                            {PrecisWord[4] = "warm"}
                                          else {PrecisWord[4] = "hot"}
                                        }
                                }
                        }
                }
          }

  return}                

function getPHum(tempwork) {
  if (OutDPCurr > 65)
    {PrecisWord[5] = "humid"}
  else { if (OutHumCurr <= 50)
    {PrecisWord[5] = "dry"}
          else { if (OutTempCurr <= 60 && OutHumCurr >= 75)
                  {PrecisWord[5] = "damp"}
                }
          }

  return}                


function getPWind(tempwork) {
  if (CalcWindGust10 == "---")
          {tempwind = 0}
  else {tempwind = parseFloat(CalcWindGust10)}
  
  if (StaWindSpeedCurr > CalcWindGust10)
    {tempwind = StaWindSpeedCurr}
    
  if (tempwind >= 39)
    {PrecisWord[3] = "very Windy"}
          else { if (tempwind >= 25)
                    {PrecisWord[3] = "windy"}
                  else { if (tempwind >= 13)
                          {PrecisWord[3] = "breezy"}
                        }
                }
  return}                

function cleanPArray(tempword) {
  if (PrecisWord[0] > " ")
    {PrecisWord[1] = " ", PrecisWord[5] = " "}
    
  if (PrecisWord[2] > " ")
    {PrecisWord[5] = " "}
  
  i = 0
  
	while (i <= 4) {
	if (PrecisWord[i] == " ")
      {PrecisWord[i] = PrecisWord[i+1]
       PrecisWord[i+1] = " "}
  i++}
  
  i = 5

	while (PrecisWord[i] == " ") {
	i--}

  lastword = i
  
  i = 0
  PrecisString = ""
  
	while (i < lastword) {
	if (PrecisWord[i] > " ")
      {if (PrecisString > " ")
          {PrecisString += ", "+PrecisWord[i]}
        else {PrecisString = PrecisWord[i]}
      }
  i++}
  
  PrecisString += " and " + PrecisWord[lastword]
  
  // Capitalise first word
  
  l = PrecisString.length
  initchar = PrecisString.substring(0,1)
  PrecisString = PrecisString.substring(1,l)
  initchar = initchar.toUpperCase()
  
  PrecisString = (initchar+PrecisString)
	return PrecisString} 
  
    
