<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Grace,<div class=""><br class=""></div><div class="">It looks like you’re trying to run the example script <a href="http://www.ncl.ucar.edu/Applications/Scripts/csv_2.ncl" class="">csv_2.ncl</a> from the NCL website. <a href="http://ncl.ucar.edu/Applications/Data/" class="">Here’s a link</a> to all of the sample data files we host; specifically, you may want to download <a href="http://ncl.ucar.edu/Applications/Data/asc/example2.csv" class="">example2.csv</a> if you don’t already have it.</div><div class=""><br class=""></div><div class="">A quick issue I’d like to mention: this example seems to be using “<font face="Menlo" class="">group</font>” as a variable name, but recent versions of NCL treat “<font face="Menlo" class="">group</font>” as a keyword (meaning it cannot be used as a variable). I will try to update this example on our website in the near future. For now, please use “<font face="Menlo" class="">grp</font>” instead of “<font face="Menlo" class="">group</font>” as needed.</div><div class=""><br class=""></div><div class="">In this example, a CSV file “example2.csv” is read into NCL using <font face="Menlo" class="">asciiread()</font>. Then, the function <font face="Menlo" class="">str_get_field()</font> is used repeatedly to store the 1st, 5th, and 9th values of each row into the variables “<font face="Menlo" class="">name</font>”, “<font face="Menlo" class="">grp</font>”, and “<font face="Menlo" class="">size</font>”, respectively. If you were to add a “<font face="Menlo" class="">print(name)</font>” line after “<font face="Menlo" class="">name = str_get_field(lines,1,delim)</font>”, you should see output like this:</div><div class=""><font face="Menlo" class="">> print(name)<br class=""><br class="">Variable: name<br class="">Type: string<br class="">Total Size: 56 bytes<br class="">            7 values<br class="">Number of Dimensions: 1<br class="">Dimensions and sizes:   [7]<br class="">Coordinates: <br class="">(0)     psmith01<br class="">(1)     smehta<br class="">(2)     mrsjohns<br class="">(3)     psmith02<br class="">(4)     scohen<br class="">(5)     swright<br class="">(6)     amarkov<br class=""></font><br class=""></div><div class="">Similarly, printing the other variables, you would see:</div><div class=""><font face="Menlo" class="">> print(grp) <br class=""><br class="">Variable: grp<br class="">Type: integer<br class="">Total Size: 28 bytes<br class="">            7 values<br class="">Number of Dimensions: 1<br class="">Dimensions and sizes:   [7]<br class="">Coordinates: <br class="">(0)     1<br class="">(1)     1<br class="">(2)     -1<br class="">(3)     0<br class="">(4)     2<br class="">(5)     1<br class="">(6)     3<br class=""></font><br class=""></div><div class="">and</div><div class=""><font face="Menlo" class="">> print(size)<br class=""><br class="">Variable: size<br class="">Type: float<br class="">Total Size: 28 bytes<br class="">            7 values<br class="">Number of Dimensions: 1<br class="">Dimensions and sizes:   [7]<br class="">Coordinates: <br class="">(0)      1<br class="">(1)     2.1<br class="">(2)      2<br class="">(3)     10<br class="">(4)      1<br class="">(5)      1<br class="">(6)      1<br class=""></font><br class=""></div><div class="">NCL is able to concatenate strings with other data types, which is what we see in the "<font face="Menlo" class="">print("Name is'" + name + "', group is " + grp + ", size is " + size)</font>” statement. What is actually happening under the hood is something like this:</div><div class=""><font face="Menlo" class="">           / psmith01 \</font><span style="font-family: Menlo;" class="">               / 1 \              /  1  \</span></div><div class=""><font face="Menlo" class="">          // </font><span style="font-family: Menlo;" class="">smehta   \\             // 1 \\            // 2.1 \\</span></div><div class=""><font face="Menlo" class="">         /// </font><span style="font-family: Menlo;" class="">mrsjohns \\\           ///-1 \\\          ///  2  \\\</span></div><div class=""><font face="Menlo" class="">"Name is -   psmith02  - , group is     0    , size is     10     "</font></div><div class=""><div class=""><font face="Menlo" class="">         \\\ </font><span style="font-family: Menlo;" class="">scohen   ///           \\\ 2 ///          \\\  1  ///</span></div><div class=""><font face="Menlo" class="">          \\ swright  //             \\ 1 //            \\  1  //</font></div><div class=""><font face="Menlo" class="">           \ amarkov  /               \ 3 /              \  1  /</font></div><div class=""><br class=""></div></div><div class="">or in NCL:</div><div class=""><font face="Menlo" class="">print("Name is'" + name + "', group is " + grp + ", size is " + size) <br class="">(0)     Name is'psmith01', group is 1, size is 1<br class="">(1)     Name is'smehta', group is 1, size is 2.1<br class="">(2)     Name is'mrsjohns', group is -1, size is 2<br class="">(3)     Name is'psmith02', group is 0, size is 10<br class="">(4)     Name is'scohen', group is 2, size is 1<br class="">(5)     Name is'swright', group is 1, size is 1<br class="">(6)     Name is'amarkov', group is 3, size is 1</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><br class=""></div><div class="">I hope this helps,</div><div class="">Kevin</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Oct 23, 2017, at 4:14 PM, Grace Choi <<a href="mailto:gracesh27@gmail.com" class="">gracesh27@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi everyone,<div class=""><br class=""></div><div class="">So I am having a trouble understanding a part of a script for reading CSV file. </div><div class=""><br class=""></div><div class="">I have been having a hard time getting this script to work, because I am not sure how to correctly write the highlighted part of the script. </div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">begin</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">filename = "example2.csv"</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">lines = asciiread(filename,-1,"string")</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">delim = ","</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">name = str_get_field(lines,1,delim)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">group = tointeger(str_get_field(lines,5,delim)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">size = tofloat(str_get_field(lines,9,delim)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;background-color:rgb(255,217,102)" class="">print("Name is'" + name + "', group is " + group + ", size is " + size)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;background-color:rgb(255,217,102)" class="">end</span></div></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="arial, helvetica, sans-serif" class="">I am not sure what </font></span><font class=""><font face="Menlo" style="font-size:11px" class=""><span style="background-color:rgb(255,217,102)" class="">print("Name is'" + name + "', group is " + group + ", size is " + size)</span></font><font face="arial, helvetica, sans-serif" class=""><span style="background-color:rgb(255,255,255)" class=""><span style="font-size:11px" class=""> </span>indicates... What is the difference between "Name is"' + name. With an actual value put in, what should this script actually look like? </span></font></font></div><div class=""><font class=""><font face="arial, helvetica, sans-serif" class=""><span style="background-color:rgb(255,255,255)" class=""><br class=""></span></font></font></div><div class=""><font class=""><font face="arial, helvetica, sans-serif" class=""><span style="background-color:rgb(255,255,255)" class="">Thanks so much for your help.</span></font></font></div><div class=""><font class=""><font face="arial, helvetica, sans-serif" class=""><span style="background-color:rgb(255,255,255)" class=""><br class=""></span></font></font></div><div class=""><font class=""><font face="arial, helvetica, sans-serif" class=""><span style="background-color:rgb(255,255,255)" class="">Sincerely,</span></font></font></div><div class=""><font class=""><font face="arial, helvetica, sans-serif" class=""><span style="background-color:rgb(255,255,255)" class="">Grace</span></font></font></div></div>
_______________________________________________<br class="">ncl-talk mailing list<br class=""><a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">List instructions, subscriber options, unsubscribe:<br class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br class=""></div></blockquote></div><br class=""></div></body></html>