[ncl-talk] adding Cmorph binary files

Mary Haley haley at ucar.edu
Mon Jan 25 15:29:44 MST 2016


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160125/9fc6b486/attachment.html 


More information about the ncl-talk mailing list