(($gwdYear * 12) + $gwdMonth); $m--) { $y = (($m - 1) / 12); $i = ($m % 12) + 12; if(isLeapYear($y) == 1) { $dcm[1] = 29; $dcm[13] = 29; }else{ $dcm[1] = 28; $dcm[13] = 28; } $diffDays = $diffDays + $dcm[$i-1]; } $diffDays = $diffDays + ($dcm[$gwdMonth - 1] - $gwdDay); $weekDay = ($diffDays % 7) - 2; if($weekDay < 0) $weekDay = $weekDay + 7; return($weekDay + 1); } function getDateNumber($year, $month, $day){ $diffDays = 0; for($y = 0; $y < $year; $y++) { $diffDays = $diffDays + 365; if(isLeapYear($y) == 1) $diffDays = $diffDays + 1; } for($m = 1; $m < $month; $m++) { if($m == 1 or $m == 3 or $m == 5 or $m == 7 or $m == 8 or $m == 10 or $m == 12) { $diffDays = $diffDays + 31; }else{ $diffDays = $diffDays + 30; } if(isLeapYear($year) == 1 and $m == 2) $diffDays = $diffDays - 1; if(isLeapYear($year) == 0 and $m == 2) $diffDays = $diffDays - 2; } $diffDays = $diffDays + $day; return($diffDays); } function CalculateIsoWeekday($year, $month, $day){ // This function converts the weekday-numbers from the // standard function to an offset acc. to the ISO version // monday -> 0, ... , sunday -> 6 $n = getWeekday($year, $month, $day); return($n - 1); } function getWeekNumber($year, $month, $day){ // The year value is preset with that of the input date $YearInQuestion = $year; // Calculate offset to monday from the input date $InputDateOffset = CalculateIsoWeekday($year, $month, $day); // Calculate offsets for the first/last day of the year $January1Offset = CalculateIsoWeekday($YearInQuestion, 1, 1); $December31Offset = CalculateIsoWeekday($YearInQuestion, 12, 31); // If the input date is before the 4th of January and the year starts with // a friday, saturday or sunday, the week belongs to the previous year // if the entered date is not a monday or tuesday if($month == 1 and $day < 4 and $January1Offset > 3 and $InputDateOffset > 1) { $YearInQuestion = $YearInQuestion - 1; } // If the input date is after the 28th of December and the year ends with // a monday, tuesday or wednesday, then the week belongs to the following year // if the entered date is not a saturday or sunday if ($month == 12 and $day > 28 and $December31Offset < 3 and $InputDateOffset < 5) { $YearInQuestion = $YearInQuestion + 1; } // The 4th of January defines week #1 $January4 = getDatenumber($YearInQuestion, 1, 4); // Offset to the monday of week #1 $FirstMondayOfYear = getDatenumber($YearInQuestion, 1, 4 - CalculateIsoWeekday($YearInQuestion, 1, 4)); // The time range between the monday of week #1 and the monday // of the week in question is divided by 7, plus 1 for the first week $weeknum = (getDateNumber($year, $month, $day) - $InputDateOffset - $FirstMondayOfYear ) / 7 + 1; return($weeknum); } function phpdate($year, $month, $day, $format){ if($format == "mmmm") { if($month == 1) return("January"); if($month == 2) return("February"); if($month == 3) return("March"); if($month == 4) return("April"); if($month == 5) return("May"); if($month == 6) return("June"); if($month == 7) return("July"); if($month == 8) return("August"); if($month == 9) return("September"); if($month == 10) return("October"); if($month == 11) return("November"); if($month == 12) return("December"); } if($format == "yyyy") { return($year); } } function datetoname( $year, $month, $day,$instr) { $filename .= $year; if ($month <10 ) { $filename .= "0".$month; if ($day <10) { $filename .="0".$day; } else { $filename .=$day; } } else { $filename .=$month; if ($day <10) { $filename .="0".$day; } else { $filename .=$day; } } if ($instr =="aot"){ $filename .= "_".$instr.".gif"; } else { if ($instr =="tsi") { $filename .="/"; $filename .= $year; if ($month <10 ) { $filename .= "0".$month; if ($day <10) { $filename .="0".$day; } else { $filename .=$day; } } else { $filename .=$month; if ($day <10) { $filename .="0".$day; } else { $filename .=$day; } } $filename .="_TSI_movie.avi"; } else $filename .="_".$instr.".jpeg"; } return ($filename); } function getCalendar() { if($_GET["year"] == "") $year = date("Y"); else $year = $_GET["year"]; if($_GET["month"] == "") $month = date("n"); else $month = $_GET["month"]; if($_GET["day"] == "") $day = date("d"); else $day = $_GET["day"]; $instr = $_GET["instrument"]; $dow = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); if(isLeapYear($year) == 1) { $dom = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); }else{ $dom = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); } $calendar ="
"; if ($instr =="diffuse") $calendar .= "Diffuse radiation measured by Eppley B&W 848"; if ($instr =="direct") $calendar .= "Direct radiation measured by Eppley NIP"; if ($instr =="CM21_CM11") $calendar .= "Total radiation measured by K&Z CM21 and CM11"; if ($instr =="LW") $calendar .= "Longwave radiation measured by Eppley PIR Pyrgeometer"; if ($instr =="TUV") $calendar .= "Total UV radiation measured by Eppley TUV Radiometer"; if ($instr =="PAR") $calendar .= "Photosynthetically-active Radiation measured by K&Z PAR-LITE"; if ($instr =="Tc_Td") $calendar .= "Case and Dome Temperature"; if ($instr =="aot") $calendar .= "Aerosol Optical Depth measured by MFRSR-7"; if ($instr =="Diff_CM11-CM21") $calendar .="Difference between CM11 and CM21 Data"; if ($instr =="Diff_CM21-NIP-BW") $calendar .= "Difference between CM21 and the sum of NIP and BW"; if ($instr =="Rela_CM21-NIP-BW") $calendar .= "Relative Difference between CM21 and the sum of NIP and BW"; if ($instr =="Diff_Tc-Td") $calendar .= "Difference between the case and dome temperature"; if ($instr =="Ratio-PAR") $calendar .= "Ratio of PAR to total"; if ($instr =="Ratio-TUV") $calendar .= "Ratio of TUV to total"; if ($instr =="tsi") $calendar .= "Total sky imager animation from YES TSI"; $calendar .="

"; $calendar .=""; $calendar .= "
"; $calendar .= "
"; $calendar .= ""; $calendar .= ""; $calendar .= ""; $calendar .= ""; $calendar .= ""; $calendar .= ""; $calendar .= ""; $calendar .= ""; $dayno = 2 - getWeekDay($year, $month, 1); $daymin = 1; $daymax = $dom[$month - 1]; if($month == 1) {$daymaxl = 12;} else {$daymaxl = $month - 1;} for($row = 1; $row <= 7; $row++) { for($col = 1; $col <= 8; $col++) { $calendar .= ""; } $calendar .= ""; } $calendar .= ""; $calendar .= "
"; $calendar .= "C A L E N D A R"; $calendar .= "
"; $m = $month; $y = $year - 1; if($year != 1900) $calendar .= "7"; if($month == 1) { $m = 12; $y = $year - 1; }else{ $m = $month - 1; $y = $year; } if(!($year == 1900 and $month == 1)) $calendar .= "3"; $calendar .= "
"; $calendar .= "".phpdate($year, $month, $day, "mmmm", $lang) . " " . phpdate($year, $month, $day, "yyyy", $lang).""; $calendar .= "
"; if($month == 12){ $m = 1; $y = $year + 1; }else{ $m = $month + 1; $y = $year; } $calendar .= "4"; $m = $month; $y = $year + 1; $calendar .= "8"; $calendar .= "
"; // print weekday headers if($row == 1 and $col != 1) { $calendar .= ""; $calendar .= $dow[$col-1-1]; $calendar .= ""; } // print weeknumbers if($row != 1 and $col == 1) { $calendar .= ""; if($dayno < $daymin){ $y = $year; if($month == 1) $m = 12; if($month != 1) $m = $month - 1; if($month == 1) $y = $year - 1; $d = ($dom[$daymaxl - 1]) + $dayno; $calendar .= sprintf("%02d",getWeekNumber($y, $m, $d)); }else{ if($dayno > $daymax){ $y = $year; if($month == 12) $m = 1; if($month != 12) $m = $month + 1; if($month == 12) $y = $year + 1; $d = $dayno - $daymax; $calendar .= sprintf("%02d",getWeekNumber($y, $m, $d)); }else{ $calendar .= sprintf("%02d",getWeekNumber($year, $month, $dayno)); } } $calendar .= ""; } // print day numbers if($row > 1 and $col != 1){ if($dayno < $daymin){ $calendar .= ""; $calendar .= ($dom[$daymaxl - 1]) + $dayno; $calendar .= ""; }else{ if($dayno > $daymax){ $calendar .= ""; $calendar .= $dayno - $daymax; $calendar .= ""; }else{ $filename = datetoname($year,$month,$dayno,$instr); if (file_exists("/data/arm/china/".$instr."/".$filename)) { $calendar .= ""; $calendar .= ""; $calendar .= $dayno; $calendar .= ""; $calendar .= ""; } else { $calendar .= ""; $calendar .= $dayno; $calendar .= ""; } } } $dayno = $dayno + 1; } $calendar .= "
".$instr."
"; return($calendar); } ?> getCalendar()