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