<div dir="ltr"><div><div>The := syntax was introduced in NCL 6.1.1 (Feb 4, 2013)<br><br><p>
<b>New reassignment operator</b></p><p>
There's a new operator, ":=", that allows you to reassign variables
without having to delete them first.</p><p>
For example:
</p><p>
</p><pre> x = fspan(-10.5,20.8,0.1) ; array of floats
; x = "This is a string" ; this won't work
x <b>:=</b> "This is a string" ; single string
</pre>=====<br>I like the := syntax. <br><br>Not only does it negate the need to explicitly delete a variable before redefining the variable, it informs a person looking at the code that the variable on the left could change shape, sizes, type ....<br><br><br></div></div> Cheers <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 31, 2016 at 9:32 PM, Luke Osburn <span dir="ltr"><<a href="mailto:luke.osburn@monash.edu" target="_blank">luke.osburn@monash.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sounds like the variable "lines" has already been predefined with specific dimension sizes. And this does not match the assignment that you are trying to make, so you get a fatal error.<div><br></div><div>Direclty before: <span style="font-size:13px;font-family:'lucida grande',verdana,'microsoft yahei';line-height:23px">' lines = asciiread(filename1(i),-1,"</span><span style="font-size:13px;font-family:'lucida grande',verdana,'microsoft yahei';line-height:23px">str<wbr>ing")' </span></div><div><span style="font-size:13px;font-family:'lucida grande',verdana,'microsoft yahei';line-height:23px">put in: delete(lines) ;This removes the condition that the dimension sizes of left and right have to match as, lines is no longer defined. </span></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 1 November 2016 at 14:17, Yuqiang Zhang <span dir="ltr"><<a href="mailto:yuqiangzhang.thu@gmail.com" target="_blank">yuqiangzhang.thu@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div link="#0563C1" vlink="#954F72" lang="EN-US"><div class="m_8745908924922340546m_1286360134496254004WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Try this “</span><span style="font-family:"Verdana",sans-serif">lines := asciiread(filename1(i),-1,"str<wbr>ing")' </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">”<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">That happens when you read different files, and they have different length for each file. <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a> [mailto:<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.<wbr>edu</a>] <b>On Behalf Of </b>grace<br><b>Sent:</b> Monday, October 31, 2016 11:06 PM<br><b>To:</b> ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><br><b>Subject:</b> [ncl-talk] fatal:Dimension sizes of left hand side and right hand side of assignment do not match . Finding a better way to read csv data in different files for further calculation.<u></u><u></u></span></p><div><div class="m_8745908924922340546h5"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">Hi:<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> All,I have write a script to read and calculate .csv data according to the "Reading csv"example on the NCL website,but it appears fatal :<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><u></u> <u></u></span></p></div><div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">fatal:Dimension sizes of left hand side and right hand side of assignment do not match<br>fatal:["Execute.c":8567]:Execu<wbr>te: Error occurred at or near line 45 in file csv_read.ncl<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><u></u> <u></u></span></p></div></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">The line 45 is ' lines = asciiread(filename1(i),-1,"str<wbr>ing")' ........<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">.........<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">........<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">But when I try to read only one csv data,the script can work out.<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">I don't know how to fix this,can you guys help me?<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">My csv date stored like this:<u></u><u></u></span></p></div><div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><img id="m_8745908924922340546m_1286360134496254004_x0000_i1025" src="cid:image001.png@01D233CC.E69CB3E0" height="544" width="532"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">Each file include some same named csv data:<u></u><u></u></span></p></div><div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><img id="m_8745908924922340546m_1286360134496254004_x0000_i1026" src="cid:image002.png@01D233CC.E69CB3E0" height="391" width="521"><img id="m_8745908924922340546m_1286360134496254004_x0000_i1027" src="cid:image003.png@01D233CC.E69CB3E0" height="387" width="539"><u></u><u></u></span></p></div></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><u></u> <u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">Can you help me or give me some good idea?<u></u><u></u></span></p></div></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><u></u> <u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">This is my script:<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> <u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">;<br>load "$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/contributed.ncl"<br>begin<br> filename1=systemfunc("ls /public/home/huanglei/cmaqdata<wbr>/2016*/Zhouzhi.csv")<br> ; fin1=addfiles(filename1,"r")<br> ; printVarSummary(filename1)<br> print(filename1)<br> <br> ; exit<br> filenumber =38<br> time_al= new((/filenumber/),string,"No_<wbr>FillValue")<br> oth_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> xa_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> tc_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> bj_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> xy_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> wn_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> ya_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> hz_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> yl_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> ak_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> sl_al = new((/filenumber/),float,"No_F<wbr>illValue")<br> <br> do i=0,filenumber-1<br> <br> ;---Read in file as array of strings so we can parse each line.<br> ; printVarSummary(filename1(2))<br> lines = asciiread(filename1(i),-1,"str<wbr>ing")<br> nlines = dimsizes(lines)-1 ; First line is a header<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> ;<br> ; Start reading in the fields we care about:<br> ; The first line is a header, so skip this.<br> ;<br> delim = ","<br> time = str_get_field(lines(13:36),1,d<wbr>elim) <br> oth = str_get_field(lines(13:36),2,d<wbr>elim) <br> xa = str_get_field(lines(13:36),3,d<wbr>elim) <br> tc = str_get_field(lines(13:36),4,d<wbr>elim) <br> bj = str_get_field(lines(13:36),5,d<wbr>elim) <br> xy = str_get_field(lines(13:36),6,d<wbr>elim) <br> wn = str_get_field(lines(13:36),7,d<wbr>elim) <br> ya = str_get_field(lines(13:36),8,d<wbr>elim)<br> hz = str_get_field(lines(13:36),9,d<wbr>elim) <br> yl = str_get_field(lines(13:36),10,<wbr>delim) <br> ak = str_get_field(lines(13:36),11,<wbr>delim) <br> sl = str_get_field(lines(13:36),12,<wbr>delim)<br> ; print(time)<br> ; exit<br> ; time_al(i,:)= time <br> ; print(time_al(i,:))<br> oth_al(i) =sum(stringtofloat(oth)) <br> xa_al(i) = sum(stringtofloat(xa)) <br> tc_al(i) = sum(stringtofloat(tc)) <br> bj_al(i) = sum(stringtofloat(bj)) <br> xy_al(i) = sum(stringtofloat(xy)) <br> wn_al(i) = sum(stringtofloat(wn)) <br> ya_al(i) = sum(stringtofloat(ya)) <br> hz_al(i) = sum(stringtofloat(hz)) <br> yl_al(i) = sum(stringtofloat(yl)) <br> ak_al(i) = sum(stringtofloat(ak)) <br> sl_al(i) = sum(stringtofloat(sl)) <br> ; print(oth_al(i)) <br> ;exit<br> end do<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> ; time_all=ndtooned(time_al)<br> oth_all=ndtooned(oth_al)<br> xa_all=ndtooned(xa_al)<br> tc_all=ndtooned(tc_al)<br> bj_all=ndtooned(bj_al)<br> xy_all=ndtooned(xy_al)<br> wn_all=ndtooned(wn_al)<br> ya_all=ndtooned(ya_al)<br> hz_all=ndtooned(hz_al)<br> yl_all=ndtooned(yl_al) <br> ak_all=ndtooned(ak_al)<br> sl_all=ndtooned(sl_al) <u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><br> print(oth_all)<br> ; exit<br> ; calculate the avg<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> oth_avg=avg(oth_all)<br> xa_avg=avg(xa_all)<br> tc_avg=avg(tc_all)<br> bj_avg=avg(bj_all)<br> xy_avg=avg(xy_all)<br> wn_avg=avg(wn_all)<br> ya_avg=avg(ya_all)<br> hz_avg=avg(hz_all)<br> yl_avg=avg(yl_all) <br> ak_avg=avg(ak_all)<br> sl_avg=avg(sl_all)<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> ssx = hz_avg + ak_avg + sl_avg<br> nsx = ya_avg + yl_avg<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> print("oth="+oth_avg)<br> print("xa="+xa_avg)<br> print("tc="+tc_avg)<br> print("bj="+bj_avg)<br> print("xy="+xy_avg)<br> print("wn="+wn_avg)<br> print("ssx="+ssx)<br> print("nsx="+nsx)<br> title = new((/8/),string,"No_FillValue<wbr>")<br> title =(/"xa","xy","wn","bj","tc","n<wbr>sx","ssx","oth"/)<br> data = new((/8/),float,"No_FillValue"<wbr>)<br> data =(/xa_avg,xy_avg,wn_avg,bj_avg<wbr>,tc_avg,nsx,ssx,oth_avg/) <br> print(data)<br> ;staname="changan"<br> output_file="/public/home/huan<wbr>glei/cmaqdata/final_data/zhouz<wbr>hi.txt"<br> write_table(output_file,"w",[/<wbr>title,data/],"%s%9.5f")<br>end<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> <u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"><u></u> <u></u></span></p></div><div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif">My NCL version is 6.2.0.<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:17.25pt"><span style="font-family:"Verdana",sans-serif"> How can I slove the problem?<u></u><u></u></span></p></div></div></div></div></div></div><br></div></div>______________________________<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" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<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/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>