#!/usr/bin/perl # use strict; # use warnings; # changed to calculate the monthly averages first. use Time::Local my @CC=(); my @mvap=(); my @nhit=(); @mdays=(31,28,31,30,31,30,31,31,30,31,30,31); # date set at half of december 1987 for the mid month normalization $time = timegm(1,1,12,15,0,1988)-978307200; $command = 'ncdump -v MnCldAmt MnCldAmt.nc'; $istart = 0; my @docs = qx($command); $icount=0 foreach my $line (@docs) { chomp $line; if ($istart eq 0) { if ($line =~ /water_vapor =/) { $istart =1; $lon=0; $lat=0; $imonth=0; } } else { $icount++; my @values = split(',', $line); foreach my $val (@values) { if ($val < 10.0) { $mvap[$lon][$lat][$imonth] = $val; # print $lon.' '.$lat.' '.$mvap[$lon][$lat][$imonth] ," \n"; } $lon++; } if ($lon > 144) { $lon=0; $lat++; } if ($lat > 72) { # make mnthly average # for ($i=0; $i<360; $i++) { for ($j=0; $j<180; $j++) { # print $mdays[$imonth].' '.$lon.' '.$lat.' '.$mvap[$lon][$lat][$imonth] ," \n"; if ($mvap[$i][$j][$imonth] > 0.0) { $wvap[$i][$j] = $mvap[$i][$j][$imonth]/$nhit[$i][$j]; $nhit[$i][$j] = 0; $mvap[$i][$j][$imonth]=0.0; # print $lon.' '.$lat.' '.$wvap[$lon][$lat]," \n"; } else { $wvap[$i][$j] = -9999; } } } # # - calculate global average # my $W_tot_NH = 0; my $A_tot_NH = 0; my $W_tot_SH = 0; my $A_tot_SH = 0; for ( my $j = 0 ; $j < 180 ; $j++ ) { #Grid-box area is proportional to cosine of latitude my $Lat = 90 - ( $j + 0.5 ); if ( $Lat > 90 || $Lat < -90 ) { next; } my $Weight = cos( $Lat * 3.141592 / 180 ); for ( my $i = 0 ; $i < 360 ; $i++ ) { if ( $wvap[$i][$j] < -9000 ) { next; } if ( $Lat > 0 ) { $W_tot_NH += $Weight; $A_tot_NH += $wvap[$i][$j] * $Weight; # print $Weight," \n"; } else { $W_tot_SH += $Weight; $A_tot_SH += $wvap[$i][$j] * $Weight; } } } if ( $W_tot_NH > 0 && $W_tot_SH > 0 ) { $glavg = ( $A_tot_NH / $W_tot_NH + $A_tot_SH / $W_tot_SH ) / 2; $navg = $A_tot_NH / $W_tot_NH; $savg = $A_tot_SH / $W_tot_SH; # print $iyear.' '.$iday.' '.$glavg.' '.$navg.' '.$savg," \n"; print $time.' '.$glavg.' '.$navg.' '.$savg," \n"; $time = $time+$mdays[$imonth]*86400; } $imonth = $imonth + 1; $dmonth= 0; } else { $dmonth++; } } }