1 | |
---|
2 | /* file mfexec.c |
---|
3 | * ======== |
---|
4 | * |
---|
5 | * $Revision: 49 $, $Date: 2008-10-14 22:36:40 +0200 (Di, 14 Okt 2008) $ |
---|
6 | * |
---|
7 | * execution of SH commands |
---|
8 | * K. Stammler, 25-Feb-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 | |
---|
36 | #include <stdio.h> |
---|
37 | #include <string.h> |
---|
38 | #include "basecnst.h" |
---|
39 | #undef BC_DEFINE_TRUE_FALSE |
---|
40 | #ifdef BC_INC_STDLIB |
---|
41 | #include BC_INC_STDLIB |
---|
42 | #endif |
---|
43 | #include <Xm/Xm.h> |
---|
44 | #include <Xm/ToggleB.h> |
---|
45 | #include <Xm/Text.h> |
---|
46 | #include BC_SYSBASE |
---|
47 | #include "erusrdef.h" |
---|
48 | #include "motifgraph.h" |
---|
49 | #include "station_no.h" |
---|
50 | #include "cbutil.h" |
---|
51 | #include "mfexec.h" |
---|
52 | #include "cblib.h" |
---|
53 | #include "cblib3.h" |
---|
54 | #include "callsh.h" |
---|
55 | #include "infoidx.h" |
---|
56 | #include "utusrdef.h" |
---|
57 | #include "shvars.h" |
---|
58 | #include "glusrdef.h" |
---|
59 | #include "earthloc.h" |
---|
60 | #include "phaseinf.h" |
---|
61 | #include "phasemgr.h" |
---|
62 | #include "trcselect.h" |
---|
63 | #include "shm_widgets.h" |
---|
64 | #include "sysext.h" |
---|
65 | #include "seismics.h" |
---|
66 | #include "globalparams.h" |
---|
67 | |
---|
68 | |
---|
69 | /* |
---|
70 | * the following definitions must match the 'entry define shm_...' commands |
---|
71 | * in SHM_CMD_STARTUP.SHC |
---|
72 | */ |
---|
73 | #define MXC_NUM_VIEW 0 |
---|
74 | #define MXC_NUM_HIDE 1 |
---|
75 | #define MXC_NUM_FILTER 2 |
---|
76 | #define MXC_NUM_ROT 3 |
---|
77 | #define MXC_EF_VIEW (MXC_NUM_VIEW|EF_TYPE) |
---|
78 | #define MXC_EF_HIDE (MXC_NUM_HIDE|EF_TYPE) |
---|
79 | #define MXC_EF_FILTER (MXC_NUM_FILTER|EF_TYPE) |
---|
80 | #define MXC_EF_ROT (MXC_NUM_ROT|EF_TYPE) |
---|
81 | #define MXC_FLAG_VIEW (1<<MXC_NUM_VIEW) |
---|
82 | #define MXC_FLAG_HIDE (1<<MXC_NUM_HIDE) |
---|
83 | #define MXC_FLAG_FILTER (1<<MXC_NUM_FILTER) |
---|
84 | #define MXC_FLAG_ROT (1<<MXC_NUM_ROT) |
---|
85 | |
---|
86 | |
---|
87 | /* imported variables */ |
---|
88 | extern Widget xmv_w[]; /* widget array */ |
---|
89 | extern MX_CMD_READG xmv_cmd_readg; /* to write on it in external_routine */ |
---|
90 | |
---|
91 | |
---|
92 | static int mxv_display_state=0; /* display status */ |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | /* prototypes of local routines */ |
---|
97 | static void mxh_read_file_list( Widget w, MGT_DSPCTRL *ctrl, char filenames[], |
---|
98 | int format, STATUS *status ); |
---|
99 | static void mx_prepare_display( void ); |
---|
100 | static void mxh_filter_separately( Widget w, MGT_DSPCTRL *ctrl, char filter[], |
---|
101 | float autocut, STATUS *status ); |
---|
102 | static BOOLEAN mxh_rotation_is_possible( void ); |
---|
103 | static void mxh_get_vax_grflist( MX_CMD_READG *rg, char liststr[] ); |
---|
104 | static void mxh_read_statlist( char fname[], Widget w[], MX_STATLIST *sl, |
---|
105 | STATUS *status ); |
---|
106 | static void mxh_mount_cdrom( MX_CMD_READG *par, STATUS *status ); |
---|
107 | static void mxh_set_entry_name( Widget ew, char text[] ); |
---|
108 | void mx_remove_double_elements( char *str ); |
---|
109 | void mxh_compute_azimuth( char cstation[], float lat, float lon, |
---|
110 | float *azim, TSyStatus *status ); |
---|
111 | static void mxh_read_stations_from_evt( char autoevt[], char addlist[] ); |
---|
112 | static void mxh_read_location_from_evt( char autoevt[], float *lat, float *lon, |
---|
113 | TSyBoolean *found ); |
---|
114 | static void mxh_translate_button_name( char code[], char autoevt[], |
---|
115 | char addlist[], TSyStatus *status ); |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | /*--------------------------------------------------------------------------*/ |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | void mx_readg( MX_CMD_READG *par, Widget wm, Widget ws, MGT_DSPCTRL *ctrl, |
---|
124 | BOOLEAN keep_phases, char autoevt[], STATUS *status ) |
---|
125 | |
---|
126 | /* executes readg command |
---|
127 | * |
---|
128 | * parameters of routine |
---|
129 | * XM_CMD_READG *par; input; command parameters |
---|
130 | * Widget wm; input; main DrawingArea Widget |
---|
131 | * Widget ws; input; single trace window |
---|
132 | * MGT_DSPCTRL *ctrl; input; display control parameters |
---|
133 | * TSyBoolean keep_phases; input; keep phases in memory |
---|
134 | * char *autoevt input; name of evt file for retrieving stat. names |
---|
135 | * TSyStatus *status; output; return status |
---|
136 | */ |
---|
137 | { |
---|
138 | /* local variables */ |
---|
139 | static int gse_cnt=0; /* GSE counter */ |
---|
140 | char line[cBcVeryLongStrLth+1]; /* command line */ |
---|
141 | char statlist[cBcVeryLongStrLth+1]; /* station list */ |
---|
142 | char addlist[cBcLongStrLth+1]; /* parsed station string */ |
---|
143 | int i; /* bit count */ |
---|
144 | char *eptr; /* pointer to char for getenv */ |
---|
145 | TSyBoolean redraw; /* dummy */ |
---|
146 | TSyStatus locstat; /* local status */ |
---|
147 | char gsename[cBcFileLth+1]; /* name of GSE file */ |
---|
148 | |
---|
149 | /* executable code */ |
---|
150 | |
---|
151 | if (par->channum == 0 && par->format == MXC_FORMAT_SEED) { |
---|
152 | *status = MXE_NOCHANNELS; |
---|
153 | return; |
---|
154 | } /*endif*/ |
---|
155 | |
---|
156 | mg_do_drag( wm, MGC_DRAG_CLEAR, 0, 0 ); |
---|
157 | mg_plot_drag_window( ws, ctrl->show_phase_acc, status ); |
---|
158 | if (Severe(status)) return; |
---|
159 | |
---|
160 | /* translate device name if possible */ |
---|
161 | if (strcmp(par->device,"CD") == 0) { |
---|
162 | mxh_mount_cdrom( par, status ); |
---|
163 | if (Severe(status)) return; |
---|
164 | } else { |
---|
165 | eptr = getenv( par->device ); |
---|
166 | if (eptr != NULL) { |
---|
167 | if (strlen(eptr) >= BC_FILELTH) { |
---|
168 | *status = MXE_STROVFL; |
---|
169 | return; |
---|
170 | } /*endif*/ |
---|
171 | strcpy( par->device, eptr ); |
---|
172 | strcat( par->device, "/" ); |
---|
173 | } /*endif*/ |
---|
174 | } /*endif*/ |
---|
175 | |
---|
176 | if (par->keep) { |
---|
177 | mx_exec_sh( wm, ctrl, "nr" ); |
---|
178 | mx_exec_sh( wm, ctrl, "display all_dh" ); |
---|
179 | mx_exec_sh( wm, ctrl, "del _shm_filter(y)" ); |
---|
180 | mx_exec_sh( wm, ctrl, "del _shm_rot(y)" ); |
---|
181 | mx_exec_sh( wm, ctrl, "rd" ); |
---|
182 | } else { |
---|
183 | mx_exec_sh( wm, ctrl, "del all_dh" ); |
---|
184 | } /*endif*/ |
---|
185 | if (Severe(status)) return; |
---|
186 | mx_exec_sh( wm, ctrl, "dtw" ); |
---|
187 | /* mx_exec_sh( wm, ctrl, "rd" ); */ |
---|
188 | /* mx_exec_sh( wm, ctrl, "nr" ); */ |
---|
189 | |
---|
190 | /* create station list and component list */ |
---|
191 | *statlist = '\0'; |
---|
192 | for (i=0; i<MXC_STATLIST_LTH; i++) { |
---|
193 | if ((1<<i) & par->stations) { |
---|
194 | if (*statlist != '\0') strcat( statlist, "," ); |
---|
195 | mxh_translate_button_name( par->sl.code[i], autoevt, addlist, status ); |
---|
196 | if (strlen(statlist)+strlen(addlist) < cBcVeryLongStrLth) { |
---|
197 | strcat( statlist, addlist ); |
---|
198 | } else { |
---|
199 | *status = MXE_STROVFL; |
---|
200 | return; |
---|
201 | } /*endif*/ |
---|
202 | } /*endif*/ |
---|
203 | } /*endfor*/ |
---|
204 | if (strlen(statlist) > cBcVeryLongStrLth-55) { |
---|
205 | printf( "*SHM: mx_readg: station list too long\n" ); |
---|
206 | printf( " field length exceeded, abort program\n" ); |
---|
207 | exit( 1 ); |
---|
208 | } /*endif*/ |
---|
209 | if (*statlist != '\0') |
---|
210 | mx_remove_double_elements( statlist ); |
---|
211 | |
---|
212 | switch (par->format) { |
---|
213 | case MXC_FORMAT_SEED: |
---|
214 | if (par->use_readk) { |
---|
215 | |
---|
216 | /* read from VAX WORMS: (completely outdated code, no more k-files) */ |
---|
217 | /* check whether GRF or GRSN data are requested */ |
---|
218 | if (strncmp(statlist,"GRA",3) == 0 |
---|
219 | || strncmp(statlist,"GRB",3) == 0 |
---|
220 | || strncmp(statlist,"GRC",3) == 0) { |
---|
221 | /* these are GRF data ... */ |
---|
222 | ; |
---|
223 | } else { |
---|
224 | /* these are GRSN data ... */ |
---|
225 | if (par->channum > 1) |
---|
226 | printf( "*SHM: take only first channel selected\n" ); |
---|
227 | /* generate filename */ |
---|
228 | sprintf( gsename, "grn2gse_%02d.gse", ++gse_cnt ); |
---|
229 | strcpy( line, GpGetString(cGpS_defpath_extprog) ); |
---|
230 | sprintf( line+strlen(line), |
---|
231 | "grn2gse %s %s %f %s %s %s %s", |
---|
232 | par->device, par->start, par->seclth, statlist, |
---|
233 | par->comp, par->chanstr[0], gsename ); |
---|
234 | } /*endif*/ |
---|
235 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
236 | printf( "SHM-dbg2: exec: %s\n", line ); |
---|
237 | system( line ); |
---|
238 | sprintf( line, "@READGSE %s ALL", gsename ); |
---|
239 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
240 | printf( "SHM-dbg2: sh exec: %s\n", line ); |
---|
241 | mx_exec_sh( wm, ctrl, line ); |
---|
242 | /* now delete input GSE file */ |
---|
243 | /* sy_fdelete( gsename ); */ |
---|
244 | |
---|
245 | } else { |
---|
246 | |
---|
247 | /* read from Mini-SEED files */ |
---|
248 | /* to be added: check length of line */ |
---|
249 | |
---|
250 | /* make backslashes out of slashes */ |
---|
251 | eptr = par->device - 1; |
---|
252 | while (*(++eptr) != '\0') |
---|
253 | if (*eptr == '/') *eptr = '\\'; |
---|
254 | /* loop all channels */ |
---|
255 | for (i=0; i<(par->channum); i++) { |
---|
256 | #ifdef SH_SETUP_LINUX |
---|
257 | if (par->reads_invhdr) { |
---|
258 | sprintf( line, "@READS/NOSWAP/INVHDR/SFD=%s %s %s %f %s %s %s", |
---|
259 | par->sfdfile, par->device, par->start, par->seclth, |
---|
260 | statlist, par->comp, par->chanstr[i] ); |
---|
261 | } else { |
---|
262 | sprintf( line, "@READS/NOSWAP/SFD=%s %s %s %f %s %s %s", |
---|
263 | par->sfdfile, par->device, par->start, par->seclth, |
---|
264 | statlist, par->comp, par->chanstr[i] ); |
---|
265 | } /*endif*/ |
---|
266 | #else |
---|
267 | if (par->reads_invhdr) { |
---|
268 | sprintf( line, "@READS/INVHDR/SFD=%s %s %s %f %s %s %s", |
---|
269 | par->sfdfile, par->device, par->start, par->seclth, |
---|
270 | statlist, par->comp, par->chanstr[i] ); |
---|
271 | } else { |
---|
272 | sprintf( line, "@READS/SFD=%s %s %s %f %s %s %s", |
---|
273 | par->sfdfile, par->device, par->start, par->seclth, |
---|
274 | statlist, par->comp, par->chanstr[i] ); |
---|
275 | } /*endif*/ |
---|
276 | #endif |
---|
277 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
278 | printf( "SHM-dbg2: execute: >%s< length %d\n", line, strlen(line) ); |
---|
279 | mx_exec_sh( wm, ctrl, line ); |
---|
280 | } /*endfor*/ |
---|
281 | |
---|
282 | } /*endif*/ |
---|
283 | break; |
---|
284 | |
---|
285 | case MXC_FORMAT_GSE: |
---|
286 | case MXC_FORMAT_GSE2: |
---|
287 | case MXC_FORMAT_AH: |
---|
288 | case MXC_FORMAT_Q: |
---|
289 | mxh_read_file_list( wm, ctrl, par->filename, par->format, status ); |
---|
290 | if (Severe(status)) return; |
---|
291 | break; |
---|
292 | |
---|
293 | default: |
---|
294 | |
---|
295 | printf( "*SHM: mx_readg: program error\n" ); |
---|
296 | *status = MXE_PROG_BUG; |
---|
297 | return; |
---|
298 | |
---|
299 | } /*endswitch*/ |
---|
300 | |
---|
301 | cl_set_autofilters(); |
---|
302 | |
---|
303 | mx_exec_sh( wm, ctrl, "SHM_CMD_TIMEAL" ); |
---|
304 | |
---|
305 | if (keep_phases) { |
---|
306 | mg_plot_phases( wm, ctrl->show_phase_acc, status ); |
---|
307 | } /*endif*/ |
---|
308 | cl3_uppercase_names(); |
---|
309 | |
---|
310 | } /* end of mx_readg */ |
---|
311 | |
---|
312 | |
---|
313 | |
---|
314 | /*--------------------------------------------------------------------------*/ |
---|
315 | |
---|
316 | |
---|
317 | static void mxh_translate_button_name( char code[], char autoevt[], |
---|
318 | char addlist[], TSyStatus *status ) |
---|
319 | |
---|
320 | /* Translates button name into a list of stations, returned by addlist |
---|
321 | * |
---|
322 | * parameters of routine |
---|
323 | * char code[]; input; button name (station code or list abbrev) |
---|
324 | * char autoevt[]; input; name of evt file with automatic picks and loc |
---|
325 | * char addlist[]; output; resulting station list; max lth cBcLongStrLth |
---|
326 | * TSyStatus *status; output; return status |
---|
327 | */ |
---|
328 | { |
---|
329 | /* local variables */ |
---|
330 | char varname[MXC_STATSTR_LTH+2]; /* variable name */ |
---|
331 | TSyBoolean ok; /* worked ok? */ |
---|
332 | float epilat, epilon; /* epicentre location rea from evt */ |
---|
333 | float vlat1, vlat2, vlon1, vlon2;/* lat and lon area */ |
---|
334 | TSyBoolean epifound; /* epicentre found in evt */ |
---|
335 | int locvarcnt; /* location variable counter */ |
---|
336 | char vstr[cBcLongStrLth+1]; /* scratch for variable evaluation */ |
---|
337 | |
---|
338 | /* executable code */ |
---|
339 | |
---|
340 | *addlist = '\0'; |
---|
341 | if (code[0] == '$') { |
---|
342 | /* find list of stations in config file */ |
---|
343 | varname[0] = 'v'; |
---|
344 | strcpy( varname+1, code ); |
---|
345 | GpReadParameter( varname, cBcLongStrLth, addlist, &ok ); |
---|
346 | if (!ok) { |
---|
347 | *status = MXE_ILL_SUBSET; |
---|
348 | err_setcontext( " ## variable: " ); |
---|
349 | err_setcontext( varname ); |
---|
350 | *addlist = '\0'; |
---|
351 | return; |
---|
352 | } /*endif*/ |
---|
353 | } else if (strcmp(code,":AE") == 0) { |
---|
354 | if (autoevt == NULL) { |
---|
355 | printf( "*SHM: cannot translate :AE, autoevt is NULL\n" ); |
---|
356 | } else if (*autoevt == '\0') { |
---|
357 | printf( "*SHM: cannot translate :AE, autoevt is empty\n" ); |
---|
358 | } else { |
---|
359 | mxh_read_stations_from_evt( autoevt, addlist ); |
---|
360 | } /*endif*/ |
---|
361 | } else if (strcmp(code,":LOC") == 0) { |
---|
362 | if (autoevt == NULL) { |
---|
363 | /* if no autoevt file there, then use v$loc setting */ |
---|
364 | GpReadParameter( "v$loc", cBcLongStrLth, addlist, &ok ); |
---|
365 | if (!ok) { |
---|
366 | printf( "*SHM: cannot translate :LOC, autoevt is NULL and no v$loc found\n" ); |
---|
367 | *status = MXE_CONFIG_SETUP; |
---|
368 | err_setcontext( " ## variable: V$LOC not found" ); |
---|
369 | } /*endif*/ |
---|
370 | } else if (*autoevt == '\0' || strcmp(autoevt,"None") == 0) { |
---|
371 | /* same as above */ |
---|
372 | GpReadParameter( "v$loc", cBcLongStrLth, addlist, &ok ); |
---|
373 | if (!ok) { |
---|
374 | printf( "*SHM: cannot translate :LOC, autoevt is NULL and no v$loc found\n" ); |
---|
375 | *status = MXE_CONFIG_SETUP; |
---|
376 | err_setcontext( " ## variable: V$LOC not found" ); |
---|
377 | } /*endif*/ |
---|
378 | } else { |
---|
379 | /* get location from evt file */ |
---|
380 | mxh_read_location_from_evt( autoevt, &epilat, &epilon, &epifound ); |
---|
381 | if (!epifound) { |
---|
382 | /* no epicentre in evt file, behave like :AE */ |
---|
383 | printf( "*SHM: cannot translate :LOC, no epicentre found -> :AE\n" ); |
---|
384 | mxh_translate_button_name( ":AE", autoevt, addlist, status ); |
---|
385 | return; |
---|
386 | } /*endif*/ |
---|
387 | if (GpGetInt(cGpI_debug_level) > 2) |
---|
388 | printf( "SHM-dbg3: :LOC found epi %f,%f\n", epilat, epilon ); |
---|
389 | epifound = FALSE; |
---|
390 | locvarcnt = 1; |
---|
391 | FOREVER { |
---|
392 | /* read through all v$loc* variables and compare with curr. location */ |
---|
393 | sprintf( varname, "v$loc%d", locvarcnt ); |
---|
394 | GpReadParameter( varname, cBcLongStrLth, vstr, &ok ); |
---|
395 | if (!ok) break; |
---|
396 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
397 | printf( "SHM-dbg4: %s translated to %s\n", varname, vstr ); |
---|
398 | if (sscanf(vstr,"%f,%f,%f,%f %s", |
---|
399 | &vlat1,&vlon1,&vlat2,&vlon2,addlist) != 5) |
---|
400 | continue; |
---|
401 | if (vlat1 <= epilat && epilat <= vlat2 && vlon1 <= epilon |
---|
402 | && epilon <= vlon2) { |
---|
403 | epifound = TRUE; |
---|
404 | break; |
---|
405 | } /*endif*/ |
---|
406 | locvarcnt++; |
---|
407 | } /*endfor*/ |
---|
408 | if (!epifound) { |
---|
409 | GpReadParameter("v$loc", cBcLongStrLth, addlist, &ok ); |
---|
410 | if (!ok) { |
---|
411 | printf( "*SHM: no v$loc definition\n" ); |
---|
412 | *status = MXE_CONFIG_SETUP; |
---|
413 | err_setcontext( " ## variable: V$LOC not found" ); |
---|
414 | return; |
---|
415 | } /*endif*/ |
---|
416 | } /*endif*/ |
---|
417 | } /*endif*/ |
---|
418 | } else { |
---|
419 | strcpy( addlist, code ); |
---|
420 | } /*endif*/ |
---|
421 | |
---|
422 | /* if addlist is a variable, translate it */ |
---|
423 | if (addlist[0] == '$') { |
---|
424 | vstr[0] = 'v'; |
---|
425 | strcpy( vstr+1, addlist ); |
---|
426 | GpReadParameter( vstr, cBcLongStrLth, addlist, &ok ); |
---|
427 | if (!ok) { |
---|
428 | printf( "*SHM: no %s definition\n", vstr ); |
---|
429 | *status = MXE_CONFIG_SETUP; |
---|
430 | err_setcontext( " ## variable: not found: " ); |
---|
431 | err_setcontext( vstr ); |
---|
432 | return; |
---|
433 | } /*endif*/ |
---|
434 | } /*endif*/ |
---|
435 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
436 | printf( "SHM-dbg4: :LOC addlist: %s\n", addlist ); |
---|
437 | |
---|
438 | } /* end of mxh_translate_button_name */ |
---|
439 | |
---|
440 | |
---|
441 | |
---|
442 | /*--------------------------------------------------------------------------*/ |
---|
443 | |
---|
444 | |
---|
445 | |
---|
446 | void mx_filter_from_autoevt( char autoevt[], char filtername[], float *autocut ) |
---|
447 | |
---|
448 | /* Determines filter using distance between autoevt location and reference |
---|
449 | * station |
---|
450 | * |
---|
451 | * parameters of routine |
---|
452 | * char autoevt[]; input; name of autoevt file |
---|
453 | * char filtername[]; output; name of filter to use |
---|
454 | * float *autocut; output; cut off that many seconds after filtering |
---|
455 | */ |
---|
456 | { |
---|
457 | /* local variables */ |
---|
458 | float epilat, epilon; /* location from autoevt */ |
---|
459 | TSyBoolean epifound; /* epicentre found? */ |
---|
460 | GLT_STATINF *statinf; /* station info of reference station */ |
---|
461 | TSyStatus locstat; /* local status variable */ |
---|
462 | double dist, az, baz; /* for distance computation */ |
---|
463 | |
---|
464 | /* executable code */ |
---|
465 | |
---|
466 | /* preset output vars in case of error returns */ |
---|
467 | *filtername = '\0'; |
---|
468 | *autocut = 5.0; |
---|
469 | |
---|
470 | /* read the automatic location from the evt text file */ |
---|
471 | mxh_read_location_from_evt( autoevt, &epilat, &epilon, &epifound ); |
---|
472 | if (!epifound) return; |
---|
473 | |
---|
474 | /* get the station location of the reference station */ |
---|
475 | locstat = cBcNoError; |
---|
476 | statinf = gl_store_station( GpGetString(cGpS_refstation), TRUE, &locstat ); |
---|
477 | if (SySevere(&locstat)) return; |
---|
478 | |
---|
479 | /* distance of automatic ocation from reference station */ |
---|
480 | mb_locdiff( statinf->lat, statinf->lon, epilat, epilon, &dist, &az, &baz ); |
---|
481 | |
---|
482 | /* take one of two possible filters, depending on the distance */ |
---|
483 | if (dist < GpGetFloat(cGpF_autofilter_sepdist)) { |
---|
484 | strcpy( filtername, GpGetString(cGpS_autofilter_local) ); |
---|
485 | } else { |
---|
486 | strcpy( filtername, GpGetString(cGpS_autofilter_tele) ); |
---|
487 | } /*endif*/ |
---|
488 | |
---|
489 | } /* end of mx_filter_from_autoevt */ |
---|
490 | |
---|
491 | |
---|
492 | |
---|
493 | /*--------------------------------------------------------------------------*/ |
---|
494 | |
---|
495 | |
---|
496 | |
---|
497 | void mx_filter( MX_CMD_FILTER *filter, Widget w, MGT_DSPCTRL *ctrl, |
---|
498 | STATUS *status ) |
---|
499 | |
---|
500 | /* performs filtering |
---|
501 | * |
---|
502 | * parameters of routine |
---|
503 | * MX_CMD_FILTER *filter; input; filter command parameters |
---|
504 | * Widget w; input; DrawingArea Widget |
---|
505 | * MGT_DSPCTRL *ctrl; input; display control parameters |
---|
506 | * TSyStatus *status; output; return status |
---|
507 | */ |
---|
508 | { |
---|
509 | /* local variables */ |
---|
510 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
511 | char filprefix[BC_SHORTSTRLTH+1]; /* filter prefix */ |
---|
512 | char filter_typ; /* recursive or FFT, 'R' or 'F' */ |
---|
513 | TSyBoolean same_filter; /* same filter for all traces */ |
---|
514 | unsigned filent; /* filter info entry */ |
---|
515 | int trcnum; /* trace number */ |
---|
516 | void *trc; /* trace pointer */ |
---|
517 | |
---|
518 | /* executable code */ |
---|
519 | |
---|
520 | /* if no traces on display return error status */ |
---|
521 | if (mg_dsptrcs() == 0) { |
---|
522 | *status = MXE_NO_TRACES; |
---|
523 | return; |
---|
524 | } /*endif*/ |
---|
525 | |
---|
526 | /* get filter type */ |
---|
527 | #ifdef XXX |
---|
528 | filter_typ = (shv_global.use_rec_filters) ? 'R' : 'F'; |
---|
529 | if (shv_global.filter_type != ' ') filter_typ = shv_global.filter_type; |
---|
530 | #endif |
---|
531 | filter_typ = GpGetChar( cGpC_filter_type ); |
---|
532 | |
---|
533 | /* if filtering is switched off it's quick and easy */ |
---|
534 | if (filter->name[0] == '\0') { |
---|
535 | /* delete filter entry on selected traces */ |
---|
536 | if (ts_some_trace_selected()) { |
---|
537 | /* get index number of filter entry */ |
---|
538 | db_ident( "FILTER", &filent, status ); |
---|
539 | if (SySevere(status)) return; |
---|
540 | /* loop all traces and delete filter entry */ |
---|
541 | trc = NULL; |
---|
542 | trcnum = 0; |
---|
543 | FOREVER { |
---|
544 | trc = db_getp( trc, EP_NEXT, NULL ); |
---|
545 | if (trc == NULL) break; |
---|
546 | trcnum++; |
---|
547 | if (ts_is_selected(trcnum)) |
---|
548 | db_sets( trc, filent, "", status ); |
---|
549 | } /*endfor*/ |
---|
550 | ts_clear_selections(); |
---|
551 | } /*endif*/ |
---|
552 | /* remove the filter */ |
---|
553 | mxv_display_state &= ~MXC_FLAG_FILTER; |
---|
554 | sprintf( str, "shm_cmd_filter %c ;; NONE %f %d", |
---|
555 | filter_typ, filter->autocut, |
---|
556 | (GpGetInt(cGpI_trace_normalisation)==cGp_NORM_CONST) ); |
---|
557 | mx_exec_sh( w, ctrl, str ); |
---|
558 | return; |
---|
559 | } /*endif*/ |
---|
560 | |
---|
561 | /* filtering is switched on */ |
---|
562 | mxv_display_state |= MXC_FLAG_FILTER; |
---|
563 | |
---|
564 | /* now let's check which filter(s) must be used */ |
---|
565 | cl3_check_filter( filter->name, (filter_typ == 'R'), |
---|
566 | filprefix, &same_filter, status ); |
---|
567 | if (Severe(status)) return; |
---|
568 | |
---|
569 | /* if all traces need the same filter do it with the old SH-cp and quit */ |
---|
570 | if (same_filter && !ts_some_trace_selected()) { |
---|
571 | if (filter_typ == 'R') { |
---|
572 | sprintf( str, "shm_cmd_filter r;%s;%s %f %d", |
---|
573 | filprefix, filter->name, filter->autocut, |
---|
574 | (GpGetInt(cGpI_trace_normalisation)==cGp_NORM_CONST) ); |
---|
575 | } else { |
---|
576 | sprintf( str, "shm_cmd_filter %c;%s;%s %f %d", |
---|
577 | filter_typ, filprefix, filter->name, filter->autocut, |
---|
578 | (GpGetInt(cGpI_trace_normalisation)==cGp_NORM_CONST) ); |
---|
579 | } /*endif*/ |
---|
580 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
581 | printf( "SHM-dbg2: execute >%s<\n", str ); |
---|
582 | mx_exec_sh( w, ctrl, str ); |
---|
583 | return; |
---|
584 | } /*endif*/ |
---|
585 | |
---|
586 | /* now this is the hard way */ |
---|
587 | mxh_filter_separately( w, ctrl, filter->name, filter->autocut, status ); |
---|
588 | |
---|
589 | } /* end of mx_filter */ |
---|
590 | |
---|
591 | |
---|
592 | |
---|
593 | /*--------------------------------------------------------------------------*/ |
---|
594 | |
---|
595 | |
---|
596 | |
---|
597 | void mx_exec_sh( Widget w, MGT_DSPCTRL *ctrl, char line[] ) |
---|
598 | |
---|
599 | /* executes command line |
---|
600 | * |
---|
601 | * parameters of routine |
---|
602 | * Widget w; input; widget of drawing area |
---|
603 | * MGT_DSPCTRL *ctrl; input; display control parameters |
---|
604 | * char line[]; input; command line |
---|
605 | */ |
---|
606 | { |
---|
607 | /* local variables */ |
---|
608 | TSyStatus status; /* return status */ |
---|
609 | TSyBoolean redraw; /* redraw flag */ |
---|
610 | |
---|
611 | /* executable code */ |
---|
612 | |
---|
613 | status = BC_NOERROR; |
---|
614 | callsh( line, &redraw, &status ); |
---|
615 | if (Severe(&status)) { |
---|
616 | cu_alert( status ); |
---|
617 | } else { |
---|
618 | if (redraw) |
---|
619 | mg_tracedisplay( w, ctrl, &status ); |
---|
620 | if (Severe(&status)) { |
---|
621 | cu_alert( status ); |
---|
622 | } /*endif*/ |
---|
623 | } /*endif*/ |
---|
624 | |
---|
625 | } /* end of mx_exec_sh */ |
---|
626 | |
---|
627 | |
---|
628 | |
---|
629 | /*--------------------------------------------------------------------------*/ |
---|
630 | |
---|
631 | |
---|
632 | |
---|
633 | void mx_stw( Widget wm, Widget ws, MGT_DSPCTRL *ctrl ) |
---|
634 | |
---|
635 | /* executes stw command |
---|
636 | * |
---|
637 | * parameters of routine |
---|
638 | * Widget wm; input; widget ID of main DrawingArea |
---|
639 | * Widget ws; input; widget ID of single trace DrawingArea |
---|
640 | * MGT_DSPCTRL *ctrl; input; display control parameters |
---|
641 | */ |
---|
642 | { |
---|
643 | /* local variables */ |
---|
644 | char cmd[BC_LINELTH+1]; /* command line */ |
---|
645 | float start, end; /* time window */ |
---|
646 | TSyBoolean set; /* time window set */ |
---|
647 | TSyStatus locstat=BC_NOERROR; /* local status */ |
---|
648 | |
---|
649 | /* executable code */ |
---|
650 | |
---|
651 | mg_get_drag_window( &start, &end, &set ); |
---|
652 | if (!set) return; |
---|
653 | sprintf( cmd, "stw %e %e", start, end ); |
---|
654 | mx_exec_sh( wm, ctrl, cmd ); |
---|
655 | mg_do_drag( wm, MGC_DRAG_CLEAR, 0, 0 ); |
---|
656 | mg_plot_drag_window( ws, ctrl->show_phase_acc, &locstat ); |
---|
657 | |
---|
658 | } /* end of mx_stw */ |
---|
659 | |
---|
660 | |
---|
661 | |
---|
662 | /*---------------------------------------------------------------------------*/ |
---|
663 | |
---|
664 | |
---|
665 | |
---|
666 | void mx_handle_beam( Widget wm, Widget ws, BOOLEAN do_beam, MGT_DSPCTRL *ctrl, |
---|
667 | CUT_PARAMS *par, char alignphase[], STATUS *status ) |
---|
668 | |
---|
669 | /* creates or deletes beam trace (toggle routine) |
---|
670 | * |
---|
671 | * parameters of routine |
---|
672 | * Widget wm; input; Widget ID of main window |
---|
673 | * Widget ws; input; Widget ID of single trace window |
---|
674 | * TSyBoolean do_beam; input; do beam (not align) |
---|
675 | * MGT_DSPCTRL *ctrl; input; display control |
---|
676 | * CUT_PARAMS *par; input; analysis parameters |
---|
677 | * char alignphase[]; input; name of phase to be aligned |
---|
678 | * TSyStatus *status; output; return status |
---|
679 | */ |
---|
680 | { |
---|
681 | /* local variables */ |
---|
682 | int t; /* trace counter */ |
---|
683 | TSyStatus locstat; /* local status */ |
---|
684 | char str[BC_LINELTH+1]; /* scratch */ |
---|
685 | char trcstr[BC_LINELTH+1]; /* trace list string */ |
---|
686 | TSyBoolean create_beam; /* create or delete beam */ |
---|
687 | |
---|
688 | /* executable code */ |
---|
689 | |
---|
690 | /* look for BEAM trace */ |
---|
691 | create_beam = TRUE; |
---|
692 | for (t=1; t<=mg_dsptrcs(); t++) { |
---|
693 | locstat = BC_NOERROR; |
---|
694 | db_gets( mg_trcptr(t), ES_STATION, BC_LINELTH, str, &locstat ); |
---|
695 | if (locstat == BC_NOERROR && strcmp(str,"BEAM") == 0) { |
---|
696 | create_beam = FALSE; |
---|
697 | break; |
---|
698 | } else if (locstat == BC_NOERROR && strcmp(str,"ALIGN") == 0) { |
---|
699 | create_beam = FALSE; |
---|
700 | break; |
---|
701 | } /*endif*/ |
---|
702 | } /*endfor*/ |
---|
703 | |
---|
704 | mg_do_drag( wm, MGC_DRAG_CLEAR, 0, 0 ); |
---|
705 | locstat = BC_NOERROR; |
---|
706 | mg_plot_drag_window( ws, ctrl->show_phase_acc, &locstat ); |
---|
707 | if (create_beam) { |
---|
708 | if (do_beam) { |
---|
709 | sprintf( str, "shm_cmd_make_beam %e %e %s", |
---|
710 | par->b_azimuth, par->b_slowness, GpGetString(cGpS_refstation) ); |
---|
711 | if (cu_get_exec_flag(CUC_F_EXEC_RESIDCORR)) strcat( str, " P" ); |
---|
712 | mx_exec_sh( wm, ctrl, str ); |
---|
713 | } else { |
---|
714 | cl_calc_align_times( alignphase, BC_LINELTH-19, trcstr, status ); |
---|
715 | /* this is the textlength in the sprintf cmd ^ */ |
---|
716 | if (Severe(status)) return; |
---|
717 | if (*trcstr == '\0') { |
---|
718 | *status = MXE_NO_TRACES; |
---|
719 | return; |
---|
720 | } /*endif*/ |
---|
721 | sprintf( str, "shm_cmd_make_align %s", trcstr ); |
---|
722 | mx_exec_sh( wm, ctrl, str ); |
---|
723 | } /*endif*/ |
---|
724 | } else { |
---|
725 | mx_exec_sh( wm, ctrl, "shm_cmd_delete_beam" ); |
---|
726 | } /*endif*/ |
---|
727 | |
---|
728 | } /* end of mx_handle_beam */ |
---|
729 | |
---|
730 | |
---|
731 | |
---|
732 | /*---------------------------------------------------------------------------*/ |
---|
733 | |
---|
734 | |
---|
735 | #define MAX_NEW_TRC 3 |
---|
736 | #define NEW_TRC_R 0 |
---|
737 | #define NEW_TRC_T 1 |
---|
738 | #define NEW_TRC_Z 2 |
---|
739 | |
---|
740 | |
---|
741 | |
---|
742 | void mx_rotation( Widget wm, MGT_DSPCTRL *ctrl, float azimuth, |
---|
743 | float lat, float lon, TSyStatus *status ) |
---|
744 | |
---|
745 | /* Performs rotation of traces with given azimuth of, if 0.0, computing |
---|
746 | * azimuth by given location |
---|
747 | * |
---|
748 | * parameters of routine |
---|
749 | * Widget wm; input; widget ID of main window |
---|
750 | * MGT_DSPCTRL *ctrl; input; display control |
---|
751 | * float azimuth; input; rotation angle |
---|
752 | * float lat, lon; input; event location |
---|
753 | * STATUS *status; output; return status |
---|
754 | */ |
---|
755 | { |
---|
756 | /* local variables */ |
---|
757 | void *trc; /* running index */ |
---|
758 | void *trc_z, *trc_n, *trc_e; /* trace pointers */ |
---|
759 | char comp; /* component */ |
---|
760 | char station[BC_SHORTSTRLTH+1]; /* station name */ |
---|
761 | char cstation[BC_SHORTSTRLTH+1]; /* current station name */ |
---|
762 | TSyBoolean flush; /* do rotation */ |
---|
763 | TSyStatus locstat; /* local status */ |
---|
764 | char cmd[BC_LINELTH+1]; /* command line for SH */ |
---|
765 | void *newtrc[MAX_NEW_TRC]; /* new created traces */ |
---|
766 | int newtrclth; /* number of new traces */ |
---|
767 | float xazim; /* local copy of azimuth */ |
---|
768 | TSyBoolean dmy; /* dummy */ |
---|
769 | |
---|
770 | /* executable code */ |
---|
771 | |
---|
772 | /* check whether rotated traces are there */ |
---|
773 | locstat = BC_NOERROR; |
---|
774 | trc = NULL; |
---|
775 | FOREVER { |
---|
776 | /* get next trace */ |
---|
777 | trc = db_getp( trc, EP_NEXT, NULL ); |
---|
778 | if (trc == NULL) break; |
---|
779 | if (db_getf(trc,MXC_EF_ROT,&locstat)) { |
---|
780 | mxv_display_state &= ~MXC_FLAG_ROT; |
---|
781 | mx_exec_sh( wm, ctrl, "shm_cmd_rotate unrotate" ); |
---|
782 | return; |
---|
783 | } /*endif*/ |
---|
784 | } /*endfor*/ |
---|
785 | /* no rotated traces there -> continue and make them */ |
---|
786 | |
---|
787 | /* initialize */ |
---|
788 | mxv_display_state |= MXC_FLAG_ROT; |
---|
789 | trc_z = trc_n = trc_e = NULL; |
---|
790 | *station = '\0'; |
---|
791 | mx_exec_sh( wm, ctrl, "shm_cmd_rotate begin" ); |
---|
792 | |
---|
793 | /* loop all traces in memory */ |
---|
794 | flush = FALSE; |
---|
795 | trc = NULL; |
---|
796 | do { |
---|
797 | /* get next trace */ |
---|
798 | trc = db_getp( trc, EP_NEXT, NULL ); |
---|
799 | /* get station and component */ |
---|
800 | locstat = BC_NOERROR; |
---|
801 | flush = (trc == NULL); |
---|
802 | if (!flush) { |
---|
803 | db_gets( trc, ES_STATION, BC_SHORTSTRLTH, cstation, &locstat ); |
---|
804 | if (Severe(&locstat)) {*cstation = '\0'; locstat = BC_NOERROR;} |
---|
805 | comp = db_getc( trc, EC_COMP, &locstat ); |
---|
806 | if (Severe(&locstat)) {comp = ' '; locstat = BC_NOERROR;} |
---|
807 | flush = (strcmp(station,cstation) != 0); |
---|
808 | } /*endif*/ |
---|
809 | if (flush) { |
---|
810 | /* rotate if traces are there */ |
---|
811 | if (trc_n != NULL && trc_e != NULL) { |
---|
812 | /* compute azimuth if equal to 0.0 */ |
---|
813 | if (azimuth == 0.0) { |
---|
814 | mxh_compute_azimuth( cstation, lat, lon, &xazim, status ); |
---|
815 | if (SySevere(status)) return; |
---|
816 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
817 | printf( "SHM-dbg5: rotate: azimuth %f for %s\n", |
---|
818 | xazim, cstation ); |
---|
819 | } else { |
---|
820 | xazim = azimuth; |
---|
821 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
822 | printf( "SHM-dbg5: rotate: constant azimuth %f for %s\n", |
---|
823 | xazim, cstation ); |
---|
824 | } /*endif*/ |
---|
825 | /* generate SH command line and execute it */ |
---|
826 | if (trc_z == NULL) { |
---|
827 | sprintf( cmd, "shm_cmd_rotate ;; a:%lx a:%lx %g", |
---|
828 | trc_n, trc_e, xazim ); |
---|
829 | } else { |
---|
830 | sprintf( cmd, "shm_cmd_rotate a:%lx a:%lx a:%lx %g", |
---|
831 | trc_z, trc_n, trc_e, xazim ); |
---|
832 | } /*endif*/ |
---|
833 | callsh( cmd, &dmy, status ); |
---|
834 | if (Severe(status)) return; |
---|
835 | /* get trace pointers of new traces */ |
---|
836 | db_createdlist( NULL, &newtrclth ); |
---|
837 | if (newtrclth != 2) { |
---|
838 | printf( "*SHM: mx_rotation: this cannot happen (1)\n" ); |
---|
839 | *status = MXE_PROG_BUG; |
---|
840 | return; |
---|
841 | } /*endif*/ |
---|
842 | db_createdlist( newtrc, &newtrclth ); |
---|
843 | newtrc[NEW_TRC_Z] = (trc_z == NULL) |
---|
844 | ? NULL : db_getp(newtrc[NEW_TRC_R],EP_PREV,NULL); |
---|
845 | # ifdef XPHASE |
---|
846 | /* copy phases to output traces */ |
---|
847 | if (trc_z != NULL) |
---|
848 | db_setp( newtrc[NEW_TRC_Z], EP_USRX, |
---|
849 | pi_copy_phaselist(db_getp(trc_z,EP_USRX,NULL),status),status); |
---|
850 | if (Severe(status)) return; |
---|
851 | db_setp( newtrc[NEW_TRC_R], EP_USR2, |
---|
852 | pi_copy_phaselist(db_getp(trc_n,EP_USRX,NULL),status), status ); |
---|
853 | if (Severe(status)) return; |
---|
854 | db_setp( newtrc[NEW_TRC_T], EP_USR2, |
---|
855 | pi_copy_phaselist(db_getp(trc_e,EP_USRX,NULL),status), status ); |
---|
856 | if (Severe(status)) return; |
---|
857 | # endif |
---|
858 | } /*endif*/ |
---|
859 | /* reset variables for next rotation */ |
---|
860 | strcpy( station, cstation ); |
---|
861 | trc_z = trc_n = trc_e = NULL; |
---|
862 | } /*endif*/ |
---|
863 | if (Cap(comp) == 'Z') trc_z = trc; |
---|
864 | else if (Cap(comp) == 'N') trc_n = trc; |
---|
865 | else if (Cap(comp) == 'E') trc_e = trc; |
---|
866 | } while (trc != NULL); |
---|
867 | |
---|
868 | /* cleanup */ |
---|
869 | mx_exec_sh( wm, ctrl, "shm_cmd_rotate finish" ); |
---|
870 | |
---|
871 | } /* end of mx_rotation */ |
---|
872 | |
---|
873 | |
---|
874 | #undef MAX_NEW_TRC |
---|
875 | #undef NEW_TRC_R |
---|
876 | #undef NEW_TRC_T |
---|
877 | #undef NEW_TRC_Z |
---|
878 | |
---|
879 | |
---|
880 | |
---|
881 | /*---------------------------------------------------------------------------*/ |
---|
882 | |
---|
883 | |
---|
884 | |
---|
885 | BOOLEAN mx_need_rotation( void ) |
---|
886 | |
---|
887 | /* Returns whether rotation mode is switched on. If no rotation is possible |
---|
888 | * it switches off rotation mode. |
---|
889 | * |
---|
890 | * no input parameters |
---|
891 | */ |
---|
892 | { |
---|
893 | /* local variables */ |
---|
894 | TSyBoolean redraw; /* redraw display (not used) */ |
---|
895 | TSyStatus locstat; /* local status */ |
---|
896 | |
---|
897 | /* executable code */ |
---|
898 | |
---|
899 | if (MXC_FLAG_ROT & mxv_display_state) { |
---|
900 | if (mxh_rotation_is_possible()) { |
---|
901 | return TRUE; |
---|
902 | } else { |
---|
903 | mx_clear_rotation(); |
---|
904 | locstat = BC_NOERROR; |
---|
905 | callsh( "external_routine prepare_display", &redraw, &locstat ); |
---|
906 | callsh( "hide all", &redraw, &locstat ); |
---|
907 | callsh( "display _shm_view(y)", &redraw, &locstat ); |
---|
908 | callsh( "rd r", &redraw, &locstat ); |
---|
909 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
910 | printf( "SHM-dbg2: rotation mode switched off by mx_need_rotation\n" ); |
---|
911 | return FALSE; |
---|
912 | } /*endif*/ |
---|
913 | } else { |
---|
914 | return FALSE; |
---|
915 | } /*endif*/ |
---|
916 | |
---|
917 | } /* end of mx_need_rotation */ |
---|
918 | |
---|
919 | |
---|
920 | |
---|
921 | /*---------------------------------------------------------------------------*/ |
---|
922 | |
---|
923 | |
---|
924 | |
---|
925 | static BOOLEAN mxh_rotation_is_possible( void ) |
---|
926 | |
---|
927 | /* checks whether a rotation is possible on the traces in memory |
---|
928 | * |
---|
929 | * no parameters |
---|
930 | */ |
---|
931 | { |
---|
932 | /* local variables */ |
---|
933 | TPmTrace *trc; /* pointer to current trace */ |
---|
934 | int t; /* trace counter */ |
---|
935 | TSyStatus locstat; /* local status */ |
---|
936 | char station[BC_SHORTSTRLTH+1]; /* station name */ |
---|
937 | char c_station[BC_SHORTSTRLTH+1]; /* current station */ |
---|
938 | char c_comp; /* current component */ |
---|
939 | TSyBoolean z_found, n_found, e_found; /* components found */ |
---|
940 | |
---|
941 | /* executable code */ |
---|
942 | |
---|
943 | /* loop over all traces in memory */ |
---|
944 | trc = NULL; |
---|
945 | station[0] = '\0'; |
---|
946 | z_found = n_found = e_found = FALSE; |
---|
947 | for (t=0; t<db_lstlth(); t++) { |
---|
948 | /* get next trace pointer */ |
---|
949 | locstat = BC_NOERROR; |
---|
950 | trc = db_getp( trc, EP_NEXT, &locstat ); |
---|
951 | if (Severe(&locstat)) {printf("*SHM: mx-error(10) ***\n"); continue;} |
---|
952 | /* get current station and component */ |
---|
953 | db_gets( trc, ES_STATION, BC_SHORTSTRLTH, c_station, &locstat ); |
---|
954 | if (Severe(&locstat)) continue; |
---|
955 | c_comp = db_getc( trc, EC_COMP, &locstat ); |
---|
956 | if (Severe(&locstat)) continue; |
---|
957 | if (strcmp(station,c_station) != 0) { |
---|
958 | z_found = n_found = e_found = FALSE; |
---|
959 | strcpy( station, c_station ); |
---|
960 | } /*endif*/ |
---|
961 | switch (c_comp) { |
---|
962 | case 'z': case 'Z': z_found = TRUE; break; |
---|
963 | case 'n': case 'N': n_found = TRUE; break; |
---|
964 | case 'e': case 'E': e_found = TRUE; break; |
---|
965 | } /*endswitch*/ |
---|
966 | if (z_found && n_found && e_found) return TRUE; |
---|
967 | } /*endfor*/ |
---|
968 | |
---|
969 | return FALSE; |
---|
970 | |
---|
971 | } /* end of mxh_rotation_is_possible */ |
---|
972 | |
---|
973 | |
---|
974 | |
---|
975 | /*---------------------------------------------------------------------------*/ |
---|
976 | |
---|
977 | |
---|
978 | |
---|
979 | void mx_trclist_command( Widget wm, Widget ws, MGT_DSPCTRL *ctrl, char cmd[], |
---|
980 | STATUS *status ) |
---|
981 | |
---|
982 | /* executes SH command on trace list |
---|
983 | * |
---|
984 | * parameters of routine |
---|
985 | * Widget wm, ws; input; widget ID's of drawing areas |
---|
986 | * MGT_DSPCTRL *ctrl; input; display control |
---|
987 | * char cmd[]; input; command to be executed |
---|
988 | * TSyStatus *status; output; return status |
---|
989 | */ |
---|
990 | { |
---|
991 | /* local variables */ |
---|
992 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
993 | char cmdline[BC_LINELTH+1]; /* command string */ |
---|
994 | |
---|
995 | /* executable code */ |
---|
996 | |
---|
997 | ts_get_selection_string( BC_LINELTH, str ); |
---|
998 | if (*str == '\0' && *cmd >= 'a' && *cmd <= 'z') return; |
---|
999 | if (*str == '\0') strcpy( str, "all" ); |
---|
1000 | |
---|
1001 | if (strlen(cmd)+strlen(str) > BC_LINELTH-1) { |
---|
1002 | *status = MXE_STROVFL; |
---|
1003 | return; |
---|
1004 | } /*endif*/ |
---|
1005 | sprintf( cmdline, cmd, str ); |
---|
1006 | |
---|
1007 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
1008 | printf( "SHM-dbg4: executing: >%s<\n", cmdline ); |
---|
1009 | mx_exec_sh( wm, ctrl, cmdline ); |
---|
1010 | |
---|
1011 | ts_clear_selections(); |
---|
1012 | |
---|
1013 | mg_do_drag( wm, MGC_DRAG_CLEAR, 0, 0 ); |
---|
1014 | mg_plot_drag_window( ws, ctrl->show_phase_acc, status ); |
---|
1015 | |
---|
1016 | } /* end of mx_trclist_command */ |
---|
1017 | |
---|
1018 | |
---|
1019 | |
---|
1020 | /*----------------------------------------------------------------------------*/ |
---|
1021 | |
---|
1022 | |
---|
1023 | |
---|
1024 | void mx_trclist_refml( STATUS *status ) |
---|
1025 | |
---|
1026 | /* stores reference ml in parameter list |
---|
1027 | * |
---|
1028 | * parameters of routine |
---|
1029 | * TSyStatus *status; output; return status |
---|
1030 | */ |
---|
1031 | { |
---|
1032 | /* local variables */ |
---|
1033 | char selstr[BC_LINELTH+1]; /* selection string */ |
---|
1034 | int trcnum; /* trace number */ |
---|
1035 | TPmTrace *trc; /* pointer to trace */ |
---|
1036 | char station[BC_SHORTSTRLTH+1]; /* station name of ref ml */ |
---|
1037 | char c_station[BC_SHORTSTRLTH+1]; /* current station */ |
---|
1038 | TPiPhaseRoot *proot; /* poiner to phase root */ |
---|
1039 | TPiPhaseList *plist; /* phase list */ |
---|
1040 | TPiPhase *phase; /* pointer to phase info */ |
---|
1041 | int p; /* phase counter */ |
---|
1042 | TSyStatus locstat; /* local status */ |
---|
1043 | TSyBoolean ml_done; /* found ml entry on ref. station */ |
---|
1044 | TSyBoolean is_ml_station; /* curr. station is ml ref station */ |
---|
1045 | |
---|
1046 | /* executable code */ |
---|
1047 | |
---|
1048 | ts_get_selection_string( BC_LINELTH, selstr ); |
---|
1049 | /* ts_clear_selections(); */ /* clear selection done in shm.c */ |
---|
1050 | if (*selstr == '\0') { |
---|
1051 | *status = MXE_NONE_SELECT; |
---|
1052 | return; |
---|
1053 | } else if (strchr(selstr,',') != NULL) { |
---|
1054 | *status = MXE_MANY_SELECT; |
---|
1055 | err_setcontext( " ## too many traces selected: " ); |
---|
1056 | err_setcontext( selstr ); |
---|
1057 | return; |
---|
1058 | } /*endif*/ |
---|
1059 | |
---|
1060 | /* get station name of selected trace */ |
---|
1061 | trcnum = 0; |
---|
1062 | sscanf( selstr, "%d", &trcnum ); |
---|
1063 | trc = mg_trcptr( trcnum ); |
---|
1064 | if (trc == NULL) { |
---|
1065 | *status = MXE_PROG_BUG; |
---|
1066 | err_setcontext( " ## selected trace resulted in NULL pointer" ); |
---|
1067 | return; |
---|
1068 | } /*endif*/ |
---|
1069 | db_gets( trc, ES_STATION, BC_SHORTSTRLTH, station, status ); |
---|
1070 | if (Severe(status)) return; |
---|
1071 | |
---|
1072 | /* loop all phases and look for ml entries */ |
---|
1073 | ml_done = FALSE; |
---|
1074 | proot = NULL; |
---|
1075 | FOREVER { |
---|
1076 | /* get next phase root pointer */ |
---|
1077 | proot = PiNextPhaseRoot( proot ); |
---|
1078 | if (proot == NULL) break; |
---|
1079 | /* get phase list and station name */ |
---|
1080 | plist = PiPhaseListOfRoot( proot ); |
---|
1081 | if (plist == NULL) continue; |
---|
1082 | strcpy( c_station, PiStationOfRoot(proot) ); |
---|
1083 | is_ml_station = (strcmp(c_station,station) == 0); |
---|
1084 | /* loop all phases of trace */ |
---|
1085 | for (p=0; p<PiPhaseListLength(plist); p++) { |
---|
1086 | phase = PiGetPhase( plist, p, status ); |
---|
1087 | if (Severe(status)) return; |
---|
1088 | if (phase->magn_source == cPiMagnMl) { |
---|
1089 | /* found an ml entry */ |
---|
1090 | if (is_ml_station) { |
---|
1091 | /* set magnitude flag */ |
---|
1092 | phase->flags |= fPiAttribMagn; |
---|
1093 | ml_done = TRUE; |
---|
1094 | } else { |
---|
1095 | /* clear magnitude flag */ |
---|
1096 | phase->flags &= ~fPiAttribMagn; |
---|
1097 | } /*endif*/ |
---|
1098 | } /*endif*/ |
---|
1099 | } /*endfor*/ |
---|
1100 | } /*endfor*/ |
---|
1101 | |
---|
1102 | /* no ml entry found */ |
---|
1103 | if (!ml_done) |
---|
1104 | *status = MXE_NO_MLENTRY; |
---|
1105 | |
---|
1106 | } /* end of mx_trclist_refml */ |
---|
1107 | |
---|
1108 | |
---|
1109 | |
---|
1110 | /*----------------------------------------------------------------------------*/ |
---|
1111 | |
---|
1112 | |
---|
1113 | |
---|
1114 | void mx_analyst_name( Widget w[], MGT_DSPCTRL *ctrl, STATUS *status ) |
---|
1115 | |
---|
1116 | /* Reads analyst's initials from dialog box checks it and closes dialog |
---|
1117 | * box if everything is ok. |
---|
1118 | * |
---|
1119 | * parameters of routine |
---|
1120 | * Widget w[]; input; widget array |
---|
1121 | * TSyStatus *status; output; return status |
---|
1122 | */ |
---|
1123 | { |
---|
1124 | /* local variables */ |
---|
1125 | char *initials; /* pointer to initials */ |
---|
1126 | char analyst[BC_SHORTSTRLTH+1]; /* copy of initials */ |
---|
1127 | TSyBoolean found; /* name found */ |
---|
1128 | TGpTextList txtlst; /* text list with analysts initals */ |
---|
1129 | int i; /* counter */ |
---|
1130 | |
---|
1131 | /* executable code */ |
---|
1132 | |
---|
1133 | initials = cu_get_string( w[k_widget_analyst_name_text] ); |
---|
1134 | if (initials == NULL) {*status = MXE_ILL_ANALYST; return;} |
---|
1135 | if (*initials == '\0') {*status = MXE_ILL_ANALYST; return;} |
---|
1136 | if (strlen(initials) > 4) {*status = MXE_ILL_ANALYST; return;} |
---|
1137 | strcpy( analyst, initials ); |
---|
1138 | /*ut_cap( analyst );*/ |
---|
1139 | |
---|
1140 | /* get list of analysts from setup file */ |
---|
1141 | GpParseTextList( GpGetString(cGpS_list_of_analysts), &txtlst ); |
---|
1142 | |
---|
1143 | found = FALSE; |
---|
1144 | for (i=0; i<txtlst.numelem; i++) { |
---|
1145 | found = (strcmp(txtlst.elem[i],analyst) == 0); |
---|
1146 | if (found) break; |
---|
1147 | } /*endwhile*/ |
---|
1148 | |
---|
1149 | GpFreeTextList( &txtlst ); |
---|
1150 | |
---|
1151 | if (found) { |
---|
1152 | XtUnmanageChild( w[k_widget_analyst_box] ); |
---|
1153 | GpSetString( cGpS_analyst, analyst, NULL ); |
---|
1154 | } else { |
---|
1155 | *status = MXE_ILL_ANALYST; |
---|
1156 | } /*endif*/ |
---|
1157 | |
---|
1158 | } /* end of mx_analyst_name */ |
---|
1159 | |
---|
1160 | |
---|
1161 | |
---|
1162 | /*--------------------------------------------------------------------------*/ |
---|
1163 | |
---|
1164 | |
---|
1165 | |
---|
1166 | void mx_filter_box_defaults( Widget w[], MX_CMD_FILTER *fil ) |
---|
1167 | |
---|
1168 | /* resets filter box |
---|
1169 | * |
---|
1170 | * parameters of routine |
---|
1171 | * Widget w[]; input; widget array |
---|
1172 | * MX_CMD_FILTER *fil; input; filter parameters |
---|
1173 | */ |
---|
1174 | { |
---|
1175 | /* local variables */ |
---|
1176 | Arg al[1]; /* argument list */ |
---|
1177 | int cut_w_no; /* widget number of cutoff time */ |
---|
1178 | int i; /* counter */ |
---|
1179 | |
---|
1180 | /* executable code */ |
---|
1181 | |
---|
1182 | if (fil->autocut >= 600.0) cut_w_no = k_widget_filter_autocut_10min; |
---|
1183 | else if (fil->autocut >= 300.0) cut_w_no = k_widget_filter_autocut_5min; |
---|
1184 | else if (fil->autocut >= 180.0) cut_w_no = k_widget_filter_autocut_3min; |
---|
1185 | else if (fil->autocut >= 60.0) cut_w_no = k_widget_filter_autocut_1min; |
---|
1186 | else if (fil->autocut >= 20.0) cut_w_no = k_widget_filter_autocut_20sec; |
---|
1187 | else if (fil->autocut >= 5.0) cut_w_no = k_widget_filter_autocut_5sec; |
---|
1188 | else cut_w_no = k_widget_filter_autocut_0; |
---|
1189 | XtSetArg( al[0], XmNmenuHistory, w[cut_w_no] ); |
---|
1190 | XtSetValues( w[k_widget_filter_autocut_option], al, 1 ); |
---|
1191 | |
---|
1192 | for (i=k_widget_filter_none; i<=k_widget_filter_sro_lp; i++) |
---|
1193 | if (i != k_widget_filter_lrsm_lp) |
---|
1194 | XmToggleButtonSetState( w[i], FALSE, FALSE ); |
---|
1195 | if (strcmp(fil->name,"GRF_STANDARD_BP") == 0) |
---|
1196 | XmToggleButtonSetState( w[k_widget_filter_standard_bp], TRUE, FALSE ); |
---|
1197 | else if (strcmp(fil->name,"WWSSN_SP") == 0) |
---|
1198 | XmToggleButtonSetState( w[k_widget_filter_wwssn_sp], TRUE, FALSE ); |
---|
1199 | else if (strcmp(fil->name,"WWSSN_LP") == 0) |
---|
1200 | XmToggleButtonSetState( w[k_widget_filter_wwssn_lp], TRUE, FALSE ); |
---|
1201 | else if (strcmp(fil->name,"LRSM_SP") == 0) |
---|
1202 | XmToggleButtonSetState( w[k_widget_filter_lrsm_sp], TRUE, FALSE ); |
---|
1203 | else if (strcmp(fil->name,"LRSM_LP") == 0) |
---|
1204 | XmToggleButtonSetState( w[k_widget_filter_lrsm_lp], TRUE, FALSE ); |
---|
1205 | else if (strcmp(fil->name,"KIRNOS") == 0) |
---|
1206 | XmToggleButtonSetState( w[k_widget_filter_kirnos], TRUE, FALSE ); |
---|
1207 | else if (strcmp(fil->name,"WOODAND") == 0) |
---|
1208 | XmToggleButtonSetState( w[k_widget_filter_woodand], TRUE, FALSE ); |
---|
1209 | else if (strcmp(fil->name,"SRO_LP") == 0) |
---|
1210 | XmToggleButtonSetState( w[k_widget_filter_sro_lp], TRUE, FALSE ); |
---|
1211 | |
---|
1212 | cu_set_string( w[k_widget_filter_edit_text], fil->name ); |
---|
1213 | |
---|
1214 | } /* end of mx_filter_box_defaults */ |
---|
1215 | |
---|
1216 | |
---|
1217 | |
---|
1218 | /*----------------------------------------------------------------------------*/ |
---|
1219 | |
---|
1220 | |
---|
1221 | |
---|
1222 | void mx_sh_external_routine( char cmd[], STATUS *status ) |
---|
1223 | |
---|
1224 | /* external routine for SH |
---|
1225 | * |
---|
1226 | * parameters of routine |
---|
1227 | * char cmd[]; input; switch to subcommands |
---|
1228 | * TSyStatus *status; output; return status |
---|
1229 | */ |
---|
1230 | { |
---|
1231 | /* local variables */ |
---|
1232 | |
---|
1233 | /* executable code */ |
---|
1234 | |
---|
1235 | if (strcmp(cmd,"PREPARE_DISPLAY") == 0) { |
---|
1236 | mx_prepare_display(); |
---|
1237 | } else if (strcmp(cmd,"SAVE_DSP_PHASES") == 0) { |
---|
1238 | /*cl3_save_phase_display( status );*/ |
---|
1239 | if (GpGetInt(cGpI_debug_level) > 2) |
---|
1240 | printf( "SHM-dbg3: external_routine: SAVE_DSP_PHASES disabled\n" ); |
---|
1241 | } else if (strcmp(cmd,"RESTORE_DSP_PHASES") == 0) { |
---|
1242 | if (GpGetInt(cGpI_debug_level) > 2) |
---|
1243 | printf( "SHM-dbg3: external_routine: RESTORE_DSP_PHASES disabled\n" ); |
---|
1244 | } else if (strcmp(cmd,"RESET_DISPLAY_FLAGS") == 0) { |
---|
1245 | mxv_display_state = 0; |
---|
1246 | } else if (strcmp(cmd,"PHASE_CHECK") == 0) { |
---|
1247 | PiPhaseDump(); |
---|
1248 | } else if (strncmp(cmd,"BTN_READS",9) == 0) { |
---|
1249 | if (GpGetInt(cGpI_debug_level) > 2) |
---|
1250 | printf( "SHM-dbg3: external_routine: btn_reads ignored\n" ); |
---|
1251 | } else if (strncmp(cmd,"READ_DIALOG:",12) == 0) { |
---|
1252 | mxh_read_statlist( cmd+12, xmv_w, &xmv_cmd_readg.sl, status ); |
---|
1253 | } else if (strncmp(cmd,"LOC_EXTERNAL:",13) == 0) { |
---|
1254 | mxh_set_entry_name( xmv_w[k_widget_param_hypoloc], cmd+13 ); |
---|
1255 | } else if (strncmp(cmd,"TABLE_ML_SIGMA:",15) == 0) { |
---|
1256 | si_read_table( cmd+15, "ml-sigma", status ); |
---|
1257 | } else if (strcmp(cmd,"DUMP_GLOBALS") == 0) { |
---|
1258 | GpDumpParams(); |
---|
1259 | } else if (strncmp(cmd,"MINMAXFMT:",10) == 0) { |
---|
1260 | /* disabled */ |
---|
1261 | if (GpGetInt(cGpI_debug_level) > 0) |
---|
1262 | printf( "SHM-dbg1: function minmaxfmt obsolete\n" ); |
---|
1263 | } else { |
---|
1264 | *status = MXE_ILL_EXTROUT; |
---|
1265 | return; |
---|
1266 | } /*endif*/ |
---|
1267 | |
---|
1268 | } /* end of mx_sh_external_routine */ |
---|
1269 | |
---|
1270 | |
---|
1271 | |
---|
1272 | /*----------------------------------------------------------------------------*/ |
---|
1273 | |
---|
1274 | |
---|
1275 | |
---|
1276 | static void mx_prepare_display( void ) |
---|
1277 | |
---|
1278 | /* selects traces to be displayed on next redraw (sets EF_VIEW flag). |
---|
1279 | * |
---|
1280 | */ |
---|
1281 | { |
---|
1282 | /* local variables */ |
---|
1283 | int t; /* trace counter */ |
---|
1284 | TPmTrace *trc; /* pointer to trace info */ |
---|
1285 | TSyStatus locstat; /* local status */ |
---|
1286 | TSyBoolean dsp; /* do display trace */ |
---|
1287 | TSyBoolean dsp_filtered; /* display filtered traces */ |
---|
1288 | TSyBoolean dsp_rotated; /* display rotated traces */ |
---|
1289 | |
---|
1290 | /* executable code */ |
---|
1291 | |
---|
1292 | dsp_filtered = (MXC_FLAG_FILTER & mxv_display_state); |
---|
1293 | dsp_rotated = (MXC_FLAG_ROT & mxv_display_state); |
---|
1294 | |
---|
1295 | /* loop over all traces in memory */ |
---|
1296 | trc = NULL; |
---|
1297 | for (t=0; t<db_lstlth(); t++) { |
---|
1298 | /* get next trace pointer */ |
---|
1299 | locstat = BC_NOERROR; |
---|
1300 | trc = db_getp( trc, EP_NEXT, &locstat ); |
---|
1301 | if (Severe(&locstat)) {printf("*SHM: mx-error(1) ***\n"); continue;} |
---|
1302 | dsp = ( |
---|
1303 | !db_getf(trc,MXC_EF_HIDE,&locstat) |
---|
1304 | && db_getf(trc,MXC_EF_FILTER,&locstat) == dsp_filtered |
---|
1305 | && db_getf(trc,MXC_EF_ROT,&locstat) == dsp_rotated |
---|
1306 | ); |
---|
1307 | db_setf( trc, MXC_EF_VIEW, dsp, &locstat ); |
---|
1308 | if (Severe(&locstat)) {printf("*SHM: mx-error(2) ***\n"); continue;} |
---|
1309 | } /*endfor*/ |
---|
1310 | |
---|
1311 | } /* end of mx_prepare_display */ |
---|
1312 | |
---|
1313 | |
---|
1314 | |
---|
1315 | /*----------------------------------------------------------------------------*/ |
---|
1316 | |
---|
1317 | |
---|
1318 | |
---|
1319 | void mx_clear_rotation( void ) |
---|
1320 | |
---|
1321 | /* resets rotation state |
---|
1322 | * |
---|
1323 | * no parameters |
---|
1324 | */ |
---|
1325 | { |
---|
1326 | /* executable code */ |
---|
1327 | |
---|
1328 | mxv_display_state &= ~MXC_FLAG_ROT; |
---|
1329 | |
---|
1330 | } /* end of mx_clear_rotation */ |
---|
1331 | |
---|
1332 | |
---|
1333 | |
---|
1334 | /*----------------------------------------------------------------------------*/ |
---|
1335 | |
---|
1336 | |
---|
1337 | |
---|
1338 | void mx_get_chanlist( Widget w[], MX_CMD_READG *rg ) |
---|
1339 | |
---|
1340 | |
---|
1341 | /* reads list of channels from dialog box into channel array |
---|
1342 | * |
---|
1343 | * parameters of routine |
---|
1344 | * Widget w[]; input; widget array |
---|
1345 | * MX_CMD_READG *rg; output; channel array (chanstr) |
---|
1346 | */ |
---|
1347 | { |
---|
1348 | /* local variables */ |
---|
1349 | int i; /* channel counter */ |
---|
1350 | int cwno[MXC_MAXCHAN]; /* channel widget numbers */ |
---|
1351 | char *str; /* pointer to string */ |
---|
1352 | |
---|
1353 | /* executable code */ |
---|
1354 | |
---|
1355 | cwno[0] = k_widget_read_grsn_1hz; |
---|
1356 | cwno[1] = k_widget_read_grsn_20hz; |
---|
1357 | cwno[2] = k_widget_read_grsn_80hz; |
---|
1358 | cwno[3] = k_widget_read_grsn_edit_hz; |
---|
1359 | |
---|
1360 | /* reset channel counter */ |
---|
1361 | rg->channum = 0; |
---|
1362 | |
---|
1363 | for (i=0; i<MXC_MAXCHAN; i++) { |
---|
1364 | if (XmToggleButtonGetState(w[cwno[i]])) { |
---|
1365 | strcpy( rg->chanstr[rg->channum], rg->sl.channel[i] ); |
---|
1366 | if (strcmp(rg->chanstr[rg->channum],"ed") == 0) { |
---|
1367 | str = cu_get_string( w[k_widget_read_grsn_hz_text] ); |
---|
1368 | if (strlen(str) <= MXC_CHANLTH && strlen(str) > 0) { |
---|
1369 | strcpy( rg->chanstr[rg->channum], str ); |
---|
1370 | } else { |
---|
1371 | printf( "*SHM: illegal channel string %s\n", str ); |
---|
1372 | } /*endif*/ |
---|
1373 | } /*endif*/ |
---|
1374 | (rg->channum)++; |
---|
1375 | } /*endif*/ |
---|
1376 | } /*endfor*/ |
---|
1377 | |
---|
1378 | #ifdef XXX |
---|
1379 | /* check buttons */ |
---|
1380 | if (XmToggleButtonGetState(w[k_widget_read_grsn_1hz])) { |
---|
1381 | strcpy( rg->chanstr[rg->channum], "LH" ); |
---|
1382 | (rg->channum)++; |
---|
1383 | } /*endif*/ |
---|
1384 | if (XmToggleButtonGetState(w[k_widget_read_grsn_20hz])) { |
---|
1385 | strcpy( rg->chanstr[rg->channum], "BH" ); |
---|
1386 | (rg->channum)++; |
---|
1387 | } /*endif*/ |
---|
1388 | if (XmToggleButtonGetState(w[k_widget_read_grsn_80hz])) { |
---|
1389 | strcpy( rg->chanstr[rg->channum], "HH" ); |
---|
1390 | (rg->channum)++; |
---|
1391 | } /*endif*/ |
---|
1392 | if (XmToggleButtonGetState(w[k_widget_read_grsn_edit_hz])) { |
---|
1393 | str = cu_get_string( w[k_widget_read_grsn_hz_text] ); |
---|
1394 | if (strlen(str) <= MXC_CHANLTH && strlen(str) > 0) { |
---|
1395 | strcpy( rg->chanstr[rg->channum], str ); |
---|
1396 | } else { |
---|
1397 | printf( "*SHM: illegal channel string %s\n", str ); |
---|
1398 | } /*endif*/ |
---|
1399 | (rg->channum)++; |
---|
1400 | } /*endif*/ |
---|
1401 | #endif |
---|
1402 | |
---|
1403 | } /* end of mx_get_chanlist */ |
---|
1404 | |
---|
1405 | |
---|
1406 | |
---|
1407 | /*----------------------------------------------------------------------------*/ |
---|
1408 | |
---|
1409 | |
---|
1410 | |
---|
1411 | static void mxh_read_statlist( char fname[], Widget w[], MX_STATLIST *sl, |
---|
1412 | STATUS *status ) |
---|
1413 | |
---|
1414 | /* reads in station list from file 'fname' |
---|
1415 | * |
---|
1416 | * parameters of routine |
---|
1417 | * char fname[]; input; name of input file |
---|
1418 | * Widget w[]; input; widget array (widgets will be modified) |
---|
1419 | * MX_STATLIST *sl; output; station list for dialog box |
---|
1420 | * TSyStatus *status; output; return status |
---|
1421 | */ |
---|
1422 | { |
---|
1423 | /* local variables */ |
---|
1424 | FILE *fp; /* pointer to input file */ |
---|
1425 | char line[BC_LINELTH+1]; /* current line */ |
---|
1426 | int s; /* station counter */ |
---|
1427 | int c; /* channel counter */ |
---|
1428 | int cwno[MXC_MAXCHAN]; /* channel widget numbers */ |
---|
1429 | int slen; /* string length */ |
---|
1430 | char *ch; /* char pointer */ |
---|
1431 | Arg args[2]; /* argument list */ |
---|
1432 | int n; /* argument counter */ |
---|
1433 | XmString xmstr; /* Xm string */ |
---|
1434 | |
---|
1435 | /* executable code */ |
---|
1436 | |
---|
1437 | fp = sy_fopen( fname, "r" ); |
---|
1438 | if (fp == NULL) { |
---|
1439 | *status = MXE_OPENREAD; |
---|
1440 | err_setcontext( " ## file " ); err_setcontext( fname ); |
---|
1441 | return; |
---|
1442 | } /*endif*/ |
---|
1443 | |
---|
1444 | /* initialize output record */ |
---|
1445 | for (s=0; s<MXC_STATLIST_LTH; s++) strcpy( sl->code[s], "---" ); |
---|
1446 | strcpy( sl->set1code, "---" ); |
---|
1447 | strcpy( sl->set2code, "---" ); |
---|
1448 | sl->set1start = sl->set1end = sl->set2start = sl->set2end = 0; |
---|
1449 | strcpy( sl->channel[0], "LH" ); |
---|
1450 | strcpy( sl->channel[1], "BH" ); |
---|
1451 | strcpy( sl->channel[2], "HH" ); |
---|
1452 | strcpy( sl->channel[3], "ed" ); |
---|
1453 | |
---|
1454 | s = c = 0; |
---|
1455 | while (fgets(line,BC_LINELTH,fp) != NULL) { |
---|
1456 | if (*line == '!' || *line == '\n') continue; |
---|
1457 | slen = strlen( line ) - 1; |
---|
1458 | if (line[slen] == '\n') line[slen] = '\0'; |
---|
1459 | if (strncmp(line,"set1:",5) == 0) { |
---|
1460 | if (sscanf(line+5,"%d %d %s", |
---|
1461 | &(sl->set1start),&(sl->set1end),sl->set1code) != 3) |
---|
1462 | fprintf( stderr, |
---|
1463 | "*SHM: mx_read_statlist: error reading subset 1\n" ); |
---|
1464 | } else if (strncmp(line,"set2:",5) == 0) { |
---|
1465 | if (sscanf(line+5,"%d %d %s", |
---|
1466 | &(sl->set2start),&(sl->set2end),sl->set2code) != 3) |
---|
1467 | fprintf( stderr, |
---|
1468 | "*SHM: mx_read_statlist: error reading subset 2\n" ); |
---|
1469 | } else if (*line == '*') { |
---|
1470 | if (s == MXC_STATLIST_LTH) { |
---|
1471 | fprintf( stderr, "*SHM: mx_read_statlist: too many stations\n" ); |
---|
1472 | } else { |
---|
1473 | ch = line + 1; |
---|
1474 | while (*ch == ' ' && *ch != '\0') ch++; |
---|
1475 | if (strlen(ch) > MXC_STATSTR_LTH) { |
---|
1476 | fprintf( stderr, |
---|
1477 | "*SHM: mx_read_statlist: station name %s too long\n", ch ); |
---|
1478 | } else { |
---|
1479 | strcpy( sl->code[s++], ch ); |
---|
1480 | } /*endif*/ |
---|
1481 | } /*endif*/ |
---|
1482 | } else if (*line == 'c') { |
---|
1483 | if (c < MXC_MAXCHAN) { |
---|
1484 | sl->channel[c][0] = line[2]; |
---|
1485 | sl->channel[c][1] = line[3]; |
---|
1486 | sl->channel[c][2] = '\0'; |
---|
1487 | c++; |
---|
1488 | } else { |
---|
1489 | fprintf( stderr, "*SHM: mx_read_statlist: too many channels\n" ); |
---|
1490 | } /*endif*/ |
---|
1491 | } else { |
---|
1492 | fprintf( stderr, "*SHM: mx_read_statlist: illegal line:\n%s", line ); |
---|
1493 | } /*endif*/ |
---|
1494 | } /*endwhile*/ |
---|
1495 | |
---|
1496 | sy_fclose( fp ); |
---|
1497 | |
---|
1498 | /* set dialog box */ |
---|
1499 | for (s=0; s<MXC_STATLIST_LTH; s++) { |
---|
1500 | xmstr = XmStringCreateLtoR( sl->code[s], "" ); |
---|
1501 | n = 0; |
---|
1502 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1503 | XtSetValues( w[k_widget_read_grsn_station+s], args, n ); |
---|
1504 | XtSetSensitive( w[k_widget_read_grsn_station+s], (sl->code[s][0] != '-')); |
---|
1505 | } /*endfor*/ |
---|
1506 | |
---|
1507 | xmstr = XmStringCreateLtoR( sl->set1code, "" ); |
---|
1508 | n = 0; |
---|
1509 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1510 | XtSetValues( w[k_widget_read_grsn_grf], args, n ); |
---|
1511 | XtSetSensitive( w[k_widget_read_grsn_grf], (sl->set1code[0] != '-') ); |
---|
1512 | xmstr = XmStringCreateLtoR( sl->set2code, "" ); |
---|
1513 | n = 0; |
---|
1514 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1515 | XtSetValues( w[k_widget_read_grsn_grsn], args, n ); |
---|
1516 | XtSetSensitive( w[k_widget_read_grsn_grsn], (sl->set2code[0] != '-') ); |
---|
1517 | |
---|
1518 | cwno[0] = k_widget_read_grsn_1hz; |
---|
1519 | cwno[1] = k_widget_read_grsn_20hz; |
---|
1520 | cwno[2] = k_widget_read_grsn_80hz; |
---|
1521 | cwno[3] = k_widget_read_grsn_edit_hz; |
---|
1522 | for (c=0; c<MXC_MAXCHAN; c++) { |
---|
1523 | xmstr = XmStringCreateLtoR( sl->channel[c], "" ); |
---|
1524 | n = 0; |
---|
1525 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1526 | XtSetValues( w[cwno[c]], args, n ); |
---|
1527 | XtSetSensitive( w[cwno[c]], (sl->channel[c][0] != '-')); |
---|
1528 | } /*endfor*/ |
---|
1529 | |
---|
1530 | } /* end of mxh_read_statlist */ |
---|
1531 | |
---|
1532 | |
---|
1533 | |
---|
1534 | /*----------------------------------------------------------------------------*/ |
---|
1535 | |
---|
1536 | |
---|
1537 | |
---|
1538 | void mx_name_read_buttons( Widget w[], int dialbox_num, TSyStatus *status ) |
---|
1539 | |
---|
1540 | /* reads in station list from parameter file. Original from mxh_read_statlist. |
---|
1541 | * |
---|
1542 | * parameters of routine |
---|
1543 | * Widget w[]; input; widget array (widgets will be modified) |
---|
1544 | * int dialbox_num; input; number of dialog box to be modified |
---|
1545 | * MX_STATLIST *sl; output; station list for dialog box |
---|
1546 | * TSyStatus *status; output; return status |
---|
1547 | */ |
---|
1548 | { |
---|
1549 | /* local variables */ |
---|
1550 | char parname[cBcLineLth+1]; /* name of parameter (dialog box number) */ |
---|
1551 | char parval[cBcLongStrLth+1]; /* list of stations */ |
---|
1552 | int ok; /* parameter ok? */ |
---|
1553 | TGpTextList slist; /* parsed station list */ |
---|
1554 | int s; /* station counter */ |
---|
1555 | int setcnt; /* set counter */ |
---|
1556 | int c; /* channel counter */ |
---|
1557 | int cwno[MXC_MAXCHAN]; /* channel widget numbers */ |
---|
1558 | Arg args[2]; /* argument list */ |
---|
1559 | int n; /* argument counter */ |
---|
1560 | XmString xmstr; /* Xm string */ |
---|
1561 | MX_STATLIST *sl; /* station list for dialog box */ |
---|
1562 | int slen; /* string length */ |
---|
1563 | |
---|
1564 | /* executable code */ |
---|
1565 | |
---|
1566 | sl = &(xmv_cmd_readg.sl); |
---|
1567 | |
---|
1568 | /* get station parameter from parameter file */ |
---|
1569 | sprintf( parname, "v$read_dialog_stations_%02d", dialbox_num ); |
---|
1570 | GpReadParameter( parname, cBcLongStrLth, parval, &ok ); |
---|
1571 | if (!ok) {*status = MXE_NOT_FOUND;return;} |
---|
1572 | GpParseTextList( parval, &slist ); |
---|
1573 | |
---|
1574 | /* initialize output record */ |
---|
1575 | for (s=0; s<MXC_STATLIST_LTH; s++) strcpy( sl->code[s], "---" ); |
---|
1576 | strcpy( sl->set1code, "---" ); |
---|
1577 | strcpy( sl->set2code, "---" ); |
---|
1578 | sl->set1start = sl->set1end = sl->set2start = sl->set2end = 0; |
---|
1579 | strcpy( sl->channel[0], "LH" ); |
---|
1580 | strcpy( sl->channel[1], "BH" ); |
---|
1581 | strcpy( sl->channel[2], "HH" ); |
---|
1582 | strcpy( sl->channel[3], "ed" ); |
---|
1583 | |
---|
1584 | setcnt = 0; |
---|
1585 | for (s=0; s<slist.numelem; s++) { |
---|
1586 | slen = strlen( slist.elem[s] ); |
---|
1587 | if (slen > MXC_STATSTR_LTH) { |
---|
1588 | fprintf( stderr, |
---|
1589 | "*SHM: mx_name_read_buttons: station name %s too long\n", |
---|
1590 | slist.elem[s] ); |
---|
1591 | continue; |
---|
1592 | } /*endif*/ |
---|
1593 | if (s == MXC_STATLIST_LTH) { |
---|
1594 | strcpy( sl->set1code, slist.elem[s] ); |
---|
1595 | } else if (s == MXC_STATLIST_LTH+1) { |
---|
1596 | strcpy( sl->set2code, slist.elem[s] ); |
---|
1597 | } else if (s < MXC_STATLIST_LTH) { |
---|
1598 | if (slist.elem[s][0] == '[') { |
---|
1599 | setcnt++; |
---|
1600 | if (setcnt == 1) { |
---|
1601 | sl->set1start = s; |
---|
1602 | } else if (setcnt == 2) { |
---|
1603 | sl->set2start = s; |
---|
1604 | } /*endif*/ |
---|
1605 | strcpy( sl->code[s], slist.elem[s]+1 ); |
---|
1606 | } else if (slist.elem[s][slen-1] == ']') { |
---|
1607 | if (setcnt == 1) { |
---|
1608 | sl->set1end = s; |
---|
1609 | } else if (setcnt == 2) { |
---|
1610 | sl->set2end = s; |
---|
1611 | } /*endif*/ |
---|
1612 | strcpy( sl->code[s], slist.elem[s] ); |
---|
1613 | sl->code[s][slen-1] = '\0'; |
---|
1614 | } else { |
---|
1615 | strcpy( sl->code[s], slist.elem[s] ); |
---|
1616 | } /*endif*/ |
---|
1617 | } /*endif*/ |
---|
1618 | } /*endfor*/ |
---|
1619 | if (setcnt > 0 && sl->set1code[0] == '-') strcpy( sl->set1code, "SET1" ); |
---|
1620 | if (setcnt > 1 && sl->set2code[0] == '-') strcpy( sl->set2code, "SET2" ); |
---|
1621 | |
---|
1622 | GpFreeTextList( &slist ); |
---|
1623 | |
---|
1624 | /* get channel parameter from parameter file */ |
---|
1625 | sprintf( parname, "v$read_dialog_channels_%02d", dialbox_num ); |
---|
1626 | GpReadParameter( parname, cBcLongStrLth, parval, &ok ); |
---|
1627 | if (ok) { |
---|
1628 | GpParseTextList( parval, &slist ); |
---|
1629 | c = 0; |
---|
1630 | for (s=0; s<slist.numelem; s++) |
---|
1631 | if (s < MXC_MAXCHAN && strlen(slist.elem[s]) <= MXC_CHANLTH) |
---|
1632 | strcpy( sl->channel[c++], slist.elem[s] ); |
---|
1633 | GpFreeTextList( &slist ); |
---|
1634 | } /*endif*/ |
---|
1635 | |
---|
1636 | /* set dialog box */ |
---|
1637 | for (s=0; s<MXC_STATLIST_LTH; s++) { |
---|
1638 | xmstr = XmStringCreateLtoR( sl->code[s], "" ); |
---|
1639 | n = 0; |
---|
1640 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1641 | XtSetValues( w[k_widget_read_grsn_station+s], args, n ); |
---|
1642 | XtSetSensitive( w[k_widget_read_grsn_station+s], (sl->code[s][0] != '-')); |
---|
1643 | XmToggleButtonSetState( w[k_widget_read_grsn_station+s], FALSE, TRUE ); |
---|
1644 | } /*endfor*/ |
---|
1645 | |
---|
1646 | xmstr = XmStringCreateLtoR( sl->set1code, "" ); |
---|
1647 | n = 0; |
---|
1648 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1649 | XtSetValues( w[k_widget_read_grsn_grf], args, n ); |
---|
1650 | XtSetSensitive( w[k_widget_read_grsn_grf], (sl->set1code[0] != '-') ); |
---|
1651 | xmstr = XmStringCreateLtoR( sl->set2code, "" ); |
---|
1652 | n = 0; |
---|
1653 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1654 | XtSetValues( w[k_widget_read_grsn_grsn], args, n ); |
---|
1655 | XtSetSensitive( w[k_widget_read_grsn_grsn], (sl->set2code[0] != '-') ); |
---|
1656 | |
---|
1657 | cwno[0] = k_widget_read_grsn_1hz; |
---|
1658 | cwno[1] = k_widget_read_grsn_20hz; |
---|
1659 | cwno[2] = k_widget_read_grsn_80hz; |
---|
1660 | cwno[3] = k_widget_read_grsn_edit_hz; |
---|
1661 | for (c=0; c<MXC_MAXCHAN; c++) { |
---|
1662 | xmstr = XmStringCreateLtoR( sl->channel[c], "" ); |
---|
1663 | n = 0; |
---|
1664 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
1665 | XtSetValues( w[cwno[c]], args, n ); |
---|
1666 | XtSetSensitive( w[cwno[c]], (sl->channel[c][0] != '-')); |
---|
1667 | } /*endfor*/ |
---|
1668 | |
---|
1669 | } /* end of mx_name_read_buttons */ |
---|
1670 | |
---|
1671 | |
---|
1672 | |
---|
1673 | /*----------------------------------------------------------------------------*/ |
---|
1674 | |
---|
1675 | |
---|
1676 | |
---|
1677 | static void mxh_read_file_list( Widget w, MGT_DSPCTRL *ctrl, char filenames[], |
---|
1678 | int format, STATUS *status ) |
---|
1679 | |
---|
1680 | /* reads in all GSE files matching the wildcard string "filenames" |
---|
1681 | * |
---|
1682 | * parameters of routine |
---|
1683 | * Widget w; input; widget ID of drawing area |
---|
1684 | * MGT_DSPCTRL *ctrl; input; display control params |
---|
1685 | * char filenames[]; input; wild card string for filenames |
---|
1686 | * int format; input; format code |
---|
1687 | * TSyStatus *status; output; return status |
---|
1688 | */ |
---|
1689 | { |
---|
1690 | /* local variables */ |
---|
1691 | char currfile[BC_FILELTH+1]; /* current file */ |
---|
1692 | char altfile[cBcFileLth+1]; /* another filename */ |
---|
1693 | int filecnt; /* file counter */ |
---|
1694 | char cmd[BC_LINELTH+1]; /* comand line */ |
---|
1695 | char *cp; /* moving pointer */ |
---|
1696 | TSyBoolean redraw; /* dummy */ |
---|
1697 | int i; /* counter */ |
---|
1698 | |
---|
1699 | /* executable code */ |
---|
1700 | |
---|
1701 | mx_exec_sh( w, ctrl, "nr" ); |
---|
1702 | filecnt = 0; |
---|
1703 | FOREVER { |
---|
1704 | |
---|
1705 | /* try to find next matching file */ |
---|
1706 | sy_findfile( SYC_FF_NAME|SYC_FF_DIR|SYC_FF_EXT, filenames, currfile ); |
---|
1707 | if (*currfile == '\0') { |
---|
1708 | if (filecnt == 0) { |
---|
1709 | *status = MXE_NO_GSE_MATCH; |
---|
1710 | break; |
---|
1711 | } /*endif*/ |
---|
1712 | break; |
---|
1713 | } /*endif*/ |
---|
1714 | |
---|
1715 | /* put backslashes instead if slashes because of SH command line */ |
---|
1716 | cp = currfile - 1; |
---|
1717 | while (*(++cp) != '\0') |
---|
1718 | if (*cp == '/') |
---|
1719 | *cp = '\\'; |
---|
1720 | |
---|
1721 | /* process file currfile */ |
---|
1722 | if (strlen(currfile)+12 > BC_LINELTH) { |
---|
1723 | *status = MXE_STROVFL; |
---|
1724 | break; |
---|
1725 | } /*endif*/ |
---|
1726 | switch (format) { |
---|
1727 | case MXC_FORMAT_GSE: sprintf( cmd, "@READGSE_MERGE %s ALL", currfile ); break; |
---|
1728 | case MXC_FORMAT_GSE2: sprintf( cmd, "@READGSE_MERGE %s ALL", currfile ); break; |
---|
1729 | case MXC_FORMAT_AH: sprintf( cmd, "@READAH %s ALL", currfile ); break; |
---|
1730 | case MXC_FORMAT_Q: |
---|
1731 | strcpy( altfile, currfile ); |
---|
1732 | i = strlen( altfile ) - 4; |
---|
1733 | if (i > 1 && strcmp(altfile+i,".QBN") == 0) { |
---|
1734 | altfile[i] = '\0'; |
---|
1735 | sprintf( cmd, "@READ %s ALL", altfile ); |
---|
1736 | } else { |
---|
1737 | sprintf( cmd, "! @READ %s ALL", altfile ); |
---|
1738 | } /*endif*/ |
---|
1739 | break; |
---|
1740 | default: |
---|
1741 | printf( "*SHM: mxh_read_file_list: this should not happen\n" ); |
---|
1742 | break; |
---|
1743 | } /*endswitch*/ |
---|
1744 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
1745 | printf( "SHM-dbg2: executing command: %s\n", cmd ); |
---|
1746 | callsh( cmd, &redraw, status ); |
---|
1747 | if (Severe(status)) { |
---|
1748 | /* should print out error in a more elaborate way */ |
---|
1749 | printf( "*SHM: readgse error %d\n", *status ); |
---|
1750 | *status = BC_NOERROR; |
---|
1751 | } /*endif*/ |
---|
1752 | /* mx_exec_sh( w, ctrl, cmd ); */ |
---|
1753 | |
---|
1754 | /* increment file counter */ |
---|
1755 | filecnt++; |
---|
1756 | |
---|
1757 | } /*endfor*/ |
---|
1758 | mx_exec_sh( w, ctrl, "rd" ); |
---|
1759 | |
---|
1760 | } /* end of mxh_read_file_list */ |
---|
1761 | |
---|
1762 | |
---|
1763 | |
---|
1764 | /*----------------------------------------------------------------------------*/ |
---|
1765 | |
---|
1766 | |
---|
1767 | #define MAX_S_LTH 8 |
---|
1768 | |
---|
1769 | |
---|
1770 | static void mxh_filter_separately( Widget w, MGT_DSPCTRL *ctrl, char filter[], |
---|
1771 | float autocut, STATUS *status ) |
---|
1772 | |
---|
1773 | /* Filters traces on display separately. |
---|
1774 | * |
---|
1775 | * parameters of routine |
---|
1776 | * Widget w; input; widget ID of drawing window |
---|
1777 | * MGT_DSPCTRL *ctrl; input; display control |
---|
1778 | * char filter[]; input; name of filter (without prefix) |
---|
1779 | * float autocut; input; autocut of traces in sec |
---|
1780 | * TSyStatus *status; output; return status |
---|
1781 | */ |
---|
1782 | { |
---|
1783 | /* local variables */ |
---|
1784 | void *trc; /* trace pointer */ |
---|
1785 | int trcnum; /* trace number on display */ |
---|
1786 | char complete_name[BC_FILELTH+1]; /* complete filter name */ |
---|
1787 | char tfname[BC_FILELTH+1]; /* transfer function name */ |
---|
1788 | char last_name[BC_FILELTH+1]; /* last filter */ |
---|
1789 | BOOLEAN simulation; /* is simulation filter */ |
---|
1790 | char station[BC_SHORTSTRLTH+1]; /* station name */ |
---|
1791 | char cmd[BC_LINELTH+1]; /* SH command */ |
---|
1792 | char filter_typ, filter_typ_save; /* filter type */ |
---|
1793 | void *newtrc; /* pointer to new trace */ |
---|
1794 | void *tmp; /* scratch pointer */ |
---|
1795 | void *lasttrc; /* last trace at beginning */ |
---|
1796 | TIME ttime; /* start time of trace */ |
---|
1797 | char strtime[cBcTimeLth+1]; /* converted start time */ |
---|
1798 | int trcflags; /* trace flags for filtered traces */ |
---|
1799 | TSyStatus locstat; /* local status */ |
---|
1800 | BOOLEAN dmy; /* dummy */ |
---|
1801 | unsigned filent; /* filter entry */ |
---|
1802 | char singfilt[BC_FILELTH+1]; /* single filter name */ |
---|
1803 | char filprefix[BC_FILELTH+1]; /* filter prefix on rec. filters */ |
---|
1804 | |
---|
1805 | /* executable code */ |
---|
1806 | |
---|
1807 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
1808 | printf( "SHM-dbg2: mx_filter: different filters used\n" ); |
---|
1809 | |
---|
1810 | #ifdef XXX |
---|
1811 | filter_typ = (shv_global.use_rec_filters) ? 'R' : 'F'; |
---|
1812 | if (shv_global.filter_type != ' ') filter_typ = shv_global.filter_type; |
---|
1813 | #endif |
---|
1814 | filter_typ = GpGetChar(cGpC_filter_type); |
---|
1815 | filter_typ_save = filter_typ; |
---|
1816 | simulation = (strchr(filter,'+') != NULL); |
---|
1817 | if (strlen(filter) > BC_FILELTH-2*MAX_S_LTH) { |
---|
1818 | *status = MXE_STROVFL; |
---|
1819 | return; |
---|
1820 | } /*endif*/ |
---|
1821 | |
---|
1822 | /* get index number of filter entry */ |
---|
1823 | db_ident( "FILTER", &filent, status ); |
---|
1824 | if (SySevere(status)) return; |
---|
1825 | |
---|
1826 | /* prepare traces */ |
---|
1827 | mx_exec_sh( w, ctrl, "shm_cmd_sepfil_begin" ); |
---|
1828 | |
---|
1829 | /* set newtrc to last trace in memory */ |
---|
1830 | newtrc = NULL; |
---|
1831 | FOREVER { |
---|
1832 | tmp = db_getp( newtrc, EP_NEXT, NULL ); |
---|
1833 | if (tmp == NULL) break; |
---|
1834 | newtrc = tmp; |
---|
1835 | } /*endfor*/ |
---|
1836 | if (newtrc == NULL) { |
---|
1837 | printf( "*SHM: mx_filter: no traces\n" ); |
---|
1838 | *status = MXE_PROG_BUG; |
---|
1839 | return; |
---|
1840 | } /*endif*/ |
---|
1841 | lasttrc = newtrc; |
---|
1842 | |
---|
1843 | /* loop all traces on display */ |
---|
1844 | trcnum = 0; |
---|
1845 | *last_name = '\0'; |
---|
1846 | trc = NULL; |
---|
1847 | do { |
---|
1848 | filter_typ = filter_typ_save; /* in case it has been changed by FORCE_T */ |
---|
1849 | trcnum++; |
---|
1850 | trcflags = 0; |
---|
1851 | trc = db_getp( trc, EP_NEXT, NULL ); |
---|
1852 | if (trc == NULL) { |
---|
1853 | printf( "*SHM: mx_filter: this is impossible (10)\n" ); |
---|
1854 | *status = MXE_PROG_BUG; |
---|
1855 | return; |
---|
1856 | } /*endif*/ |
---|
1857 | if (!ts_some_trace_selected() || ts_is_selected(trcnum)) { |
---|
1858 | *complete_name = '\0'; |
---|
1859 | if (filter_typ == 'R') { |
---|
1860 | cl_filter_prefix( trc, MAX_S_LTH, complete_name ); |
---|
1861 | strcpy( filprefix, complete_name ); |
---|
1862 | } /*endif*/ |
---|
1863 | if (simulation) { |
---|
1864 | /*db_gets( trc, ES_STATION, BC_SHORTSTRLTH, station, status );*/ |
---|
1865 | /*if (Severe(status)) return;*/ |
---|
1866 | locstat = cBcNoError; |
---|
1867 | db_gett( trc, ET_START, &ttime, &locstat ); |
---|
1868 | tc_a2t( &ttime, strtime, &locstat ); |
---|
1869 | cu_get_stream_string( trc, station, NULL ); |
---|
1870 | cu_lookup_filter( station, strtime, tfname, &trcflags, status ); |
---|
1871 | if (Severe(status)) return; |
---|
1872 | if (trcflags & CUC_F_TRC_FORCE_F) { |
---|
1873 | strcpy( complete_name, tfname ); |
---|
1874 | filter_typ = 'F'; |
---|
1875 | } else if (trcflags & CUC_F_TRC_FORCE_T) { |
---|
1876 | strcpy( complete_name, tfname ); |
---|
1877 | filter_typ = 'T'; |
---|
1878 | } else { |
---|
1879 | strcat( complete_name, tfname ); |
---|
1880 | } /*endif*/ |
---|
1881 | strcat( complete_name, "_" ); |
---|
1882 | } /*endif*/ |
---|
1883 | strcat( complete_name, filter ); |
---|
1884 | if (ts_is_selected(trcnum)) { |
---|
1885 | /* take filter from dialog box into filter info entry */ |
---|
1886 | if (GpGetInt(cGpI_debug_level) > 3) |
---|
1887 | printf( "shm-dbg4: set single filter %s on trace %d\n", |
---|
1888 | filter, trcnum ); |
---|
1889 | if (filter_typ == 'R') { |
---|
1890 | strcpy( singfilt, filprefix ); |
---|
1891 | strcat( singfilt, filter ); |
---|
1892 | } else { |
---|
1893 | strcpy( singfilt, filter ); |
---|
1894 | } /*endif*/ |
---|
1895 | db_sets( trc, filent, singfilt, status ); |
---|
1896 | if (Severe(status)) return; |
---|
1897 | } else { |
---|
1898 | locstat = cBcNoError; |
---|
1899 | db_gets( trc, filent, BC_FILELTH, singfilt, &locstat ); |
---|
1900 | if (locstat == cBcNoError && *singfilt != '\0') { |
---|
1901 | strcat( complete_name, ";" ); |
---|
1902 | strcat( complete_name, singfilt ); |
---|
1903 | } /*endif*/ |
---|
1904 | } /*endif*/ |
---|
1905 | if (strcmp(complete_name,last_name) != 0) { |
---|
1906 | sprintf( cmd, "fili %c %s", filter_typ, complete_name ); |
---|
1907 | callsh( cmd, &dmy, status ); |
---|
1908 | if (Severe(status)) { |
---|
1909 | *status = BC_NOERROR; |
---|
1910 | if (GpGetInt(cGpI_debug_level) > 1) |
---|
1911 | printf( "SHM-dbg2: filter, %s not available, use dummy filter\n", |
---|
1912 | complete_name ); |
---|
1913 | sprintf( cmd, "fili %c dummy", filter_typ ); |
---|
1914 | callsh( cmd, &dmy, status ); |
---|
1915 | if (Severe(status)) return; |
---|
1916 | } /*endif*/ |
---|
1917 | strcpy( last_name, complete_name ); |
---|
1918 | } /*endif*/ |
---|
1919 | sprintf( cmd, "filter %c a:%lx", filter_typ, trc ); |
---|
1920 | callsh( cmd, &dmy, status ); |
---|
1921 | if (Severe(status)) return; |
---|
1922 | newtrc = db_getp( newtrc, EP_NEXT, NULL ); |
---|
1923 | if (newtrc == NULL) { |
---|
1924 | *status = MXE_PROG_BUG; |
---|
1925 | printf( "*SHM: mx_filter: no trace created\n" ); |
---|
1926 | return; |
---|
1927 | } /*endif*/ |
---|
1928 | sprintf( cmd, "flt:%s", filter ); |
---|
1929 | db_sets( newtrc, ES_COMMENT, cmd, status ); |
---|
1930 | if (Severe(status)) return; |
---|
1931 | db_setf( newtrc, MXC_EF_FILTER, TRUE, status ); |
---|
1932 | if (Severe(status)) return; |
---|
1933 | } else { |
---|
1934 | sprintf( cmd, "copy a:%lx", trc ); |
---|
1935 | callsh( cmd, &dmy, status ); |
---|
1936 | if (Severe(status)) return; |
---|
1937 | newtrc = db_getp( newtrc, EP_NEXT, NULL ); |
---|
1938 | if (newtrc == NULL) { |
---|
1939 | *status = MXE_PROG_BUG; |
---|
1940 | printf( "*SHM: mx_filter: no trace created\n" ); |
---|
1941 | return; |
---|
1942 | } /*endif*/ |
---|
1943 | sprintf( cmd, "flt:NONE" ); |
---|
1944 | db_sets( newtrc, ES_COMMENT, cmd, status ); |
---|
1945 | if (Severe(status)) return; |
---|
1946 | db_setf( newtrc, MXC_EF_FILTER, TRUE, status ); |
---|
1947 | if (Severe(status)) return; |
---|
1948 | } /*endif*/ |
---|
1949 | |
---|
1950 | /* make trace red on alert flag */ |
---|
1951 | if (CUC_F_TRC_ALERT & trcflags) |
---|
1952 | mg_make_alert_trace( w, newtrc, status ); |
---|
1953 | |
---|
1954 | } while (trc != lasttrc); |
---|
1955 | |
---|
1956 | /* cleanup */ |
---|
1957 | sprintf( cmd, "shm_cmd_sepfil_finish %s %f %d", |
---|
1958 | filter, autocut, (GpGetInt(cGpI_trace_normalisation)==cGp_NORM_CONST) ); |
---|
1959 | mx_exec_sh( w, ctrl, cmd ); |
---|
1960 | |
---|
1961 | ts_clear_selections(); |
---|
1962 | |
---|
1963 | } /* end of mxh_filter_separately */ |
---|
1964 | |
---|
1965 | |
---|
1966 | #undef MAX_S_LTH |
---|
1967 | |
---|
1968 | |
---|
1969 | |
---|
1970 | /*----------------------------------------------------------------------------*/ |
---|
1971 | |
---|
1972 | |
---|
1973 | #ifdef XXX |
---|
1974 | |
---|
1975 | #define GRFNUM 19 |
---|
1976 | |
---|
1977 | |
---|
1978 | |
---|
1979 | static void mxh_get_vax_grflist( MX_CMD_READG *rg, char liststr[] ) |
---|
1980 | |
---|
1981 | /* returns list string for readk command |
---|
1982 | * |
---|
1983 | * parameters of routine |
---|
1984 | * MX_CMD_READG *rg; input; read parameters |
---|
1985 | * char liststr[]; output; list string |
---|
1986 | */ |
---|
1987 | { |
---|
1988 | /* local variables */ |
---|
1989 | long statmap; /* station map */ |
---|
1990 | int compmap; /* component map */ |
---|
1991 | int idx[GRFNUM]; /* list of GRF numbers */ |
---|
1992 | int cnt; /* number of stations */ |
---|
1993 | int i; /* counter */ |
---|
1994 | |
---|
1995 | /* executable code */ |
---|
1996 | |
---|
1997 | if (strcmp(rg->sl.code[0],"GRA1") != 0) { |
---|
1998 | strcpy( liststr, "NONE" ); |
---|
1999 | return; |
---|
2000 | } /*endif*/ |
---|
2001 | |
---|
2002 | statmap = 0; |
---|
2003 | compmap = rg->comp; |
---|
2004 | |
---|
2005 | /* make own station map */ |
---|
2006 | for (i=0; i<MXC_STATLIST_LTH; i++) { |
---|
2007 | if ((1<<i) & rg->stations) { |
---|
2008 | if (strncmp(rg->sl.code[i],"GR",2) != 0) continue; |
---|
2009 | if (strcmp(rg->sl.code[i],"GRA1") == 0) statmap |= (1<<STC_GRA1); |
---|
2010 | else if (strcmp(rg->sl.code[i],"GRA2") == 0) statmap |= (1<<STC_GRA2); |
---|
2011 | else if (strcmp(rg->sl.code[i],"GRA3") == 0) statmap |= (1<<STC_GRA3); |
---|
2012 | else if (strcmp(rg->sl.code[i],"GRA4") == 0) statmap |= (1<<STC_GRA4); |
---|
2013 | else if (strcmp(rg->sl.code[i],"GRB1") == 0) statmap |= (1<<STC_GRB1); |
---|
2014 | else if (strcmp(rg->sl.code[i],"GRB2") == 0) statmap |= (1<<STC_GRB2); |
---|
2015 | else if (strcmp(rg->sl.code[i],"GRB3") == 0) statmap |= (1<<STC_GRB3); |
---|
2016 | else if (strcmp(rg->sl.code[i],"GRB4") == 0) statmap |= (1<<STC_GRB4); |
---|
2017 | else if (strcmp(rg->sl.code[i],"GRB5") == 0) statmap |= (1<<STC_GRB5); |
---|
2018 | else if (strcmp(rg->sl.code[i],"GRC1") == 0) statmap |= (1<<STC_GRC1); |
---|
2019 | else if (strcmp(rg->sl.code[i],"GRC2") == 0) statmap |= (1<<STC_GRC2); |
---|
2020 | else if (strcmp(rg->sl.code[i],"GRC3") == 0) statmap |= (1<<STC_GRC3); |
---|
2021 | else if (strcmp(rg->sl.code[i],"GRC4") == 0) statmap |= (1<<STC_GRC4); |
---|
2022 | } /*endif*/ |
---|
2023 | } /*endfor*/ |
---|
2024 | |
---|
2025 | /* create list of GRF numbers */ |
---|
2026 | cnt = 0; |
---|
2027 | if ((1<<STC_GRA1) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 1; |
---|
2028 | if ((1<<STC_GRA1) & statmap && (1<<STC_COMP_N) & compmap) idx[cnt++] = 2; |
---|
2029 | if ((1<<STC_GRA1) & statmap && (1<<STC_COMP_E) & compmap) idx[cnt++] = 3; |
---|
2030 | if ((1<<STC_GRA2) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 4; |
---|
2031 | if ((1<<STC_GRA3) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 5; |
---|
2032 | if ((1<<STC_GRA4) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 6; |
---|
2033 | if ((1<<STC_GRB1) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 7; |
---|
2034 | if ((1<<STC_GRB1) & statmap && (1<<STC_COMP_N) & compmap) idx[cnt++] = 8; |
---|
2035 | if ((1<<STC_GRB1) & statmap && (1<<STC_COMP_E) & compmap) idx[cnt++] = 9; |
---|
2036 | if ((1<<STC_GRB2) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 10; |
---|
2037 | if ((1<<STC_GRB3) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 11; |
---|
2038 | if ((1<<STC_GRB4) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 12; |
---|
2039 | if ((1<<STC_GRB5) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 13; |
---|
2040 | if ((1<<STC_GRC1) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 14; |
---|
2041 | if ((1<<STC_GRC1) & statmap && (1<<STC_COMP_N) & compmap) idx[cnt++] = 15; |
---|
2042 | if ((1<<STC_GRC1) & statmap && (1<<STC_COMP_E) & compmap) idx[cnt++] = 16; |
---|
2043 | if ((1<<STC_GRC2) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 17; |
---|
2044 | if ((1<<STC_GRC3) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 18; |
---|
2045 | if ((1<<STC_GRC4) & statmap && (1<<STC_COMP_Z) & compmap) idx[cnt++] = 19; |
---|
2046 | |
---|
2047 | /* put this list into a string */ |
---|
2048 | if (cnt == 0) { strcpy( liststr, "NONE" ); return; } |
---|
2049 | sprintf( liststr, "%d", idx[0] ); |
---|
2050 | for (i=1; i<cnt; i++) |
---|
2051 | sprintf( liststr+strlen(liststr), ",%d", idx[i] ); |
---|
2052 | |
---|
2053 | } /* end of mxh_get_vax_grflist */ |
---|
2054 | |
---|
2055 | #endif |
---|
2056 | |
---|
2057 | /*----------------------------------------------------------------------------*/ |
---|
2058 | |
---|
2059 | |
---|
2060 | |
---|
2061 | static void mxh_mount_cdrom( MX_CMD_READG *par, STATUS *status ) |
---|
2062 | |
---|
2063 | /* mounts cdrom for reading |
---|
2064 | * |
---|
2065 | * parameters of routine |
---|
2066 | * MX_CMD_READG *par; input/modify; read command parameters |
---|
2067 | * STATUS *status; output; return status |
---|
2068 | */ |
---|
2069 | { |
---|
2070 | /* local variables */ |
---|
2071 | int i; /* counter */ |
---|
2072 | char stream[BC_LINELTH+1]; /* stream string */ |
---|
2073 | char cmdline[BC_LONGSTRLTH+1]; /* command line */ |
---|
2074 | char *env; /* pointer to environment */ |
---|
2075 | TSyBoolean redraw; /* not used */ |
---|
2076 | TSyStatus locstat; /* not used */ |
---|
2077 | TSyBoolean is_sol2; /* is Solaris 2 machine */ |
---|
2078 | |
---|
2079 | /* executable code */ |
---|
2080 | |
---|
2081 | if (par->channum == 0) { |
---|
2082 | *status = MXE_NOCHANNELS; |
---|
2083 | return; |
---|
2084 | } else if (par->channum > 1) { |
---|
2085 | printf( "*SHM: take only first channel selected\n" ); |
---|
2086 | } /*endif*/ |
---|
2087 | |
---|
2088 | /* find first station in list */ |
---|
2089 | for (i=0; i<MXC_STATLIST_LTH; i++) |
---|
2090 | if ((1<<i) & par->stations) break; |
---|
2091 | |
---|
2092 | /* if no station selected return */ |
---|
2093 | if (i == MXC_STATLIST_LTH) { |
---|
2094 | *status = MXE_NOSTATIONS; |
---|
2095 | return; |
---|
2096 | } /*endif*/ |
---|
2097 | |
---|
2098 | /* build stream name from first station */ |
---|
2099 | strcpy( stream, par->sl.code[i] ); |
---|
2100 | strcat( stream, "-" ); |
---|
2101 | strcat( stream, par->chanstr[0] ); |
---|
2102 | strcat( stream, "-z" ); |
---|
2103 | ut_uncap( stream ); |
---|
2104 | |
---|
2105 | is_sol2 = cl_is_solaris_2(); |
---|
2106 | |
---|
2107 | /* close SEED files */ |
---|
2108 | locstat = BC_NOERROR; |
---|
2109 | callsh( "reads/close", &redraw, &locstat ); |
---|
2110 | |
---|
2111 | /* build and execute command line */ |
---|
2112 | if (is_sol2) { |
---|
2113 | /* *cmdline = '\0'; */ |
---|
2114 | strcpy( cmdline, "cmdtool " ); |
---|
2115 | } else { |
---|
2116 | strcpy( cmdline, "cmdtool " ); |
---|
2117 | } /*endif*/ |
---|
2118 | env = getenv( "SEED_PROG" ); |
---|
2119 | if (env != NULL) { |
---|
2120 | strcat( cmdline, env ); |
---|
2121 | strcat( cmdline, "/" ); |
---|
2122 | } /*endif*/ |
---|
2123 | sprintf( cmdline+strlen(cmdline), "szgrf_cd_mount.csh %s %s", |
---|
2124 | stream, par->start ); |
---|
2125 | system( cmdline ); |
---|
2126 | |
---|
2127 | if (is_sol2) { |
---|
2128 | strcpy( par->device, "/cdrom/cdrom0" ); |
---|
2129 | } else { |
---|
2130 | strcpy( par->device, "/cdrom" ); |
---|
2131 | } /*endif*/ |
---|
2132 | |
---|
2133 | } /* end of mxh_mount_cdrom */ |
---|
2134 | |
---|
2135 | |
---|
2136 | |
---|
2137 | /*----------------------------------------------------------------------------*/ |
---|
2138 | |
---|
2139 | |
---|
2140 | |
---|
2141 | static void mxh_set_entry_name( Widget ew, char text[] ) |
---|
2142 | |
---|
2143 | /* Sets menu entry text |
---|
2144 | * |
---|
2145 | * parameters of routine |
---|
2146 | * Widget ew; input; menu entry widget |
---|
2147 | * char text[]; input; new text for widget |
---|
2148 | */ |
---|
2149 | { |
---|
2150 | /* local variables */ |
---|
2151 | char ltext[cBcLineLth+1]; /* local copy of text to remove '_' */ |
---|
2152 | Arg args[2]; /* argument list */ |
---|
2153 | int n; /* argument counter */ |
---|
2154 | XmString xmstr; /* Xm string */ |
---|
2155 | |
---|
2156 | /* executable code */ |
---|
2157 | |
---|
2158 | if (strlen(text) >= cBcLineLth) { |
---|
2159 | fprintf( stderr, "*SHM: mxh_set_entry_name: name too long\n" ); |
---|
2160 | return; |
---|
2161 | } /*endif*/ |
---|
2162 | strcpy( ltext, text ); |
---|
2163 | for (n=0; n<strlen(ltext); n++) |
---|
2164 | if (ltext[n] == '_') ltext[n] = ' '; |
---|
2165 | |
---|
2166 | xmstr = XmStringCreateLtoR( ltext, "" ); |
---|
2167 | n = 0; |
---|
2168 | XtSetArg( args[n], XmNlabelString, xmstr ); n++; |
---|
2169 | XtSetValues( ew, args, n ); |
---|
2170 | |
---|
2171 | } /* end of mxh_set_entry_name */ |
---|
2172 | |
---|
2173 | |
---|
2174 | |
---|
2175 | /*----------------------------------------------------------------------------*/ |
---|
2176 | |
---|
2177 | |
---|
2178 | |
---|
2179 | void mx_remove_double_elements( char str[] ) |
---|
2180 | |
---|
2181 | /* removes double elements from comma separated list |
---|
2182 | * |
---|
2183 | * parameters of routine |
---|
2184 | * char str[]; modify; list |
---|
2185 | */ |
---|
2186 | { |
---|
2187 | /* local variables */ |
---|
2188 | TGpTextList tl; /* text list */ |
---|
2189 | int i, j; /* counters */ |
---|
2190 | |
---|
2191 | /* executable code */ |
---|
2192 | |
---|
2193 | GpParseTextList( str, &tl ); |
---|
2194 | |
---|
2195 | for (i=0; i<tl.numelem; i++) |
---|
2196 | for (j=(i+1); j<tl.numelem; j++) |
---|
2197 | if (strcmp(tl.elem[i],tl.elem[j]) == 0) |
---|
2198 | tl.elem[j][0] = '\0'; |
---|
2199 | |
---|
2200 | strcpy( str, tl.elem[0] ); |
---|
2201 | for (i=1; i<tl.numelem; i++) { |
---|
2202 | if (tl.elem[i][0] != '\0') { |
---|
2203 | strcat( str, "," ); |
---|
2204 | strcat( str, tl.elem[i] ); |
---|
2205 | } /*endif*/ |
---|
2206 | } /*endfor*/ |
---|
2207 | |
---|
2208 | GpFreeTextList( &tl ); |
---|
2209 | |
---|
2210 | } /* end of mx_remove_double_elements */ |
---|
2211 | |
---|
2212 | |
---|
2213 | |
---|
2214 | /*----------------------------------------------------------------------------*/ |
---|
2215 | |
---|
2216 | |
---|
2217 | |
---|
2218 | void mxh_compute_azimuth( char station[], float lat, float lon, |
---|
2219 | float *azim, TSyStatus *status ) |
---|
2220 | |
---|
2221 | /* Computes azimuth from station and epicentre location |
---|
2222 | * |
---|
2223 | * parameters of routine |
---|
2224 | * char cstation[]; input; name of station |
---|
2225 | * float lat, lon; input; epicentre location |
---|
2226 | * float *azim; output; azimuth computed |
---|
2227 | * TSyStatus *status; output; return status |
---|
2228 | */ |
---|
2229 | { |
---|
2230 | /* local variables */ |
---|
2231 | GLT_STATINF *statinf; /* station info */ |
---|
2232 | double d_dist, d_azim, d_bazim; |
---|
2233 | |
---|
2234 | /* executable code */ |
---|
2235 | |
---|
2236 | statinf = gl_store_station( station, TRUE, status ); |
---|
2237 | if (Severe(status)) return; |
---|
2238 | mb_locdiff( statinf->lat, statinf->lon, lat, lon, |
---|
2239 | &d_dist, &d_azim, &d_bazim ); |
---|
2240 | *azim = d_bazim; |
---|
2241 | |
---|
2242 | } /* end of mxh_compute_azimuth */ |
---|
2243 | |
---|
2244 | |
---|
2245 | |
---|
2246 | /*----------------------------------------------------------------------------*/ |
---|
2247 | |
---|
2248 | |
---|
2249 | static void mxh_read_stations_from_evt( char autoevt[], char addlist[] ) |
---|
2250 | |
---|
2251 | /* Reads station list from evtfile |
---|
2252 | * |
---|
2253 | * parameters of routine |
---|
2254 | * char autoevt[]; input: name of evt file |
---|
2255 | * char addlist[]; output; list of station names |
---|
2256 | */ |
---|
2257 | { |
---|
2258 | /* local variables */ |
---|
2259 | FILE *fp; /* pointer to file */ |
---|
2260 | char tmpfile[cBcFileLth+1]; /* temporary file */ |
---|
2261 | static int fcnt=1; /* temp file counter */ |
---|
2262 | char shellcmd[cBcLongStrLth+1]; /* shell command */ |
---|
2263 | char line[cBcLineLth+1]; /* current line in file */ |
---|
2264 | int i; /* counter */ |
---|
2265 | |
---|
2266 | /* executable code */ |
---|
2267 | |
---|
2268 | *addlist = '\0'; |
---|
2269 | sprintf( tmpfile, "/tmp/ae_stations_%d.000", fcnt++ ); |
---|
2270 | sprintf( shellcmd, |
---|
2271 | "grep 'Station code :' %s | awk '{print $4}' | sort -u >%s", |
---|
2272 | autoevt, tmpfile ); |
---|
2273 | printf( "executing: %s\n", shellcmd ); |
---|
2274 | system( shellcmd ); |
---|
2275 | fp = fopen( tmpfile, "r" ); |
---|
2276 | while (fgets(line,cBcLineLth,fp) != NULL) { |
---|
2277 | i = strlen( line ); |
---|
2278 | if (line[i-1] == '\n') line[i-1] = '\0'; |
---|
2279 | if (strlen(addlist) > cBcLongStrLth-2) { |
---|
2280 | fclose( fp ); |
---|
2281 | printf( "*SHM: evt station list truncated\n" ); |
---|
2282 | return; |
---|
2283 | } /*endif*/ |
---|
2284 | if (*addlist != '\0') strcat( addlist, "," ); |
---|
2285 | strcat( addlist, line ); |
---|
2286 | } /*endwhile*/ |
---|
2287 | fclose( fp ); |
---|
2288 | } |
---|
2289 | |
---|
2290 | |
---|
2291 | /*----------------------------------------------------------------------------*/ |
---|
2292 | |
---|
2293 | |
---|
2294 | |
---|
2295 | static void mxh_read_location_from_evt( char autoevt[], float *lat, float *lon, |
---|
2296 | TSyBoolean *found ) |
---|
2297 | |
---|
2298 | /* Reads latitude and longitude from evt file |
---|
2299 | * |
---|
2300 | * parameters of routine |
---|
2301 | * char autoevt[]; input; name of evt file |
---|
2302 | * float *lat, *lon; output; location read from above file |
---|
2303 | * TSyBoolean *found; output; TRUE if location is found |
---|
2304 | */ |
---|
2305 | { |
---|
2306 | /* local variables */ |
---|
2307 | FILE *fp; /* pointer to file */ |
---|
2308 | char line[cBcLineLth+1]; /* current line of file */ |
---|
2309 | TSyBoolean latfound, lonfound; /* latitude and longitude found */ |
---|
2310 | int i; /* counter */ |
---|
2311 | |
---|
2312 | /* executable code */ |
---|
2313 | |
---|
2314 | /* open evt file */ |
---|
2315 | *found = TRUE; |
---|
2316 | fp = fopen( autoevt, "r" ); |
---|
2317 | if (fp == NULL) { |
---|
2318 | *found = FALSE; |
---|
2319 | return; |
---|
2320 | } /*endif*/ |
---|
2321 | |
---|
2322 | /* read through file */ |
---|
2323 | latfound = lonfound = FALSE; |
---|
2324 | while (fgets(line,cBcLineLth,fp) != NULL) { |
---|
2325 | if (strncmp(line,"Latitude ",9) == 0) { |
---|
2326 | i = 9; /* length of Latitude string */ |
---|
2327 | while (line[i] == ' ' || line[i] == ':') |
---|
2328 | i++; |
---|
2329 | if (sscanf(line+i,"%f",lat) == 1) |
---|
2330 | latfound = TRUE; |
---|
2331 | } /*endif*/ |
---|
2332 | if (strncmp(line,"Longitude ",10) == 0) { |
---|
2333 | i = 10; /* length of Latitude string */ |
---|
2334 | while (line[i] == ' ' || line[i] == ':') |
---|
2335 | i++; |
---|
2336 | if (sscanf(line+i,"%f",lon) == 1) |
---|
2337 | lonfound = TRUE; |
---|
2338 | } /*endif*/ |
---|
2339 | if (latfound && lonfound) |
---|
2340 | break; |
---|
2341 | } /*endwhile*/ |
---|
2342 | |
---|
2343 | if (!latfound || !lonfound) { |
---|
2344 | *found = FALSE; |
---|
2345 | return; |
---|
2346 | } /*endif*/ |
---|
2347 | |
---|
2348 | fclose( fp ); |
---|
2349 | |
---|
2350 | } /* end of mxh_read_location_from_evt */ |
---|
2351 | |
---|
2352 | |
---|
2353 | |
---|
2354 | /*----------------------------------------------------------------------------*/ |
---|