\n");
foreach($insquery as $num => $q)
{
printf("Inserted Query #%s: %s \n", $num, $q);
$insresult=mysql_query($q);
if (mysql_errno()>0)
printf(" Errorno: %s \n", mysql_errno());
if (mysql_error()!="")
printf(" Errormsg: %s \n", mysql_error());
if (mysql_info()!="")
printf(" Info: %s \n", mysql_info());
printf(" Affected Rows: %s
\n", mysql_affected_rows());
mysql_free_result($insresult);
if (mysql_errno()>0)
{
printf("ERROR => stop inserting.
\n");
break;
}
}
// reset after insert
unset($_SESSION["insert"]);
unset($_SESSION["name"]);
unset($_SESSION["comment"]);
}
else
printf(" \n", GetClearedURL());
}
function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs)
{
$db_id = mysql_pconnect($host, $user, $pw);
if ($db_id==FALSE)
{
printf("mysql_connect returned the following error: %s\n", mysql_error());
die("");
}
mysql_select_db($db);
$query0 = CreateQuery($alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
$result0 = mysql_query($query0, $db_id);
$result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
if ($result0)
{
if ($html=="1" || $html=="2")
{
PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $result1, "yes");
if (!(empty($_SESSION["sequon"]) && empty($_SESSION["sequoff"])))
{
printf("
\n");
printf("Remark: To store your selection you have to press 'Update Data Set' \n");
printf(" \n");
printf("Your Data Set: \n");
$on=str_replace(" ", ",", trim($_SESSION["sequon"]));
$off=str_replace(" ", ",", trim($_SESSION["sequoff"]));
//set observation mode
if ($_SESSION["sequoff"]==" ")
$obsmode="Wobble";
else
$obsmode="On";
//get key from db for insert query
$query = "SELECT fObservationModeKEY FROM ObservationMode WHERE fObservationModeName='".$obsmode."'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$_SESSION["obsmode"] = $row["fObservationModeKEY"];
mysql_free_result($result);
$values=array("Sum(fRunTime)/60" => $runtime,
"Min(fRunTime)/60" => $runtimemin,
"Max(fUnsuitableInner)" => $unsuitablemax,
"Max(fUnreliableInner)" => $unreliablemax,
"Max(fIsolatedInner)" => $isolatedmax,
"Max(fIsolatedMaxCluster)" => $imcmax,
"Max(fArrTimeMeanInner)" => $arrtimemax,
"Min(fArrTimeMeanInner)" => $arrtimemin,
"Max(fArrTimeRmsInner)" => $arrtimermsmax,
"Avg(fMeanPedRmsInner)" => $pedrmsmean,
"Std(fMeanPedRmsInner)" => $pedrmsrms,
"Min(fMeanPedRmsInner)" => $pedrmsmin,
"Max(fMeanPedRmsInner)" => $pedrmsmax,
"Min(fPulsePosMean)" => $pulseposmin,
"Max(fPulsePosMean)" => $pulseposmax,
"Max(fPulsePosRms)" => $pulseposrmsmax,
"Max(fMaxHumidity)" => $hummax,
"Max(fInhomogeneity)" => $inhommax,
"Avg(fInhomogeneity)" => $inhommean,
"Std(fInhomogeneity)" => $inhomrms,
"Min(fMeanNumberIslands)" => $numislmin,
"Max(fMeanNumberIslands)" => $numislmax,
"Avg(fDataRate)" => $clratemean,
"Min(fDataRate)" => $clratemin,
"Max(fDataRate)" => $clratemax,
"Min(fMuonRate)" => $muonratemin,
"Max(fMuonRate)" => $muonratemax,
"Min(fMuonNumber)" => $muonnumbermin,
"Avg(fPSF)" => $psfmean,
"Std(fPSF)" => $psfrms,
"Min(fPSF)" => $psfmin,
"Max(fPSF)" => $psfmax,
"Min(fEffOnTime/fRunTime)" => $relontimemin,
"Max(fEffOnTime/fRunTime)" => $relontimemax,
"Min(fBrightnessMed)" => $brightmin,
"Max(fBrightnessMed)" => $brightmax,
"Min(fNumStarsMed)" => $idstarsmin,
"Max(fNumStarsMed)" => $idstarsmax,
"Min(fNumStarsCorMed)" => $corstarsmin,
"Max(fNumStarsCorMed)" => $corstarsmax,
"Min(fZenithDistanceMin)" => $zdmin,
"Max(fZenithDistanceMax)" => $zdmax,
"Min(fRunStart)" => $starttime,
"Max(fRunStop)" => $stoptime,
);
//get runtimes of dataset
function GetSequenceValues($db_id, $sequences, $txt, &$values)
{
$query="SELECT COUNT(*) ";
foreach($values as $name => $varname)
$query.=", " . $name;
$query.=" FROM Sequences ";
$query.=" LEFT JOIN Calibration USING(fSequenceFirst,fTelescopeNumber) ";
$query.=" LEFT JOIN Star USING(fSequenceFirst,fTelescopeNumber) ";
$query.=" WHERE Sequences.fSequenceFirst IN (" . $sequences . ")";
$result = mysql_query($query, $db_id);
$row = mysql_fetch_assoc($result);
foreach($values as $name => $varname)
$values[$name][$txt]=$row[$name];
mysql_free_result($result);
}
//get next dataset#
$query="SELECT fDataSetNumber+1 FROM DataSets ORDER BY fDataSetNumber DESC LIMIT 0,1";
$result = mysql_query($query, $db_id);
$row = mysql_fetch_assoc($result);
$dataset=$row["fDataSetNumber+1"];
if (empty($dataset))
$dataset=1;
mysql_free_result($result);
//get sourcenames
function GetSources($db_id, $sequences)
{
$query="SELECT fSourceName FROM Source LEFT JOIN Sequences USING(fSourceKEY) ";
$query.="WHERE fSequenceFirst IN (" . $sequences . ") GROUP BY fSourceName";
$result = mysql_query($query, $db_id);
while ($row = mysql_fetch_assoc($result))
$sources.=" " . $row["fSourceName"];
mysql_free_result($result);
return $sources;
}
$sourceson=GetSources($db_id, $on);
$sourcesoff=GetSources($db_id, $off);
//get sourcename for dataset
$son=str_replace(" ", "','", trim($sourceson));
$query="SELECT fRealSourceKEY, Count(*), fSourceName FROM Source where fSourceName IN ('" . $son . "') GROUP BY fRealSourceKEY";
$result = mysql_query($query, $db_id);
$row = mysql_fetch_assoc($result);
$numsources=$row["Count(*)"];
$numrealkeys=mysql_num_rows($result);
$_SESSION["realsourcekey"]=$row["fRealSourceKEY"];
$_SESSION["realsourcename"]=$row["fSourceName"];
mysql_free_result($result);
//printf("found %s sources with real sourcekey %s", $numsources, $realsourcekey);
//printf("found %s keys", $numrealkeys);
//check observationmode for on-sequences
$query="SELECT fObservationModeKEY FROM Sequences where fSequenceFirst IN (" . $on . ") GROUP BY fObservationModeKEY";
$result = mysql_query($query, $db_id);
$row = mysql_fetch_assoc($result);
$obskey=$row["fObservationModeKEY"];
$numobskeys=mysql_num_rows($result);
mysql_free_result($result);
//check dt for on-sequences
$query="SELECT fDiscriminatorThresholdTableKEY FROM Sequences where fSequenceFirst IN (" . $on . ") GROUP BY fDiscriminatorThresholdTableKEY";
$result = mysql_query($query, $db_id);
$numdtkeys=mysql_num_rows($result);
mysql_free_result($result);
//set limit
$runtimelimit=5;
$unsuitablemaxlimit=15;
$isolatedlimit=0;
$imclimit=0;
$pedrmsrms=0.09;
$scalelimit=1.3;
$inhomlimit=13;
$numstarslimit=20;
$numstarscorlimit=10;
//check values for infos, warnings and errors
$numerr=0;
if (!empty($on))
{
$color=array("INFO" => "#000000",
"WARN" => "#FF9900",
"ERROR" => "#FF0000");
printf("
\n");
$vals=array("on", "off");
foreach($vals as $num => $val)
{
if (empty(${$val}))
continue;
//get information from the database
GetSequenceValues($db_id, ${$val}, $val, $values);
if ($values["Min(fNumStarsCorMed)"][$val]<$numstarscorlimit)
printf("
%s: At least one of your %s-sequences has less than %s correlated stars (%s).
\n",
$color["WARN"], "WARN", $val, $numstarscorlimit, $values["Min(fNumStarsCorMed)"][$val]);
if ($values["Min(fNumStarsMed)"][$val]<$numstarslimit)
printf("
%s: At least one of your %s-sequences has less than %s identified stars (%s).
\n",
$color["WARN"], "WARN", $val, $numstarslimit, $values["Min(fNumStarsMed)"][$val]);
if ($values["Min(fRunTime)/60"][$val]<$runtimelimit)
printf("
%s: At least one of your %s-sequences is shorter than %s min (%s min).
\n",
$color["INFO"], "INFO", $val, $runtimelimit, $values["Min(fRunTime)/60"][$val]);
if ($values["Max(fInhomogeneity)"][$val]>$inhomlimit)
printf("
%s: At least one of your %s-sequences has an inhomogeneity larger than %s (%s).
\n",
$color["WARN"], "WARN", $val, $inhomlimit, $values["Max(fInhomogeneity)"][$val]);
if ($values["Max(fUnsuitableInner)"][$val]>$unsuitablemaxlimit)
printf("
%s: At least one of your %s-sequences has more than %s unsuitable inner pixel (%s).
\n",
$color["WARN"], "WARN", $val, $unsuitablemaxlimit, $values["Max(fUnsuitableInner)"][$val]);
if ($values["Max(fIsolatedInner)"][$val]>$isolatedlimit)
printf("
%s: At least one of your %s-sequences has more than %s isolated inner pixel (%s).
\n",
$color["WARN"], "WARN", $val, $isolatedlimit, $values["Max(fIsolatedInner)"][$val]);
if ($values["Max(fIsolatedMaxCluster)"][$val]>$imclimit)
printf("
%s: At least one of your %s-sequences has more than %s isolated max cluster (%s).
\n",
$color["WARN"], "WARN", $val, $imclimit, $values["Max(fIsolatedMaxCluster)"][$val]);
}
//check selected dataset for errors
if (!empty($on) && $values["Max(fMeanPedRmsInner)"]["on"]>$values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms)
printf("
%s: At least one of your on-sequences has a PedRms larger than %s (%s).
\n",
$color["WARN"], "WARN", $values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms, $values["Max(fMeanPedRmsInner)"]["on"]);
if (!empty($off) && $values["Max(fMeanPedRmsInner)"]["off"]>$values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms)
printf("
%s: At least one of your off-sequences has a PedRms larger than %s (%s).
\n",
$color["WARN"], "WARN", $values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms, $values["Max(fMeanPedRmsInner)"]["off"]);
if (!empty($off) && $values["Min(fMeanPedRmsInner)"]["off"]<$values["Avg(fMeanPedRmsInner)"]["on"]-$pedrmsrms)
printf("
%s: At least one of your off-sequences has a PedRms smaller than %s (%s).
%s: Your scale factor is larger than %s (%0.2f). Try to find more offdata!
\n",
$color["WARN"], "WARN", $scalelimit, $scale);
$doubleseq=0;
foreach(explode(" ", $_SESSION["sequon"]) as $n => $s)
{
if (ereg($s, $_SESSION["sequoff"]))
$doubleseq++;
}
if ($obskey!=$_SESSION["obsmode"])
{
printf("
%s: You have a mistake in your observation mode.
\n",
$color["ERROR"], "ERROR");
$numerr=$numerr+1;
}
if ($doubleseq>0)
{
printf("
%s: You have selected sequences (%s) as On AND Off.
\n",
$color["ERROR"], "ERROR", $doubleseq);
$numerr=$numerr+1;
}
if ($numrealkeys>1)
{
printf("
%s: You have selected more than one (%s) on source.
\n",
$color["ERROR"], "ERROR", $numrealkeys);
$numerr=$numerr+1;
}
if ($numobskeys>1)
{
printf("
%s: You have selected more than one (%s) different observation modes in your on sequences.
\n",
$color["ERROR"], "WARN", $numobskeys);
//$numerr=$numerr+1;
}
if ($numdtkeys>1)
{
printf("
%s: Your selected on sequences have more than one (%s) different discriminator threshold tables.
\n",
$color["ERROR"], "WARN", $numdtkeys);
}
if (empty($_SESSION["realsourcekey"]))
{
printf("
%s: The source you selected does not have a real sourcekey, yet. Please insert fRealSourceKEY in the DB for %s (contact: datacenter@astro.uni-wuerzburg.de).
\n",
$color["ERROR"], "ERROR", $sourceson);
$numerr=$numerr+1;
}
if (empty($_SESSION["name"]))
{
printf("
%s: You have to choose a name.
\n",
$color["ERROR"], "ERROR");
$numerr=$numerr+1;
}
if (empty($_SESSION["comment"]))
{
printf("
");
//set runtime in session (has to be after calling GetSequenceValues())
$_SESSION["runtime"] = $values["Sum(fRunTime)/60"]["on"];
$_SESSION["zdmin"] = $values["Min(fZenithDistanceMin)"]["on"];
$_SESSION["zdmax"] = $values["Max(fZenithDistanceMax)"]["on"];
$_SESSION["meanrate"] = $values["Avg(fDataRate)"]["on"];
$_SESSION["psfmean"] = $values["Avg(fPSF)"]["on"];
$_SESSION["psfmin"] = $values["Min(fPSF)"]["on"];
$_SESSION["psfmax"] = $values["Max(fPSF)"]["on"];
printf("SequencesOn: %s \n", $_SESSION["sequon"]);
if ($_SESSION["sequoff"]!=" ")
printf("SequencesOff: %s \n", $_SESSION["sequoff"]);
printf("Observation mode: %s \n", $obsmode);
printf("RunTime: %s min \n", $_SESSION["runtime"]);
printf("Mean Rate after cleaning: %s Hz \n", $_SESSION["meanrate"]);
printf("Zd: %s - %s deg \n", $_SESSION["zdmin"], $_SESSION["zdmax"]);
printf("PSF: %s (%s - %s) mm \n", $_SESSION["psfmean"], $_SESSION["psfmin"], $_SESSION["psfmax"]);
//user name
printf("User name: %s
\n", $_SERVER['PHP_AUTH_USER']);
// data set name and comment: to be inserted by the user
printf("Data set name: \n", $_SESSION["name"]);
printf("Comment:
\n", $_SESSION["comment"]);
//PrintUpdateDataSetButton() has to be called before InsertDataSet()
// to ensure that there are no problem with insert and $_SESSION["insert"]
//allow 'insert/get dataset' in case no error is found
if ($numerr!=0)
{
printf("Remark: Only data sets without errors can be inserted. ");
printf("Your data set has %s error(s).
", $numerr);
PrintUpdateDataSetButton();
}
else
{
PrintUpdateDataSetButton();
if ($_SERVER['PHP_AUTH_USER']=="MAGIC")
printf("
\n Remark: As user MAGIC you are not allowed to insert data sets into the database. For an own account, please contact datacenter@astro.uni-wuerzburg.de
\n");
else
InsertDataSet($values, $dataset);
printf(" \n", GetClearedURL());
}
//print table with more information on dataset
printf("
\n");
printf("
More Information on Your Data Set:
");
printf("
Next DataSet# in DB:
%s
", $dataset);
printf("
SequencesOn:
%s
", $_SESSION["sequon"]);
if ($_SESSION["sequoff"]!=" ")
{
printf("
SequencesOff:
%s
", $_SESSION["sequoff"]);
printf("
Scale factor (On/Off):
%0.2f
", $scale);
}
printf("
SourcenamesOn [%s]:
%s
", str_word_count($sourceson, 0, "1234567890+"), $sourceson);
if ($_SESSION["sequoff"]!=" ")
printf("