Source for file convert.php
Documentation is available at convert.php
* One-time HRDI data conversion script.
* This conversion script converts the data imported from 4D to a format used
* by the HRDIODB software. It does the following conversions:
* - Changes the relationship between HRDI_Days and HRDI_Modes
* - Changes all instances of "Middle" flight direction to "Maneuver"
* - Corrects any incorrect azimuth (cause by human entry error)
* - Parses azimuths to store them in four numerical fields instead of one
* This file is part of HRDIODB.
* HRDIODB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* HRDIODB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with HRDIODB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** Configuration file */
require_once("conf.php");
/** HRDI database class */
require_once("hrdi_db_class.php");
$conv = array (1 => "relationship between HRDI_Days and HRDI_Modes",
2 => "Flight Direction from \"Middle\" to \"Maneuver\"",
3 => "incorrect Azimuths",
4 => "String Azimuths to 4 separate numerical fields",
5 => "all of the above, in order");
// HRDI database instance
// Figure out which conversion to make
print "Please specify the number of the conversion you want to run\n\n";
for($i = 1; $i <= count($conv); $i++ ) {
print "\t$i: Convert {$conv[$i]}\n";
* Performs the first conversion, namely changes the relationship between
* HRDI_Days and HRDI_Modes.
print "Converting {$conv[1]}\n";
$sql = "SELECT Record_Num,UARS_Day
$days = $hdb->get_list($sql);
print "$total days to convert\n";
for ($i = 0; $i < count($days); $i++ ) {
print ($i + 1). " of $total\n";
$sql = "UPDATE HRDI_Modes
SET UARS_Day='{$days[$i]['UARS_Day']}'
WHERE Days_Relate_Num='{$days[$i]['Record_Num']}'";
* Performs the second conversion, namely changes all instances of "Middle"
* flight direction to "Maneuver".
print "Converting {$conv[2]}\n";
SET Flight_Direction='Maneuver'
WHERE Flight_Direction='Middle'";
print "Updated ". $hdb->db->affectedRows(). " days\n";
* Performs the third conversion, namely corrects any incorrect azimuth.
print "Converting {$conv[3]}\n";
$sql = "UPDATE HRDI_Modes
print "Converted ". $hdb->db->affectedRows(). " '45135' Azimuths\n";
$sql = "UPDATE HRDI_Modes
WHERE Azimuth='±45,±135'";
print "Converted ". $hdb->db->affectedRows(). " '±45,±135' Azimuths\n";
$sql = "UPDATE HRDI_Modes
WHERE Azimuth='+45+,135'";
print "Converted ". $hdb->db->affectedRows(). " '+45+,135' Azimuths\n";
* Performs the fourth conversion, namely parses azimuths to store them in four
* numerical fields instead of one string field.
$sql = "SELECT ID,Azimuth
$modes = $hdb->get_list($sql);
foreach ($modes as $mode) {
if (preg_match("/(([+-]*)(\d+))(,\s*([+-]*)(\d+))*/", $mode['Azimuth'], $match)) {
$azimuths[] = '-'. $match[3];
print "Error! Unhandled Azimuth (1) for ID {$mode['ID']}\n";
$azimuths[] = '-'. $match[6];
print "Error! Unhandled Azimuth (2) for ID {$mode['ID']}\n";
$sql = "UPDATE HRDI_Modes
SET Azimuth1='{$azimuths[0]}'";
$sql .= ",Azimuth2='{$azimuths[1]}'";
$sql .= ",Azimuth3='{$azimuths[2]}'";
$sql .= ",Azimuth4='{$azimuths[3]}'";
$sql .= " WHERE ID='{$mode['ID']}'";
print "Updating Azimuths for mode ID {$mode['ID']}\n";
} else if (strlen($mode['Azimuth'])) {
print "Error! Could not parse azimuth {$mode['Azimuth']} for mode ID {$mode['ID']}\n";
|