[SAC-HELP] SAC reading binary files

Philip Crotwell crotwell at seis.sc.edu
Mon Jul 28 07:46:31 PDT 2008


The attached files work for reading/writing in C without using the sac library.

Philip

On Fri, Jul 25, 2008 at 5:17 PM, Ryan P Cary <RPCary at lbl.gov> 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
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sac.h
URL: <http://www.iris.washington.edu/pipermail/sac-help/attachments/20080728/b86be7f6/attachment.h>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: readsac.c
URL: <http://www.iris.washington.edu/pipermail/sac-help/attachments/20080728/b86be7f6/attachment.c>


More information about the sac-help mailing list