<div dir="ltr"><div><div>BTW, I upload the necessary sample data into the <a href="http://ftp.cgd.ucar.edu">ftp.cgd.ucar.edu</a>. <br><br><br></div>Best regards,<br></div>Tony<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 27, 2015 at 9:27 AM, Guiting Song <span dir="ltr"><<a href="mailto:guitingsong@gmail.com" target="_blank">guitingsong@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Dear All,<br><br></div>I made a depth interpolation by applying linint1 function for ROMS results, howvever, I keep getting the warning as follows:<br><div><div><br>warning:linint1: xi and xo must be monotonically increasing<br><br></div><div>Does anybody meet the same problem? Appreciated if anyone can give me some suggestions.<br><br></div><div>my scripts are as follows, I also attached a revised roms_depth_interp_ratio.ncl function for your reference.<br><br></div><div>Tony<br><br>______________________________________________<br><br>;*************************************************<br>; roms_5.ncl<br>;<br>; Concepts illustrated:<br>; - Plotting ROMS data<br>; - Loading NCL functions from another script<br>; - Changing the reference annotation string for vectors<br>; - Overlaying vectors and filled contours on a map<br>;<br>; roms depth slice using roms_3d_interp with velocity overlay<br>; note: roms_3d_interp is working on "rho" coords<br>; if you specify variable "u" or "v" it is transfering them<br>; first to the "rho" and than interpolate.<br>;<br>;*************************************************<br>load "/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/csm/gsn_code.ncl" <br>load "/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/csm/gsn_csm.ncl" <br>load "/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/ROMS_utils.ncl"<br>load "/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/roms_depth_interp_ratio.ncl"<br>begin<br>;************************************************<br>; User settings<br>;************************************************<br> fhis = "/home/arnold/ROMS_AGRIF_MLCS/Roms_tools/Run/FORECAST/<a href="http://roms_his_forecast.nc" target="_blank">roms_his_forecast.nc</a>" <br>;***********************************************<br>system("/bin/rm -f /home/arnold/ROMS_AGRIF_MLCS/Roms_tools/Run/FORECAST/<a href="http://roms_interpolation2.nc" target="_blank">roms_interpolation2.nc</a>") ; remove any pre-existing file<br>ncdf = addfile("/home/arnold/ROMS_AGRIF_MLCS/Roms_tools/Run/FORECAST/<a href="http://roms_interpolation2.nc" target="_blank">roms_interpolation2.nc</a>" ,"c") ; open output netCDF file<br> ;===================================================================<br> ; create global attributes of the file (optional)<br> ;===================================================================<br> fAtt = True ; assign file attributes<br> fAtt@title = "NCL Simple Approach to netCDF Creation"<br> fAtt@source_file = "<a href="http://roms_his_forecast.nc" target="_blank">roms_his_forecast.nc</a>"<br> fAtt@Conventions = "None"<br> fAtt@creation_date = systemfunc ("date")<br> fileattdef( ncdf, fAtt ) ; copy file attributes <br><br>;***********************************************<br>; Read data<br>;***********************************************<br> his = addfile (fhis,"r")<br> lon2d = his->lon_rho<br> lat2d = his->lat_rho<br> times = his->time<br> ZETA = his->zeta<br> h = his->h<br> hc = his->hc <br> Cs_r = his->Cs_r<br> Sc_r = his->s_rho<br> s = his->salt<br> if(isfilevar(his,"Vtransform"))<br> vtransform = his->Vtransform<br> else<br> print("Do not have Vtransform in file needed for depth calculations, using 2 as default")<br> vtransform = 2<br> return<br> end if<br> lev = his->s_rho<br> lev_v = (/1.0, 0.75, 0.5, 0.25, 0.0/)<br> T = his->temp<br> salt = his->salt<br> dim_T=dimsizes(T)<br> U1 = his->u<br> U=u2rho(U1)<br> V1 = his->v<br> V = v2rho(V1)<br> ntim = dimsizes(times) ; get dimension sizes <br> nlev = dimsizes(lev_v) <br> nlat1 = dimsizes(lat2d) <br> nlat = nlat1(0)<br> nlon1 = dimsizes(lon2d)<br> nlon = nlon1(1) <br> dimSizes = (/ ntim, nlev, nlat, nlon /) <br> dimSizes2 = (/ ntim, nlat, nlon /)<br> U_out = new(dimSizes,typeof(U))<br> V_out = new(dimSizes,typeof(V))<br> T_out = new(dimSizes,typeof(T))<br> IST_out = new(dimSizes,typeof(T))<br> S_out = new(dimSizes,typeof(T))<br> P_out = new(dimSizes,typeof(T))<br> <br>;---------- depth calculation ---------------------------------- <br> depth = new(dim_T,typeof(U))<br> hinv=1./h<br> N=dimSizes(1)<br> M=dimSizes(0)<br>if (vtransform.eq.2)<br> do it=0,M-1<br> do k=0,N-1<br> cff = 1./(hc + h);<br> cffr = hc*Sc_r(k) + h*Cs_r(k);<br> depth(it,k,:,:)=ZETA(it,:,:) + ( ZETA(it,:,:) + h )*cffr*cff<br> end do<br> end do<br> end if<br><br> if (vtransform.eq.1)<br> do it=0,M-1<br> do k=0,N-1<br> cffr = hc*(Sc_r(k) - Cs_r(k))<br> depth(it,k,:,:)=cffr+Cs_r(k)*h + ZETA(it,:,:)*(1+(cffr+Cs_r(k)*h)*hinv)<br> end do<br> end do<br> end if <br><br>;-------------- Depth calculation ------------------------------ <br><br><br>;-----------in situ temp calculation ---------------------------<br>;pre = depth_to_pres(depth,False)*10<br>pre=abs(depth)*0.01*10<br>pre@units = "dbar"<br><br>pref = 0.0 ; user specified reference pressure (dbars)<br>pref@units = "dbar" ; must be decibar units<br><br>;istemp = new(dim_T,typeof(T))<br>;istemp = potmp_insitu_ocn(T,s,pre, pref, 1 ,True) ; pot(ntim,klev,nlat,nlon)<br><br>;------------- in situ temp calculation ---------------------------<br> <br> T_out(:,nlev-1,:,:) = T(:,dim_T(1)-1,:,:) <br> U_out(:,nlev-1,:,:) = U(:,dim_T(1)-1,:,:)<br> V_out(:,nlev-1,:,:) = V(:,dim_T(1)-1,:,:)<br> S_out(:,nlev-1,:,:) = salt(:,dim_T(1)-1,:,:)<br> IST_out(:,nlev-1,:,:) = T(:,dim_T(1)-1,:,:)<br> IST_out@units = "Degrees C"<br> IST_out@standard_name = "sea_water_potential_temperature" <br> IST_out@long_name = "In Situ Temperature"<br> ;IST_out@_FillValue = 9.96921e+36<br> <br> do it = 0,ntim-1 ; TIME LOOP <br>; print("Working on time: " + times(it) ) <br> do il = 0,nlev-2<br> do i=0,dimSizes(2)-1<br> do j=0,dimSizes(3)-1<br> <br>; out = roms_depth_interp_ratio(his,"temp",it,lev_v(il))<br>; printVarSummary(out)<br> x=depth(it,:,i,j)<br> min_x = min(x)*lev_v(il)<br> <br> T_out(it,il,i,j) = linint1(x,T(it,:,i,j),False,min_x,0);<br> S_out(it,il,i,j) = linint1(x,salt(it,:,i,j),False,min_x,0);<br> U_out(it,il,i,j) = linint1(x,U(it,:,i,j),False,min_x,0);<br> V_out(it,il,i,j) = linint1(x,V(it,:,i,j),False,min_x,0);<br> P_out(it,il,i,j) = linint1(x,pre(it,:,i,j),False,min_x,0);<br> IST_out(it,il,i,j)= potmp_insitu_ocn(T_out(it,il,i,j),S_out(it,il,i,j),P_out(it,il,i,j), pref, 0 ,True)<br>; T_out(it,il,:,:) = (/roms_depth_interp_ratio(his,"temp",it,lev_v(il))/)<br>; S_out(it,il,:,:) = (/roms_depth_interp_ratio(his,"salt",it,lev_v(il))/)<br>; U_out(it,il,:,:) = (/roms_depth_interp_ratio(his, "u", it,lev_v(il))/) ; they are automatically put to "rho"<br>; V_out(it,il,:,:) = (/roms_depth_interp_ratio(his, "v", it,lev_v(il))/) <br> end do<br> end do <br> end do<br> end do <br> U_out!0="time"<br> U_out!1="lev"<br> U_out!2="lat"<br> U_out!3="lon"<br> V_out!0="time"<br> V_out!1="lev"<br> V_out!2="lat"<br> V_out!3="lon"<br> T_out!0="time"<br> T_out!1="lev"<br> T_out!2="lat"<br> T_out!3="lon"<br> IST_out!0="time"<br> IST_out!1="lev"<br> IST_out!2="lat"<br> IST_out!3="lon"<br> <br> <br>; printVarSummary(T_out)<br>; printVarSummary(U_out)<br> ;=====================================================================<br><br> ncdf->T = T_out <br> ncdf->U = U_out <br> ncdf->V = V_out<br> ncdf->Time = times<br> ncdf->lat_rho = lat2d<br> ncdf->lon_rho = lon2d<br> ncdf->lev = lev_v<br> ncdf->zeta = ZETA<br> ncdf->istemp = IST_out <br>end<br><br><br></div></div></div>
</blockquote></div><br></div>