Sympa comme résultat !
Le script est très bien pensé.
Perso, j'ai réécris mon script PHP qui lit dans les fichiers binaires de sortie de -lola en Java qui me fais gagner 50% du temps d'exécution sur le script PHP que voilà :
Code
#!/usr/bin/php <?php error_reporting(E_ALL); define('COORDBOXESIZE', 1); define('DATADIR', "dataset"); # files to read $fn_index = DATADIR.'/last.bin.index'; $fn_bin = DATADIR.'/last.bin'; # --- NO NEED TO MODIFY BELOW --- # # contient les infos $index = array(); $index_out = array(); $fp = fopen($fn_index, 'r'); while(!feof($fp)) { $l = trim(fgets($fp)); $a = explode(':', $l); if(count($a) === 7) { $index[] = array($a[3], $a[4], $a[5]); $index_out[$a[4]][] = $a[3]; } unset($l, $a); } fclose($fp); # # # DATA : $lat =-90+COORDBOXESIZE/2; $lon = -180+COORDBOXESIZE/2; $nbr_lon = 360/COORDBOXESIZE; $nbr_lat = 180/COORDBOXESIZE; $correct_file = false; $point_num=0; $count_index = count($index); # $nbr_points = $nbr_lon * $nbr_lat; $fp = fopen($fn_bin, 'rb'); for($lat; $lat <= 90; $lat += COORDBOXESIZE) { for($lon; $lon <= 180; $lon += COORDBOXESIZE) { //---------------------------------------------------------------BeginningOfMessage $data = array(); for($n=0; $n < $count_index; $n++) { $val = unpack('f', fread($fp, 4)); $type = $index[$n][0]; $level = $index[$n][1]; $time = $index[$n][2]; $data[$level][$type] = (float)$val[1]; # returning at top position if(fseek($fp, 4*$nbr_points-4, SEEK_CUR) === -1 || feof($fp)) die('## fseek/foef failed on line '. __LINE__ ."\n"); } /* print_r($data); exit;/* debug */ $empty = array(); $empty[] = 0; $empty[] = 0; $empty[] = 0; $clouds = array('H'=>$empty,'M'=>$empty,'L'=>$empty,'C'=>$empty); echo sprintf('%+.2f',$lat).':'.sprintf('%+.2f',$lon); reset($index_out); while(list($k,$v)=each($index_out)) { if($k === "surface") { # Precipitation Rate [kg/m^2/s]*3600 = mm/hour (1L=1dm^3) (1mm<=>1L) $prate = $data[$k]['PRATE']*3600; //unit: mm/hour if($prate > 0) { echo ' P'; echo sprintf("%.2f", $prate); # Precipitation type if((float)$data[$k]['CRAIN'] != 0) echo 'R'; if((float)$data[$k]['CSNOW'] != 0) echo 'S'; if((float)$data[$k]['CFRZR'] != 0) echo 'F'; if((float)$data[$k]['CICEP'] != 0) echo 'I'; } } elseif(ereg('cloud', $k)) { if(isset($data[$k]['PRES'])) { $pres = (int) (((float)$data[$k]['PRES'])/100); // --top level-- if($k === "high cloud top level") { $clouds['H'][0] = $pres; } elseif($k === "middle cloud top level") { $clouds['M'][0] = $pres; } elseif($k === "low cloud top level") { $clouds['L'][0] = $pres; } //- -bottom level-- elseif($k === "high cloud bottom level") { $clouds['H'][1] = $pres; } elseif($k === "middle cloud bottom level") { $clouds['M'][1] = $pres; } elseif($k === "low cloud bottom level") { $clouds['L'][1] = $pres; } } elseif(isset($data[$k]['TCDC'])) { $p = (int) $data[$k]['TCDC']; if($p > 100) $p = 0; // prevent from using an undefined value (unknown = no clouds) if($p > 99) $p = 99; if($k === "high cloud layer") { $clouds['H'][2] = $p; } elseif($k === "middle cloud layer") { $clouds['M'][2] = $p; } elseif($k === "low cloud layer") { $clouds['L'][2] = $p; } elseif($k === "convective cloud layer") { $clouds['C'][2] = $p; } } } else { list($lev, $unit) = explode(' ', $k); if($unit === "mb") { //--compulsory fields # Level information (in mb/10) echo sprintf(" %d", $lev/10); # Temperature (2 digits with sign) $tmp = (int)($data[$k]['TMP']-273+0.5); if($tmp > 99) $tmp = 99; if($tmp < 0) echo '-'; else echo '+'; echo sprintf("%02d", abs($tmp)); # Wind $u = (float)$data[$k]['UGRD']; $v = (float)$data[$k]['VGRD']; $spd = sqrt(pow($u, 2) + pow($v, 2)); $spd *= 1.943861286; if($u == 0) $dir = $v < 0 ? -pi()/2 : pi()/2; else $dir = atan($v/$u); if($u < 0) $dir += pi(); $dir = (int) (630 - rad2deg($dir))%360; // 630=90+360+180 (+180 because vetor shows what the wind does, not were it is coming from) if($spd > 299) { echo sprintf('%03dPP%02d', $dir, 99); } elseif($spd > 199) { echo sprintf('%03dPP%02d', $dir, $spd-200); } elseif($spd > 99) { echo sprintf('%03dP%02d', $dir, $spd-100); } else { echo sprintf('%03d%02d', $dir, $spd); } //--optional fields # Relative humidity if(isset($data[$k]['RH'])) { $rh = (int)$data[$k]['RH']; if($rh > 99) $rh = 99; if($rh != 0) echo sprintf('%02d', $rh); } # Cloud Mixing Ratio [mg/kg] if(isset($data[$k]['CLWMR'])) { $cmr = (int) ($data[$k]['CLWMR'] * 1e6); if($cmr != 0) echo sprintf('C%d', $cmr); } } elseif($lev === "mean") { $qnh = $data[$k]['PRMSL']/100; echo sprintf(' Q%.1f', $qnh); } } } $list = array('L','M','H','C'); $first = true; foreach($list as $k) { $v = $clouds[$k]; if($v[0] > 0 && $v[1] > 0 && $v[2] > 0 && ((float)$v[0]) * ((float)$v[1]) * ((float)$v[2]) !== 0) { if($first) echo ' '; if($k === 'C') echo $k.sprintf('%02d', $v[2]); else echo $k.sprintf('%04d%04d%02d', $v[0], $v[1], $v[2]); $first = false; } } echo "\n";/* end of line -> new line */ # Moving to next point $point_num++; if(fseek($fp, 4*$point_num) === -1) die('## fseek failed on line '. __LINE__ ." (moving to next point)\n"); //-----------------------------------------------------------------EndOfMessage } $lon = -180+COORDBOXESIZE/2; } fclose($fp); ?>
Bon, le script ci-dessus lit sur la Terre entière avec une résolution de 1° (changeable en fonction de la commande lola) et donne en sortie un META format que mon serveur météo sait lire
Si ça peut te donner des idées
En ce moment, IKE fait des ravages