[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.

grace 313695096 at qq.com
Mon Oct 31 21:06:25 MDT 2016


Hi:
   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 :
 

  fatal:Dimension sizes of left hand side and right hand side of assignment do not match
fatal:["Execute.c":8567]:Execute: Error occurred at or near line 45 in file csv_read.ncl

 


 The line 45 is   '  lines  = asciiread(filename1(i),-1,"string")'   ........
 .........
 ........
 But when I try to read only one csv data,the script can work out.
 I don't know how to fix this,can you guys help me?
 My csv date stored like this:
  
 Each file include some same named  csv data:
  

 

 Can you  help me or give me some good idea?

 

 This is my script:
  
 ;
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
 filename1=systemfunc("ls /public/home/huanglei/cmaqdata/2016*/Zhouzhi.csv")
  ;   fin1=addfiles(filename1,"r")
    ; printVarSummary(filename1)
     print(filename1)
 
 ; exit
     filenumber =38
     time_al= new((/filenumber/),string,"No_FillValue")
     oth_al = new((/filenumber/),float,"No_FillValue")
     xa_al  = new((/filenumber/),float,"No_FillValue")
     tc_al  = new((/filenumber/),float,"No_FillValue")
     bj_al  = new((/filenumber/),float,"No_FillValue")
     xy_al  = new((/filenumber/),float,"No_FillValue")
     wn_al  = new((/filenumber/),float,"No_FillValue")
     ya_al  = new((/filenumber/),float,"No_FillValue")
     hz_al  = new((/filenumber/),float,"No_FillValue")
     yl_al  = new((/filenumber/),float,"No_FillValue")
     ak_al  = new((/filenumber/),float,"No_FillValue")
     sl_al  = new((/filenumber/),float,"No_FillValue")
    
  do i=0,filenumber-1
            
          ;---Read in file as array of strings so we can parse each line.
     ; printVarSummary(filename1(2))
       lines  = asciiread(filename1(i),-1,"string")
       nlines = dimsizes(lines)-1   ; First line is a header
     ;
    ; Start reading in the fields we care about:
    ; The first line is a header, so skip this.
    ;
      delim     = ","
      time = str_get_field(lines(13:36),1,delim)  
      oth  = str_get_field(lines(13:36),2,delim)  
      xa   = str_get_field(lines(13:36),3,delim)  
      tc   = str_get_field(lines(13:36),4,delim)  
      bj   = str_get_field(lines(13:36),5,delim)  
      xy   = str_get_field(lines(13:36),6,delim)  
      wn   = str_get_field(lines(13:36),7,delim)  
      ya   = str_get_field(lines(13:36),8,delim)
      hz   = str_get_field(lines(13:36),9,delim)  
      yl   = str_get_field(lines(13:36),10,delim)  
      ak   = str_get_field(lines(13:36),11,delim)  
      sl   = str_get_field(lines(13:36),12,delim)
            ;  print(time)
            ;   exit
                         ; time_al(i,:)= time  
      ;     print(time_al(i,:))
                         oth_al(i) =sum(stringtofloat(oth))  
                         xa_al(i)  = sum(stringtofloat(xa))  
                         tc_al(i)  = sum(stringtofloat(tc))  
                         bj_al(i)  = sum(stringtofloat(bj))  
                         xy_al(i)  = sum(stringtofloat(xy))  
                         wn_al(i)  = sum(stringtofloat(wn))  
                         ya_al(i)  = sum(stringtofloat(ya))  
                         hz_al(i)  = sum(stringtofloat(hz))  
                         yl_al(i)  = sum(stringtofloat(yl))  
                         ak_al(i)  = sum(stringtofloat(ak))  
                         sl_al(i)  = sum(stringtofloat(sl)) 
        ;  print(oth_al(i))     
        ;exit
         end do
                         ;  time_all=ndtooned(time_al)
                          oth_all=ndtooned(oth_al)
                          xa_all=ndtooned(xa_al)
                          tc_all=ndtooned(tc_al)
                          bj_all=ndtooned(bj_al)
                          xy_all=ndtooned(xy_al)
                          wn_all=ndtooned(wn_al)
                          ya_all=ndtooned(ya_al)
                          hz_all=ndtooned(hz_al)
                          yl_all=ndtooned(yl_al)  
                          ak_all=ndtooned(ak_al)
                          sl_all=ndtooned(sl_al) 
 
         print(oth_all)
 ;   exit
  ; calculate the avg
                           oth_avg=avg(oth_all)
                          xa_avg=avg(xa_all)
                          tc_avg=avg(tc_all)
                          bj_avg=avg(bj_all)
                          xy_avg=avg(xy_all)
                          wn_avg=avg(wn_all)
                          ya_avg=avg(ya_all)
                          hz_avg=avg(hz_all)
                          yl_avg=avg(yl_all)  
                          ak_avg=avg(ak_all)
                          sl_avg=avg(sl_all)
                           ssx = hz_avg + ak_avg + sl_avg
                          nsx = ya_avg + yl_avg
                          print("oth="+oth_avg)
                         print("xa="+xa_avg)
                         print("tc="+tc_avg)
                         print("bj="+bj_avg)
                         print("xy="+xy_avg)
                         print("wn="+wn_avg)
                         print("ssx="+ssx)
                         print("nsx="+nsx)
                  title  = new((/8/),string,"No_FillValue")
                  title =(/"xa","xy","wn","bj","tc","nsx","ssx","oth"/)
                  data = new((/8/),float,"No_FillValue")
                  data =(/xa_avg,xy_avg,wn_avg,bj_avg,tc_avg,nsx,ssx,oth_avg/)  
                  print(data)
                  ;staname="changan"
                  output_file="/public/home/huanglei/cmaqdata/final_data/zhouzhi.txt"
                 write_table(output_file,"w",[/title,data/],"%s%9.5f")
end

  

 

  My NCL version is 6.2.0.
  How can I slove the problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/58731751/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 14613 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/58731751/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 14372 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/58731751/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 13876 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/58731751/attachment-0002.obj 


More information about the ncl-talk mailing list