;************************************************ load "/home/ipsita/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "/home/ipsita/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "/home/ipsita/lib/ncarg/nclscripts/csm/contributed.ncl" ;============================================================== ; MAIN ;============================================================== begin vNam1="TOA" netCDF=True ;============================================================== nlat=1200 nlon=2400 lt = latGlobeFo(nlat,"lat","latitude","degrees_north") lt = lt(::-1) ; North to South lat=lt(400:799) lon = lonGlobeFo(nlon,"lon","longitude","degrees_east") lon&lon = lon ; update coordinates ;***************************************************************** ; Variables to hold binned quantities ;***************************************************************** GBIN = new ( (/400,nlon/), float ) GKNT = new ( (/400,nlon/), integer ) GBIN = 0.0 ; initialization GKNT = 0 ;***************************************************************** diri="./" filo = "2012_10_25_21" ; output file name fili=systemfunc("cd "+diri+"; ls MT1SCAS_1.06*2012_10_25_21*.h5") nfil=dimsizes(fili) print("nffil="+nfil) ;============================================================== ;=============================================================== f=addfile(fili, "r") vnlon = "/ScienceData/Longitude_TOA_Pixels" ulon = f->$vnlon$ flon=tofloat(ulon) lon2d = tofloat(ulon@Scale_Factor) * flon + tofloat(ulon@Add_Offset) vnlat = "/ScienceData/Colatitude_TOA_Pixels" ulat = f->$vnlat$ flat=tofloat(ulat) lt2d = tofloat(ulat@Scale_Factor) * flat + tofloat(ulat@Add_Offset) lat2d = 90.-lt2d vnrh1 = "/ScienceData/Flux_Longwave_TOA" urh1=f->$vnrh1$ rh1 = tofloat(urh1@Scale_Factor) * tofloat(urh1) + tofloat(urh1@Add_Offset) ;============================================================== copy_VarAtts(ulon, lon2d) copy_VarAtts(ulat, lat2d) copy_VarAtts(urh1, rh1) lon2d@units = "degree_east" lat2d@units = "degree_north" rh1@long_name = urh1@Long_Name rh1@units = urh1@Units rh1@_FillValue = tofloat(urh1@Scale_Factor) * tofloat(urh1@Fill_Value) + tofloat(urh1@Add_Offset) print("min(rh1) = " + min(rh1) + ", max(rh1) = " + max(rh1)) bin_sum(GBIN,GKNT,lon,lat,ndtooned(lon2d),ndtooned(lat2d),ndtooned(rh1)) ;================================================== ;================================================== ; Perform averaging ;***************************************************************** GKNT = where(GKNT.eq.0 , GKNT@_FillValue, GKNT) GBIN = GBIN/GKNT ;***************************************************************** print("min(GKNT) = " + min(GKNT) + ", max(GKNT) = " + max(GKNT)) print("min(GBIN) = " + min(GBIN) + ", max(GBIN) = " + max(GBIN)) GBIN!0 = "lat" GBIN!1 = "lon" GBIN&lat = lat GBIN&lon = lon copy_VarCoords(GBIN, GKNT) ; copy coords ;***************************************************************** if (isfilevaratt(f, vNam1, "long_name")) then GBIN@long_name = "BINNED: "+vNam1 GKNT@long_name = "BINNED COUNT: "+vNam1 end if if (isfilevaratt(f, vNam1, "units")) then GBIN@units = f->$vNam1$@units end if ;============================================================= ; netCDF ;***************************************************************** if (netCDF) then diro = "./" ; output directory fout = diro+filo+".nc" print(fout) system("/bin/rm -f "+fout) ; remove any pre-existing file ncdf = addfile(fout ,"c") ; open output netCDF file ;================================================================ ; create global attributes of the file (not required) ;================================================================ fAtt = True ; assign file attributes fAtt@title = "SAPHIR RelativeHumidity Swath Binned " fAtt@creation_date = systemfunc ("date") fileattdef( ncdf, fAtt ) ; copy file attributes ; recommended (generally) ncdf->TOA = GBIN end if end