load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" nlat = 360 mlon = 720 lat = latGlobeFo(nlat,"lat","latitude","degrees_north") ; lat=LAT(106:253) lon = lonGlobeFo(mlon,"lon","longitude","degrees_east") lon=(/lon -180./) lon&lon=lon ; print(lat) ; print(lon) ;***************************************************************** ; Variables to hold binned quantities ;***************************************************************** gbin = new ( (/nlat,mlon/), float ) gknt = new ( (/nlat,mlon/), integer) gbin = 0.0 ; initialization gknt = 0 ;***************************************************************** diri = "./" fili = systemfunc("cd "+diri+" ; ls 2A25.20000701*.nc") nfil = dimsizes( fili ) ;***************************************************************** ; Loop over the files ;***************************************************************** tStrt = systemfunc("date") ; time the loop (wall clock) vNam = "rain" do nf=0,nfil-1 print(nf+" "+fili(nf)) f = addfile(diri+fili(nf), "r") ; read data x = f->$vNam$ lat2d = ( f->Latitude ) lon2d = ( f->Longitude) ; LAT2d=ndtooned(lat2d) ; print(LAT2d) bin_sum(gbin,gknt,lon,lat \ ,ndtooned(lon2d),ndtooned (lat2d),ndtooned(x) ) delete(lat2d) ; may change for the next file delete(lon2d) delete( x ) end do wallClockElapseTime(tStrt, "Main File Loop", 0) ;***************************************************************** ; User nust perform averaging ;***************************************************************** gknt = where(gknt.eq.0 , gknt@_FillValue, gknt) gbin = gbin/gknt gbin!0 = "lat" gbin!1 = "lon" gbin&lat = lat gbin&lon = lon copy_VarCoords(gbin, gknt) ; copy coords if (isfilevaratt(f, vNam, "long_name")) then gbin@long_name = "BINNED: "+vNam gknt@long_name = "BINNED COUNT: "+vNam end if if (isfilevaratt(f, vNam, "units")) then gbin@units = f->$vNam$@units end if file_out="out.nc" ;output file ;print(gbin) fbinwrite(file_out,gbin)