# URLs for this page are in the form blah.php?&file=20040250000
# useful PHP URLs at http://uk.php.net/manual/en/ref.array.php
# Inputs like:
# plots.php?PERIOD=Day&PLOT=3DF&T=1&YEAR=2004&MONTH=06&DAY=06 - assumes a day plot
# plots.php?&file=3DF_T1_20040810_0000_D0000
# plots.php?&file=3DF_T1_20040810_0000_D0000&PERIOD=Orbit
$monthdays=array(0,0,31,59,90,120,151,181,212,243,273,304,334,365);
$monthdayL=array(0,0,31,60,91,121,152,182,213,244,274,305,335,366);
$monthdur =array(0,31,28,31,30,31,30,31,31,30,31,30,31); # same line lower down.
$monthname=array("0","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$plottype =array(0,"3DF","TIMING");
$periodtype=array(0,"day","orbit");
$anodetype=array(0,"two anodes", "all anodes");
$currentlagtime=21*86400; # 3 weeks lag (2 weeks wasn't enough on a quick test)
$defaultyear =date('y',time()-$currentlagtime)+2000;
$defaultmonth=date('m',time()-$currentlagtime);
$defaultday =date('d',time()-$currentlagtime);
#$defaultyear ="2004";$defaultmonth="09";$defaultday ="01";
$file="";
if (isset($_GET[file])) {
$file= $_GET[file];
if (strlen($file) >40 ) { $file=""; } # Stop huge strings breaking it.
}
if ( preg_match("/_[Tt][12]_200[6789][01]\d[0123]\d_\d\d\d\d_[dD]\d\d\d\d$/", $file) ) {
$message= "PERFECT URL!";
$pieces= explode("_", $file);
$plot=$pieces[0]; # type of plot
if (in_array($plot, $plottype)) {} # good
else {$plot=$plottype[1];}
$TC=substr($pieces[1],1,1); # s/c, no need for check since in preg_match
$year=substr($pieces[2],0,4); # year
# if ($year<2004 ) { $year=2004;}# earliest year = 2004 - both lines commented out as taken care of in preg_match above
# if ($year>2009 ) { $year=2004;}# Max year = 2009 (end of)
if ($year=="2008") {$monthday=$monthdayL;$monthdur[2]=29;}
else {$monthday=$monthdays;}
$month=substr($pieces[2],4,2); # month
if ( (int)$month<1 || (int)$month >12) { $month="01";}
$month=sprintf("%02d",(int)$month);
$day =substr($pieces[2],6,2); # day
if ($day > $monthdur[(int)$month] ) { $day="01";}
$day=sprintf("%02d",(int)$day);
$ST=$pieces[3];
if ( (int)substr($ST ,2,2) > 59) { $ST =substr($ST ,0,2)."00"; }
$DUR=substr($pieces[4],1,4);
if ( (int)substr($DUR,2,2) > 59) { $DUR=substr($DUR,0,2)."00"; }
if ($DUR == "2400") { $period = $periodtype[1];} # Day
elseif ($DUR != "0100") { $period = $periodtype[2];} # Not Day and not Hour, so Orbit
else { # must be an hour plot - but don't know if came from orbit or day
if (isset($_GET[PERIOD])) {
$period= $_GET[PERIOD];
if (strlen($period) >10 ) { $period=$periodtype[1]; } # Stop huge strings breaking it.
if (in_array($period, $periodtype)) {} # good
else {$period=$periodtype[1];} # assume it's a day one
}
else {$period=$periodtype[1];}
}
} # end #file
else {
if (isset($_GET[PERIOD])) {
$period= $_GET[PERIOD];
if (strlen($period) >10 ) { $period=$periodtype[1]; } # Stop huge strings breaking it.
if (in_array($period, $periodtype)) {} # good
else {$period=$periodtype[1];}
}
else {$period=$periodtype[1];}
$plot=$plottype[1];
if (isset($_GET[PLOT])) {
$plot= $_GET[PLOT];
# if (strlen($plot) >10 ) { $plot=$plottype[1]; } # Stop huge strings breaking it.
if (in_array($plot, $plottype)) {} # good
else {$plot=$plottype[1];}
}
$TC="1";
if (isset($_GET[T])) {
$TC= $_GET[T];
# if (strlen($TC) >1 ) { $TC="1"; } # Stop huge strings breaking it.
if ( preg_match("/^[12]$/", $TC) ) {} # good
else {$TC="1";}
}
$year=$defaultyear;
$monthday=$monthdayL;
if (isset($_GET[YEAR])) {
$year= $_GET[YEAR];
# if (strlen($year) >4 ) { $year=$defaultyear; } # Stop huge strings breaking it.
if ( preg_match("/^200[456789]$/", $year) ) {} # good
else {$year=$defaultyear;}
if ($year == "2004" or $year == "2008") {$monthday=$monthdayL;$monthdur[2]=29;}
else {$monthday=$monthdays;}
}
$year=sprintf("%04d",(int)$year);
$month=$defaultmonth;
if (isset($_GET[MONTH])) {
$month= $_GET[MONTH];
# if (strlen($month) >2 ) { $month="01"; } # Stop huge strings breaking it.
if ( preg_match("/^0[123456789]$/", $month) ) {} # good
elseif ( preg_match("/^1[012]$/", $month) ) {} # good
else {$month=$defaultmonth;}
}
$month=sprintf("%02d",(int)$month);
$day=$defaultday;
if (isset($_GET[DAY])) {
$day= $_GET[DAY];
# if (strlen($day) > 2 ) { $day="01"; } # Stop huge strings breaking it.
if ( preg_match("/^[0123]\d$/", $day) ) {
if ($day > $monthdur[(int)$month] ) { $day="01";}
} # good
else {$day=$defaultday;}
}
$day=sprintf("%02d",(int)$day);
$ST ="0000";
$DUR="2400";
# Assumes file is for a day, not an orbit.
$file=$plot."_T".$TC."_".$year.$month.$day."_".$ST."_D".$DUR;
# If orbit was selected, turn to orbit
if ($period==$periodtype[2]) { # D
$file=newfilename($file,$plot,$TC,$year,$month,$day,"0000","2400","+orbit","orbit");
$pieces= explode("_", $file);
$ST=$pieces[3];
$DUR=substr($pieces[4],1,4);
}
}
$DOY=sprintf("%03d",(int)$day+(int)$monthday[(int)$month]); # gives Day of Year number
?>
#######################################################################
function newfilename($file,$plot,$TC,$year,$month,$day,$ST,$DUR,$durT,$newDUR) {
# $durT=[+-]\d\d\d\d or [+-]orbit, $newDUR=0100, 2400, orbit
$Dyear=$year;
$Dmonth=$month;
$Dday=$day;
$DST=$ST;
$DDUR=$DUR; # needed?
$monthdur =array(0,31,28,31,30,31,30,31,31,30,31,30,31); # same line at top.
if ( preg_match("/^hrplot$/", $newDUR) ) { # cheat! using $durT not for it's intended use
$DDUR="0100";
$DST=(int)$ST+(int)$durT; # remember to make these 4 digits!
}
elseif ( preg_match("/^orbit$/", $newDUR) ) {
# Orbit back and forth here
# Load in array $imagelist
include "filelist_T".$TC."_Orbit_".$plot.".inc";
# Move from orbit to Orbit forwards
if ( preg_match("/^\+orbit$/", $durT) && $DUR != "2400" && $DUR != "0100") {
$key=array_search($file,$imagelist);
$key=(int)$key+1;
if ($key >= count ($imagelist)) {
print "Date too high for an orbit file, going to first orbit available...
\n";
return $imagelist[(int)(count ($imagelist))-1]; break;
}
return $imagelist[$key]; break;
}
# Move from orbit to Orbit backwards
elseif ( preg_match("/^-orbit$/", $durT) && $DUR != "2400" && $DUR != "0100") {
$key=array_search($file,$imagelist);
$key=(int)$key-1;
if ($key <0 ) {
$key = 0;
print "Date too low for an orbit file, going to first orbit available...
\n";
}
return $imagelist[$key]; break;
}
# Move from day to Orbit, find earlist orbit that starts that day.
elseif ($DUR == "2400" && $newDUR == "orbit") {
$search=$year.$month.$day;
$pieces= explode("_", $imagelist[0]);
if ( (int)$search < (int)$pieces[2]) { # check first date in $imagelist
print "Date too low for an orbit file, going to first orbit available...
\n";
return $imagelist[0]; break;
}
$z=0; $n= count ($imagelist);
while ($z<$n) {
if ( preg_match("/$search/", $imagelist[$z]) ) {
return $imagelist[$z]; break;
}
$z++;
}
# if got here must have not been in list...
print "Date too high for an orbit file, going to first orbit available...
\n";
return $imagelist[$n-1]; break;
}
# Move from hour to Orbit
elseif ($DUR == "0100" && $newDUR == "orbit") {
$z=0; $n= count ($imagelist); $search=$year.$month.$day;
while ($z<$n) {
if ( preg_match("/$search/", $imagelist[$z]) ) { # first one on that day.
$pieces1= explode("_", $imagelist[$z]);
$pieces2= explode("_", $imagelist[$z+1]);
# Assume no more than 2 orbits per day
if ($pieces1[3] > (int)$ST ) { # previous orbit
return $imagelist[$z-1]; break;
}
elseif ($pieces2[3] > (int)$ST ) { # current orbit
return $imagelist[$z ]; break;
}
else { # next orbit
return $imagelist[$z+1]; break;
}
}
$z++;
}
}
else { print " No orbit stuff done!"; }
}
elseif ($DUR == "2400" && $ST == "0000" && $newDUR == "orbit") {
$DDUR= $newDUR;
}
## Move from Day to hour
elseif ($DUR == "2400" && $ST == "0000" && $newDUR == "0100") {
$DDUR= $newDUR;
$DST = (int)$DST+(int)$durT;
}
## Move from hour to hour, reset minutes to zero.
elseif ($DUR == "0100" && $newDUR == "0100") {
$DST = substr($DST,0,2)."00"; # reset minutes, probably not necessary
$DST = (int)$DST+(int)$durT;
$DDUR= $newDUR; # already is 1 hour
}
# Move from Orbit to hour
elseif ($DUR != "2400" && $DUR != "0100" && $newDUR == "0100") {
$DST = substr($DST,0,2)."00"; # reset minutes
$DST = (int)$DST+(int)$durT;
$DDUR= $newDUR;
}
## Move from hour to Day,
elseif ($DUR == "0100" && $newDUR == "2400") {
$DST = "0000"; # reset hours and minutes
$DDUR= $newDUR;
}
## Move from Orbit to Day,
elseif ($DUR != "2400" && $DUR != "0100" && $newDUR == "2400") {
$DST = "0000"; # reset hours and minutes
$DDUR= $newDUR;
}
# Move from Day to Day,
elseif ($DUR == "2400" && $newDUR == "2400") {
$DST="0000"; # reset hours and minutes
$DST = (int)$DST+(int)$durT;
$DDUR= $newDUR;
}
# Assume no jump is bigger than 3days!!!!!!!
# Hours gone in to new day?
if ( (int)$DST < -4800 ) { $DST = (int)$DST + 7200 ; $Dday = (int)$Dday - 3 ;}
elseif ( (int)$DST < -2400 ) { $DST = (int)$DST + 4800 ; $Dday = (int)$Dday - 2 ;}
elseif ( (int)$DST < 0 ) { $DST = (int)$DST + 2400 ; $Dday = (int)$Dday - 1 ;}
if ( (int)$DST >= 7200 ) { $DST = (int)$DST - 7200 ; $Dday = (int)$Dday + 3 ;}
elseif ( (int)$DST >= 4800 ) { $DST = (int)$DST - 4800 ; $Dday = (int)$Dday + 2 ;}
elseif ( (int)$DST >= 2400 ) { $DST = (int)$DST - 2400 ; $Dday = (int)$Dday + 1 ;}
# day gone in to new month?
if ((int)$Dmonth==2 && ((int)$Dyear==2000 || (int)$Dyear==2004 || (int)$Dyear==2008) && (int)$Dday >29 )
{ $Dday = (int)$Dday - 29; $Dmonth = 3; }
elseif ((int)$Dmonth==3 && ((int)$Dyear==2000 || (int)$Dyear==2004 || (int)$Dyear==2008) && (int)$Dday < 1 )
{ $Dday = (int)$Dday + 29; $Dmonth = 2; }
else {
if ( (int)$Dday > (int)$monthdur[(int)$Dmonth] ) {
$Dday = (int)$Dday - (int)$monthdur[(int)$Dmonth];
$Dmonth = (int)$Dmonth + 1 ;
if ((int)$Dmonth == 13 ) {
$Dmonth == 1;
$Dyear == (int)$Dyear + 1;
if ((int)$Dyear >2009) {$Dyear = 2009; $Dmonth = 12; $Dday = 31; $DST=0; $DDUR=2400;}
}
}
elseif ( (int)$Dday < 1 ) {
$Dmonth = (int)$Dmonth - 1 ;
if ((int)$Dmonth == 0) {
$Dmonth=12;
$Dyear = (int)$Dyear - 1;
if ((int)$Dyear <2004) {$Dyear = 2004; $Dmonth = 1; $Dday = 1; $DST=0; $DDUR=2400;}
}
$Dday = (int)$Dday + (int)$monthdur[(int)$Dmonth]; # make sure have reduced month first!
}
}
$Dyear =sprintf("%04d",(int)$Dyear );
$Dmonth=sprintf("%02d",(int)$Dmonth);
$Dday =sprintf("%02d",(int)$Dday );
$DST =sprintf("%04d",(int)$DST );
$DDUR =sprintf("%04d",(int)$DDUR );
return $plot."_T".$TC."_".$Dyear.$Dmonth.$Dday."_".$DST."_D".$DDUR;
}
?>