<div dir="ltr">Hi Xiao,<div>I would suggest reading in the text file as a string using asciiread, then switch the NaN values to 0, then convert to float. Note that there are numerous string functions in NCL (many of them start with "str").</div><div><br></div><div>An example:</div><div>; a = asciiread("file.txt",(/-1/),"string")</div><div>a = "-0.1 20 -999999 NaN 10.4 NaN" ; set up test data<br></div><div>b = str_sub_str(a,"NaN","0") ; convert NaN to 0's<br></div><div>c = str_split(b," ") ; split all values into individual strings<br></div><div>d = tofloat(c)</div><div>print(d)</div><div><br></div><div><div>Variable: d</div><div>Type: float</div><div>Total Size: 24 bytes</div><div> 6 values</div><div>Number of Dimensions: 1</div><div>Dimensions and sizes:<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>[6]</div><div>Coordinates: </div><div>(0)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>-0.1</div><div>(1)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>20</div><div>(2)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>-999999</div><div>(3)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span> 0</div><div>(4)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>10.4</div><div>(5)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span> 0</div></div><div><br></div><div>The above call to str_split assumes that your values are separated by spaces, and thus you might need to change this if your values are separated by commas or something else.</div><div><br></div><div>Hope that helps! If not, or if you have further questions please post to the ncl-talk email list.</div><div>Adam</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 9:00 AM, Zhang, Xiao <span dir="ltr"><<a href="mailto:xiao.zhang@pnnl.gov" target="_blank">xiao.zhang@pnnl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div class="m_4157258251068262391WordSection1">
<p class="MsoNormal">Hello,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I have a big text input file, most values are numbers but it has string “NaN” in it. After reading in I tried to replace it with 0 using: (where a.eq.”NaN”,0,a), but it didn’t work. Anyone knows how to fix it? Thank you!<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Best,<u></u><u></u></p>
<p class="MsoNormal">Xiao<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">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/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span><font color="#888888">Adam Phillips <br></font></span></div><span><font color="#888888">Associate Scientist, </font></span><span><font color="#888888">Climate and Global Dynamics Laboratory, NCAR<br></font></span></div></div><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a> </font></span><span><font color="#888888">303-497-1726 </font></span></div><span><font color="#888888"></font></span><div><div><span><font color="#888888"><br></font></span><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank"></a></font></span></div></div></div></div></div></div></div></div></div></div></div>
</div>