<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I am only answering question #1.  That list of numbers is a very special case.  Every number is exactly half way between two integers.  Because of this, you get into the fine details of how different compilers handle rounding.  There is a difference in the tie-breaking rule for numbers that are exactly half way between the two closest representable values.</div><br>Your versions of NCL and gfortran use a rounding mode called "Round half to even".  But your PGI compiler uses a different rounding mode called "Round half away from zero".  This explains the differences between the lists that you showed.  See the wikipedia page "Rounding" for more details.</div><div dir="ltr"><br></div><div dir="ltr">There are other names in use.  In particular, the IEEE 754 standard for floating point arithmetic uses different and more precise names for these two rounding modes.</div><div dir="ltr"><br></div>In NCL, if you want "Round half away from zero" like you showed, then yes, you should use the "round" function, instead of depending on printf rounding.  Unfortunately, the exact rounding mode of NCL's "round" function is not documented and not guaranteed.  This behavior may change between NCL versions, install configurations, and platforms.  I hope the current behavior is sufficient for your immediate purposes.<br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 20, 2019 at 4:26 AM Ehsan Taghizadeh via ncl-talk <<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div style="font-family:"bookman old style","new york",times,serif;font-size:16px"><div dir="ltr">Hi,<br>I hope you're doing great.</div><div dir="ltr">I have some difficulties and I'll be thankful if I could have your help.</div><div dir="ltr"><br></div><div dir="ltr">1- Why -0.5 is written 0 (not -1) while -1.5 is written -2, with <font face="courier new, courier, monaco, monospace, sans-serif" size="2">"%4.0f"</font> in the following lines? It seems reals round to even numbers.</div><div dir="ltr"><br></div><div dir="ltr"><span><font size="2" face="courier new, courier, monaco, monospace, sans-serif" style="background-color:inherit">a := (/-0.5D0, 0.5D0, -1.5D0, 1.5D0, -2.5D0, 2.5D0, -3.5D0, 3.5D0/)</font></span></div><div dir="ltr"><span><font size="2" style="background-color:inherit"><span><font face="courier new, courier, monaco, monospace, sans-serif" style="background-color:inherit"> print(sprintf("%4.0f", a))</font></span><br></font></span></div><div dir="ltr"><span><span><font size="3" style="background-color:inherit"><br></font></span></span></div><div dir="ltr"><span><span><font size="3" style="background-color:inherit">output:</font></span></span></div><div dir="ltr"><span><div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(0)       -0</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(1)        0</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(2)       -2</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(3)        2</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(4)       -2</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(5)        2</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(6)       -4</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(7)        4</font></div><div dir="ltr">However, this is same for gfortran.</div></div><div dir="ltr">fortran code:</div><div dir="ltr"><br></div><div dir="ltr"><div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">implicit none</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">real*8 :: a(8)</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">a = (/-0.5D0, 0.5D0, -1.5D0, 1.5D0, -2.5D0, 2.5D0, -3.5D0, 3.5D0/)</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">print"(f4.0)", a</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">end</font></div></div><font size="3"><div dir="ltr"><font size="3"><br></font></div>output:</font></div><div dir="ltr"><div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif"> -0.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">  0.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif"> -2.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">  2.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif"> -2.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">  2.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif"> -4.</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">  4.</font></div><div><br></div></div><span><span style="color:rgb(0,0,0)"><div dir="ltr" style="font-size:16px;font-family:"bookman old style","new york",times,serif"><span><span style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px">But for PGI compiler I see the other (expected) result:</span></span></div><div dir="ltr" style="font-size:16px;font-family:"bookman old style","new york",times,serif"><span><span style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px">output:</span></span></div><div dir="ltr"><div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2"> -1.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2">  1.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2"> -2.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2">  2.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2"> -3.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2">  3.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2"> -4.</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2">  4.</font></div><div style="font-size:16px;font-family:"bookman old style","new york",times,serif"><br></div></div></div><div dir="ltr" style="font-size:16px;font-family:"bookman old style","new york",times,serif">I confused what happened? Back to NCL, should I use round function, as below, to write output, always?<br></div></span></span></div><div dir="ltr"><span><span style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px"><br></span></span></div><div dir="ltr"><span><span style="color:rgb(0,0,0)"><font face="courier new, courier, monaco, monospace, sans-serif" style="background-color:inherit" size="2">b = round(a,0)<br></font></span></span></div><div dir="ltr"><span><span style="color:rgb(0,0,0)"><font face="courier new, courier, monaco, monospace, sans-serif" style="background-color:inherit" size="2">print(sprintf("%4.0f", b))</font><br></span></span></div><div dir="ltr"><span><span style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px"><span><span><br></span></span></span></span></div><div dir="ltr"><span><span style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px"><span><span>output:</span></span></span></span></div><div dir="ltr"><span><span style="color:rgb(0,0,0)"><div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(0)       -1</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(1)        1</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(2)       -2</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(3)        2</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(4)       -3</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(5)        3</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(6)       -4</font></div><div><font size="2" face="courier new, courier, monaco, monospace, sans-serif">(7)        4</font></div><div style="font-family:"bookman old style","new york",times,serif;font-size:16px"><br></div><div style="font-family:"bookman old style","new york",times,serif;font-size:16px" dir="ltr">2- How could I select (or delete) unordered subscription from a multidimensional array? For example, if there is an array (a) with following dimensions:</div><div style="font-family:"bookman old style","new york",times,serif;font-size:16px" dir="ltr"><br></div><div dir="ltr"><font face="courier new, courier, monaco, monospace, sans-serif" size="2">[lev | 34] x [lat | 361] x [lon | 720]</font><br></div><div style="font-family:"bookman old style","new york",times,serif;font-size:16px" dir="ltr"><br></div><div style="font-family:"bookman old style","new york",times,serif;font-size:16px" dir="ltr">and I want to make other array like a, exclude a(0,:,:), a(7,:,:) and a(10,:,:), what way is better than the following line?</div><div dir="ltr"><div><div dir="ltr"> <font face="courier new, courier, monaco, monospace, sans-serif" size="2">b := a((/1,2,3,4,5,6,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33/),:,:)</font></div><div style="font-size:16px;font-family:"bookman old style","new york",times,serif"><br></div></div>3- How could I compute difference between two successive levels, instead of using following loop:</div><div dir="ltr"><span style="font-family:"courier new",courier,monaco,monospace,sans-serif;font-size:small">FL = u@lev</span><br></div><div dir="ltr"><div><div dir="ltr"><font face="courier new, courier, monaco, monospace, sans-serif" size="2"><div><div dir="ltr" style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px"><font face="courier new, courier, monaco, monospace, sans-serif" size="2">ws(0,:,:) = 0.0<br></font></div><div>do i = 1, dimsizes(FL)-1<br></div></div></font></div><div dir="ltr"><font face="courier new, courier, monaco, monospace, sans-serif" size="2">    ws(i,:,:) = sqrt((u(i,:,:)-u(i-1,:,:))^2+(v(i,:,:)-v(i-1,:,:))^2)</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif" size="2">end do</font></div><div dir="ltr">As you know above lines compute wind shear.</div></div><div dir="ltr"><br></div></div><div dir="ltr">Pardon me to ask different questions in one email.</div><div dir="ltr">I'll be thankful for any help.</div><div dir="ltr"><br></div><div dir="ltr"><i><font size="2">Sincerely</font></i></div><div dir="ltr"><i><font size="2">Ehsan</font></i></div><div dir="ltr"><i><font size="2">PhD student of Meteorology,</font></i></div><div dir="ltr"><i><font size="2">Institute of Geophysics, University of Tehran, Tehran, Iran</font></i></div></div></span></span></div></span></div></div></div></blockquote></div></div></div></div></div></div></div>