0)) $lastyear = $skol[0]; if($skol[1]>0 && $skol[1] <10000){ $nlin++; if($skol[0]>1900) $nlin00++; if($skol[0]>1925) $nlin25++; if($skol[0]>1950) $nlin50++; if($skol[0]>1900 && $skol[0]<(1900+($endYear-1900)/3)) $nlin00_1t++; // series with many holes in the start has to be rejected if($skol[0]>1925 && $skol[0]<(1925+($endYear-1925)/3)) $nlin25_1t++; if($skol[0]>1950 && $skol[0]<(1950+($endYear-1950)/3)) $nlin50_1t++; if($skol[0]>1900 + ($endYear-1900)*2/3) $nlin00_3t++; // series with many holes in the end has to be rejected if($skol[0]>1925 + ($endYear-1925)*2/3) $nlin25_3t++; if($skol[0]>1950 + ($endYear-1950)*2/3) $nlin50_3t++; } } // printf("start=%s, end=%s, lines=%s\n", $firstyear, $lastyear, $nlin); rewind($sfile); $sline= fgets($sfile); $m18=0; $vlong = false; $vlong_xLY = false; $long = false; $mlong = false; if($firstyear <= 1900 && $lastyear >= ($endYear) && $nlin00 > 0.8*12*($endYear-1900) && $nlin00_1t > 0.8*12*($endYear-1900)/3 && $nlin00_3t > 0.8*12*($endYear-1900)/3) { $vlong = true; // $novl++; // printf("Very long series: %s, lines=%d\n", $filn, $nlin00); } //very long if($firstyear <= 1900 && $lastyear +1 >= ($endYear) && $nlin00 > 0.8*12*($endYear-1900-1) && $nlin00_1t > 0.8*12*($endYear-1900-1)/3 && $nlin00_3t > 0.8*12*($endYear-1900-1)/3) { $vlong_xLY = true; $novl++; printf("Very long series X last Year: %s, lines=%d, 1t=%d 3t=%d\n", $filn, $nlin00, $nlin00_1t, $nlin00_3t); } //very long_xLY (vl except last year) if($firstyear <= 1925 && $lastyear >= ($endYear) && $nlin25 > 0.8*12*($endYear-1925) && $nlin25_1t > 0.8*12*($endYear-1925)/3 && $nlin25_3t > 0.8*12*($endYear-1925)/3 && !$vlong_xLY) { $long = true; $nol++; printf("Long series: %s, lines=%d 1t=%d 3t=%d\n", $filn, $nlin25, $nlin25_1t, $nlin25_3t); } //long if($firstyear <= 1950 && $lastyear >= ($endYear) && $nlin50 > 0.8*12*($endYear-1950) && $nlin50_1t > 0.8*12*($endYear-1950)/3 && $nlin50_3t > 0.8*12*($endYear-1950)/3 && !$vlong_xLY && !$long) { $mlong = true; $noml++; printf("Medium long series: %s, lines=%d, 1t=%d 3t=%d\n", $filn, $nlin50, $nlin50_1t, $nlin50_3t); } //medium long if($firstyear <= 1925 && $lastyear >= ($endYear)) printf("Test: %s, lines=%d, 1t=%d 3t=%d\n", $filn, $nlin25, $nlin25_1t, $nlin25_3t); $nlin=0; $started=false; $lastvalue=0; while(! feof($sfile)){ $skol = explode(";", $sline); $skol[3]=trim($skol[3]); if($skol[1] <= 0 && $started){ // simple interpolation $skol[1] = $lastvalue; } if($skol[1] > 0){ $started = true; $lastvalue=$skol[1]; $m18 = round((($skol[0]+0.0416)-1800)*12); $sum[$m18] += $skol[1]; $ind[$m18]++; if($skol[1] < $misum[$m18]){$misums[$m18]=$misum[$m18]; $misum[$m18] = $skol[1]; } if($skol[1] > $masum[$m18]) $masum[$m18] = $skol[1]; if($vlong_xLY && $skol[0] > 1900 && $skol[0] < $endYear-1){ $gsum3vl[$m18][floor(($mkol[2]+90)/30)][floor(($mkol[3]+180)/30)] += $skol[1]; $gind3vl[$m18][floor(($mkol[2]+90)/30)][floor(($mkol[3]+180)/30)]++; $sumf19[$m18] += $skol[1]; $indf19[$m18]++; if($skol[1] < $misumf19[$m18]) $misumf19[$m18] = $skol[1]; if($skol[1] > $masumf19[$m18]) $masumf19[$m18] = $skol[1]; $olinef19 = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofilef19, $olinef19); } if($long && $skol[0] > 1925 && $skol[0] < $endYear){ $gsum3l[$m18][floor(($mkol[2]+90)/30)][floor(($mkol[3]+180)/30)] += $skol[1]; $gind3l[$m18][floor(($mkol[2]+90)/30)][floor(($mkol[3]+180)/30)]++; $sumf20[$m18] += $skol[1]; $indf20[$m18]++; if($skol[1] < $misumf20[$m18]) $misumf20[$m18] = $skol[1]; if($skol[1] > $masumf20[$m18]) $masumf20[$m18] = $skol[1]; $olinef20 = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofilef20, $olinef20); } if($mlong && $skol[0] > 1950 && $skol[0] < $endYear){ $gsum[$m18][floor( ($mkol[2]+90)/3)] [floor(($mkol[3]+180)/3)] += $skol[1]; $gind[$m18][floor( ($mkol[2]+90)/3)] [floor(($mkol[3]+180)/3)]++; $gsum2[$m18][floor(($mkol[2]+90)/10)][floor(($mkol[3]+180)/10)] += $skol[1]; $gind2[$m18][floor(($mkol[2]+90)/10)][floor(($mkol[3]+180)/10)]++; $gsum3[$m18][floor(($mkol[2]+90)/30)][floor(($mkol[3]+180)/30)] += $skol[1]; $gind3[$m18][floor(($mkol[2]+90)/30)][floor(($mkol[3]+180)/30)]++; $summl[$m18] += $skol[1]; $indml[$m18]++; if($skol[1] < $misumml[$m18]) $misumml[$m18] = $skol[1]; if($skol[1] > $masumml[$m18]) $masumml[$m18] = $skol[1]; $olinemlong = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofilemlong, $olinemlong); } if(($vlong || $long || $mlong) && $skol[0]>1950 && $skol[0] < $endYear){ if($mkol[2]>=30){ $sumNP[$m18] += $skol[1]; $indNP[$m18]++; if($skol[1] < $misumNP[$m18]) $misumNP[$m18] = $skol[1]; if($skol[1] > $masumNP[$m18]) $masumNP[$m18] = $skol[1]; $olineNP = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofileNP, $olineNP); } elseif($mkol[2]>=0 && $mkol[2] < 30){ $sumN60[$m18] += $skol[1]; $indN60[$m18]++; if($skol[1] < $misumN60[$m18]) $misumN60[$m18] = $skol[1]; if($skol[1] > $masumN60[$m18]) $masumN60[$m18] = $skol[1]; $olineN6 = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofileN6, $olineN6); } elseif($mkol[2]<0 && $mkol[2] > -30){ $sumS60[$m18] += $skol[1]; $indS60[$m18]++; if($skol[1] < $misumS60[$m18]) $misumS60[$m18] = $skol[1]; if($skol[1] > $masumS60[$m18]) $masumS60[$m18] = $skol[1]; $olineS6 = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofileS6, $olineS6); } elseif($mkol[2] <= -30){ $sumSP[$m18] += $skol[1]; $indSP[$m18]++; if($skol[1] < $misumSP[$m18]) $misumSP[$m18] = $skol[1]; if($skol[1] > $masumSP[$m18]) $masumSP[$m18] = $skol[1]; $olineSP = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofileSP, $olineSP); } } $nlin++; }// if $oline = sprintf("%s, %s, %s, %s, %s, %s, %s, %s, %s\n", $skol[0], $m18, $skol[1], $skol[2], $skol[3], $mkol[2], $mkol[3], $mkol[4], $mkol[5]); fwrite($ofile, $oline); $sline= fgets($sfile); // $m18++; } // while fclose($sfile); }// if }// while fclose($mfile); fclose($ofile); fclose($ofileNP); fclose($ofileN6); printf("
\n Number of files read = %d \n no very long = %d, \n no long =%d \n no medium long =%d\n", $nofiles, $novl, $nol, $noml); $m=0; $aline = sprintf("Year No Avg Min SMin Max, No19 Av19 Mi19 Ma19, No20 Av20 Mi20 Ma20, NoML AvML MiML MaML NoNP AvNP MiNP MaNP, NoN6 AvN6 MiN6 MaN6, NoS6 AvS6 MiS6 MaS6, NoSP AvSP MiSP MaSP GrVL, Grl, Grml\n"); fwrite($afile, $aline); $aline = sprintf("3x3Year Not Nog Avg Min Max\n"); $aline = sprintf("10x10Year Not Nog Avg Min Max\n"); $aline = sprintf("30x30Year Not Nog Avg Min Max\n"); fwrite($afile2, $aline); $aline = sprintf("30x30Year No Av Avgr No11 Av No12 Av No13 Av No21 Av No22 Av No23 Av No31 Av No32 Av No33 Av\n"); fwrite($afileg, $aline); for($i=1800; $i<=$currentYear; $i++){ for($j=1; $j<=12; $j++){ if($ind[$m]>0){ $y = $i + round(($j-0.5)/12,4); /* for ($lat=0; $lat <60; $lat++){ // 3x3 grid for($lon=0; $lon<120; $lon++){ if($gind[$m][$lat][$lon] >0){ $h= $gsum[$m][$lat][$lon]/$gind[$m][$lat][$lon]; $lonk = abs(cos(deg2rad(($lat+0.5)*3))); $sum2[$m] += $h * $lonk; $ind3[$m] += $lonk; $ind2t[$m] += $gind[$m][$lat][$lon]; if($h < $misum2[$m]) $misum2[$m] = $h; if($h > $masum2[$m]) $masum2[$m] = $h; } } } */ for ($lat=0; $lat <18; $lat++){ // 10x10 grid for($lon=0; $lon<36; $lon++){ if($gind2[$m][$lat][$lon] >0){ $h= $gsum2[$m][$lat][$lon]/$gind2[$m][$lat][$lon]; $lonk = abs(cos(deg2rad(($lat+0.5)*10))); $sum3[$m] += $h*$lonk; $ind3[$m] += $lonk; $ind3t[$m] += $gind2[$m][$lat][$lon]; if($h < $misum3[$m]) $misum3[$m] = $h; if($h > $masum3[$m]) $masum3[$m] = $h; } } } for ($lat=0; $lat <6; $lat++){ // 30 x 30 grid for($lon=0; $lon<12; $lon++){ $lonk = abs(cos(deg2rad(($lat+0.5)*30))); // smaller longitudes closer to the poles if($gind3[$m][$lat][$lon] >0){ $h= $gsum3[$m][$lat][$lon]/$gind3[$m][$lat][$lon]; $sum4[$m] += $h*$lonk; $ind4[$m] += $lonk; $ind4t[$m] += $gind3[$m][$lat][$lon]; if($h < $misum4[$m]) $misum4[$m] = $h; if($h > $masum4[$m]) $masum4[$m] = $h; } if($gind3vl[$m][$lat][$lon] >0){ $h= $gsum3vl[$m][$lat][$lon]/$gind3vl[$m][$lat][$lon]; $sum4vl[$m] += $h*$lonk; $ind4vl[$m] += $lonk; $ind4vlt[$m] += $gind3vl[$m][$lat][$lon]; } if($gind3l[$m][$lat][$lon] >0){ $h= $gsum3l[$m][$lat][$lon]/$gind3l[$m][$lat][$lon]; $sum4l[$m] += $h*$lonk; $ind4l[$m] += $lonk; $ind4lt[$m] += $gind3l[$m][$lat][$lon]; } } } $g10x10=$g30x30=$g30x30vl=$g30x30l=0; ; if($ind2[$m]>0) $g10x10 = $sum3[$m]/$ind3[$m]; if($ind4[$m]>0) $g30x30 = $sum4[$m]/$ind4[$m]; if($ind4vl[$m]>0) $g30x30vl= $sum4vl[$m]/$ind4vl[$m]; if($ind4l[$m]>0) $g30x30l = $sum4l[$m]/$ind4l[$m]; $af19=$af20=$aml=$aNP=$aN60=$aS60=0; if($indf19[$m]>0) $af19= $sumf19[$m]/$indf19[$m]; if($indf20[$m]>0) $af20= $sumf20[$m]/$indf20[$m]; if($indml[$m]>0) $aml= $summl[$m]/$indml[$m]; if($indNP[$m]>0) $aNP = $sumNP[$m]/$indNP[$m]; if($indN60[$m]>0) $aN60= $sumN60[$m]/$indN60[$m]; if($indS60[$m]>0) $aS60= $sumS60[$m]/$indS60[$m]; if($indSP[$m]>0) $aSP= $sumSP[$m]/$indSP[$m]; $aline = sprintf("%.4f %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", $y, $ind[$m], $sum[$m]/$ind[$m], $misum[$m], $misums[$m], $masum[$m], $indf19[$m], $af19, $misumf19[$m], $masumf19[$m], $indf20[$m], $af20, $misumf20[$m], $masumf20[$m], $indml[$m], $aml, $misumml[$m], $masumml[$m], $indNP[$m], $aNP, $misumNP[$m], $masumNP[$m], $indN60[$m], $aN60, $misumN60[$m], $masumN60[$m], $indS60[$m], $aS60, $misumS60[$m], $masumS60[$m], $indSP[$m], $aSP, $misumSP[$m], $masumSP[$m], $ind3[$m], /*$g10x10,*/ $ind4vlt[$m], $ind4lt[$m], $g30x30vl, $g30x30l, $g30x30 ); fwrite($afile, $aline); if($ind2[$m]>0){ $aline = sprintf("g3x3 %.4f %d %d %f %.1f %.1f\n", $y, $ind2t[$m], $ind2[$m], $sum2[$m]/$ind2[$m], $misum2[$m], $masum2[$m]); fwrite($afile2, $aline); $aline = sprintf("g10x10 %.4f %d %d %f %.1f %.1f\n", $y, $ind3t[$m], $ind3[$m], $sum3[$m]/$ind3[$m], $misum3[$m], $masum3[$m]); fwrite($afile2, $aline); $aline = sprintf("g30x60 %.4f %d %d %f %.1f %.1f\n", $y, $ind4t[$m], $ind4[$m], $sum4[$m]/$ind4[$m], $misum4[$m], $masum4[$m]); fwrite($afile2, $aline); } $ag3 = 0; if($ind4[$m]>0) $ag3 = $sum4[$m]/$ind4[$m]; $alineg = sprintf("%.4f %d %d %d ", $y, $ind[$m], $sum[$m]/$ind[$m], $ag3); for ($lat=0; $lat <3; $lat++){ for($lon=0; $lon<3; $lon++){ if($gind3[$m][$lat][$lon]){ $alineg = sprintf("%s %d %d ", $alineg, $gind3[$m][$lat][$lon], $gsum3[$m][$lat][$lon]/$gind3[$m][$lat][$lon]); }else $alineg = sprintf("%s 0 0 ", $alineg); } // for lon } // for lat $alineg = sprintf("%s\n", $alineg); fwrite($afileg, $alineg); }// if $m++; }// for }// for fclose($afile); fclose($afile2); fclose($afileg); ?>