<div dir="ltr"><div>Please try the function <b>str_split_csv</b>. It is designed to work with CSV data that may contain empty fields and consecutive delimiters.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 6, 2020 at 9:28 AM Ehsan Taghizadeh via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.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 style="font-size:16px"></div>
<div dir="ltr" style="font-size:16px">Dear Rick,</div><div dir="ltr" style="font-size:16px">Thank you so much for your nice help. It seems to work for stringtoint but not for stringtofloat!</div><div style="font-size:16px"><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></div></blockquote><div><br></div><div> </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 style="font-family:"bookman old style","new york",times,serif;font-size:16px">
</div><div id="gmail-m_1143051973717922934yahoo_quoted_2734002388">
<div style="font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;color:rgb(38,40,42)">
<div>
On Tuesday, October 6, 2020, 06:13:23 PM GMT+3:30, Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>> wrote:
</div>
<div><br></div>
<div><div id="gmail-m_1143051973717922934yiv3065514746"><div dir="ltr"><div>Hi,</div><div><br clear="none"></div><div>At least part of the issue is that your file has consecutive delimiters, and str_get_field treats those as one (I did not know that!), so parsing the columns gets out of sync on lines with ",,"</div><div><br clear="none"></div><div>See example 5 at the link below for how to deal with this. It essentially uses str_sub_str() to textually replace instances of ",," with some appropriate _FillValue. It does this in the strings returned from asciiread() and then attempts to parse using str_get_field<br clear="none"></div><div><br clear="none"></div><div><a rel="nofollow" shape="rect" href="http://ncl.ucar.edu/Document/Functions/Built-in/str_get_field.shtml" target="_blank">http://ncl.ucar.edu/Document/Functions/Built-in/str_get_field.shtml</a></div><div><br clear="none"></div><div>Hope that helps,</div><div>Rick<br clear="none"></div><div><br clear="none"></div></div><br clear="none"><div><div id="gmail-m_1143051973717922934yiv3065514746yqt16042"><div dir="ltr">On Tue, Oct 6, 2020 at 8:18 AM Ehsan Taghizadeh via ncl-talk <<a rel="nofollow" shape="rect" href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br clear="none"></div><blockquote 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">Dears,</div><div dir="ltr">I would like to read a ".csv" file including different fields. Some arrays have no data and are empty. May I ask how I handle this file? I've tried the following lines, but I got the following warning because of arrays with no data.</div><div dir="ltr"><br clear="none"></div><div dir="ltr"><div><div> f = "ncl.csv"</div><div> lnst<span style="white-space:pre-wrap"> </span>= asciiread(f,-1,"string")</div><div> delim = ","</div><div><br clear="none"></div><div>;-Read fields</div><div> pr<span style="white-space:pre-wrap"> </span>= tofloat(str_get_field(lnst(1:),7, delim))<br clear="none"></div><div><br></div><div dir="ltr">error:</div><div dir="ltr"><span>warning: tofloat: A bad value was passed to (string) tofloat, input strings must contain numeric digits, replacing with missing value</span><br clear="none"></div><div><br clear="none"></div></div>I've attached a sample input file and I'll be thankful if I hear from you.</div><div dir="ltr"><br clear="none"></div><div dir="ltr"><i><font size="2">Sincerely,</font></i></div><div dir="ltr"><i><font size="2">Ehsan Taghizadeh</font></i></div><div dir="ltr"><i><font size="2">University of Tehran, Iran</font></i></div></div></div></blockquote></div></div></div></div></div></div></blockquote></div></div>