<div dir="ltr"><div class="gmail_default" style="font-size:small">Unfortunately you can&#39;t use NCL functions to just read parts of an ASCII file.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">However, you could use the UNIX &quot;cut&quot; command to select out the subsections you want.  See this page for some examples:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><a href="http://www.ncl.ucar.edu/Applications/read_ascii.shtml">http://www.ncl.ucar.edu/Applications/read_ascii.shtml</a><br></div><div class="gmail_default"><br></div><div class="gmail_default">Use your browser search to look for the word &quot;cut&quot;. You will find several references.</div><div class="gmail_default"><br></div><div class="gmail_default">Good luck,</div><div class="gmail_default"><br></div><div class="gmail_default">--Mary</div><div class="gmail_default"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 4:58 AM, Guido Cioni <span dir="ltr">&lt;<a href="mailto:guidocioni@gmail.com" target="_blank">guidocioni@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Just to be correct about this, but someone could step in if I&#39;m saying stupid things, you HAVE to load the file into the memory (asciifile) and then subset with data(5:10), for example. <div>If you don&#39;t want to load the entire file just cut it before reading it into NCL. <span class="HOEnZb"><font color="#888888"><br><div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_-7730919517539955853Apple-interchange-newline">Guido Cioni</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="http://guidocioni.altervista" target="_blank">http://guidocioni.altervista</a>.<wbr>org</div>

</div></font></span><div><div class="h5">
<br><div><blockquote type="cite"><div>On 28 Feb 2017, at 12:56, Guido Cioni &lt;<a href="mailto:guidocioni@gmail.com" target="_blank">guidocioni@gmail.com</a>&gt; wrote:</div><br class="m_-7730919517539955853Apple-interchange-newline"><div><div style="word-wrap:break-word">Hey Xiaofeng,<div>First, I would suggest you to remove all the rows that are not supposed to be read by NCL (i.e. the header) beforehand, otherwise you&#39;ll get into the trouble. If you tell NCL to expect 2 columns of integers when there is 1 of string...you imagine what could result of this :) You can skip the header somehow, but to debug the code it&#39;s easier to have fewer complications. </div><div><br></div><div>Second, I&#39;m pretty sure that the <font face="Menlo">asciiread</font> procedure (which, I believe, you&#39;re using) does not work well with strings AND numeric values on the same row. If you read from the documentation (<a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml" target="_blank">http://www.ncl.ucar.edu/<wbr>Document/Functions/Built-in/<wbr>asciiread.shtml</a>) &quot;For<span style="color:rgb(51,51,51);font-family:verdana,sans-serif;font-size:13.3333px;background-color:rgb(255,255,255)"> string data, each line of the file is read as a string&quot;</span></div><div>So the line begins as a string it would read it as a string. In order to read strings and values you have to read everything as string and then perform a conversion, as explained here (<a href="http://www.ncl.ucar.edu/Applications/read_ascii.shtml#pw" target="_blank">http://www.ncl.ucar.edu/<wbr>Applications/read_ascii.shtml#<wbr>pw</a>, see Example for <a href="http://www.ncl.ucar.edu/Applications/Data/asc/istasyontablosu_son.txt" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif;font-size:13.3333px;font-variant-ligatures:normal" target="_blank">p</a>w.dat file, which is really similar to what you have).</div><div><br></div><div>So I would modify your ascii file as follows (you can compute totals afterwards, that&#39;s what NCL is meant for):</div><div><br></div><div><div><font face="Menlo">China<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>1,321<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       19.84%</font></div><div><font face="Menlo">India<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>1,132<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       16.96%</font></div><div><font face="Menlo">United States<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">        </span>304<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       4.56%</font></div><div><font face="Menlo">Indonesia<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">        </span>232<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       3.47%</font></div><div><font face="Menlo">Brazil<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>187<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       2.80%</font></div><div><font face="Menlo">Pakistan<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">        </span>163<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       2.44%</font></div><div><font face="Menlo">Bangladesh<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">        </span>159<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       2.38%</font></div><div><font face="Menlo">Nigeria<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>148<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       2.22%</font></div><div><font face="Menlo">Russia<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>142<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       2.13%</font></div><div><font face="Menlo">Japan<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>128<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       1.92%</font></div><div><font face="Menlo">Mexico<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>107<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       1.60%</font></div><div><font face="Menlo">Philippines<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">        </span>89<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       1.33%</font></div><div><font face="Menlo">Vietnam<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>84<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       1.31%</font></div><div><font face="Menlo">Germany<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>82<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       1.23%</font></div><div><font face="Menlo">Egypt<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>81<span class="m_-7730919517539955853Apple-tab-span" style="white-space:pre-wrap">                </span>       1.13%</font></div><div><br></div><div>and read it as (NOT TESTED): </div><div><br></div><div><pre style="margin-top:0px;margin-bottom:0px;padding:0px;font-size:13.3333px;line-height:12pt;font-family:courier;border-style:solid;border-width:0px 0px 15px;border-color:transparent;font-variant-ligatures:normal">  fname = &quot;asc4.txt&quot;
  data  = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif" target="_blank"><strong style="margin:0px;padding:0px">asciiread</strong></a>(fname,-1,&quot;string&quot;)
  population = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/stringtofloat.shtml" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif" target="_blank"><strong style="margin:0px;padding:0px">stringtofloat</strong></a>(<a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_field.shtml" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif" target="_blank"><strong style="margin:0px;padding:0px">str_get_field</strong></a>(<wbr>data, 2,&quot; &quot;))
  precentage = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/stringtofloat.shtml" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif" target="_blank"><strong style="margin:0px;padding:0px">stringtofloat</strong></a>(<a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_field.shtml" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif" target="_blank"><strong style="margin:0px;padding:0px">str_get_field</strong></a>(<wbr>data, 3,&quot; &quot;))
  country    = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_field.shtml" style="margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif" target="_blank"><strong style="margin:0px;padding:0px">str_get_field</strong></a>(data, 1,&quot; &quot;)</pre><div><br></div></div><div>Carefully read the page <a href="http://www.ncl.ucar.edu/Applications/read_ascii.shtml" target="_blank">http://www.ncl.ucar.edu/<wbr>Applications/read_ascii.shtml</a>, there are a lot of examples.</div><div><br></div><div>Cheers</div><div><br></div><div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_-7730919517539955853Apple-interchange-newline">Guido Cioni</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="http://guidocioni.altervista/" target="_blank">http://guidocioni.altervista</a>.<wbr>org</div>

</div>
<br><div><blockquote type="cite"><div>On 28 Feb 2017, at 12:29, Xiaofeng Li &lt;<a href="mailto:Xiaofeng.Li@newcastle.ac.uk" target="_blank">Xiaofeng.Li@newcastle.ac.uk</a>&gt; wrote:</div><br class="m_-7730919517539955853Apple-interchange-newline"><div><span id="m_-7730919517539955853cid:BCB4EFC862A06644858B3CCB21238BF0@eurprd07.prod.outlook.com">&lt;asc4.txt&gt;</span></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></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></div>