source: EEW/trunk/mcast2eew/GCBRTSPModule.cc @ 3772

Revision 3772, 2.6 KB checked in by solanki, 4 years ago (diff)

Added earthworm support

Line 
1#include "GCBRTSPModule.h"
2#include "eewPropertiesST.h"
3#include "Duration.h"
4#include "EEW.h"
5//#define FILEDUMP 0
6
7GCBRTSPModule::GCBRTSPModule(){}
8
9GCBRTSPModule::GCBRTSPModule(Channel chn): Module(chn){
10  //Initialize per-channel datastructures here//
11    LTA = 0;
12    tflag = false;
13    gain = chn.gain;
14   
15//     eewPropertiesST* prop = eewPropertiesST::getInstance();
16
17//     if(string(channel.channel) == string(string(prop->getChannelType())+"Z")){
18//       gain = prop->getgainZ();
19//     }
20//     else if(string(channel.channel) == string(string(prop->getChannelType())+"E")){
21//       gain = prop->getgainE();
22//     }
23//     else if(string(channel.channel) == string(string(prop->getChannelType())+"N")){
24//       gain = prop->getgainN();
25//     }
26    cout <<"Gain for "<<chn<<" is "<<gain<<endl;
27
28#ifdef WRITE2SAC
29    int samplerate = chn.samprate;//eewPropertiesST::getInstance()->getSampleRate();
30    sacwrt.open(channel,"acc",1.0/samplerate);
31#endif
32
33}
34
35GCBRTSPModule::~GCBRTSPModule(){
36  //Release per-channel resources here//
37#ifdef WRITE2SAC
38    sacwrt.close();
39#endif
40}
41
42
43void GCBRTSPModule::load(string config_filename) throw(Error){
44    //initialize the module
45  cout <<"Loading GCBR Module"<<endl;
46}
47
48void GCBRTSPModule::unload(){
49  //release the resources
50  cout <<"Unloading GCBR Module"<<endl;
51}
52
53
54void GCBRTSPModule::process(timeval timestamp,
55                           unsigned int in_nsamp,
56                           int* in,
57                           unsigned int& out_nsamp,
58                           float* out){
59
60    //Write code to process the time series data//
61    //cout <<"["<<channel<<"] "<<"Start time "<<TimeStamp(timestamp)<<" Delay :"<<(double)(TimeStamp::current_time() - TimeStamp(timestamp))<<" seconds, samples="<<in_nsamp<<endl;
62
63
64#ifdef WRITE2SAC
65    sacwrt.write(in,in_nsamp);
66#endif
67
68    double sum = 0.0;
69    double avg = 0.0;
70    float multfact = (float)eewPropertiesST::getInstance()->getSampleMultFactor();
71
72    for(int i=0;i<in_nsamp;i++){
73        in[i] = in[i]*multfact;
74        sum += in[i];
75    }
76
77    avg = sum/((in_nsamp)*60.0);   
78    ltalist.push_back(avg);
79    LTA += avg;
80    if(ltalist.size() > 60){
81      LTA -= ltalist.front();
82      ltalist.pop_front();
83    }
84
85    unsigned long tsec = timestamp.tv_sec;
86    //cout <<channel<<" gain is "<<gain<<endl;
87    for(int j=0;j<in_nsamp;j++){
88      out[j] = (float)((float)(in[j] - LTA)/gain);
89        tsec++;
90    }
91    out_nsamp = in_nsamp;
92
93    //   for(int i=0;i<in_nsamp;i++){
94    //  cout <<out[i]<<",";
95    // }
96    //cout <<endl;
97}
98
99
100
101void GCBRTSPModule::restart(timeval timestamp){
102    //Write code to handle gaps in time series data//
103  //    cout <<channel<<" GAP Found."<<endl;
104
105    LTA = 0;
106    ltalist.clear();
107
108#ifdef WRITE2SAC
109    sacwrt.close();
110    sacwrt.reopen();
111#endif
112}
Note: See TracBrowser for help on using the repository browser.