<div dir="ltr"><div><div><div><div><div>I am sure that NCL can do this. However, the description is rather obscure.<br><br><a href="http://www.ncl.ucar.edu/Document/Functions/string.shtml">http://www.ncl.ucar.edu/Document/Functions/string.shtml</a><br><br></div>What have you tried?<br><br>----<br><br></div>     s   = addfile(&quot;foo.txt&quot;,-1,&quot;string&quot;)<br></div>     ns = dimsizes(ns)                          ; number of lines<br><br>     delim = &quot; &quot;     ;    &quot;\/:;=-&quot;  ... whatever<br></div>     do n=0,ns-1<br></div><div>          nfld = <strong>str_fields_count</strong>(s(n), delim)  ; # fields in current line<br></div><div>          id    = <strong>str_get_field</strong>(s(n), 1, delim)    ; 1st field is the ID<br></div><div>       do nf=2,nfld<br></div><div>            fld = <strong>str_get_field</strong>(s(n), nf, delim)  <br></div><div>       end do<br></div>     end do<br><div><div><div><div><div><br></div><div>Put print statements to follow this.<br><br></div><div>Good luck<br></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 18, 2017 at 10:18 AM, Zhang, Xiao <span dir="ltr">&lt;<a href="mailto:xiao.zhang@pnnl.gov" target="_blank">xiao.zhang@pnnl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div link="blue" vlink="purple" lang="EN-US">
<div class="m_8616908477152577490WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Dennis and Dave,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Thanks for your help! The question is more complicated than just reading in. I’ll try to explain more clearly.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">For example, each line first column refers to an ID (“ID”), and the following are other grid cells associated with this grid (“Vari_ID”). Now I have a mask
 file and need to select all associated grid cells (Vari_ID) belonging to the mask file and the output file should have same format as input which is ID first and then associate grid cells. As the file has more than 4000 rows, it would be almost impossible
 to check the column number in each line and then count over. Do you know a good way to solve the problem?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Best,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Xiao<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Dennis Shea [mailto:<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>]
<br>
<b>Sent:</b> Thursday, May 18, 2017 7:44 AM<br>
<b>To:</b> Zhang, Xiao<br>
<b>Cc:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
<b>Subject:</b> Re: [ncl-talk] file with each line having varied length<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">The question leaves out many details. What is it that you want?<u></u><u></u></p>
</div>
<p class="MsoNormal">   x   = asciiread(&quot;foo.txt&quot;,-1,&quot;<wbr>integer&quot;)  ; x will be one-dimensional<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   nx = dimsizes(x)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   print(&quot;nx=&quot;+nx)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   print(&quot;---&quot;)<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">   print(x)<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Wed, May 17, 2017 at 11:25 PM, Zhang, Xiao &lt;<a href="mailto:xiao.zhang@pnnl.gov" target="_blank">xiao.zhang@pnnl.gov</a>&gt; wrote:<u></u><u></u></p>
<p class="MsoNormal">Hi I have a question in processing a file. Each line of this file has different length. For example, first line has 5 integers and second line has 9. And there are over 4000 lines. Is there a good way to deal with it? Thanks!<br>
<br>
<br>
______________________________<wbr>_________________<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" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>

</blockquote></div><br></div>