gctl_seismic/lib/seismic/sac.h
2024-09-10 20:22:53 +08:00

261 lines
8.1 KiB
C++

/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#ifndef _GCTL_SEISMIC_SAC_H
#define _GCTL_SEISMIC_SAC_H
#include "signal.h"
namespace gctl
{
enum SAC_ENUM
{
itime = 1,
irlim,
iamph,
ixy,
iunkn,
idisp,
ivel,
iacc,
ib,
iday,
io,
ia,
it0,
it1,
it2,
it3,
it4,
it5,
it6,
it7,
it8,
it9,
iradnv,
itannv,
iradev,
itanev,
inorth,
ieast,
ihorza,
idown,
iup,
illlbb,
iwwsn1,
iwwsn2,
ihglp,
isro,
inucl,
ipren,
ipostn,
iquake,
ipreq,
ipostq,
ichem,
iother,
igood,
iglch,
idrop,
ilowsn,
irldta,
ivolts,
imb,
ims,
iml,
imw,
imd,
imx,
ineic,
ipdeq,
ipdew,
ipde,
iisc,
ireb,
iusgs,
ibrk,
icaltech,
illnl,
ievloc,
ijsop,
iuser,
iunknown,
iqb,
iqb1,
iqb2,
iqbx,
iqmt,
ieq,
ieq1,
ieq2,
ime,
iex,
inu,
inc,
io_,
il,
ir,
it,
iu,
ieq3,
ieq0,
iex0,
iqc,
iqb0,
igey,
ilit,
imet,
iodor,
isun,
imercury,
ivenus,
iearth,
imoon,
imars,
};
struct SAC_HD
{
float delta, depmin, depmax, unused1, odelta; //0 - 4
float b, e, o, a, internal; //5 - 9
float t0, t1, t2, t3, t4; //10 - 14
float t5, t6, t7, t8, t9; //15 - 19
float f, resp0, resp1, resp2, resp3; //20 - 24
float resp4, resp5, resp6, resp7, resp8; //25 - 29
float resp9, stla, stlo, stel, stdp; //30 - 34
float evla, evlo, evel, evdp, mag; //35 - 39
float user0, user1, user2, user3, user4; //40 - 44
float user5, user6, user7, user8, user9; //45 - 49
float dist, az, baz, gcarc, sb;
float sdelta, depmen, cmpaz, cmpinc, xminimum;
float xmaximum, yminimum, ymaximum, adjtm, unused2;
float unused3, unused4, unused5, unused6, unused7;
int nzyear, nzjday, nzhour, nzmin, nzsec;
int nzmsec, nvhdr, norid, nevid, npts;
int nsnpts, nwfid, nxsize, nysize, unused8;
int iftype, idep, iztype, unused9, iinst;
int istreg, ievreg, ievtyp, iqual, isynth;
int imagtyp, imagsrc, ibody, unused10, unused11;
int unused12, unused13, unused14, unused15, unused16;
int leven, lpspol, lovrok, lcalda, unused17;
char kstnm[8], kevnm[16]; // valid length for storing is 15
char khole[8], ko[8], ka[8]; // valid length for storing is 7
char kt0[8], kt1[8], kt2[8];
char kt3[8], kt4[8], kt5[8];
char kt6[8], kt7[8], kt8[8];
char kt9[8], kf[8], kuser0[8];
char kuser1[8], kuser2[8], kcmpnm[8];
char knetwk[8], kdatrd[8], kinst[8];
};
static SAC_HD sac_null =
{
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
"-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
"-12345 ", "-12345 ", "-12345 ",
};
#ifdef GCTL_SEISMIC_MATHGL
class SAC_PLOT : public mglDraw
{
private:
SAC_HD *hd_ptr;
SIG_UNIT *sig_ptr;
std::string file;
public:
SAC_PLOT();
virtual ~SAC_PLOT();
void link_source(SIG_UNIT *sig, SAC_HD *hd, std::string filename);
int Draw(mglGraph *gr);
};
#endif // GCTL_SEISMIC_MATHGL
class SAC
{
public:
SAC_HD head = sac_null;
SIG_UNIT signal;
#ifdef GCTL_SEISMIC_MATHGL
SAC_PLOT plt;
#endif // GCTL_SEISMIC_MATHGL
public:
SAC();
SAC(std::string filename, bool headonly = false);
virtual ~SAC();
void read(std::string filename, bool headonly = false);
void save(std::string filename) const;
void info() const;
void sync();
void cut_section(SAC &ret, double st, double et) const;
void cut_section(SAC &ret, const UTC_TIME &st, double len) const;
void stack_sac(const gctl::array<SAC*> &list);
//void merge_sac(const gctl::array<SAC*> &list);
void down_sampling(int factor);
void remove_mean();
void remove_outliers(double factor);
void normalize(double norm = 1.0);
#ifdef GCTL_SEISMIC_MATHGL
int plot(std::string filename = "null");
#endif // GCTL_SEISMIC_MATHGL
};
}
#endif // _GCTL_SEISMIC_SAC_H