Converting binary data to ascii

Thiago Veloso thi_veloso at YAHOO.COM.BR
Mon May 18 10:17:57 EDT 2009


  Dear Chuck,

  I've just tested and your tip helped me. The script worked like a charm after including the 'c events' command.

  Thank you very much!

  Best,

  Thiago.

--- On Fri, 15/5/09, Charles Seman <Charles.Seman at noaa.gov> wrote:

From: Charles Seman <Charles.Seman at noaa.gov>
Subject: Re: Converting binary data to ascii
To: thi_veloso at yahoo.com.br
Date: Friday, 15 May, 2009, 1:38 PM

Dear Thiago,

Perhaps it may help if you add a 'c events' in your script as follows:
       'c events'
       x=x+1
     endwhile
     y=y+1
   endwhile
   t=t+1
 endwhile

In a local script here, a test in which the 'c events' command was commented out (code segment show below) generated a "Segmentation fault" message:
*  'c events'
 xx = xx+1
endwhile
 yy = yy+1
endwhile
 zz = zz+1
endwhile
 tt = tt+1
endwhile

I hope this helps,
Chuck

Thiago Veloso wrote:
>  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
> 
> 

-- 
Please note that Charles.Seman at noaa.gov should be considered my NOAA
email address, not cjs at gfdl.noaa.gov.

********************************************************************
Charles Seman                                Charles.Seman at noaa.gov
U.S. Department of Commerce / NOAA / OAR
Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
201 Forrestal Road                              fax: (609) 987-5063
Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
********************************************************************

"The contents of this message are mine personally and do not necessarily
reflect any position of the Government or NOAA."




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20090518/fde3a98f/attachment.html 


More information about the gradsusr mailing list