<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;"><font size="2">Thank you Adam and Kevin</font><div><font size="2"><br></font></div><div><font size="2">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 size="2">Sun</font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div><div><font size="2">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">kevin.havener@us.af.mil</a>> wrote:</font></div><font size="2"><br class="Apple-interchange-newline"></font><blockquote type="cite"><font size="2">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 out.nc") ; remove any pre-existing file<br> ncdf_out = addfile("out.nc" ,"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 828-271-4323; DSN 673-9044<br>NIPRNet <a href="mailto:kevin.havener@us.af.mil">kevin.havener@us.af.mil</a><br>SIPRNet <a href="mailto:kevin.f.havener.civ@mail.smil.mil">kevin.f.havener.civ@mail.smil.mil</a><br><br><br>-----Original Message-----<br>From: <a href="mailto:ncl-talk-bounces@ucar.edu">ncl-talk-bounces@ucar.edu</a> [<a href="mailto:ncl-talk-bounces@ucar.edu">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">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 out.nc") ; remove any pre-existing file<br> ncdf_out = addfile("out.nc" ,"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">ncl-talk-bounces@ucar.edu</a> [<a href="mailto:ncl-talk-bounces@ucar.edu">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">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 = "precipmonmean.nc"<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">asphilli@ucar.edu</a>> wrote:<br><br><br><span class="Apple-tab-span" style="white-space:pre">        </span>Hi Sunmin,<br><span class="Apple-tab-span" style="white-space:pre">        </span>lonFlip flips the attached longitude coordinate variable, and not the array itself. Try:<br><span class="Apple-tab-span" style="white-space:pre">        </span>printVarSummary(data)<br><span class="Apple-tab-span" style="white-space:pre">        </span>data = lonFlip(data) <br><span class="Apple-tab-span" style="white-space:pre">        </span>printVarSummary(data)<br><span class="Apple-tab-span" style="white-space:pre">        </span>If you have any further questions please respond to ncl-talk.<br><span class="Apple-tab-span" style="white-space:pre">        </span>Adam<br><br><span class="Apple-tab-span" style="white-space:pre">        </span>On Fri, Feb 20, 2015 at 8:04 AM, Sunmin Park <<a href="mailto:mireiyue@gmail.com">mireiyue@gmail.com</a>> wrote:<br><span class="Apple-tab-span" style="white-space:pre">        </span><br><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Dear NCL users<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </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 class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Thank you in advance,<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Sun-<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>begin<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>;==============================================================<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>; Open the file:<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>;================================================================<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> diri = "/Users/spark/vertical/00_DATA/"<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> fili = "precipmonmean.nc <<a href="http://precipmonmean.nc/">http://precipmonmean.nc/</a>> "<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> f = addfile (diri+fili+".nc", "r")<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> varname = "precip"<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> data = f->$varname$<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> LON1 = f->lon ;({-180:180}) ;<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> LAT = f->lat ;({-90:90}) ;<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> LON = lonFlip(LON1)<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> printVarSummary(data)<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> printVarSummary(LON)<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> print(LON)<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Variable: LON<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Type: float<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Total Size: 576 bytes<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> 144 values<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Number of Dimensions: 1<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Dimensions and sizes: [lon | 144]<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Coordinates:<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> lon: [-178.75..178.75]<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Number Of Attributes: 6<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> units : degrees_east<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> long_name : Longitude<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> actual_range : ( 1.25, 358.75 )<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> standard_name : longitude<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> axis : X<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span> lonFlip : longitude coordinate variable has been reordered via lonFlip<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(0) 181.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(1) 183.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(2) 186.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(3) 188.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(4) 191.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(5) 193.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(6) 196.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(7) 198.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(8) 201.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(9) 203.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(10) 206.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>.<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>.<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>.<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(135) 158.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(136) 161.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(137) 163.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(138) 166.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(139) 168.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(140) 171.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(141) 173.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(142) 176.25<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>(143) 178.75<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>_______________________________________________<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>ncl-talk mailing list<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>List instructions, subscriber options, unsubscribe:<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><br><br><br><br><br><span class="Apple-tab-span" style="white-space:pre">        </span>-- <br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span>Adam Phillips <br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span>Associate Scientist, Climate and Global Dynamics Division, NCAR<br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span>www.cgd.ucar.edu/staff/asphilli/ 303-497-1726 <br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span><http://www.cgd.ucar.edu/staff/asphilli> <br><br><br>_______________________________________________<br>ncl-talk mailing list<br>List instructions, subscriber options, unsubscribe:<br>http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br></font></blockquote></div><br></body></html>