//------------------------------------------------------------------------------// // This script is used to insert alignment values from ascii files into the data base // April 2012 Hubert van Hecke // Updated Jan 2014 //------------------------------------------------------------------------------// $from = $_POST['from']; //echo "from=$from
"; //------------------------------------------------------------------------------// if ($from==NULL || $from==0) { echo (" select input file



Choose an input file:
Assign a version number:
Comment for this record:
 
"); } // end from=0 //-----------------------------------------------------------------------------------------------// // (1) Come here from the front page if ($from==1) { $infile = $_POST['infile']; $version = $_POST['inversion']; $comment = $_POST['comment']; echo "$comment:$comment."; echo "
From file: $infile, version: $inversion
"; $lfound = 0; $fh = fopen($infile,'r'); while ( ($line = fgets($fh)) && $lfound==0) { if (substr($line,0,1)=="*") { $tokens = explode(" ",$line); $object = $tokens[1]; //echo "token1 = $object
"; if ($object=="SW0" || $object=="SE0" || $object=="NW0" || $object=="NE0") $lfound = 2; if ($object=="SW1" || $object=="SE1" || $object=="NW1" || $object=="NE1") $lfound = 2; if ($object=="SW2" || $object=="SE2" || $object=="NW2" || $object=="NE2") $lfound = 2; if ($object=="SW3" || $object=="SE3" || $object=="NW3" || $object=="NE3") $lfound = 2; if ($object=="delta_x_m" || $object=="delta_y_m" || $object=="delta_phi_m") $lfound = 3; if ($lfound>0) echo "

Record(s) found for object $object, type $lfound
"; } } fclose($fh); //if ($lfound>0) xxx Include "connect.php"; $conn = odbcConnect(); if ( ! $conn ) { echo "connection problem..."; return 0; } $query = "SELECT version,object FROM fvtx_survey WHERE version=$version AND object='$object'"; echo "
$query
"; $result = odbc_exec($conn,$query); $num = odbc_num_rows($result); odbcClose($conn); if ($num>0) { echo "*** there are already records for version $version and object $object
*** nothing done.
"; } else { echo (" No old records found for version $version and object $object
inserting data into the DB?
"); } // else all ok } // from=1 //-------------------------- from = 2: station 0,1,2,3 (all wedges) ---------------------------------------------- if ($from==2) { $version = $_POST['inversion']; $fname = $_POST['infile']; $comment = $_POST['comment']; echo "comment 2:$comment"; Include "connect.php"; $conn = odbcConnect(); if ( ! $conn ) { echo "connection problem..."; return 0; } //$version = 1; $xmid = array(); $ymid = array(); $angle = array(); $pi = 3.14159; // this is the order in which millepede gives the shifts, using a command like: // misalignment->Scan("arm:cage:station:delta_x_millepede","sector==-9999"); $diskname = array("SW0","SW1","SW2","SW3", "SE0","SE1","SE2","SE3", "NW0","NW1","NW2","NW3", "NE0","NE1","NE2","NE3"); $delta_x_m = array(0, -0.336807, -0.609819, -0.892556, 0, 0.0086472, 0.0191192, 0.0183769, 0, 0.0156216, 0.0443183, 0.0649802, 0, -0.018033, -0.038126, -0.040429); $delta_y_m = array(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0); echo (" Insert station-0,1,2,3 survey numbers into the data base "); $iwedge = 0; $writeflg = 0; $linecount = 1; echo "$fname"; $disk0_file = fopen($fname,r); while ($line = fgets($disk0_file)) { // read the whole input file if (substr($line,0,1)=="*" && // next wedge quadrant record block substr($line,2,3)!="SCM") { // not a 'disk' record $disk = substr($line_save,2,3); for ($j=0; $j<16; $j++) { if ($disk==$diskname[$j]) $jdisk = $j; } echo "

* Large wedges, numbers for $line: $disk
"; if ($writeflg==1) { echo "

