source: EEW/trunk/mcast2eew/eewProperties.cc @ 3706

Revision 3706, 6.0 KB checked in by solanki, 4 years ago (diff)

Faster version of caltech EEW.

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