<div dir="ltr">Also, there are a few other approaches.<br><br>; two 'other' approaches for the simple file<br><br> filename = "example1.csv"<br><br>; [1]<br><br> nrow = numAsciiRow(filename)<br> ncol = 3 ; manually specify<br> values_2d = asciiread(filename,(/nrow,ncol/),"integer")<br> write_matrix(values_2d,ncol+"2I5",False)<br><br> print("----")<br><br>; [2]<br><br> row_one = asciiread(filename,1,"string") ; read 1st row as string; ;print(row_one)<br> NCOL = str_fields_count(row_one, ",")<br> VALUES_2D = asciiread(filename,(/nrow,NCOL/),"integer")<br> write_matrix(VALUES_2D, NCOL+"I5" ,False) <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 15, 2016 at 4:26 AM, Karin Meier-Fleischer <span dir="ltr"><<a href="mailto:meier-fleischer@dkrz.de" target="_blank">meier-fleischer@dkrz.de</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"><div>Hi Joowan,</div><div><br></div><div>you’re right but you can use the newer str_split_csv function to get all elements into a 2D array directly:</div><div><div><br></div><div><font face="Courier New" color="#002e7a" size="2">begin</font></div><div><font face="Courier New" color="#002e7a" size="2"> filename = "example1.csv"</font></div><div><font face="Courier New" color="#002e7a" size="2"><br></font></div><div><font face="Courier New" color="#002e7a" size="2"> data = asciiread(filename,-1,"string”)</font></div><div><div><font face="Courier New" color="#002e7a" size="2"> print("______________")</font></div></div><div><font face="Courier New" color="#002e7a" size="2"><br></font></div><div><font face="Courier New" color="#002e7a" size="2">;-- use str_split_csv to get 2d array</font></div><div><font face="Courier New" color="#002e7a" size="2"> ncols = dimsizes(str_split(data(0),","))</font></div><div><font face="Courier New" color="#002e7a" size="2"><br></font></div><div><font face="Courier New" color="#002e7a" size="2"> values_2d = toint(str_split_csv(data, ",", 0))</font></div><div><font face="Courier New" color="#002e7a" size="2"> print(values_2d)</font></div><div><font face="Courier New" color="#002e7a" size="2"> print("______________")</font></div><div><font face="Courier New" color="#002e7a" size="2"><br></font></div><div><font face="Courier New" color="#002e7a" size="2"> write_matrix(values_2d,ncols+"I5",False)</font></div><div><font face="Courier New" color="#002e7a" size="2"><br></font></div><div><font face="Courier New" color="#002e7a" size="2">end</font></div></div><div><br></div><div>Terminal output:</div><div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> > ncl csv_1.ncl</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> Copyright (C) 1995-2015 - All Rights Reserved</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> University Corporation for Atmospheric Research</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> NCAR Command Language Version 6.3.0</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> The use of this software is governed by a License Agreement.</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> See <a href="http://www.ncl.ucar.edu/" target="_blank">http://www.ncl.ucar.edu/</a> for more details.</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(0)<span style="white-space:pre-wrap">        </span>34,67,56</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(1)<span style="white-space:pre-wrap">        </span>36,87,78</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(2)<span style="white-space:pre-wrap">        </span>31,56,88</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(3)<span style="white-space:pre-wrap">        </span>29,67,92</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(4)<span style="white-space:pre-wrap">        </span>54,71,68</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(5)<span style="white-space:pre-wrap">        </span>42,65,82</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(0)<span style="white-space:pre-wrap">        </span>______________</font></div><div style="margin:0px;background-color:rgb(212,251,121);min-height:22px"><font face="Courier New" color="#0042aa" size="2"><br></font></div><div style="margin:0px;background-color:rgb(212,251,121);min-height:22px"><font face="Courier New" color="#0042aa" size="2"><br></font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Variable: values_2d</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Type: integer</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Total Size: 72 bytes</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 18 values</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Number of Dimensions: 2</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[6] x [3]</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Coordinates: </font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">Number Of Attributes: 1</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> _FillValue :<span style="white-space:pre-wrap">        </span>-<a href="tel:2147483647" value="+12147483647" target="_blank">2147483647</a></font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(0,0)<span style="white-space:pre-wrap">        </span>34</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(0,1)<span style="white-space:pre-wrap">        </span>67</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(0,2)<span style="white-space:pre-wrap">        </span>56</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(1,0)<span style="white-space:pre-wrap">        </span>36</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(1,1)<span style="white-space:pre-wrap">        </span>87</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(1,2)<span style="white-space:pre-wrap">        </span>78</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(2,0)<span style="white-space:pre-wrap">        </span>31</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(2,1)<span style="white-space:pre-wrap">        </span>56</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(2,2)<span style="white-space:pre-wrap">        </span>88</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(3,0)<span style="white-space:pre-wrap">        </span>29</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(3,1)<span style="white-space:pre-wrap">        </span>67</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(3,2)<span style="white-space:pre-wrap">        </span>92</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(4,0)<span style="white-space:pre-wrap">        </span>54</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(4,1)<span style="white-space:pre-wrap">        </span>71</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(4,2)<span style="white-space:pre-wrap">        </span>68</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(5,0)<span style="white-space:pre-wrap">        </span>42</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(5,1)<span style="white-space:pre-wrap">        </span>65</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(5,2)<span style="white-space:pre-wrap">        </span>82</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2">(0)<span style="white-space:pre-wrap">        </span>______________</font></div><p style="margin:0px;background-color:rgb(212,251,121);min-height:22px"><font face="Courier New" color="#0042aa" size="2"> <br></font></p><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 34 67 56</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 36 87 78</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 31 56 88</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 29 67 92</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 54 71 68</font></div><div style="margin:0px;background-color:rgb(212,251,121)"><font face="Courier New" color="#0042aa" size="2"> 42 65 82</font></div></div><div><br></div><div><br></div><div>Bye,</div><div>Karin</div><div><br></div><br><div><blockquote type="cite"><div><div class="h5"><div>Am 15.05.2016 um 07:17 schrieb Joowan Kim <<a href="mailto:joowan@ucar.edu" target="_blank">joowan@ucar.edu</a>>:</div><br></div></div><div><div><div class="h5"><div dir="ltr"><div style="font-size:12.8px">Dear whom it concerns,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Just quick report of error in web example</div><div style="font-size:12.8px">"<a href="https://www.ncl.ucar.edu/Applications/read_csv.shtml" target="_blank">https://www.ncl.ucar.edu/Applications/read_csv.shtml</a>"</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">In the example page "csv_1.ncl" can NOT reproduce all data in "example1.csv"</div><div style="font-size:12.8px">(it only reads first colume of each line and simply repeats. Values in 2nd and 3rd row</div><div style="font-size:12.8px">are ignored) I guess it may confuse some people.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Just FYI</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Best!</div><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Joowan Kim<br>National Center for Atmospheric Research<br>PO Box 3000 Boulder, CO 80307<br><div>web: <a href="http://acd.ucar.edu/~joowan" target="_blank">http://acd.ucar.edu/~joowan</a><br></div><div>email: <a href="mailto:joowan@ucar.edu" target="_blank">joowan@ucar.edu</a> </div><div> <a href="mailto:joowan.k@gmail.com" target="_blank">joowan.k@gmail.com</a><br></div><div><br></div></div></div></div></div></div></div></div></div></div></div>
</div></div></div>
_______________________________________________<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/mailman/listinfo/ncl-talk</a><br></div></blockquote></div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span style="border-collapse:separate;border-spacing:0px"><div style="word-wrap:break-word"><span style="border-collapse:separate;font-family:Helvetica;font-variant:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word">____________________________________</div></span><span style="font-size:13px;font-family:'Courier New'">Dipl. Geophys. Karin Meier-Fleischer</span></div></span><div><font face="Courier New"><span style="font-size:13px">Visualisierung</span></font></div><div><font face="Courier New"><span style="font-size:13px">Abteilung Anwendungen</span></font></div><div><font face="Courier New"><span style="font-size:13px"><br></span></font></div><div><font face="Courier New"><span style="font-size:13px">Deutsches Klimarechenzentrum GmbH (DKRZ)</span></font></div><div><font face="Courier New"><span style="font-size:13px">Bundesstrasse 45a * D-</span></font><span style="font-size:13px;font-family:'Courier New';text-align:-webkit-auto">20146 Hamburg </span></div><div><font face="Courier New"><span style="font-size:13px">Germany </span></font></div><div><font face="Courier New"><span style="font-size:13px"><br></span></font></div><div><span style="font-family:'Courier New';font-size:13px">Phone:<span style="white-space:pre-wrap">        </span><a href="tel:%2B49%20%280%2940%20460094%20126" value="+4940460094126" target="_blank">+49 (0)40 460094 126</a></span></div><div><div><span style="font-family:'Courier New';font-size:13px;text-align:-webkit-auto">Fax:<span style="white-space:pre-wrap">        </span><a href="tel:%2B49%20%280%2940%20460094%20270" value="+4940460094270" target="_blank">+49 (0)40 460094 270</a></span></div><div><font face="Courier New"><span style="font-size:13px">E-Mail:<span style="white-space:pre-wrap">        </span></span></font><span style="font-size:13px;font-family:'Courier New';text-align:-webkit-auto"><a href="mailto:meier-fleischer@dkrz.de" target="_blank">meier-fleischer@dkrz.de</a></span></div></div><div><font face="Courier New"><span style="font-size:13px">URL:<span style="white-space:pre-wrap">        </span></span></font><span style="text-align:-webkit-auto;font-size:13px;font-family:'Courier New'"><a href="http://www.dkrz.de/" target="_blank">http://www.dkrz.de/</a></span></div><div><font face="Courier New"><span style="font-size:13px"><br></span></font></div><div><font face="Courier New"><span style="font-size:13px">Geschäftsführer: Prof. Dr. Thomas Ludwig</span></font></div><div><font face="Courier New"><span style="font-size:13px">Sitz der Gesellschaft: Hamburg</span></font></div><div><font face="Courier New"><span style="font-size:13px">Amtsgericht Hamburg HRB 39784</span></font></div><div><br></div></div></span></div></div></div></div></div><br><br>
</div>
<br></div><br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>