[SAC-HELP] Fwd: How to tell the endianness of a sac file

Kuang He icrazy at gmail.com
Fri Sep 5 22:49:45 PDT 2008


> Ying Cal
> There is currently no easy way to check the endianness of a sac file
> directly, but
>
> What you can do is something like
> % od -j 304 -N 4 -t d4  sacfile
> 0000460                 6
> 0000464
>
> % od -j 304 -N 4 -t d4  sacfile.swap
> 0000460         100663296
> 0000464
>
> It outputs the header version number, which should be 6.  If it is
> not 6 (100663296 or anything else)
> then you either have a byte swapped  sac file or the file is not a
> sacfile.  This will only tell you if
> the file you are looking at is the same endianness as your system.

Together with the little program below (which was take from the C
FAQ), we are able to tell the endianness of the sac file! :-)

/*
 * Determine whether an Operating System is big-endian or little endian
 */

#include <stdio.h>

int main()
{
  int x = 1;

  printf("This computer is ");
  if(*(char *)&x == 1)
      printf("little-endian\n");
  else
      printf("big-endian\n");

  return 0;
}


Best regards,

--
Kuang He
Department of Physics
University of Connecticut
Storrs, CT 06269-3046

Tel: +1.860.486.4919
Web: http://www.phys.uconn.edu/~he/

> The current version of SAC (v101.1) can read and write both types of
> sac files.
>
> Cheers,
> Brian



More information about the sac-help mailing list