Converting binary data to ascii

Thiago Veloso thi_veloso at YAHOO.COM.BR
Fri May 15 08:57:12 EDT 2009


 Dear all,
 
 I have a relatively long (6-year) series of sattelite-based hourly precipitation estimates, which is in binary format. Considering I need to manipulate this data on external programs, I'm trying to extract it to ascii files.

 
 Currently I´m using GrADS v1.9b4 running on a ordinary 32-bit desktop Ubuntu 9.04. Some years ago a colleague (now retired) developed a script which used to work in out previous datasets. But it won't work with these specific precipitation estimates files (maybe due to the enormous volume). GrADS suddenly crashes with an "segmentation fault" error message.

 Would anybody gently help me to identify what is causing the error? Following is the script code...

 Thanks in advance.

   'reinit'; 'c';
 
   prompt 'Variable: '; pull var
   prompt 'Latitude  (lat1 lat2): '; pull lat
   prompt 'Longitude (lon1 lon2): '; pull lon
   prompt 'Tempo (t1 t2): '; pull t
 
   'open /usr/local/grads-1.9b4/lib/CMORPH_8km-30-minute.ctl'
 
  ' set lat 'lat; 'set lon 'lon; 'set t 't;
 
  'q dims'; x=sublin(result,2); y=sublin(result,3); t=sublin(result,5);
  x1=subwrd(x,11); y1=subwrd(y,11); t1=subwrd(t,11); 
  x2=subwrd(x,13); y2=subwrd(y,13); t2=subwrd(t,13);
 
  if(x2=''); x1=subwrd(x, 9); x2=x1; endif 
  if(y2=''); y1=subwrd(y, 9); y2=y1; endif 
  if(t2=''); t1=subwrd(t, 9); t2=t1; endif
 
  x=x1; xmax=x2; y=y1; ymax=y2; t=t1; tmax=t2;
 
 
 lixo=write(var'.txt', 'lon     lat    lev    time    'r)
 
 while (t<=tmax)
 
    'set t 't; y=y1;
 
    while (y<=ymax)
 
      'set y 'y; x=x1;
 
      while(x<=xmax)
 
        'set x 'x; 'set t 't; 
 
        r1=xyzt(); 
 
       'd 'var; r=subwrd(result, 4);
 
        lixo=write(var'.txt', r1%r,append);
        x=x+1
      endwhile
      y=y+1
    endwhile
    t=t+1
  endwhile
  say ' End of Process!'
 
 
 
  function xyzt()
    'q dims'; x=sublin(result,2); y=sublin(result,3); z=sublin(result,4); t=sublin(result,5);
    x=subwrd(x,6); y=subwrd(y,6); z=subwrd(z,6); t=subwrd(t,6);
  return(x'    'y'    'z'    't'    ')
 
  function countwrd(x)
    i=0
    while (subwrd(x,i+1)!='')
      i=i+1;
    endwhile
  return(i)
 
  function openfile(arq)
    'open 'arq; r=sublin(result,2);
    if subwrd(r,2)='Error'
      'sdfopen 'arq;
    endif
  return




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20090515/9f9e3049/attachment.html 


More information about the gradsusr mailing list