<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><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,"string")' </span><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>”<o:p></o:p></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. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></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'> ncl-talk-bounces@ucar.edu [mailto:ncl-talk-bounces@ucar.edu] <b>On Behalf Of </b>grace<br><b>Sent:</b> Monday, October 31, 2016 11:06 PM<br><b>To:</b> ncl-talk <ncl-talk@ucar.edu><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.<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'>Hi:<o:p></o:p></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 :<o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><o:p> </o:p></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]:Execute: Error occurred at or near line 45 in file csv_read.ncl<o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><o:p> </o:p></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,"string")' ........<o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'>.........<o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'>........<o:p></o:p></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.<o:p></o:p></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?<o:p></o:p></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:<o:p></o:p></span></p></div><div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><img width=532 height=544 id="_x0000_i1025" src="cid:image001.png@01D233CC.E69CB3E0"><o:p></o:p></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:<o:p></o:p></span></p></div><div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><img width=521 height=391 id="_x0000_i1026" src="cid:image002.png@01D233CC.E69CB3E0"><img width=539 height=387 id="_x0000_i1027" src="cid:image003.png@01D233CC.E69CB3E0"><o:p></o:p></span></p></div></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><o:p> </o:p></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?<o:p></o:p></span></p></div></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'>This is my script:<o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'> <o:p></o:p></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/nclscripts/csm/contributed.ncl"<br>begin<br> filename1=systemfunc("ls /public/home/huanglei/cmaqdata/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_FillValue")<br> oth_al = new((/filenumber/),float,"No_FillValue")<br> xa_al = new((/filenumber/),float,"No_FillValue")<br> tc_al = new((/filenumber/),float,"No_FillValue")<br> bj_al = new((/filenumber/),float,"No_FillValue")<br> xy_al = new((/filenumber/),float,"No_FillValue")<br> wn_al = new((/filenumber/),float,"No_FillValue")<br> ya_al = new((/filenumber/),float,"No_FillValue")<br> hz_al = new((/filenumber/),float,"No_FillValue")<br> yl_al = new((/filenumber/),float,"No_FillValue")<br> ak_al = new((/filenumber/),float,"No_FillValue")<br> sl_al = new((/filenumber/),float,"No_FillValue")<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,"string")<br> nlines = dimsizes(lines)-1 ; First line is a header<o:p></o:p></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,delim) <br> oth = str_get_field(lines(13:36),2,delim) <br> xa = str_get_field(lines(13:36),3,delim) <br> tc = str_get_field(lines(13:36),4,delim) <br> bj = str_get_field(lines(13:36),5,delim) <br> xy = str_get_field(lines(13:36),6,delim) <br> wn = str_get_field(lines(13:36),7,delim) <br> ya = str_get_field(lines(13:36),8,delim)<br> hz = str_get_field(lines(13:36),9,delim) <br> yl = str_get_field(lines(13:36),10,delim) <br> ak = str_get_field(lines(13:36),11,delim) <br> sl = str_get_field(lines(13:36),12,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<o:p></o:p></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) <o:p></o:p></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<o:p></o:p></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)<o:p></o:p></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<o:p></o:p></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")<br> title =(/"xa","xy","wn","bj","tc","nsx","ssx","oth"/)<br> data = new((/8/),float,"No_FillValue")<br> data =(/xa_avg,xy_avg,wn_avg,bj_avg,tc_avg,nsx,ssx,oth_avg/) <br> print(data)<br> ;staname="changan"<br> output_file="/public/home/huanglei/cmaqdata/final_data/zhouzhi.txt"<br> write_table(output_file,"w",[/title,data/],"%s%9.5f")<br>end<o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:17.25pt'><span style='font-family:"Verdana",sans-serif'><o:p> </o:p></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.<o:p></o:p></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?<o:p></o:p></span></p></div></div></div></body></html>