load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
diro = "./"
filo = "vwnd.mon.mean.1958-2014.nc"
all_files = systemfunc ("ls /home/haha/data/vgrd/grib/*.grib")
fall = addfiles (all_files, "r")
ListSetType(fall,"join")
vwnd = fall[:]->VGRD_GDS0_ISBL_S123
lat = vwnd&g0_lat_1
lon = vwnd&g0_lon_2
lev = vwnd&lv_ISBL0
delete(vwnd&g0_lat_1)
delete(vwnd&g0_lon_2)
delete(vwnd&lv_ISBL0)
startTime = cd_inv_calendar(1958,01,1,00,00,00,"months since 1958-1-1",0)
endTime = cd_inv_calendar(2014,12,1,00,00,00,"months since 1958-1-1",0)
time = fspan(startTime, endTime, 672+12)
time!0 = "time"
time&time = time
time@units = "months since 1958-1-1"
ntim = dimsizes(time)
lat!0 = "lat"
lat&lat = (/lat/)
nlat = dimsizes(lat)
lon!0 = "lon"
lon&lon = (/lon/)
nlon = dimsizes(lon)
lev!0 = "lev"
lev&lev = (/lev/)
nlev = dimsizes(lev)
vwnd!0 = "time"
vwnd!1 = "lev"
vwnd!2 = "lat"
vwnd!3 = "lon"
vwnd&time = time
vwnd&lev = lev
vwnd&lat = lat
vwnd&lon = lon
printVarSummary(time)
printVarSummary(lat)
printVarSummary(lon)
printVarSummary(lev)
printVarSummary(vwnd)
;create netCDF file
system("/bin/rm -rf " + diro +filo)
fout = addfile(diro + filo, "c")
setfileoption(fout, "DefineMode", True)
fAtt = True
fAtt@creation_date = systemfunc("date")
fileattdef(fout, fAtt)
dimNames = (/"time", "lev", "lat", "lon"/)
dimSizes = (/-1, nlev, nlat, nlon/)
dimUnlim = (/True, False, False, False/)
filedimdef(fout, dimNames, dimSizes, dimUnlim)
filevardef(fout, "time", typeof(time), getvardims(time))
filevardef(fout, "lev", typeof(lev), getvardims(lev))
filevardef(fout, "lat", typeof(lat), getvardims(lat))
filevardef(fout, "lon", typeof(lon), getvardims(lon))
filevardef(fout, "vwnd", typeof(vwnd), getvardims(vwnd))
filevarattdef(fout, "time", time)
filevarattdef(fout, "lev", lev)
filevarattdef(fout, "lat", lat)
filevarattdef(fout, "lon", lon)
filevarattdef(fout, "vwnd", vwnd)
setfileoption(fout, "DefineMode", False)
fout->time = (/time/)
fout->lev = (/lev/)
fout->lat = (/lat/)
fout->lon = (/lon/)
fout->vwnd = (/vwnd/)
end