[ncl-talk] adding Cmorph binary files

Mary Haley haley at ucar.edu
Tue Jan 26 09:03:09 MST 2016


The error message from write_table is telling you exactly what the problem
is:

fatal:Argument type mismatch on argument (2) of (write_table) can not coerce

If you look at the write_table documentation:

http://www.ncl.ucar.edu/Document/Functions/Built-in/write_table.shtml

Argument 2 (argument count starts at 0) is the "alist" argument, which must
be a list. This means you have to surround the variable with "[/" and "/]".
See the examples section in the above link.

--Mary


On Tue, Jan 26, 2016 at 6:30 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:

> Hi Mary.
>
> Thanks.
> The lines,  outfile  = "cmorph"
> ;       outfile  =  outfile+0+".txt"
> ;       drf      = "cmori"
> ;       drf      =  drf+0+".txt"
>
> were added to write the data in each file separately. I wanted to check if
> the addition of the data is taking place. I got 24 files by the name of
> cmorph0.txt
> cmorph10.txt
> cmorph11.txt
> cmorph12.txt
> cmorph13.txt
> cmorph14.txt
> cmorph15.txt
> cmorph16.txt
> cmorph17.txt
> cmorph18.txt
> cmorph19.txt
> cmorph1.txt
> cmorph20.txt
> cmorph21.txt
> cmorph22.txt
> cmorph23.txt
>
>
>  actually I have to add the data (cmorph rainfall) corresponding to 24
> files and make it as a daily data.
>
> So I have converted 4 dim variable (cmorrf, the dimensions being file
> number, ntime, lat, lon) into one dimension (cmor1d) using ndtooned
> function. then each 1 dim variable I was trying to add using a do loop.
> I dont know how to define a NULL array (1 dimensional).
>
> Secondly, I could not use the write_table function. I was getting the
> following error...
>
> Variable: cmorrf
> Type: float
> Total Size: 783288192 bytes
>             195822048 values
> Number of Dimensions: 4
> Dimensions and sizes: [24] x [1] x [1649] x [4948]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue : 9.96921e+36
> fatal:Argument type mismatch on argument (2) of (write_table) can not
> coerce
> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 70 in
> file cmorph-daily-v2.ncl
>
> Thanks again
>
>
> On Tuesday, 26 January 2016 3:59 AM, Mary Haley <haley at ucar.edu> wrote:
>
>
> There are a few issues with your script.
>
> [1]
>        do n     =  0, no_of_files
> Shouldn't this be:
>        do n     =  0, no_of_files-1
> [2] I don't understand this part:
>      outfile  = "cmorph"
>      outfile  =  outfile+0+".txt"
>      drf      = "cmori"
>      drf      =  drf+0+".txt"
> Are the "0" supposed to be "n"?
> [3]
>    rf =  fbindirread(files(0),0,(/ntim,nlat,nlon/),"ubyte")
> Shouldn't this be:
>    rf =  fbindirread(files(n),0,(/ntim,nlat,nlon/),"ubyte")
>
>                           ^^^
> [4]  Why do you want to write the values to an ASCII files?  And, if you
> are going to do this, why use asciiwrite?  This writes one value per line
> which is extremely inefficient. Really, writing any kind of ASCII file is
> not ideal for large files. You should probably look at using "write_table"
> which at least allows for multiple values per line.
> [5]
> You are calling "asciiwrite" inside the do loop, with the same output
> filename. This is going to cause the output file to get overwritten each
> time, and not appended to.
> If you have enough memory, then I would create "rf" outside the loop so
> that it has an extra leftmost dimension of size no_of_files, and then call
> "asciiwrite" outside the do loop:
>   rf =  new((/no_of_files,ntim,nlat,nlon/),"ubyte")
>   do n =  0, no_of_files
>     rf(n,:,:,:) = fbindirread(files(n),0,(/ntim,nlat,nlon/),"ubyte")
>   end do
>   cmorrf   =  where(rf.eq.255,255,rf*0.2)
>   asciiwrite(outfile,cmorrf)
> If you don't have the memory to do this, then look into using
> "write_table", which allows for appending to an existing file.  See example
> "write_asc_4.ncl" at:
> http://www.ncl.ucar.edu/Applications/o-ascii.shtml
> --Mary
>
>
> On Sun, Jan 24, 2016 at 9:57 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:
>
> I have to add the 24 binary rainfall files (cmorph) and get one rainfall
> variable that has 24 hours data.
>
> Following the part of the script used for reading the rainfall.
>
>
> ; ----Defining for Once -----
>
>   wks         = gsn_open_wks("ps","cmorph-v2")
>                 gsn_define_colormap(wks,"prcp_2")
>
>   plot        = new(24,graphic)
>
>     files        =   systemfunc("ls CMORPH_8KM-30MIN_20151130*")
> ;                      print(files)
> ;                      print(files(0))
>     no_of_files  =   dimsizes(files)
>                       print(no_of_files)
>
>    ntim        =  1
>    nlat        =  1649
>    nlon        =  4948
>
>   lat         = 59.963614 - ispan(0,nlat-1,1)*0.072771377
>   lat!0       = "latitude"
>   lat at units   = "degrees_north"
> ;                printVarSummary(lat)
> ;                 print(lat)
>
>   lon         = 0.036378335 + ispan(0,nlon-1,1)*0.072756669
>   lon!0       = "longitude"
>   lon at units   = "degrees_east"
> ;                 printVarSummary(lon)
> ;                   print(lon)
> ; Reading File-----------------
>
>         cmordaily= new(8159252,float,255)
>                    printVarSummary(cmordaily)
>
>
>        do n     =  0, no_of_files
>        outfile  = "cmorph"
>        outfile  =  outfile+n+".txt"
>        drf      = "cmori"
>        drf      =  drf+n+".txt"
>
>        rf       =  fbindirread(files(0),0,(/ntim,nlat,nlon/),"ubyte")
>                      printVarSummary(rf)
>
> ;    temp        =   str_split(files(n),"_")  ; For date of the data file
> ;    date_time   =   temp(1)+temp(2)
> ;                     print(date_time)
> ;  date_time!0   =   "time"
>
>
>    cmorrf               =  where(rf.eq.255,255,rf*0.2)
>                                printVarSummary(cmorrf)
>    cmorrf at units         = "mm"
>    cmorrf at _FillValue    = 255
>                               asciiwrite(outfile,cmorrf)
>
>    cmor1d               =   ndtooned(cmorrf)
>                             asciiwrite("cmor1d_after1d.txt",cmor1d)
>                               printVarSummary(cmor1d)
>
>   cmordaily      = cmor1d+cmordaily
> ;  cmordaily at _FillValue  = 255
>                    asciiwrite(drf,cmordaily)
>
>
>
> I am not getting getting the data added in the last file.
> I am attaching the cmordaily files.
> Following files are created
> -rw-rw-r-- 1 aditya aditya      3635 Jan 24 22:08 cmorph-daily.ncl
> -rw-rw-r-- 1 aditya aditya  25048562 Jan 24 22:11 cmorph0.txt
> -rw-rw-r-- 1 aditya aditya  25048562 Jan 24 22:11 cmor1d_after1d.txt
> -rw-rw-r-- 1 aditya aditya  32637008 Jan 24 22:12 cmori0.txt
>
> cmori0.txt file has only 8199252 values each equal to 255.
> can someone suggest...
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
>
> _______________________________________________
> 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/20160126/bc38e4cc/attachment.html 


More information about the ncl-talk mailing list