sac-format 0.6.0 C++20 SAC (Seismic Analysis Code) File Library |
#include <sac_format.hpp>
Static Public Member Functions | |
static void | write_data (std::ofstream *sac_file, const std::vector< double > &data_vec) |
Writes data vectors. | |
Private Member Functions | |
void | calc_gcarc () noexcept |
Calculate great-circle arc-distance (gcarc). | |
void | calc_dist () noexcept |
Calculate distance (using gcarc). | |
void | calc_az () noexcept |
Calculate azimuth. | |
void | calc_baz () noexcept |
Calculate back-azimuth. | |
void | read_float_headers_starter (std::ifstream *sac_file) |
Reads SAC-headers from words 000–009. | |
void | read_float_headers_t (std::ifstream *sac_file) |
Reads SAC-headers from words 010–020. | |
void | read_float_headers_resp (std::ifstream *sac_file) |
Reads SAC-headers from words 021–030. | |
void | read_float_headers_station_event (std::ifstream *sac_file) |
Reads SAC-headers from words 031–039. | |
void | read_float_headers_user (std::ifstream *sac_file) |
Reads SAC-headers from words 040–049. | |
void | read_float_headers_geometry (std::ifstream *sac_file) |
Reads SAC-headers from words 050–053. | |
void | read_float_headers_meta (std::ifstream *sac_file) |
Reads SAC-headers from words 054–069. | |
void | read_float_headers (std::ifstream *sac_file) |
Reads SAC-headers from words 000–069. | |
void | read_int_headers_datetime (std::ifstream *sac_file) |
Reads SAC-headers from words 070–075. | |
void | read_int_headers_meta (std::ifstream *sac_file) |
Reads SAC-headers from words 076–104. | |
void | read_int_headers (std::ifstream *sac_file) |
Reads SAC-headers from words 070–104. | |
void | read_bool_headers (std::ifstream *sac_file) |
Reads SAC-headers from words 105–109. | |
void | read_string_headers (std::ifstream *sac_file) |
Reads SAC-headers from words 110–157. | |
void | read_datas (std::ifstream *sac_file) |
Reads data vectors. | |
void | read_footers (std::ifstream *sac_file) |
Reads SAC-footers (post-data words 00–43). | |
void | write_float_headers_starter (std::ofstream *sac_file) const |
Writes SAC-headers from words 000–009. | |
void | write_float_headers_t (std::ofstream *sac_file) const |
Writes SAC-headers from words 010–020. | |
void | write_float_headers_resp (std::ofstream *sac_file) const |
Writes SAC-headers from words 021–030. | |
void | write_float_headers_station_event (std::ofstream *sac_file) const |
Writes SAC-headers from words 031–039. | |
void | write_float_headers_user (std::ofstream *sac_file) const |
Writes SAC-headers from words 040–049. | |
void | write_float_headers_geometry (std::ofstream *sac_file) const |
Writes SAC-headers from words 050–053. | |
void | write_float_headers_meta (std::ofstream *sac_file) const |
Writes SAC-headers from words 054–069. | |
void | write_float_headers (std::ofstream *sac_file) const |
Writes SAC-headers from words 000–069. | |
void | write_int_headers_datetime (std::ofstream *sac_file) const |
Writes SAC-headers from words 070–075. | |
void | write_int_headers_meta (std::ofstream *sac_file, int hdr_ver) const |
Writes SAC-headers from words 076–104. | |
void | write_int_headers (std::ofstream *sac_file, int hdr_ver) const |
Writes SAC-headers from words 070–104. | |
void | write_bool_headers (std::ofstream *sac_file) const |
Writes SAC-headers from words 105–109. | |
void | write_string_headers (std::ofstream *sac_file) const |
Writes SAC-headers from words 110–157. | |
void | write_footers (std::ofstream *sac_file) const |
Writes SAC-footers (post-data words 00–43). | |
bool | geometry_set () const noexcept |
Determine if locations are set for geometry calculation. | |
point | station_location () const noexcept |
Return station location as a point. | |
point | event_location () const noexcept |
Return even location as a point. | |
void | resize_data1 (size_t size) noexcept |
void | resize_data2 (size_t size) noexcept |
void | resize_data (size_t size) noexcept |
Resize data vectors (only if eligible). | |
Private Attributes | |
std::array< float, num_float > | floats {} |
Float storage array. | |
std::array< double, num_double > | doubles {} |
Double storage array. | |
std::array< int, num_int > | ints {} |
Integer storage array. | |
std::array< bool, num_bool > | bools {} |
Boolean storage array. | |
std::array< std::string, num_string > | strings {} |
String storage array. | |
std::array< std::vector< double >, num_data > | data {} |
std::vector<double> storage array. | |
The Trace class.
This class is the recommended way for reading/writing SAC-files.
It safely reads all data, provides automatic write support based upon the nVHdr header value (determine if a footer should be included or not).
It provides getters and setters for all SAC headers and the data.
| noexcept |
Trace default constructor.
Fills all values with their default (unset) values. Data vectors are of size zero.
| explicit |
Binary SAC-file reader.
[in] | path | std::filesystem::path SAC-file to be read. |
io_error | If the file is not safe to read for whatever reason. |
std::exception | (disk failure). |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| privatenoexcept |
Calculate azimuth.
| privatenoexcept |
Calculate back-azimuth.
| privatenoexcept |
Calculate distance (using gcarc).
Assumes spherical Earth (in future may update to include flattening and different planteray bodies).
| privatenoexcept |
Calculate great-circle arc-distance (gcarc).
| noexcept |
Calculates gcarc, dist, az, and baz from stla, stlo, evla, and evlo.
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| inlineprivatenoexcept |
Return even location as a point.
| noexcept |
| noexcept |
| noexcept |
| noexcept |
Calculate frequency from delta.
| noexcept |
| privatenoexcept |
Determine if locations are set for geometry calculation.
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
Binary SAC-file legacy-write convenience function.
[in] | path | std::filesystem::path SAC-file to be written. |
io_error | If the file cannot be written (bad path or bad permissions). |
std::execption | Other unwritable issues (not enough space, disk failure, etc.). |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
Trace equality operator.
| private |
Reads SAC-headers from words 105–109.
Note that this expects the position of the reader to be the beginning of word 105.
Note that this modifies the position of the reader to the end of word 109.
Loads all boolean headers.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads data vectors.
Note that this modifies the position of the reader to the end of the data section(s).
For data1 reads words 158–(158 + npts).
For data2 reads words (158 + 1 + npts)–(159 + (2 * npts))
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 000–069.
Note that this expects the position of the reader to be the beginning of word 000.
Note that this modifies the position of the reader to the end of word 069.
Loads all the float headers.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 050–053.
Note that this expects the position of the reader to be the beginning of word 050.
Note that this modifies the position of the reader to the end of word 053.
Headers loaded: dist, az, baz, and gcarc.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 054–069.
Note that this expects the position of the reader to be the beginning of word 054.
Note that this modifies the position of the reader to the end of word 069.
Headers loaded: sb, sdelta, depmen, cmpaz, cmpinc, xminimum, xmaximum, yminimum, and ymaximum.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 021–030.
Note that this expects the position of the reader to be the beginning of word 021.
Note that this modifies the position of the reader to the end of word 030.
Headers loaded: resp0, resp1, resp2, resp3, resp4, resp5, resp6, resp7, resp8, and resp9.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 000–009.
Note that this expects the position of the reader to be the beginning of word 000.
Note that this modifies the position of the reader to the end of word 009.
Headers loaded: delta, depmin, depmax, odelta, b, e, o, and a.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 031–039.
Note that this expects the position of the reader to be the beginning of word 031.
Note that this modifies the position of the reader to the end of word 039.
Headers loaded: stla, stlo, stel, stdp, evla, evlo, evel, evdp, and mag.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 010–020.
Note that this expects the position of the reader to be the beginning of word 010.
Note that this modifies the position of the reader to the end of word 020.
Headers loaded: t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, and f.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 040–049.
Note that this expects the position of the reader to be the beginning of word 040.
Note that this modifies the position of the reader to the end of word 049.
Headers loaded: user0, user1, user2, user3, user4, user5, user6, user7, user8, and user9.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-footers (post-data words 00–43).
Note that this modifies the position of the reader to the end of the footer section.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 070–104.
Note that this expects the position of the reader to be the beginning of word 070.
Note that this modifies the position of the reader to the end of word 104.
Loads all integer headers.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 070–075.
Note that this expects the position of the reader to be the beginning of word 070.
Note that this modifies the position of the reader to the end of word 075.
Headers loaded: nzyear, nzjday, nzhour, nzmin, nzsec, and nzmsec.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 076–104.
Note that this expects the position of the reader to be the beginning of word 076.
Note that this modifies the position of the reader to the end of word 104.
Headers loaded: nvhdr, norid, nevid, npts, nsnpts, nwfid, nxsize, nysize, iftype, idep, iztype, iinst, istreg, ievreg, ievtyp, iqual, isynth, imagtyp, imagsrc, and ibody.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
| private |
Reads SAC-headers from words 110–157.
Note that this expects the position of the reader to be the beginning of word 110.
Note that this modifies the position of the reader to the end of word 157.
Loads all string headers.
[in,out] | sac_file | std::ifstream* SAC-file to be read. |
Resize data vectors (only if eligible).
Will always resize data1, data2 only resizes if it can have non-zero size.
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| inlineprivatenoexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
Get time string.
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
Binary SAC-file writer.
[in] | path | std::filesystem::path SAC-file to write. |
[in] | legacy | bool Legacy-write flag (default false = v7, true = v6). |
io_error | If the file cannot be written (bad path or bad permissions). |
std::exception | Other unwritable issues (not enough space, disk failure, etc.). |
| private |
Writes SAC-headers from words 105–109.
Note that this expects the position of the writer to be the beginning of word 105.
Note that this modifies the position of the writer to the end of word 109.
Writes all boolean headers.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| static |
Writes data vectors.
Note that this modifies the position of the writer to the end of the data section wriitten.
For data1 writes words 158–(158 + npts).
For data2 writess words (158 + 1 + npts)–(159 + (2 * npts))
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
[in] | data_vec | std::vector<double> Data-vector to write. |
| private |
Writes SAC-headers from words 000–069.
Note that this expects the position of the writer to be the beginning of word 000.
Note that this modifies the position of the writer to the end of word 069.
Writes all the float headers.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 050–053.
Note that this expects the position of the writer to be the beginning of word 050.
Note that this modifies the position of the writer to the end of word 053.
Headers written: dist, az, baz, and gcarc.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 054–069.
Note that this expects the position of the writer to be the beginning of word 054.
Note that this modifies the position of the writer to the end of word 069.
Headers written: sb, sdelta, depmen, cmpaz, cmpinc, xminimum, xmaximum, yminimum, and ymaximum.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 021–030.
Note that this expects the position of the writer to be the beginning of word 021.
Note that this modifies the position of the writer to the end of word 030.
Headers written: resp0, resp1, resp2, resp3, resp4, resp5, resp6, resp7, resp8, and resp9.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 000–009.
Note that this expects the position of the writer to be the beginning of word 000.
Note that this modifies the position of the writer to the end of word 009.
Headers written: delta, depmin, depmax, odelta, b, e, o, and a.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 031–039.
Note that this expects the position of the writer to be the beginning of word 031.
Note that this modifies the position of the writer to the end of word 039.
Headers written: stla, stlo, stel, stdp, evla, evlo, evel, evdp, and mag.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 010–020.
Note that this expects the position of the writer to be the beginning of word 010.
Note that this modifies the position of the writer to the end of word 020.
Headers written: t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, and f.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-headers from words 040–049.
Note that this expects the position of the writer to be the beginning of word 040.
Note that this modifies the position of the writer to the end of word 049.
Headers written: user0, user1, user2, user3, user4, user5, user6, user7, user8, and user9.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| private |
Writes SAC-footers (post-data words 00–43).
Note that this modifies the position of the writer to the end of the footer section.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
Writes SAC-headers from words 070–104.
Note that this expects the position of the writer to be the beginning of word 070.
Note that this modifies the position of the writer to the end of word 104.
Writes all integer headers.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
[in] | hdr_ver | Integer header version to be written. |
| private |
Writes SAC-headers from words 070–075.
Note that this expects the position of the writer to be the beginning of word 070.
Note that this modifies the position of the writer to the end of word 075.
Headers written: nzyear, nzjday, nzhour, nzmin, nzsec, and nzmsec.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
Writes SAC-headers from words 076–104.
Note that this expects the position of the writer to be the beginning of word 076.
Note that this modifies the position of the writer to the end of word 104.
Headers written: nvhdr, norid, nevid, npts, nsnpts, nwfid, nxsize, nysize, iftype, idep, iztype, iinst, istreg, ievreg, ievtyp, iqual, isynth, imagtyp, imagsrc, and ibody.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
[in] | hdr_ver | Integer header version to be written. |
| private |
Writes SAC-headers from words 110–157.
Note that this expects the position of the writer to be the beginning of word 110.
Note that this modifies the position of the writer to the end of word 157.
Writes all string headers.
[in,out] | sac_file | std::ofstream* SAC-file to be written. |
| noexcept |
| noexcept |
| noexcept |
| noexcept |
std::vector<double> storage array.
| private |
Double storage array.
| private |
String storage array.