<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">&lt;<a href="mailto:guitingsong@gmail.com" target="_blank">guitingsong@gmail.com</a>&gt;</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 &quot;rho&quot; coords<br>; if you specify variable &quot;u&quot; or &quot;v&quot; it is transfering them<br>; first to the &quot;rho&quot; and than interpolate.<br>;<br>;*************************************************<br>load &quot;/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;  <br>load &quot;/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;  <br>load &quot;/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/ROMS_utils.ncl&quot;<br>load &quot;/home/arnold/software/ncl_ncarg/lib/ncarg/nclscripts/roms_depth_interp_ratio.ncl&quot;<br>begin<br>;************************************************<br>; User settings<br>;************************************************<br>   fhis  = &quot;/home/arnold/ROMS_AGRIF_MLCS/Roms_tools/Run/FORECAST/<a href="http://roms_his_forecast.nc" target="_blank">roms_his_forecast.nc</a>&quot; <br>;***********************************************<br>system(&quot;/bin/rm -f /home/arnold/ROMS_AGRIF_MLCS/Roms_tools/Run/FORECAST/<a href="http://roms_interpolation2.nc" target="_blank">roms_interpolation2.nc</a>&quot;)   ; remove any pre-existing file<br>ncdf = addfile(&quot;/home/arnold/ROMS_AGRIF_MLCS/Roms_tools/Run/FORECAST/<a href="http://roms_interpolation2.nc" target="_blank">roms_interpolation2.nc</a>&quot; ,&quot;c&quot;)  ; open output netCDF file<br> ;===================================================================<br>    ; create global attributes of the file (optional)<br>    ;===================================================================<br>       fAtt               = True            ; assign file attributes<br>       fAtt@title         = &quot;NCL Simple Approach to netCDF Creation&quot;<br>       fAtt@source_file   =  &quot;<a href="http://roms_his_forecast.nc" target="_blank">roms_his_forecast.nc</a>&quot;<br>       fAtt@Conventions   = &quot;None&quot;<br>       fAtt@creation_date = systemfunc (&quot;date&quot;)<br>       fileattdef( ncdf, fAtt )            ; copy file attributes       <br><br>;***********************************************<br>; Read data<br>;***********************************************<br>   his   =  addfile (fhis,&quot;r&quot;)<br>   lon2d = his-&gt;lon_rho<br>   lat2d = his-&gt;lat_rho<br>   times = his-&gt;time<br>   ZETA  = his-&gt;zeta<br>   h = his-&gt;h<br>   hc = his-&gt;hc   <br>   Cs_r = his-&gt;Cs_r<br>   Sc_r = his-&gt;s_rho<br>   s = his-&gt;salt<br>   if(isfilevar(his,&quot;Vtransform&quot;))<br>        vtransform = his-&gt;Vtransform<br>   else<br>        print(&quot;Do not have Vtransform in file needed for depth calculations, using 2 as default&quot;)<br>        vtransform = 2<br>        return<br>   end if<br>   lev   = his-&gt;s_rho<br>   lev_v = (/1.0, 0.75, 0.5, 0.25, 0.0/)<br>   T = his-&gt;temp<br>   salt = his-&gt;salt<br>   dim_T=dimsizes(T)<br>   U1 = his-&gt;u<br>   U=u2rho(U1)<br>   V1 = his-&gt;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 = &quot;dbar&quot;<br><br>pref = 0.0               ; user specified reference pressure (dbars)<br>pref@units = &quot;dbar&quot;   ; 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 = &quot;Degrees C&quot;<br>  IST_out@standard_name =  &quot;sea_water_potential_temperature&quot; <br>  IST_out@long_name = &quot;In Situ Temperature&quot;<br>  ;IST_out@_FillValue = 9.96921e+36<br>  <br>    do it = 0,ntim-1            ; TIME LOOP <br>;  print(&quot;Working on time: &quot; + 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,&quot;temp&quot;,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,&quot;temp&quot;,it,lev_v(il))/)<br>;   S_out(it,il,:,:) = (/roms_depth_interp_ratio(his,&quot;salt&quot;,it,lev_v(il))/)<br>;   U_out(it,il,:,:) = (/roms_depth_interp_ratio(his, &quot;u&quot;, it,lev_v(il))/) ; they are automatically put to &quot;rho&quot;<br>;   V_out(it,il,:,:) = (/roms_depth_interp_ratio(his, &quot;v&quot;, it,lev_v(il))/)           <br>            end do<br>          end do      <br>       end do<br>     end do <br>    U_out!0=&quot;time&quot;<br>    U_out!1=&quot;lev&quot;<br>    U_out!2=&quot;lat&quot;<br>    U_out!3=&quot;lon&quot;<br>    V_out!0=&quot;time&quot;<br>    V_out!1=&quot;lev&quot;<br>    V_out!2=&quot;lat&quot;<br>    V_out!3=&quot;lon&quot;<br>    T_out!0=&quot;time&quot;<br>    T_out!1=&quot;lev&quot;<br>    T_out!2=&quot;lat&quot;<br>    T_out!3=&quot;lon&quot;<br>    IST_out!0=&quot;time&quot;<br>    IST_out!1=&quot;lev&quot;<br>    IST_out!2=&quot;lat&quot;<br>    IST_out!3=&quot;lon&quot;<br>    <br>    <br>;    printVarSummary(T_out)<br>;    printVarSummary(U_out)<br>  ;=====================================================================<br><br>       ncdf-&gt;T = T_out                                     <br>       ncdf-&gt;U = U_out                        <br>         ncdf-&gt;V = V_out<br>         ncdf-&gt;Time = times<br>       ncdf-&gt;lat_rho = lat2d<br>       ncdf-&gt;lon_rho = lon2d<br>       ncdf-&gt;lev = lev_v<br>       ncdf-&gt;zeta = ZETA<br>       ncdf-&gt;istemp = IST_out <br>end<br><br><br></div></div></div>
</blockquote></div><br></div>