[ncl-talk] asciiread

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Tue Oct 6 10:07:33 MDT 2020


Please try the function *str_split_csv*.  It is designed to work with CSV
data that may contain empty fields and consecutive delimiters.


On Tue, Oct 6, 2020 at 9:28 AM Ehsan Taghizadeh via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Dear Rick,
> Thank you so much for your nice help. It seems to work for stringtoint but
> not for stringtofloat!
>
> *Sincerely,*
> *Ehsan*
>



> On Tuesday, October 6, 2020, 06:13:23 PM GMT+3:30, Rick Brownrigg <
> brownrig at ucar.edu> wrote:
>
> Hi,
>
> 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 ",,"
>
> 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
>
> http://ncl.ucar.edu/Document/Functions/Built-in/str_get_field.shtml
>
> Hope that helps,
> Rick
>
>
> On Tue, Oct 6, 2020 at 8:18 AM Ehsan Taghizadeh via ncl-talk <
> ncl-talk at mailman.ucar.edu> wrote:
>
> Dears,
> 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.
>
>   f = "ncl.csv"
>   lnst = asciiread(f,-1,"string")
>   delim = ","
>
> ;-Read fields
>   pr = tofloat(str_get_field(lnst(1:),7, delim))
>
> error:
> warning: tofloat: A bad value was passed to (string) tofloat, input
> strings must contain numeric digits, replacing with missing value
>
> I've attached a sample input file and I'll be thankful if I hear from you.
>
> *Sincerely,*
> *Ehsan Taghizadeh*
> *University of Tehran, Iran*
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201006/06906270/attachment.html>


More information about the ncl-talk mailing list