Writing data:
"; $object = "'".substr($line_save,2,3)." wedge x'"; //-------------------- wedge x ---------------------------- $arr = "'{"; // psql array string start for ($i=0; $i<23; $i++) { $val = substr($xmid[$i],0,11); // read the string //$val += $delta_x_m[$jdisk]; // apply the x-shift $arr = $arr.$val.","; // append to the output string } $val = substr($xmid[23],0,11); // last element //$val += $delta_x_m[$jdisk]; // apply the x-shift $arr = $arr.$val."}'"; // add to the string and cloe it $query = "SELECT version,object FROM fvtx_survey WHERE version=$version AND object=$object ORDER BY version"; $result = odbc_exec($conn,$query); $num = odbc_num_rows($result); if ($num>0) { echo "*** $num entries found for version $version object $object
"; $ver_high = odbc_result($result,1); $version = $ver_high+1; echo "Highest version number found: $ver_high -> setting version to $version
"; } $query = "INSERT into fvtx_survey (version,object,values,comment) VALUES($version,$object,$arr,'$comment')"; echo "1:
$query
"; //xxx $result = odbc_exec($conn,$query); $object = "'".substr($line_save,2,3)." wedge y'"; //--------------- wedge y ------------------------------------ $arr = "'{"; for ($i=0; $i<23; $i++) { $val = substr($ymid[$i],0,11); // read the string $val += $delta_y_m[$jdisk]; // apply the y-shift $arr = $arr.$val.","; // append to the output string } $val = substr($ymid[23],0,11); // last element //$val += $delta_y_m[$jdisk]; // apply the y-shift $arr = $arr.$val."}'"; // add to the string and cloe it $query = "INSERT into fvtx_survey (version,object,values) VALUES($version,$object,$arr)"; echo "2:
$query
"; //xxx $result = odbc_exec($conn,$query); $object = "'".substr($line_save,2,3)." wedge phi'"; //--------------- wedge phi -------------------------------- $arr = "'{"; for ($i=0; $i<23; $i++) { $arr = $arr.substr($angle[$i],0,11).","; } $arr = $arr.substr($angle[23],0,11)."}'"; // last element $query = "INSERT into fvtx_survey (version,object,values) VALUES($version,$object,$arr)"; echo "3:
$query
"; //xxx $result = odbc_exec($conn,$query); } // end if write flag is set $line_save = $line; $writeflg = 1; $iwedge = 0; } // end if wedge block start elseif (substr($line,2,3)!="SCM") { // not a 'disk' record // echo " $line
"; $vals = explode(",",$line); $xmid[$iwedge] = $vals[1]; $ymid[$iwedge] = $vals[2]; $angle[$iwedge] = $vals[3]; // if ( $iwedge==0 ) $sign = sign($angle[0]); // keep the sign of the first angle //if ($sign>0) { // $angle[$iwedge] -= 90.0; // $angle[$iwedge] *= -1.0; //} //if ($sign<0) { // $angle[$iwedge] += 90.0; // $angle[$iwedge] *= -1.0; // if ($angle[$iwedge]<0) $angle[$iwedge] += 360.0; // $xmid[$iwedge] *=-1.0; // $ymid[$iwedge] *=-1.0; //} //echo "x= $x1, $x2, $xmid[$iwedge], y= $y1, $y2, $xmid[$iwedge], r= $r, angle= $angle[$iwedge]
"; echo "$iwedge: x= $xmid[$iwedge], y= $ymid[$iwedge], angle= $angle[$iwedge]
"; $iwedge++; } } // end read whole file $object = "'".substr($line_save,2,3)." wedge x'"; $arr = "'{"; for ($i=0; $i<23; $i++) { $arr = $arr.substr($xmid[$i],0,7).","; } $arr = $arr.substr($xmid[23],0,7)."}'"; $query = "INSERT into fvtx_survey (version,object,values) VALUES($version,$object,$arr)"; echo "4:
$query
"; //xxx $result = odbc_exec($conn,$query); $object = "'".substr($line_save,2,3)." wedge y'"; $arr = "'{"; for ($i=0; $i<23; $i++) { $arr = $arr.substr($ymid[$i],0,7).","; } $arr = $arr.substr($ymid[23],0,7)."}'"; $query = "INSERT into fvtx_survey (version,object,values) VALUES($version,$object,$arr)"; echo "5:
$query
"; //xxx $result = odbc_exec($conn,$query); $object = "'".substr($line_save,2,3)." wedge phi'"; $arr = "'{"; for ($i=0; $i<23; $i++) { $arr = $arr.substr($angle[$i],0,7).","; } $arr = $arr.substr($angle[23],0,7)."}'"; $query = "INSERT into fvtx_survey (version,object,values) VALUES($version,$object,$arr)"; echo "6:
$query
"; //xxx $result = odbc_exec($conn,$query); fclose($disk0_file); echo (" No old records found for version $version and object $object
inserting data into the DB?
"); echo (" "); odbcClose($conn); } //end from=2 large and small wedges //----------------------- from=3: disk x, y, phi ------------------------------------------------------------------------ if ($from==3) { $version = $_POST['inversion']; $fname = $_POST['infile']; $comment = $_POST['comment']; echo "comment 3:$comment."; Include "connect.php"; $conn = odbcConnect(); if ( ! $conn ) { echo "connection problem..."; return 0; } echo (" Insert disk positions into the data base "); echo "
\n processing $fname \n
\n"; $conn = odbcConnect(); if ( ! $conn ) { echo "connection problem..."; return 0; } $disk0_file = fopen($fname,r); while ($line = fgets($disk0_file)) { if (substr($line,0,1)=="*") { // next quadrant block $tokens = explode(" ",$line); $object = $tokens[1]; // first word after the * if ($object=="delta_x_m" || $object=="delta_y_m" || $object=="delta_phi_m") { echo "
\n valid object seen = $object \n
\n"; $line = fgets($disk0_file); // read the next line $vals = "{".$line."}"; $query = "INSERT INTO fvtx_survey (version,object,values,comment) VALUES ($inversion,'$object','$vals','$comment')"; echo "7:
\n $query \n
\n"; //xxx $result = odbc_exec($conn,$query); } // valid object name } // * - type line } // read over all lines fclose($disk0_file); odbcClose($conn); echo ("
"); } //end from=3 disk placement //------------------------------------------------------------------------// function sign( $number ) { return ( $number > 0 ) ? 1 : ( ( $number < 0 ) ? -1 : 0 ); } //------------------------------------------------------------------------// ?>