<div dir="ltr">This is how I would edit your script.    I would remove all trace of LON and LAT they serve no purpose but to confuse things.  Paste your whole script here, so people can actually check what you&#39;re doing.   And probably past the output of the below as well. <div><br></div><div><br></div><div>Adam had a typo in his code so if you just copy pasted that without checking it there will have been an error. </div><div><br></div><div><br></div><div>              ~Alan.</div><div><br></div><div><br><div><div>  diri    = &quot;/Users/spark/vertical/00_DATA/&quot;</div><div>  fili    = &quot;<a href="http://precipmonmean.nc">precipmonmean.nc</a>&quot;</div><div>  f       = addfile (diri+fili+&quot;.nc&quot;, &quot;r&quot;)</div><div>  varname = &quot;precip&quot;</div><div>  data = f-&gt;$varname$</div><div><br></div><div><br></div><div>;;;;   There is no need for these lines, it just complicates the script. </div><div>;;; Keep metadata attached to the variables to keep things simple. </div><div>;;  LON     = data&amp;lon</div><div>;;  LAT     = data&amp;lat      ;({-90:90})  ;</div><div>;;  LON     = lonFlip(LON1)</div><div><br></div><div>  printVarSummary(data)</div><div>  data1 = lonFlip(data)   ;  data1&amp;lon is now flipped but LON or data&amp;lon are not, those variables are no longer associated to data1. </div><div>  printVarSummary(data1)   ;  </div><div><br></div><div> print(data1&amp;lon(::10))  ;; print every 10th lon to see how it&#39;s doing.</div><div> print(data1&amp;lat(::10))  ;; print every 10th lat to see how it&#39;s doing.</div><div><br></div><div>  lat = fspan(-85,85,85)               ;; do you want this to be 86, every 2 degree?  At the moment it&#39;s every 2.13... degree. </div><div>  lon = fspan(-180,180,72)</div><div>  lat@units = &quot;degrees_east&quot;</div><div>  lon@units = &quot;degrees_north&quot;</div><div>  precipreg = linint2_Wrap(data1&amp;lon,data1&amp;lat,data1,True,lon,lat,0)</div><div> printVarSummary(precipreg)</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 20, 2015 at 2:30 PM, Sunmin Park <span dir="ltr">&lt;<a href="mailto:mireiyue@gmail.com" target="_blank">mireiyue@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 style="word-wrap:break-word"><font>Thank you Adam and Kevin</font><div><font><br></font></div><div><font>I tired what Adam suggested and it still shows the warning. I am trying to use the scripts that Kevin sent me. But I am confused with the line says &quot;<b>if the rightmost dimension is longitude then flip the data</b>”. The rightmost is longitude then should I do array reverse like precip_in(<span style="background-color:rgb(255,255,255);line-height:16px">(:,:,::-1)?</span></font></div><div><br></div><div><font>Sun</font></div><div><div class="h5"><div><font><br></font></div><div><font><br></font></div><div><font><br></font></div><div><font><br></font></div><div><div><font>On Feb 20, 2015, at 7:55 AM, HAVENER, KEVIN F GS-12 USAF AFWA 14 WS/WXED &lt;<a href="mailto:kevin.havener@us.af.mil" target="_blank">kevin.havener@us.af.mil</a>&gt; wrote:</font></div><font><br></font><blockquote type="cite"><font>Incomplete copy paste from my last email.  Here it is with the last few lines intact.  Sorry for the misdirection.<br><br>begin<br>;***********************************************<br>; get variable names from grib file<br>;***********************************************<br>   grib_in  = addfile(&quot;./U78559.grb&quot;,&quot;r&quot;)   <br>   names    = getfilevarnames(grib_in); extract all variable names <br>;<br>;  get the longitudinal dimension name(s)<br>;<br>   dimnames = getvardims(grib_in)<br>   print(dimnames)<br>   londims = str_match_ic(dimnames,&quot;lon&quot;)<br>;***********************************************<br>; create output netcdf file<br>;*********************************************** <br>   system(&quot;rm <a href="http://out.nc" target="_blank">out.nc</a>&quot;) ; remove any pre-existing file<br>   ncdf_out = addfile(&quot;<a href="http://out.nc" target="_blank">out.nc</a>&quot; ,&quot;c&quot;)       ; create output netCDF file<br>;***********************************************<br>; loop through variables and output each to netcdf<br>;***********************************************<br>   do i = 0, dimsizes(names)-1  <br>     print (names(i))<br>     ;<br>     ; strings need to be converted to character if you want them in the output file<br>     ; <br>     if (typeof(grib_in-&gt;$names(i)$) .eq. &quot;string&quot;) then<br>       continue<br>     end if<br>     ;<br>     ; if the rightmost dimension is longitude then flip the data<br>     ; otherwise just copy the variable unaltered<br>     ;<br>     dims := getfilevardims(grib_in,names(i))<br>     rdim = dims(dimsizes(dims)-1)<br>     if (any(londims .eq. rdim)) then<br>        ncdf_out-&gt;$names(i)$ = lonFlip(grib_in-&gt;$names(i)$)<br>     else   <br>        ncdf_out-&gt;$names(i)$ = grib_in-&gt;$names(i)$<br>     end if<br>   end do   <br>end<br><br>Kevin Havener, DAFC, 14WS/WXED<br>Comm <a href="tel:828-271-4323" value="+18282714323" target="_blank">828-271-4323</a>; DSN 673-9044<br>NIPRNet <a href="mailto:kevin.havener@us.af.mil" target="_blank">kevin.havener@us.af.mil</a><br>SIPRNet <a href="mailto:kevin.f.havener.civ@mail.smil.mil" target="_blank">kevin.f.havener.civ@mail.smil.mil</a><br><br><br>-----Original Message-----<br>From: <a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a> [<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">mailto:ncl-talk-bounces@ucar.edu</a>] On Behalf Of HAVENER, KEVIN F GS-12 USAF AFWA 14 WS/WXED<br>Sent: Friday, February 20, 2015 10:51 AM<br>To: Sunmin Park<br>Cc: <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>Subject: Re: [ncl-talk] lonFlip function<br><br>Here is a script that I got from the ncl website somewhere, or maybe from the mailing list, because re-ordering 0-360 arrays is something I have to do frequently. It re-orders the array and re-calculates the longitudes.  I deal with grib1/2 files, so it reads a grib and writes out a netcdf, but it doesn&#39;t really matter what the input file type is as long as ncl likes it.<br><br>begin<br>;***********************************************<br>; get variable names from grib file<br>;***********************************************<br>   grib_in  = addfile(&quot;./U78559.grb&quot;,&quot;r&quot;)   <br>   names    = getfilevarnames(grib_in); extract all variable names <br>;<br>;  get the longitudinal dimension name(s) ;<br>   dimnames = getvardims(grib_in)<br>   print(dimnames)<br>   londims = str_match_ic(dimnames,&quot;lon&quot;)<br>;***********************************************<br>; create output netcdf file<br>;*********************************************** <br>   system(&quot;rm <a href="http://out.nc" target="_blank">out.nc</a>&quot;) ; remove any pre-existing file<br>   ncdf_out = addfile(&quot;<a href="http://out.nc" target="_blank">out.nc</a>&quot; ,&quot;c&quot;)       ; create output netCDF file<br>;***********************************************<br>; loop through variables and output each to netcdf<br>;***********************************************<br>   do i = 0, dimsizes(names)-1  <br>     print (names(i))<br>     ;<br>     ; strings need to be converted to character if you want them in the output file<br>     ; <br>     if (typeof(grib_in-&gt;$names(i)$) .eq. &quot;string&quot;) then<br>       continue<br>     end if<br>     ;<br>     ; if the rightmost dimension is longitude then flip the data<br>     ; otherwise just copy the variable unaltered<br>     ;<br>     dims := getfilevardims(grib_in,names(i))<br>     rdim = dims(dimsizes(dims)-1)<br>     if (any(londims .eq. rdim)) then<br>        ncdf_out-&gt;$names(i)$ = lonFlip(grib_in-&gt;$names(i)$)<br>     else   <br>        ncdf_out-&gt;$names(i)$ = grib_in-&gt;$names(i)$<br><br>Kevin Havener<br><br>-----Original Message-----<br>From: <a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a> [<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">mailto:ncl-talk-bounces@ucar.edu</a>] On Behalf Of Sunmin Park<br>Sent: Friday, February 20, 2015 10:32 AM<br>To: Adam Phillips<br>Cc: <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>Subject: Re: [ncl-talk] lonFlip function<br><br>Thank you Adam<br><br>I am trying to do regredding the data using the function linint2_Wrap. <br>I got warning<br>&quot;warning:linint2: xi, yi, xo, and yo must be monotonically increasing&quot;<br>therefore I think it is due to LON values. <br>How I can remove the warning? <br><br><br>  diri    = &quot;/Users/spark/vertical/00_DATA/&quot;<br>  fili    = &quot;<a href="http://precipmonmean.nc" target="_blank">precipmonmean.nc</a>&quot;<br>  f       = addfile (diri+fili+&quot;.nc&quot;, &quot;r&quot;)<br>  varname = &quot;precip&quot;<br>  data = f-&gt;$varname$<br><br>  LON     = f-&gt;lon ({0:360})  ;<br>  LAT     = f-&gt;lat ;({-90:90})  ;<br>;  LON     = lonFlip(LON1)<br><br>  printVarSummary(data)<br>  data1 = lonFlip(data)<br>  printVarSummary(data1)<br><br>  lat = fspan(-85,85,85)<br>  lon = fspan(-180,180,72)<br>  lat@units = &quot;degrees_east&quot;<br>  lon@units = &quot;degrees_north&quot;<br>  precipreg = linint2_Wrap(LON,LAT,data1,True,lon,lat,0)<br>printVarSummary(precipreg)<br><br>On Feb 20, 2015, at 7:17 AM, Adam Phillips &lt;<a href="mailto:asphilli@ucar.edu" target="_blank">asphilli@ucar.edu</a>&gt; wrote:<br><br><br><span style="white-space:pre-wrap">        </span>Hi Sunmin,<br><span style="white-space:pre-wrap">        </span>lonFlip flips the attached longitude coordinate variable, and not the array itself. Try:<br><span style="white-space:pre-wrap">        </span>printVarSummary(data)<br><span style="white-space:pre-wrap">        </span>data = lonFlip(data) <br><span style="white-space:pre-wrap">        </span>printVarSummary(data)<br><span style="white-space:pre-wrap">        </span>If you have any further questions please respond to ncl-talk.<br><span style="white-space:pre-wrap">        </span>Adam<br><br><span style="white-space:pre-wrap">        </span>On Fri, Feb 20, 2015 at 8:04 AM, Sunmin Park &lt;<a href="mailto:mireiyue@gmail.com" target="_blank">mireiyue@gmail.com</a>&gt; wrote:<br><span style="white-space:pre-wrap">        </span><br><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Dear NCL users<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>I am trying to change longitude 0,360 to -180,180. I used the function lonFlip to change longitude but it has wrong values. When I use printVarSummary the coordinate looks fine but when I print it out (print) it doesn&#39;t change LON (the file that I am using is GPCP monthly mean precipitation from NCAR) How can I get correct LON (-180,180)?<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Thank you in advance,<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Sun-<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl&quot;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>begin<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>;==============================================================<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>; Open the file:<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>;================================================================<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  diri    = &quot;/Users/spark/vertical/00_DATA/&quot;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  fili    = &quot;<a href="http://precipmonmean.nc" target="_blank">precipmonmean.nc</a> &lt;<a href="http://precipmonmean.nc/" target="_blank">http://precipmonmean.nc/</a>&gt; &quot;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  f       = addfile (diri+fili+&quot;.nc&quot;, &quot;r&quot;)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  varname = &quot;precip&quot;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  data = f-&gt;$varname$<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  LON1     = f-&gt;lon ;({-180:180})  ;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  LAT     = f-&gt;lat ;({-90:90})  ;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  LON     = lonFlip(LON1)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  printVarSummary(data)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  printVarSummary(LON)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  print(LON)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>return<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Variable: LON<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Type: float<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Total Size: 576 bytes<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>            144 values<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Number of Dimensions: 1<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Dimensions and sizes:   [lon | 144]<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Coordinates:<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>            lon: [-178.75..178.75]<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>Number Of Attributes: 6<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  units :       degrees_east<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  long_name :   Longitude<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  actual_range :        ( 1.25, 358.75 )<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  standard_name :       longitude<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  axis :        X<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>  lonFlip :     longitude coordinate variable has been reordered via lonFlip<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(0)     181.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(1)     183.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(2)     186.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(3)     188.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(4)     191.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(5)     193.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(6)     196.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(7)     198.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(8)     201.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(9)     203.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(10)    206.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>.<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>.<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>.<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(135)   158.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(136)   161.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(137)   163.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(138)   166.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(139)   168.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(140)   171.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(141)   173.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(142)   176.25<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>(143)   178.75<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>_______________________________________________<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>ncl-talk mailing list<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>List instructions, subscriber options, unsubscribe:<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><br><br><br><br><br><span style="white-space:pre-wrap">        </span>-- <br><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span>Adam Phillips <br><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span>Associate Scientist,  Climate and Global Dynamics Division, NCAR<br><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a>   <a href="tel:303-497-1726" value="+13034971726" target="_blank">303-497-1726</a> <br><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span><br><span style="white-space:pre-wrap">        </span>&lt;<a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank">http://www.cgd.ucar.edu/staff/asphilli</a>&gt; <br><br><br>_______________________________________________<br>ncl-talk mailing list<br>List instructions, subscriber options, unsubscribe:<br><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br></font></blockquote></div><br></div></div></div><br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>