<div dir="ltr"><div>Huansheng Chen,<br></div><div><br></div><div>The number 0.1 does not have an exact representation in regular floating point computer arithmetic. The closest possible floating point numbers are approximately 0.10000000149 (single precision), or 0.10000000000000000555 (double precision).</div><div><br></div><div>Therefore, it is impossible to create numeric arrays with exactly 0.1 degree intervals.</div><div><br></div><div>The cases for 1.0, 0.5 and 0.25 degree intervals are different, because each of these numbers has an exact representation in floating point arithmetic.<br><br>Please read this section on Wikipedia. The discussion uses 0.1 as an example, the same interval that you want:</div><div><br></div><a href="https://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding" target="_blank">https://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding</a><div><br></div><div>Also note that your original end points (89.95d, 179.95d) do not have exact floating point representations.<br><div><br></div><div>The best you can do is to make a set of approximate numbers that matches what you need in some way. Can you restate your problem in terms of how you want to fit your interval and end points to a theoretical set of numbers?</div><div><br></div><div>--Dave</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 18, 2015 at 3:50 AM, <a href="mailto:chenhuansheng@mail.iap.ac.cn" target="_blank">chenhuansheng@mail.iap.ac.cn</a> <span dir="ltr"><<a href="mailto:chenhuansheng@mail.iap.ac.cn" target="_blank">chenhuansheng@mail.iap.ac.cn</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><u></u>
<div style="margin:10px">
<div>Hi Mary,</div>
<div> </div>
<div>I tried "<a href="mailto:Opt@URCorner%C2%A0%C2%A0=+(/+%C2%A089.97d,+%C2%A0179.97d/)" target="_blank">Opt@URCorner =
(/ 89.97d, 179.97d/)</a>", this resulted in "grid_dims = 3600,
1800".</div>
<div>However, the lat-lon intervals are not exactly 0.1 degree. </div>
<div style="color:rgb(255,0,0)">For example: "grid_center_lon = -179.95,
-179.849994442901, -179.749988885802, "</div>
<div style="color:rgb(255,0,0)">It should be "grid_center_lon = -179.95, -179.85,
-179.75, "</div>
<div> </div>
<div>I also tried "<a href="mailto:Opt@URCorner%C2%A0%C2%A0=+(/+%C2%A089.95001d,+%C2%A0179.95001d/)" target="_blank">Opt@URCorner =
(/ 89.95001d, 179.95001d/)</a>", the problem was similar.</div>
<div>"grid_center_lon = -179.95, -179.849999997221, -179.749999994443, "</div>
<div> </div>
<div>The results I want are the 0.1x0.1 grids with exactly equal latitude and
longtitude intervals (0.1 degree). How can I get it ?</div>
<div>For the 0.25x0.25 grids, the output results are right.<br></div>
<div>Best Wishes,</div>
<div>Huansheng</div>
<div> </div>
<hr style="min-height:1px;width:210px" align="left" color="#b5c4df" size="1">
<div><span>
<div style="font-size:10pt;font-family:verdana;margin:10px">
<div>
<div style="font-size:10pt;font-family:verdana;margin:10px">
<div>陈焕盛(LAPC/IAP)</div>
<div>大气边界层物理和大气化学国家重点实验室</div>
<div>中国科学院大气物理研究所</div></div></div></div></span></div>
<div> </div>
<div style="border-top-color:rgb(181,196,223);border-width:1pt medium medium;border-style:solid none none;padding:3pt 0cm 0cm">
<div style="font-size:12px;font-family:tahoma;background-color:rgb(239,239,239);color:rgb(0,0,0);padding:8px">
<div><b>From:</b> <a href="mailto:haley@ucar.edu" target="_blank">Mary Haley</a></div>
<div><b>Date:</b> 2015-10-17 00:47</div>
<div><b>To:</b> <a href="mailto:chenhuansheng@mail.iap.ac.cn" target="_blank">chenhuansheng@mail.iap.ac.cn</a></div>
<div><b>CC:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk</a></div>
<div><b>Subject:</b> Re: [ncl-talk] question to the NCL latlon_to_SCRIP
function</div></div></div>
<div>
<div style="background-color:white">
<div dir="ltr">
<div style="font-size:small">It looks like a simple
rounding error. </div>
<div style="font-size:small"><br></div>
<div style="font-size:small">By providing strict corner
lat/lon boundary values and a small resolution, you end up with values like
89.950001 and 179.950001. These are out of range of the URCorner boundary values
that you provided, so you then end up with the last two values removed.
</div>
<div style="font-size:small"><br></div>
<div style="font-size:small">You can try using slightly a
higher values for URCorner:</div>
<div style="font-size:small"><br></div>
<div style="font-size:small">
<div>Opt@URCorner = (/ 89.97d,
179.97d/)<br></div>
<div><br></div>
<div>I've created a ticket (NCL-2293) on this to see if this
is something we can improve.</div>
<div><br></div>
<div>--Mary</div>
<div><br></div></div></div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Oct 16, 2015 at 1:13 AM, <a href="mailto:chenhuansheng@mail.iap.ac.cn" target="_blank">chenhuansheng@mail.iap.ac.cn</a>
<span dir="ltr"><<a href="mailto:chenhuansheng@mail.iap.ac.cn" target="_blank">chenhuansheng@mail.iap.ac.cn</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="padding-left:1ex;margin:0px 0px 0px 0.8ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><u></u>
<div style="margin:10px">
<div>
<div>Dear all,</div>
<div> </div>
<div>I used the latlon_to_SCRIP function to
generate lat-lon grid file with SCRIP format which will then be
used as input files of the ESMF application "ESMF_RegridWeightGen".</div>
<div>When I applied latlon_to_SCRIP to 1x1, 0.5x0.5 and 0.25x0.25 grids,
the output results were right. However, when I applied latlon_to_SCRIP to
0.1x0.1 grids, the output results </div>
<div>are wrong. Do the latlon_to_SCRIP function support to generate a
0.1x0.1 grid file? Can you help me to solve this problem? </div>
<div>Thank you very much.</div>
<div> </div>
<div style="color:rgb(255,0,0)">The code used to generate the 0.25x0.25
grids are as follows:</div>
<div>_______________</div>
<div>
<div>Opt
= True</div>
<div><a href="mailto:Opt@LLCorner" target="_blank">Opt@LLCorner</a> = (/
-89.875d, -179.875d/)</div>
<div><a href="mailto:Opt@URCorner" target="_blank">Opt@URCorner</a> = (/
89.875d, 179.875d/)</div>
<div><a href="mailto:Opt@ForceOverwrite" target="_blank">Opt@ForceOverwrite</a>
= True</div>
<div><a href="mailto:Opt@PrintTimings" target="_blank">Opt@PrintTimings</a> = True</div>
<div>latlon_to_SCRIP(srcGridName,"0.25x0.25",Opt)</div>
<div>delete(Opt)</div>
<div>________________</div>
<div> </div></div>
<div style="color:rgb(255,0,0)">The header of the output netcdf file is as
follows: </div>
<div>________________</div>
<div>
<div>dimensions:</div>
<div> grid_size = 1036800 ;</div>
<div> grid_corners = 4 ;</div>
<div> grid_rank = 2 ;</div>
<div>variables:</div>
<div> int grid_dims(grid_rank)
;</div>
<div> double
grid_center_lat(grid_size) ;</div>
<div>
grid_center_lat:units = "degrees" ;</div>
<div> double
grid_center_lon(grid_size) ;</div>
<div>
grid_center_lon:units = "degrees" ;</div>
<div> int grid_imask(grid_size)
;</div>
<div>
grid_imask:units = "unitless" ;</div>
<div> double
grid_corner_lat(grid_size, grid_corners) ;</div>
<div>
grid_corner_lat:units = "degrees" ;</div>
<div> double
grid_corner_lon(grid_size, grid_corners) ;</div>
<div>
grid_corner_lon:units = "degrees" ;</div>
<div> </div>
<div>// global attributes:</div>
<div>
:date_created = "Thu Oct 15 19:49:54 CST 2015" ;</div>
<div>
:Createdby = "ESMF_regridding.ncl" ;</div>
<div>
:Conventions = "SCRIP" ;</div>
<div>
:title = "0.25x0.25 grid" ;</div>
<div>data:</div>
<div> </div>
<div>grid_dims = 1440, 720 ;</div></div>
<div>________________</div>
<div> </div>
<div> </div>
<div>
<div style="color:rgb(255,0,0)">The code used to generate the 0.1x0.1 grids
are as follows:</div></div>
<div>
<div>_______________</div>
<div>
<div>Opt
= True</div>
<div><a href="mailto:Opt@LLCorner" target="_blank">Opt@LLCorner</a> = (/
-89.95d, -179.95d/)</div>
<div><a href="mailto:Opt@URCorner" target="_blank">Opt@URCorner</a> = (/
89.95d, 179.95d/)</div>
<div><a href="mailto:Opt@ForceOverwrite" target="_blank">Opt@ForceOverwrite</a>
= True</div>
<div><a href="mailto:Opt@PrintTimings" target="_blank">Opt@PrintTimings</a> = True</div>
<div>latlon_to_SCRIP(srcGridName,"0.1x0.1",Opt)</div>
<div>delete(Opt)</div>
<div>________________</div>
<div> </div>
<div style="color:rgb(255,0,0)">The header of the output netcdf file is as
follows: </div></div></div>
<div>_____________</div>
<div>
<div>dimensions:</div>
<div> grid_size = 6474601 ;</div>
<div> grid_corners = 4 ;</div>
<div> grid_rank = 2 ;</div>
<div>variables:</div>
<div> int grid_dims(grid_rank)
;</div>
<div> double
grid_center_lat(grid_size) ;</div>
<div>
grid_center_lat:units = "degrees" ;</div>
<div> double
grid_center_lon(grid_size) ;</div>
<div>
grid_center_lon:units = "degrees" ;</div>
<div> int grid_imask(grid_size)
;</div>
<div>
grid_imask:units = "unitless" ;</div>
<div> double
grid_corner_lat(grid_size, grid_corners) ;</div>
<div>
grid_corner_lat:units = "degrees" ;</div>
<div> double
grid_corner_lon(grid_size, grid_corners) ;</div>
<div>
grid_corner_lon:units = "degrees" ;</div>
<div> </div>
<div>// global attributes:</div>
<div>
:date_created = "Thu Oct 15 20:27:42 CST 2015" ;</div>
<div>
:Createdby = "ESMF_regridding.ncl" ;</div>
<div>
:Conventions = "SCRIP" ;</div>
<div>
:title = "0.1deg grid" ;</div>
<div>data:</div>
<div> </div>
<div>grid_dims = 3599, 1799 ;</div></div>
<div>_____________</div>
<div style="font-weight:bold;color:rgb(255,0,0)">Why the grid_dims are
3599x1799? I think it should be 3600x1800.</div>
<div> </div>
<div> </div>
<div>Yours Sincerely,</div>
<div>Huansheng Chen</div></div>
<div> </div>
<hr style="min-height:1px;width:210px" align="left" color="#b5c4df" size="1">
<div><span>
<div style="font-size:10pt;font-family:verdana;margin:10px">
<div>
<div style="font-size:10pt;font-family:verdana;margin:10px">
<div>陈焕盛(LAPC/IAP)</div>
<div>大气边界层物理和大气化学国家重点实验室</div>
<div>中国科学院大气物理研究所</div></div></div></div></span></div></div></blockquote></div></div></div></div></div></blockquote></div></div></div></div>