1 | |
---|
2 | /* file cbutil.c |
---|
3 | * ======== |
---|
4 | * |
---|
5 | * $Revision: 35 $, $Date: 2008-07-04 11:21:14 +0200 (Fr, 04 Jul 2008) $ |
---|
6 | * |
---|
7 | * utility routines for callbacks |
---|
8 | * K. Stammler, 3-Mar-93 |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | /* |
---|
13 | * |
---|
14 | * SeismicHandler, seismic analysis software |
---|
15 | * Copyright (C) 1996, Klaus Stammler, Federal Institute for Geosciences |
---|
16 | * and Natural Resources (BGR), Germany |
---|
17 | * |
---|
18 | * This program is free software; you can redistribute it and/or modify |
---|
19 | * it under the terms of the GNU General Public License as published by |
---|
20 | * the Free Software Foundation; either version 2 of the License, or |
---|
21 | * (at your option) any later version. |
---|
22 | * |
---|
23 | * This program is distributed in the hope that it will be useful, |
---|
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
26 | * GNU General Public License for more details. |
---|
27 | * |
---|
28 | * You should have received a copy of the GNU General Public License |
---|
29 | * along with this program; if not, write to the Free Software |
---|
30 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | #include <stdio.h> |
---|
36 | #include <string.h> |
---|
37 | #include "basecnst.h" |
---|
38 | #ifdef BC_INC_STDLIB |
---|
39 | #include BC_INC_STDLIB |
---|
40 | #endif |
---|
41 | #include <Xm/Xm.h> |
---|
42 | #include <Xm/ToggleB.h> |
---|
43 | #include <Xm/Text.h> /* because XmTextSetString is not defined in Xm.h */ |
---|
44 | #include <time.h> |
---|
45 | #include <math.h> |
---|
46 | #undef BC_DEFINE_TRUE_FALSE |
---|
47 | #include BC_SYSBASE |
---|
48 | #include BC_TCUSRDEF |
---|
49 | #include "infoidx.h" |
---|
50 | #include "glusrdef.h" |
---|
51 | #include "fctxmt.h" |
---|
52 | #include "sherrors.h" |
---|
53 | #include "earthloc.h" |
---|
54 | #include "ptusrdef.h" |
---|
55 | #include "ffusrdef.h" |
---|
56 | #include "erusrdef.h" |
---|
57 | #include "utusrdef.h" |
---|
58 | #include "motifgraph.h" |
---|
59 | #include "seismics.h" |
---|
60 | #include "cbutil.h" |
---|
61 | #include "phaseinf.h" |
---|
62 | #include "phasemgr.h" |
---|
63 | #include "shvars.h" |
---|
64 | #include "shm_widgets.h" |
---|
65 | #include "globalparams.h" |
---|
66 | |
---|
67 | |
---|
68 | #define WAIT_UNIT 10000 |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | /* global variables */ |
---|
73 | static Widget cuv_alert_widget; /* widget ID of alert box */ |
---|
74 | static Widget cuv_multipli_value; /* widget ID for multiplic. box (value) */ |
---|
75 | static Widget cuv_multipli_box; /* widget ID for multiplic. box */ |
---|
76 | static Widget cuv_multipli_edit; /* widget ID for multiplic. box (edit) */ |
---|
77 | static TPiPhase *cuv_multipli_phase=NULL; /* pointer to multiplication value */ |
---|
78 | static TPiPhase *cuv_multipli_trc=NULL; /* pointer to multiplication value */ |
---|
79 | static int cuv_execflags=0; /* execution flag memory */ |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | /* prototype of get_geo */ |
---|
85 | void xxx_get_geo(float *elat, float *elon, int *num_id, char *qnam); |
---|
86 | |
---|
87 | /* prototypes of local routines */ |
---|
88 | static void cuh_strip_blanks( char str[] ); |
---|
89 | static void cuh_wait( int cnt ); |
---|
90 | static void cuh_phase_onset( char phase[], void *trc, char **onset, |
---|
91 | float *residcorr ); |
---|
92 | static GLT_STATINF *cu_get_statinf( TPmTrace *trc, TSyStatus *status ); |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | /*---------------------------------------------------------------------------*/ |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | void cu_reset_phase( TPiPhase *phase ) |
---|
101 | |
---|
102 | /* resets phase info to default values |
---|
103 | * |
---|
104 | * parameters of routine |
---|
105 | * TPiPhase *phase; output; structure to reset |
---|
106 | */ |
---|
107 | { |
---|
108 | /* executable code */ |
---|
109 | |
---|
110 | phase->onset[0] = '\0'; |
---|
111 | phase->onset_acc_l = cPiAccEmpty; |
---|
112 | phase->onset_acc_r = cPiAccEmpty; |
---|
113 | phase->spec = cPiSpecEmergent; |
---|
114 | phase->sign = 0; |
---|
115 | phase->source = cPiSourceUndefined; |
---|
116 | phase->quality = GpGetInt( cGpI_default_quality ); |
---|
117 | phase->weight = cu_quality2weight( phase->quality ); |
---|
118 | phase->ampl = 0.0; |
---|
119 | phase->ampl_time = 0.0; |
---|
120 | phase->ampl_veloc = 0.0; |
---|
121 | phase->ampl_displ = 0.0; |
---|
122 | phase->period = 0.0; |
---|
123 | phase->magnitude = 0.0; |
---|
124 | phase->magn_source = cPiMagnUndefined; |
---|
125 | phase->ap_source = cPiApsrcUndefined; |
---|
126 | phase->bb.bbampl = 0.0; |
---|
127 | phase->bb.bbperiod = 0.0; |
---|
128 | phase->bb.bbampl_time = 0.0; |
---|
129 | phase->bb.mbb = 0.0; |
---|
130 | phase->signoise = 0.0; |
---|
131 | phase->resid = 0.0; |
---|
132 | phase->resid_type = cPiResidUndefined; |
---|
133 | phase->resid_corr = cPiResidCorrEmpty; |
---|
134 | phase->flags = 0; |
---|
135 | phase->filter[0] = '\0'; |
---|
136 | phase->comment[0] = '\0'; |
---|
137 | phase->reliable = TRUE; |
---|
138 | |
---|
139 | } /* end of cu_reset_phase */ |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | /*---------------------------------------------------------------------------*/ |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | void cu_reset_parameters( CUT_PARAMS *par ) |
---|
148 | |
---|
149 | /* resets parameters to default values |
---|
150 | * |
---|
151 | * parameters of routine |
---|
152 | * CUT_PARAMS *par; parameters to be reset |
---|
153 | */ |
---|
154 | { |
---|
155 | /* executable code */ |
---|
156 | |
---|
157 | par->distance = 0.0; |
---|
158 | par->dist_unit = CUC_DIST_UNIT_DEG; |
---|
159 | par->b_slowness = 0.0; |
---|
160 | par->b_slowness_err = 0.0; |
---|
161 | par->b_azimuth = 0.0; |
---|
162 | par->b_azimuth_err = 0.0; |
---|
163 | par->l_slowness = 0.0; |
---|
164 | par->l_azimuth = 0.0; |
---|
165 | par->depth = GpGetFloat( cGpF_default_depth ); |
---|
166 | par->depth_type = GpGetInt( cGpI_default_depth_type ); |
---|
167 | par->origin[0] = '\0'; |
---|
168 | par->source_lat = 0.0; |
---|
169 | par->source_lon = 0.0; |
---|
170 | par->source_type = GpGetInt( cGpI_default_event_type ); |
---|
171 | par->center_lat = 0.0; |
---|
172 | par->center_lon = 0.0; |
---|
173 | par->ref_lat = 0; |
---|
174 | par->ref_lon = 0; |
---|
175 | par->reg_id = 0; |
---|
176 | par->regname[0] = '\0'; |
---|
177 | par->loc_meth = CUC_LOCMETH_UNDEFINED; |
---|
178 | par->loc_quality = GpGetInt( cGpI_default_loc_quality ); |
---|
179 | par->loc_addpar[0] = '\0'; |
---|
180 | par->velmod[0] = '\0'; |
---|
181 | par->momten[0] = '\0'; |
---|
182 | par->momten_descr[0] = '\0'; |
---|
183 | par->fps_angles[0] = '\0'; |
---|
184 | par->fps_descr[0] = '\0'; |
---|
185 | par->mu_descr[0] = '\0'; |
---|
186 | par->cornerfreq = 0.0; |
---|
187 | par->lowfreqlevel = 0.0; |
---|
188 | par->m0 = 0.0; |
---|
189 | par->stations_used = 0; |
---|
190 | par->phase[0] = '\0'; |
---|
191 | if (par->comment != NULL) |
---|
192 | sy_deallocmem( par->comment ); |
---|
193 | par->comment = NULL; |
---|
194 | par->source[0] = '\0'; |
---|
195 | par->soft_change = FALSE; |
---|
196 | par->flags = GpGetInt( cGpI_default_phase_flags ); |
---|
197 | par->err.lat = 0.0; |
---|
198 | par->err.lon = 0.0; |
---|
199 | par->err.dep = 0.0; |
---|
200 | par->err.orig = 0.0; |
---|
201 | par->err.smajor = 0.0; |
---|
202 | par->err.sminor = 0.0; |
---|
203 | par->err.majstrike = 0.0; |
---|
204 | par->err.dist_unit = CUC_DIST_UNIT_DEG; |
---|
205 | |
---|
206 | PiSbClearAll( &(par->slowbox) ); |
---|
207 | |
---|
208 | cu_clear_exec_flags(); |
---|
209 | |
---|
210 | } /* end of cu_reset_parameters */ |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | /*--------------------------------------------------------------------------*/ |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | void cu_reset_paramsets( CUT_PARAMSETS *parset ) |
---|
219 | |
---|
220 | /* resets all parameter sets |
---|
221 | * |
---|
222 | * parameters of routine |
---|
223 | * CUT_PARAMSETS *parset; output; parameter to be reset |
---|
224 | */ |
---|
225 | { |
---|
226 | /* local variables */ |
---|
227 | int i; /* counter */ |
---|
228 | |
---|
229 | /* executable code */ |
---|
230 | |
---|
231 | /* parset->state = CUC_PARSTATE_PROCESS; */ |
---|
232 | parset->evid = 0; |
---|
233 | parset->parno = 0; |
---|
234 | for (i=0; i<CUC_MAXPARSET; i++) |
---|
235 | cu_reset_parameters( parset->par+i ); |
---|
236 | |
---|
237 | } /* end of cu_reset_paramsets */ |
---|
238 | |
---|
239 | |
---|
240 | |
---|
241 | /*--------------------------------------------------------------------------*/ |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | void cu_set_read_time( Widget date, Widget time, float incr, TSyStatus *status ) |
---|
246 | |
---|
247 | /* increments read time by "incr" seconds |
---|
248 | * |
---|
249 | * parameters of routine |
---|
250 | * Widget date, time; input; Widget ID's for date and time text |
---|
251 | * float incr; input; time increment in seconds |
---|
252 | * TSyStatus *status; output; return status |
---|
253 | */ |
---|
254 | { |
---|
255 | /* local variables */ |
---|
256 | char *str; /* string pointer */ |
---|
257 | char timestr[BC_LINELTH+1]; /* time string */ |
---|
258 | NTIME ntime; /* numeric time */ |
---|
259 | int loopcnt; /* loop counter */ |
---|
260 | static int last_timestamp=0; /* last timestamp */ |
---|
261 | /* QueryPointer returns */ |
---|
262 | Window root, child; |
---|
263 | int root_x, root_y; |
---|
264 | int win_x, win_y; |
---|
265 | unsigned mask; |
---|
266 | |
---|
267 | /* executable code */ |
---|
268 | |
---|
269 | loopcnt = 0; |
---|
270 | |
---|
271 | do { |
---|
272 | |
---|
273 | str = cu_get_string( date ); |
---|
274 | strcpy( timestr, str ); |
---|
275 | cuh_strip_blanks( timestr ); |
---|
276 | strcat( timestr, "_" ); |
---|
277 | str = cu_get_string( time ); |
---|
278 | strcat( timestr, str ); |
---|
279 | cuh_strip_blanks( timestr ); |
---|
280 | if (incr == CUC_MONTH_INC) { |
---|
281 | tc_t2n( timestr, &ntime, status ); |
---|
282 | if (Severe(status)) return; |
---|
283 | if (++(ntime.month) > 12) { |
---|
284 | ntime.month = 1; |
---|
285 | (ntime.year)++; |
---|
286 | } /*endif*/ |
---|
287 | tc_n2t( &ntime, timestr, status ); |
---|
288 | } else if (incr == CUC_MONTH_DEC) { |
---|
289 | tc_t2n( timestr, &ntime, status ); |
---|
290 | if (Severe(status)) return; |
---|
291 | if (--(ntime.month) <= 0) { |
---|
292 | ntime.month = 12; |
---|
293 | (ntime.year)--; |
---|
294 | } /*endif*/ |
---|
295 | tc_n2t( &ntime, timestr, status ); |
---|
296 | } else if (incr == CUC_YEAR_INC) { |
---|
297 | tc_t2n( timestr, &ntime, status ); |
---|
298 | if (Severe(status)) return; |
---|
299 | (ntime.year)++; |
---|
300 | tc_n2t( &ntime, timestr, status ); |
---|
301 | } else if (incr == CUC_YEAR_DEC) { |
---|
302 | tc_t2n( timestr, &ntime, status ); |
---|
303 | if (Severe(status)) return; |
---|
304 | (ntime.year)--; |
---|
305 | tc_n2t( &ntime, timestr, status ); |
---|
306 | } else { |
---|
307 | tc_tadd( timestr, incr, timestr, status ); |
---|
308 | } /*endif*/ |
---|
309 | if (Severe(status)) return; |
---|
310 | timestr[11] = '\0'; |
---|
311 | timestr[20] = '\0'; |
---|
312 | cu_set_string( date, timestr ); |
---|
313 | cu_set_string( time, timestr+12 ); |
---|
314 | |
---|
315 | XQueryPointer( XtDisplay(date), XtWindow(date), &root, &child, |
---|
316 | &root_x, &root_y, &win_x, &win_y, &mask ); |
---|
317 | if (!(Button1Mask & mask)) break; |
---|
318 | |
---|
319 | if (loopcnt == 0) { |
---|
320 | cuh_wait( 5*WAIT_UNIT ); |
---|
321 | } else if (loopcnt >= 1) { |
---|
322 | cuh_wait( WAIT_UNIT ); |
---|
323 | } /*endif*/ |
---|
324 | |
---|
325 | XQueryPointer( XtDisplay(date), XtWindow(date), &root, &child, |
---|
326 | &root_x, &root_y, &win_x, &win_y, &mask ); |
---|
327 | |
---|
328 | loopcnt++; |
---|
329 | |
---|
330 | } while (Button1Mask & mask); |
---|
331 | |
---|
332 | } /* end of cu_set_read_time */ |
---|
333 | |
---|
334 | |
---|
335 | |
---|
336 | /*-----------------------------------------------------------------------*/ |
---|
337 | |
---|
338 | |
---|
339 | |
---|
340 | void cu_set_read_time_file( Widget w[], int mode, char autoevt[], |
---|
341 | TSyStatus *status ) |
---|
342 | |
---|
343 | /* reads next/previous time from file |
---|
344 | * |
---|
345 | * parameters of routine |
---|
346 | * Widget w[]; input; widget array |
---|
347 | * int mode; input; search mode |
---|
348 | * char autoevt[]; output; name of evt-file |
---|
349 | * TSyStatus *status; output; return status |
---|
350 | */ |
---|
351 | { |
---|
352 | /* local variables */ |
---|
353 | static int curr_line=0; /* current line count */ |
---|
354 | FILE *fp; /* file pointer */ |
---|
355 | char line[cBcLongStrLth+1]; /* current line */ |
---|
356 | char *c, *cp, *cc; /* pointers to char */ |
---|
357 | int i; /* line counter */ |
---|
358 | char timestr[BC_TIMELTH+1]; /* time string */ |
---|
359 | char file[BC_FILELTH+1]; /* input file */ |
---|
360 | int slen; /* string length */ |
---|
361 | int loopcnt; /* loop counter */ |
---|
362 | /* QueryPointer returns */ |
---|
363 | Window root, child; |
---|
364 | int root_x, root_y; |
---|
365 | int win_x, win_y; |
---|
366 | unsigned mask; |
---|
367 | |
---|
368 | /* executable code */ |
---|
369 | |
---|
370 | /* build filename */ |
---|
371 | c = cu_get_string( w[k_widget_read_grsn_eventfile_text] ); |
---|
372 | if (strlen(c) > BC_FILELTH) { |
---|
373 | *status = CUE_STROVFL; |
---|
374 | return; |
---|
375 | } /*endif*/ |
---|
376 | |
---|
377 | /* check whether filename is complete */ |
---|
378 | fp = sy_fopen( c, "r" ); |
---|
379 | if (fp == NULL) { |
---|
380 | /* no directory specified, take default directory */ |
---|
381 | slen = (int)strlen( GpGetString(cGpS_defpath_events) ); |
---|
382 | if (slen+strlen(c)+1 > BC_FILELTH) { |
---|
383 | *status = CUE_STROVFL; |
---|
384 | return; |
---|
385 | } /*endif*/ |
---|
386 | strcpy( file, GpGetString(cGpS_defpath_events) ); |
---|
387 | if (file[slen-1] != '/') |
---|
388 | strcat( file, "/" ); |
---|
389 | strcat( file, c ); |
---|
390 | /* open file */ |
---|
391 | fp = sy_fopen( file, "r" ); |
---|
392 | if (fp == NULL) { |
---|
393 | printf( "*SHM: file %s not found\n", c ); |
---|
394 | return; |
---|
395 | } /*endif*/ |
---|
396 | } else { |
---|
397 | /* directory is there, take it as it is */ |
---|
398 | strcpy( file, c ); |
---|
399 | } /*endif*/ |
---|
400 | |
---|
401 | loopcnt = 0; |
---|
402 | do { |
---|
403 | |
---|
404 | fseek( fp, 0, 0 ); |
---|
405 | |
---|
406 | if (mode == CUC_LIST_NEXT) { |
---|
407 | curr_line++; |
---|
408 | } else { |
---|
409 | curr_line--; |
---|
410 | } /*endif*/ |
---|
411 | if (curr_line <= 0) curr_line = 1; |
---|
412 | |
---|
413 | i = 0; |
---|
414 | *line = '\0'; |
---|
415 | while (i < curr_line) { |
---|
416 | if (fgets(line,cBcLongStrLth,fp) == NULL) |
---|
417 | curr_line--; |
---|
418 | if (*line != '!') i++; |
---|
419 | } /*endwhile*/ |
---|
420 | |
---|
421 | sprintf( timestr, "%d", curr_line ); |
---|
422 | cu_set_string( w[k_widget_read_grsn_eventno_text], timestr ); |
---|
423 | |
---|
424 | /* read and then remove remainder of line (after time string) */ |
---|
425 | *autoevt = '\0'; |
---|
426 | if (*line == '\0') {sy_fclose( fp ); return;} |
---|
427 | i = (int)strlen( line ) - 1; |
---|
428 | if (line[i] == '\n') line[i] = '\0'; |
---|
429 | c = line; |
---|
430 | while (*c != '\0' && *c == ' ') |
---|
431 | c++; |
---|
432 | cp = c; |
---|
433 | while (*cp != '\0' && *cp != ' ') |
---|
434 | cp++; |
---|
435 | /* remove remainder and put it to autoevt */ |
---|
436 | if (*cp != '\0') { |
---|
437 | *cp++ = '\0'; |
---|
438 | while (*cp != '\0' && *cp == ' ') cp++; |
---|
439 | cc = cp; |
---|
440 | while (*cc != ' ' && *cc != '\0') cc++; |
---|
441 | if (*cp != '\0') { |
---|
442 | if ((cc-cp) > BC_FILELTH) { |
---|
443 | *status = CUE_STROVFL; |
---|
444 | sy_fclose( fp ); |
---|
445 | return; |
---|
446 | } /*endif*/ |
---|
447 | sscanf( cp, "%s", autoevt ); |
---|
448 | } /*endif*/ |
---|
449 | } /*endif*/ |
---|
450 | |
---|
451 | /* reformat time string */ |
---|
452 | tc_tadd( c, 0.0, timestr, status ); |
---|
453 | if (Severe(status)) {sy_fclose( fp ); return;} |
---|
454 | |
---|
455 | timestr[11] = '\0'; |
---|
456 | timestr[20] = '\0'; |
---|
457 | cu_set_string( w[k_widget_read_grsn_date], timestr ); |
---|
458 | cu_set_string( w[k_widget_read_grsn_time], timestr+12 ); |
---|
459 | |
---|
460 | if (loopcnt == 0) { |
---|
461 | cuh_wait( 5*WAIT_UNIT ); |
---|
462 | } else if (loopcnt >= 1) { |
---|
463 | cuh_wait( WAIT_UNIT ); |
---|
464 | } /*endif*/ |
---|
465 | |
---|
466 | XQueryPointer( XtDisplay(w[k_widget_read_grsn_date]), |
---|
467 | XtWindow(w[k_widget_read_grsn_date]), &root, &child, |
---|
468 | &root_x, &root_y, &win_x, &win_y, &mask ); |
---|
469 | |
---|
470 | loopcnt++; |
---|
471 | |
---|
472 | } while (Button1Mask & mask); |
---|
473 | |
---|
474 | sy_fclose( fp ); |
---|
475 | |
---|
476 | } /* end of cu_set_read_time_file */ |
---|
477 | |
---|
478 | |
---|
479 | |
---|
480 | /*-----------------------------------------------------------------------*/ |
---|
481 | |
---|
482 | |
---|
483 | |
---|
484 | void cu_current_time( char str[] ) |
---|
485 | |
---|
486 | /* returns current time. Minimum length of str is 21 |
---|
487 | * |
---|
488 | * parameter of routine |
---|
489 | * char str[]; output; time string |
---|
490 | */ |
---|
491 | { |
---|
492 | /* local variable */ |
---|
493 | char s[81]; |
---|
494 | time_t ct; |
---|
495 | |
---|
496 | /* executable code */ |
---|
497 | |
---|
498 | ct = time( NULL ); |
---|
499 | strcpy( s, ctime(&ct) ); |
---|
500 | strncpy( str, s+8, 2 ); /* dd */ |
---|
501 | str[2] = '-'; /* dd- */ |
---|
502 | strncpy( str+3, s+4, 3 ); /* dd-mmm */ |
---|
503 | str[6] = '-'; /* dd-mmm- */ |
---|
504 | strncpy( str+7, s+20, 4 ); /* dd-mmm-yyyy */ |
---|
505 | str[11] = '_'; /* dd-mmm-yyyy_ */ |
---|
506 | strncpy( str+12, s+11, 8 ); /* dd-mmm-yyyy_hh:mm:ss */ |
---|
507 | str[20] = '\0'; |
---|
508 | |
---|
509 | } /* end of cu_current_time */ |
---|
510 | |
---|
511 | |
---|
512 | |
---|
513 | /*--------------------------------------------------------------------------*/ |
---|
514 | |
---|
515 | |
---|
516 | |
---|
517 | static void cuh_strip_blanks( char str[] ) |
---|
518 | |
---|
519 | /* removes blanks at beginning and end of string |
---|
520 | * |
---|
521 | * parameters of routine |
---|
522 | * char str[]; modify; string to remove blanks |
---|
523 | */ |
---|
524 | { |
---|
525 | /* local variables */ |
---|
526 | int slen; /* string length */ |
---|
527 | |
---|
528 | /* executable code */ |
---|
529 | |
---|
530 | while (*str == ' ') |
---|
531 | strcpy( str, str+1 ); |
---|
532 | |
---|
533 | slen = strlen( str ) - 1; |
---|
534 | while (str[slen] == ' ') |
---|
535 | str[slen--] = '\0'; |
---|
536 | |
---|
537 | } /* end of cuh_strip_blanks */ |
---|
538 | |
---|
539 | |
---|
540 | |
---|
541 | /*--------------------------------------------------------------------------*/ |
---|
542 | |
---|
543 | |
---|
544 | |
---|
545 | static void cuh_wait( int cnt ) |
---|
546 | |
---|
547 | /* wait loop |
---|
548 | * |
---|
549 | * parameters of routine |
---|
550 | * int cnt; input; loop counter |
---|
551 | */ |
---|
552 | { |
---|
553 | /* local variables */ |
---|
554 | float dmy; |
---|
555 | |
---|
556 | /* executable code */ |
---|
557 | |
---|
558 | #ifdef XXX |
---|
559 | dmy = 1000.0; |
---|
560 | while (cnt-- > 0) { |
---|
561 | dmy = sqrt( dmy ); |
---|
562 | dmy = pow( dmy, 2.0 ); |
---|
563 | } /*endwhile*/ |
---|
564 | #endif |
---|
565 | |
---|
566 | usleep( 3*cnt ); |
---|
567 | |
---|
568 | } /* end of cuh_wait */ |
---|
569 | |
---|
570 | |
---|
571 | |
---|
572 | /*--------------------------------------------------------------------------*/ |
---|
573 | |
---|
574 | |
---|
575 | |
---|
576 | void cu_accept_phase( Widget wm, Widget ws, TPiPhase *phase, TPmTrace *phtrc, |
---|
577 | TSyBoolean acc, TSyStatus *status ) |
---|
578 | |
---|
579 | /* accepts a phase from dialog box |
---|
580 | * |
---|
581 | * parameters of routine |
---|
582 | * Widget wm; input; main window |
---|
583 | * Widget ws; input; single trace window |
---|
584 | * TPiPhase *phase; input; pointer to phase info |
---|
585 | * TPmTrace *phtrc; input; pointer to trace |
---|
586 | * TSyBoolean acc; input; show accuracies of phases |
---|
587 | * TSyStatus *status; output; returns status if no NULL |
---|
588 | */ |
---|
589 | { |
---|
590 | /* local variables */ |
---|
591 | TSyStatus locstat=BC_NOERROR; /* local status */ |
---|
592 | |
---|
593 | /* executable code */ |
---|
594 | |
---|
595 | PmAddPhase( phtrc, phase, status ); |
---|
596 | if (SySevere(status)) return; |
---|
597 | |
---|
598 | mg_do_phase( (Widget)0, MGC_WDW_LAST, MGC_PHASE_CLEAR, |
---|
599 | 0, 0, NULL, NULL, NULL ); |
---|
600 | mg_mark_one_phase( wm, ws, phase, phtrc, acc ); |
---|
601 | |
---|
602 | } /* end of cu_accept_phase */ |
---|
603 | |
---|
604 | |
---|
605 | |
---|
606 | /*--------------------------------------------------------------------------*/ |
---|
607 | |
---|
608 | |
---|
609 | |
---|
610 | void cu_phase_box_defaults( Widget w[], TPiPhase *phase ) |
---|
611 | |
---|
612 | /* sets button states of phase box |
---|
613 | * |
---|
614 | * parameters of routine |
---|
615 | * Widget w[]; input; widget array |
---|
616 | * TPiPhase *phase; input; phase info |
---|
617 | */ |
---|
618 | { |
---|
619 | /* local variables */ |
---|
620 | Arg al[1]; /* argument list */ |
---|
621 | int qual_widget; /* quality button */ |
---|
622 | |
---|
623 | /* executable code */ |
---|
624 | |
---|
625 | cu_set_string( w[k_widget_phase_name_text], phase->name ); |
---|
626 | XmToggleButtonSetState( w[k_widget_phase_spec_e], |
---|
627 | (phase->spec == cPiSpecEmergent), FALSE ); |
---|
628 | XmToggleButtonSetState( w[k_widget_phase_spec_i], |
---|
629 | (phase->spec == cPiSpecImpulsive), FALSE ); |
---|
630 | XmToggleButtonSetState( w[k_widget_phase_sign_p], |
---|
631 | (phase->sign > 0), FALSE ); |
---|
632 | XmToggleButtonSetState( w[k_widget_phase_sign_m], |
---|
633 | (phase->sign < 0), FALSE ); |
---|
634 | XmToggleButtonSetState( w[k_widget_phase_sign_0], |
---|
635 | (phase->sign == 0), FALSE ); |
---|
636 | XmToggleButtonSetState( w[k_widget_phase_reliab_yes], |
---|
637 | phase->reliable, FALSE ); |
---|
638 | XmToggleButtonSetState( w[k_widget_phase_reliab_no], |
---|
639 | !(phase->reliable), FALSE ); |
---|
640 | |
---|
641 | if (phase->quality < 1) phase->quality = 1; |
---|
642 | if (phase->quality > 9) phase->quality = 9; |
---|
643 | qual_widget = k_widget_phase_qual_0 + phase->quality; |
---|
644 | XtSetArg( al[0], XmNmenuHistory, w[qual_widget] ); |
---|
645 | XtSetValues( w[k_widget_phase_weight_option], al, 1 ); |
---|
646 | |
---|
647 | } /* end of cu_phase_box_defaults */ |
---|
648 | |
---|
649 | |
---|
650 | |
---|
651 | /*--------------------------------------------------------------------------*/ |
---|
652 | |
---|
653 | |
---|
654 | |
---|
655 | #define SH_DEBUG |
---|
656 | |
---|
657 | #define CLEAR_AND_RETURN \ |
---|
658 | sy_deallocmem( delay ); \ |
---|
659 | sy_deallocmem( lat ); \ |
---|
660 | sy_deallocmem( xcp ); \ |
---|
661 | sy_deallocmem( code ); \ |
---|
662 | return; |
---|
663 | |
---|
664 | #define CODELTH 7 |
---|
665 | |
---|
666 | |
---|
667 | |
---|
668 | void cu_localization( char phasename[], int do_flags, CUT_PARAMS *par, |
---|
669 | TSyStatus *status ) |
---|
670 | |
---|
671 | /* performs localization of event, using marked phases of type "phasename". |
---|
672 | * If CUF_DOLOC_SLOAZ is specified in "do_flags" than slowness and azimuth |
---|
673 | * is determined from a plane wave approximation. If CUF_DOLOC_DISTANCE |
---|
674 | * is specified the distance in degrees for the given phase and the current |
---|
675 | * slowness value is computed using the appropriate travel time table. |
---|
676 | * |
---|
677 | * parameters of routine |
---|
678 | * char phasename[]; input; name of phase to be used |
---|
679 | * int do_flags; input; CUF_DOLOC_SLOAZ and/or CUF_DOLOC_DISTANCE |
---|
680 | * CUT_PARAMS *par; input/output; analysis parameters |
---|
681 | * TSyStatus *status; output; return status |
---|
682 | */ |
---|
683 | { |
---|
684 | /* local variables */ |
---|
685 | int alloclth; /* array length to allocate */ |
---|
686 | float *delay; /* pointer to time delays */ |
---|
687 | float *x, *y; /* pointer to relative coordinate */ |
---|
688 | float *shift; /* time shifts */ |
---|
689 | float *resid; /* station residuals to plane wave */ |
---|
690 | STATLOC *lat, *lon; /* pointer to station locations */ |
---|
691 | char *code; /* station codes */ |
---|
692 | int codepos; /* code string position */ |
---|
693 | TSyBoolean same_array; /* use relative or absolute locations */ |
---|
694 | int listlth; /* number of phases found */ |
---|
695 | int t; /* trace counter */ |
---|
696 | void *trc; /* current trace pointer */ |
---|
697 | char station[BC_LINELTH+1]; /* name of current station */ |
---|
698 | GLT_STATINF *statinf; /* pointer to station info */ |
---|
699 | int arrcode; /* array code */ |
---|
700 | char *onset; /* pointer to onset time */ |
---|
701 | char firsttime[BC_TIMELTH+1]; /* onset time of first trace */ |
---|
702 | char reftime[BC_TIMELTH+1]; /* reference time */ |
---|
703 | float dt; /* sample distance in sec */ |
---|
704 | TSyBoolean same_dt; /* same sample distance */ |
---|
705 | float travtime; /* trave time */ |
---|
706 | int loc_method; /* location method */ |
---|
707 | TSyBoolean german_event; /* this is a german event (roughly) */ |
---|
708 | float ref_shift; /* time shift betw. first and ref. trace */ |
---|
709 | STATLOC clat, clon; /* location of center */ |
---|
710 | float u_azim; /* used azimuth */ |
---|
711 | double dbl_dist, dbl_azim, dbl_bazim; /* double results of locdiff */ |
---|
712 | float *xcp, *ycp, *tcp; /* backup values */ |
---|
713 | float residcorr; /* residual correction */ |
---|
714 | int ii; /* counter */ |
---|
715 | TPiPhaseRoot *proot; /* pointer to phase root */ |
---|
716 | TPiPhaseList *plist; /* pointer to phase list */ |
---|
717 | TPiPhase *resphase; /* pointer to phase */ |
---|
718 | TSyStatus locstat; /* local status */ |
---|
719 | float residrms; /* root mean square residual */ |
---|
720 | |
---|
721 | /* executable code */ |
---|
722 | |
---|
723 | alloclth = mg_dsptrcs(); |
---|
724 | if (alloclth == 0) { |
---|
725 | *status = CUE_NOTRACES; |
---|
726 | return; |
---|
727 | } /*endif*/ |
---|
728 | |
---|
729 | /* allocate memory */ |
---|
730 | delay = (float *)sy_allocmem( (alloclth+1)*5, (int)sizeof(float), status ); |
---|
731 | if (Severe(status)) return; |
---|
732 | lat = (STATLOC *)sy_allocmem( (alloclth+1)*2, (int)sizeof(STATLOC), status ); |
---|
733 | if (Severe(status)) {sy_deallocmem(delay); return;} |
---|
734 | x = delay + alloclth+1; |
---|
735 | y = x + alloclth+1; |
---|
736 | shift = y + alloclth+1; |
---|
737 | resid = shift + alloclth+1; |
---|
738 | lon = lat + alloclth+1; |
---|
739 | xcp = (float *)sy_allocmem( (alloclth+1)*3, (int)sizeof(float), status ); |
---|
740 | if (Severe(status)) {sy_deallocmem(delay); sy_deallocmem(lat); return;} |
---|
741 | ycp = xcp + alloclth+1; |
---|
742 | tcp = ycp + alloclth+1; |
---|
743 | code = (char *)sy_allocmem( (alloclth+1)*(CODELTH+1), |
---|
744 | (int)sizeof(char), status ); |
---|
745 | if (Severe(status)) {sy_deallocmem(delay); sy_deallocmem(lat); |
---|
746 | sy_deallocmem(xcp); return;} |
---|
747 | |
---|
748 | /* get delays and positions */ |
---|
749 | listlth = 0; |
---|
750 | same_array = TRUE; |
---|
751 | *firsttime = *reftime = '\0'; |
---|
752 | dt = 0.0; |
---|
753 | same_dt = TRUE; |
---|
754 | arrcode = -1; |
---|
755 | clat = clon = 0.0; |
---|
756 | codepos = 0; |
---|
757 | trc = NULL; |
---|
758 | for (t=0; t<alloclth; t++) { |
---|
759 | trc = db_getp( trc, EP_DSPN, status ); |
---|
760 | if (SySevere(status)) {CLEAR_AND_RETURN} |
---|
761 | /* get name of station */ |
---|
762 | db_gets( trc, ES_STATION, BC_LINELTH, station, status ); |
---|
763 | if (Severe(status)) {CLEAR_AND_RETURN} |
---|
764 | strncpy( code+codepos, station, CODELTH ); |
---|
765 | codepos += CODELTH+1; |
---|
766 | /* check for phase onset on BEAM if reference station is CENTRE */ |
---|
767 | if (strcmp(station,"BEAM") == 0 || strcmp(station,"ALIGN") == 0) { |
---|
768 | if (strcmp(GpGetString(cGpS_refstation),"CENTRE") != 0 |
---|
769 | && strcmp(GpGetString(cGpS_refstation),"CENTER") != 0) |
---|
770 | continue; |
---|
771 | cuh_phase_onset( phasename, trc, &onset, &residcorr ); |
---|
772 | if (onset == NULL) continue; |
---|
773 | strcpy( reftime, onset ); |
---|
774 | continue; |
---|
775 | } /*endif*/ |
---|
776 | /* retrieve station info */ |
---|
777 | statinf = (GLT_STATINF *)db_getp( trc, EP_STAT, status ); |
---|
778 | if (statinf == NULL) { |
---|
779 | *status = BC_NOERROR; |
---|
780 | statinf = gl_store_station( station, TRUE, status ); |
---|
781 | if (Severe(status)) {CLEAR_AND_RETURN} |
---|
782 | db_setp( trc, EP_STAT, statinf, status ); |
---|
783 | if (Severe(status)) {CLEAR_AND_RETURN} |
---|
784 | } /*endif*/ |
---|
785 | /* get phase onset time */ |
---|
786 | cuh_phase_onset( phasename, trc, &onset, &residcorr ); |
---|
787 | if (onset == NULL) continue; |
---|
788 | /* if reference station is in selected list, store onset */ |
---|
789 | if (strcmp(station,GpGetString(cGpS_refstation)) == 0) |
---|
790 | strcpy( reftime, onset ); |
---|
791 | /* store station location */ |
---|
792 | lat[listlth] = statinf->lat; |
---|
793 | lon[listlth] = statinf->lon; |
---|
794 | x[listlth] = statinf->xrel; |
---|
795 | y[listlth] = statinf->yrel; |
---|
796 | clat += statinf->lat; |
---|
797 | clon += statinf->lon; |
---|
798 | /* check whether to use relative or absolute location */ |
---|
799 | if (arrcode < 0) arrcode = statinf->arr_id; |
---|
800 | if (statinf->arr_id != arrcode) same_array = FALSE; |
---|
801 | /* store onset time on first trace and relative delays */ |
---|
802 | if (*firsttime == '\0') { |
---|
803 | strcpy( firsttime, onset ); |
---|
804 | delay[listlth] = 0.0; |
---|
805 | } else { |
---|
806 | delay[listlth] = tc_tdiff( onset, firsttime, status ); |
---|
807 | if (Severe(status)) {CLEAR_AND_RETURN} |
---|
808 | } /*endif*/ |
---|
809 | if (par->loc_meth == CUC_LOCMETH_RESIDCORR) { |
---|
810 | delay[listlth] -= residcorr; |
---|
811 | /* printf( "*SHM: apply residual correction\n" ); */ |
---|
812 | } /*endif*/ |
---|
813 | /* check for the sample rate */ |
---|
814 | if (dt == 0.0) { |
---|
815 | dt = db_getr( trc, ER_DELTA, NULL ); |
---|
816 | } else { |
---|
817 | if (db_getr(trc,ER_DELTA,NULL) != dt) |
---|
818 | same_dt = FALSE; |
---|
819 | } /*endif*/ |
---|
820 | listlth++; |
---|
821 | } /*endfor*/ |
---|
822 | |
---|
823 | if (arrcode == 0) |
---|
824 | same_array = FALSE; |
---|
825 | |
---|
826 | /* get position of reference station */ |
---|
827 | cu_reference_location( lat+listlth, lon+listlth, x+listlth, |
---|
828 | y+listlth, &arrcode, status ); |
---|
829 | if (Severe(status)) {CLEAR_AND_RETURN} |
---|
830 | |
---|
831 | #ifdef XXX |
---|
832 | if (!same_array) { |
---|
833 | if (GpGetInt(cGpI_debug_level) > 2) |
---|
834 | printf( "SHM-dbg3: rel. location from (lat,lon) recomputed.\n" ); |
---|
835 | mt_deg_to_km( listlth+1, lat, lon, x, y ); |
---|
836 | } /*endif*/ |
---|
837 | #endif |
---|
838 | mb_deg_to_km( listlth+1, lat, lon, x, y ); |
---|
839 | |
---|
840 | for (t=0; t<=listlth; t++) |
---|
841 | printf( "%lf %lf %f %f\n", lat[t], lon[t], x[t], y[t] ); |
---|
842 | |
---|
843 | |
---|
844 | if (listlth < 3 && (CUF_DOLOC_SLOAZ & do_flags)) { |
---|
845 | |
---|
846 | *status = CUE_TOOLESS; |
---|
847 | CLEAR_AND_RETURN |
---|
848 | |
---|
849 | } else if (CUF_DOLOC_SLOAZ & do_flags) { |
---|
850 | |
---|
851 | /* check delta-t if only three traces */ |
---|
852 | if (listlth == 3 && !same_dt) { |
---|
853 | *status = SHE_DIFFSAMP; |
---|
854 | CLEAR_AND_RETURN |
---|
855 | } /*endif*/ |
---|
856 | |
---|
857 | /* perform location */ |
---|
858 | /* it does not matter that "delay" is relative to */ |
---|
859 | /* "firsttime" instead of "reftime" */ |
---|
860 | /* save values */ |
---|
861 | for (ii=0; ii<listlth; ii++) { |
---|
862 | tcp[ii] = delay[ii]; |
---|
863 | xcp[ii] = x[ii]; |
---|
864 | ycp[ii] = y[ii]; |
---|
865 | } /*endfor*/ |
---|
866 | # ifdef SH_DEBUG |
---|
867 | mt_locate_old( listlth, delay, x, y, dt, |
---|
868 | &(par->b_azimuth), &(par->b_azimuth_err), &(par->b_slowness), |
---|
869 | &(par->b_slowness_err), status ); |
---|
870 | /* restore values */ |
---|
871 | for (ii=0; ii<listlth; ii++) { |
---|
872 | delay[ii] = tcp[ii]; |
---|
873 | x[ii] = xcp[ii]; |
---|
874 | y[ii] = ycp[ii]; |
---|
875 | } /*endfor*/ |
---|
876 | mt_locate_svd( listlth, delay, x, y, dt, |
---|
877 | &(par->b_azimuth), &(par->b_azimuth_err), &(par->b_slowness), |
---|
878 | &(par->b_slowness_err), status ); |
---|
879 | /* restore values */ |
---|
880 | for (ii=0; ii<listlth; ii++) { |
---|
881 | delay[ii] = tcp[ii]; |
---|
882 | x[ii] = xcp[ii]; |
---|
883 | y[ii] = ycp[ii]; |
---|
884 | } /*endfor*/ |
---|
885 | # endif |
---|
886 | par->l_slowness = par->l_azimuth = 0.0; |
---|
887 | mt_locate( listlth, delay, x, y, dt, |
---|
888 | &(par->b_azimuth), &(par->b_azimuth_err), &(par->b_slowness), |
---|
889 | &(par->b_slowness_err), status ); |
---|
890 | if (Severe(status)) {CLEAR_AND_RETURN} |
---|
891 | /* restore values */ |
---|
892 | for (ii=0; ii<listlth; ii++) { |
---|
893 | delay[ii] = tcp[ii]; |
---|
894 | x[ii] = xcp[ii]; |
---|
895 | y[ii] = ycp[ii]; |
---|
896 | } /*endfor*/ |
---|
897 | mt_locate_old_error( listlth, delay, x, y, |
---|
898 | par->b_azimuth, par->b_slowness, resid ); |
---|
899 | /* par->b_azimuth -= 180.0; */ |
---|
900 | /* if (par->b_azimuth < 0.0) par->b_azimuth += 360.0; */ |
---|
901 | par->l_slowness = 0.0; |
---|
902 | par->l_azimuth = 0.0; |
---|
903 | par->stations_used = listlth; |
---|
904 | clat /= (STATLOC)listlth; |
---|
905 | clon /= (STATLOC)listlth; |
---|
906 | par->center_lat = clat; |
---|
907 | par->center_lon = clon; |
---|
908 | |
---|
909 | /* insert residuals, loop all phases */ |
---|
910 | codepos = 0; |
---|
911 | proot = NULL; |
---|
912 | residrms = 0.0; |
---|
913 | ii = 0; |
---|
914 | FOREVER { |
---|
915 | proot = PiNextPhaseRoot( proot ); |
---|
916 | if (proot == NULL) break; |
---|
917 | plist = PiPhaseListOfRoot( proot ); |
---|
918 | if (plist == NULL) continue; |
---|
919 | strcpy( station, PiStationOfRoot(proot) ); |
---|
920 | codepos = 0; |
---|
921 | for (t=0; t<alloclth; t++) { |
---|
922 | if (strcmp(code+codepos,station) == 0) { |
---|
923 | resphase = PiFindPhase( plist, phasename ); |
---|
924 | if (resphase == NULL) break; |
---|
925 | resphase->resid = resid[t]; |
---|
926 | resphase->resid_type = cPiResidPlaneWave; |
---|
927 | residrms += (resid[t])*(resid[t]); |
---|
928 | ii++; |
---|
929 | break; |
---|
930 | } /*endif*/ |
---|
931 | codepos += CODELTH+1; |
---|
932 | } /*endfor*/ |
---|
933 | } /*endfor*/ |
---|
934 | residrms = sqrt( residrms / (float)ii ); |
---|
935 | printf( "*SHM: mean root square residual: %5.2f\n", residrms ); |
---|
936 | |
---|
937 | } else { |
---|
938 | |
---|
939 | } /*endif*/ |
---|
940 | |
---|
941 | /* store phase in parameter block */ |
---|
942 | strcpy( par->phase, phasename ); |
---|
943 | |
---|
944 | if (!(CUF_DOLOC_DISTANCE & do_flags)) {CLEAR_AND_RETURN} |
---|
945 | |
---|
946 | if (*phasename == 'b') { |
---|
947 | /* the following doesn't make sense for beam selections */ |
---|
948 | *status = CUE_DUMMY_PHASE; |
---|
949 | err_setcontext( " ## phase "); err_setcontext( phasename ); |
---|
950 | CLEAR_AND_RETURN |
---|
951 | } /*endif*/ |
---|
952 | |
---|
953 | /* compute distance */ |
---|
954 | if (par->loc_meth == CUC_LOCMETH_RESIDCORR) { |
---|
955 | loc_method = CUC_LOCMETH_RESIDCORR; |
---|
956 | } else { |
---|
957 | loc_method = (par->l_slowness == 0.0 && par->l_azimuth == 0.0) ? |
---|
958 | CUC_LOCMETH_BEAMUNCORR : CUC_LOCMETH_BEAMCORR; |
---|
959 | } /*endif*/ |
---|
960 | if (loc_method == CUC_LOCMETH_BEAMUNCORR |
---|
961 | || loc_method == CUC_LOCMETH_RESIDCORR) { |
---|
962 | par->distance = pt_distance( phasename, par->b_slowness, |
---|
963 | par->depth, status ); |
---|
964 | if (*reftime == '\0') |
---|
965 | mt_beamshift( listlth+1, x,y, par->b_azimuth, par->b_slowness, shift ); |
---|
966 | } else { |
---|
967 | par->distance = pt_distance( phasename, par->l_slowness, |
---|
968 | par->depth, status ); |
---|
969 | if (*reftime == '\0') |
---|
970 | mt_beamshift( listlth+1, x,y, par->l_azimuth, par->l_slowness, shift ); |
---|
971 | } /*endif*/ |
---|
972 | par->dist_unit = CUC_DIST_UNIT_DEG; |
---|
973 | if (Severe(status)) {par->distance = 0.0; CLEAR_AND_RETURN} |
---|
974 | par->loc_meth = loc_method; |
---|
975 | if (*reftime == '\0') ref_shift = *shift - shift[listlth]; |
---|
976 | |
---|
977 | /* get location of reference station */ |
---|
978 | par->ref_lat = lat[listlth]; |
---|
979 | par->ref_lon = lon[listlth]; |
---|
980 | |
---|
981 | sy_deallocmem( delay ); |
---|
982 | sy_deallocmem( lat ); |
---|
983 | sy_deallocmem( xcp ); |
---|
984 | sy_deallocmem( code ); |
---|
985 | |
---|
986 | /* get coordinates of source */ |
---|
987 | if (GpGetInt(cGpI_debug_level) > 2) |
---|
988 | printf( "SHM-dbg3: source region computed on sphere !\n" ); |
---|
989 | if (par->loc_meth == CUC_LOCMETH_BEAMUNCORR |
---|
990 | || par->loc_meth == CUC_LOCMETH_RESIDCORR) { |
---|
991 | mb_sphereadd( par->ref_lat, par->ref_lon, par->distance, |
---|
992 | par->b_azimuth, &(par->source_lat), &(par->source_lon) ); |
---|
993 | } else { |
---|
994 | mb_sphereadd( par->ref_lat, par->ref_lon, par->distance, |
---|
995 | par->l_azimuth, &(par->source_lat), &(par->source_lon) ); |
---|
996 | } /*endif*/ |
---|
997 | #ifdef XXXNEW |
---|
998 | if (par->center_lat == 0.0 && par->center_lon == 0.0) { |
---|
999 | *status = CUE_NOCENTER; |
---|
1000 | return; |
---|
1001 | } /*endif*/ |
---|
1002 | u_azim = (par->loc_meth == CUC_LOCMETH_BEAMUNCORR |
---|
1003 | || par->loc_meth == CUC_LOCMETH_RESIDCORR) ? |
---|
1004 | par->b_azimuth : par->l_azimuth; |
---|
1005 | mb_sphereadd( par->center_lat, par->center_lon, par->distance, |
---|
1006 | u_azim, &(par->source_lat), &(par->source_lon) ); |
---|
1007 | mb_locdiff( par->ref_lat, par->ref_lon, par->source_lat, par->source_lon, |
---|
1008 | &dbl_dist, &dbl_azim, &dbl_bazim ); |
---|
1009 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
1010 | printf( "SHM-dbg2: center (%5.2f,%5.2f) ref (%5.2lf,%5.2lf)\n", |
---|
1011 | par->distance, u_azim, dbl_dist, dbl_bazim ): |
---|
1012 | /* distance & azimuth in 'par' setzen */ |
---|
1013 | #endif |
---|
1014 | |
---|
1015 | /* get name of source region */ |
---|
1016 | german_event = cu_german_event( par->source_lat, par->source_lon ); |
---|
1017 | if (german_event) { |
---|
1018 | xxx_get_geo( &(par->source_lat), &(par->source_lon), |
---|
1019 | &(par->reg_id), par->regname ); |
---|
1020 | if (par->reg_id < 0) { |
---|
1021 | *status = CUE_NOGETGEO; |
---|
1022 | err_setcontext( " ## getgeo error " ); |
---|
1023 | err_setcontext_l( par->reg_id ); |
---|
1024 | return; |
---|
1025 | } /*endif*/ |
---|
1026 | par->table_number = CUC_REGTABLE_GERGEO; |
---|
1027 | } else { |
---|
1028 | mb_ferindex( par->source_lat, par->source_lon, &(par->reg_id), status ); |
---|
1029 | if (Severe(status)) return; |
---|
1030 | mb_fername( par->reg_id, BC_LINELTH, par->regname, status ); |
---|
1031 | if (Severe(status)) return; |
---|
1032 | par->table_number = CUC_REGTABLE_FLINNENG; |
---|
1033 | } /*endif*/ |
---|
1034 | par->loc_quality = CUC_LOCQ_RELIABLE; |
---|
1035 | |
---|
1036 | /* reset source of information */ |
---|
1037 | par->source[0] = '\0'; |
---|
1038 | |
---|
1039 | if (!(CUF_DOLOC_ORIGIN & do_flags)) return; |
---|
1040 | |
---|
1041 | /* get origin time, onset time on reference station is in reftime */ |
---|
1042 | travtime = pt_travel( phasename, par->distance, par->depth, status ); |
---|
1043 | if (Severe(status)) return; |
---|
1044 | if (*reftime == '\0') { |
---|
1045 | tc_tadd( firsttime, ref_shift, reftime, status ); |
---|
1046 | } /*endif*/ |
---|
1047 | tc_tadd( reftime, -travtime, par->origin, status ); |
---|
1048 | if (Severe(status)) return; |
---|
1049 | |
---|
1050 | } /* end of cu_localization */ |
---|
1051 | |
---|
1052 | |
---|
1053 | |
---|
1054 | #undef CLEAR_AND_RETURN |
---|
1055 | |
---|
1056 | |
---|
1057 | |
---|
1058 | /*--------------------------------------------------------------------------*/ |
---|
1059 | |
---|
1060 | |
---|
1061 | |
---|
1062 | static void cuh_phase_onset( char phase[], TPmTrace *trc, char **onset, |
---|
1063 | float *residcorr ) |
---|
1064 | |
---|
1065 | /* checks whether phase is marked in trc, returns onset time or NULL |
---|
1066 | * |
---|
1067 | * parameters of routine |
---|
1068 | * char phase[]; input; phase name |
---|
1069 | * TPmTrace *trc; input; pointer to trace info |
---|
1070 | * char **onset; output; pointer to onset time |
---|
1071 | * float *residcorr; output; residual correction (or cPiResidCorrEmpty) |
---|
1072 | */ |
---|
1073 | { |
---|
1074 | /* local variables */ |
---|
1075 | TPiPhaseList *phaselist; /* pointer to phase list */ |
---|
1076 | TPiPhase *c_phase; /* pointer to current phase */ |
---|
1077 | TSyStatus locstat=BC_NOERROR; /* local status */ |
---|
1078 | int p; /* phase counter */ |
---|
1079 | |
---|
1080 | /* executable code */ |
---|
1081 | |
---|
1082 | phaselist = PmGetPhaseList( trc ); |
---|
1083 | if (phaselist == NULL) { |
---|
1084 | *onset = NULL; |
---|
1085 | return; |
---|
1086 | } /*endif*/ |
---|
1087 | for (p=0; p<PiPhaseListLength(phaselist); p++) { |
---|
1088 | c_phase = PiGetPhase( phaselist, p, NULL ); |
---|
1089 | if (strcmp(c_phase->name,phase) == 0 |
---|
1090 | && c_phase->source != cPiSourceTheo) { |
---|
1091 | *onset = c_phase->onset; |
---|
1092 | *residcorr = c_phase->resid_corr; |
---|
1093 | return; |
---|
1094 | } /*endif*/ |
---|
1095 | } /*endfor*/ |
---|
1096 | *onset = NULL; |
---|
1097 | return; |
---|
1098 | |
---|
1099 | } /* end of cuh_phase_onset */ |
---|
1100 | |
---|
1101 | |
---|
1102 | |
---|
1103 | /*--------------------------------------------------------------------------*/ |
---|
1104 | |
---|
1105 | |
---|
1106 | |
---|
1107 | void cu_set_param_values( Widget w[], CUT_PARAMS *par, int parno ) |
---|
1108 | |
---|
1109 | /* sets values of parameter block to dialog box. If distance in deg is |
---|
1110 | * smaller than 5 it is recomputed into km. |
---|
1111 | * |
---|
1112 | * parameters of routine |
---|
1113 | * Widget w[]; input; widget array |
---|
1114 | * CUT_PARAMS *par; input/modify; parameter values |
---|
1115 | * int parno; input; number of parameter set |
---|
1116 | */ |
---|
1117 | { |
---|
1118 | /* local variables */ |
---|
1119 | Arg al[1]; /* argument list */ |
---|
1120 | int w_locq; /* location quality widget */ |
---|
1121 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
1122 | int i; /* counter */ |
---|
1123 | |
---|
1124 | /* executable code */ |
---|
1125 | |
---|
1126 | /* check distance */ |
---|
1127 | if (par->dist_unit == CUC_DIST_UNIT_DEG && par->distance < 5.0) { |
---|
1128 | par->dist_unit = CUC_DIST_UNIT_KM; |
---|
1129 | par->distance *= CUC_DEG_TO_KM; |
---|
1130 | } /*endif*/ |
---|
1131 | |
---|
1132 | sprintf( str, "%5.1f", par->b_azimuth ); |
---|
1133 | cu_set_string( w[k_widget_param_azimuth_text], str ); |
---|
1134 | sprintf( str, "%5.1f", par->distance ); |
---|
1135 | if (par->dist_unit == CUC_DIST_UNIT_KM) |
---|
1136 | strcat( str, "km" ); |
---|
1137 | cu_set_string( w[k_widget_param_distance_text], str ); |
---|
1138 | sprintf( str, "%5.1f", par->depth ); |
---|
1139 | cu_set_string( w[k_widget_param_depth_text], str ); |
---|
1140 | sprintf( str, "%5.2f", par->b_slowness ); |
---|
1141 | cu_set_string( w[k_widget_param_slowness_text], str ); |
---|
1142 | sprintf( str, "%6.3f", par->source_lat ); |
---|
1143 | cu_set_string( w[k_widget_param_lat_text], str ); |
---|
1144 | sprintf( str, "%6.3f", par->source_lon ); |
---|
1145 | cu_set_string( w[k_widget_param_lon_text], str ); |
---|
1146 | |
---|
1147 | /* set time string */ |
---|
1148 | if (par->origin[0] == '\0') { |
---|
1149 | /* writing an empty string "" to the edit strings when dialog box |
---|
1150 | * was unmapped crashed the program (Bad Pixmap) on mapping the |
---|
1151 | * dialog box afterwards |
---|
1152 | */ |
---|
1153 | cu_set_string( w[k_widget_param_origin_d_text], " " ); |
---|
1154 | cu_set_string( w[k_widget_param_origin_t_text], " " ); |
---|
1155 | } else { |
---|
1156 | i = 0; |
---|
1157 | while (par->origin[i] != '_') { |
---|
1158 | i++; |
---|
1159 | if (par->origin[i] == '\0' || i > BC_TIMELTH) { |
---|
1160 | cu_set_string( w[k_widget_param_origin_d_text], " " ); |
---|
1161 | cu_set_string( w[k_widget_param_origin_t_text], " " ); |
---|
1162 | printf( "*SHM: cu_set_param_values: error in time string\n" ); |
---|
1163 | return; |
---|
1164 | } /*endif*/ |
---|
1165 | } /*endwhile*/ |
---|
1166 | strncpy( str, par->origin, i ); str[i] = '\0'; |
---|
1167 | cu_set_string( w[k_widget_param_origin_d_text], str ); |
---|
1168 | strcpy( str, (par->origin)+i+1 ); |
---|
1169 | cu_set_string( w[k_widget_param_origin_t_text], str ); |
---|
1170 | } /*endif*/ |
---|
1171 | |
---|
1172 | /* set quality option menu */ |
---|
1173 | switch (par->loc_quality) { |
---|
1174 | case CUC_LOCQ_INCOHERENT: w_locq = k_widget_param_locq_incoherent; break; |
---|
1175 | case CUC_LOCQ_NOBEARING: w_locq = k_widget_param_locq_nobearing; break; |
---|
1176 | case CUC_LOCQ_REGION: w_locq = k_widget_param_locq_region; break; |
---|
1177 | case CUC_LOCQ_RELIABLE: w_locq = k_widget_param_locq_reliable; break; |
---|
1178 | case CUC_LOCQ_UNDEFINED: w_locq = k_widget_param_locq_undefined; break; |
---|
1179 | default: w_locq = k_widget_param_locq_undefined; break; |
---|
1180 | } /*endswitch*/ |
---|
1181 | XtSetArg( al[0], XmNmenuHistory, w[w_locq] ); |
---|
1182 | XtSetValues( w[k_widget_param_locq_option], al, 1 ); |
---|
1183 | |
---|
1184 | /* set event type option menu */ |
---|
1185 | switch (par->source_type) { |
---|
1186 | case CUC_TYPE_LOCAL_QUAKE: w_locq = k_widget_phase_type_local; break; |
---|
1187 | case CUC_TYPE_REGIO_QUAKE: w_locq = k_widget_phase_type_regio; break; |
---|
1188 | case CUC_TYPE_TELE_QUAKE: w_locq = k_widget_phase_type_tele; break; |
---|
1189 | case CUC_TYPE_NUCLEAR: w_locq = k_widget_phase_type_nuclear; break; |
---|
1190 | case CUC_TYPE_BLAST: w_locq = k_widget_phase_type_blast; break; |
---|
1191 | case CUC_TYPE_MINING: w_locq = k_widget_phase_type_mining; break; |
---|
1192 | default: w_locq = k_widget_phase_type_other; break; |
---|
1193 | } /*endswitch*/ |
---|
1194 | XtSetArg( al[0], XmNmenuHistory, w[w_locq] ); |
---|
1195 | XtSetValues( w[k_widget_phase_type_option], al, 1 ); |
---|
1196 | |
---|
1197 | /* set parameter set option menu */ |
---|
1198 | XtSetArg( al[0], XmNmenuHistory, w[k_widget_param_set_1+parno] ); |
---|
1199 | XtSetValues( w[k_widget_param_set_option], al, 1 ); |
---|
1200 | |
---|
1201 | } /* end of cu_set_param_values */ |
---|
1202 | |
---|
1203 | |
---|
1204 | |
---|
1205 | /*--------------------------------------------------------------------------*/ |
---|
1206 | |
---|
1207 | |
---|
1208 | |
---|
1209 | void cu_print_param_values( CUT_PARAMS *par ) |
---|
1210 | |
---|
1211 | /* prints out parameters |
---|
1212 | * |
---|
1213 | * parameters of routine |
---|
1214 | * CUT_PARAMS *par; input; analysis parameters |
---|
1215 | */ |
---|
1216 | { |
---|
1217 | /* executable code */ |
---|
1218 | |
---|
1219 | if (par->distance == 0.0) { |
---|
1220 | printf( " distance : not specified\n" ); |
---|
1221 | } else { |
---|
1222 | printf( " distance : %5.1f\n", par->distance ); |
---|
1223 | } /*endif*/ |
---|
1224 | if (par->b_slowness == 0.0 && par->b_azimuth == 0.0) { |
---|
1225 | printf( " beam-slowness: not specified\n" ); |
---|
1226 | printf( " beam-azimuth : not specified\n" ); |
---|
1227 | } else { |
---|
1228 | printf( " beam-slowness: %5.1f +/- %5.1f (%s)\n", |
---|
1229 | par->b_slowness, par->b_slowness_err, par->phase ); |
---|
1230 | printf( " beam-azimuth : %5.1f +/- %5.1f (%s)\n", |
---|
1231 | par->b_azimuth, par->b_azimuth_err, par->phase ); |
---|
1232 | } /*endif*/ |
---|
1233 | if (par->l_slowness == 0.0 && par->l_azimuth == 0.0) { |
---|
1234 | printf( " epi-slowness : not specified\n" ); |
---|
1235 | printf( " epi-azimuth : not specified\n" ); |
---|
1236 | } else { |
---|
1237 | printf( " epi-slowness : %5.1f (%s)\n", |
---|
1238 | par->l_slowness, par->phase ); |
---|
1239 | printf( " epi-azimuth : %5.1f (%s)\n", |
---|
1240 | par->l_azimuth, par->phase ); |
---|
1241 | } /*endif*/ |
---|
1242 | printf( " depth : %5.1f +/- %5.1f\n", |
---|
1243 | par->depth, par->err.dep ); |
---|
1244 | if (par->ref_lat == 0.0 && par->ref_lon == 0.0) { |
---|
1245 | printf( " reference : %s\n", GpGetString(cGpS_refstation) ); |
---|
1246 | } else { |
---|
1247 | printf( " reference : %s, %7.2f lat %7.2f lon\n", |
---|
1248 | GpGetString(cGpS_refstation), par->ref_lat, par->ref_lon ); |
---|
1249 | } /*endif*/ |
---|
1250 | if (par->loc_meth == CUC_LOCMETH_BEAMUNCORR) { |
---|
1251 | printf( " location determined from beam\n" ); |
---|
1252 | } else if (par->loc_meth == CUC_LOCMETH_BEAMCORR) { |
---|
1253 | printf( " location determined from corrected slowness & azimuth\n" ); |
---|
1254 | } else if (par->loc_meth == CUC_LOCMETH_HYPO) { |
---|
1255 | printf( " location determined by Hypoellipse\n" ); |
---|
1256 | } /*endif*/ |
---|
1257 | if (par->origin[0] == '\0') { |
---|
1258 | printf( " origin time : not specified\n" ); |
---|
1259 | } else { |
---|
1260 | printf( " origin time : %s\n", par->origin ); |
---|
1261 | } /*endif*/ |
---|
1262 | if (par->source_lat == 0.0 && par->source_lon == 0.0) { |
---|
1263 | printf( " epicenter : not specified\n" ); |
---|
1264 | } else { |
---|
1265 | printf( " epicenter : %7.2f lat %7.2f lon\n", |
---|
1266 | par->source_lat, par->source_lon ); |
---|
1267 | } /*endif*/ |
---|
1268 | if (par->regname[0] == '\0') { |
---|
1269 | printf( " FE region : not specified\n" ); |
---|
1270 | } else { |
---|
1271 | printf( " FE region : %s\n", par->regname ); |
---|
1272 | } /*endif*/ |
---|
1273 | #ifdef XXX |
---|
1274 | if (par->evid == 0) { |
---|
1275 | printf( " Event ID : not specified\n" ); |
---|
1276 | } else { |
---|
1277 | printf( " Event ID : %09ld\n", par->evid ); |
---|
1278 | } /*endif*/ |
---|
1279 | #endif |
---|
1280 | |
---|
1281 | } /* end of cu_print_param_values */ |
---|
1282 | |
---|
1283 | |
---|
1284 | |
---|
1285 | /*--------------------------------------------------------------------------*/ |
---|
1286 | |
---|
1287 | |
---|
1288 | |
---|
1289 | void cu_get_param_values( Widget w[], CUT_PARAMS *par ) |
---|
1290 | |
---|
1291 | /* copies values from dialog box to parameter block |
---|
1292 | * |
---|
1293 | * parameters of routine |
---|
1294 | * Widget w[]; input; widget array |
---|
1295 | * CUT_PARAMS *par; output; parameter values |
---|
1296 | */ |
---|
1297 | { |
---|
1298 | /* local variables */ |
---|
1299 | char *str1, *str2; /* pointers to strings */ |
---|
1300 | int slen1, slen2; /* string lengths */ |
---|
1301 | STATUS locstat; /* local status */ |
---|
1302 | char *txt; /* text pointer */ |
---|
1303 | int slen; /* string length */ |
---|
1304 | |
---|
1305 | /* executable code */ |
---|
1306 | |
---|
1307 | if (sscanf( cu_get_string(w[k_widget_param_azimuth_text]), "%f", |
---|
1308 | &(par->b_azimuth) ) != 1) { |
---|
1309 | par->b_azimuth = 0.0; |
---|
1310 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1311 | printf( "SHM-dbg1: cu_get_param_values: couldn't read azimuth\n" ); |
---|
1312 | } /*endif*/ |
---|
1313 | txt = cu_get_string( w[k_widget_param_distance_text] ); |
---|
1314 | if (sscanf( txt, "%f", &(par->distance) ) != 1) { |
---|
1315 | par->distance = 0.0; |
---|
1316 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1317 | printf( "SHM-dbg1: cu_get_param_values: couldn't read distance\n" ); |
---|
1318 | } /*endif*/ |
---|
1319 | par->dist_unit = CUC_DIST_UNIT_DEG; |
---|
1320 | slen = strlen( txt ); |
---|
1321 | if (slen > 2 && txt[slen-2] == 'k' && txt[slen-1] == 'm') |
---|
1322 | par->dist_unit = CUC_DIST_UNIT_KM; |
---|
1323 | if (sscanf( cu_get_string(w[k_widget_param_depth_text]), "%f", |
---|
1324 | &(par->depth) ) != 1) { |
---|
1325 | par->depth = 0.0; |
---|
1326 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1327 | printf( "SHM-dbg1: cu_get_param_values: couldn't read depth\n" ); |
---|
1328 | } /*endif*/ |
---|
1329 | if (sscanf( cu_get_string(w[k_widget_param_slowness_text]), "%f", |
---|
1330 | &(par->b_slowness) ) != 1) { |
---|
1331 | par->b_slowness = 0.0; |
---|
1332 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1333 | printf( "SHM-dbg1: cu_get_param_values: couldn't read slowness\n" ); |
---|
1334 | } /*endif*/ |
---|
1335 | str1 = cu_get_string( w[k_widget_param_origin_d_text] ); |
---|
1336 | str2 = cu_get_string( w[k_widget_param_origin_t_text] ); |
---|
1337 | slen1 = strlen( str1 ); |
---|
1338 | slen2 = strlen( str2 ); |
---|
1339 | if (slen1 > 6 && slen2 > 0) { |
---|
1340 | if (slen1+slen2+1 <= BC_TIMELTH) { |
---|
1341 | sprintf( par->origin, "%s_%s", str1, str2 ); |
---|
1342 | /* check time */ |
---|
1343 | locstat = BC_NOERROR; |
---|
1344 | tc_tadd( par->origin, 0.0, par->origin, &locstat ); |
---|
1345 | if (Severe(&locstat)) { |
---|
1346 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1347 | printf( "SHM-dbg1: cu_get_param_values: couldn't read origin time\n" ); |
---|
1348 | par->origin[0] = '\0'; |
---|
1349 | } /*endif*/ |
---|
1350 | } /*endif*/ |
---|
1351 | } else { |
---|
1352 | par->origin[0] = '\0'; |
---|
1353 | } /*endif*/ |
---|
1354 | if (sscanf( cu_get_string(w[k_widget_param_lat_text]), "%f", |
---|
1355 | &(par->source_lat) ) != 1) { |
---|
1356 | par->source_lat = 0.0; |
---|
1357 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1358 | printf( "SHM-dbg1: cu_get_param_values: couldn't read source lat\n" ); |
---|
1359 | } /*endif*/ |
---|
1360 | if (sscanf( cu_get_string(w[k_widget_param_lon_text]), "%f", |
---|
1361 | &(par->source_lon) ) != 1) { |
---|
1362 | par->source_lon = 0.0; |
---|
1363 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1364 | printf( "SHM-dbg1: cu_get_param_values: couldn't read source lon\n" ); |
---|
1365 | } /*endif*/ |
---|
1366 | |
---|
1367 | } /* end of cu_get_param_values */ |
---|
1368 | |
---|
1369 | |
---|
1370 | |
---|
1371 | /*--------------------------------------------------------------------------*/ |
---|
1372 | |
---|
1373 | |
---|
1374 | |
---|
1375 | void cu_get_display_control( Widget w[], MGT_DSPCTRL *ctrl ) |
---|
1376 | |
---|
1377 | /* puts display controls values from dialog box to control structure |
---|
1378 | * |
---|
1379 | * parameters of routine |
---|
1380 | * Widget w[]; input; Widget array of dialog box elements |
---|
1381 | * MGT_DSPCTRL *ctrl; output; values retrieved |
---|
1382 | */ |
---|
1383 | { |
---|
1384 | /* local variables */ |
---|
1385 | |
---|
1386 | /* executable code */ |
---|
1387 | /* |
---|
1388 | sscanf( cu_get_string(w[k_widget_ctrl_zoom_text]), |
---|
1389 | "%f", &(ctrl->zoom) ); |
---|
1390 | */ |
---|
1391 | } /* end of cu_get_display_control */ |
---|
1392 | |
---|
1393 | |
---|
1394 | |
---|
1395 | /*--------------------------------------------------------------------------*/ |
---|
1396 | |
---|
1397 | |
---|
1398 | |
---|
1399 | void cu_theo_arrivals( Widget wm, Widget ws, CUT_PARAMS *par, STATUS *status ) |
---|
1400 | |
---|
1401 | /* marks theoretical arrivals on all traces on display |
---|
1402 | * |
---|
1403 | * parameters of routine |
---|
1404 | * Widget wm; input; widget ID of main window |
---|
1405 | * Widget ws; input; widget ID of single trace window |
---|
1406 | * CUT_PARAMS *par; input; analysis parameters |
---|
1407 | * STATUS *status; output; return status |
---|
1408 | */ |
---|
1409 | { |
---|
1410 | /* local variables */ |
---|
1411 | TPmTrace *trc; /* pointer to trace */ |
---|
1412 | char curr_phase[BC_LINELTH+1]; /* current theo phase */ |
---|
1413 | GLT_STATINF *statinf; /* pointer to station info */ |
---|
1414 | float distance; /* distance in deg */ |
---|
1415 | float azimuth; /* back azimuth in deg */ |
---|
1416 | float travtime; /* trave time in sec */ |
---|
1417 | TPiPhase theo_phase; /* theoretical phase */ |
---|
1418 | int slen; /* string length */ |
---|
1419 | TSyStatus locstat; /* local status */ |
---|
1420 | char *sc, *dc; /* moving pointers */ |
---|
1421 | TSyBoolean quit; /* quit loop */ |
---|
1422 | |
---|
1423 | /* executable code */ |
---|
1424 | |
---|
1425 | if (par->distance == 0.0) { |
---|
1426 | *status = CUE_NODISTANCE; |
---|
1427 | return; |
---|
1428 | } /*endif*/ |
---|
1429 | |
---|
1430 | /* delete all theoretical phases from all traces */ |
---|
1431 | cu_delete_all_phases( wm, ws, "--theo--", TRUE ); |
---|
1432 | |
---|
1433 | /* compute and mark new phases */ |
---|
1434 | sc = GpGetString( cGpS_theo_phase_list ); |
---|
1435 | dc = curr_phase; |
---|
1436 | quit = FALSE; |
---|
1437 | while (!quit) { |
---|
1438 | |
---|
1439 | if (*sc != ',' && *sc != '\0') { |
---|
1440 | *dc++ = *sc++; |
---|
1441 | continue; |
---|
1442 | } /*endif*/ |
---|
1443 | if (*sc++ == '\0') quit = TRUE; |
---|
1444 | *dc = '\0'; |
---|
1445 | dc = curr_phase; |
---|
1446 | |
---|
1447 | /* if comment line or depth phase at depth 0, do nothing */ |
---|
1448 | if (par->depth == 0.0 && |
---|
1449 | (*curr_phase == 'p' || *curr_phase == 's')) continue; |
---|
1450 | |
---|
1451 | /* process current phase for each trace */ |
---|
1452 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
1453 | printf( "SHM-dbg2: phase %s\n", curr_phase ); |
---|
1454 | trc = NULL; |
---|
1455 | FOREVER { |
---|
1456 | locstat = cBcNoError; |
---|
1457 | trc = db_getp( trc, EP_DSPN, &locstat ); |
---|
1458 | if (trc == NULL) break; |
---|
1459 | /* compute traveltime and setup phase descr. */ |
---|
1460 | statinf = cu_get_statinf( trc, status ); |
---|
1461 | if (*status == CUE_BEAMSTATION) {*status=BC_NOERROR; continue;} |
---|
1462 | if (SySevere(status)) return; |
---|
1463 | mb_spherediff( statinf->lat, statinf->lon, |
---|
1464 | par->source_lat, par->source_lon, |
---|
1465 | &distance, &azimuth ); |
---|
1466 | locstat = cBcNoError; |
---|
1467 | travtime = pt_travel( curr_phase, distance, |
---|
1468 | par->depth, &locstat ); |
---|
1469 | if (locstat != cBcNoError) continue; |
---|
1470 | if (Severe(status)) return; |
---|
1471 | cu_reset_phase( &theo_phase ); |
---|
1472 | strcpy( theo_phase.name, curr_phase ); |
---|
1473 | tc_tadd( par->origin, travtime, |
---|
1474 | theo_phase.onset, status ); |
---|
1475 | if (SySevere(status)) return; |
---|
1476 | theo_phase.spec = cPiSpecEmergent; |
---|
1477 | /*theo_phase.phasetrc = mg_trcptr( t+1 );*/ |
---|
1478 | theo_phase.sign = 0; |
---|
1479 | theo_phase.source = cPiSourceTheo; |
---|
1480 | /* put phase on screen */ |
---|
1481 | cu_accept_phase( wm, ws, &theo_phase, trc, FALSE, status ); |
---|
1482 | if (SySevere(status)) return; |
---|
1483 | } /*endfor*/ |
---|
1484 | |
---|
1485 | } /*endwhile*/ |
---|
1486 | |
---|
1487 | } /* end of cu_theo_arrivals */ |
---|
1488 | |
---|
1489 | |
---|
1490 | |
---|
1491 | /*--------------------------------------------------------------------------*/ |
---|
1492 | |
---|
1493 | |
---|
1494 | |
---|
1495 | void cu_delete_all_phases( Widget wm, Widget ws, char name[], |
---|
1496 | TSyBoolean allmem ) |
---|
1497 | |
---|
1498 | /* All phases with name "name" are deleted. If name=="--theo--", all |
---|
1499 | * theoretical phases will be deleted, if name="--pseudo--", all pseudo-phases |
---|
1500 | * starting with 'b' are deleted. |
---|
1501 | * |
---|
1502 | * parameters of routine |
---|
1503 | * Widget wm; input; widget ID of main drawing area |
---|
1504 | * Widget ws; input; widget ID of single draw window |
---|
1505 | * char name; input; name of phases to be deleted |
---|
1506 | * TSyBoolean allmem; input; all phases in memory (TRUE) or on display only |
---|
1507 | */ |
---|
1508 | { |
---|
1509 | /* local variables */ |
---|
1510 | TSyStatus locstat; /* local status */ |
---|
1511 | int trcno; /* number of traces */ |
---|
1512 | TSyBoolean do_theo; /* delete theo phases */ |
---|
1513 | TSyBoolean do_pseudo; /* delete all pseudo phases */ |
---|
1514 | TPiPhaseRoot *proot; /* pointer to phase root */ |
---|
1515 | TPiPhaseList *plist; /* pointer to phase list */ |
---|
1516 | int plist_lth; /* length of phase list */ |
---|
1517 | int p; /* phase counter */ |
---|
1518 | TPiPhase *rem_phase; /* phase to be removed */ |
---|
1519 | TPmTrace *trc; /* pointer to trace */ |
---|
1520 | |
---|
1521 | /* executable code */ |
---|
1522 | |
---|
1523 | do_theo = (strcmp(name,"--theo--") == 0); |
---|
1524 | do_pseudo = (strcmp(name,"--pseudo--") == 0); |
---|
1525 | |
---|
1526 | /* loop over traces on display */ |
---|
1527 | proot = NULL; |
---|
1528 | FOREVER { |
---|
1529 | proot = PiNextPhaseRoot( proot ); |
---|
1530 | if (proot == NULL) break; |
---|
1531 | plist = PiPhaseListOfRoot( proot ); |
---|
1532 | if (plist == NULL) continue; |
---|
1533 | plist_lth = PiPhaseListLength( plist ); |
---|
1534 | for (p=0; p<plist_lth; p++) { |
---|
1535 | locstat = cBcNoError; |
---|
1536 | rem_phase = PiGetPhase( plist, p, &locstat ); |
---|
1537 | if (locstat != cBcNoError) continue; |
---|
1538 | if (do_pseudo && rem_phase->name[0] != 'b') continue; |
---|
1539 | if (do_theo && rem_phase->source != cPiSourceTheo) continue; |
---|
1540 | if (strcmp(name,"*") != 0) |
---|
1541 | if (!do_pseudo && !do_theo && (strcmp(rem_phase->name,name) != 0)) |
---|
1542 | continue; |
---|
1543 | /* remove phase(s) from display */ |
---|
1544 | trc = NULL; |
---|
1545 | FOREVER { |
---|
1546 | trc = PmFindTrace( trc, PiDescrOfRoot(proot) ); |
---|
1547 | if (trc == NULL) break; |
---|
1548 | mg_mark_one_phase( wm, ws, rem_phase, trc, FALSE ); |
---|
1549 | } /*endfor*/ |
---|
1550 | PiDeletePhase( plist, rem_phase, &locstat ); |
---|
1551 | p--; |
---|
1552 | plist_lth--; |
---|
1553 | } /*endfor*/ |
---|
1554 | } /*endfor*/ |
---|
1555 | |
---|
1556 | } /* end of cu_delete_all_phases */ |
---|
1557 | |
---|
1558 | |
---|
1559 | |
---|
1560 | /*--------------------------------------------------------------------------*/ |
---|
1561 | |
---|
1562 | |
---|
1563 | |
---|
1564 | static GLT_STATINF *cu_get_statinf( TPmTrace *trc, TSyStatus *status ) |
---|
1565 | |
---|
1566 | /* returns pointer to static station info block of trace number "trcno" |
---|
1567 | * |
---|
1568 | * parameters of routine |
---|
1569 | * TPmTrace *trc; input; pointer to trace |
---|
1570 | * TSyStatus *status; output; return status |
---|
1571 | * returns static pointer to station info |
---|
1572 | */ |
---|
1573 | { |
---|
1574 | /* local variables */ |
---|
1575 | GLT_STATINF *statinf; /* pointer to station info */ |
---|
1576 | TSyStatus locstat; /* local status */ |
---|
1577 | char station[BC_LINELTH+1]; /* station name */ |
---|
1578 | |
---|
1579 | /* executable code */ |
---|
1580 | |
---|
1581 | locstat = cBcNoError; |
---|
1582 | statinf = (GLT_STATINF *)db_getp( trc, EP_STAT, &locstat ); |
---|
1583 | if (statinf == NULL) { |
---|
1584 | db_gets( trc, ES_STATION, BC_LINELTH, station, status ); |
---|
1585 | if (Severe(status)) return NULL; |
---|
1586 | if (strcmp(station,"BEAM") == 0 || strcmp(station,"ALIGN") == 0) { |
---|
1587 | *status = CUE_BEAMSTATION; |
---|
1588 | return NULL; |
---|
1589 | } /*endif*/ |
---|
1590 | statinf = gl_store_station( station, TRUE, status ); |
---|
1591 | if (Severe(status)) return NULL; |
---|
1592 | db_setp( trc, EP_STAT, statinf, status ); |
---|
1593 | if (Severe(status)) return NULL; |
---|
1594 | } /*endif*/ |
---|
1595 | |
---|
1596 | return statinf; |
---|
1597 | |
---|
1598 | } /* end of cu_get_statinf */ |
---|
1599 | |
---|
1600 | |
---|
1601 | |
---|
1602 | /*--------------------------------------------------------------------------*/ |
---|
1603 | |
---|
1604 | |
---|
1605 | |
---|
1606 | void cu_alert_message( Widget w, char text [] ) |
---|
1607 | |
---|
1608 | /* puts alert box on screen |
---|
1609 | * |
---|
1610 | * parameters of routine |
---|
1611 | * Widget w; input; alert box widget ID |
---|
1612 | * char text[]; input; alert message |
---|
1613 | */ |
---|
1614 | { |
---|
1615 | /* local variables */ |
---|
1616 | Arg arg[3]; /* argument list */ |
---|
1617 | int n; /* arg counter */ |
---|
1618 | static XmString xstr; /* x string */ |
---|
1619 | static TSyBoolean xstr_init=FALSE; /* x string created */ |
---|
1620 | |
---|
1621 | /* executable code */ |
---|
1622 | |
---|
1623 | if (XtIsManaged(w)) XtUnmanageChild( w ); |
---|
1624 | |
---|
1625 | /*if (xstr_init) XmStringFree( (char *)xstr );*/ |
---|
1626 | xstr = XmStringLtoRCreate( text, XmSTRING_DEFAULT_CHARSET ); |
---|
1627 | xstr_init = TRUE; |
---|
1628 | |
---|
1629 | n = 0; |
---|
1630 | XtSetArg( arg[n], XmNmessageString, xstr ); n++; |
---|
1631 | XtSetValues( w, arg, n ); |
---|
1632 | |
---|
1633 | XtManageChild( w ); |
---|
1634 | XFlush( XtDisplay(w) ); |
---|
1635 | |
---|
1636 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
1637 | printf( "SHM-dbg4: cu_alert_message: after XtManageChild\n" ); |
---|
1638 | |
---|
1639 | } /* end of cu_alert_message */ |
---|
1640 | |
---|
1641 | |
---|
1642 | |
---|
1643 | /*--------------------------------------------------------------------------*/ |
---|
1644 | |
---|
1645 | |
---|
1646 | |
---|
1647 | void cu_alert( TSyStatus status ) |
---|
1648 | |
---|
1649 | /* puts alert message on screen |
---|
1650 | * |
---|
1651 | * parameters of routine |
---|
1652 | * TSyStatus status; input; status code |
---|
1653 | */ |
---|
1654 | { |
---|
1655 | /* local variables */ |
---|
1656 | char str[BC_LONGSTRLTH+1]; /* scratch string */ |
---|
1657 | char context[BC_LINELTH+1]; /* error context */ |
---|
1658 | |
---|
1659 | /* executable code */ |
---|
1660 | |
---|
1661 | err_msg( status, str ); |
---|
1662 | err_getcontext( context ); |
---|
1663 | if (*context != '\0') { |
---|
1664 | if (strlen(str)+strlen(context)+1 < BC_LONGSTRLTH) { |
---|
1665 | strcat( str, "\n" ); |
---|
1666 | strcat( str, context ); |
---|
1667 | } /*endif*/ |
---|
1668 | err_clearcontext(); |
---|
1669 | } /*endif*/ |
---|
1670 | |
---|
1671 | if (cuv_alert_widget == (Widget)0) { |
---|
1672 | printf( "*SHM: alert widget not yet set: ***\n" ); |
---|
1673 | printf( "%s\n", str ); |
---|
1674 | return; |
---|
1675 | } /*endif*/ |
---|
1676 | |
---|
1677 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
1678 | printf( "SHM-dbg4: want to create error message: %s\n", str ); |
---|
1679 | |
---|
1680 | cu_alert_message( cuv_alert_widget, str ); |
---|
1681 | |
---|
1682 | } /* end of cu_alert */ |
---|
1683 | |
---|
1684 | |
---|
1685 | |
---|
1686 | /*--------------------------------------------------------------------------*/ |
---|
1687 | |
---|
1688 | |
---|
1689 | |
---|
1690 | void cu_set_alert_widget( Widget w ) |
---|
1691 | |
---|
1692 | /* sets alert widget |
---|
1693 | * |
---|
1694 | * parameters of routine |
---|
1695 | * Widget w; input; widget ID of alert box |
---|
1696 | */ |
---|
1697 | { |
---|
1698 | /* local variables */ |
---|
1699 | |
---|
1700 | /* executable code */ |
---|
1701 | |
---|
1702 | cuv_alert_widget = w; /* used for status message output */ |
---|
1703 | |
---|
1704 | } /* end of cu_set_alert_widget */ |
---|
1705 | |
---|
1706 | |
---|
1707 | |
---|
1708 | /*--------------------------------------------------------------------------*/ |
---|
1709 | |
---|
1710 | |
---|
1711 | |
---|
1712 | void cu_set_multiplication_widget( Widget box, Widget label, Widget edit ) |
---|
1713 | |
---|
1714 | /* sets widget ID's of multiplication box |
---|
1715 | * |
---|
1716 | * parameters of routine |
---|
1717 | * Widget box; input; widget ID of whole box |
---|
1718 | * Widget label; input; widget ID of title label |
---|
1719 | * Widget edit; input; widget ID of value editable text |
---|
1720 | */ |
---|
1721 | { |
---|
1722 | /* executable code */ |
---|
1723 | |
---|
1724 | cuv_multipli_box = box; |
---|
1725 | cuv_multipli_value = label; |
---|
1726 | cuv_multipli_edit = edit; |
---|
1727 | |
---|
1728 | } /* end of cu_set_multiplication_widget */ |
---|
1729 | |
---|
1730 | |
---|
1731 | |
---|
1732 | /*--------------------------------------------------------------------------*/ |
---|
1733 | |
---|
1734 | |
---|
1735 | |
---|
1736 | void cu_multiplication_dialog( TPmTrace *phtrc, TPiPhase *phase ) |
---|
1737 | |
---|
1738 | /* let the user multiply the value |
---|
1739 | * |
---|
1740 | * parameters of routine |
---|
1741 | * TPmTrace *phtrc input; phase pointer |
---|
1742 | * TPiPhase *phase; modify; phase amplitudes to update |
---|
1743 | */ |
---|
1744 | { |
---|
1745 | /* local variables */ |
---|
1746 | static XmString val; /* value text */ |
---|
1747 | static BOOLEAN val_init=FALSE; /* value is initalized */ |
---|
1748 | Arg a[1]; /* argument */ |
---|
1749 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
1750 | |
---|
1751 | /* executable code */ |
---|
1752 | |
---|
1753 | cuv_multipli_phase = phase; |
---|
1754 | cuv_multipli_trc = phtrc; |
---|
1755 | sprintf( str, "value %f", phase->ampl ); |
---|
1756 | |
---|
1757 | if (XtIsManaged(cuv_multipli_box)) |
---|
1758 | XtUnmanageChild( cuv_multipli_box ); |
---|
1759 | if (val_init) XtFree( (char *)val ); |
---|
1760 | val = XmStringLtoRCreate( str, "" ); |
---|
1761 | val_init = TRUE; |
---|
1762 | XtSetArg( a[0], XmNlabelString, val ); |
---|
1763 | XtSetValues( cuv_multipli_value, a, 1 ); |
---|
1764 | XtManageChild( cuv_multipli_box ); |
---|
1765 | |
---|
1766 | } /* end of cu_multiplication_dialog */ |
---|
1767 | |
---|
1768 | |
---|
1769 | |
---|
1770 | /*--------------------------------------------------------------------------*/ |
---|
1771 | |
---|
1772 | |
---|
1773 | |
---|
1774 | void cu_do_multiplication( float fac, TSyStatus *status ) |
---|
1775 | |
---|
1776 | /* performs multiplication prepared by cu_multiplication_dialog |
---|
1777 | * |
---|
1778 | * parameters of routine |
---|
1779 | * float fac; input; factor |
---|
1780 | * TSyStatus *status; output; return status |
---|
1781 | */ |
---|
1782 | { |
---|
1783 | /* local variables */ |
---|
1784 | char *valptr; /* pointer to value */ |
---|
1785 | float factor; /* multiplication factor */ |
---|
1786 | TSyStatus locstat; /* local status */ |
---|
1787 | |
---|
1788 | /* executable code */ |
---|
1789 | |
---|
1790 | if (cuv_multipli_phase == NULL) { |
---|
1791 | *status = CUE_NOMULTIPLI; |
---|
1792 | return; |
---|
1793 | } else if (cuv_multipli_trc == NULL) { |
---|
1794 | *status = CUE_NOMULTIPLI; |
---|
1795 | return; |
---|
1796 | } /*endif*/ |
---|
1797 | |
---|
1798 | if (fac == CUC_MULTIPLI_EDIT_MUL || fac == CUC_MULTIPLI_EDIT_DIV) { |
---|
1799 | valptr = cu_get_string( cuv_multipli_edit ); |
---|
1800 | if (sscanf( valptr, "%f", &factor ) != 1) { |
---|
1801 | *status = CUE_CNV_FLOAT; |
---|
1802 | err_setcontext( " ## number: " ); |
---|
1803 | err_setcontext( valptr ); |
---|
1804 | return; |
---|
1805 | } /*endif*/ |
---|
1806 | if (fac == CUC_MULTIPLI_EDIT_DIV) |
---|
1807 | factor = 1.0 / factor; |
---|
1808 | } else { |
---|
1809 | factor = fac; |
---|
1810 | } /*endif*/ |
---|
1811 | |
---|
1812 | cuv_multipli_phase->period *= factor; |
---|
1813 | locstat = BC_NOERROR; |
---|
1814 | cu_ampl_restitution( cuv_multipli_trc, |
---|
1815 | cuv_multipli_phase->ampl, |
---|
1816 | cuv_multipli_phase->period, "DSP", |
---|
1817 | &(cuv_multipli_phase->ampl_displ), cuv_multipli_phase->filter, |
---|
1818 | &locstat ); |
---|
1819 | if (locstat != BC_NOERROR) cuv_multipli_phase->ampl_displ = 0.0; |
---|
1820 | locstat = BC_NOERROR; |
---|
1821 | cu_ampl_restitution( cuv_multipli_trc, |
---|
1822 | cuv_multipli_phase->ampl, |
---|
1823 | cuv_multipli_phase->period, "VEL", |
---|
1824 | &(cuv_multipli_phase->ampl_veloc), cuv_multipli_phase->filter, |
---|
1825 | &locstat ); |
---|
1826 | if (locstat != BC_NOERROR) cuv_multipli_phase->ampl_veloc = 0.0; |
---|
1827 | cu_print_phase( cuv_multipli_phase ); |
---|
1828 | cuv_multipli_phase = NULL; |
---|
1829 | |
---|
1830 | if (XtIsManaged(cuv_multipli_box)) |
---|
1831 | XtUnmanageChild( cuv_multipli_box ); |
---|
1832 | |
---|
1833 | } /* end of cu_do_multiplication */ |
---|
1834 | |
---|
1835 | |
---|
1836 | |
---|
1837 | /*--------------------------------------------------------------------------*/ |
---|
1838 | |
---|
1839 | |
---|
1840 | |
---|
1841 | void cu_print_phase( TPiPhase *phase ) |
---|
1842 | |
---|
1843 | /* prints out phase information |
---|
1844 | * |
---|
1845 | * parameters of routine |
---|
1846 | * TPiPhase *phase; input; phase info |
---|
1847 | */ |
---|
1848 | { |
---|
1849 | /* local variables */ |
---|
1850 | TPmTrace *trcptr; /* trace pointer */ |
---|
1851 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
1852 | TSyStatus locstat=cBcNoError; /* local status */ |
---|
1853 | |
---|
1854 | /* executable code */ |
---|
1855 | |
---|
1856 | printf( "\n" ); |
---|
1857 | printf( " phase : %s ", phase->name ); |
---|
1858 | if (phase->spec == cPiSpecEmergent) printf( "emergent " ); |
---|
1859 | if (phase->spec == cPiSpecImpulsive) printf( "impulsive " ); |
---|
1860 | if (phase->sign == 1) printf( "compression " ); |
---|
1861 | if (phase->sign == -1) printf( "dilatation " ); |
---|
1862 | if (phase->source == cPiSourceTheo) printf( "theoretical" ); |
---|
1863 | if (phase->source == cPiSourceAuto) printf( "automatic" ); |
---|
1864 | printf( "\n" ); |
---|
1865 | printf( " onset : %s\n", phase->onset ); |
---|
1866 | if (phase->period > 0.0) { |
---|
1867 | printf( " period: %5.2f\n", phase->period ); |
---|
1868 | } else { |
---|
1869 | printf( " period: not specified\n" ); |
---|
1870 | } /*endif*/ |
---|
1871 | if (phase->filter[0] != '\0') { |
---|
1872 | printf( " filter: %s\n", phase->filter ); |
---|
1873 | } else { |
---|
1874 | printf( " filter: none\n" ); |
---|
1875 | } /*endif*/ |
---|
1876 | if (phase->ampl > 0.0) { |
---|
1877 | printf( " amplitude (plain): %6.1f\n", phase->ampl ); |
---|
1878 | } else { |
---|
1879 | printf( " amplitude (plain): not specified\n" ); |
---|
1880 | } /*endif*/ |
---|
1881 | if (phase->ampl_veloc > 0.0) { |
---|
1882 | printf( " amplitude (veloc): %6.1f\n", phase->ampl_veloc ); |
---|
1883 | } else { |
---|
1884 | printf( " amplitude (veloc): not specified\n" ); |
---|
1885 | } /*endif*/ |
---|
1886 | if (phase->ampl_displ > 0.0) { |
---|
1887 | printf( " amplitude (displ): %6.1f\n", phase->ampl_displ ); |
---|
1888 | } else { |
---|
1889 | printf( " amplitude (displ): not specified\n" ); |
---|
1890 | } /*endif*/ |
---|
1891 | if (phase->bb.bbampl > 0.0) { |
---|
1892 | printf( " amplitude (BB) : %6.1f\n", phase->bb.bbampl ); |
---|
1893 | } else { |
---|
1894 | printf( " amplitude (BB) : not specified\n" ); |
---|
1895 | } /*endif*/ |
---|
1896 | if (phase->ampl_time > 0.0) { |
---|
1897 | printf( " amplitude time : %5.2f\n", phase->ampl_time ); |
---|
1898 | } else { |
---|
1899 | printf( " amplitude time : not specified\n" ); |
---|
1900 | } /*endif*/ |
---|
1901 | if (phase->comment[0] != '\0') |
---|
1902 | printf( " comment: %s\n", phase->comment ); |
---|
1903 | |
---|
1904 | # ifdef XXX |
---|
1905 | trcptr = phase->phasetrc; |
---|
1906 | if (trcptr != NULL) { |
---|
1907 | db_gets( trcptr, ES_STATION, BC_LINELTH, str, &locstat ); |
---|
1908 | if (locstat == BC_NOERROR) |
---|
1909 | printf( " station: %s\n", str ); |
---|
1910 | } /*endif*/ |
---|
1911 | # endif |
---|
1912 | printf( "\n" ); |
---|
1913 | |
---|
1914 | } /* end of cu_print_phase */ |
---|
1915 | |
---|
1916 | |
---|
1917 | |
---|
1918 | /*--------------------------------------------------------------------------*/ |
---|
1919 | |
---|
1920 | |
---|
1921 | |
---|
1922 | void cu_ampl_restitution( TPmTrace *trcptr, float ampl, float period, |
---|
1923 | char kind[], float *rest_ampl, char filter[], TSyStatus *status ) |
---|
1924 | |
---|
1925 | /* returns restituted amplitude, velocity or displacement, depending on |
---|
1926 | * parameter "kind" ("VEL" or "DSP", respectively). The filter variable |
---|
1927 | * must have length BC_LINELTH+1. |
---|
1928 | * |
---|
1929 | * parameters of routine |
---|
1930 | * void *trcptr; input; pointer to trace info |
---|
1931 | * float ampl; input; input amplitude |
---|
1932 | * float period; input; period of signal in sec |
---|
1933 | * char kind[]; input; either "VEL" or "DSP" |
---|
1934 | * float *rest_ampl; output; restituted amplitude |
---|
1935 | * char filter[]; output; filter name (min. length BC_LINELTH+1) |
---|
1936 | * TSyStatus *status; output; return status |
---|
1937 | * returns restituted amplitude |
---|
1938 | */ |
---|
1939 | { |
---|
1940 | /* local variables */ |
---|
1941 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
1942 | TSyStatus locstat; /* local status */ |
---|
1943 | char *filptr; /* pointer to filter name */ |
---|
1944 | float frq; /* frequency of signal in Hz */ |
---|
1945 | float tffac; /* transfer function factor */ |
---|
1946 | float tffac2; /* second factor of this kind */ |
---|
1947 | char lfilname[BC_LINELTH+1]; /* local filter name */ |
---|
1948 | TIME ttime; /* trace time */ |
---|
1949 | char strtime[cBcTimeLth+1]; /* string time */ |
---|
1950 | int trcflags; /* trace flags for filtered traces */ |
---|
1951 | |
---|
1952 | /* executable code */ |
---|
1953 | |
---|
1954 | if (trcptr == NULL) { |
---|
1955 | *status = CUE_BUG; |
---|
1956 | printf( |
---|
1957 | "*SHM: cu_ampl_restitution: NULL ptr (illegal phase->phasetrc)\n" ); |
---|
1958 | return; |
---|
1959 | } /*endif*/ |
---|
1960 | |
---|
1961 | if (period < 1.e-8) { |
---|
1962 | *status = CUE_ZERO_PERIOD; |
---|
1963 | return; |
---|
1964 | } /*endif*/ |
---|
1965 | frq = 1/period; |
---|
1966 | |
---|
1967 | /* if a filter is applied the comment info entry contains its name */ |
---|
1968 | locstat = BC_NOERROR; |
---|
1969 | db_gets( trcptr, ES_COMMENT, BC_LINELTH, str, &locstat ); |
---|
1970 | if (locstat == BC_NOERROR) { |
---|
1971 | /* we have to look for a substring starting with 'FLT:' */ |
---|
1972 | filptr = strstr( str, "FLT:" ); |
---|
1973 | if (filptr == NULL) filptr = strstr( str, "flt:" ); |
---|
1974 | if (filptr != NULL) { |
---|
1975 | sscanf( filptr+4, "%s", filter ); |
---|
1976 | } else { |
---|
1977 | *filter = '\0'; |
---|
1978 | } /*endif*/ |
---|
1979 | } else { |
---|
1980 | /* if no filter found in the comment string it is an unfiltered trace */ |
---|
1981 | *filter = '\0'; |
---|
1982 | } /*endif*/ |
---|
1983 | strcpy( lfilname, filter ); |
---|
1984 | |
---|
1985 | /* if it is an unfiltered trace, take the transfer function of the recording |
---|
1986 | * instrument. This is returned by cu_lookup_filter. */ |
---|
1987 | if (*lfilname == '\0') { |
---|
1988 | locstat = cBcNoError; |
---|
1989 | db_gett( trcptr, ET_START, &ttime, &locstat ); |
---|
1990 | tc_a2t( &ttime, strtime, &locstat ); |
---|
1991 | cu_get_stream_string( trcptr, str, status ); |
---|
1992 | if (Severe(status)) return; |
---|
1993 | cu_lookup_filter( str, strtime, lfilname, &trcflags, status ); |
---|
1994 | if (Severe(status)) return; |
---|
1995 | } /*endif*/ |
---|
1996 | |
---|
1997 | /* if the trace is unfiltered or filtered with an simulation filter, the |
---|
1998 | * transfer function is found by applying a prefix 'TF_VEL_' or 'TF_DSP_'. |
---|
1999 | * Then this this contains the complete information needed here. |
---|
2000 | * Build filter name & read amplitude */ |
---|
2001 | strcpy( str, "TF_" ); |
---|
2002 | strcat( str, kind ); |
---|
2003 | strcat( str, "_" ); |
---|
2004 | strcat( str, lfilname ); |
---|
2005 | tffac = ff_filter_amplitude( str, frq, status ); |
---|
2006 | |
---|
2007 | /* if the filter cannot be found with a TF_VEL/DSP prefix it is not a |
---|
2008 | * simulation filter, so we need the transfer function of the filter |
---|
2009 | * and the transfer function of the recording instrument. |
---|
2010 | */ |
---|
2011 | if (SySevere(status)) { |
---|
2012 | /* at an unfiltered trace this means that the transfer function of the |
---|
2013 | * recording instrument has not been found before. So nothing can |
---|
2014 | * be done here. */ |
---|
2015 | if (*lfilname == '\0') return; |
---|
2016 | *status = cBcNoError; |
---|
2017 | /* get amplification of applied filter */ |
---|
2018 | tffac = ff_filter_amplitude( lfilname, frq, status ); |
---|
2019 | printf( "SHM-dbg2: fac1: filter applied: %s -> %f\n", lfilname, tffac ); |
---|
2020 | if (SySevere(status)) return; |
---|
2021 | /* add transfer function of recording instrument (like code above) */ |
---|
2022 | locstat = cBcNoError; |
---|
2023 | db_gett( trcptr, ET_START, &ttime, &locstat ); |
---|
2024 | tc_a2t( &ttime, strtime, &locstat ); |
---|
2025 | cu_get_stream_string( trcptr, str, status ); |
---|
2026 | if (SySevere(status)) return; |
---|
2027 | cu_lookup_filter( str, strtime, lfilname, &trcflags, status ); |
---|
2028 | if (SySevere(status)) return; |
---|
2029 | strcpy( str, "TF_" ); |
---|
2030 | strcat( str, kind ); |
---|
2031 | strcat( str, "_" ); |
---|
2032 | strcat( str, lfilname ); |
---|
2033 | tffac2 = ff_filter_amplitude( str, frq, status ); |
---|
2034 | printf( "SHM-dbg2: fac2: transfer function of rec. instr. %s -> %f\n", |
---|
2035 | str, tffac2 ); |
---|
2036 | tffac *= tffac2; |
---|
2037 | } /*endif*/ |
---|
2038 | |
---|
2039 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
2040 | printf( "SHM-dbg2: filter %s, frq %f, factor %f\n", str, frq, tffac ); |
---|
2041 | |
---|
2042 | if (tffac < 1.e-10) { |
---|
2043 | *status = CUE_ZERO_TRANSF; |
---|
2044 | return; |
---|
2045 | } /*endif*/ |
---|
2046 | *rest_ampl = ampl / tffac; |
---|
2047 | |
---|
2048 | } /* end of cu_ampl_restitution */ |
---|
2049 | |
---|
2050 | |
---|
2051 | |
---|
2052 | /*--------------------------------------------------------------------------*/ |
---|
2053 | |
---|
2054 | |
---|
2055 | |
---|
2056 | void cu_get_tf_name( char station[], int maxlth, char filter[], |
---|
2057 | TSyStatus *status ) |
---|
2058 | |
---|
2059 | /* returns name of transfer function derived from station name |
---|
2060 | * |
---|
2061 | * parameters of routine |
---|
2062 | * char station[]; input; station name |
---|
2063 | * int maxlth; input; maximum length of output string |
---|
2064 | * char filter[]; output; derived filter name |
---|
2065 | * TSyStatus *status; output; return status |
---|
2066 | */ |
---|
2067 | { |
---|
2068 | /* executable code */ |
---|
2069 | |
---|
2070 | if (maxlth < 7) { |
---|
2071 | *status = CUE_STROVFL; |
---|
2072 | return; |
---|
2073 | } /*endif*/ |
---|
2074 | |
---|
2075 | if (strncmp(station,"GR",2) == 0 && station[2] >= 'A' && |
---|
2076 | station[2] <= 'C' && station[3] >= '1' && station[3] <= '5') { |
---|
2077 | strcpy( filter, "GRF" ); |
---|
2078 | } else if (strcmp(station,"GEC2B") == 0 || strcmp(station,"GEC2") == 0) { |
---|
2079 | strcpy( filter, "GRSN" ); |
---|
2080 | } else if (strcmp(station,"GEC2A") == 0) { |
---|
2081 | strcpy( filter, "GERESS" ); |
---|
2082 | } else if (strncmp(station,"GE",2) == 0 && station[2] >= 'A' && |
---|
2083 | station[2] <= 'D' && station[3] >= '0' && station[3] <= '9') { |
---|
2084 | strcpy( filter, "GERESS" ); |
---|
2085 | } else if (strcmp(station,"BFO") == 0) { |
---|
2086 | strcpy( filter, "GRSN" ); |
---|
2087 | } else if (strcmp(station,"BRG") == 0) { |
---|
2088 | strcpy( filter, "GRSN" ); |
---|
2089 | } else if (strcmp(station,"BRNL") == 0) { |
---|
2090 | strcpy( filter, "GRSN" ); |
---|
2091 | } else if (strcmp(station,"BUG") == 0) { |
---|
2092 | strcpy( filter, "GRSN" ); |
---|
2093 | } else if (strcmp(station,"CLL") == 0) { |
---|
2094 | strcpy( filter, "GRSN" ); |
---|
2095 | } else if (strcmp(station,"CLZ") == 0) { |
---|
2096 | strcpy( filter, "GRSN" ); |
---|
2097 | } else if (strcmp(station,"FUR") == 0) { |
---|
2098 | strcpy( filter, "GRSN" ); |
---|
2099 | } else if (strcmp(station,"GSH") == 0) { |
---|
2100 | strcpy( filter, "GRSN" ); |
---|
2101 | } else if (strcmp(station,"HAM") == 0) { |
---|
2102 | strcpy( filter, "GRSN" ); |
---|
2103 | } else if (strcmp(station,"IBB") == 0) { |
---|
2104 | strcpy( filter, "GRSN" ); |
---|
2105 | } else if (strcmp(station,"LID") == 0) { |
---|
2106 | strcpy( filter, "GRSN" ); |
---|
2107 | } else if (strcmp(station,"MOX") == 0) { |
---|
2108 | strcpy( filter, "GRSN" ); |
---|
2109 | } else if (strcmp(station,"SEG") == 0) { |
---|
2110 | strcpy( filter, "GRSN" ); |
---|
2111 | } else if (strcmp(station,"STU") == 0) { |
---|
2112 | strcpy( filter, "GRSN" ); |
---|
2113 | } else if (strcmp(station,"TNS") == 0) { |
---|
2114 | strcpy( filter, "GRSN" ); |
---|
2115 | } else if (strcmp(station,"WET") == 0) { |
---|
2116 | strcpy( filter, "GRSN" ); |
---|
2117 | } else { |
---|
2118 | strcpy( filter, station ); |
---|
2119 | } /*endif*/ |
---|
2120 | |
---|
2121 | } /* end of cu_get_tf_name */ |
---|
2122 | |
---|
2123 | |
---|
2124 | |
---|
2125 | /*--------------------------------------------------------------------------*/ |
---|
2126 | |
---|
2127 | |
---|
2128 | |
---|
2129 | void cu_print_info( char str[] ) |
---|
2130 | |
---|
2131 | /* prints out informational message |
---|
2132 | * |
---|
2133 | * parameters of routine |
---|
2134 | * char str[]; input; message to print |
---|
2135 | */ |
---|
2136 | { |
---|
2137 | /* executable code */ |
---|
2138 | |
---|
2139 | printf( "SHM-i! %s\n", str ); |
---|
2140 | |
---|
2141 | } /* end of cu_print_info */ |
---|
2142 | |
---|
2143 | |
---|
2144 | |
---|
2145 | /*--------------------------------------------------------------------------*/ |
---|
2146 | |
---|
2147 | |
---|
2148 | |
---|
2149 | void cu_set_string( Widget w, char str[] ) |
---|
2150 | |
---|
2151 | /* sets string in text widget str. Checks whether str is empty, in this case |
---|
2152 | * a single blank is inserted because of bug in Motif software |
---|
2153 | * |
---|
2154 | * parameters of routine |
---|
2155 | * Widget w; input; widget ID |
---|
2156 | * char str[]; input; text to be set |
---|
2157 | */ |
---|
2158 | { |
---|
2159 | /* local variables */ |
---|
2160 | |
---|
2161 | /* executable code */ |
---|
2162 | |
---|
2163 | if (*str == '\0') { |
---|
2164 | XmTextSetString( w, " " ); |
---|
2165 | } else { |
---|
2166 | XmTextSetString( w, str ); |
---|
2167 | } /*endif*/ |
---|
2168 | |
---|
2169 | } /* end of cu_set_string */ |
---|
2170 | |
---|
2171 | |
---|
2172 | |
---|
2173 | /*--------------------------------------------------------------------------*/ |
---|
2174 | |
---|
2175 | |
---|
2176 | |
---|
2177 | char *cu_get_string( Widget w ) |
---|
2178 | |
---|
2179 | /* gets string from text widget str. Checks whether string in text widget is |
---|
2180 | * a single blank, in this case a pointer to an empty string is returned |
---|
2181 | * because of bug in Motif software |
---|
2182 | * |
---|
2183 | * parameters of routine |
---|
2184 | * Widget w; input; widget ID |
---|
2185 | * returns pointer to static string |
---|
2186 | */ |
---|
2187 | { |
---|
2188 | /* local variables */ |
---|
2189 | static char zero='\0'; |
---|
2190 | char *ptr; /* pointer to widget string */ |
---|
2191 | |
---|
2192 | /* executable code */ |
---|
2193 | |
---|
2194 | ptr = (char *)XmTextGetString( w ); |
---|
2195 | if (ptr[0] == ' ' && ptr[1] == '\0') { |
---|
2196 | return &zero; |
---|
2197 | } else { |
---|
2198 | return ptr; |
---|
2199 | } /*endif*/ |
---|
2200 | |
---|
2201 | } /* end of cu_set_string */ |
---|
2202 | |
---|
2203 | |
---|
2204 | |
---|
2205 | /*---------------------------------------------------------------------------*/ |
---|
2206 | |
---|
2207 | |
---|
2208 | |
---|
2209 | #define ON_ERROR_RETURN \ |
---|
2210 | if (Severe(status)) { \ |
---|
2211 | err_setcontext( " ## station " ); \ |
---|
2212 | err_setcontext( station ); \ |
---|
2213 | return; \ |
---|
2214 | } |
---|
2215 | |
---|
2216 | |
---|
2217 | |
---|
2218 | void cu_reference_location( STATLOC *lat, STATLOC *lon, float *xrel, |
---|
2219 | float *yrel, int *arrcode, STATUS *status ) |
---|
2220 | |
---|
2221 | /* returns location of reference point |
---|
2222 | * |
---|
2223 | * parameters of routine |
---|
2224 | * STATLOC *lat, *lon; output; reference location (if not NULL) |
---|
2225 | * float *xrel, *yrel; output; relative location in km (if not NULL) |
---|
2226 | * int *arrcode; output; array code (if not NULL) |
---|
2227 | * STATUS *status; output; return status |
---|
2228 | */ |
---|
2229 | { |
---|
2230 | /* local variables */ |
---|
2231 | TPmTrace *trc; /* pointer to trace */ |
---|
2232 | char station[BC_SHORTSTRLTH+1]; /* current station name */ |
---|
2233 | int dsplth; /* number of traces on display */ |
---|
2234 | STATUS locstat; /* local status */ |
---|
2235 | GLT_STATINF *statinf; /* pointer to station info */ |
---|
2236 | STATLOC mean_lat, mean_lon; /* mean location */ |
---|
2237 | float mean_x, mean_y; /* mean relative location */ |
---|
2238 | int mean_arrcode; /* array code of all */ |
---|
2239 | |
---|
2240 | /* executable code */ |
---|
2241 | |
---|
2242 | /* check for first trace */ |
---|
2243 | if (strcmp(GpGetString(cGpS_refstation),"FIRST") == 0) { |
---|
2244 | trc = db_getp( NULL, EP_DSPN, NULL ); |
---|
2245 | if (trc == NULL) {*status = CUE_NOTRACES; return;} |
---|
2246 | db_gets( trc, ES_STATION, BC_SHORTSTRLTH, station, status ); |
---|
2247 | ON_ERROR_RETURN |
---|
2248 | statinf = gl_store_station( station, TRUE, status ); |
---|
2249 | ON_ERROR_RETURN |
---|
2250 | if (lat != NULL) *lat = statinf->lat; |
---|
2251 | if (lon != NULL) *lon = statinf->lon; |
---|
2252 | if (xrel != NULL) *xrel = statinf->xrel; |
---|
2253 | if (yrel != NULL) *yrel = statinf->yrel; |
---|
2254 | if (arrcode != NULL) *arrcode = statinf->arr_id; |
---|
2255 | return; |
---|
2256 | } /*endif*/ |
---|
2257 | |
---|
2258 | /* check for other station than center */ |
---|
2259 | if (strcmp(GpGetString(cGpS_refstation),"CENTRE") != 0 |
---|
2260 | && strcmp(GpGetString(cGpS_refstation),"CENTER") != 0) { |
---|
2261 | statinf = gl_store_station( GpGetString(cGpS_refstation), TRUE, status ); |
---|
2262 | ON_ERROR_RETURN |
---|
2263 | if (lat != NULL) *lat = statinf->lat; |
---|
2264 | if (lon != NULL) *lon = statinf->lon; |
---|
2265 | if (xrel != NULL) *xrel = statinf->xrel; |
---|
2266 | if (yrel != NULL) *yrel = statinf->yrel; |
---|
2267 | if (arrcode != NULL) *arrcode = statinf->arr_id; |
---|
2268 | return; |
---|
2269 | } /*endif*/ |
---|
2270 | |
---|
2271 | /* loop all traces on display and compute center */ |
---|
2272 | /* !!! actually this is not quite correct, fix it later !!! */ |
---|
2273 | dsplth = 0; |
---|
2274 | mean_lat = mean_lon = 0.0; |
---|
2275 | mean_x = mean_y = 0.0; |
---|
2276 | mean_arrcode = -1; |
---|
2277 | trc = NULL; |
---|
2278 | FOREVER { |
---|
2279 | trc = db_getp( trc, EP_DSPN, NULL ); |
---|
2280 | if (trc == NULL) break; |
---|
2281 | locstat = BC_NOERROR; |
---|
2282 | db_gets( trc, ES_STATION, BC_SHORTSTRLTH, station, status ); |
---|
2283 | ON_ERROR_RETURN |
---|
2284 | if (strcmp(station,"BEAM") == 0 || strcmp(station,"ALIGN") == 0) |
---|
2285 | continue; |
---|
2286 | statinf = gl_store_station( station, TRUE, status ); |
---|
2287 | ON_ERROR_RETURN |
---|
2288 | mean_lat += statinf->lat; |
---|
2289 | mean_lon += statinf->lon; |
---|
2290 | mean_x += statinf->xrel; |
---|
2291 | mean_y += statinf->yrel; |
---|
2292 | if (mean_arrcode == -1) mean_arrcode = statinf->arr_id; |
---|
2293 | else if (mean_arrcode != 0) |
---|
2294 | if (mean_arrcode != statinf->arr_id) |
---|
2295 | mean_arrcode = 0; |
---|
2296 | dsplth++; |
---|
2297 | } /*endfor*/ |
---|
2298 | |
---|
2299 | if (dsplth == 0) { |
---|
2300 | *status= CUE_NOTRACES; |
---|
2301 | return; |
---|
2302 | } /*endif*/ |
---|
2303 | |
---|
2304 | if (lat != NULL) *lat = mean_lat / (float)dsplth; |
---|
2305 | if (lon != NULL) *lon = mean_lon / (float)dsplth; |
---|
2306 | if (xrel != NULL) *xrel = mean_x / (float)dsplth; |
---|
2307 | if (yrel != NULL) *yrel = mean_y / (float)dsplth; |
---|
2308 | if (arrcode != NULL) *arrcode = mean_arrcode; |
---|
2309 | |
---|
2310 | } /* end of cu_reference_location */ |
---|
2311 | |
---|
2312 | |
---|
2313 | |
---|
2314 | #undef ON_ERROR_RETURN |
---|
2315 | |
---|
2316 | |
---|
2317 | |
---|
2318 | /*--------------------------------------------------------------------------*/ |
---|
2319 | |
---|
2320 | |
---|
2321 | |
---|
2322 | void cu_delete_trace( void *trc ) |
---|
2323 | |
---|
2324 | /* deletes trace from memory |
---|
2325 | * |
---|
2326 | * parameters of routine |
---|
2327 | * void *trc; input; pointer to trace |
---|
2328 | */ |
---|
2329 | { |
---|
2330 | /* local variables */ |
---|
2331 | |
---|
2332 | /* executable code */ |
---|
2333 | |
---|
2334 | sy_deallocmem( db_getp(trc,EP_DATA,NULL) ); |
---|
2335 | if (db_getp(trc,EP_USR1,NULL) != NULL) |
---|
2336 | sy_deallocmem( db_getp(trc,EP_USR1,NULL) ); |
---|
2337 | if (db_getp(trc,EP_USR2,NULL) != NULL) |
---|
2338 | sy_deallocmem( db_getp(trc,EP_USR2,NULL) ); |
---|
2339 | db_delist( gc, trc ); |
---|
2340 | db_delete( trc ); |
---|
2341 | |
---|
2342 | } /* end of cu_delete_trace */ |
---|
2343 | |
---|
2344 | |
---|
2345 | |
---|
2346 | /*--------------------------------------------------------------------------*/ |
---|
2347 | |
---|
2348 | |
---|
2349 | |
---|
2350 | void cu_get_stream_string( TPmTrace *trc, char stream[], STATUS *status ) |
---|
2351 | |
---|
2352 | /* Returns stream string of specified trace. If status != NULL then |
---|
2353 | * error codes are returned otherwise 'X'-characters are copied to the |
---|
2354 | * output string. Minimum length of output string is cBcShortStrLth. |
---|
2355 | * |
---|
2356 | * parameters of routine |
---|
2357 | * TPmTrace *trc; input; pointer to trace |
---|
2358 | * char stream[]; output; stream string (e.g. BFO-BH-Z) |
---|
2359 | * STATUS *status; output; return status |
---|
2360 | */ |
---|
2361 | { |
---|
2362 | /* local variables */ |
---|
2363 | char str[cBcLineLth+1]; /* scratch string */ |
---|
2364 | STATUS locstat; /* local status */ |
---|
2365 | char comp, ch1, ch2; /* channel and component info */ |
---|
2366 | |
---|
2367 | /* executable code */ |
---|
2368 | |
---|
2369 | locstat = cBcNoError; |
---|
2370 | db_gets( trc, ES_STATION, BC_LINELTH, str, &locstat ); |
---|
2371 | if (SySevere(&locstat)) { |
---|
2372 | if (status != NULL) {*status = locstat; return;} |
---|
2373 | strcpy( str, "XXX" ); |
---|
2374 | } /*endif*/ |
---|
2375 | if (strlen(str) >= cBcShortStrLth-5) str[cBcShortStrLth-5] = '\0'; |
---|
2376 | |
---|
2377 | locstat = cBcNoError; |
---|
2378 | comp = db_getc( trc, EC_COMP, &locstat ); |
---|
2379 | if (SySevere(&locstat)) { |
---|
2380 | if (status != NULL) {*status = locstat; return;} |
---|
2381 | comp = 'X'; |
---|
2382 | } /*endif*/ |
---|
2383 | |
---|
2384 | locstat = cBcNoError; |
---|
2385 | ch1 = db_getc( trc, EC_CHAN1, &locstat ); |
---|
2386 | if (SySevere(&locstat)) { |
---|
2387 | if (status != NULL) {*status = locstat; return;} |
---|
2388 | ch1 = 'X'; |
---|
2389 | } /*endif*/ |
---|
2390 | |
---|
2391 | locstat = cBcNoError; |
---|
2392 | ch2 = db_getc( trc, EC_CHAN2, &locstat ); |
---|
2393 | if (SySevere(&locstat)) { |
---|
2394 | if (status != NULL) {*status = locstat; return;} |
---|
2395 | ch2 = 'X'; |
---|
2396 | } /*endif*/ |
---|
2397 | |
---|
2398 | sprintf( stream, "%s-%c%c-%c", str, ch1, ch2, comp ); |
---|
2399 | |
---|
2400 | } /* end cu_get_stream_string */ |
---|
2401 | |
---|
2402 | |
---|
2403 | |
---|
2404 | /*--------------------------------------------------------------------------*/ |
---|
2405 | |
---|
2406 | |
---|
2407 | |
---|
2408 | void cu_trace_check( int ptrop ) |
---|
2409 | |
---|
2410 | /* Loops all traces in list (specified by ptrop) and prints station names |
---|
2411 | * and components |
---|
2412 | * |
---|
2413 | * parameters of routine |
---|
2414 | * int ptrop; input; pointer name |
---|
2415 | */ |
---|
2416 | { |
---|
2417 | /* local variables */ |
---|
2418 | void *trc; /* pointer to trace */ |
---|
2419 | TSyStatus locstat; /* return status */ |
---|
2420 | char station[cBcFileLth+1]; /* current station name */ |
---|
2421 | int t; /* trace counter */ |
---|
2422 | |
---|
2423 | /* executable code */ |
---|
2424 | |
---|
2425 | t = 0; |
---|
2426 | trc = NULL; |
---|
2427 | FOREVER { |
---|
2428 | locstat = cBcNoError; |
---|
2429 | trc = db_getp( trc, ptrop, &locstat ); |
---|
2430 | if (trc == NULL) break; |
---|
2431 | locstat = cBcNoError; |
---|
2432 | db_gets( trc, ES_STATION, cBcLineLth, station, &locstat ); |
---|
2433 | printf( "trcchk: %02d: %s\n", ++t, station ); |
---|
2434 | } /*endfor*/ |
---|
2435 | |
---|
2436 | } /* end of cu_trace_check */ |
---|
2437 | |
---|
2438 | |
---|
2439 | |
---|
2440 | /*---------------------------------------------------------------------------*/ |
---|
2441 | |
---|
2442 | |
---|
2443 | |
---|
2444 | void cu_lookup_filter( char station[], char ttime[], char tfname[], |
---|
2445 | int *trcflags, TSyStatus *status ) |
---|
2446 | |
---|
2447 | /* Tries to find transfer function name for given station. If not found |
---|
2448 | * station name is returned in tfname. 'station' and 'tfname' may be the |
---|
2449 | * same variable. |
---|
2450 | * |
---|
2451 | * parameters of routine |
---|
2452 | * char station[]; input; station name |
---|
2453 | * char ttime[]; input; trace time |
---|
2454 | * char tfname[]; output; filter name |
---|
2455 | * int *trcflags output; trace flags to be set on created traces |
---|
2456 | * TSyStatus *status; output; return status |
---|
2457 | */ |
---|
2458 | { |
---|
2459 | /* local variables */ |
---|
2460 | char *env; /* pointer to value of SH_INPUTS */ |
---|
2461 | char lookup_file[cBcFileLth+1]; /* name of lookup table */ |
---|
2462 | FILE *look; /* pointer to lookup table file */ |
---|
2463 | char line[cBcLineLth+1]; /* current line of file */ |
---|
2464 | char stat[cBcLineLth+1]; /* local copy of station name */ |
---|
2465 | char l_station[cBcLineLth+1]; /* current station */ |
---|
2466 | char l_filter[cBcLineLth+1]; /* current filter */ |
---|
2467 | char t_from[cBcLineLth+1]; /* time interval start */ |
---|
2468 | char t_until[cBcLineLth+1]; /* time interval end */ |
---|
2469 | char flagstr[cBcLineLth+1]; /* additional info */ |
---|
2470 | float tdiff; /* difference time */ |
---|
2471 | int readret; /* number of items read */ |
---|
2472 | int filecnt; /* file counter */ |
---|
2473 | char *fl; /* pointer to lookup file name */ |
---|
2474 | TSyStatus locstat; /* return status */ |
---|
2475 | |
---|
2476 | /* executable code */ |
---|
2477 | |
---|
2478 | /* copy station name */ |
---|
2479 | if (strlen(station) > cBcLineLth) { |
---|
2480 | *status = CUE_STROVFL; |
---|
2481 | return; |
---|
2482 | } /*endif*/ |
---|
2483 | if (strncmp(station,"B@",2) == 0) { |
---|
2484 | strcpy( stat, station+2 ); |
---|
2485 | } else { |
---|
2486 | strcpy( stat, station ); |
---|
2487 | } /*endif*/ |
---|
2488 | |
---|
2489 | *trcflags = 0; |
---|
2490 | |
---|
2491 | /* search built-in table (faster) */ |
---|
2492 | if (stat[0] == 'G' && stat[1] == 'R') { |
---|
2493 | if (strncmp(stat,"GRA1-BH-",8) == 0) { |
---|
2494 | locstat = cBcNoError; |
---|
2495 | tdiff = tc_tdiff( ttime, "26-may-2006_20:00", &locstat ); |
---|
2496 | if (tdiff < 0.0) { |
---|
2497 | strcpy(tfname,"GRF"); return; |
---|
2498 | } else { |
---|
2499 | strcpy(tfname,"GRSN"); return; |
---|
2500 | } /*endif*/ |
---|
2501 | } /*endif*/ |
---|
2502 | if (strncmp(stat,"GRA2-BH-",8) == 0) { |
---|
2503 | locstat = cBcNoError; |
---|
2504 | tdiff = tc_tdiff( ttime, "09-Oct-2006_9:00", &locstat ); |
---|
2505 | if (tdiff < 0.0) { |
---|
2506 | strcpy(tfname,"GRF"); return; |
---|
2507 | } else { |
---|
2508 | strcpy(tfname,"GRSN"); return; |
---|
2509 | } /*endif*/ |
---|
2510 | } /*endif*/ |
---|
2511 | if (strncmp(stat,"GRA3-BH-",8) == 0) { |
---|
2512 | locstat = cBcNoError; |
---|
2513 | tdiff = tc_tdiff( ttime, "11-Oct-2006_9:00", &locstat ); |
---|
2514 | if (tdiff < 0.0) { |
---|
2515 | strcpy(tfname,"GRF"); return; |
---|
2516 | } else { |
---|
2517 | strcpy(tfname,"GRSN"); return; |
---|
2518 | } /*endif*/ |
---|
2519 | } /*endif*/ |
---|
2520 | if (strncmp(stat,"GRA4-BH-",8) == 0) { |
---|
2521 | locstat = cBcNoError; |
---|
2522 | tdiff = tc_tdiff( ttime, "25-Sep-2006_8:00", &locstat ); |
---|
2523 | if (tdiff < 0.0) { |
---|
2524 | strcpy(tfname,"GRF"); return; |
---|
2525 | } else { |
---|
2526 | strcpy(tfname,"GRSN"); return; |
---|
2527 | } /*endif*/ |
---|
2528 | } /*endif*/ |
---|
2529 | if (strncmp(stat,"GRB1-BH-",8) == 0) { |
---|
2530 | locstat = cBcNoError; |
---|
2531 | tdiff = tc_tdiff( ttime, "15-Sep-2006_8:00", &locstat ); |
---|
2532 | if (tdiff < 0.0) { |
---|
2533 | strcpy(tfname,"GRF"); return; |
---|
2534 | } else { |
---|
2535 | strcpy(tfname,"GRSN"); return; |
---|
2536 | } /*endif*/ |
---|
2537 | } /*endif*/ |
---|
2538 | if (strncmp(stat,"GRB2-BH-",8) == 0) { |
---|
2539 | locstat = cBcNoError; |
---|
2540 | tdiff = tc_tdiff( ttime, "21-jun-2006_9:07", &locstat ); |
---|
2541 | if (tdiff < 0.0) { |
---|
2542 | strcpy(tfname,"GRF"); return; |
---|
2543 | } else { |
---|
2544 | strcpy(tfname,"GRSN"); return; |
---|
2545 | } /*endif*/ |
---|
2546 | } /*endif*/ |
---|
2547 | if (strncmp(stat,"GRB3-BH-",8) == 0) { |
---|
2548 | locstat = cBcNoError; |
---|
2549 | tdiff = tc_tdiff( ttime, "19-oct-2006_9:00", &locstat ); |
---|
2550 | if (tdiff < 0.0) { |
---|
2551 | strcpy(tfname,"GRF"); return; |
---|
2552 | } else { |
---|
2553 | strcpy(tfname,"GRSN"); return; |
---|
2554 | } /*endif*/ |
---|
2555 | } /*endif*/ |
---|
2556 | if (strncmp(stat,"GRB4-BH-",8) == 0) { |
---|
2557 | locstat = cBcNoError; |
---|
2558 | tdiff = tc_tdiff( ttime, "28-Sep-2006_10:00", &locstat ); |
---|
2559 | if (tdiff < 0.0) { |
---|
2560 | strcpy(tfname,"GRF"); return; |
---|
2561 | } else { |
---|
2562 | strcpy(tfname,"GRSN"); return; |
---|
2563 | } /*endif*/ |
---|
2564 | } /*endif*/ |
---|
2565 | if (strncmp(stat,"GRB5-BH-",8) == 0) { |
---|
2566 | locstat = cBcNoError; |
---|
2567 | tdiff = tc_tdiff( ttime, "7-aug-2006_9:00", &locstat ); |
---|
2568 | if (tdiff < 0.0) { |
---|
2569 | strcpy(tfname,"GRF"); return; |
---|
2570 | } else { |
---|
2571 | strcpy(tfname,"GRSN"); return; |
---|
2572 | } /*endif*/ |
---|
2573 | } /*endif*/ |
---|
2574 | if (strncmp(stat,"GRC1-BH-",8) == 0) { |
---|
2575 | locstat = cBcNoError; |
---|
2576 | tdiff = tc_tdiff( ttime, "15-mar-2005_9:00", &locstat ); |
---|
2577 | if (tdiff < 0.0) { |
---|
2578 | strcpy(tfname,"GRF"); return; |
---|
2579 | } else { |
---|
2580 | strcpy(tfname,"GRSN"); return; |
---|
2581 | } /*endif*/ |
---|
2582 | } /*endif*/ |
---|
2583 | if (strncmp(stat,"GRC2-BH-",8) == 0) { |
---|
2584 | locstat = cBcNoError; |
---|
2585 | tdiff = tc_tdiff( ttime, "9-may-2006_9:44", &locstat ); |
---|
2586 | if (tdiff < 0.0) { |
---|
2587 | strcpy(tfname,"GRF"); return; |
---|
2588 | } else { |
---|
2589 | strcpy(tfname,"GRSN"); return; |
---|
2590 | } /*endif*/ |
---|
2591 | } /*endif*/ |
---|
2592 | if (strncmp(stat,"GRC3-BH-",8) == 0) { |
---|
2593 | locstat = cBcNoError; |
---|
2594 | tdiff = tc_tdiff( ttime, "26-jul-2006_9:00", &locstat ); |
---|
2595 | if (tdiff < 0.0) { |
---|
2596 | strcpy(tfname,"GRF"); return; |
---|
2597 | } else { |
---|
2598 | strcpy(tfname,"GRSN"); return; |
---|
2599 | } /*endif*/ |
---|
2600 | } /*endif*/ |
---|
2601 | if (strncmp(stat,"GRC4-BH-",8) == 0) { |
---|
2602 | locstat = cBcNoError; |
---|
2603 | tdiff = tc_tdiff( ttime, "19-Aug-2006_9:00", &locstat ); |
---|
2604 | if (tdiff < 0.0) { |
---|
2605 | strcpy(tfname,"GRF"); return; |
---|
2606 | } else { |
---|
2607 | strcpy(tfname,"GRSN"); return; |
---|
2608 | } /*endif*/ |
---|
2609 | } /*endif*/ |
---|
2610 | } else if (stat[0] == 'G' && stat[1] == 'E') { |
---|
2611 | if (strcmp(stat,"GEA0-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2612 | if (strcmp(stat,"GEA0-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2613 | if (strcmp(stat,"GEA0-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2614 | if (strcmp(stat,"GEA1-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2615 | if (strcmp(stat,"GEA1-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2616 | if (strcmp(stat,"GEA1-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2617 | if (strcmp(stat,"GEA2-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2618 | if (strcmp(stat,"GEA2-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2619 | if (strcmp(stat,"GEA2-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2620 | if (strcmp(stat,"GEA3-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2621 | if (strcmp(stat,"GEA3-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2622 | if (strcmp(stat,"GEA3-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2623 | if (strcmp(stat,"GEB1-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2624 | if (strcmp(stat,"GEB1-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2625 | if (strcmp(stat,"GEB1-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2626 | if (strcmp(stat,"GEB2-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2627 | if (strcmp(stat,"GEB2-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2628 | if (strcmp(stat,"GEB2-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2629 | if (strcmp(stat,"GEB3-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2630 | if (strcmp(stat,"GEB3-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2631 | if (strcmp(stat,"GEB3-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2632 | if (strcmp(stat,"GEB4-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2633 | if (strcmp(stat,"GEB4-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2634 | if (strcmp(stat,"GEB4-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2635 | if (strcmp(stat,"GEB5-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2636 | if (strcmp(stat,"GEB5-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2637 | if (strcmp(stat,"GEB5-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2638 | if (strcmp(stat,"GEC1-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2639 | if (strcmp(stat,"GEC1-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2640 | if (strcmp(stat,"GEC1-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2641 | if (strcmp(stat,"GEC2-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2642 | if (strcmp(stat,"GEC2-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2643 | if (strcmp(stat,"GEC2-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2644 | if (strcmp(stat,"GEC3-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2645 | if (strcmp(stat,"GEC3-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2646 | if (strcmp(stat,"GEC3-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2647 | if (strcmp(stat,"GEC4-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2648 | if (strcmp(stat,"GEC4-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2649 | if (strcmp(stat,"GEC4-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2650 | if (strcmp(stat,"GEC5-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2651 | if (strcmp(stat,"GEC5-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2652 | if (strcmp(stat,"GEC5-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2653 | if (strcmp(stat,"GEC6-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2654 | if (strcmp(stat,"GEC6-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2655 | if (strcmp(stat,"GEC6-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2656 | if (strcmp(stat,"GEC7-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2657 | if (strcmp(stat,"GEC7-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2658 | if (strcmp(stat,"GEC7-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2659 | if (strcmp(stat,"GED1-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2660 | if (strcmp(stat,"GED1-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2661 | if (strcmp(stat,"GED1-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2662 | if (strcmp(stat,"GED2-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2663 | if (strcmp(stat,"GED2-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2664 | if (strcmp(stat,"GED2-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2665 | if (strcmp(stat,"GED3-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2666 | if (strcmp(stat,"GED3-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2667 | if (strcmp(stat,"GED3-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2668 | if (strcmp(stat,"GED4-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2669 | if (strcmp(stat,"GED4-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2670 | if (strcmp(stat,"GED4-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2671 | if (strcmp(stat,"GED5-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2672 | if (strcmp(stat,"GED5-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2673 | if (strcmp(stat,"GED5-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2674 | if (strcmp(stat,"GED6-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2675 | if (strcmp(stat,"GED6-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2676 | if (strcmp(stat,"GED6-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2677 | if (strcmp(stat,"GED7-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2678 | if (strcmp(stat,"GED7-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2679 | if (strcmp(stat,"GED7-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2680 | if (strcmp(stat,"GED8-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2681 | if (strcmp(stat,"GED8-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2682 | if (strcmp(stat,"GED8-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2683 | if (strcmp(stat,"GED9-SH-Z") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2684 | if (strcmp(stat,"GED9-SH-N") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2685 | if (strcmp(stat,"GED9-SH-E") == 0) {strcpy(tfname,"GERESS"); return;} |
---|
2686 | } /*endif*/ |
---|
2687 | if (strcmp(stat,"BFO-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2688 | if (strcmp(stat,"BFO-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2689 | if (strcmp(stat,"BFO-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2690 | if (strcmp(stat,"BRG-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2691 | if (strcmp(stat,"BRG-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2692 | if (strcmp(stat,"BRG-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2693 | if (strcmp(stat,"BRNL-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2694 | if (strcmp(stat,"BRNL-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2695 | if (strcmp(stat,"BRNL-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2696 | if (strcmp(stat,"BSEG-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2697 | if (strcmp(stat,"BSEG-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2698 | if (strcmp(stat,"BSEG-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2699 | if (strcmp(stat,"BUG-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2700 | if (strcmp(stat,"BUG-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2701 | if (strcmp(stat,"BUG-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2702 | if (strcmp(stat,"CLL-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2703 | if (strcmp(stat,"CLL-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2704 | if (strcmp(stat,"CLL-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2705 | if (strcmp(stat,"CLZ-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2706 | if (strcmp(stat,"CLZ-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2707 | if (strcmp(stat,"CLZ-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2708 | if (strcmp(stat,"FUR-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2709 | if (strcmp(stat,"FUR-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2710 | if (strcmp(stat,"FUR-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2711 | if (strcmp(stat,"GSH-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2712 | if (strcmp(stat,"GSH-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2713 | if (strcmp(stat,"GSH-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2714 | if (strcmp(stat,"HAM-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2715 | if (strcmp(stat,"HAM-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2716 | if (strcmp(stat,"HAM-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2717 | if (strcmp(stat,"IBB-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2718 | if (strcmp(stat,"IBB-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2719 | if (strcmp(stat,"IBB-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2720 | if (strcmp(stat,"IBBN-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2721 | if (strcmp(stat,"IBBN-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2722 | if (strcmp(stat,"IBBN-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2723 | if (strcmp(stat,"LID-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2724 | if (strcmp(stat,"LID-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2725 | if (strcmp(stat,"LID-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2726 | if (strcmp(stat,"MOX-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2727 | if (strcmp(stat,"MOX-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2728 | if (strcmp(stat,"MOX-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2729 | if (strcmp(stat,"TNS-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2730 | if (strcmp(stat,"TNS-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2731 | if (strcmp(stat,"TNS-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2732 | if (strcmp(stat,"RGN-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2733 | if (strcmp(stat,"RGN-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2734 | if (strcmp(stat,"RGN-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2735 | if (strcmp(stat,"STU-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2736 | if (strcmp(stat,"STU-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2737 | if (strcmp(stat,"STU-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2738 | if (strcmp(stat,"WET-BH-Z") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2739 | if (strcmp(stat,"WET-BH-N") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2740 | if (strcmp(stat,"WET-BH-E") == 0) {strcpy(tfname,"GRSN"); return;} |
---|
2741 | if (strcmp(stat,"GRFO-BH-Z") == 0) {strcpy(tfname,"GRFO"); return;} |
---|
2742 | if (strcmp(stat,"GRFO-BH-N") == 0) {strcpy(tfname,"GRFO"); return;} |
---|
2743 | if (strcmp(stat,"GRFO-BH-E") == 0) {strcpy(tfname,"GRFO"); return;} |
---|
2744 | |
---|
2745 | /* search lookup table files */ |
---|
2746 | for (filecnt=0;;filecnt++) { |
---|
2747 | |
---|
2748 | /* get next filter lookup file and open it */ |
---|
2749 | fl = GpGetStringElem( cGpL_filter_lookup_table, filecnt ); |
---|
2750 | if (fl == NULL) break; |
---|
2751 | if (strlen(fl) > cBcFileLth) { |
---|
2752 | *status = CUE_STROVFL; |
---|
2753 | return; |
---|
2754 | } /*endif*/ |
---|
2755 | strcpy( lookup_file, fl ); |
---|
2756 | if (GpGetInt(cGpI_debug_level) > 6) |
---|
2757 | printf( "SHM-dbg7: open filter_lookup %s for %s at %s\n", |
---|
2758 | lookup_file, station, ttime ); |
---|
2759 | look = sy_fopen( lookup_file, "r" ); |
---|
2760 | if (look == NULL) { |
---|
2761 | *status = CUE_OPENREAD; |
---|
2762 | err_setcontext( " ## file " ); err_setcontext( lookup_file ); |
---|
2763 | return; |
---|
2764 | } /*endif*/ |
---|
2765 | |
---|
2766 | /* read through this filter lookup file */ |
---|
2767 | while (fgets(line,cBcLineLth,look) != NULL) { |
---|
2768 | if (*line == '!' || *line == '\n') continue; |
---|
2769 | readret = sscanf( line, "%s %s %s %s %s", l_station, l_filter, |
---|
2770 | t_from, t_until, flagstr ); |
---|
2771 | if (readret < 2 || readret == 3) { |
---|
2772 | /* at least stream name and translation name (filter) must be specified */ |
---|
2773 | *status = CUE_READ_INPUT; |
---|
2774 | err_setcontext( " ## file " ); err_setcontext( lookup_file ); |
---|
2775 | sy_fclose( look ); |
---|
2776 | return; |
---|
2777 | } /*endif*/ |
---|
2778 | if (strcmp(l_station,stat) == 0) { |
---|
2779 | /* check whether a time interval is specified and if time is within this */ |
---|
2780 | if (readret >= 4) { |
---|
2781 | if (strcmp(t_from,"...") != 0) { |
---|
2782 | tdiff = tc_tdiff( ttime, t_from, status ); |
---|
2783 | if (SySevere(status)) {sy_fclose(look); return;} |
---|
2784 | if (tdiff < 0.0) continue; /* time before start time */ |
---|
2785 | } /*endif*/ |
---|
2786 | if (strcmp(t_until,"...") != 0) { |
---|
2787 | tdiff = tc_tdiff( ttime, t_until, status ); |
---|
2788 | if (SySevere(status)) {sy_fclose(look); return;} |
---|
2789 | if (tdiff > 0.0) continue; /* time after end time */ |
---|
2790 | } /*endif*/ |
---|
2791 | } /*endif*/ |
---|
2792 | /* now check for flags */ |
---|
2793 | if (readret > 4) { |
---|
2794 | if (strstr(flagstr,"-ALERT-") != NULL) |
---|
2795 | *trcflags |= CUC_F_TRC_ALERT; |
---|
2796 | if (strstr(flagstr,"-FORCEFFT-") != NULL) |
---|
2797 | *trcflags |= CUC_F_TRC_FORCE_F; |
---|
2798 | if (strstr(flagstr,"-FORCETAB-") != NULL) |
---|
2799 | *trcflags |= CUC_F_TRC_FORCE_T; |
---|
2800 | } /*endif*/ |
---|
2801 | strcpy( tfname, l_filter ); |
---|
2802 | sy_fclose( look ); |
---|
2803 | return; |
---|
2804 | } /*endif*/ |
---|
2805 | } /*endwhile*/ |
---|
2806 | |
---|
2807 | } /*endfor*/ |
---|
2808 | |
---|
2809 | /* nothing found, return station name itself */ |
---|
2810 | if (tfname != stat) strcpy( tfname, stat ); |
---|
2811 | sy_fclose( look ); |
---|
2812 | |
---|
2813 | /* replace hyphens '-' by colons ':' */ |
---|
2814 | env = tfname-1; |
---|
2815 | while (*(++env) != '\0') |
---|
2816 | if (*env == '-') *env = ':'; |
---|
2817 | |
---|
2818 | } /* end of cu_lookup_filter */ |
---|
2819 | |
---|
2820 | |
---|
2821 | |
---|
2822 | /*--------------------------------------------------------------------------*/ |
---|
2823 | |
---|
2824 | #ifdef XXX |
---|
2825 | |
---|
2826 | /* this is the old version reading via external_routine */ |
---|
2827 | |
---|
2828 | void cu_next_read_dialog( void ) |
---|
2829 | |
---|
2830 | /* Displays next station list in dialog box |
---|
2831 | * |
---|
2832 | * parameters of routine |
---|
2833 | */ |
---|
2834 | { |
---|
2835 | /* local variables */ |
---|
2836 | static int cnt=0; /* set counter */ |
---|
2837 | char shcmd[cBcLineLth+1]; /* sh command string */ |
---|
2838 | TSyBoolean redraw; /* not used */ |
---|
2839 | TSyStatus status; /* return status */ |
---|
2840 | |
---|
2841 | /* executable code */ |
---|
2842 | |
---|
2843 | sprintf( shcmd, "shm_cmd_read_dialog statlist_%02d.stx", ++cnt ); |
---|
2844 | status = cBcNoError; |
---|
2845 | callsh( shcmd, &redraw, &status ); |
---|
2846 | |
---|
2847 | if (status != cBcNoError) { |
---|
2848 | status = cBcNoError; |
---|
2849 | cnt=1; |
---|
2850 | callsh( "shm_cmd_read_dialog statlist_01.stx", &redraw, &status ); |
---|
2851 | } /*endif*/ |
---|
2852 | |
---|
2853 | } /* end of cu_next_dialog */ |
---|
2854 | |
---|
2855 | #endif |
---|
2856 | |
---|
2857 | /*--------------------------------------------------------------------------*/ |
---|
2858 | |
---|
2859 | |
---|
2860 | |
---|
2861 | void cu_next_read_dialog( Widget w[] ) |
---|
2862 | |
---|
2863 | /* Displays next station list in dialog box |
---|
2864 | * |
---|
2865 | * parameters of routine |
---|
2866 | * Widget w[]; input; widget array |
---|
2867 | */ |
---|
2868 | { |
---|
2869 | /* local variables */ |
---|
2870 | static int cnt=0; /* set counter */ |
---|
2871 | TSyStatus status; /* return status */ |
---|
2872 | |
---|
2873 | /* executable code */ |
---|
2874 | |
---|
2875 | status = cBcNoError; |
---|
2876 | mx_name_read_buttons( w, ++cnt, &status ); |
---|
2877 | if (status != cBcNoError) { |
---|
2878 | status = cBcNoError; |
---|
2879 | cnt=1; |
---|
2880 | mx_name_read_buttons( w, cnt, &status ); |
---|
2881 | } /*endif*/ |
---|
2882 | |
---|
2883 | } /* end of cu_next_dialog */ |
---|
2884 | |
---|
2885 | |
---|
2886 | |
---|
2887 | /*--------------------------------------------------------------------------*/ |
---|
2888 | |
---|
2889 | |
---|
2890 | |
---|
2891 | void cu_set_exec_flag( int flag, TSyBoolean value ) |
---|
2892 | |
---|
2893 | /* Sets/Clears execution flags |
---|
2894 | * |
---|
2895 | * parameters of routine |
---|
2896 | * int flag; input; which flag to set/clear |
---|
2897 | * TSyBoolean val; input; new value of flag |
---|
2898 | */ |
---|
2899 | { |
---|
2900 | /* executable code */ |
---|
2901 | |
---|
2902 | if (value) { |
---|
2903 | cuv_execflags |= flag; |
---|
2904 | } else { |
---|
2905 | cuv_execflags &= ~flag; |
---|
2906 | } /*endif*/ |
---|
2907 | |
---|
2908 | } /* end of cu_set_exec_flag */ |
---|
2909 | |
---|
2910 | |
---|
2911 | |
---|
2912 | /*--------------------------------------------------------------------------*/ |
---|
2913 | |
---|
2914 | |
---|
2915 | |
---|
2916 | TSyBoolean cu_get_exec_flag( int flag ) |
---|
2917 | |
---|
2918 | /* Returns flag status |
---|
2919 | * |
---|
2920 | * parameters of routine |
---|
2921 | * int flag; input; flag to return status |
---|
2922 | */ |
---|
2923 | { |
---|
2924 | /* executable code */ |
---|
2925 | |
---|
2926 | return (cuv_execflags & flag); |
---|
2927 | |
---|
2928 | } /* end of cu_get_exec_flag */ |
---|
2929 | |
---|
2930 | |
---|
2931 | |
---|
2932 | /*--------------------------------------------------------------------------*/ |
---|
2933 | |
---|
2934 | |
---|
2935 | |
---|
2936 | void cu_clear_exec_flags( void ) |
---|
2937 | |
---|
2938 | /* Clears all execution flags |
---|
2939 | * |
---|
2940 | * no parameters |
---|
2941 | */ |
---|
2942 | { |
---|
2943 | /* executable code */ |
---|
2944 | |
---|
2945 | cuv_execflags = 0; |
---|
2946 | |
---|
2947 | } /* end of cu_clear_exec_flags */ |
---|
2948 | |
---|
2949 | |
---|
2950 | |
---|
2951 | /*--------------------------------------------------------------------------*/ |
---|
2952 | |
---|
2953 | |
---|
2954 | |
---|
2955 | void cu_rename_phase( Widget w[] ) |
---|
2956 | |
---|
2957 | /* renames phase from or to unknown phase '???' |
---|
2958 | * |
---|
2959 | * parameters of routine |
---|
2960 | * Widget w[]; input widget array |
---|
2961 | */ |
---|
2962 | { |
---|
2963 | /* local variables */ |
---|
2964 | char pname[cBcLineLth+1]; /* current phase name */ |
---|
2965 | int cnt; /* change counter */ |
---|
2966 | |
---|
2967 | /* executable code */ |
---|
2968 | |
---|
2969 | strcpy( pname, cu_get_string(w[k_widget_phase_name_text]) ); |
---|
2970 | if (PiPhaseIsPicked("???")) { |
---|
2971 | PiRenamePhase( "???", pname, &cnt ); |
---|
2972 | } else { |
---|
2973 | PiRenamePhase( pname, "???", &cnt ); |
---|
2974 | } /*endif*/ |
---|
2975 | |
---|
2976 | } /* end of cu_rename_phase */ |
---|
2977 | |
---|
2978 | |
---|
2979 | |
---|
2980 | /*--------------------------------------------------------------------------*/ |
---|
2981 | |
---|
2982 | |
---|