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

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

Added earthworm support

Line 
1/*
2  Author: Kalpesh Solanki
3 */
4
5#include "eewPropertiesST.h"
6#include "Configuration.h"
7#include <stdio.h>
8#include <errno.h>
9#include "GenLimits.h"
10
11eewPropertiesST * eewPropertiesST::handle = NULL;
12
13
14
15
16eewPropertiesST::eewPropertiesST(){};
17
18
19eewPropertiesST* eewPropertiesST::getInstance(){
20  if(handle==NULL){
21    handle = new eewPropertiesST();
22  }
23  return handle;
24}
25
26void eewPropertiesST::init(string config_filename) throw(Error){
27    //Check if file exists//
28    fstream file;
29    file.open(config_filename.c_str(),fstream::in);
30    if(file.fail()){
31        throw Error("eewPropertiesST::eewPropertiesST: Unable to open "+config_filename);
32    }
33    file.close();
34 
35    //Populate KeyValue Map//
36    char key[MAXSTR];
37    char value[MAXSTR];
38    int ret=TN_EOF;
39    Configuration cfg(config_filename.c_str());
40   
41    while((ret=cfg.next(key,value))==TN_SUCCESS){
42        if(kvm[key] != ""){
43            throw Error("eewPropertiesST::eewPropertiesST: Duplicate key found :"+string(key));
44        }
45        kvm[key] = value;
46    }
47    //Check for non-defaults//
48   
49        if(kvm["FilterOrder"] == ""){
50               
51                        throw Error("eewPropertiesST::eewPropertiesST: Parameter FilterOrder not found.");
52                               
53        }
54        else{
55                try{
56                       
57                                        _filterorder = toInt(kvm["FilterOrder"]);
58                                       
59                }
60                catch(Error& e){
61                        throw Error("Configuration file is not in a valid format. FilterOrder is invalid");
62                }
63            }
64       
65        if(kvm["HPcutoff"] == ""){
66               
67                        throw Error("eewPropertiesST::eewPropertiesST: Parameter HPcutoff not found.");
68                               
69        }
70        else{
71                try{
72                       
73                                        _hpcutoff = toFloat(kvm["HPcutoff"]);
74                                       
75                }
76                catch(Error& e){
77                        throw Error("Configuration file is not in a valid format. HPcutoff is invalid");
78                }
79            }
80       
81        if(kvm["WaitTimeAfterPick"] == ""){
82               
83                        throw Error("eewPropertiesST::eewPropertiesST: Parameter WaitTimeAfterPick not found.");
84                               
85        }
86        else{
87                try{
88                       
89                                        _waittimeafterpick = toInt(kvm["WaitTimeAfterPick"]);
90                                       
91                }
92                catch(Error& e){
93                        throw Error("Configuration file is not in a valid format. WaitTimeAfterPick is invalid");
94                }
95            }
96       
97        if(kvm["LatencyTolerance"] == ""){
98               
99                        throw Error("eewPropertiesST::eewPropertiesST: Parameter LatencyTolerance not found.");
100                               
101        }
102        else{
103                try{
104                       
105                                        _latencytolerance = toInt(kvm["LatencyTolerance"]);
106                                       
107                }
108                catch(Error& e){
109                        throw Error("Configuration file is not in a valid format. LatencyTolerance is invalid");
110                }
111            }
112       
113        if(kvm["VelocityThreshold"] == ""){
114               
115                        throw Error("eewPropertiesST::eewPropertiesST: Parameter VelocityThreshold not found.");
116                               
117        }
118        else{
119                try{
120                       
121                                        _velocitythreshold = toFloat(kvm["VelocityThreshold"]);
122                                       
123                }
124                catch(Error& e){
125                        throw Error("Configuration file is not in a valid format. VelocityThreshold is invalid");
126                }
127            }
128       
129        if(kvm["ClipWaitSeconds"] == ""){
130               
131                        throw Error("eewPropertiesST::eewPropertiesST: Parameter ClipWaitSeconds not found.");
132                               
133        }
134        else{
135                try{
136                       
137                                        _clipwaitseconds = toInt(kvm["ClipWaitSeconds"]);
138                                       
139                }
140                catch(Error& e){
141                        throw Error("Configuration file is not in a valid format. ClipWaitSeconds is invalid");
142                }
143            }
144       
145        if(kvm["SampleMultFactor"] == ""){
146               
147                        throw Error("eewPropertiesST::eewPropertiesST: Parameter SampleMultFactor not found.");
148                               
149        }
150        else{
151                try{
152                       
153                                        _samplemultfactor = toInt(kvm["SampleMultFactor"]);
154                                       
155                }
156                catch(Error& e){
157                        throw Error("Configuration file is not in a valid format. SampleMultFactor is invalid");
158                }
159            }
160       
161        if(kvm["ServerName"] == ""){
162               
163                        throw Error("eewPropertiesST::eewPropertiesST: Parameter ServerName not found.");
164                               
165        }
166        else{
167                try{
168                       
169                                        _servername = kvm["ServerName"];
170                                       
171                }
172                catch(Error& e){
173                        throw Error("Configuration file is not in a valid format. ServerName is invalid");
174                }
175            }
176       
177        if(kvm["ServerPort"] == ""){
178               
179                        throw Error("eewPropertiesST::eewPropertiesST: Parameter ServerPort not found.");
180                               
181        }
182        else{
183                try{
184                       
185                                        _serverport = toInt(kvm["ServerPort"]);
186                                       
187                }
188                catch(Error& e){
189                        throw Error("Configuration file is not in a valid format. ServerPort is invalid");
190                }
191            }
192       
193        if(kvm["NetAlgoServerName"] == ""){
194               
195                        throw Error("eewPropertiesST::eewPropertiesST: Parameter NetAlgoServerName not found.");
196                               
197        }
198        else{
199                try{
200                       
201                                        _netalgoservername = kvm["NetAlgoServerName"];
202                                       
203                }
204                catch(Error& e){
205                        throw Error("Configuration file is not in a valid format. NetAlgoServerName is invalid");
206                }
207            }
208       
209        if(kvm["NetAlgoServerPort"] == ""){
210               
211                        throw Error("eewPropertiesST::eewPropertiesST: Parameter NetAlgoServerPort not found.");
212                               
213        }
214        else{
215                try{
216                       
217                                        _netalgoserverport = toInt(kvm["NetAlgoServerPort"]);
218                                       
219                }
220                catch(Error& e){
221                        throw Error("Configuration file is not in a valid format. NetAlgoServerPort is invalid");
222                }
223            }
224       
225}
226
227int eewPropertiesST::toInt(string int_val) throw(Error){
228        char val[32];
229        strcpy(val,int_val.c_str());
230
231        int v = atoi(val);
232//      if(errno == ERANGE || errno == EINVAL){
233//              throw Error("Invalid Integer");
234//      }
235       
236        return v;
237}
238
239float eewPropertiesST::toFloat(string float_val) throw(Error){
240        char val[32];
241        strcpy(val,float_val.c_str());
242
243        float v = atof(val);
244//      if(errno == ERANGE || errno == EINVAL){
245//              throw Error("Invalid Float");
246//      }
247        return v;
248}
249
250double eewPropertiesST::toDouble(string double_val) throw(Error){
251        char val[32];
252        strcpy(val,double_val.c_str());
253
254        double v = (double)atof(val);
255//      if(errno == ERANGE || errno == EINVAL){
256//              throw Error("Invalid Double");
257//      }
258        return v;
259}
260
261
262bool eewPropertiesST::toBool(string bool_val) throw(Error){
263        if(bool_val == "true"){
264                return true;
265        }
266        else if(bool_val == "false"){
267                return false;
268        }
269        else{
270                throw Error("Invalid Bool");
271        }
272}
273
274
275
276int eewPropertiesST::getFilterOrder() const{
277        return _filterorder;
278}
279
280float eewPropertiesST::getHPcutoff() const{
281        return _hpcutoff;
282}
283
284int eewPropertiesST::getWaitTimeAfterPick() const{
285        return _waittimeafterpick;
286}
287
288int eewPropertiesST::getLatencyTolerance() const{
289        return _latencytolerance;
290}
291
292float eewPropertiesST::getVelocityThreshold() const{
293        return _velocitythreshold;
294}
295
296int eewPropertiesST::getClipWaitSeconds() const{
297        return _clipwaitseconds;
298}
299
300int eewPropertiesST::getSampleMultFactor() const{
301        return _samplemultfactor;
302}
303
304string eewPropertiesST::getServerName() const{
305        return _servername;
306}
307
308int eewPropertiesST::getServerPort() const{
309        return _serverport;
310}
311
312string eewPropertiesST::getNetAlgoServerName() const{
313        return _netalgoservername;
314}
315
316int eewPropertiesST::getNetAlgoServerPort() const{
317        return _netalgoserverport;
318}
319
320
321
Note: See TracBrowser for help on using the repository browser.