source: SH_SHM/trunk/source/shmenux.c @ 398

Revision 398, 42.1 KB checked in by marcus, 12 years ago (diff)

r219 | walther | 2011-06-01 16:33:50 +0200 (Mi, 01 Jun 2011) | 7 lines

  • Introduced tweo qualifiers for the changed behaviour of RMS. Details see http://www.seismic-handler.org/portal/ticket/36. "SRS" simulates one alternative of the unpredictable result of the 2008 version. The other alternative is covered using no qualifier at all. "SAM" simulates the processing of versions before 2007.
  • Updated RMS help file.
Line 
1
2/* file SHMENUX.C
3 *      =========
4 *
5 * version 33, 26-Jul-2006
6 *
7 * menu routines for seismhandler
8 * K. Stammler, 30-JUL-1990
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 <math.h>
38#include "basecnst.h"
39#include BC_SYSBASE
40#ifdef BC_INC_STDLIB
41#include BC_INC_STDLIB
42#endif
43#include "shconst.h"
44#include "shvars.h"
45#include "cpusrdef.h"
46#include "glusrdef.h"
47#include "uiusrdef.h"
48#include "ssusrdef.h"
49#include BC_GCUSRDEF
50#include "ttusrdef.h"
51#include "tcusrdef.h"
52#include "infoidx.h"
53#include "fctxsl.h"
54#include "fctxdm.h"
55#include "fctxml.h"
56#include "fctxcr.h"
57#include "fctxmt.h"
58#include "fctxpm.h"
59#include "residual.h"
60#include "sherrors.h"
61#ifdef SH_SOCKET
62#include "port_io.h"
63#endif
64
65
66
67/*----------------------------------------------------------------------------*/
68
69
70
71void mnx_locate( PARAM *par, int *status )
72
73/* locates events using arrival times at array stations
74 *
75 * parameters of routine
76 * PARAM    *par;           input; name & parameters
77 * int      *status;        output; return status
78 *
79 * 1. param:  trace list
80 * 2. param:  azimuth variable
81 * 3. param:  slowness variable
82 * 4. param:  azimuth-error variable
83 * 5. param:  slowness-error variable
84 */
85{
86        /* local variables */
87        TRACE    *trc[SHC_ILISTLTH];       /* trace list */
88        REAL     shift[SHC_ILISTLTH];      /* shift time in sec */
89        REAL     x[SHC_ILISTLTH];          /* plane x-positions */
90        REAL     y[SHC_ILISTLTH];          /* plane y-positions */
91        STATLOC  lat[SHC_ILISTLTH];        /* surface latitude positions */
92        STATLOC  lon[SHC_ILISTLTH];        /* surface longitude positions */
93        int      arrcode[SHC_ILISTLTH];    /* array codes */
94        REAL     elev[SHC_ILISTLTH];       /* station elevations */
95        REAL     veloc[SHC_ILISTLTH];      /* average velocities */
96        int      listlth;                  /* list length */
97        BOOLEAN  same_array;               /* all traces from same array */
98        int      i;                        /* counter */
99        int      selmode;                  /* select mode */
100        char     station[BC_SHORTSTRLTH+1];/* current station name */
101        REAL     azimuth, azimerr;         /* azimuth & error */
102        REAL     slowness, slowerr;        /* slowness & error */
103        REAL     dt;                       /* sample distance */
104        char     str[BC_LINELTH+1];        /* scratch */
105        char     symbol[BC_SHORTSTRLTH+1]; /* symbol name */
106        int      inplev;                   /* input level */
107        REAL     default_vel;              /* default velocity */
108        GLT_STATINF *statinf;              /* pointer to station info */
109
110        /* executable code */
111
112        if  (cp_pnexc(par,5,status))  return;
113
114        selmode = (cp_qexist(par,"NOMARK")) ? MM_NOMARK : MM_TRCMARK;
115        if  (cp_qexist(par,"PARENT"))  {
116                inplev = -1;
117        } else if  (cp_qexist(par,"INTERACTIVE"))  {
118                inplev = shv_maininput;
119        } else {
120                inplev = ss_inplev();
121        } /*endif*/
122
123        if  (!sl_qualr(par,"VELOC",&default_vel,status))
124                default_vel = 0.0;
125
126        if  (cp_pentered(par,1,status))  {
127                ml_gettrcpar( par, 1, tc, "@@", trc, &listlth, status );
128                if  (*status != SHE_NOERROR)  return;
129                for  (i=0;i<listlth;i++)
130                        shift[i] = -db_getr( trc[i], ER_TORIG, NULL );
131        } else {   /* select time points by cursor */
132                if  (*status != SHE_NOERROR)  return;
133                ui_shift( inplev );
134                ml_crsrlst_time( selmode, trc, shift, &listlth, status );
135                ui_unshift();
136                for  (i=0;i<listlth;i++)
137                        shift[i] = -shift[i];
138        } /*endif*/
139
140        same_array = TRUE;
141        for  (i=0;i<listlth;i++)  {
142                db_gets( trc[i], ES_STATION, BC_SHORTSTRLTH, station, status );
143                if  (*status != SHE_NOERROR)  return;
144                /* gl_full_statloc( station, lat+i, lon+i, arrcode+i, x+i, y+i,
145                        0, NULL, status ); */
146                statinf = (GLT_STATINF *)db_getp( trc[i], EP_STAT, status );
147                if  (statinf == NULL)  {
148                        *status = BC_NOERROR;
149                        statinf = gl_store_station( station, TRUE, status );
150                        if  (Severe(status))  return;
151                        db_setp( trc[i], EP_STAT, statinf, status );
152                        if  (Severe(status))  return;
153                } /*endif*/
154                lat[i] = statinf->lat;
155                lon[i] = statinf->lon;
156                arrcode[i] = statinf->arr_id;
157                x[i] = statinf->xrel;
158                y[i] = statinf->yrel;
159                if  ((i > 0) && (arrcode[i] != *arrcode))  same_array = FALSE;
160                elev[i] = statinf->elevation;
161                veloc[i] = default_vel == 0.0 ? statinf->velocity : default_vel;
162        } /*endfor*/
163        if  (same_array)  {
164                if  (*arrcode == 0)  same_array = FALSE;
165                if  (cp_qexist(par,"NOARRAY"))  same_array = FALSE;
166        } /*endif*/
167
168        if  (!same_array)
169                mt_deg_to_km( listlth, lat, lon, x, y );
170
171        /* check delta-t if only three traces */
172        if  (listlth == 3)  {
173                dt = db_getr( trc[0], ER_DELTA, NULL );
174                if  ((db_getr(trc[1],ER_DELTA,NULL) != dt)  ||
175                        (db_getr(trc[2],ER_DELTA,NULL) != dt))  {
176                        *status = SHE_DIFFSAMP;
177                        return;
178                } /*endif*/
179        } /*endif*/
180
181        /* perform location */
182        mt_locate( listlth, shift, x, y, dt,
183                &azimuth, &azimerr, &slowness, &slowerr, status );
184        if  (Severe(status))  return;
185        azimuth -= 180.0;
186        if  (azimuth < 0.0)  azimuth += 360.0;
187
188        if  (cp_qexist(par,"ELEVATION"))  {
189                mt_elevation_correction( slowness, listlth, elev, veloc,
190                        shift, status );
191                if  (Severe(status))  return;
192                /* do it again */
193                mt_locate( listlth, shift, x, y, dt,
194                        &azimuth, &azimerr, &slowness, &slowerr, status );
195                if  (Severe(status))  return;
196                azimuth -= 180.0;
197                if  (azimuth < 0.0)  azimuth += 360.0;
198        } /*endif*/
199
200        /* store or display results */
201        if  (cp_pnum(par) <= 1)  {  /* no output variables -> display */
202                sprintf( str, "   azimuth : %+7.2f  +- %6.2f\n", azimuth, azimerr );
203                gc_write( tc, str );
204                sprintf( str, "   slowness: %5.2f    +- %5.2f\n", slowness, slowerr );
205                gc_write( tc, str );
206        } else {
207                if  (cp_pentered(par,2,status))  {
208                        cp_getstr( par, 2, tc, "@@", BC_LINELTH, symbol, status );
209                        if  (*status != SHE_NOERROR)  return;
210                        sprintf( str, "%e", azimuth );
211                        sl_setsymbol( symbol, str, status );
212                } /*endif*/
213                if  (cp_pentered(par,3,status))  {
214                        cp_getstr( par, 3, tc, "@@", BC_LINELTH, symbol, status );
215                        if  (*status != SHE_NOERROR)  return;
216                        sprintf( str, "%e", slowness );
217                        sl_setsymbol( symbol, str, status );
218                } /*endif*/
219                if  (cp_pentered(par,4,status))  {
220                        cp_getstr( par, 4, tc, "@@", BC_LINELTH, symbol, status );
221                        if  (*status != SHE_NOERROR)  return;
222                        sprintf( str, "%e", azimerr );
223                        sl_setsymbol( symbol, str, status );
224                } /*endif*/
225                if  (cp_pentered(par,5,status))  {
226                        cp_getstr( par, 5, tc, "@@", BC_LINELTH, symbol, status );
227                        if  (*status != SHE_NOERROR)  return;
228                        sprintf( str, "%e", slowerr );
229                        sl_setsymbol( symbol, str, status );
230                } /*endif*/
231        } /*endif*/
232
233} /* end of mnx_locate */
234
235
236
237/*----------------------------------------------------------------------------*/
238
239
240
241#define CLEAR_AND_RETURN \
242        sy_deallocmem( shift ); \
243        sy_deallocmem( lat ); \
244        sy_deallocmem( arrcode ); \
245        return;
246
247
248
249void mnx_beam( PARAM *par, STATUS *status )
250
251/* shift traces according to their station location and given azimuth
252 * and slowness
253 *
254 * parameters of routine
255 * PARAM    *par;           input; name & parameters
256 * STATUS   *status;        output; return status
257 *
258 * 1. param:  trace list
259 * 2. param:  azimuth
260 * 3. param:  slowness
261 */
262{
263        /* local variables */
264        TRACE    *trc[SHC_ILISTLTH];    /* trace list */
265        REAL     *shift;                /* shift time in sec */
266        REAL     *x;                    /* plane x-positions */
267        REAL     *y;                    /* plane y-positions */
268        STATLOC  *lat;                  /* surface latitude positions */
269        STATLOC  *lon;                  /* surface longitude positions */
270        REAL     *elev;                 /* station elevations */
271        REAL     *veloc;                /* average velocities */
272        REAL     *residcorr;            /* residual corrections */
273        int      *arrcode;              /* array codes */
274        int      listlth;               /* list length */
275        BOOLEAN  same_array;            /* all traces from same array */
276        int      i;                     /* counter */
277        char     station[BC_SHORTSTRLTH+1]; /* current station name */
278        REAL     azimuth;               /* azimuth */
279        REAL     slowness;              /* slowness */
280        REAL     minshift;              /* minimum shift time */
281        char     str[BC_LINELTH+1];     /* scratch string */
282        REAL     default_vel;           /* default velocity */
283        int      refidx;                /* reference index */
284        char     refstat[BC_SHORTSTRLTH+1]; /* reference station name */
285        GLT_STATINF  *statinf;          /* pointer to station info */
286        BOOLEAN  use_refstation;        /* reference station is specified */
287        char     residph[BC_SHORTSTRLTH+1]; /* residual phase */
288
289        /* executable code */
290
291        if  (cp_pnexc(par,3,status))  return;
292
293        ml_gettrcpar( par, 1, tc, "   beam traces: ", trc, &listlth, status );
294        if  (*status != SHE_NOERROR)  return;
295        cp_getfloat( par, 2, tc, "   azimuth: ", &azimuth, status );
296        if  (*status != SHE_NOERROR)  return;
297        cp_getfloat( par, 3, tc, "   slowness: ", &slowness, status );
298        if  (*status != SHE_NOERROR)  return;
299
300        if  (!sl_quals(par,"RESID",BC_SHORTSTRLTH,residph,status))
301                *residph = '\0';
302        if  (SySevere(status))  return;
303
304        /* allocate memory for station info, listlth is increased by 1: */
305        /*    index 'listlth' contains info about reference station   */
306        shift = (REAL *)sy_allocmem( (listlth+1)*6, (int)sizeof(REAL), status );
307        if  (Severe(status))  return;
308        lat = (STATLOC *)sy_allocmem( (listlth+1)*2, (int)sizeof(STATLOC), status );
309        if  (Severe(status))  {sy_deallocmem(shift); return;}
310        arrcode = (int *)sy_allocmem( listlth+1, (int)sizeof(int), status );
311        if  (Severe(status))  {sy_deallocmem(shift); sy_deallocmem(lat); return;}
312        x = shift + listlth+1;
313        y = x + listlth+1;
314        elev = y + listlth+1;
315        veloc = elev + listlth+1;
316        residcorr = elev + listlth+1;
317        lon = lat + listlth+1;
318
319        /* rescale input if sx,sy is given */
320        if  (cp_qexist(par,"CART"))  {
321                /* compute azimuth & slowness from cartesian input */
322                minshift = BC_PI/2.0 - atan2( azimuth, slowness );
323                slowness = sqrt( azimuth*azimuth + slowness*slowness );
324                azimuth = minshift;
325        } /*endif*/
326
327        if  (!sl_qualr(par,"VELOC",&default_vel,status))
328                default_vel = 0.0;
329        if  (SySevere(status))  {CLEAR_AND_RETURN}
330
331        /* get reference station, refidx is set to 'listlth' */
332        refidx = listlth;
333        use_refstation = FALSE;
334        if  (sl_quals(par,"REF",BC_SHORTSTRLTH,refstat,status))  {
335                if  (strcmp(refstat,"CENTRE") == 0 || strcmp(refstat,"CENTER") == 0)  {
336                        /* take center of array */
337                        *refstat = '\0';
338                } else {
339                        /* retrieve station info about reference station */
340                        statinf = gl_store_station( refstat, TRUE, status );
341                        if  (Severe(status))  {CLEAR_AND_RETURN}
342                        lat[refidx] = statinf->lat;
343                        lon[refidx] = statinf->lon;
344                        arrcode[refidx] = statinf->arr_id;
345                        x[refidx] = statinf->xrel;
346                        y[refidx] = statinf->yrel;
347                        use_refstation = TRUE;
348                } /*endif*/
349        } else {
350                /* take center of array */
351                *refstat = '\0';
352        } /*endif*/
353        if  (Severe(status))  {CLEAR_AND_RETURN}
354
355        /* retrieve station info of all traces and store it in the arrays */
356        same_array = TRUE;
357        for  (i=0;i<listlth;i++)  {
358                db_gets( trc[i], ES_STATION, BC_SHORTSTRLTH, station, status );
359                if  (refidx < 0)  /* reference station not yet found */
360                        if  (strcmp(station,refstat) == 0)
361                                refidx = i;
362                if  (Severe(status))  {CLEAR_AND_RETURN}
363                statinf = (GLT_STATINF *)db_getp( trc[i], EP_STAT, status );
364                if  (statinf == NULL)   {
365                        *status = BC_NOERROR;
366                        statinf = gl_store_station( station, TRUE, status );
367                        if  (Severe(status))  {CLEAR_AND_RETURN}
368                        db_setp( trc[i], EP_STAT, statinf, status );
369                        if  (Severe(status))  {CLEAR_AND_RETURN}
370                } /*endif*/
371                lat[i] = statinf->lat;
372                lon[i] = statinf->lon;
373                arrcode[i] = statinf->arr_id;
374                x[i] = statinf->xrel;
375                y[i] = statinf->yrel;
376                if  ((i > 0) && (arrcode[i] != *arrcode))  same_array = FALSE;
377                elev[i] = statinf->elevation;
378                veloc[i] = default_vel == 0.0 ? statinf->velocity : default_vel;
379                if  (*residph != '\0')  {
380                        residcorr[i] = RsResidual( station, residph, slowness, azimuth,
381                                status );
382                        if  (SySevere(status))  {CLEAR_AND_RETURN}
383                } /*endif*/
384        } /*endfor*/
385
386        /* check for use of absolute or relative locations */
387        if  (same_array && use_refstation && *arrcode != arrcode[refidx])
388                same_array = FALSE;
389        if  (same_array)  {
390                if  (*arrcode == 0)  same_array = FALSE;
391                if  (cp_qexist(par,"NOARRAY"))  same_array = FALSE;
392        } /*endif*/
393
394        /* relative locations from absolute if relative loc's are not already given*/
395        if  (!same_array)  {
396                if  (use_refstation)  {
397                        mt_deg_to_km( listlth+1, lat, lon, x, y );
398                } else {
399                        mt_deg_to_km( listlth, lat, lon, x, y );
400                } /*endif*/
401        } /*endif*/
402
403        /* for center reference find mean value position */
404        if  (!use_refstation)  {
405                x[refidx] = y[refidx] = 0.0;
406                for  (i=0; i<listlth; i++)  {
407                        x[refidx] += x[i];
408                        y[refidx] += y[i];
409                } /*endfor*/
410                x[refidx] /= (float)listlth;
411                y[refidx] /= (float)listlth;
412                elev[refidx] = 0.0;
413        } /*endif*/
414
415        /* dump out relative locations if requested */
416        if  (cp_qexist(par,"DUMPREL"))
417                for  (i=0; i<listlth; i++)
418                        printf( "%f %f\n", x[i]-x[refidx], y[i]-y[refidx] );
419
420        /* compute shift times from relative locations */
421        mt_beamshift( listlth+1, x, y, azimuth, slowness, shift );
422        if  (cp_qexist(par,"ELEVATION"))
423                mt_elevation_correction( slowness, listlth+1, elev, veloc,
424                        shift, status );
425        if  (Severe(status))  {CLEAR_AND_RETURN}
426        if  (*residph != '\0')
427                for  (i=0; i<listlth; i++)
428                        shift[i] -= residcorr[i];
429
430        /* reverse sign if requested */
431        if  (cp_qexist(par,"NEG"))
432                for  (i=0; i<=listlth; i++)
433                        shift[i] = -shift[i];
434
435        /* set reference delay */
436        minshift = shift[refidx];
437
438        /* now do the shift operation */
439        sprintf( str, "%e %e %e", x[refidx], y[refidx], (*shift)-minshift );
440        db_sets( trc[0], ES_OPINFO, str, status );
441        if  (Severe(status))  {CLEAR_AND_RETURN}
442        if  (cp_qexist(par,"ABS"))  {
443                for  (i=0;i<listlth;i++)  {
444                        db_setr( trc[i], ER_TORIG, shift[i]-minshift, status );
445                        if  (*status != SHE_NOERROR)  {CLEAR_AND_RETURN}
446                } /*endfor*/
447        } else {
448                for  (i=0;i<listlth;i++)  {
449                        db_setr( trc[i], ER_TORIG,
450                                db_getr(trc[i],ER_TORIG,NULL)+shift[i]-minshift, status );
451                        if  (*status != SHE_NOERROR)  {CLEAR_AND_RETURN}
452                } /*endfor*/
453        } /*endif*/
454
455        CLEAR_AND_RETURN
456
457} /* end of mnx_beam */
458
459
460
461#undef CLEAR_AND_RETURN
462
463
464
465/*----------------------------------------------------------------------------*/
466
467
468
469void mnx_shift( PARAM *par, int *status )
470
471/* shift traces
472 *
473 * parameters of routine
474 * PARAM    *par;           input; name & parameters
475 * int      *status;        output; return status
476 *
477 * 1. param:  trace list
478 * 2. param:  time (explicit shift)
479 */
480{
481        /* local variables */
482        TRACE    *trc[SHC_ILISTLTH];     /* trace list */
483        int      listlth;                /* list length */
484        int      i;                      /* counter */
485        REAL     orig, shift;            /* shift time(s) */
486        int      selmode;                /* selection mode */
487        char     shiftcmd[BC_LINELTH+1]; /* shift command */
488        REAL     cnvdepth;               /* conversion depth */
489        char     infstr[BC_LINELTH+1];   /* info entry string */
490        unsigned infent;                 /* info entry */
491        REAL     shiftoff;               /* shift offset */
492        int      diff_phase;             /* phase difference */
493        BOOLEAN  negative;               /* negative shift */
494        int      inplev;                 /* input level */
495
496        /* executable code */
497
498        if  (cp_pnexc(par,4,status))  return;
499        if  (cp_qexist(par,"PARENT"))  {
500                inplev = -1;
501        } else if  (cp_qexist(par,"INTERACTIVE"))  {
502                inplev = shv_maininput;
503        } else {
504                inplev = ss_inplev();
505        } /*endif*/
506
507        negative = cp_qexist( par, "NEG" );
508
509        if  (cp_pnum(par) == 0)  {   /* shift by graphic cursor */
510
511                selmode = (cp_qexist(par,"NOMARK")) ? MM_NOMARK : MM_TRCMARK;
512                ui_shift( inplev );
513                cr_gettrctime( selmode, trc, &orig, status );
514                ui_unshift();
515                if  (*status != SHE_NOERROR)  return;
516                ui_shift( inplev );
517                cr_gettrctime( selmode, trc+1, &shift, status );
518                ui_unshift();
519                if  (*status != SHE_NOERROR)  return;
520                db_setr( trc[0], ER_TORIG,
521                        db_getr(trc[0],ER_TORIG,NULL)+shift-orig, status );
522
523        } else {
524
525                ml_gettrcpar( par, 1, tc, "   traces: ", trc, &listlth, status );
526                if  (*status != SHE_NOERROR)  return;
527                cp_getstr( par, 2, tc, "   shift command: ", BC_LINELTH,
528                        shiftcmd, status );
529                if  (Severe(status))  return;
530
531                if  (strcmp(shiftcmd,"PS_DELAY") == 0)  {
532                        diff_phase = TTC_P_S_DIFF;
533                } else if  (strcmp(shiftcmd,"P_PPP_DELAY") == 0)  {
534                        diff_phase = TTC_P_Ppp_DIFF;
535                } else if  (strcmp(shiftcmd,"P_PPS_DELAY") == 0)  {
536                        diff_phase = TTC_P_Pps_DIFF;
537                } else {
538                        diff_phase = 0;
539                } /*endif*/
540
541                if  (diff_phase != 0)  {
542                        cp_getfloat( par, 3, tc, "   conv depth (km): ", &cnvdepth,
543                                status );
544                        if  (Severe(status))  return;
545                        cp_getstr( par, 4, tc, "   info entry: ", BC_LINELTH,
546                                infstr, status );
547                        if  (Severe(status))  return;
548                        db_ident( infstr, &infent, status );
549                        if  (Severe(status))  return;
550                        shiftoff = tt_mantle_diff( diff_phase, cnvdepth,
551                                6.4, status );
552                        for  (i=0;i<listlth;i++)  {
553                                shift = tt_mantle_diff( diff_phase, cnvdepth,
554                                        db_getr(trc[i],infent,status), status ) -
555                                        shiftoff;
556                                if  (Severe(status))  return;
557                                if  (negative)  shift = -shift;
558                                db_setr( trc[i], ER_TORIG,
559                                        db_getr(trc[i],ER_TORIG,NULL)-shift, status );
560                                if  (*status != SHE_NOERROR)  return;
561                        } /*endfor*/
562                } else {
563                        if  (strcmp(shiftcmd,"RED_TIME") == 0)  {
564                                cp_getfloat( par, 3, tc, "   velocity: ", &shift, status );
565                                if  (Severe(status))  return;
566                                ml_reduced_time( listlth, trc, shift, status );
567                                if  (Severe(status))  return;
568                        } else if  (strcmp(shiftcmd,"TIME_AL") == 0)  {
569                                if  (cp_pentered(par,3,status))  {
570                                        cp_getstr( par, 3, tc, "@@", BC_LINELTH,
571                                                infstr, status );
572                                } else {
573                                        *infstr = '\0';
574                                } /*endif*/
575                                if  (Severe(status))  return;
576                                ml_time_align( listlth, trc, infstr, status );
577                                if  (Severe(status))  return;
578                        } else if  (strcmp(shiftcmd,"SD_DELAY") == 0)  {
579                                cp_getfloat( par, 3, tc, "   slowness: ", &shiftoff, status );
580                                if  (Severe(status))  return;
581                                cp_getstr( par, 4, tc, "   distance entry: ", BC_LINELTH,
582                                        infstr, status );
583                                if  (Severe(status))  return;
584                                ml_sddelay( listlth, trc, shiftoff, infstr, status );
585                                if  (Severe(status))  return;
586                        } else {
587                                cp_getfloat( par, 2, tc, "   time (sec): ", &shift, status );
588                                if  (*status != SHE_NOERROR)  return;
589                                if  (negative)  shift = -shift;
590                                for  (i=0;i<listlth;i++)  {
591                                        db_setr( trc[i], ER_TORIG,
592                                                db_getr(trc[i],ER_TORIG,NULL)+shift, status );
593                                        if  (*status != SHE_NOERROR)  return;
594                                } /*endfor*/
595                        } /*endif*/
596                } /*endif*/
597
598        } /*endif*/
599
600} /* end of mnx_shift */
601
602
603
604/*-------------------------------------------------------------------------*/
605
606
607
608void mnx_al( PARAM *par, int *status )
609
610/* align traces
611 * 1. param:  trace list
612 * 2. param:  time info entry
613 * 3. param:  time position (default 0)
614 *
615 * parameters of routine
616 * PARAM    *par;           input; name & parameters
617 * int      *status;        output; return status
618 */
619{
620        /* local variables */
621        REAL     timpos;              /* time position of aligning */
622        void     *trc[SHC_ILISTLTH];  /* trace list */
623        REAL     shift[SHC_ILISTLTH]; /* shift time in sec */
624        int      listlth;             /* list length */
625        int      i;                   /* counter */
626        int      selmode;             /* select mode */
627        unsigned tentry;              /* time entry */
628        TIME     ttime, start;        /* info time & start time of trace */
629        char     infstr[BC_SHORTSTRLTH+1];  /* info entry string */
630        int      inplev;              /* input level, for mouse selections */
631
632        /* executable code */
633
634        if  (cp_pnexc(par,3,status))  return;
635
636        if  (cp_pentered(par,3,status))  {
637                cp_getfloat( par, 3, tc, "@@", &timpos, status );
638                if  (*status != SHE_NOERROR)  return;
639        } else {
640                timpos = 0.0;
641        } /*endif*/
642
643        /* get input level, for mouse selections only */
644   if  (cp_qexist(par,"PARENT"))  {
645      inplev = -1;
646   } else if  (cp_qexist(par,"INTERACTIVE"))  {
647      inplev = shv_maininput;
648   } else {
649      inplev = ss_inplev();
650   } /*endif*/
651
652        if  (cp_pentered(par,1,status))  {  /* time points from info entry */
653
654                /* get trace list from 1. parameter and time info from 2. par */
655                ml_gettrcpar( par, 1, tc, "@@", trc, &listlth, status );
656                if  (*status != SHE_NOERROR)  return;
657                cp_getstr( par, 2, tc, "   time info entry: ", BC_SHORTSTRLTH,
658                        infstr, status );
659                if  (*status != SHE_NOERROR)  return;
660
661                /* check info entry string */
662                db_ident( infstr, &tentry, status );
663                if  (*status != SHE_NOERROR)  return;
664                if  ((tentry & E_TYPMASK) != ET_TYPE)  {
665                        *status = SHE_ILTYPE;
666                        return;
667                } /*endif*/
668
669                /* get time offsets from info entry */
670                if  (tentry == ET_START)  {
671                        for  (i=0;i<listlth;i++)  {
672                                db_setr( trc[i], ER_TORIG, timpos, status );
673                                if  (*status != SHE_NOERROR)  return;
674                        } /*endfor*/
675                } else {
676                        for  (i=0;i<listlth;i++)  {
677                                db_gett( trc[i], tentry, &ttime, status );
678                                if  (*status != SHE_NOERROR)  return;
679                                db_gett( trc[i], ET_START, &start, status );
680                                if  (*status != SHE_NOERROR)  return;
681                                db_setr( trc[i], ER_TORIG,
682                                        timpos+tc_adiff(&start,&ttime), status );
683                                if  (*status != SHE_NOERROR)  return;
684                        } /*endfor*/
685                } /*endif*/
686
687        } else {   /* trace & delay selection by graphic cursor */
688
689                /* select traces and time points by graphic cursor */
690                selmode = (cp_qexist(par,"NOMARK")) ? MM_NOMARK : MM_TRCMARK;
691                ui_shift( inplev );
692                ml_crsrlst_time( selmode, trc, shift, &listlth, status );
693                ui_unshift();
694                if  (*status != SHE_NOERROR)  return;
695
696                /* shift traces */
697                for  (i=0;i<listlth;i++)  {
698                        db_setr( trc[i], ER_TORIG,
699                                timpos+db_getr(trc[i],ER_TORIG,NULL)-shift[i], status );
700                        if  (*status != SHE_NOERROR)  return;
701                } /*endfor*/
702       
703        } /*endif*/
704
705} /* end of mnx_al */
706
707
708
709/*-------------------------------------------------------------------------*/
710
711
712
713void mnx_syw( PARAM *par, int *status )
714
715/* sets y-window in display
716 *
717 * parameters of routine
718 * PARAM    *par;           input; name & parameters
719 * int      *status;        output; return status
720 */
721{
722        /* local variables */
723        float      lo_y, hi_y;      /* y-window */
724
725        /* executable code */
726
727        if  (cp_pnum(par) == 0)  {
728                cr_ywindow( MM_PTMARK, &lo_y, &hi_y, status );
729                if  (*status != SHE_NOERROR)  return;
730        } else {
731                if  (cp_pnexc(par,2,status))  return;
732                cp_getfloat( par, 1, tc, "   lower bound: ", &lo_y, status );
733                if  (*status != SHE_NOERROR)  return;
734                cp_getfloat( par, 2, tc, "   upper bound: ", &hi_y, status );
735                if  (*status != SHE_NOERROR)  return;
736        } /*endif*/
737        dm_ywdw( lo_y, hi_y, status );
738
739} /* end of mnx_syw */
740
741
742
743/*-------------------------------------------------------------------------*/
744
745
746
747void mnx_styw( PARAM *par, int *status )
748
749/* sets time & y-window in display
750 *
751 * parameters of routine
752 * PARAM    *par;           input; name & parameters
753 * int      *status;        output; return status
754 */
755{
756        /* local variables */
757        float      lo_y, hi_y;      /* y-window */
758        float      lo_t, hi_t;      /* time window */
759
760        /* executable code */
761
762        if  (cp_pnum(par) == 0)  {
763                cr_tywindow( MM_PTMARK, &lo_t, &hi_t, &lo_y, &hi_y, status );
764                if  (*status != SHE_NOERROR)  return;
765        } else {
766                if  (cp_pnexc(par,4,status))  return;
767                cp_getfloat( par, 1, tc, "   lower t-bound: ", &lo_t, status );
768                if  (*status != SHE_NOERROR)  return;
769                cp_getfloat( par, 2, tc, "   upper t-bound: ", &hi_t, status );
770                if  (*status != SHE_NOERROR)  return;
771                cp_getfloat( par, 3, tc, "   lower y-bound: ", &lo_y, status );
772                if  (*status != SHE_NOERROR)  return;
773                cp_getfloat( par, 4, tc, "   upper y-bound: ", &hi_y, status );
774                if  (*status != SHE_NOERROR)  return;
775        } /*endif*/
776        dm_timewdw( lo_t, hi_t, status );
777        dm_ywdw( lo_y, hi_y, status );
778
779} /* end of mnx_styw */
780
781
782
783/*----------------------------------------------------------------------------*/
784
785
786
787void mnx_yinfo( PARAM *par, STATUS *status )
788
789/* sets y-info entry in display
790 * 1. param:   info entry name
791 *
792 * parameters of routine
793 * PARAM    *par;           input; name & parameters
794 * STATUS   *status;        output; return status
795 */
796{
797        /* local variables */
798        unsigned ientry;               /* info entry */
799        char     infstr[BC_LINELTH+1]; /* info entry name */
800
801        /* executable code */
802
803        if  (cp_pnexc(par,1,status))  return;
804        cp_getstr( par, 1, tc, "   info entry or NONE: ", BC_LINELTH,
805                infstr, status );
806        if  (Severe(status))  return;
807        if  (strcmp(infstr,"NONE") == 0)  {
808                ientry = E_NONE;
809        } else {
810                db_ident( infstr, &ientry, status );
811                if  (Severe(status))  return;
812        } /*endif*/
813        dm_setyentry( ientry, status );
814
815} /* end of yinfo */
816
817
818
819/*----------------------------------------------------------------------------*/
820
821
822
823void mnx_am( PARAM *par, int *status )
824
825/* determine amplitudes
826 * 1. param:  trace
827 *
828 * parameters of routine
829 * PARAM    *par;           input; name & parameters
830 * int      *status;        output; return status
831 */
832{
833        /* local variables */
834        TRACE    *trc;                 /* trace pointer */
835        REAL     lo_time, hi_time;     /* time window */
836        int      selmode;              /* selection mode */
837        REAL     r;
838        long     start, lth;           /* trace window */
839        long     minpos, maxpos;       /* positions of min & max */
840        SAMPLE   min, max;             /* minimum & maximum */
841        char     str[BC_LINELTH+1];    /* scratch string */
842        char     symbol[BC_LINELTH+1]; /* symbol name */
843        REAL     dt;                   /* sample distance */
844        int      inplev;               /* input level, for cursor selections */
845
846        /* executable code */
847
848        if  (cp_pnexc(par,7,status))  return;
849        selmode = (cp_qexist(par,"NOMARK")) ? MM_NOMARK : MM_TRCMARK;
850
851        /* get input level, for mouse selections only */
852   if  (cp_qexist(par,"PARENT"))  {
853      inplev = -1;
854   } else if  (cp_qexist(par,"INTERACTIVE"))  {
855      inplev = shv_maininput;
856   } else {
857      inplev = ss_inplev();
858   } /*endif*/
859
860        if  (cp_pnum(par) == 0)  {
861                ui_shift( inplev );
862                cr_gettrctime( selmode, &trc, &lo_time, status );
863                if  (Severe(status))  {ui_unshift(); return;}
864                cr_getloc( selmode, &hi_time, NULL, NULL, status );
865                if  (Severe(status))  return;
866                ui_unshift();
867        } else {
868                trc = ml_get1trcpar( par, 1, tc, "@@", status );
869                if  (Severe(status))  return;
870                if  (cp_pnum(par) > 1)  {
871                        cp_getfloat( par, 2, tc, "   lo-bound: ", &lo_time, status );
872                        if  (Severe(status))  return;
873                        cp_getfloat( par, 3, tc, "   hi-bound: ", &hi_time, status );
874                        if  (Severe(status))  return;
875                } else {
876                        cr_window( selmode, &lo_time, &hi_time, status );
877                        if  (Severe(status))  return;
878                } /*endif*/
879        } /*endif*/
880        if  (hi_time < lo_time)  {
881                r = hi_time;
882                hi_time = lo_time;
883                lo_time = r;
884        } /*endif*/
885        start = dm_getsample( trc, lo_time, TRUE );
886        lth = dm_getsample( trc, hi_time, TRUE ) - start + 1;
887
888        sl_findmaxpos( (SAMPLE *)db_getp(trc,EP_DATA,NULL)+start, lth,
889                &min, &max, &minpos, &maxpos );
890
891        if  (cp_qexist(par,"ABS"))  {
892                min = Abs( min );
893                max = Abs( max );
894                if  (min > max)  max = min;
895                min = max;
896        } /*endif*/
897
898        if  (cp_pnum(par) <= 3)  {
899                sprintf( str, "   min: %e    max: %e\n", min, max );
900                gc_write( cc, str );
901        } else {
902                dt = db_getr( trc, ER_DELTA, NULL );
903                if  (cp_pentered(par,4,status))  {
904                        cp_getstr( par, 4, tc, "@@", BC_LINELTH, symbol, status );
905                        if  (Severe(status))  return;
906                        sprintf( str, "%e", min );
907                        sl_setsymbol( symbol, str, status );
908                        if  (Severe(status))  return;
909                } /*endif*/
910                if  (cp_pentered(par,5,status))  {
911                        cp_getstr( par, 5, tc, "@@", BC_LINELTH, symbol, status );
912                        if  (Severe(status))  return;
913                        sprintf( str, "%e", max );
914                        sl_setsymbol( symbol, str, status );
915                        if  (Severe(status))  return;
916                } /*endif*/
917                if  (cp_pentered(par,6,status))  {
918                        cp_getstr( par, 6, tc, "@@", BC_LINELTH, symbol, status );
919                        if  (Severe(status))  return;
920                        sprintf( str, "%e", db_getr(trc,ER_TORIG,NULL) +
921                                start*dt + (REAL)minpos*dt );
922                        sl_setsymbol( symbol, str, status );
923                        if  (Severe(status))  return;
924                } /*endif*/
925                if  (cp_pentered(par,7,status))  {
926                        cp_getstr( par, 7, tc, "@@", BC_LINELTH, symbol, status );
927                        if  (Severe(status))  return;
928                        sprintf( str, "%e", db_getr(trc,ER_TORIG,NULL) +
929                                start*dt + (REAL)maxpos*dt );
930                        sl_setsymbol( symbol, str, status );
931                        if  (Severe(status))  return;
932                } /*endif*/
933        } /*endif*/
934
935} /* end of mnx_am */
936
937
938
939/*----------------------------------------------------------------------------*/
940
941
942
943void mnx_resample( PARAM *par, int *status )
944
945/* resamples traces
946 * 1. param:  trace list
947 * 2. param:  new sample distance (in sec)
948 *
949 * parameters of routine
950 * PARAM    *par;           input; name & parameters
951 * int      *status;        output; return status
952 */
953{
954        /* local variables */
955        TRACE    *trc[SHC_ILISTLTH];  /* trace pointer */
956        int      listlth;             /* length of trace list */
957        REAL     new_dt;              /* new sample distance in sec */
958        int      i;                   /* counter */
959        REAL     min, max;            /* new minimum and maximum */
960
961        /* executable code */
962
963        if  (cp_pnexc(par,2,status))  return;
964
965        ml_gettrcpar( par, 1, tc, "   trace list: ", trc, &listlth, status );
966        if  (Severe(status))  return;
967        cp_getfloat( par, 2, tc, "   new sample distance (sec): ",
968                &new_dt, status );
969        if  (Severe(status))  return;
970        if  (new_dt <= 0.0)  {
971                *status = SHE_ILPAR;
972                return;
973        } /*endif*/
974
975        for  (i=0; i<listlth; i++ )  {
976                ml_resample( trc[i], new_dt, status );
977                if  (Severe(status)) return;
978                sl_findmax( db_getp(trc[i],EP_DATA,NULL),
979                        db_getl(trc[i],EL_LENGTH,NULL), &min, &max );
980                db_setr( trc[i], ER_MINVAL, min, status );
981                if  (Severe(status))  return;
982                db_setr( trc[i], ER_MAXVAL, max, status );
983                if  (Severe(status))  return;
984        } /*endfor*/
985
986} /* end of mnx_resample */
987
988
989
990/*----------------------------------------------------------------------------*/
991
992
993
994void mnx_title( PARAM *par, STATUS *status )
995
996/* sets new title
997 * 1. param:  title line
998 * 2. param:  text of title
999 *
1000 * parameters of routine
1001 * PARAM    *par;           input; name & parameters
1002 * STATUS   *status;        output; return status
1003 */
1004{
1005        /* local variables */
1006        int      lineno;             /* line number */
1007        char     text[BC_LINELTH+1]; /* new text of title */
1008        float    x, y;               /* title position */
1009        int      wdw;                /* window number */
1010
1011        /* executable code */
1012
1013        if  (cp_pnexc(par,4,status))  return;
1014        cp_getint( par, 1, tc, "   title line: ", &lineno, status );
1015        if  (Severe(status))  return;
1016        cp_getstr( par, 2, tc, "   title text: ", BC_LINELTH, text, status );
1017        if  (Severe(status))  return;
1018
1019        if  (!sl_quali(par,"WDW",&wdw,status))
1020                wdw = gc;
1021        if  (Severe(status))  return;
1022
1023        dm_settitle( wdw, --lineno, text, status );
1024        if  (Severe(status))  return;
1025
1026        if  (cp_pentered(par,3,status))  {
1027                cp_getfloat( par, 3, tc, "@@", &x, status );
1028                if  (Severe(status))  return;
1029                cp_getfloat( par, 4, tc, "   y-pos: ", &y, status );
1030                if  (Severe(status))  return;
1031                dm_settitlepos( wdw, lineno, x, y, status );
1032        } /*endif*/
1033
1034} /* end of mnx_title */
1035
1036
1037
1038/*----------------------------------------------------------------------------*/
1039
1040
1041
1042void mnx_hc( PARAM *par, STATUS *status )
1043
1044/* makes hardcopy of window
1045 * 1. param:  channel map of destination channel
1046 * 2. param:  channel map of source channel
1047 *
1048 * parameters of routine
1049 * PARAM    *par;           input; name & parameters
1050 * STATUS   *status;        output; return status
1051 */
1052{
1053        /* local variables */
1054        char     mapstr[BC_LINELTH+1];    /* map string */
1055        CHMAP    src, dst;                /* channel (bit)map */
1056        static CHMAP default_out=0;       /* default output channel */
1057        char     outfile[BC_FILELTH+1];   /* name of output file */
1058        char     symbol[BC_LINELTH+1];    /* symbol name */
1059
1060        /* executable code */
1061
1062        if  (cp_pnexc(par,3,status))  return;
1063
1064        if  (sl_quals(par,"DEFAULT",BC_LINELTH,mapstr,status))  {
1065                sl_cnvgcflags( mapstr, &default_out, status );
1066                return;
1067        } /*endif*/
1068        if  (Severe(status))  return;
1069
1070        if  (cp_pentered(par,1,status))  {
1071                cp_getstr( par, 1, tc, "   source channel: ", BC_LINELTH,
1072                        mapstr, status );
1073                if  (Severe(status))  return;
1074                sl_cnvgcflags( mapstr, &src, status );
1075                if  (Severe(status))  return;
1076        } else {
1077                src = gc;
1078        } /*endif*/
1079        if  (cp_pentered(par,2,status))  {
1080                cp_getstr( par, 2, tc, "   dest channel(s): ", BC_LINELTH,
1081                        mapstr, status );
1082                if  (Severe(status))  return;
1083                sl_cnvgcflags( mapstr, &dst, status );
1084                if  (Severe(status))  return;
1085        } else {
1086                dst = default_out;
1087        } /*endif*/
1088
1089        if  (src == 0)  {
1090                gc_closeplot( dst, outfile, status );
1091        } else {
1092                gc_playback( src, dst, outfile, status );
1093        } /*endif*/
1094
1095        if  (cp_pentered(par,3,status))  {
1096                cp_getstr( par, 3, tc, "   file symbol: ", BC_LINELTH,
1097                        symbol, status );
1098                if  (Severe(status))  return;
1099                sl_setsymbol( symbol, outfile, status );
1100        } /*endif*/
1101
1102#ifdef SH_SOCKET
1103        if  (ui_lastsocket() > 0)
1104                pio_send_file_to_socket( outfile, ui_lastsocket(), status );
1105#endif
1106
1107} /* end of mnx_hc */
1108
1109
1110
1111/*----------------------------------------------------------------------------*/
1112
1113
1114
1115void mnx_pmch( PARAM *par, STATUS *status )
1116
1117/* selects window for particle motion diagrams
1118 * 1. param:  window number (channel map)
1119 *
1120 * parameters of routine
1121 * PARAM    *par;           input; name & parameters
1122 * STATUS   *status;        output; return status
1123 */
1124{
1125        /* local variables */
1126        char     mapstr[BC_LINELTH+1];    /* map string */
1127        int      map;                     /* channel (bit)map */
1128
1129        /* executable code */
1130
1131        if  (cp_pnexc(par,1,status))  return;
1132
1133        if  (cp_pentered(par,1,status))  {
1134                cp_getstr( par, 1, tc, "   window: ", BC_LINELTH,
1135                        mapstr, status );
1136                if  (Severe(status))  return;
1137                sl_cnvgcflags( mapstr, &map, status );
1138                if  (Severe(status))  return;
1139        } else {
1140                map = 0;
1141        } /*endif*/
1142        pm_setoutput( map );
1143
1144} /* end of mnx_pmch */
1145
1146
1147
1148/*----------------------------------------------------------------------------*/
1149
1150
1151
1152void mnx_pm( PARAM *par, STATUS *status )
1153
1154/* draws particle motion diagrams
1155 * 1. param: trace list
1156 * 2. param: lo bound of time window [FIXED]
1157 * 3. param: hi bound of time window [FIXED]
1158 *
1159 * parameters of routine
1160 * PARAM    *par;           input; name & parameters
1161 * STATUS   *status;        output; return status
1162 */
1163{
1164        /* local variables */
1165        TRACE    *trc[SHC_ILISTLTH];       /* trace list */
1166        int      listlth;                  /* length of list */
1167        REAL     lowdw, hiwdw;             /* time window */
1168        REAL     loy, hiy;                 /* y range */
1169        REAL     dt;                       /* sample distance */
1170        REAL     origtime;                 /* origin time */
1171        int      t;                        /* trace counter */
1172        SAMPLE   *xstart[PMC_MAXPM];       /* x coo start samples */
1173        SAMPLE   *ystart[PMC_MAXPM];       /* y coo start samples */
1174        long     lth;                      /* length of pm in samples */
1175        float    tzoom[PMC_MAXPM];         /* trace zoom factors */
1176        float    zoom;                     /* general zoom */
1177        int      mode;                     /* 0=fixed, 1=varwdw, 2=movewdw */
1178        char     inftxt[PMC_MAXPM][BC_SHORTSTRLTH+1];   /* info texts */
1179        char     *inftxtptr[PMC_MAXPM];    /* pointer to info texts */
1180        char     cmp[2];                   /* component */
1181        STATUS   locstat;                  /* local status */
1182        int      inplev;                   /* input level */
1183        REAL     begcirc;                  /* radius of start circle */
1184
1185        /* executable code */
1186
1187        mode = 0;
1188        if  (cp_qexist(par,"VWDW"))  mode = 1;
1189        if  (cp_qexist(par,"MWDW"))  mode = 2;
1190
1191        if  (cp_qexist(par,"PARENT"))  {
1192                inplev = -1;
1193        } else if  (cp_qexist(par,"INTERACTIVE"))  {
1194                inplev = shv_maininput;
1195        } else {
1196                inplev = ss_inplev();
1197        } /*endif*/
1198
1199        if  (!sl_qualr(par,"CIRCLE",&begcirc,status))
1200                begcirc = 0.;
1201        if  (Severe(status))  return;
1202
1203        if  (cp_pnexc(par,3,status))  return;
1204        ml_gettrcpar( par, 1, tc, "   trace list: ", trc, &listlth, status );
1205        if  (Severe(status))  return;
1206        if  (mode == 0)  {
1207                cp_getfloat( par, 2, tc, " lo-wdw: ", &lowdw, status );
1208                if  (Severe(status))  return;
1209                cp_getfloat( par, 3, tc, " hi-wdw: ", &hiwdw, status );
1210                if  (Severe(status))  return;
1211        } else if  (mode == 2)  {
1212                cp_getfloat( par, 2, tc, " width: ", &origtime, status );
1213                if  (Severe(status))  return;
1214        } /*endif*/
1215
1216        if  (!sl_qualr(par,"ZOOM",&zoom,status))
1217                zoom = 1.0;
1218
1219        /* set info texts */
1220        cmp[1] = '\0';
1221        for  (t=0; t<(listlth/2); t++)  {
1222                inftxt[t][0] = '\0';
1223                inftxtptr[t] = inftxt[t];
1224                db_gets( trc[t*2], ES_STATION, BC_SHORTSTRLTH-4, inftxt[t], status );
1225                if  (*status == SHE_NOINFO)  *status = SHE_NOERROR;
1226                if  (Severe(status))  return;
1227                strcat( inftxt[t], " " );
1228                locstat = SHE_NOERROR;
1229                *cmp = db_getc( trc[t*2], EC_COMP, &locstat );
1230                if  (locstat == SHE_NOERROR)  strcat( inftxt[t], cmp );
1231                strcat( inftxt[t], "-" );
1232                *cmp = db_getc( trc[t*2+1], EC_COMP, &locstat );
1233                if  (locstat == SHE_NOERROR)  strcat( inftxt[t], cmp );
1234        } /*endfor*/
1235
1236        if  (listlth & 1)  {
1237                *status = SHE_SPECERROR+8;
1238                return;
1239        } else if  (listlth > (2*PMC_MAXPM))  {
1240                *status = SHE_SPECERROR+9;
1241                return;
1242        } /*endif*/
1243
1244        if  (mode == 0)  {
1245                dt = 0.0;
1246                for  (t=0; t<listlth; t++)  {
1247                        if  (dt == 0.0)
1248                                dt = db_getr( trc[t], ER_DELTA, NULL );
1249                        if  (dt != db_getr(trc[t],ER_DELTA,NULL))  {
1250                                *status = SHE_DIFFSAMP;
1251                                return;
1252                        } /*endif*/
1253                        if  (t & 1)  {
1254                                ystart[t/2] = (SAMPLE *)db_getp( trc[t], EP_DATA, NULL ) +
1255                                        dm_sgetsample( trc[t], lowdw, status );
1256                        } else {
1257                                xstart[t/2] = (SAMPLE *)db_getp( trc[t], EP_DATA, NULL ) +
1258                                        dm_sgetsample( trc[t], lowdw, status );
1259                                tzoom[t/2] = db_getr(trc[t],ER_ZOOM,NULL)*zoom;
1260                        } /*endif*/
1261                        if  (Severe(status))  return;
1262                        if  (t == 0)
1263                                lth = (SAMPLE *)db_getp( trc[t], EP_DATA, NULL ) +
1264                                        dm_sgetsample( trc[t], hiwdw, status ) - xstart[0];
1265                        if  (Severe(status))  return;
1266                } /*endfor*/
1267                ui_shift( inplev );
1268                pm_fixedwdw( gc, xstart, ystart, listlth/2, lth, inftxtptr,
1269                        tzoom, begcirc, status );
1270                ui_unshift();
1271        } else {
1272                if  (mode == 1)  {
1273                        ui_shift( inplev );
1274                        cr_getloc( MM_NOMARK, &origtime, NULL, NULL, status );
1275                        ui_unshift();
1276                        if  (Severe(status))  {
1277                                if  (*status == SHE_EXIT)  *status = SHE_NOERROR;
1278                                return;
1279                        } /*endif*/
1280                        for  (t=0; t<listlth; t++)
1281                                cr_trcmark( trc[t], origtime, 1.0 );
1282                } /*endif*/
1283                dm_dspcoo( &lowdw, &loy, &hiwdw, &hiy );
1284                hiwdw += lowdw;
1285                hiy += loy;
1286                dt = 0.0;
1287                for  (t=0; t<listlth; t++)  {
1288                        if  (dt == 0.0)
1289                                dt = db_getr( trc[t], ER_DELTA, NULL );
1290                        if  (dt != db_getr(trc[t],ER_DELTA,NULL))  {
1291                                *status = SHE_DIFFSAMP;
1292                                return;
1293                        } /*endif*/
1294                        if  (t & 1)  {
1295                                ystart[t/2] = (SAMPLE *)db_getp( trc[t], EP_DATA, NULL ) +
1296                                        dm_sgetsample( trc[t], lowdw, status );
1297                        } else {
1298                                xstart[t/2] = (SAMPLE *)db_getp( trc[t], EP_DATA, NULL ) +
1299                                        dm_sgetsample( trc[t], lowdw, status );
1300                                tzoom[t/2] = db_getr(trc[t],ER_ZOOM,NULL)*zoom;
1301                        } /*endif*/
1302                        if  (Severe(status))  return;
1303                        dm_sgetsample( trc[t], hiwdw, status );
1304                        while  (Severe(status))  {
1305                                if  (hiwdw <= lowdw)  return;
1306                                *status = SHE_NOERROR;
1307                                hiwdw -= dt;
1308                                dm_sgetsample( trc[t], hiwdw, status );
1309                        } /*endwhile*/
1310                } /*endfor*/
1311                ui_shift( inplev );
1312                if  (mode == 1)  {
1313                        pm_varwdw( gc, xstart, ystart, listlth/2, lowdw, hiwdw, origtime,
1314                                dt, inftxtptr, tzoom, loy, hiy, begcirc, status );
1315                } else {
1316                        pm_movewdw( gc, xstart, ystart, listlth/2, lowdw, hiwdw, origtime,
1317                                dt, inftxtptr, tzoom, loy, hiy, begcirc, status );
1318                } /*endif*/
1319                ui_unshift();
1320        } /*endif*/
1321
1322} /* end of mnx_pm */
1323
1324
1325
1326/*----------------------------------------------------------------------------*/
1327
1328
1329
1330void mnx_rms( PARAM *par, STATUS *status )
1331
1332/* Computes RMS of samples of trace
1333 * 1. param: trace
1334 * 2. param: lo bound of time window [FIXED]
1335 * 3. param: hi bound of time window [FIXED]
1336 *
1337 * parameters of routine
1338 * PARAM    *par;           input; name & parameters
1339 * STATUS   *status;        output; return status
1340 */
1341{
1342        /* local variables */
1343        TRACE    *trc;                   /* trace pointer */
1344        REAL     lowdw, hiwdw;           /* time wdw in sec */
1345        long     loidx, hiidx;           /* time wdw in samples */
1346        long     i;                      /* sample counter */
1347        SAMPLE   rms;                    /* sum of samples */
1348        SAMPLE   *dat;                   /* data pointer */
1349        char     symbol[BC_LINELTH+1];   /* symbol name */
1350        char     str[BC_LINELTH+1];      /* scratch string */
1351        int      mode;                   /* mode of operation */
1352
1353        /* executable code */
1354
1355        /* Compute rms. For more information about rms trouble please see
1356         * http://list.seismic-handler.org/pipermail/users/2011-May/000092.html
1357         * http://www.seismic-handler.org/portal/ticket/36
1358         * http://www.seismic-handler.org/portal/changeset/373
1359         */
1360        mode = 0;
1361
1362        /* Compute square root sum of the trace. This computation is one of the
1363         * unpredictable possibilities in versions prior to revision 373.
1364         */
1365        if  (cp_qexist(par,"SRS"))
1366            mode = 1;
1367
1368        /* Compute "squared arithmetic mean" of the trace. This was done in
1369         * older versions before version control was introduced.
1370         */
1371        if  (cp_qexist(par,"SAM"))
1372            mode = 2;
1373
1374        if  (cp_pnexc(par,4,status))  return;
1375        trc = ml_get1trcpar( par, 1, tc, "   trace number: ", status );
1376        if  (Severe(status))  return;
1377
1378        if  (cp_pentered(par,2,status))  {
1379                ml_windowpars( par, 2, tc, "   lower bound: ", "   upper bound: ",
1380                        &lowdw, &hiwdw, status );
1381                if  (Severe(status))  return;
1382                loidx = dm_getsample( trc, lowdw, TRUE );
1383                hiidx = dm_getsample( trc, hiwdw, TRUE );
1384        } else {
1385                loidx = 0;
1386                hiidx = db_getl( trc, EL_LENGTH, NULL ) - 1;
1387        } /*endif*/
1388
1389        if  (loidx > hiidx)  {
1390                *status = SHE_ZWDW;
1391                return;
1392        } /*endif*/
1393
1394        dat = (SAMPLE *)db_getp( trc, EP_DATA, status );
1395        if  (Severe(status))  return;
1396        rms = 0.0;
1397        for  (i=loidx; i<=hiidx; i++)
1398                rms += dat[i]*dat[i];
1399
1400        if (mode == 0)
1401            rms = sqrt(rms / (SAMPLE)(hiidx-loidx+1) );
1402        else if (mode == 2)
1403            rms = sqrt(rms) / (SAMPLE)(hiidx-loidx+1);
1404
1405        if  (cp_pentered(par,4,status))  {
1406                cp_getstr( par, 4, tc, "@@", BC_LINELTH, symbol, status );
1407                if  (Severe(status))  return;
1408                sprintf( str, "%e", rms );
1409                sl_setsymbol( symbol, str, status );
1410                if  (Severe(status))  return;
1411        } else {
1412                sprintf( str, "   rms: %e\n", rms );
1413                gc_write( cc, str );
1414        } /*endif*/
1415
1416} /* end of mnx_rms */
1417
1418
1419
1420/*----------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.