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 ; get file and variable name from shell environment ; ================================================= ifile = getenv("opath")+getenv("pfile") ofile = getenv("opath")+getenv("qfile") ivar = getenv("ivar") ; read variables from file ; ======================== f1 = addfile (ifile, "r") var = f1->$ivar$ time = f1->time lat2d = f1->lat lon2d = f1->lon ; print("lat2d: min="+min(lat2d)+" max="+max(lat2d)) ; printVarSummary(var) ; print(" min="+min(var)+" max="+max(var)) dimvar = dimsizes( var ) nt = dimvar(0) nlat = dimvar(1) mlon = dimvar(2) ;******************************************** ; Before interpolating make all lon >= 0.0 ; The reason is to get around the dateline longitude sign switch ; going from positive [eg 150E] to negative [eg -170] ;******************************************** lon2d = where(lon2d.ge.0, lon2d, lon2d+360.) ; LON1D = ndtooned(lon2d) ; convert to one dimensional array ; ii = ind(LON1D.lt.0.) ; returns indices where condition is true ; LON1D(ii) = LON1D(ii) + 360. ; lon2d = onedtond( LON1D, dimsizes(lon2d) ) ; converts to multidimesional array ; print(" min="+min(lat2d)+" max="+max(lat2d)) ; min=0.89728 max=85.3335 ; print(" min="+min(lon2d)+" max="+max(lon2d)) ; min=148.64 max=357.433 ;******************************************** ; interpolate: specify region, set up new lat/lon grid that original data will be regridded to ;******************************************** NLAT = 360 ;180 MLON = 720 dlat = 0.5 lat = (ispan ( 0,NLAT-1,1 )*dlat)-90 ; -90 to 89 lat!0 = "lat" lat@units = "degrees_north" lat&lat = lat dlon = 0.5 lon = ispan ( 0,MLON-1,1 )*dlon ; 0 to 359 lon!0 = "lon" lon@units = "degrees_east" lon&lon = lon varNEW = new ((/nt,NLAT,MLON/), typeof(var), getFillValue(var)) varNEW!0 = "time" varNEW&time = time varNEW!1 = "lat" varNEW&lat = lat varNEW!2 = "lon" varNEW&lon = lon varNEW@units = var@units varNEW@long_name = var@long_name ; printVarSummary(var) ; printVarSummary(varNEW) do t = 0, nt-1 varNEW(t,:,:) = triple2grid(ndtooned(lon2d), ndtooned(lat2d), ndtooned( var(t,:,:) ) ,lon, lat, False) end do ;printVarSummary(lat) ;printVarSummary(varNEW) ; write modified data into netcdf file ; ncdf = addfile(ofile,"w") ; overwrite (w-option), create new (c-option) ncdf = addfile(ofile,"c") ; overwrite (w-option), create new (c-option) ncdf->time = time ncdf->lon = lon ncdf->lat = lat ncdf->$ivar$ = varNEW end