[ncl-talk] asciiread

Ehsan Taghizadeh ehsantaghizadeh at yahoo.com
Tue Oct 6 09:28:23 MDT 2020


 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 TaghizadehUniversity of Tehran, Iran_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201006/1d51cde4/attachment.html>


More information about the ncl-talk mailing list