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 ;***************************************************************** ; Variables to hold binned quantities ;***************************************************************** gbin = new ( (/nlat,mlon/), float ) GBIN = new ( (/nlat,mlon/), float ) gknt = new ( (/nlat,mlon/), integer) gbin = 0.0 ; initialization gknt = 0 GBIN=0 ;***************************************************************** ; Opening file/s ;***************************************************************** diri = "./" dir1 = "/media/IPSITA2_/TRMM_LH2/TRMM_NASA/" fili = systemfunc("cd "+diri+" ; ls 2A25.20000701*.HDF") fil1 = systemfunc("cd "+dir1+" ; ls 3G25.20000701*.nc") nfil1 = dimsizes( fili ) nfili = dimsizes( fil1 ) print(nfil1) print(nfili) ;***************************************************************** ; Loop over the files ;***************************************************************** tStrt = systemfunc("date") ; time the loop (wall clock) vNam = "rain" vNam1 = "convQ1RMean" ;do nf=0,nfil-1 q2=new((/19,720,148/),float) q3=new((/19,720,148/),float) q2=0.0 q3=0.0 do nf=0,1 print(nf+" "+fili(nf)) f = addfile(diri+fili(nf), "r") f1 = addfile(dir1+fil1(nf), "r") xs=0 x=0 lat2d=0 lon2d=0 LAT1D=0 LON1D=0 delete(x) delete(xs) delete(lat2d) delete(lon2d) delete(LAT1D) delete(LON1D) xs =( f->$vNam$) ; (nscan,nray,ncell1)=>(0,1,2) q1 =( f1->$vNam1$) q2=q1+q2 ; print("q1="+q1+" q2="+q2) ; print(q2) printVarSummary(q1) x = where(xs.ge.toshort(0), xs*0.01, -9999.0) print(dimsizes(x)) print(dimsizes(xs)) delete(xs) x@_FillValue = -9999.0 printMinMax(x,0) printMinMax(q1,0) lat2d = ( f->Latitude ) ; (nscan,nray) lon2d = ( f->Longitude) ; (nscan,nray) LAT1D = ndtooned( conform(x,lat2d, (/0,1/)) ) LON1D = ndtooned( conform(x,lon2d, (/0,1/)) ) ; print(LAT1D) ; print(LON1D) bin_sum(gbin,gknt,lon,lat,LON1D,LAT1D,ndtooned(x)) ; print( gknt@_FillValue) ; print( gbin@_FillValue) end do q3=q2/2 printMinMax(q3,0) printVarSummary(q3) wallClockElapseTime(tStrt, "Main File Loop", 0) ;***************************************************************** ; User must perform averaging ;***************************************************************** gknt = where(gknt.eq.0 , gknt@_FillValue, gknt) ; print(gknt) ;print(gbin) gbin = gbin/gknt gbin!0 = "lat" gbin!1 = "lon" gbin&lon = lon gbin&lat = lat 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 GBIN=gbin(lon|:,lat|106:253) printVarSummary(gbin) printVarSummary(GBIN) ;***************************************************************** ;*****************************************************************