<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Alan <div><br></div><div>Thank you for your help. It seems working now. </div><div><br></div><div>Sun</div><div><br></div><div><br><div><div>On Feb 20, 2015, at 12:04 PM, Alan Brammer <<a href="mailto:abrammer@albany.edu">abrammer@albany.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><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'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 = "/Users/spark/vertical/00_DATA/"</div><div> fili = "<a href="http://precipmonmean.nc/">precipmonmean.nc</a>"</div><div> f = addfile (diri+fili+".nc", "r")</div><div> varname = "precip"</div><div> data = f->$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&lon</div><div>;; LAT = data&lat ;({-90:90}) ;</div><div>;; LON = lonFlip(LON1)</div><div><br></div><div> printVarSummary(data)</div><div> data1 = lonFlip(data) ; data1&lon is now flipped but LON or data&lon are not, those variables are no longer associated to data1. </div><div> printVarSummary(data1) ; </div><div><br></div><div> print(data1&lon(::10)) ;; print every 10th lon to see how it's doing.</div><div> print(data1&lat(::10)) ;; print every 10th lat to see how it'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's every 2.13... degree. </div><div> lon = fspan(-180,180,72)</div><div> lat@units = "degrees_east"</div><div> lon@units = "degrees_north"</div><div> precipreg = linint2_Wrap(data1&lon,data1&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"><<a href="mailto:mireiyue@gmail.com" target="_blank">mireiyue@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 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 "<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 <<a href="mailto:kevin.havener@us.af.mil" target="_blank">kevin.havener@us.af.mil</a>> 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("./U78559.grb","r") <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,"lon")<br>;***********************************************<br>; create output netcdf file<br>;*********************************************** <br> system("rm <a href="http://out.nc/" target="_blank">out.nc</a>") ; remove any pre-existing file<br> ncdf_out = addfile("<a href="http://out.nc/" target="_blank">out.nc</a>" ,"c") ; 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->$names(i)$) .eq. "string") 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->$names(i)$ = lonFlip(grib_in->$names(i)$)<br> else <br> ncdf_out->$names(i)$ = grib_in->$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'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("./U78559.grb","r") <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,"lon")<br>;***********************************************<br>; create output netcdf file<br>;*********************************************** <br> system("rm <a href="http://out.nc/" target="_blank">out.nc</a>") ; remove any pre-existing file<br> ncdf_out = addfile("<a href="http://out.nc/" target="_blank">out.nc</a>" ,"c") ; 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->$names(i)$) .eq. "string") 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->$names(i)$ = lonFlip(grib_in->$names(i)$)<br> else <br> ncdf_out->$names(i)$ = grib_in->$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>"warning:linint2: xi, yi, xo, and yo must be monotonically increasing"<br>therefore I think it is due to LON values. <br>How I can remove the warning? <br><br><br> diri = "/Users/spark/vertical/00_DATA/"<br> fili = "<a href="http://precipmonmean.nc/" target="_blank">precipmonmean.nc</a>"<br> f = addfile (diri+fili+".nc", "r")<br> varname = "precip"<br> data = f->$varname$<br><br> LON = f->lon ({0:360}) ;<br> LAT = f->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 = "degrees_east"<br> lon@units = "degrees_north"<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 <<a href="mailto:asphilli@ucar.edu" target="_blank">asphilli@ucar.edu</a>> 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 <<a href="mailto:mireiyue@gmail.com" target="_blank">mireiyue@gmail.com</a>> 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'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 "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"<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 = "/Users/spark/vertical/00_DATA/"<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span> fili = "<a href="http://precipmonmean.nc/" target="_blank">precipmonmean.nc</a> <<a href="http://precipmonmean.nc/" target="_blank">http://precipmonmean.nc/</a>> "<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span> f = addfile (diri+fili+".nc", "r")<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span> varname = "precip"<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span> data = f->$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->lon ;({-180:180}) ;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span> LAT = f->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><<a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank">http://www.cgd.ucar.edu/staff/asphilli</a>> <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>
</blockquote></div><br></div></body></html>