load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" diro = "./" ; Output directory for netCDF diri = "./" ; input directory fils = systemfunc ("cd "+diri+" ; ls *.nc4") ; file paths print(fils) nfils = dimsizes(fils) ; target grid nlat = 181 mlon = 360 LAT = latGlobeF(nlat, "LAT", "latitude", "degrees_north") LON = lonGlobeF(mlon, "LON", "longitude", "degrees_east") method= "bilinear" ;;;setfileoption("nc","Format","NetCDF4") ; if nc4 output is desired fAtt = True ; assign file attributes fAtt@Conventions = "CF-1.0" do nf = 0, nfils-1 print("=============> nf="+nf+" "+fils(nf)+" <================") wcStrt = systemfunc("date") g1 = addfile(diri+fils(nf),"r") varName = getfilevarnames(g1) nvar = dimsizes(varName) if (nf.eq.0) then print(varName) varName = str_sub_str(varName, "/", "") ; strip the / from the name print(varName) end if time = g1->time time2 = ut_calendar(time, -3) time2!0 = "time" time2&time = time time2@long_name = "current date as YYYYMMDD" TAITIME = g1->TAITIME ; write netCDF the 'simple' way filo = "rGEOS5_"+(time2+2)+".nc" system("/bin/rm -f " + diro + filo) ; remove if exists fout = addfile (diro + filo, "c") ; open output file fAtt@creation_date = systemfunc ("date") fAtt@source_file = fils(nf) fAtt@title = "Regrid: GEOS5 grid to NGAC grid via "+method+" interpolation" fileattdef( fout, fAtt ) ; copy file attributes fout->time = time fout->time2 = time2 fout->TAITIME = TAITIME fout->LAT = LAT fout->LON = LON do nv=0,nvar-1 rank = dimsizes( getfilevardimsizes(g1,varName(nv)) ) if (rank.eq.3) then var = lonFlip( g1->$varName(nv)$ ) ; original variable fliped to 0->360 VAR = linint2_Wrap(var&lon,var&lat,var,True,LON,LAT,0) ; Map GEOS5 grid to NGAC grid if (nf.eq.0 .and. nv.eq.0) then printVarSummary(VAR) end if fout->$varName(nv)$ = VAR end if end do ; nv (variable loop) wallClockElapseTime(wcStrt, ("nf="+nf), 0) end do ; nf (file loop)