1 | |
---|
2 | /* file shexec.c |
---|
3 | * ======== |
---|
4 | * |
---|
5 | * $Revision: 15 $, $Date: 2008-01-25 11:48:08 +0100 (Fr, 25 Jan 2008) $ |
---|
6 | * |
---|
7 | * main subroutines of SH |
---|
8 | * K. Stammler, 10-Feb-93 |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | /* |
---|
13 | * |
---|
14 | * SeismicHandler, seismic analysis software |
---|
15 | * Copyright (C) 1992, Klaus Stammler, Federal Institute for Geosciences |
---|
16 | * and Natural Resources (BGR), Germany |
---|
17 | * |
---|
18 | * This program is free software; you can redistribute it and/or modify |
---|
19 | * it under the terms of the GNU General Public License as published by |
---|
20 | * the Free Software Foundation; either version 2 of the License, or |
---|
21 | * (at your option) any later version. |
---|
22 | * |
---|
23 | * This program is distributed in the hope that it will be useful, |
---|
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
26 | * GNU General Public License for more details. |
---|
27 | * |
---|
28 | * You should have received a copy of the GNU General Public License |
---|
29 | * along with this program; if not, write to the Free Software |
---|
30 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | #include <stdio.h> |
---|
36 | #include <string.h> |
---|
37 | #include "basecnst.h" |
---|
38 | #include "sysbase.h" |
---|
39 | #ifdef BC_INC_STDLIB |
---|
40 | #include BC_INC_STDLIB |
---|
41 | #ifdef BC_INC_UNISTD |
---|
42 | #include BC_INC_UNISTD |
---|
43 | #endif |
---|
44 | #endif |
---|
45 | #include "seusrdef.h" |
---|
46 | #include "cpusrdef.h" |
---|
47 | #include "fctxmn0.h" |
---|
48 | #include "fctxmn1.h" |
---|
49 | #include "fctxmn2.h" |
---|
50 | #include "fctxmn3.h" |
---|
51 | #include "fctxmn4.h" |
---|
52 | #include "fctxmn5.h" |
---|
53 | #include "fctxmni.h" |
---|
54 | #include "fctxmnx.h" |
---|
55 | #include "fctxdm.h" |
---|
56 | #include "fctxmt.h" |
---|
57 | #include "shvars.h" |
---|
58 | #include "erusrdef.h" |
---|
59 | #include "ssusrdef.h" |
---|
60 | #include "uiusrdef.h" |
---|
61 | #include "qiusrdef.h" |
---|
62 | #include "qfusrdef.h" |
---|
63 | #include "earthloc.h" |
---|
64 | #include "sherrors.h" |
---|
65 | #include "residual.h" |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | /* prototype for readk if used */ |
---|
70 | #ifdef SH_SETUP_READK |
---|
71 | void mngrf_readk( PARAM *cmd, STATUS *status ); |
---|
72 | #endif |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | /*------------------------------------------------------------------------*/ |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | void se_initialize( int argc, char *argv[], STATUS *status ) |
---|
81 | |
---|
82 | /* initializes SH program: |
---|
83 | * (i) set session ID string |
---|
84 | * (ii) UNIX path names or path list file (set shd_... variables) |
---|
85 | * (iii) set input/output dirs for graphic (gc_...) routines |
---|
86 | * (iv) set global vars: shflags_shv, shglbflags_shv, graphic channels |
---|
87 | * (v) open protocol file |
---|
88 | * (vi) initialize q-file interface |
---|
89 | * (vii) set default names for earthloc input files (mb_...) |
---|
90 | * (viii) open startup file (set ui_level to 1) |
---|
91 | * |
---|
92 | * parameters of routine |
---|
93 | * int argc; input; command line parameters |
---|
94 | * char argv[]; input; -- " -- |
---|
95 | * STATUS *status; output; return status |
---|
96 | */ |
---|
97 | { |
---|
98 | /* local variables */ |
---|
99 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
100 | BOOLEAN ok; /* status ok ? */ |
---|
101 | PARAM cmd; /* SH command block */ |
---|
102 | |
---|
103 | /* executable code */ |
---|
104 | |
---|
105 | /* get path names: either from UNIX environment ... */ |
---|
106 | # ifdef BC_SUN |
---|
107 | se_get_sh_environment(); |
---|
108 | # endif |
---|
109 | |
---|
110 | /* get session ID string */ |
---|
111 | strcpy( id_shv, SHC_FILE_PREFIX ); |
---|
112 | # ifdef BC_SUN |
---|
113 | mt_randomstr( 4, id_shv+SHC_FILE_PREFIX_LENGTH ); |
---|
114 | strcat( id_shv, "_" ); |
---|
115 | # endif /* BC_SUN */ |
---|
116 | |
---|
117 | strcpy( str, shd_scratch ); |
---|
118 | # ifdef SHC_HCFILE_WITH_RANDOM |
---|
119 | strcat( str, id_shv ); |
---|
120 | # else |
---|
121 | strcat( str, SHC_FILE_PREFIX ); |
---|
122 | # endif |
---|
123 | gc_set_outputdir( str, status ); |
---|
124 | gc_set_inputdir( shd_inputs, status ); |
---|
125 | |
---|
126 | /* setup global flags */ |
---|
127 | shflags_shv = SHF_LOGCMD|SHF_CAPCNV|SHF_CMDERRSTOP|SHF_CHATTY; |
---|
128 | shglbflags_shv = shflags_shv; |
---|
129 | |
---|
130 | /* set preliminary output channels */ |
---|
131 | gc = gc_shv = tc = tc_shv = cc = cc_shv = 0; |
---|
132 | |
---|
133 | /* initialize protocol file */ |
---|
134 | strcpy( protfile_shv, shd_scratch ); |
---|
135 | strcat( protfile_shv, id_shv ); |
---|
136 | strcat( protfile_shv, "PROT" ); |
---|
137 | ui_initialize( protfile_shv, status ); |
---|
138 | if (Severe(status)) return; |
---|
139 | ui_absflag( shflags_shv ); |
---|
140 | |
---|
141 | /* initialize q-file interface */ |
---|
142 | qi_initcnv(); |
---|
143 | |
---|
144 | /* initialize names of input files */ |
---|
145 | strcpy( str, shd_inputs ); |
---|
146 | strcat( str, "fereg.dat" ); |
---|
147 | mb_setindexfile( str, status ); |
---|
148 | if (Severe(status)) |
---|
149 | sy_alert( "*** didn't set FER index file name properly ***\n" ); |
---|
150 | *status = BC_NOERROR; |
---|
151 | strcpy( str, shd_inputs ); |
---|
152 | strcat( str, "fername.dat" ); |
---|
153 | mb_setfernamefile( str, status ); |
---|
154 | if (Severe(status)) |
---|
155 | sy_alert( "*** didn't set FER name file name properly ***\n" ); |
---|
156 | *status = BC_NOERROR; |
---|
157 | |
---|
158 | /* open startup command file */ |
---|
159 | cp_parse( "SHSTRTUP/FLAGS+=AF", &cmd, status ); |
---|
160 | mn0_callproc( &cmd, status ); |
---|
161 | if (Severe(status)) { |
---|
162 | sy_alert( "*** no startup file found ***" ); |
---|
163 | return; |
---|
164 | } /*endif*/ |
---|
165 | |
---|
166 | RsReadTables( "default", status ); |
---|
167 | if (Severe(status)) { |
---|
168 | sy_alert( "*** error reading residual tables ***" ); |
---|
169 | *status = cBcNoError; |
---|
170 | } /*endif*/ |
---|
171 | |
---|
172 | } /* end of se_initialize */ |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | /*------------------------------------------------------------------------*/ |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | void se_terminate( void ) |
---|
181 | |
---|
182 | /* closes all files and renames log file |
---|
183 | * |
---|
184 | * no parameters |
---|
185 | */ |
---|
186 | { |
---|
187 | /* local variables */ |
---|
188 | STATUS status; /* return status */ |
---|
189 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
190 | |
---|
191 | /* executable code */ |
---|
192 | |
---|
193 | status = BC_NOERROR; |
---|
194 | qf_rclose( &status ); |
---|
195 | strcpy( str, shd_scratch ); |
---|
196 | strcat( str, SHC_FILE_PREFIX ); |
---|
197 | strcat( str, "LAST" ); |
---|
198 | strcat( str, SHC_DE_CMD ); |
---|
199 | sy_fdelete( str ); |
---|
200 | strcpy( str, shd_scratch ); |
---|
201 | strcat( str, SHC_FILE_PREFIX ); |
---|
202 | strcat( str, "LAST" ); |
---|
203 | ui_exit( str ); |
---|
204 | gc_finish(); |
---|
205 | |
---|
206 | } /* end of se_terminate */ |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | /*------------------------------------------------------------------------*/ |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | void se_execute_command( PARAM *cmd, char cmdlin[], char execstr[], |
---|
215 | BOOLEAN *quit, BOOLEAN *redraw, BOOLEAN *iscmdproc, int *rdlevel, |
---|
216 | char prompt[], STATUS *status ) |
---|
217 | |
---|
218 | /* executes the command "cmd" |
---|
219 | * |
---|
220 | * parameters of routine |
---|
221 | * PARAM *cmd; input; command verb & parameters |
---|
222 | * char cmdlin[]; input; command line |
---|
223 | * char execstr[]; output; next command line (from EXEC command) |
---|
224 | * BOOLEAN *quit; output; quit program |
---|
225 | * BOOLEAN *redraw; output; redraw screen after command |
---|
226 | * int *rdlevel; modify; redraw level |
---|
227 | * char prompt[]; output; prompt string |
---|
228 | * STATUS *status; output; return status |
---|
229 | */ |
---|
230 | { |
---|
231 | /* executable code */ |
---|
232 | |
---|
233 | *iscmdproc = FALSE; |
---|
234 | |
---|
235 | switch (cmd->p[0][0]) { |
---|
236 | case 'A': |
---|
237 | if (cp_cmdverb(cmd,"AL")) { |
---|
238 | mnx_al( cmd, status ); |
---|
239 | *redraw = TRUE; |
---|
240 | } else if (cp_cmdverb(cmd,"AM")) { |
---|
241 | mnx_am( cmd, status ); |
---|
242 | } else if (cp_cmdverb(cmd,"APPEND")) { |
---|
243 | mn4_append( cmd, status ); |
---|
244 | *redraw = TRUE; |
---|
245 | } else if (cp_cmdverb(cmd,"ARP")) { |
---|
246 | mn3_arp( cmd, status ); |
---|
247 | *redraw = TRUE; |
---|
248 | } else { |
---|
249 | mn0_callproc( cmd, status ); |
---|
250 | *iscmdproc = TRUE; |
---|
251 | } /*endif*/ |
---|
252 | break; |
---|
253 | case 'B': |
---|
254 | if (cp_cmdverb(cmd,"BEAM")) { |
---|
255 | mnx_beam( cmd, status ); |
---|
256 | *redraw = TRUE; |
---|
257 | } else { |
---|
258 | mn0_callproc( cmd, status ); |
---|
259 | *iscmdproc = TRUE; |
---|
260 | } /*endif*/ |
---|
261 | break; |
---|
262 | case 'C': |
---|
263 | if (cp_cmdverb(cmd,"CALC")) { |
---|
264 | mn0_calc( cmd, status ); |
---|
265 | } else if (cp_cmdverb(cmd,"CALL")) { |
---|
266 | mn3_call( cmd, status ); |
---|
267 | } else if (cp_cmdverb(cmd,"CMD")) { |
---|
268 | mn2_cmd( cmd, status ); |
---|
269 | } else if (cp_cmdverb(cmd,"CONNECT")) { |
---|
270 | mn4_connect( cmd, status ); |
---|
271 | *redraw = TRUE; |
---|
272 | } else if (cp_cmdverb(cmd,"COPY")) { |
---|
273 | mn1_copy( cmd, status ); |
---|
274 | *redraw = TRUE; |
---|
275 | } else if (cp_cmdverb(cmd,"CORR")) { |
---|
276 | mn2_corr( cmd, status ); |
---|
277 | *redraw = TRUE; |
---|
278 | } else if (cp_cmdverb(cmd,"CORRL")) { |
---|
279 | mn2_corrl( cmd, status ); |
---|
280 | } else if (cp_cmdverb(cmd,"CREATE")) { |
---|
281 | mn1_create( cmd, status ); |
---|
282 | *redraw = TRUE; |
---|
283 | } else if (cp_cmdverb(cmd,"CURVE")) { |
---|
284 | mn3_curve( cmd, status ); |
---|
285 | } else if (cp_cmdverb(cmd,"CUT")) { |
---|
286 | mn3_cut( cmd, status ); |
---|
287 | } else { |
---|
288 | mn0_callproc( cmd, status ); |
---|
289 | *iscmdproc = TRUE; |
---|
290 | } /*endif*/ |
---|
291 | break; |
---|
292 | case 'D': |
---|
293 | if (cp_cmdverb(cmd,"DECIMATE")) { |
---|
294 | mn5_decimate( cmd, status ); |
---|
295 | *redraw = TRUE; |
---|
296 | } else if (cp_cmdverb(cmd,"DEFAULT")) { |
---|
297 | mn0_default( cmd, status ); |
---|
298 | } else if (cp_cmdverb(cmd,"DEL")) { |
---|
299 | mn1_del( cmd, status ); |
---|
300 | *redraw = TRUE; |
---|
301 | } else if (cp_cmdverb(cmd,"DEMEAN")) { |
---|
302 | mn4_demean( cmd, status ); |
---|
303 | *redraw = TRUE; |
---|
304 | } else if (cp_cmdverb(cmd,"DERIVE")) { |
---|
305 | mn4_derive( cmd, status ); |
---|
306 | *redraw = TRUE; |
---|
307 | } else if (cp_cmdverb(cmd,"DESPIKE")) { |
---|
308 | mn3_despike( cmd, status ); |
---|
309 | *redraw = TRUE; |
---|
310 | } else if (cp_cmdverb(cmd,"DISPLAY")) { |
---|
311 | mn2_display( cmd, status ); |
---|
312 | *redraw = TRUE; |
---|
313 | } else if (cp_cmdverb(cmd,"DTW")) { |
---|
314 | dm_timewdw( 0.0, 0.0, status ); |
---|
315 | *redraw = TRUE; |
---|
316 | } else if (cp_cmdverb(cmd,"DYW")) { |
---|
317 | dm_ywdw( 0.0, 0.0, status ); |
---|
318 | *redraw = TRUE; |
---|
319 | } else { |
---|
320 | mn0_callproc( cmd, status ); |
---|
321 | *iscmdproc = TRUE; |
---|
322 | } /*endif*/ |
---|
323 | break; |
---|
324 | case 'E': |
---|
325 | if (cp_cmdverb(cmd,"ECHO_CH")) { |
---|
326 | mn0_ecch( cmd, status ); |
---|
327 | } else if (cp_cmdverb(cmd,"ECHO")) { |
---|
328 | mn0_echo( cmd, status ); |
---|
329 | } else if (cp_cmdverb(cmd,"ENTER")) { |
---|
330 | mn0_enter( cmd, status ); |
---|
331 | } else if (cp_cmdverb(cmd,"ENTRY")) { |
---|
332 | mn1_entry( cmd, status ); |
---|
333 | } else if (cp_cmdverb(cmd,"EXEC")) { |
---|
334 | if (cp_pnexc(cmd,1,status)) return; |
---|
335 | cp_getstr( cmd, 1, tc, " cmd: ", BC_LINELTH, execstr, status ); |
---|
336 | } else if (cp_cmdverb(cmd,"EXTERNAL_ROUTINE")) { |
---|
337 | mn5_external_routine( cmd, status ); |
---|
338 | } else if (cp_cmdverb(cmd,"EXTRACT")) { |
---|
339 | mn2_extract( cmd, status ); |
---|
340 | } else { |
---|
341 | mn0_callproc( cmd, status ); |
---|
342 | *iscmdproc = TRUE; |
---|
343 | } /*endif*/ |
---|
344 | break; |
---|
345 | case 'F': |
---|
346 | if (cp_cmdverb(cmd,"FCT")) { |
---|
347 | mn0_fct( cmd, status ); |
---|
348 | } else if (cp_cmdverb(cmd,"FFT")) { |
---|
349 | mn4_fft( cmd, status ); |
---|
350 | *redraw = TRUE; |
---|
351 | } else if (cp_cmdverb(cmd,"FILI")) { |
---|
352 | mn2_fili( cmd, status ); |
---|
353 | } else if (cp_cmdverb(cmd,"FILTER")) { |
---|
354 | mn2_filter( cmd, status ); |
---|
355 | *redraw = TRUE; |
---|
356 | } else if (cp_cmdverb(cmd,"FINDGAP")) { |
---|
357 | mn5_findgap( cmd, status ); |
---|
358 | } else if (cp_cmdverb(cmd,"FIXGAP")) { |
---|
359 | mn5_fixgap( cmd, status ); |
---|
360 | *redraw = TRUE; |
---|
361 | } else if (cp_cmdverb(cmd,"FIT")) { |
---|
362 | mn4_fit( cmd, status ); |
---|
363 | } else if (cp_cmdverb(cmd,"FOLD")) { |
---|
364 | mn3_fold( cmd, status ); |
---|
365 | *redraw = TRUE; |
---|
366 | } else { |
---|
367 | mn0_callproc( cmd, status ); |
---|
368 | *iscmdproc = TRUE; |
---|
369 | } /*endif*/ |
---|
370 | break; |
---|
371 | case 'G': |
---|
372 | if (cp_cmdverb(cmd,"GOTO")) { |
---|
373 | mn0_goto( cmd, status ); |
---|
374 | } else { |
---|
375 | mn0_callproc( cmd, status ); |
---|
376 | *iscmdproc = TRUE; |
---|
377 | } /*endif*/ |
---|
378 | break; |
---|
379 | case 'H': |
---|
380 | if (cp_cmdverb(cmd,"HC")) { |
---|
381 | mnx_hc( cmd, status ); |
---|
382 | } else if (cp_cmdverb(cmd,"HELP")) { |
---|
383 | mn0_help( cmd, status ); |
---|
384 | } else if (cp_cmdverb(cmd,"HIDE")) { |
---|
385 | mn2_hide( cmd, status ); |
---|
386 | *redraw = TRUE; |
---|
387 | } else if (cp_cmdverb(cmd,"HOTKEY")) { |
---|
388 | mn0_hotkey( cmd, status ); |
---|
389 | } else { |
---|
390 | mn0_callproc( cmd, status ); |
---|
391 | *iscmdproc = TRUE; |
---|
392 | } /*endif*/ |
---|
393 | break; |
---|
394 | case 'I': |
---|
395 | if (cp_cmdverb(cmd,"IF")) { |
---|
396 | mn0_if( cmd, status ); |
---|
397 | } else if (cp_cmdverb(cmd,"INT")) { |
---|
398 | mn4_int( cmd, status ); |
---|
399 | *redraw = TRUE; |
---|
400 | # ifdef XXX |
---|
401 | } else if (cp_cmdverb(cmd,"INVERSE")) { |
---|
402 | mngrf_inverse( cmd, status ); |
---|
403 | *redraw = TRUE; |
---|
404 | # endif /* XXX */ |
---|
405 | } else { |
---|
406 | mn0_callproc( cmd, status ); |
---|
407 | *iscmdproc = TRUE; |
---|
408 | } /*endif*/ |
---|
409 | break; |
---|
410 | case 'J': |
---|
411 | case 'K': |
---|
412 | case 'L': |
---|
413 | if (cp_cmdverb(cmd,"LEVELDETEC")) { |
---|
414 | mn4_leveldetec( cmd, status ); |
---|
415 | } else if (cp_cmdverb(cmd,"LOCATE")) { |
---|
416 | mnx_locate( cmd, status ); |
---|
417 | } else if (cp_cmdverb(cmd,"LOG")) { |
---|
418 | mn5_log( cmd, status ); |
---|
419 | } else { |
---|
420 | mn0_callproc( cmd, status ); |
---|
421 | *iscmdproc = TRUE; |
---|
422 | } /*endif*/ |
---|
423 | break; |
---|
424 | case 'M': |
---|
425 | if (cp_cmdverb(cmd,"MARK")) { |
---|
426 | mn2_mark( cmd, status ); |
---|
427 | } else if (cp_cmdverb(cmd,"MAXAMPL")) { |
---|
428 | mn1_maxampl( cmd, status ); |
---|
429 | *redraw = TRUE; |
---|
430 | } else if (cp_cmdverb(cmd,"MAXIMUM")) { |
---|
431 | mn5_maximum( cmd, status ); |
---|
432 | *redraw = TRUE; |
---|
433 | } else if (cp_cmdverb(cmd,"MDIR")) { |
---|
434 | mn2_mdir( cmd, status ); |
---|
435 | } else if (cp_cmdverb(cmd,"MEAN")) { |
---|
436 | mn5_mean( cmd, status ); |
---|
437 | *redraw = TRUE; |
---|
438 | } else if (cp_cmdverb(cmd,"MEND")) { |
---|
439 | mn3_mend( cmd, status ); |
---|
440 | *redraw = TRUE; |
---|
441 | } else if (cp_cmdverb(cmd,"MERGE")) { |
---|
442 | mn4_merge( cmd, status ); |
---|
443 | *redraw = TRUE; |
---|
444 | } else if (cp_cmdverb(cmd,"MERGE_PAIR")) { |
---|
445 | mn4_merge_pair( cmd, status ); |
---|
446 | *redraw = FALSE; |
---|
447 | } else if (cp_cmdverb(cmd,"MIRROR")) { |
---|
448 | mn3_mirror( cmd, status ); |
---|
449 | *redraw = TRUE; |
---|
450 | } else { |
---|
451 | mn0_callproc( cmd, status ); |
---|
452 | *iscmdproc = TRUE; |
---|
453 | } /*endif*/ |
---|
454 | break; |
---|
455 | case 'N': |
---|
456 | if (cp_cmdverb(cmd,"NORM")) { |
---|
457 | mn1_norm( cmd, redraw, status ); |
---|
458 | } else if (cp_cmdverb(cmd,"NOP")) { |
---|
459 | } else if (cp_cmdverb(cmd,"NR")) { |
---|
460 | (*rdlevel)++; |
---|
461 | } else { |
---|
462 | mn0_callproc( cmd, status ); |
---|
463 | *iscmdproc = TRUE; |
---|
464 | } /*endif*/ |
---|
465 | break; |
---|
466 | case 'O': |
---|
467 | if (cp_cmdverb(cmd,"OVERLAY")) { |
---|
468 | mn3_overlay( cmd, status ); |
---|
469 | } else { |
---|
470 | mn0_callproc( cmd, status ); |
---|
471 | *iscmdproc = TRUE; |
---|
472 | } /*endif*/ |
---|
473 | break; |
---|
474 | case 'P': |
---|
475 | if (cp_cmdverb(cmd,"PICK")) { |
---|
476 | mn2_pick( cmd, status ); |
---|
477 | } else if (cp_cmdverb(cmd,"PM")) { |
---|
478 | mnx_pm( cmd, status ); |
---|
479 | } else if (cp_cmdverb(cmd,"PMCH")) { |
---|
480 | mnx_pmch( cmd, status ); |
---|
481 | } else if (cp_cmdverb(cmd,"POLFIL")) { |
---|
482 | mn4_polfil( cmd, status ); |
---|
483 | *redraw = TRUE; |
---|
484 | } else if (cp_cmdverb(cmd,"PROMPT")) { |
---|
485 | mn5_prompt( cmd, BC_LINELTH, prompt, status ); |
---|
486 | } else { |
---|
487 | mn0_callproc( cmd, status ); |
---|
488 | *iscmdproc = TRUE; |
---|
489 | } /*endif*/ |
---|
490 | break; |
---|
491 | case 'Q': |
---|
492 | if (cp_cmdverb(cmd,"QUIT")) { |
---|
493 | mn0_quit( cmd, quit, status ); |
---|
494 | } else { |
---|
495 | mn0_callproc( cmd, status ); |
---|
496 | *iscmdproc = TRUE; |
---|
497 | } /*endif*/ |
---|
498 | break; |
---|
499 | case 'R': |
---|
500 | if (cp_cmdverb(cmd,"RD")) { |
---|
501 | mn1_rd( cmd, rdlevel, status ); |
---|
502 | *redraw = TRUE; |
---|
503 | } else if (cp_cmdverb(cmd,"READ")) { |
---|
504 | mni_read( cmd, status ); |
---|
505 | *redraw = TRUE; |
---|
506 | } else if (cp_cmdverb(cmd,"READA")) { |
---|
507 | mni_reada( cmd, status ); |
---|
508 | *redraw = TRUE; |
---|
509 | } else if (cp_cmdverb(cmd,"READF")) { |
---|
510 | mni_readf( cmd, status ); |
---|
511 | *redraw = TRUE; |
---|
512 | #ifdef XXX |
---|
513 | } else if (cp_cmdverb(cmd,"READG")) { |
---|
514 | mn5_readg( cmd, status ); |
---|
515 | *redraw = TRUE; |
---|
516 | #endif |
---|
517 | # ifdef SH_SETUP_READK |
---|
518 | } else if (cp_cmdverb(cmd,"READK")) { |
---|
519 | mngrf_readk( cmd, status ); |
---|
520 | *redraw = TRUE; |
---|
521 | # endif /* SH_SETUP_READK */ |
---|
522 | } else if (cp_cmdverb(cmd,"READS")) { |
---|
523 | mni_reads( cmd, status ); |
---|
524 | *redraw = TRUE; |
---|
525 | } else if (cp_cmdverb(cmd,"REPLACE")) { |
---|
526 | mn5_replace( cmd, status ); |
---|
527 | *redraw = TRUE; |
---|
528 | } else if (cp_cmdverb(cmd,"RESAMPLE")) { |
---|
529 | mnx_resample( cmd, status ); |
---|
530 | } else if (cp_cmdverb(cmd,"RETURN")) { |
---|
531 | mn0_cmdreturn( status ); |
---|
532 | } else if (cp_cmdverb(cmd,"RMS")) { |
---|
533 | mnx_rms( cmd, status ); |
---|
534 | } else if (cp_cmdverb(cmd,"ROT")) { |
---|
535 | mn1_rot( cmd, status ); |
---|
536 | *redraw = TRUE; |
---|
537 | } else { |
---|
538 | mn0_callproc( cmd, status ); |
---|
539 | *iscmdproc = TRUE; |
---|
540 | } /*endif*/ |
---|
541 | break; |
---|
542 | case 'S': |
---|
543 | if (cp_cmdverb(cmd,"SAMPLE")) { |
---|
544 | mn5_sample( cmd, status ); |
---|
545 | } else if (cp_cmdverb(cmd,"SDEF")) { |
---|
546 | mn0_sdef( cmd, status ); |
---|
547 | } else if (cp_cmdverb(cmd,"SDEL")) { |
---|
548 | mn0_sdel( cmd, status ); |
---|
549 | } else if (cp_cmdverb(cmd,"SET")) { |
---|
550 | mn1_set( cmd, status ); |
---|
551 | } else if (cp_cmdverb(cmd,"SHIFT")) { |
---|
552 | mnx_shift( cmd, status ); |
---|
553 | *redraw = TRUE; |
---|
554 | } else if (cp_cmdverb(cmd,"SHMSETUP")) { |
---|
555 | mn5_shmsetup( cmd, status ); |
---|
556 | } else if (cp_cmdverb(cmd,"SMOOTH")) { |
---|
557 | mn5_smooth( cmd, status ); |
---|
558 | *redraw = TRUE; |
---|
559 | } else if (cp_cmdverb(cmd,"SPECDIV")) { |
---|
560 | mn5_specdiv( cmd, status ); |
---|
561 | *redraw = TRUE; |
---|
562 | } else if (cp_cmdverb(cmd,"SPECTRUM")) { |
---|
563 | mn4_spectrum( cmd, status ); |
---|
564 | *redraw = TRUE; |
---|
565 | } else if (cp_cmdverb(cmd,"SPECTROGRAM")) { |
---|
566 | mn4_spectrogram( cmd, status ); |
---|
567 | *redraw = FALSE; |
---|
568 | } else if (cp_cmdverb(cmd,"SPIKING")) { |
---|
569 | mn3_spikefil( cmd, status ); |
---|
570 | *redraw = TRUE; |
---|
571 | } else if (cp_cmdverb(cmd,"STABILITY")) { |
---|
572 | mn4_stability( cmd, status ); |
---|
573 | *redraw = TRUE; |
---|
574 | } else if (cp_cmdverb(cmd,"STALTA")) { |
---|
575 | mn4_stalta( cmd, status ); |
---|
576 | *redraw = TRUE; |
---|
577 | } else if (cp_cmdverb(cmd,"STW")) { |
---|
578 | mn1_stw( cmd, status ); |
---|
579 | *redraw = TRUE; |
---|
580 | } else if (cp_cmdverb(cmd,"STYW")) { |
---|
581 | mnx_styw( cmd, status ); |
---|
582 | *redraw = TRUE; |
---|
583 | } else if (cp_cmdverb(cmd,"SYW")) { |
---|
584 | mnx_syw( cmd, status ); |
---|
585 | *redraw = TRUE; |
---|
586 | } else if (cp_cmdverb(cmd,"SUM")) { |
---|
587 | mn1_sum( cmd, status ); |
---|
588 | *redraw = TRUE; |
---|
589 | } else if (cp_cmdverb(cmd,"SWITCH")) { |
---|
590 | mn0_switch( cmd, &shflags_shv, status ); |
---|
591 | } else if (cp_cmdverb(cmd,"SYSTEM")) { |
---|
592 | mn0_system( cmd, status ); |
---|
593 | } else { |
---|
594 | mn0_callproc( cmd, status ); |
---|
595 | *iscmdproc = TRUE; |
---|
596 | } /*endif*/ |
---|
597 | break; |
---|
598 | case 'T': |
---|
599 | if (cp_cmdverb(cmd,"TIME")) { |
---|
600 | mn2_time( cmd, status ); |
---|
601 | } else if (cp_cmdverb(cmd,"TITLE")) { |
---|
602 | mnx_title( cmd, status ); |
---|
603 | *redraw = TRUE; |
---|
604 | } else if (cp_cmdverb(cmd,"TRCFCT")) { |
---|
605 | mn2_trcfct( cmd, status ); |
---|
606 | *redraw = TRUE; |
---|
607 | } else if (cp_cmdverb(cmd,"TRCTXT")) { |
---|
608 | dm_inftext( cmdlin, status ); |
---|
609 | *redraw = TRUE; |
---|
610 | } else if (cp_cmdverb(cmd,"TRCTXTP")) { |
---|
611 | mn1_trctxtp( cmd, status ); |
---|
612 | *redraw = TRUE; |
---|
613 | } else if (cp_cmdverb(cmd,"TREND")) { |
---|
614 | mn4_trend( cmd, status ); |
---|
615 | *redraw = TRUE; |
---|
616 | } else { |
---|
617 | mn0_callproc( cmd, status ); |
---|
618 | *iscmdproc = TRUE; |
---|
619 | } /*endif*/ |
---|
620 | break; |
---|
621 | case 'U': |
---|
622 | if (cp_cmdverb(cmd,"UNIT")) { |
---|
623 | mn3_unit( cmd, status ); |
---|
624 | } else { |
---|
625 | mn0_callproc( cmd, status ); |
---|
626 | *iscmdproc = TRUE; |
---|
627 | } /*endif*/ |
---|
628 | break; |
---|
629 | case 'V': |
---|
630 | case 'W': |
---|
631 | if (cp_cmdverb(cmd,"WDW")) { |
---|
632 | mn0_wdw( cmd, status ); |
---|
633 | } else if (cp_cmdverb(cmd,"WRITE")) { |
---|
634 | mni_write( cmd, status ); |
---|
635 | } else if (cp_cmdverb(cmd,"WRITEA")) { |
---|
636 | mni_writea( cmd, status ); |
---|
637 | } else { |
---|
638 | mn0_callproc( cmd, status ); |
---|
639 | *iscmdproc = TRUE; |
---|
640 | } /*endif*/ |
---|
641 | break; |
---|
642 | case 'X': |
---|
643 | case 'Y': |
---|
644 | if (cp_cmdverb(cmd,"YINFO")) { |
---|
645 | mnx_yinfo( cmd, status ); |
---|
646 | *redraw = TRUE; |
---|
647 | } else { |
---|
648 | mn0_callproc( cmd, status ); |
---|
649 | *iscmdproc = TRUE; |
---|
650 | } /*endif*/ |
---|
651 | break; |
---|
652 | case 'Z': |
---|
653 | if (cp_cmdverb(cmd,"ZOOM")) { |
---|
654 | mn1_zoom( cmd, status ); |
---|
655 | *redraw = TRUE; |
---|
656 | } else { |
---|
657 | mn0_callproc( cmd, status ); |
---|
658 | *iscmdproc = TRUE; |
---|
659 | } /*endif*/ |
---|
660 | break; |
---|
661 | case '0': case '1': case '2': case '3': case '4': |
---|
662 | case '5': case '6': case '7': case '8': case '9': |
---|
663 | case '/': case '\\': |
---|
664 | mn0_callproc( cmd, status ); |
---|
665 | *iscmdproc = TRUE; |
---|
666 | break; |
---|
667 | default: |
---|
668 | if (cmd->p[0][0] >= 'a' && cmd->p[0][0] <= 'z') |
---|
669 | *status = SHE_LOWRCASE; |
---|
670 | break; |
---|
671 | } /*endswitch*/ |
---|
672 | |
---|
673 | } /* end of se_execute_command */ |
---|
674 | |
---|
675 | |
---|
676 | |
---|
677 | /*------------------------------------------------------------------------*/ |
---|
678 | |
---|
679 | |
---|
680 | |
---|
681 | void se_cmdabort( PARAM *par, char cmdline[], STATUS status ) |
---|
682 | |
---|
683 | /* creates error file, aborts command procedure and returns to level 0 |
---|
684 | * |
---|
685 | * parameters of routine |
---|
686 | * PARAM *par; input; parameter block |
---|
687 | * char cmdline[]; input; user input |
---|
688 | * STATUS status; input; error number |
---|
689 | */ |
---|
690 | { |
---|
691 | /* local variables */ |
---|
692 | static int errnum; /* error number */ |
---|
693 | char msg[BC_LINELTH+1]; /* error message */ |
---|
694 | char context[BC_LINELTH+1]; /* error context */ |
---|
695 | char fname[BC_LINELTH+1]; /* file name */ |
---|
696 | FILE *err; /* file pointers */ |
---|
697 | int *line; /* line in command procedure */ |
---|
698 | int i; /* counter */ |
---|
699 | int locstat; /* local status */ |
---|
700 | |
---|
701 | /* executable code */ |
---|
702 | |
---|
703 | /* create error file */ |
---|
704 | |
---|
705 | locstat = 0; |
---|
706 | strcpy( fname, shd_scratch ); |
---|
707 | strcat( fname, id_shv ); |
---|
708 | strcat( fname, "ERR" ); |
---|
709 | strcat( fname, SHC_DE_TEXT ); |
---|
710 | strcpy( msg, ">>> status report in error file " ); |
---|
711 | strcat( msg, fname ); |
---|
712 | strcat( msg, " <<<\n" ); |
---|
713 | gc_write( cc, msg ); |
---|
714 | err = sy_fopen( fname, "w" ); |
---|
715 | if (err == NULL) return; |
---|
716 | |
---|
717 | err_msg( status, msg ); |
---|
718 | err_getcontext( context ); |
---|
719 | fprintf( err, "STATUS REPORT FILE\n" ); |
---|
720 | fprintf( err, "==================\n\n" ); |
---|
721 | fprintf( err, "session ID %s, error number %d\n", id_shv, ++errnum ); |
---|
722 | fprintf( err, "status code %d\n", status ); |
---|
723 | fprintf( err, "error message:\n" ); |
---|
724 | fprintf( err, "%s\n", msg ); |
---|
725 | if (*context != '\0') { |
---|
726 | fprintf( err, "error context:\n" ); |
---|
727 | fprintf( err, "%s\n", context ); |
---|
728 | } /*endif*/ |
---|
729 | fprintf( err, "in source line\n%s\n", cmdline ); |
---|
730 | fprintf( err, "source line after translation\n" ); |
---|
731 | cp_verify( par, BC_LINELTH, msg, &locstat ); |
---|
732 | if (locstat != SHE_NOERROR) { |
---|
733 | fprintf( err, ">>> verify error <<<\n\n" ); |
---|
734 | } else { |
---|
735 | fprintf( err, "%s\n\n", msg ); |
---|
736 | } /*endif*/ |
---|
737 | |
---|
738 | fprintf( err, "traceback command levels (current level %d):\n", |
---|
739 | ui_level() ); |
---|
740 | line = ui_lines(); |
---|
741 | for (i=0;i<=ui_level();i++) |
---|
742 | fprintf( err, "line %3d in level %d (file %s)\n", |
---|
743 | *line++, i, ui_levelname(i) ); |
---|
744 | |
---|
745 | fprintf( err, "\nflag status $%04x (global: $%04x)\n", |
---|
746 | shflags_shv, shglbflags_shv ); |
---|
747 | fprintf( err, "---------------------------------\n" ); |
---|
748 | if (shflags_shv & SHF_LOGCMD) fprintf( err, "PROTOCOL\n" ); |
---|
749 | if (shflags_shv & SHF_ECHO) fprintf( err, "ECHO\n" ); |
---|
750 | if (shflags_shv & SHF_CAPCNV) fprintf( err, "CAPCNV\n" ); |
---|
751 | if (shflags_shv & SHF_STEP) fprintf( err, "STEP\n" ); |
---|
752 | if (shflags_shv & SHF_VERIFY) fprintf( err, "VERIFY\n" ); |
---|
753 | if (shflags_shv & SHF_CMDERRSTOP) fprintf( err, "CMDERRSTOP\n" ); |
---|
754 | if (shflags_shv & SHF_SHERRSTOP) fprintf( err, "SHERRSTOP\n" ); |
---|
755 | if (shflags_shv & SHF_NOERRMSG) fprintf( err, "NOERRMSG\n" ); |
---|
756 | if (shflags_shv & SHF_CHATTY) fprintf( err, "CHATTY\n" ); |
---|
757 | if (shflags_shv & SHF_STARTUP) fprintf( err, "STARTUP\n" ); |
---|
758 | |
---|
759 | fprintf( err, "\n" ); |
---|
760 | ss_dump( err, -1 ); |
---|
761 | fprintf( err, "\n" ); |
---|
762 | ss_dump( err, SHC_SYMLOC ); |
---|
763 | fprintf( err, "\n" ); |
---|
764 | ss_dump( err, SHC_SYMGLB ); |
---|
765 | fprintf( err, "\n" ); |
---|
766 | |
---|
767 | fclose( err ); |
---|
768 | |
---|
769 | /* abort command procedure & return to interactive level */ |
---|
770 | locstat = SHE_NOERROR; |
---|
771 | while (ui_level() > 0) |
---|
772 | mn0_cmdreturn( &locstat ); |
---|
773 | |
---|
774 | } /* end of se_cmdabort */ |
---|
775 | |
---|
776 | |
---|
777 | |
---|
778 | /*------------------------------------------------------------------------*/ |
---|
779 | |
---|
780 | |
---|
781 | |
---|
782 | void se_check_qual( CHMAP ch, PARAM *par ) |
---|
783 | |
---|
784 | /* prints unchecked qualifiers |
---|
785 | * |
---|
786 | * parameters of routine |
---|
787 | * CHMAP ch; input; output channel(s) |
---|
788 | * PARAM *par; input; parameter block |
---|
789 | */ |
---|
790 | { |
---|
791 | /* executable code */ |
---|
792 | |
---|
793 | printf( "%c", (char)7 ); |
---|
794 | gc_write( ch, "*** unrecognized qualifier \"" ); |
---|
795 | gc_write( ch, cp_uncheckedqual(par) ); |
---|
796 | gc_write( ch, "\" ***\n" ); |
---|
797 | |
---|
798 | } /* end of se_check_qual */ |
---|
799 | |
---|
800 | |
---|
801 | |
---|
802 | /*------------------------------------------------------------------------*/ |
---|
803 | |
---|
804 | |
---|
805 | |
---|
806 | void se_do_step( char stepcmd, STATUS *status ) |
---|
807 | |
---|
808 | /* processes step command entered by user |
---|
809 | * |
---|
810 | * parameters of routine |
---|
811 | * char stepcmd; input; step command |
---|
812 | * STATUS *status; output; return status |
---|
813 | */ |
---|
814 | { |
---|
815 | /* local variables */ |
---|
816 | PARAM scmd; /* to call TT */ |
---|
817 | |
---|
818 | /* executable code */ |
---|
819 | |
---|
820 | switch (stepcmd) { |
---|
821 | case '@': |
---|
822 | cp_parse( "TT", &scmd, status ); |
---|
823 | if (Severe(status)) return; |
---|
824 | mn0_callproc( &scmd, status ); |
---|
825 | break; |
---|
826 | } /*endswitch*/ |
---|
827 | |
---|
828 | } /* end of se_do_step */ |
---|
829 | |
---|
830 | |
---|
831 | |
---|
832 | /*------------------------------------------------------------------------*/ |
---|
833 | |
---|
834 | |
---|
835 | |
---|
836 | void se_dsplymsg( wdw, status ) |
---|
837 | |
---|
838 | /* displays error message */ |
---|
839 | |
---|
840 | /* parameters of routine */ |
---|
841 | int wdw; /* window number */ |
---|
842 | int status; /* input; error number */ |
---|
843 | |
---|
844 | { |
---|
845 | /* local variables */ |
---|
846 | char msg[BC_LINELTH+1]; /* error message */ |
---|
847 | char str[BC_LONGSTRLTH+1]; |
---|
848 | |
---|
849 | /* executable code */ |
---|
850 | err_msg( status, msg ); |
---|
851 | printf( "%c", (char)7 ); |
---|
852 | if (wdw == 0) { |
---|
853 | sy_alert( msg ); |
---|
854 | } else { |
---|
855 | gc_write( wdw, msg ); |
---|
856 | gc_wrtch( wdw, '\n' ); |
---|
857 | } /*endif*/ |
---|
858 | |
---|
859 | err_getcontext( msg ); |
---|
860 | if (*msg != '\0') { |
---|
861 | if (wdw == 0) { |
---|
862 | sprintf( str, ">>> context: %s", msg ); |
---|
863 | sy_alert( str ); |
---|
864 | } else { |
---|
865 | gc_write( wdw, ">>> context: " ); |
---|
866 | gc_write( wdw, msg ); |
---|
867 | gc_wrtch( wdw, '\n' ); |
---|
868 | } /*endif*/ |
---|
869 | } /*endif*/ |
---|
870 | |
---|
871 | } /* end of se_dsplymsg */ |
---|
872 | |
---|
873 | |
---|
874 | |
---|
875 | /*------------------------------------------------------------------------*/ |
---|
876 | |
---|
877 | |
---|
878 | |
---|
879 | void se_readshpaths( char file[], BOOLEAN *ok ) |
---|
880 | |
---|
881 | /* reads SH paths from file |
---|
882 | * |
---|
883 | * parameters of routine |
---|
884 | * char file[]; input; name of input file |
---|
885 | * BOOLEAN *ok; output; file found and read |
---|
886 | */ |
---|
887 | { |
---|
888 | /* local variables */ |
---|
889 | FILE *pf; /* file pointer */ |
---|
890 | char line[BC_LINELTH+1]; /* current line */ |
---|
891 | char item[BC_LINELTH+1]; /* item name */ |
---|
892 | char dir[BC_LINELTH+1]; /* directory string */ |
---|
893 | |
---|
894 | /* executable code */ |
---|
895 | |
---|
896 | *ok = TRUE; |
---|
897 | pf = sy_fopen( file, "r" ); |
---|
898 | if (pf == NULL) { |
---|
899 | *ok = FALSE; |
---|
900 | return; |
---|
901 | } /*endif*/ |
---|
902 | while (fgets(line,BC_LINELTH,pf) != NULL) { |
---|
903 | if (*line != '!') { |
---|
904 | sscanf( line, "%s %s", item, dir ); |
---|
905 | if (strcmp(item,"SCRATCH:") == 0) { |
---|
906 | strcpy( shd_scratch, dir ); |
---|
907 | } else if (strcmp(item,"INPUTS:") == 0) { |
---|
908 | strcpy( shd_inputs, dir ); |
---|
909 | } else { |
---|
910 | printf( "*** undefined SH path: %s ***\n", item ); |
---|
911 | } /*endif*/ |
---|
912 | } /*endif*/ |
---|
913 | } /*endif*/ |
---|
914 | sy_fclose( pf ); |
---|
915 | |
---|
916 | } /* end of se_readshpaths */ |
---|
917 | |
---|
918 | |
---|
919 | |
---|
920 | /*------------------------------------------------------------------------*/ |
---|
921 | |
---|
922 | |
---|
923 | #ifdef BC_SUN |
---|
924 | |
---|
925 | |
---|
926 | void se_get_sh_environment( void ) |
---|
927 | |
---|
928 | /* reads environment variables and copies directories to shd_... variables |
---|
929 | * |
---|
930 | * no parameters |
---|
931 | */ |
---|
932 | { |
---|
933 | /* local variables */ |
---|
934 | char *eptr; /* pointer to translated value */ |
---|
935 | |
---|
936 | /* executable code */ |
---|
937 | |
---|
938 | eptr = (char *)getenv( "SH_SCRATCH" ); |
---|
939 | if (eptr != NULL) |
---|
940 | if (strlen(eptr) < BC_FILELTH) |
---|
941 | strcpy( shd_scratch, eptr ); |
---|
942 | eptr = (char *)getenv( "SH_INPUTS" ); |
---|
943 | if (eptr != NULL) |
---|
944 | if (strlen(eptr) < BC_FILELTH) |
---|
945 | strcpy( shd_inputs, eptr ); |
---|
946 | |
---|
947 | } /* end of se_get_sh_environment */ |
---|
948 | |
---|
949 | |
---|
950 | #endif |
---|
951 | |
---|
952 | |
---|
953 | |
---|
954 | /*------------------------------------------------------------------------*/ |
---|