libsacio  1.0.2
Seismic Analysis Code I/O Library
Macros | Functions
sacio.c File Reference

sac I/O and manipulation More...

Macros

#define ERROR_NOT_A_SAC_FILE   1317
 Not a sac file.
 
#define ERROR_OVERWRITE_FLAG_IS_OFF   1303
 Overwrite flag, lovrok is set to 0.
 
#define ERROR_WRITING_FILE   115
 Error writing sac file.
 
#define ERROR_READING_FILE   114
 Error reading sac file.
 
#define ERROR_FILE_DOES_NOT_EXIST   108
 Error file does not exist.
 
#define ERROR_OPENING_FILE   101
 Error opening sac file.
 
#define SAC_OK   0
 Success, everything is ok.
 
#define SAC_HEADER_SIZEOF_NUMBER   (sizeof(float))
 Size of header values in bytes.
 
#define SAC_DATA_SIZE   SAC_HEADER_SIZEOF_NUMBER
 Size of data values in bytes.
 
#define SAC_HEADER_VERSION_6   6
 Sac version no 6.
 
#define SAC_HEADER_VERSION_7   7
 Sac version no 7.
 
#define SAC_HEADER_MAJOR_VERSION   SAC_HEADER_VERSION_6
 Current Major sac version number.
 
#define SAC_HEADER_MAX_VERSION   SAC_HEADER_VERSION_7
 Current Maximum sac version number.
 
#define SAC_VERSION_LOCATION   76
 Offset in 4-byte words of the header version.
 
#define MIN(a, b)   ((a < b) ? a : b )
 Minimum of two values.
 
#define MAX(a, b)   ((a > b) ? a : b )
 Maximum of two values.
 
#define B(s)   sac_float(s, SAC_B)
 Get begin value.
 
#define E(s)   sac_float(s, SAC_E)
 Get end value.
 
#define DT(s)   sac_float(s, SAC_DELTA)
 Get delta time value.
 
#define SAC_HEADER_FLOATS   70 /* 4 bytes (real or float) */
 
#define SAC_HEADER_INTEGERS   15
 
#define SAC_HEADER_ENUMS   20
 
#define SAC_HEADER_LOGICALS   5
 
#define SAC_HEADER_STRINGS   24 /* 9 bytes (characters) actually 23 + 1 */
 
#define SAC_HEADER_NUMBERS   ( SAC_HEADER_FLOATS + SAC_HEADER_INTEGERS + SAC_HEADER_ENUMS + SAC_HEADER_LOGICALS )
 
#define X(name, key)   z->key = SAC_FLOAT_UNDEFINED;
 X-Macro for sac_f64_new() More...
 
#define X(name, key)   case SAC_##name: s->h->key = (float) value; break;
 X-Macro for sac_f64_new() More...
 
#define X(name, key)   case SAC_##name: s->z->key = value; s->h->key = (float) value; break;
 X-Macro for sac_f64_new() More...
 
#define X(name, key)   case SAC_##name: *v = s->h->key; break;
 X-Macro for sac_f64_new() More...
 
#define X(name, key)   case SAC_##name: *v = s->z->key; break;
 X-Macro for sac_f64_new() More...
 
#define X(name, key)   s->h->key = (float) s->z->key;
 X-Macro for sac_f64_new() More...
 
#define X(name, key)   s->z->key = s->h->key;
 X-Macro for sac_f64_new() More...
 
#define COPY_MOVE(dst, src, n)
 
#define SAC_ALPHA_FLOAT_LINES   14
 
#define SAC_ALPHA_INT_LINES   8
 
#define SAC_ALPHA_STRING_LINES   8
 
#define SAC_ALPHA_FLOAT_FMT   "%#15.7g"
 
#define SAC_ALPHA_INT_FMT   "%10d"
 
#define SAC_ALPHA_STRING_FMT   "%8s"
 
#define SAC_ALPHA_DOUBLE_FMT   "%.17g"
 
#define SAC_HEADER_SIZE   632
 Size of header.
 
#define X(name, key)   SAC_##name ,
 X-Macro for sac_f64_new() More...
 
#define START_BEFORE   1<<0
 Start Time is before Begin value (B)
 
#define START_INSIDE   1<<1
 Start Time is between Begin (B) and End Value (E)
 
#define START_AFTER   1<<2
 Start Time is after End value (E)
 
#define END_BEFORE   1<<3
 End Time is before Start time (B)
 
#define END_INSIDE   1<<4
 End Time is between Begin (B) and End Value (E)
 
#define END_AFTER   1<<5
 End Time is after End Value (E)
 

Functions

void sac_write_alpha (sac *s, char *filename, int *nerr)
 Write a sac file in alpha-numeric format. More...
 
sacsac_read_alpha (char *filename, int *nerr)
 Read a alpha-numeric sac file. More...
 
sacsac_cut (sac *sin, char *c1, double t1, char *c2, double t2, enum CutAction cutact, int *nerr)
 cut a sac file More...
 

Detailed Description

sac I/O and manipulation

Macro Definition Documentation

◆ COPY_MOVE

#define COPY_MOVE (   dst,
  src,
 
)
Value:
do { \
memcpy(dst, src, n); \
dst[n] = 0; \
src += n; \
dst += (n+1); \
} while(0) ;

◆ SAC_HEADER_ENUMS

