<div dir="ltr"><div dir="ltr"><div>the if statement inside the loop should be:</div><div><br></div><div> do i=0,3<br> if (xAbsDif(i).eq.xMinVal) then<br> print(i)<br> end if<br> end do<br></div><div><br></div><div>Cheers</div><div>Rashed<br></div><div><br></div><div><br></div><div><br></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 21, 2019 at 3:09 AM dale zuri <<a href="mailto:dalezuri@gmail.com">dalezuri@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Ncl user,<div><br><div>I would like to implement the closest value function without using ind function. I would appreciate any suggestion. </div></div><div>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">value2check = </span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.382</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">array2check = (/</span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.0001</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures"> ,</span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.5888</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.01</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.5</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">/)</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">index <span class="gmail-m_-1612610262032248655gmail-Apple-converted-space"> </span>= closest_val(value2check,array2check)</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">print(index)</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">xAbsDif = abs(value2check-array2check)</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">xMinVal = min(xAbsDif)</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">iClose<span class="gmail-m_-1612610262032248655gmail-Apple-converted-space"> </span>= (ind(xAbsDif.eq.xMinVal))</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">print(iClose)</span></p><p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">:::::without using ind;;;;;</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(175,173,36)">do</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures"> i=</span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">0</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">,</span><span class="gmail-m_-1612610262032248655gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">3</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(175,173,36)">if</span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures"> any(xAbsDif(i)) .eq. any(xMinVal) </span><span class="gmail-m_-1612610262032248655gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(175,173,36)">then</span></p>
<p class="gmail-m_-1612610262032248655gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">print<span style="background-color:rgb(0,166,178)">(i) ;; it's not giving right answer</span></span></p>
<p class="gmail-m_-1612610262032248655gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">end</span><span class="gmail-m_-1612610262032248655gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">if</span></p>
<p class="gmail-m_-1612610262032248655gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">end</span><span class="gmail-m_-1612610262032248655gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">do</span></p><p class="gmail-m_-1612610262032248655gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-m_-1612610262032248655gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-m_-1612610262032248655gmail-s1" style="font-variant-ligatures:no-common-ligatures">Thanks</span></p></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>