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

Luke Osburn luke.osburn at monash.edu
Mon Oct 31 21:32:53 MDT 2016


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.

Direclty before: '  lines  = asciiread(filename1(i),-1,"string")'
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.

On 1 November 2016 at 14:17, Yuqiang Zhang <yuqiangzhang.thu at gmail.com>
wrote:

> Try this “lines  := asciiread(filename1(i),-1,"string")'  ”
>
> That happens when you read different files, and they have different length
> for each file.
>
>
>
> *From:* ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] *On
> Behalf Of *grace
> *Sent:* Monday, October 31, 2016 11:06 PM
> *To:* ncl-talk <ncl-talk at ucar.edu>
> *Subject:* [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.
>
>
>
> 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?
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/617bc26f/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 13876 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/617bc26f/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 14372 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/617bc26f/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 14613 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161101/617bc26f/attachment-0002.png 


More information about the ncl-talk mailing list