children(); // Need to check weather the last mon and yr is the same, don't need to regenterate it. sscanf($w->SUN[$mon],"%f %f",$min,$max); $sun=0; for($i=0;$i<5;$i++) $sun+=random_float($min,$max); $sun=$sun/5.0; sscanf($w->RAIN[$mon],"%f %f",$min,$max); $rain=0; for($i=0;$i<5;$i++) $rain+=random_float($min,$max); $rain=$rain/5.0; sscanf($w->TEMP[$mon],"%f %f",$min,$max); $temp=0; for($i=0;$i<5;$i++) $temp+=random_float($min,$max); $temp=$temp/5.0; sscanf($w->WIND[$mon],"%f %f",$min,$max); $wind=0; for($i=0;$i<5;$i++) $wind+=random_float($min,$max); $wind=$wind/5.0; $wt[0]=$sun*100; $wt[1]=$rain*100; $wt[2]=$temp*100; $wt[3]=$wind*100; $wt[0]=(int)$wt[0]/100.0; $wt[1]=(int)$wt[1]/100.0; $wt[2]=(int)$wt[2]/100.0; $wt[3]=(int)$wt[3]/100.0; return($wt); } // Load weather xml file from the passed file and return the weather loaded or ERROR function weather_load($fname) { if(!file_exists($fname))return("ERROR"); $xml = simplexml_load_file($fname); return($xml); } // Update the weather for the month function weather_update($fname,$mon,$year) { $wth=weather_load($fname); if($wth=="ERROR")return(0); $current=$wth->children(); $wt=weather_get($wth,(int)$mon); if($current->CURSUN>0) { $wt[0]*=3; $wt[1]*=3; $wt[2]*=3; $wt[3]*=3; $wt[0]+=$current->CURSUN; $wt[1]+=$current->CURRAIN; $wt[2]+=$current->CURTEMP; $wt[3]+=$current->CURWIND; $wt[0]/=4.0; $wt[1]/=4.0; $wt[2]/=4.0; $wt[3]/=4.0; } $current->LASTSUN=$current->CURSUN; $current->LASTRAIN=$current->CURRAIN; $current->LASTTEMP=$current->CURTEMP; $current->LASTWIND=$current->CURWIND; $current->MONTH=$mon; $current->CURSUN=$wt[0]; $current->CURRAIN=$wt[1]; $current->CURTEMP=$wt[2]; $current->CURWIND=$wt[3]; sscanf($current->HISUN,"%f %d %d",$hi,$m,$y); if($wt[0]>$hi) $current->HISUN=$wt[0]." ".$mon." ".$year; sscanf($current->HIRAIN,"%f %d %d",$hi,$m,$y); if($wt[1]>$hi) $current->HIRAIN=$wt[1]." ".$mon." ".$year; sscanf($current->HITEMP,"%f %d %d",$hi,$m,$y); if($wt[2]>$hi) $current->HITEMP=$wt[2]." ".$mon." ".$year; sscanf($current->HIWIND,"%f %d %d",$hi,$m,$y); if($wt[3]>$hi) $current->HIWIND=$wt[3]." ".$mon." ".$year; sscanf($current->LOSUN,"%f %d %d",$hi,$m,$y); if($wt[0]<$hi) $current->LOSUN=$wt[0]." ".$mon." ".$year; sscanf($current->LORAIN,"%f %d %d",$hi,$m,$y); if($wt[1]<$hi) $current->LORAIN=$wt[1]." ".$mon." ".$year; sscanf($current->LOTEMP,"%f %d %d",$hi,$m,$y); if($wt[2]<$hi) $current->LOTEMP=$wt[2]." ".$mon." ".$year; sscanf($current->LOWIND,"%f %d %d",$hi,$m,$y); if($wt[3]<$hi) $current->LOWIND=$wt[3]." ".$mon." ".$year; sscanf($current->TOTSUN,"%f %d",$tot,$months); $months++; $tot=(int)$tot+$wt[0]; $current->TOTSUN=$tot." ".$months; sscanf($current->TOTRAIN,"%f %d",$tot,$months); $months++; $tot=(int)$tot+$wt[1]; $current->TOTRAIN=$tot." ".$months; sscanf($current->TOTTEMP,"%f %d",$tot,$months); $months++; $tot=(int)$tot+$wt[2]; $current->TOTTEMP=$tot." ".$months; sscanf($current->TOTWIND,"%f %d",$tot,$months); $months++; $tot=(int)$tot+$wt[3]; $current->TOTWIND=$tot." ".$months; $wth->asXml($fname); } ?>