(time() + 180*3600)) { die("The time was too far in the future, 180 days max"); } // now we have a populated model, run the predictor runPred($pred_model); } function makesha1hash($pred_model) { $sha1str; foreach ( $pred_model as $idx => $value ){ $sha1str .= $idx . "=" . $value . ","; } $uuid = sha1($sha1str); return $uuid; } function verifyModel($pred_model, $software_available) { if(!isset($pred_model)) return false; foreach($pred_model as $idx => $value) { if ($idx == "software") { if (!in_array($value, $software_available)) return false; } else { if (!is_numeric($value)) { return false; } } } return true; } function runPred($pred_model) { // make in INI file makePredDir($pred_model); makeINI($pred_model); // if we're using --hd, then append it to the exec string if ( $pred_model['software'] == "gfs_hd" ) $use_hd ="--hd "; // use `at` to automatically background the task $ph = popen("at now", "w"); fwrite($ph, "cd /var/www/hab/predict/ && ./predict.py -v --latdelta=3 --londelta=3 --lat=52 --lon=0 " . $use_hd . $pred_model['uuid']); fclose($ph); } function makePredDir($pred_model) { shell_exec("mkdir preds/" . $pred_model['uuid']); //make sure we use the uuid from model } function makeINI($pred_model) { // makes an ini file $fh = fopen("preds/" . $pred_model['uuid'] . "/scenario.ini", "a"); //append $w_string = "[launch-site]\nlatitude = " . $pred_model['lat'] . "\naltitude = " . $pred_model['alt'] . "\n"; $w_string .= "longitude = " . $pred_model['lon'] . "\n[atmosphere]\nwind-error = "; $w_string .= $pred_model['wind_error'] . "\n[altitude-model]\nascent-rate = " . $pred_model['asc'] . "\n"; $w_string .= "descent-rate = " . $pred_model['des'] . "\nburst-altitude = "; $w_string .= $pred_model['burst'] . "\n[launch-time]\nhour = " . $pred_model['hour'] . "\n"; $w_string .= "month = " . $pred_model['month'] . "\nsecond = " . $pred_model['sec'] . "\n"; $w_string .= "year = " . $pred_model['year'] . "\nday = " . $pred_model['day'] . "\nminute = "; $w_string .= $pred_model['min'] . "\n"; fwrite($fh, $w_string); fclose($fh); } function runGRIB($pred_model) { // runs the grib predictor $lockfile = fopen("lock", "w"); $shellcmd = "./one_off_prediction " . $pred_model['lat'] . " " . $pred_model['lon'] . " " . $pred_model['alt'] ." " . (float)$pred_model['asc'] . " " . $pred_model['des']*1.1045 . " " . $pred_model['burst'] . " " . $pred_model['timestamp'] . " " . $pred_model['float'] . " &"; echo $shellcmd; //shell_exec($shellcmd); if (!file_exists("flight_path.csv")) { unlink("lock"); die("The predictor didn't write a file"); } shell_exec("mv flight_path.* preds/".$pred_model['uuid']."/"); unlink("lock"); } ?>