#define SAC_HEADER_ENUMS   20
Parameters
SAC_HEADER_ENUMSNumber of Enumerated values in the SAC Header Size: SAC_HEADER_SIZEOF_NUMBER bytes

◆ SAC_HEADER_FLOATS

#define SAC_HEADER_FLOATS   70 /* 4 bytes (real or float) */
Parameters
SAC_HEADER_FLOATSNumber of Floating point values in the SAC Header Size: SAC_HEADER_SIZEOF_NUMBER bytes

◆ SAC_HEADER_INTEGERS

#define SAC_HEADER_INTEGERS   15
Parameters
SAC_HEADER_INTEGERSNumber of Integer values in the SAC Header Size: SAC_HEADER_SIZEOF_NUMBER bytes

◆ SAC_HEADER_LOGICALS

#define SAC_HEADER_LOGICALS   5
Parameters
SAC_HEADER_LOGICALSNumber of Logical values in the SAC Header Size: SAC_HEADER_SIZEOF_NUMBER bytes

◆ SAC_HEADER_NUMBERS

Parameters
SAC_HEADER_NUMBERSNumber of numeric values in the SAC Header Size: SAC_HEADER_SIZEOF_NUMBER bytes

◆ SAC_HEADER_STRINGS

#define SAC_HEADER_STRINGS   24 /* 9 bytes (characters) actually 23 + 1 */
Parameters
SAC_HEADER_STRINGSNumber of strings in the SAC Header. The number here is in reality one less as the number below as of header version 6. The second value, the event name is twice as long as any other characer string

◆ X [1/8]

#define X (   name,
  key 
)    z->key = SAC_FLOAT_UNDEFINED;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [2/8]

#define X (   name,
  key 
)    case SAC_##name: s->h->key = (float) value; break;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [3/8]

#define X (   name,
  key 
)    case SAC_##name: s->z->key = value; s->h->key = (float) value; break;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [4/8]

#define X (   name,
  key 
)    case SAC_##name: *v = s->h->key; break;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [5/8]

#define X (   name,
  key 
)    case SAC_##name: *v = s->z->key; break;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [6/8]

#define X (   name,
  key 
)    s->h->key = (float) s->z->key;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [7/8]

#define X (   name,
  key 
)    s->z->key = s->h->key;

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

◆ X [8/8]

#define X (   name,
  key 
)    SAC_##name ,

X-Macro for sac_f64_new()

X-Macro for sac_f32_new()

Function Documentation

◆ sac_cut()

sac* sac_cut ( sac sin,
char *  c1,
double  t1,
char *  c2,
double  t2,
enum CutAction  cutact,
int *  nerr 
)

cut a sac file

cut a sac file and return a new sac file

Parameters
sinsac file
c1reference time pick for start time
t1relative time from c1
c2reference time pick for end time
t2relative time from c2
cutactBehavior of cut
  • CutNone = 0
  • CutFatal = 1
  • CutUseBe = 2
  • CutFillZero = 3
nerrstatus code
  • 0 on success
  • Might be non-zero when using CutUseBE
Returns
newly cut sac file
Note
Time pick reference
  • "Z" - Actual time
  • "B" - Begin time
  • "E" - End time
  • "O" - Origin time
  • "A" - First arrival time
  • "F" - Final arrival time: SAC_F value
  • "T0" to "T9" - t0 to t9 arrival times

Example of cutting a sac file

int nerr = 0;
double b = 0, e = 0;
sac *cut = NULL;
sac *s = sac_read("t/test_io_small.sac", &nerr);
assert_eq(nerr, 0);
// Cut the sac file, returning a new file
cut = sac_cut(s, "Z", 10.0, "Z", 30.0, CutUseBE, &nerr);
sac_get_float(cut, SAC_B, &b);
sac_get_float(cut, SAC_E, &e);
assert_eq(b, 10.0);
assert_eq(e, 30.0);

◆ sac_read_alpha()

sac* sac_read_alpha ( char *  filename,
int *  nerr 
)

Read a alpha-numeric sac file.

Read a sac file in alpha-numeric format

Parameters
filenamealpha numeric sac file to read from
nerrerror status code
Returns
sac file, NULL on error

Example of reading an alpha-numeric sac file

int nerr = 0;
sac *s = sac_read_alpha("t/test_spec_alpha.sac", &nerr);
assert_eq(nerr, 0);
assert_ne(s, NULL);

Reading a non-existant file returns a NULL pointer and nerr is set to 101

int nerr = 0;
sac *s = sac_read_alpha("non-existant-file", &nerr);
assert_eq(nerr, 101);
assert_eq(s, NULL);

Reading a file that is not a alpha-numeric file returns a NULL pointer and nerr is set to 1319

int nerr = 0;
sac *s = sac_read_alpha("t/test_io_small.sac", &nerr);
assert_eq(nerr, 1319);
assert_eq(s, NULL);

◆ sac_write_alpha()

void sac_write_alpha ( sac s,
char *  filename,
int *  nerr 
)

Write a sac file in alpha-numeric format.

Write a sac file into an alpha-numeric format

Parameters
ssac file to write
filenamefile to write to
nerrerror status code
int nerr = 0;
sac *s = sac_read("t/test_io_small.sac", &nerr);
assert_eq(nerr, 0);
// Write the sac file into alpha-numeric format
sac_write_alpha(s, "t/test_io_small_alpha.sac.tmp", &nerr);
assert_eq(nerr, 0);