[SAC-HELP] SAC reading binary files

Ryan P Cary RPCary at lbl.gov
Fri Jul 25 14:17:42 PDT 2008


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




More information about the sac-help mailing list