;***************************************************** 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" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl" ;***************************************************** begin ;create file output name diri = "/thumper/zmangin/mteor_507/data/" diri1 = "/chinook/zmangin/isugcm/isugcm_tri65_hourly/" diro = "/chinook/zmangin/isugcm/narr/" filo = "case1.narr.rectilinear.nc" system("/bin/rm -f " + diro + filo) ; remove if exists fout = addfile(diro+filo,"c") ;specify new number of lat/lon points ;nlat = 30 ;64 ;nlon = 130 ;128 ;Gaussian grid ;latG = latGau(nlat, "lat", "latitude", "degrees_north") ;lonG = fspan(0,359,nlon) ; create longitudes or read from file ;vars from input file f = addfile (diri+"case1.nc", "r") time = f->time y = f->y x = f->x lat2d = f->lat ; size = (nlat,nlon) lon2d = f->lon ; size = (nlat,nlon) lat = ndtooned(lat2d) lon = ndtooned(lon2d) precip = f->apcp ;vars from another file f1 = addfile(diri1+"1978-09.nc","r") lat_out = f1->lat lon_out = f1->lon ;printVarSummary(lat) ;printVarSummary(lon) ;print(lat) ;print(lon) ;rearrange lat from low to high ; lat2d = (/ lat2d(::-1,:) /) ; rearrange values only ; precip = (/ apcp(:,::-1,:) /) ;copy_VarCoords(lat2d,lat) ;copy_VarCoords(lon2d,lon) ;printVarSummary(lat2d) ;printVarSummary(lon2d) ;printVarSummary(time) ;print("lat min max = ") ;printMinMax(lat,True) ;print("lon min max = ") ;printMinMax(lon,True) lat42 = fspan(.89,85,30) lon42 = fspan(-179.997,179.993,130) ;apcp_grid = new((/1,277,349/),"float") ;apcp_grd = new((/8,30,130/),"float") ;plot precip on new grid ;apcp_grd = rcm2rgrid(lat2d,lon2d,precip,lat,lon,0) apcp_grd = linint2(lon,lat,precip,lat42,lon42,precip,0) ;apcp_grd = area_hi2lores(lon,lat,precip,True,1,lon42,lat42,False) ;opt_a = True ;opt_a@critpc = 70 ;apcp_out = area_hi2lores_Wrap (lon,lat, precip, True, 1, lon_out, lat_out, opt_a) print(apcp_grd) ;print(apcp_out) ;printVarSummary(apcp_grd) exit ;*************************************************************** ; explicitly declare file definition mode. Improve efficiency. ;*************************************************************** setfileoption(fout,"DefineMode",True) ;*************************************************************** ; create global attributes of the file ;*************************************************************** fAtt = True ; assign file attributes fAtt@title = "NCL Efficient Approach to netCDF Creation" fAtt@source_file = "/chinook/zmangin/isugcm/narr/apcp.1981.duplicate.nc" fAtt@Conventions = "None" fAtt@creation_date = systemfunc ("date") fileattdef( fout, fAtt ) ; copy file attributes ;*************************************************************** ; predefine the coordinate variables and their dimensionality ; Note: to get an UNLIMITED record dimension, we set the dimensionality ; to -1 (or the actual size) and set the dimension name to True. ;*************************************************************** dimNames = (/"time", "lat", "lon"/) dimSizes = (/ -1 , nlat, nlon/) dimUnlim = (/ True , False, False/) filedimdef(fout,dimNames,dimSizes,dimUnlim) ;************************************************* filevardef(fout, "time" ,typeof(time) ,getvardims(time)) filevardef(fout, "lat" ,typeof(lat) ,getvardims(lat)) filevardef(fout, "lon" ,typeof(lon) ,getvardims(lon)) filevardef(fout, "prect" ,typeof(apcp_grd),getvardims(apcp_grd)) ;************************************************* ; Copy attributes associated with each variable to the file ; All attributes associated with each variable will be copied. ;************************************************* filevarattdef(fout,"time" ,time) ; copy time attributes filevarattdef(fout,"lat" ,lat) ; copy lat attributes filevarattdef(fout,"lon" ,lon) ; copy lon attributes filevarattdef(fout,"prect",apcp_grd) ; copy apcp_grd attributes ;************************************************* ; explicitly exit file definition mode. **NOT REQUIRED** ;************************************************* setfileoption(fout,"DefineMode",False) ;************************************************* ; output only the data values since the dimensionality and such have ; been predefined. The "(/", "/)" syntax tells NCL to only output the ; data values to the predefined locations on the file. ;************************************************* fout->time = (/time/) fout->lat = (/lat/) fout->lon = (/lon/) fout->prect = (/prect/) ;************************************************* end