libsacio
1.0.2
Seismic Analysis Code I/O Library
|
sac file I/O and manipulation More...
Functions | |
sac * | sac::sac_read (char *filename, int *nerr) |
Read a sac file. More... | |
sac * | sac::sac_read_header (char *filename, int *nerr) |
Read a sac file header. More... | |
void | sac::sac_write (sac *s, char *filename, int *nerr) |
write a sac file to disk More... | |
void | sac::sac_write_header (sac *s, char *filename, int *nerr) |
write a sac header to disk More... | |
int | sac::sac_is_timeval (int hid) |
Identify if a header is a time value. More... | |
int | sac::sac_set_pick (sac *s, int n, double value) |
Set a time pick value. More... | |
int | sac::sac_get_pick (sac *s, int n, double *t) |
Get a timing pick. More... | |
void | sac::sac_set_v7 (sac *s) |
Set the header version to 7. More... | |
void | sac::sac_set_v6 (sac *s) |
Set the header version to 6. More... | |
sac * | sac::sac_new () |
create a new sac file structure More... | |
void | sac::sac_free (sac *s) |
free a sac file structure More... | |
void | sac::sac_alloc (sac *s) |
allocate the sac data portion of a sac strucutre More... | |
void | sac::sac_be (sac *s) |
Set the beginning and end time for a sac file. More... | |
void | sac::sac_header_copy (sac *to, sac *from) |
copy the sac header More... | |
void | sac::sac_meta_copy (sac *to, sac *from) |
copy the sac meta header More... | |
void | sac::sac_data_copy (sac *to, sac *from) |
copy sac data More... | |
sac * | sac::sac_copy (sac *s) |
copy a sac file More... | |
off_t | sac::sac_size (sac *s) |
Get the size of a sac file in bytes. More... | |
int | sac::sac_comps (sac *s) |
Get the number of data components. More... | |
void | sac::sac_extrema (sac *s) |
compute depmin, depmax, and depmen in sac header More... | |
int | sac::sac_time_to_index (sac *s, double t) |
Convert a time to index. More... | |
sac * | sac::sac_read_with_cut (char *filename, char *c1, double t1, char *c2, double t2, enum CutAction cutact, int *nerr) |
read a sac file while cutting More... | |
int | sac::sac_set_string (sac *s, int hdr, char *v) |
Set a character string in a sac file. More... | |
int | sac::sac_get_string (sac *s, int hdr, char *v, size_t n) |
Get a character string from a sac file. More... | |
int | sac::sac_set_float (sac *s, int hdr, double v) |
Set a floating point value in a sac file. More... | |
int | sac::sac_get_float (sac *s, int hdr, double *v) |
Get a floating point value from a sac file. More... | |
int | sac::sac_set_int (sac *s, int hdr, int v) |
Set a integer value in a sac file. More... | |
int | sac::sac_get_int (sac *s, int hdr, int *v) |
Get a integer value from a sac file. More... | |
int | sac::sac_hdr_defined (sac *s,...) |
Check if multiple header values are defined. More... | |
int | sac::sac_get_time_ref (sac *s, timespec64 *t) |
Get the reference time from a sac file. More... | |
int | sac::sac_get_time (sac *s, int hdr, timespec64 *t) |
Get time value from sac file. More... | |
int | sac::sac_set_time (sac *s, timespec64 t) |
int | sac::sac_fmt (char *dst, size_t n, const char *fmt, sac *s) |
format sac values into a string More... | |
sac file I/O and manipulation
enum HeaderID |
Sac Header IDs.
void sac_alloc | ( | sac * | s | ) |
allocate the sac data portion of a sac strucutre
allocate the sac data poriton of a sac structure. The memory size the data and components are determined by sac_comps() and the number of points npts
. Any previous data is freed before allocation
s | sac file to allocate the data for |
Example of creating and allocating space for data in a sac file in memory
void sac_be | ( | sac * | s | ) |
Set the beginning and end time for a sac file.
Set the beginning and end time for a sac file
s | sac file |
int sac_comps | ( | sac * | s | ) |
Get the number of data components.
Get the number of data components: 1 - Evenly spaced time (ITIME), general xy (IXY) or unknown (IUKN), xyz (IXYZ) 2 - Unevenly spcaed time (ITIME), real-imag (IRLIM), amp-phase (IAMPH)
s | sac file |
copy a sac file
copy a sac file: header, meta, and data. This is probably what is usually wanted. This creates a new sac file, copieds the header, meta data, and the actual data.
s | sac file to copy |
copy sac data
copy sac data from one file to another. For data to be successfully copied, the following fields must match:
to | destination |
from | source |
void sac_extrema | ( | sac * | s | ) |
compute depmin, depmax, and depmen in sac header
compute depmin, depmax and depmen value for the sac header report if any of the values are not finite numbers, i.e. inf or nan
s | sac file |
Example of
int sac_fmt | ( | char * | dst, |
size_t | n, | ||
const char * | fmt, | ||
sac * | s | ||
) |
format sac values into a string
format sac values into a string
12.64
. All relative timing uses lowercase characters1994/06/09T00:33:16.123
. All absolute timing uses uppercase characters%N.%S.%H.%C
net.sta.loc.cha%N %S %L %C %TB %TE
similar to a data requestdst | Output character string |
n | Length of dst |
fmt | Formatting string |
s | sac file to get values from |
dst
, -1 on errorExample
void sac_free | ( | sac * | s | ) |
free a sac file structure
free a sac file structure. Free any data components, meta data, header and other associated components
s | sac file struture to free |
Example of creating and freeing a sac file in memory
int sac_get_float | ( | sac * | s, |
int | hdr, | ||
double * | v | ||
) |
Get a floating point value from a sac file.
Get a floating point value from a sac file. If the header version is 6
, values are always from the 32-bit header. If the header version is 7
, values from the 64-bit header are preferred, otherwise the 32-bit header values are used.
s | sac file |
hdr | HeaderID |
v | output floating point value |
int sac_get_int | ( | sac * | s, |
int | hdr, | ||
int * | v | ||
) |
Get a integer value from a sac file.
Get a integer value from a sac file
s | sac file |
hdr | HeaderID |
v | output integer value |
int sac_get_pick | ( | sac * | s, |
int | n, | ||
double * | t | ||
) |
Get a timing pick.
Get a timing pick from the sac header
s | sac file |
n | pick number |
t | return value (64-bit value) |
Example of getting a time pick by its number, 0 to 9
int sac_get_string | ( | sac * | s, |
int | hdr, | ||
char * | v, | ||
size_t | n | ||
) |
Get a character string from a sac file.
Get a character string from a sac file
s | sac file |
hdr | HeaderID, Listing of string ::HeadersID is below |
v | output character string |
n | length of v |
int sac_get_time | ( | sac * | s, |
int | hdr, | ||
timespec64 * | t | ||
) |
Get time value from sac file.
Get time value from sac file
s | sac file |
hdr | header index value |
t | timespec64 output value |
int sac_get_time_ref | ( | sac * | s, |
timespec64 * | t | ||
) |
Get the reference time from a sac file.
Get the refereence time from a sac file
s | sac file |
t | timespec64 output value |
int sac_hdr_defined | ( | sac * | s, |
... | |||
) |
Check if multiple header values are defined.
Check if mulutple header values are defined
s | sac file |
... | HeaderID list, NULL terminatated |
copy the sac header
copy the sac header from from
to to
to | destination |
from | source |
int sac_is_timeval | ( | int | hid | ) |
Identify if a header is a time value.
Check is the sac header value is a time value
hid | sac HeaderID |
copy the sac meta header
copy the sac meta header from from
to to
to | destination |
from | source |
sac * sac_new | ( | ) |
create a new sac file structure
create a new sac file structure. Header and meta data are allocated. Data components are not allocated and should be done with sac_alloc() after setting the
type of file and the number of data points
Create a new sac file in memory
sac * sac_read | ( | char * | filename, |
int * | nerr | ||
) |
Read a sac file.
Read a sac file, data and header
filename | file to read data and header from |
nerr | status code, 0 on success, non-zero on header |
Reading a sac file should result in a pointer to a sac-file structure
Reading a file that does not exist will return a NULL pointer and an error code of 108
Reading a file that exists but is not a sac file will return a NULL pointer and an error code of 1317
sac * sac_read_header | ( | char * | filename, |
int * | nerr | ||
) |
sac * sac_read_with_cut | ( | char * | filename, |
char * | c1, | ||
double | t1, | ||
char * | c2, | ||
double | t2, | ||
enum CutAction | cutact, | ||
int * | nerr | ||
) |
read a sac file while cutting
read a sac file while cutting
filename | sac file to read |
c1 | reference time pick for start, see list below |
t1 | relative time from time pick c1 |
c2 | reference time pick for end, see list below |
t2 | relative time ffrom time pick c2 |
cutact | Behavior of cut
|
nerr | Status code, 0 on success, non-zero on Error |
int sac_set_float | ( | sac * | s, |
int | hdr, | ||
double | v | ||
) |
Set a floating point value in a sac file.
Set a floating point value in a sac file. If the value is in the 64-bit header, the value is copied into the 32-bit and 64-bit header. If the value is only in the 32-bit header, the value is only copied there
s | sac file |
hdr | HeaderID |
v | floating point to set |
int sac_set_int | ( | sac * | s, |
int | hdr, | ||
int | v | ||
) |
Set a integer value in a sac file.
Set a integer in a sac file
s | sac file |
hdr | HeaderID |
v | integer value to set |
int sac_set_pick | ( | sac * | s, |
int | n, | ||
double | value | ||
) |
Set a time pick value.
Set a time pick value in a sac header
s | sac file |
n | pick number |
value | timing value to set (64 bit value) |
Exaple of setting the time pick t3 to 13.50
int sac_set_string | ( | sac * | s, |
int | hdr, | ||
char * | v | ||
) |
Set a character string in a sac file.
Set a character stirng in a sac file
s | sac file |
hdr | HeaderID, only valid sac header are setable |
v | character string to set |
int sac_set_time | ( | sac * | s, |
timespec64 | t | ||
) |
Set the reference time for a sac file, assumed to be the origin time
s | sac file |
t | origin time |
Effective sac commands are:
SAC> ch o gmt 1994 160 00 33 16 230 SAC> ch iztype IO SAC> ch allt (-1.0 * &1,o)
void sac_set_v6 | ( | sac * | s | ) |
Set the header version to 6.
s | sac file |
Set the header version to 6
. See sac::sac_get_float() and sac::sac_set_float() for the details about how the different header version impact which floating point values are set and get.
void sac_set_v7 | ( | sac * | s | ) |
Set the header version to 7.
s | sac file |
Set the header version to 7
. See sac::sac_get_float() and sac::sac_set_float() for the details about how the different header version impact which floating point values are set and get.
off_t sac_size | ( | sac * | s | ) |
Get the size of a sac file in bytes.
Get the size of a sac file in bytes if stored on disk
s | sac file |
int sac_time_to_index | ( | sac * | s, |
double | t | ||
) |
Convert a time to index.
Convert a time value to a data point index. All values are relative to the b
value
s | sac file |
t | time value |
void sac_write | ( | sac * | s, |
char * | filename, | ||
int * | nerr | ||
) |
write a sac file to disk
write a sac file to disk, header and data
s | sac file to write to disk |
filename | file to write to |
nerr | status code, 0 on success, non-zero on error |
Example of writing a sac file
void sac_write_header | ( | sac * | s, |
char * | filename, | ||
int * | nerr | ||
) |
write a sac header to disk
write a sac header to disk
s | sac header to write to disk |
filename | file to write to, must exist and be a sac file |
nerr | status code, 0 on success, non-zero on error |
Example of writing a sac header
A file that does not exist should return a error code of 108
A file that is not a sac file should return an error code of 1317