<div dir="ltr">Thank you so much for your explanations. It makes so much sense now.<div><br></div><div>Sincerely,</div><div>Grace</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 23, 2017 at 6:45 PM, Kevin Hallock <span dir="ltr"><<a href="mailto:hallock@ucar.edu" target="_blank">hallock@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Grace,<div><br></div><div>It looks like you’re trying to run the example script <a href="http://www.ncl.ucar.edu/Applications/Scripts/csv_2.ncl" target="_blank">csv_2.ncl</a> from the NCL website. <a href="http://ncl.ucar.edu/Applications/Data/" target="_blank">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" target="_blank">example2.csv</a> if you don’t already have it.</div><div><br></div><div>A quick issue I’d like to mention: this example seems to be using “<font face="Menlo">group</font>” as a variable name, but recent versions of NCL treat “<font face="Menlo">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">grp</font>” instead of “<font face="Menlo">group</font>” as needed.</div><div><br></div><div>In this example, a CSV file “example2.csv” is read into NCL using <font face="Menlo">asciiread()</font>. Then, the function <font face="Menlo">str_get_field()</font> is used repeatedly to store the 1st, 5th, and 9th values of each row into the variables “<font face="Menlo">name</font>”, “<font face="Menlo">grp</font>”, and “<font face="Menlo">size</font>”, respectively. If you were to add a “<font face="Menlo">print(name)</font>” line after “<font face="Menlo">name = str_get_field(lines,1,delim)</font>”, you should see output like this:</div><div><font face="Menlo">> print(name)<br><br>Variable: name<br>Type: string<br>Total Size: 56 bytes<br>            7 values<br>Number of Dimensions: 1<br>Dimensions and sizes:   [7]<br>Coordinates: <br>(0)     psmith01<br>(1)     smehta<br>(2)     mrsjohns<br>(3)     psmith02<br>(4)     scohen<br>(5)     swright<br>(6)     amarkov<br></font><br></div><div>Similarly, printing the other variables, you would see:</div><div><font face="Menlo">> print(grp) <br><br>Variable: grp<br>Type: integer<br>Total Size: 28 bytes<br>            7 values<br>Number of Dimensions: 1<br>Dimensions and sizes:   [7]<br>Coordinates: <br>(0)     1<br>(1)     1<br>(2)     -1<br>(3)     0<br>(4)     2<br>(5)     1<br>(6)     3<br></font><br></div><div>and</div><div><font face="Menlo">> print(size)<br><br>Variable: size<br>Type: float<br>Total Size: 28 bytes<br>            7 values<br>Number of Dimensions: 1<br>Dimensions and sizes:   [7]<br>Coordinates: <br>(0)      1<br>(1)     2.1<br>(2)      2<br>(3)     10<br>(4)      1<br>(5)      1<br>(6)      1<br></font><br></div><div>NCL is able to concatenate strings with other data types, which is what we see in the "<font face="Menlo">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><font face="Menlo">           / psmith01 \</font><span style="font-family:Menlo">               / 1 \              /  1  \</span></div><div><font face="Menlo">          // </font><span style="font-family:Menlo">smehta   \\             // 1 \\            // 2.1 \\</span></div><div><font face="Menlo">         /// </font><span style="font-family:Menlo">mrsjohns \\\           ///-1 \\\          ///  2  \\\</span></div><div><font face="Menlo">"Name is -   psmith02  - , group is     0    , size is     10     "</font></div><div><div><font face="Menlo">         \\\ </font><span style="font-family:Menlo">scohen   ///           \\\ 2 ///          \\\  1  ///</span></div><div><font face="Menlo">          \\ swright  //             \\ 1 //            \\  1  //</font></div><div><font face="Menlo">           \ amarkov  /               \ 3 /              \  1  /</font></div><div><br></div></div><div>or in NCL:</div><div><font face="Menlo">print("Name is'" + name + "', group is " + grp + ", size is " + size) <br>(0)     Name is'psmith01', group is 1, size is 1<br>(1)     Name is'smehta', group is 1, size is 2.1<br>(2)     Name is'mrsjohns', group is -1, size is 2<br>(3)     Name is'psmith02', group is 0, size is 10<br>(4)     Name is'scohen', group is 2, size is 1<br>(5)     Name is'swright', group is 1, size is 1<br>(6)     Name is'amarkov', group is 3, size is 1</font></div><div><font face="Menlo"><br></font></div><div><br></div><div>I hope this helps,</div><div>Kevin</div><div><br></div><div><div><blockquote type="cite"><div><div class="h5"><div>On Oct 23, 2017, at 4:14 PM, Grace Choi <<a href="mailto:gracesh27@gmail.com" target="_blank">gracesh27@gmail.com</a>> wrote:</div><br class="m_-4092490848234405291Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr">Hi everyone,<div><br></div><div>So I am having a trouble understanding a part of a script for reading CSV file. </div><div><br></div><div>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><br></div><div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_code.ncl"</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">load "$NCARG_ROOT/lib/ncarg/<wbr>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"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">begin</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">filename = "example2.csv"</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">lines = asciiread(filename,-1,"string"<wbr>)</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">delim = ","</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures">group = tointeger(str_get_field(lines,<wbr>5,delim)</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">size = tofloat(str_get_field(lines,9,<wbr>delim)</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;background-color:rgb(255,217,102)">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"><span style="font-variant-ligatures:no-common-ligatures;background-color:rgb(255,217,102)">end</span></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, helvetica, sans-serif">I am not sure what </font></span><font><font face="Menlo" style="font-size:11px"><span style="background-color:rgb(255,217,102)">print("Name is'" + name + "', group is " + group + ", size is " + size)</span></font><font face="arial, helvetica, sans-serif"><span style="background-color:rgb(255,255,255)"><span style="font-size:11px"> </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><font><font face="arial, helvetica, sans-serif"><span style="background-color:rgb(255,255,255)"><br></span></font></font></div><div><font><font face="arial, helvetica, sans-serif"><span style="background-color:rgb(255,255,255)">Thanks so much for your help.</span></font></font></div><div><font><font face="arial, helvetica, sans-serif"><span style="background-color:rgb(255,255,255)"><br></span></font></font></div><div><font><font face="arial, helvetica, sans-serif"><span style="background-color:rgb(255,255,255)">Sincerely,</span></font></font></div><div><font><font face="arial, helvetica, sans-serif"><span style="background-color:rgb(255,255,255)">Grace</span></font></font></div></div></div></div><span class="">
______________________________<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><br></span></div></blockquote></div><br></div></div></blockquote></div><br></div>