\n");
printf("Remark: To store your selection, you have to press 'Update Selection' \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 number: (only used for data set file) \n", $_SESSION["AnalysisNumber"]);
printf("Data set name: \n", $_SESSION["name"]);
printf("Comment:
\n", $_SESSION["comment"]);
//PrintUpdateDataSetButton() has to be called before InsertUpdateDataSet()
// 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
InsertUpdateDataSet($values, $dataset);
printf(" \n", GetClearedURL());
}
//print table with more information on dataset
printf("
\n");
foreach($values as $name => $varname)
{
printf("
%s
\n", $name);
foreach($vals as $num => $val)
if (!empty(${$val}))
printf("
%s
\n", $varname[$val]);
printf("
\n");
}
printf("
\n");
}
}
else
{
if ($_SESSION["user"]!=$_SESSION["olduser"] && !empty($_SESSION["olduser"]))
printf("Remark: You (userkey %s) are not allowed to change data set # %d (created by userkey %s). \n",
$_SESSION["user"], $_SESSION["SelectedDataSet"], $_SESSION["olduser"]);
else
{
printf("
\n");
printf("Remark: To store your selection for the data set, you have to press 'Store Selection' \n");
}
}
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
}
else
PrintText($result0);
mysql_free_result($result0);
mysql_free_result($result1);
}
mysql_close($db_id);
if ($html=="1")
PrintSubmittedQuery($query0, $db, "");
}
include ("include.php");
include ("menu.php");
include ("db.php");
include ("magicdefs.php");
// $debug="yes";
session_start();
if ($debug)
{
echo "GET: ";
print_r($_GET);
echo " ";
echo "POST: ";
print_r($_POST);
echo " ";
}
// set values given by $_GET
foreach ($_GET as $element => $value)
$_SESSION[$element]=$value;
// unset values in case of 'Reset'
if (empty($_GET))
foreach($_SESSION as $element => $value)
unset($_SESSION[$element]);
// set values given by $_POST
if (!empty($_POST))
foreach ($_POST as $element => $value)
$_SESSION[$element]=$value;
else
unset($_SESSION["SelectAllSequForDS"]);
if ($debug)
print_r($_SESSION);
/*
if ($_SESSION["DisplaySelected"]=="yes")
{
unset($_SESSION["fNumStart"]);
$_GET["fNumStart"]=0;
}
*/
$_SESSION["sequon"]="";
$_SESSION["sequoff"]="";
foreach($_SESSION as $key => $val)
{
if ($val=="ON" && ereg("^DSSeq[0-9]*$", $key))
$_SESSION["sequon"].=str_replace("DSSeq", " ", $key);
if ($val=="Off" && ereg("^DSSeq[0-9]*$", $key))
$_SESSION["sequoff"].=str_replace("DSSeq", " ", $key);
if ($val=="Not" && ereg("^DSSeq[0-9]*$", $key))
unset($_SESSION[$key]);
}
if (empty($_SESSION["sequon"]) && empty($_SESSION["sequoff"]))
unset($_SESSION["DisplaySelected"]);
ini_set("display_errors", "On");
ini_set("mysql.trace_mode", "On");
if (!isset($_SERVER['PHP_AUTH_USER']))
{
header('WWW-Authenticate: Basic realm="Build Datasets"');
header('HTTP/1.0 401 Unauthorized');
return;
}
else
{
$db_id = mysql_connect($host, $user, $pw);
if ($db_id==FALSE)
{
printf("mysql_connect returned the following error: ");
printf("%s ", mysql_error());
die("");
}
$userquery = "SELECT fUserName, fPassword, fUserKEY FROM " . $db . ".User ORDER BY fUserKEY";
$userresult = mysql_query($userquery);
if (!$userresult)
echo "query failed";
$validuser="no";
while ($userrow = mysql_fetch_assoc($userresult))
{
// echo crypt($_SERVER['PHP_AUTH_PW']). " ";
// echo "with crypt: " . crypt($_SERVER['PHP_AUTH_PW'], $userrow["fPassword"]) . " for user " . $userrow["fUserName"]. " ";
if (crypt($_SERVER['PHP_AUTH_PW'], $userrow["fPassword"])==$userrow["fPassword"]
&& $_SERVER['PHP_AUTH_USER']==$userrow["fUserName"])
{
$validuser="yes";
$_SESSION["user"]=$userrow["fUserKEY"];
}
}
mysql_free_result($userresult);
if ($validuser=="no")
{
printf(" Password or username incorrect ");
return;
}
}
if (!empty($_GET["fSendTxt"]))
{
header("Content-Type: application/octet");
switch($_GET["fSendTxt"])
{
case 1:
header("Content-Disposition: attachment; filename=query-result.txt");
PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
break;
case 2:
header("Content-Disposition: attachment; filename=dataset_".str_replace(" ", "_", $_SESSION["name"]).".txt");
PrintDataSetFile();
}
unset($_SESSION["fSendTxt"]);
}
else
{
echo (file_get_contents("index-header.html"));
$environment = sizeof($_GET);
// Find out whether it is the first call to the php script
$first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
InitBuildDataSets($first);
if (empty($_GET["fPrintTable"]))
PrintForm($host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
if ($environment==0)
{
printf("No query submitted yet.
\n");
printf("Either query above, or you have also the option to start with an already existing data set: \n");
printf("Dataset:
\n", $_SESSION["SelectedDataSet"]);
printf("How do you want to process this data set? \n");
printf("Use data set as starting point. \n",
$_SESSION["DataSetSelection"]=="SelectSequences"?"checked":"");
printf("Update data set in database.
\n",
$_SESSION["DataSetSelection"]=="UpdateDataSet"?"checked":"");
printf(" \n");
printf("\n");
}
else
{
printf("\n");
if (empty($_SESSION["DataSetSelection"]) && !empty($_SESSION["SelectedDataSet"]))
{
printf("Remark: You have inserted a data set number (%s), but not selected what you want to do with it. \n",
$_SESSION["SelectedDataSet"]);
printf("Please press 'Reset'. Then to choose a data set and what you want to do with it or simply 'Query Table' to start a new data set. \n");
}
else
{
if (empty($_GET["fPrintTable"]))
PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
else
PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
}
}
echo (file_get_contents("index-footer.html"));
}
if (!empty($_SESSION["DataSetSelection"]))
$_SESSION["DataSetAcknowledged"]="yes";
ini_set("display_errors", "Off");
ini_set("mysql.trace_mode", "Off");
?>