[ncl-talk] adding Cmorph binary files

Geeta Geeta geetag54 at yahoo.com
Tue Jan 26 06:30:35 MST 2016


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.txtcmorph10.txtcmorph11.txtcmorph12.txtcmorph13.txtcmorph14.txtcmorph15.txtcmorph16.txtcmorph17.txtcmorph18.txtcmorph19.txtcmorph1.txtcmorph20.txtcmorph21.txtcmorph22.txtcmorph23.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: cmorrfType: floatTotal Size: 783288192 bytes            195822048 valuesNumber of Dimensions: 4Dimensions and sizes: [24] x [1] x [1649] x [4948]Coordinates: Number Of Attributes: 1  _FillValue : 9.96921e+36fatal:Argument type mismatch on argument (2) of (write_table) can not coercefatal:["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_filesShouldn'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/20160126/e2c339d5/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmorph-daily-v2.ncl
Type: application/octet-stream
Size: 3909 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160126/e2c339d5/attachment.obj 


More information about the ncl-talk mailing list