[SAC-HELP] SAC reading binary files

Chad Trabant chad at iris.washington.edu
Mon Jul 28 09:26:49 PDT 2008


Hi Ryan,

The sac2mseed converter does not use the SAC library, you'll find the C source 
code here:

http://www.iris.edu/pub/programs/converters/

cheers,
Chad

Ryan P Cary wrote:
> Hi,
>   I am attempting to read in sac binary files without using the rsac1 routine in c. My goal is to get the floating point amplitudes into an array, and I am having trouble understanding the correct binary offset in the sac files to get to the amplitudes. The online sac manual states that the "FIRST DATA SECTION" starts at word 158, implying that the following c code should work:
> 
> FILE * f;
> float fx;
> int i;
> 
> f=fopen("83.0325.22.27.33.RED.4.sac","r");   
> 
> fseek(f, 54,SEEK_SET);//jump 54 bytes
> for (i=0; i < 200; i++)   
> {                   
> 
>          fread(&fx,sizeof(float),1,f);     
> 
>          printf("%f\n",fx);   
> 
> }   
> 
> However this seems to print junk data; I can validate what should be printed by calling rsac1.
> 
> So my questions for you are:
> 
> 1.  What is the correct offset to read in amplitudes?
> 2.  What (if any) is the spacing between the data? I ask because the manual page mentions "contents:
> 
>     * dependent variable
>     * amplitude
>     * real component "
> 
> but I can't find any description on the ordering/structur/size in bytes of these data.
> 
> 
> Thank you in advance for your effort,
> 
> -Ryan Cary
> 
> _______________________________________________
> sac-help mailing list
> sac-help at iris.washington.edu
> http://www.iris.washington.edu/mailman/listinfo/sac-help
> 




More information about the sac-help mailing list