source: SH_SHM/branches/2011.2/source/img/mapslow.c @ 364

Revision 16, 47.3 KB checked in by marcus, 15 years ago (diff)

r1 | svn | 2007-12-13 11:10:29 +0100 (Do, 13 Dez 2007) | 2 lines

Initial import

Line 
1
2/* file mapslow.c
3 *      =========
4 *
5 * version 10, 15-Oct-2005
6 *
7 * maps slowness values
8 * K. Stammler, 9-Sep-2002
9 */
10
11
12
13#include <stdio.h>
14#include <math.h>
15#include "basecnst.h"
16#include <Xm/Xm.h>
17#include <Mrm/MrmPublic.h>
18#include <X11/cursorfont.h>
19#undef BC_DEFINE_TRUE_FALSE
20#ifdef BC_INC_STDLIB
21#include BC_INC_STDLIB
22#endif
23#include "sysbase.h"
24#include "cpar.h"
25#include "../motif/pixmaps.h"
26#include "ptusrdef.h"
27#include "tcusrdef.h"
28
29
30#define COL_BLUE
31
32
33#define w_toplevel 0
34#define w_main 1
35#define w_draw 2
36#define w_menu_main 5
37#define w_entry_quit 51
38#define w_entry_plot 52
39#define w_entry_show_1 53
40#define w_entry_show_2 54
41#define w_entry_show_3 55
42#define w_entry_show_4 56
43#define w_entry_show_5 57
44#define w_entry_show_6 58
45#define w_entry_show_7 59
46#define w_entry_check_1 60
47#define w_entry_check_2 61
48#define w_entry_check_3 62
49#define w_entry_check_4 63
50#define w_entry_check_5 64
51#define w_entry_check_6 65
52#define w_entry_check_7 66
53#define w_entry_fk_1    67
54#define w_entry_fk_2    68
55#define w_entry_fk_3    69
56#define w_entry_fk_4    70
57#define w_entry_fk_5    71
58#define w_entry_fk_6    72
59#define w_entry_fk_7    73
60
61#define MscMAX_WIDGET 100
62
63#define MscMAX_COLOR 101
64
65#define MscCHARHEIGHT 30
66
67#define MscBG 0
68#define MscBLACK 1
69#define MscYELLOW 2
70#define MscSELECT 3
71#define MscFIXED_COLORS 4
72
73#define MscMAX_DETFILES 10
74#define MscDEFAULT_SETUPFILE "mapslow.par"
75
76#define MsfGMT      0x01
77#define MsfXWDW     0x02
78#define MsfEXIT     0x04
79#define MsfDUMPEVAL 0x08
80#define MsfDEBUG    0x10
81
82
83/* local types */
84
85typedef struct {
86        float     timewidth;        /* width of matrix (in s) */
87        float     slowheight;       /* height of matrix (in s/deg) */
88        float     mintime;          /* start time */
89        float     minslow;          /* start slowness */
90} MstMapArea;
91
92typedef struct {
93        int       colnum;       /* number of colors */
94        unsigned  margin_l;     /* left margin */
95        unsigned  margin_r;     /* right margin */
96        unsigned  margin_t;     /* top margin */
97        unsigned  margin_b;     /* bottom margin */
98} MstDspSetup;
99
100typedef struct {
101        float     aztol;        /* azimuth tolerance */
102        float     minqual;      /* minimum quality number */
103        float     maxqual;      /* maximum quality number (cutoff value) */
104        float     minrelpow;    /* minimum relative power */
105        float     minabspow;    /* minimum absolute power */
106        float     mineval;      /* minimum evaluation number */
107        int       eval_avlth;   /* average length in samples for evaluation function */
108        float     m_q;          /* quality multiplier */
109        float     m_r;          /* relative power multiplier */
110        float     m_a;          /* absolute power multiplier */
111        float     m_qr;         /* quality/relative power multiplier */
112        float     m_qa;         /* quality/absolute power multiplier */
113        float     m_ra;         /* relative/absolute power multiplier */
114        float     m_qra;        /* quality/relative power/absolute power multiplier */
115        float     sloint;       /* slowness interval (half-height) */
116        float     col_r;        /* red color fraction */
117        float     col_g;        /* green color fraction */
118        float     col_b;        /* blue color fraction */
119        GC        gc;           /* graphics context */
120        char      text[cBcLineLth+1]; /* descriptive text */
121} MstDetPar;
122
123
124
125/* global variables */
126static char    msv_detfile[MscMAX_DETFILES][cBcFileLth+1]; /* detfiles */
127static MstDetPar msv_detpar[MscMAX_DETFILES];  /* detection display parameters */
128static char             *msv_vec[]={"mapslow.uid"};     /* MRM database file list */
129static Display *msv_display;                   /* display */
130static Widget  msv_w[MscMAX_WIDGET];           /* widget array */
131static char    msv_pname[cBcFileLth+1];        /* program name */
132static MstMapArea        msv_area;             /* matrix */
133static MstDspSetup       msv_dsp;              /* display setup */
134static GC                msv_gc[MscMAX_COLOR]; /* color gc's */
135static GC                msv_gl[MscFIXED_COLORS]; /* fixed colors */
136static Cursor            msv_crsr_busy;        /* busy cursor */
137
138static int     msv_wdw_height;                    /* window height in pixels */
139static float   msv_tscale;                        /* time scale factor */
140static float   msv_sscale;                        /* y-scale factor (cart.) */
141static BOOLEAN msv_pixinit=FALSE;                 /* pixel buffer initialized */
142static char    msv_abstime[cBcTimeLth+1];         /* absolute time */
143static int     msv_flags;                         /* flags */
144static float   msv_baz=0.0;                       /* back azimuth */
145static char    msv_dsptime[cBcTimeLth+1];         /* display time */
146static float   msv_dspslow;                       /* display slowness */
147
148static float   msv_scale=1.0;
149static float   msv_yscale=1.0;
150
151static float   msv_dist;                          /* distance of event */
152static float   msv_depth;                         /* depth of event */
153
154static char    *msv_phases[] = {
155        "P", "PP", "PPP", "PcP", "Pdiff", "PKPab", "PKPbc", "PKPdf", "PKKPdf",
156        "PKKPbc", "PKKPab", "S", "SP", "SS", "SSS", "ScS", "PcS", "Sdiff", "SKSac",
157        "SKSdf", "SKKPab", "SKKPbc", "SKKPdf", "SKKSac", "SKKSdf", "PxPxdf",
158        "PxPxab", "PxPxbc", "SKPab", "SKPdf", "PKiKP", ""
159};
160
161
162
163
164/* prototypes */
165static void cb_call_create_widget( Widget widget, int *tag,
166        XmAnyCallbackStruct *data );
167static void cb_call_activate( Widget widget, int *tag,
168        XmToggleButtonCallbackStruct *data );
169void cb_action_motion_cart( Widget w, XEvent *ev, String *params,
170        Cardinal *parno );
171static void cb_call_expose( Widget widget, char *tag,
172        XmDrawingAreaCallbackStruct *data );
173
174static void ms_read_setup( char setup[], MstDetPar par[] );
175static void ms_prepare_gc( Widget w, MstDetPar par[], GC gl[] );
176static void ms_draw_background( Widget w, MstDspSetup *dsp, float *tscale,
177        float *sscale );
178static void ms_trafo( float t, float s, int *x, int *y );
179static void ms_draw_axes( Widget w, MstDspSetup *dsp, MstMapArea *area, GC gc,
180        char text[] );
181static ms_put_phases( Widget w, GC gc, float dist, float depth,
182        TSyBoolean lab );
183static void ms_put_detfile( Widget w, char detfile[], MstDetPar *detpar,
184        float baz, GC gc[] );
185
186
187/* routines to register */
188static MrmCount         msv_regnum = 3 ;
189static MrmRegisterArg   msv_regvec[] = {
190        { "call_create_widget", (caddr_t)cb_call_create_widget },
191        { "call_activate", (caddr_t)cb_call_activate },
192        { "call_expose", (caddr_t)cb_call_expose }
193};
194
195
196
197/* action routines */
198static   XtActionsRec msv_new_actions_cart[] = {
199        {"cb_action_motion_cart", cb_action_motion_cart}
200};
201
202
203
204int main( int argc, char *argv[] )
205{
206        /* local variables */
207        MrmHierarchy      hierarchy;        /* hierarchy */
208        MrmCode           class;            /* class */
209        XtAppContext      app_context;      /* application context */
210        Arg arglist[2];
211        int n;
212        int               pix_w, pix_h;     /* size of window in pixel */
213        char              *env;             /* pointer to environment */
214        TSyStatus         status;           /* SH return status */
215        char              setup[cBcFileLth+1];   /* display setup input file */
216        char              str[cBcLineLth+1];/* scratch string */
217        char              title[cBcLongStrLth+1]; /* title of figure */
218        int               i;                /* counter */
219        char              xwdfile[cBcFileLth+1]; /* xwd file */
220        char              cmdline[cBcLineLth+1]; /* command line */
221
222        /* executable code */
223
224        pa_init( argc, argv );
225        pix_w = pix_h = 0;
226
227        msv_flags = 0;
228
229        if  (pa_pnumber() != 6)  {
230                fprintf( stderr, "*** Usage: %s <starttime> <timewdw> <maxslow> <distance> <depth> <baz> ***\n", argv[0] );
231                fprintf( stderr, "      qualifiers:\n" );
232                fprintf( stderr, "      -d<n>=<detfile-n> det file number n\n" );
233                fprintf( stderr, "      -ms=<minslow>    minimum slowness (default 0)\n" );
234                fprintf( stderr, "      -w=<pixwidth>    width of window in pixel\n" );
235                fprintf( stderr, "      -h=<pixheight>   height of window in pixel\n" );
236                fprintf( stderr, "      -s=<setup>       default $SH_INPUTS/mapslow.par\n" );
237                fprintf( stderr, "      -t=<title>       title of figure\n" );
238                fprintf( stderr, "      -x=<xwdfile>     create xwd output file\n" );
239                fprintf( stderr, "      -q               quit program immediately\n" );
240                fprintf( stderr, "      -gmt             print data usable for gmt\n" );
241                return 1;
242        } /*endif*/
243
244        /* travel time table settings */
245        env = (char *)getenv( "SH_INPUTS" );
246        if  (env == NULL)  {
247                fprintf( stderr, "environment SH_INPUTS not set.  Abort.\n" );
248                exit( 1 );
249        } /*endif*/
250        status = cBcNoError;
251        pt_settabledir( env, &status );
252        if  (SySevere(&status)) exit(1);
253
254        /* set margins */
255        msv_dsp.margin_l = 40;
256        msv_dsp.margin_r = 100;
257        msv_dsp.margin_t = 30;
258        msv_dsp.margin_b = 60;
259        msv_dsp.colnum = 3;
260
261        strcpy( msv_pname, "mapslow" );
262        strcpy( msv_abstime, pa_pvalue(1) );
263        sscanf( pa_pvalue(2), "%f", &msv_area.timewidth );
264        sscanf( pa_pvalue(3), "%f", &msv_area.slowheight );
265        sscanf( pa_pvalue(4), "%f", &msv_dist );
266        sscanf( pa_pvalue(5), "%f", &msv_depth );
267        sscanf( pa_pvalue(6), "%f", &msv_baz );
268        if  (msv_dsp.colnum < 2)  msv_dsp.colnum = 2;
269        if  (msv_dsp.colnum > 500)  msv_dsp.colnum = 500;
270        if  (pa_qspecified("-ms"))  {
271                sscanf( pa_qvalue("-ms"), "%f", &msv_area.minslow );
272        } else {
273                msv_area.minslow = 0.0;
274        } /*endif*/
275        if  (pa_qspecified("-w"))  {
276                sscanf( pa_qvalue("-w"), "%d", &pix_w );
277                if  (pix_w < 400)  pix_w = 400;
278        } /*endif*/
279        if  (pa_qspecified("-h"))  {
280                sscanf( pa_qvalue("-h"), "%d", &pix_h );
281                if  (pix_h < 400)  pix_h = 400;
282        } /*endif*/
283        if  (pa_qspecified("-s"))  {
284                strncpy( setup, pa_qvalue("-s"), cBcFileLth );
285        } else {
286                strcpy( setup, env );
287                strcat( setup, "/" );
288                strcat( setup, MscDEFAULT_SETUPFILE );
289        } /*endif*/
290        if  (pa_qspecified("-x"))  {
291                strcpy( xwdfile, pa_qvalue("-x") );
292        } else {
293                *xwdfile = '\0';
294        } /*endif*/
295        if  (pa_qspecified("-t"))  {
296                strcpy( title, pa_qvalue("-t") );
297        } else {
298                strcpy( title, msv_abstime );
299        } /*endif*/
300        if  (pa_qspecified("-q"))  {
301                msv_flags |= MsfEXIT;
302        } /*endif*/
303        if  (pa_qspecified("-gmt"))  {
304                msv_flags |= MsfGMT;
305        } else {
306                msv_flags |= MsfXWDW;
307        } /*endif*/
308        if  (pa_qspecified("-dumpeval"))  {
309                msv_flags |= MsfDUMPEVAL;
310        } /*endif*/
311        for  (i=0; i<MscMAX_DETFILES; i++)  {
312                sprintf( str, "-d%d", i+1 );
313                if  (pa_qspecified(str))  {
314                        strcpy( msv_detfile[i], pa_qvalue(str) );
315                } else {
316                        msv_detfile[i][0] = '\0';
317                } /*endif*/
318        } /*endfor*/
319
320        msv_scale = msv_area.timewidth;
321        msv_yscale = msv_area.slowheight;
322
323        if  (MsfXWDW & msv_flags)  {
324
325                MrmInitialize ();
326                XtToolkitInitialize();
327                app_context = XtCreateApplicationContext();
328                msv_display = XtOpenDisplay(app_context, NULL, msv_pname, "mapslow",
329                        NULL, 0, &argc, argv);
330                if (msv_display == NULL) {
331                        fprintf(stderr, "%s:  Can't open display\n", msv_pname );
332                        exit(1);
333                } /*endif*/
334
335                XtAppAddActions( app_context, msv_new_actions_cart, 1 );
336
337                n = 0;
338                /* XtSetArg(arglist[n], XmNallowShellResize, True);  n++; */
339                msv_w[w_toplevel] = XtAppCreateShell( msv_pname, NULL,
340                        applicationShellWidgetClass, msv_display, arglist, n);
341
342                if  (MrmOpenHierarchy(1,msv_vec,NULL,&hierarchy) != MrmSUCCESS) {
343                        fprintf ( stderr, "can't open hierarchy\n" );
344                        exit( 1 );
345                } /*endif*/
346
347                if  (MrmRegisterNames(msv_regvec,msv_regnum) != MrmSUCCESS)  {
348                        fprintf( stderr, "can't register names\n" );
349                        exit( 1 );
350                } /*endif*/
351
352                if (MrmFetchWidget(hierarchy,"main_window",msv_w[w_toplevel],
353                        msv_w+w_main,&class) != MrmSUCCESS)  {
354                        fprintf( stderr, "can't fetch widget\n" );
355                        exit( 1 );
356                } /*endif*/
357
358                n = 0;
359                if  (pix_w > 0)  {XtSetArg( arglist[n], XmNwidth, pix_w ); n++;}
360                if  (pix_h > 0)  {XtSetArg( arglist[n], XmNheight, pix_h ); n++;}
361                if  (n > 0)  XtSetValues( msv_w[w_draw], arglist, n );
362
363                XtManageChild( msv_w[w_main] );
364                XtRealizeWidget( msv_w[w_toplevel] );
365
366                msv_crsr_busy = XCreateFontCursor( XtDisplay(msv_w[w_draw]), XC_watch );
367
368                if  (!msv_pixinit)  {
369                        status = cBcNoError;
370                        pix_create_window_buffer( XtDisplay(msv_w[w_draw]),
371                                XtWindow(msv_w[w_draw]), TRUE, &status );
372                        if  (Severe(&status))  {
373                                fprintf( stderr, "mapmatrix: error creating window buffer\n" );
374                                exit( 1 );
375                        } /*endif*/
376                        msv_pixinit = TRUE;
377                } /*endif*/
378
379        } /*endif*/
380
381        ms_read_setup( setup, msv_detpar );
382
383        if  (MsfXWDW & msv_flags)
384                ms_prepare_gc( msv_w[w_draw], msv_detpar, msv_gl );
385
386        /* draw background */
387        ms_draw_background( msv_w[w_draw], &msv_dsp, &msv_tscale, &msv_sscale );
388        ms_draw_axes( msv_w[w_draw], &msv_dsp, &msv_area, msv_gl[MscBLACK], title );
389
390        for  (i=MscMAX_DETFILES-1; i>=0; i--)
391                if  (msv_detfile[i][0] != '\0')
392                        ms_put_detfile( msv_w[w_draw], msv_detfile[i], &(msv_detpar[i]),
393                                msv_baz, msv_gc );
394
395        if  (msv_dist > 0)
396                ms_put_phases( msv_w[w_draw], msv_gl[MscYELLOW], msv_dist,
397                        msv_depth, TRUE );
398
399        if  (MsfXWDW & msv_flags)  {
400                XFlush( XtDisplay(msv_w[w_draw]) );
401                if  (*xwdfile != '\0')  {
402                        system( "sleep 1" );
403                        sprintf( cmdline, "xwd -name mapslow >%s", xwdfile );
404                        system( cmdline );
405                } /*endif*/
406                if  (!(MsfEXIT & msv_flags))
407                        XtAppMainLoop(app_context);
408        } /*endif*/
409        if  (MsfGMT & msv_flags)  {
410                printf( "echo showpage\n" );
411        } /*endif*/
412
413        return 0;
414
415} /* end of main */
416
417
418
419/*--------------------------------------------------------------------------*/
420
421
422
423static void cb_call_create_widget( Widget widget, int *tag,
424        XmAnyCallbackStruct *data )
425
426/* Callback routine on creating widgets
427 *
428 * parameters of routine
429 * Widget     widget;          input; widget number of drawing area
430 * int        *tag;            input; widget number
431 * XmAnyCallbackStruct *data;  input; not used here
432 */
433{
434        /* local variables */
435        int      wno = *tag;                 /* widget number */
436        char     acttable[BC_LONGSTRLTH+1];  /* action table */
437        XtTranslations new_table;            /* translated table */
438        Arg      al[1];
439
440        /* executable code */
441
442        if  (wno >= MscMAX_WIDGET || wno < 0)  {
443                fprintf( stderr, "--> illegal widget number %d\n", wno );
444                return;
445        } /*endif*/
446
447        /* printf( "[%d]", wno ); */
448        msv_w[wno] = widget;
449
450        if  (wno == w_draw)  {
451                strcpy( acttable, "<Motion>: cb_action_motion_cart()\n" );
452                strcat( acttable, "<Btn1Down>: cb_action_motion_cart()\n" );
453                strcat( acttable, "<Btn1Up>: cb_action_motion_cart()\n" );
454                strcat( acttable, "<Btn2Down>: cb_action_motion_cart()\n" );
455                strcat( acttable, "<Btn2Up>: cb_action_motion_cart()\n" );
456                strcat( acttable, "<Btn3Down>: cb_action_motion_cart()\n" );
457                strcat( acttable, "<Btn3Up>: cb_action_motion_cart()\n" );
458                /*strcat( acttable, "<KeyPress>: cb_action_motion_cart()\n" );*/
459                new_table = XtParseTranslationTable( acttable );
460                XtSetArg( al[0], XmNtranslations, new_table );
461                XtSetValues( msv_w[w_draw], al, 1 );
462        } /*endif*/
463
464} /* end of cb_call_create_widget */
465
466
467
468/*--------------------------------------------------------------------------*/
469
470
471
472static void cb_call_activate( Widget widget, int *tag,
473        XmToggleButtonCallbackStruct *data )
474
475/* Callback routine on button selection
476 *
477 * parameters of routine
478 * Widget     widget;          input; widget number of drawing area
479 * int        *tag;            input; tag entry
480 * XmPushButtonCallbackStruct *data;  input;
481 */
482{
483        /* local variables */
484        static int power=1;             /* current power */
485        STATUS   locstat;               /* local status */
486        char     cmd[cBcLongStrLth+1];  /* shell command */
487        int      i;                     /* index */
488
489        /* executable code */
490
491        if  (!msv_pixinit)  {
492                locstat = BC_NOERROR;
493                pix_create_window_buffer( XtDisplay(msv_w[w_draw]),
494                        XtWindow(msv_w[w_draw]), TRUE, &locstat );
495                if  (Severe(&locstat))  {
496                        fprintf( stderr, "mapmatrix: error creating window buffer\n" );
497                        exit( 1 );
498                } /*endif*/
499                msv_pixinit = TRUE;
500        } /*endif*/
501
502        switch  (*tag)  {
503        case w_entry_quit:
504                exit( 0 );
505        case w_entry_show_1:
506        case w_entry_show_2:
507        case w_entry_show_3:
508        case w_entry_show_4:
509        case w_entry_show_5:
510        case w_entry_show_6:
511        case w_entry_show_7:
512                sprintf( cmd, "$SH_UTIL/mapslow_wavedsp.csh %d %s %f %f %s %5.1f %5.1f",
513                        (*tag)-w_entry_show_1+1, msv_dsptime, msv_dspslow, msv_baz,
514                        msv_abstime, msv_dist, msv_depth );
515                XDefineCursor( XtDisplay(msv_w[w_draw]), XtWindow(msv_w[w_draw]), msv_crsr_busy );
516                XFlush( XtDisplay(msv_w[w_draw]) );
517                system( cmd );
518                XUndefineCursor( XtDisplay(msv_w[w_draw]), XtWindow(msv_w[w_draw]) );
519                break;
520        case w_entry_check_1:
521        case w_entry_check_2:
522        case w_entry_check_3:
523        case w_entry_check_4:
524        case w_entry_check_5:
525        case w_entry_check_6:
526        case w_entry_check_7:
527                i = (*tag) - w_entry_check_1;
528                sprintf( cmd, "$SH_UTIL/mapslow_detfct.csh %s %f %f %f %f,%f,%f,%f,%f,%f,%f,%f,%d",
529                        msv_detfile[i], msv_area.timewidth, msv_baz, msv_detpar[i].mineval,
530                        msv_detpar[i].m_q, msv_detpar[i].m_r, msv_detpar[i].m_a,
531                        msv_detpar[i].m_qr, msv_detpar[i].m_qa, msv_detpar[i].m_ra,
532                        msv_detpar[i].m_qra, msv_detpar[i].maxqual, msv_detpar[i].eval_avlth );
533                XDefineCursor( XtDisplay(msv_w[w_draw]), XtWindow(msv_w[w_draw]), msv_crsr_busy );
534                XFlush( XtDisplay(msv_w[w_draw]) );
535                system( cmd );
536                XUndefineCursor( XtDisplay(msv_w[w_draw]), XtWindow(msv_w[w_draw]) );
537                break;
538        case w_entry_fk_1:
539        case w_entry_fk_2:
540        case w_entry_fk_3:
541        case w_entry_fk_4:
542        case w_entry_fk_5:
543        case w_entry_fk_6:
544        case w_entry_fk_7:
545                sprintf( cmd, "$SH_UTIL/mapslow_fk.csh %d %s %f",
546                        (*tag)-w_entry_fk_1+1, msv_dsptime, msv_baz );
547                XDefineCursor( XtDisplay(msv_w[w_draw]), XtWindow(msv_w[w_draw]), msv_crsr_busy );
548                XFlush( XtDisplay(msv_w[w_draw]) );
549                system( cmd );
550                XUndefineCursor( XtDisplay(msv_w[w_draw]), XtWindow(msv_w[w_draw]) );
551                break;
552        default:
553                fprintf( stderr, "illegal widget activated (%d)\n", *tag );
554                return;
555        } /*endswitch*/
556
557} /* end of cb_call_activate */
558
559
560
561/*--------------------------------------------------------------------------*/
562
563
564
565static void cb_call_expose( Widget widget, char *tag,
566        XmDrawingAreaCallbackStruct *data )
567
568/* Callback routine on creation of drawing area
569 *
570 * parameters of routine
571 * Widget     widget;          input; widget number of drawing area
572 * char       *tag;            input; not used here
573 * XmDrawingAreaCallbackStruct *data;  input;
574 */
575{
576        /* local variables */
577
578        /* executable code */
579
580        if  (msv_pixinit)
581                pix_manage_exposure( &(data->event->xexpose) );
582
583} /* end of cb_call_expose */
584
585
586
587/*--------------------------------------------------------------------------*/
588
589
590#define POSTEXT_X -650
591#define POSTEXT_Y 637
592#define SELTEXT_X -230
593#define TEXTSPACE 200
594#define MARKWIDTH 11
595
596#define MODIF_SHIFT 0x11
597#define MODIF_LOCK  0x12
598#define MODIF_CTRL  0x14
599#define MODIF_ALT   0x18
600
601void cb_action_motion_cart( Widget w, XEvent *ev, String *params,
602        Cardinal *parno )
603
604/* action routine for pointer motion
605 *
606 * parameters of routine
607 * Widget     w;      input; widget ID
608 * XEvent     *ev;    input; current event
609 * ...   (don't know much about it)
610 */
611{
612        /* local variables */
613        static BOOLEAN is_init=FALSE;       /* already initialized */
614        static int     pos_x, pos_y;        /* draw position */
615        static int     sel_x, sel_y;        /* selected position */
616        static GC      xgc;                 /* clear GC */
617        static char    oldstr[BC_LINELTH+1]="";/* old string */
618        static char    oldstr2[BC_LINELTH+1]="";/* old string */
619        static char    oldsel[BC_LINELTH+1]="";/* old selection text */
620        static int     eff_w, eff_h;        /* effective size of window */
621        char     postext[BC_LINELTH+1];     /* position text */
622        char     postext2[BC_LINELTH+1];    /* position text */
623        char     seltext[BC_LINELTH+1];     /* selected time & slowness */
624        Window   root;                      /* root window */
625        int      w_x, w_y;                  /* window position */
626        unsigned w_w, w_h;                  /* size of window */
627   unsigned border, depth;             /* window pars (not used) */
628        float    slow_x, slow_y;            /* slowness position */
629        char     ctime[cBcTimeLth+1];       /* current absolute time */
630        STATUS   locstat;                   /* local status */
631        int      i;                         /* counter */
632        Modifiers mret;                     /* return key */
633        KeySym   keysym;                    /* key symbol */
634        int      tag;                       /* key tag */
635
636        /* executable code */
637
638        if  (w != msv_w[w_draw])  {printf("--> motion: ill wdw\n"); return;}
639
640        if  (!is_init)  {
641                XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h,
642                        &border, &depth );
643                pos_x = w_w - msv_dsp.margin_r + POSTEXT_X;
644                pos_y = w_h - msv_dsp.margin_b - POSTEXT_Y;
645                eff_w = w_w - msv_dsp.margin_l - msv_dsp.margin_r;
646                eff_h = w_h - msv_dsp.margin_t - msv_dsp.margin_b;
647                sel_x = w_w - msv_dsp.margin_r + SELTEXT_X;
648                sel_y = pos_y;
649                xgc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
650                XCopyGC( XtDisplay(w), msv_gl[MscBLACK], GCFont, xgc );
651                XSetForeground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) );
652                XSetBackground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) );
653                /* XSetFunction( XtDisplay(w), xgc, GXxor ); */
654                is_init = TRUE;
655        } /*endif*/
656
657        if  (ev->type == MotionNotify)  {
658                if  (ev->xmotion.x < msv_dsp.margin_l
659                        || ev->xmotion.y < msv_dsp.margin_t
660                        || ev->xmotion.x > msv_dsp.margin_l+eff_w
661                        || ev->xmotion.y > msv_dsp.margin_t+eff_h)  {
662                        *postext = *postext2 = '\0';
663                } else {
664                        slow_x = (float)(ev->xmotion.x - msv_dsp.margin_l);
665                        slow_y = (float)(ev->xmotion.y - msv_dsp.margin_t);
666                        slow_x = slow_x / (float)eff_w * msv_scale;
667                        slow_y = msv_area.minslow + msv_yscale
668                                - (slow_y / (float)eff_h * msv_yscale);
669                        locstat = cBcNoError;
670                        if  (*msv_abstime == '\0')  {
671                                sprintf( postext,  " curr. time: %6.2f", slow_x );
672                        } else {
673                                tc_tadd( msv_abstime, slow_x, ctime, &locstat );
674                                /* through out milliseconds */
675                                i = 0;
676                                while  (ctime[i] != '\0')  {
677                                        if  (ctime[i] == '.')  {
678                                                ctime[i] = '\0';
679                                                break;
680                                        } /*endif*/
681                                        i++;
682                                } /*endwhile*/
683                                /* strcpy( postext, ctime ); */
684                                sprintf( postext, "%s  r:%6.1f", ctime, slow_x );
685                        } /*endif*/
686                        sprintf( postext2, " slowness  : %6.2f", slow_y );
687                } /*endif*/
688                if  (*oldstr != '\0')  {
689                        pix_DrawString( XtDisplay(w), XtWindow(w), xgc,
690                                pos_x, pos_y, oldstr, strlen(oldstr) );
691                        pix_DrawString( XtDisplay(w), XtWindow(w), xgc,
692                                pos_x+TEXTSPACE, pos_y, oldstr2, strlen(oldstr2) );
693                } /*endif*/
694                if  (*postext != '\0')  {
695                        pix_DrawString( XtDisplay(w), XtWindow(w), msv_gl[MscBLACK],
696                                pos_x, pos_y, postext, strlen(postext) );
697                        pix_DrawString( XtDisplay(w), XtWindow(w), msv_gl[MscBLACK],
698                                pos_x+TEXTSPACE, pos_y, postext2, strlen(postext2) );
699                } /*endif*/
700                strcpy( oldstr, postext );
701                strcpy( oldstr2, postext2 );
702                XFlush( XtDisplay(w) );
703        } else if  (ev->type == ButtonPress) {
704                if  (!(ev->xmotion.x < msv_dsp.margin_l
705                        || ev->xmotion.y < msv_dsp.margin_t
706                        || ev->xmotion.x > msv_dsp.margin_l+eff_w
707                        || ev->xmotion.y > msv_dsp.margin_t+eff_h))  {
708                        slow_x = (float)(ev->xmotion.x - msv_dsp.margin_l);
709                        msv_dspslow = (float)(ev->xmotion.y - msv_dsp.margin_t);
710                        slow_x = slow_x / (float)eff_w * msv_scale;
711                        msv_dspslow = msv_area.minslow + msv_yscale
712                                - (msv_dspslow / (float)eff_h * msv_yscale);
713                        locstat = cBcNoError;
714                        tc_tadd( msv_abstime, slow_x, msv_dsptime, &locstat );
715                        /* through out milliseconds */
716                        i = 0;
717                        while  (msv_dsptime[i] != '\0')  {
718                                if  (msv_dsptime[i] == '.')  {
719                                        msv_dsptime[i] = '\0';
720                                        break;
721                                } /*endif*/
722                                i++;
723                        } /*endwhile*/
724                        /* manage display of selected time & slowness */
725                        sprintf( seltext, "selected: %5.2f @ %20s",
726                                msv_dspslow, msv_dsptime );
727                        if  (*oldsel != '\0')  {
728                                pix_DrawString( XtDisplay(w), XtWindow(w), xgc,
729                                        sel_x, sel_y, oldsel, strlen(oldsel) );
730                        } /*endif*/
731                        pix_DrawString( XtDisplay(w), XtWindow(w), msv_gl[MscBLACK],
732                                sel_x, sel_y, seltext, strlen(seltext) );
733                        strcpy( oldsel, seltext );
734                        /* flash selected point */
735                        pix_FillRectangle( XtDisplay(w), XtWindow(w), msv_gl[MscSELECT],
736                                ev->xmotion.x-MARKWIDTH/2, ev->xmotion.y-MARKWIDTH/2,
737                                MARKWIDTH, MARKWIDTH );
738                        XFlush( XtDisplay(w) );
739                        usleep( 500000 );
740                        pix_FillRectangle( XtDisplay(w), XtWindow(w), msv_gl[MscSELECT],
741                                ev->xmotion.x-MARKWIDTH/2, ev->xmotion.y-MARKWIDTH/2,
742                                MARKWIDTH, MARKWIDTH );
743                        /* write to stdout */
744                        printf( "time %s  slowness %4.1f  azimuth %5.1f\n",
745                                msv_dsptime, msv_dspslow, msv_baz );
746                } /*endif*/
747        } else if  (ev->type == KeyPress) {
748                XtTranslateKeycode( ev->xkey.display, ev->xkey.keycode, ev->xkey.state,
749                        &mret, &keysym );
750                if  (ev->xkey.state == MODIF_CTRL)  {
751                        switch  ((char)keysym)  {
752                        case '1':   tag = w_entry_check_1;         break;
753                        case '2':   tag = w_entry_check_2;         break;
754                        case '3':   tag = w_entry_check_3;         break;
755                        case '4':   tag = w_entry_check_4;         break;
756                        case '5':   tag = w_entry_check_5;         break;
757                        case '6':   tag = w_entry_check_6;         break;
758                        case '7':   tag = w_entry_check_7;         break;
759                        default:    tag = 0;
760                                printf( "--> pressed key %d, keysym %ld\n", ev->xkey.keycode, keysym );
761                        } /*endswitch*/
762                } else {
763                        switch  ((char)keysym)  {
764                        case '1':   tag = w_entry_show_1;         break;
765                        case '2':   tag = w_entry_show_2;         break;
766                        case '3':   tag = w_entry_show_3;         break;
767                        case '4':   tag = w_entry_show_4;         break;
768                        case '5':   tag = w_entry_show_5;         break;
769                        case '6':   tag = w_entry_show_6;         break;
770                        case '7':   tag = w_entry_show_7;         break;
771                        case 'q':   tag = w_entry_quit;           break;
772                        default:    tag = 0;
773                                printf( "--> pressed key %d, keysym %ld\n", ev->xkey.keycode, keysym );
774                        } /*endswitch*/
775                } /*endif*/
776        } /*endif*/
777
778} /* end of cb_action_motion_cart */
779
780
781
782/*--------------------------------------------------------------------------*/
783
784
785
786static void ms_read_setup( char setup[], MstDetPar par[] )
787
788/* Reads in display parameters for detection lists
789 *
790 * parameters of routine
791 * char       setup[];        input; name of input file
792 * MstDetPar  par[];          output; list of parameters
793 */
794{
795        /* local variables */
796        FILE     *fp;          /* pointer to input file */
797        int      i;            /* counter */
798        char     line[cBcLineLth+1];  /* current line of file */
799        char     val[cBcLineLth+1];   /* current value */
800        char     key[cBcLineLth+1];   /* current keyword */
801
802        /* executable code */
803
804        /* initialize setup pars */
805        for  (i=0; i<MscMAX_DETFILES; i++)  {
806                par[i].aztol = 30.0;
807                par[i].minqual = 1.0e2;
808                par[i].maxqual = 1.0e5;
809                par[i].sloint = 0.25;
810                par[i].minrelpow = 0.0;
811                par[i].minabspow = 0.0;
812                par[i].mineval = 0.0;
813                par[i].eval_avlth = 10;
814                par[i].m_q = 0.0;
815                par[i].m_r = 0.0;
816                par[i].m_a = 0.0;
817                par[i].m_qa = 0.0;
818                par[i].m_qr = 0.0;
819                par[i].m_ra = 0.0;
820                par[i].m_qra = 0.0;
821                par[i].col_r = 1.0;
822                par[i].col_g = 0.0;
823                par[i].col_b = 0.0;
824                par[i].text[0] = '\0';
825        } /*endfor*/
826
827        fp = fopen( setup, "r" );
828        if  (fp == NULL)  {
829                fprintf( stderr, "mapslow: cannot find input file %s\n", setup );
830                exit( 1 );
831        } /*endif*/
832
833        /* read through file */
834        while  (fgets(line,cBcLineLth,fp) != NULL)  {
835                if  (*line == '!' || *line == '\n')  continue;
836                if  (sscanf(line,"%d %s %s",&i,key,val) != 3)  {
837                        fprintf( stderr, "mapslow: syntax error in file %s:\n", setup );
838                        fprintf( stderr, "%s", line );
839                        exit( 1 );
840                } /*endif*/
841                i--;
842                if  (i < 0 || i >= MscMAX_DETFILES)  {
843                        fprintf( stderr, "mapslow: illegal detlist number %d\n", i );
844                        continue;
845                } /*endif*/
846                if  (strcmp(key,"aztol") == 0)  {
847                        sscanf( val, "%f", &(par[i].aztol) );
848                } else if  (strcmp(key,"minqual") == 0)  {
849                        sscanf( val, "%f", &(par[i].minqual) );
850                } else if  (strcmp(key,"maxqual") == 0)  {
851                        sscanf( val, "%f", &(par[i].maxqual) );
852                } else if  (strcmp(key,"sloint") == 0)  {
853                        sscanf( val, "%f", &(par[i].sloint) );
854                } else if  (strcmp(key,"minrelpow") == 0)  {
855                        sscanf( val, "%f", &(par[i].minrelpow) );
856                } else if  (strcmp(key,"minabspow") == 0)  {
857                        sscanf( val, "%f", &(par[i].minabspow) );
858                } else if  (strcmp(key,"mineval") == 0)  {
859                        sscanf( val, "%f", &(par[i].mineval) );
860                } else if  (strcmp(key,"eval_avlth") == 0)  {
861                        sscanf( val, "%d", &(par[i].eval_avlth) );
862                } else if  (strcmp(key,"mul_q") == 0)  {
863                        sscanf( val, "%f", &(par[i].m_q) );
864                } else if  (strcmp(key,"mul_r") == 0)  {
865                        sscanf( val, "%f", &(par[i].m_r) );
866                } else if  (strcmp(key,"mul_a") == 0)  {
867                        sscanf( val, "%f", &(par[i].m_a) );
868                } else if  (strcmp(key,"mul_qr") == 0)  {
869                        sscanf( val, "%f", &(par[i].m_qr) );
870                } else if  (strcmp(key,"mul_qa") == 0)  {
871                        sscanf( val, "%f", &(par[i].m_qa) );
872                } else if  (strcmp(key,"mul_ra") == 0)  {
873                        sscanf( val, "%f", &(par[i].m_ra) );
874                } else if  (strcmp(key,"mul_qra") == 0)  {
875                        sscanf( val, "%f", &(par[i].m_qra) );
876                } else if  (strcmp(key,"color") == 0)  {
877                        sscanf( val, "%f,%f,%f", &(par[i].col_r), &(par[i].col_g),
878                                &(par[i].col_b) );
879                } else if  (strcmp(key,"text") == 0)  {
880                        strcpy( par[i].text, val );
881                } else {
882                        fprintf( stderr, "mapslow: illegal key entry in setup: %s\n", key );
883                } /*endif*/
884        } /*endwhile*/
885
886        fclose( fp );
887
888} /* end of ms_read_setup */
889
890
891
892/*--------------------------------------------------------------------------*/
893
894
895
896
897static void ms_prepare_gc( Widget w, MstDetPar par[], GC gl[] )
898
899/* creates GC's for display
900 *
901 * parameters of routine
902 * Widget     w;          input; widget of drawing area
903 * MstDetpar  *par;       input/output(gc); display setup
904 * GC         *bg;        output; background color
905 * GC         *lab;       output; used for labelling
906 */
907{
908        /* local variables */
909        static char *visual_class[] = {
910                "StaticGray", "GrayScale", "StaticColor", "PseudoColor",
911                "TrueColor", "DirectColor"
912        };
913        int      default_depth;       /* default depth */
914        Visual   *default_visual;     /* default visual */
915        XColor   color;               /* color */
916        Colormap default_cmap;        /* default colormap */
917        XVisualInfo visual_info;      /* visual info */
918        unsigned i;                   /* counter */
919        float    frac;                /* color fraction */
920        float    frac_x, c;           /* scratch */
921        int      screen_num;          /* screen number */
922        Font     out_font;            /* font for text */
923
924        /* executable code */
925
926        screen_num = 0;
927
928        default_depth = DefaultDepth( XtDisplay(w), screen_num );
929        default_visual = DefaultVisual( XtDisplay(w), screen_num );
930        default_cmap = DefaultColormap( XtDisplay(w), screen_num );
931        if  (default_depth == 1)  {
932                fprintf( stderr, "%s: StaticGray visual not supported\n",
933                        msv_pname );
934                exit( 1 );
935        } /*endif*/
936
937        i = 5;
938        while  (!XMatchVisualInfo(XtDisplay(w),screen_num,default_depth,
939                i--,&visual_info))
940                ;
941
942        /*printf( "%s: found a %s class visual at default depth %d\n",
943                msv_pname, visual_class[++i] ); */
944        if  (i < StaticColor)  {
945                fprintf( stderr, "%s: visual class %s is not supported\n",
946                        msv_pname, visual_class[i] );
947                exit( 1 );
948        } /*endif*/
949
950#ifdef XXX
951        if  (visual_info.visual != default_visual)
952                printf( "%s: %s class visual at default depth is not default visual\n",
953                        msv_pname, visual_class[i] );
954#endif
955
956        for  (i=0; i<MscMAX_DETFILES; i++)  {
957                color.red = Nint( par[i].col_r * 65535.0 );
958                color.green = Nint( par[i].col_g * 65535.0 );
959                color.blue = Nint( par[i].col_b * 65535.0 );
960                color.flags = DoRed | DoGreen | DoBlue;
961                if  (!XAllocColor(XtDisplay(w),default_cmap,&color))  {
962                        fprintf( stderr, "%s: error allocating color\n", msv_pname );
963                        exit( 1 );
964                } /*endif*/
965                par[i].gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
966                XSetForeground( XtDisplay(w), par[i].gc, color.pixel );
967                XSetBackground( XtDisplay(w), par[i].gc,
968                        WhitePixel(XtDisplay(w),screen_num) );
969        } /*endfor*/
970
971        out_font = XLoadFont( XtDisplay(w),
972                "-b&h-lucidatypewriter-bold-r-normal-sans-*-100-*-*-*-*-*-1" );
973
974#ifdef COL_BLUE
975        color.red = 0;
976        color.green = 0;
977        color.blue = 65535;
978#else
979        color.red = 65535;
980        color.green = 65535;
981        color.blue = 65535;
982#endif
983        color.flags = DoRed | DoGreen | DoBlue;
984        if  (! XAllocColor(XtDisplay(w), default_cmap, &color ))  {
985                fprintf( stderr, "%s error allocating color\n", msv_pname );
986                exit( 1 );
987        } /*endif*/
988        gl[MscBG] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
989        XSetForeground( XtDisplay(w), gl[MscBG], color.pixel );
990        XSetBackground( XtDisplay(w), gl[MscBG],
991                WhitePixel(XtDisplay(w),screen_num) );
992        XSetFont( XtDisplay(w), gl[MscBG], out_font );
993
994#ifdef COL_BLUE
995        color.red = 65535;
996        color.green = 65535;
997        color.blue = 0;
998#else
999        color.red = 0;
1000        color.green = 0;
1001        color.blue = 0;
1002#endif
1003        color.flags = DoRed | DoGreen | DoBlue;
1004        if  (! XAllocColor(XtDisplay(w), default_cmap, &color ))  {
1005                fprintf( stderr, "%s error allocating color\n", msv_pname );
1006                exit( 1 );
1007        } /*endif*/
1008        gl[MscYELLOW] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
1009        XSetForeground( XtDisplay(w), gl[MscYELLOW], color.pixel );
1010        XSetBackground( XtDisplay(w), gl[MscYELLOW],
1011                WhitePixel(XtDisplay(w),screen_num) );
1012        XSetFont( XtDisplay(w), gl[MscYELLOW], out_font );
1013
1014        color.red = 0;
1015        color.green = 0;
1016        color.blue = 0;
1017        color.flags = DoRed | DoGreen | DoBlue;
1018        if  (! XAllocColor(XtDisplay(w), default_cmap, &color ))  {
1019                fprintf( stderr, "%s error allocating color\n", msv_pname );
1020                exit( 1 );
1021        } /*endif*/
1022        gl[MscSELECT] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
1023        XSetFunction( XtDisplay(w), gl[MscSELECT], GXxor );
1024        XSetForeground( XtDisplay(w), gl[MscSELECT], color.pixel );
1025        XSetBackground( XtDisplay(w), gl[MscSELECT],
1026                WhitePixel(XtDisplay(w),screen_num) );
1027        XSetFont( XtDisplay(w), gl[MscSELECT], out_font );
1028
1029        gl[MscBLACK] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
1030        XSetForeground( XtDisplay(w), gl[MscBLACK],
1031                BlackPixel(XtDisplay(w),screen_num) );
1032        XSetBackground( XtDisplay(w), gl[MscBLACK],
1033                 WhitePixel(XtDisplay(w),screen_num) );
1034        XSetFont( XtDisplay(w), gl[MscBLACK], out_font );
1035
1036} /* end of ms_prepare_gc */
1037
1038
1039
1040/*--------------------------------------------------------------------------*/
1041
1042
1043
1044static void ms_draw_background( Widget w, MstDspSetup *dsp, float *tscale,
1045        float *sscale )
1046
1047/* Draws background
1048 *
1049 * parameters of routine
1050 * Widget       w;         input; drawing widget
1051 * MstDspSetup  *dsp;      input; display settings
1052 * float        *tscale;   output; scaling pixel to time units
1053 * float        *sscale;   output; scaling pixel to slowness units
1054 */
1055{
1056        /* local variables */
1057        Window   root;        /* root window */
1058        int      w_x, w_y;    /* position of window */
1059        unsigned w_w, w_h;    /* size of window */
1060        unsigned border;      /* border width */
1061        unsigned depth;       /* depth of window */
1062        int      rect_width;  /* width of rectangle */
1063        int      rect_height; /* height of rectangle */
1064
1065        /* executable code */
1066
1067        if  (MsfXWDW & msv_flags)  {
1068
1069                XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h,
1070                        &border, &depth );
1071
1072                /* get width and height of rectangle */
1073                rect_width = w_w - (dsp->margin_l) - (dsp->margin_r);
1074                rect_height = w_h - (dsp->margin_t) - (dsp->margin_b);
1075
1076                pix_FillRectangle( XtDisplay(w), XtWindow(w),
1077                        msv_gl[MscBG], dsp->margin_l, dsp->margin_t,
1078                        rect_width, rect_height );
1079
1080                *tscale = msv_area.timewidth / (float)rect_width;
1081                *sscale = msv_area.slowheight / (float)rect_height;
1082                msv_wdw_height = w_h;
1083
1084        } /*endif*/
1085
1086} /* end of ms_draw_background */
1087
1088
1089
1090/*--------------------------------------------------------------------------*/
1091
1092
1093
1094static void ms_trafo( float t, float s, int *x, int *y )
1095
1096/* Converts time and slowness to pixel coordinates
1097 *
1098 * parameters of routine
1099 * float      t, s;    input; time and slowness
1100 * int        *x, *y;  output; pixel coordinates (if not NULL)
1101 */
1102{
1103        /* executable code */
1104
1105        if  (x != NULL)
1106                *x = msv_dsp.margin_l + Nint(t/msv_tscale);
1107
1108        if  (y != NULL)
1109                *y = msv_wdw_height
1110                        - (msv_dsp.margin_b + Nint((s-msv_area.minslow)/msv_sscale));
1111
1112} /* end of ms_trafo */
1113
1114
1115
1116/*--------------------------------------------------------------------------*/
1117
1118
1119
1120static void ms_draw_axes( Widget w, MstDspSetup *dsp, MstMapArea *area, GC gc,
1121        char text[] )
1122
1123/* Draws axes and labelling
1124 *
1125 * parameters of routine
1126 * Widget       w;           input; drawing widget
1127 * MstDspSetup  *dsp;        input; display settings
1128 * GC           gc;          input; drawing attributes
1129 */
1130{
1131        /* local variables */
1132        int      ixa, iya, ixb, iyb;     /* pixel coordinates */
1133        float    step;                   /* label steps */
1134        float    x;                      /* current value */
1135        char     str[cBcLineLth+1];      /* output string */
1136
1137        /* executable code */
1138
1139        if  (MsfXWDW & msv_flags)  {
1140
1141                ms_trafo( 0.0, area->minslow, &ixa, &iya );
1142                ms_trafo( area->timewidth, area->minslow, &ixb, NULL );
1143                ixb--;
1144                pix_DrawLine( XtDisplay(w), XtWindow(w), gc, ixa, iya, ixb, iya );
1145
1146                step = 10.0;
1147                if  (area->timewidth > 100.0)  step = 50.0;
1148                if  (area->timewidth > 500.0)  step = 200.0;
1149                if  (area->timewidth > 1000.0)  step = 500.0;
1150                if  (area->timewidth > 5000.0)  step = 2000.0;
1151                if  (area->timewidth > 10000.0)  step = 5000.0;
1152                if  (area->timewidth > 50000.0)  step = 20000.0;
1153
1154                x = 0.0;
1155                while  (x <= area->timewidth)  {
1156                        ms_trafo( x, area->minslow, &ixa, &iya );
1157                        iyb = iya + 5;
1158                        pix_DrawLine( XtDisplay(w), XtWindow(w), gc, ixa, iya, ixa, iyb );
1159                        sprintf( str, "%d", Nint(x) );
1160                        pix_DrawString( XtDisplay(w), XtWindow(w), gc,
1161                                ixa-10, iyb+10, str, strlen(str) );
1162                        x += step;
1163                } /*endwhile*/
1164
1165                ms_trafo( 0.0, area->minslow-2.0, &ixa, &iya );
1166                pix_DrawString( XtDisplay(w), XtWindow(w), gc, ixa, iya, text,
1167                        strlen(text));
1168
1169                ms_trafo( 0.0, msv_area.minslow, &ixa, &iya );
1170                ms_trafo( 0.0, area->slowheight+area->minslow, NULL, &iyb );
1171                ixb--;
1172                pix_DrawLine( XtDisplay(w), XtWindow(w), gc, ixa, iya, ixa, iyb );
1173                step = 1.0;
1174                if  (area->slowheight > 5.0)  step = 2.0;
1175                if  (area->slowheight > 10.0)  step = 5.0;
1176                if  (area->slowheight > 100.0)  step = 20.0;
1177
1178                x = (float)((int)(msv_area.minslow / 5.0)) * 5.0;
1179                while  (x <= (area->slowheight + area->minslow))  {
1180                        ms_trafo( 0.0, x, &ixa, &iya );
1181                        ixb = ixa - 5;
1182                        pix_DrawLine( XtDisplay(w), XtWindow(w), gc, ixa, iya, ixb, iya );
1183                        sprintf( str, "%d", Nint(x) );
1184                        pix_DrawString( XtDisplay(w), XtWindow(w), gc,
1185                                ixb-20, iya+4, str, strlen(str) );
1186                        x += step;
1187                } /*endwhile*/
1188
1189                ms_trafo( -area->timewidth * 0.03,
1190                        area->minslow + area->slowheight * 1.02, &ixa, &iya );
1191                strcpy( str, "Slowness (s/deg)" );
1192                pix_DrawString( XtDisplay(w), XtWindow(w), gc,
1193                        ixa, iya, str, strlen(str) );
1194                ms_trafo( area->timewidth * 1.03,
1195                        area->minslow - area->slowheight * 0.03, &ixa, &iya );
1196                strcpy( str, "Time (s)" );
1197                pix_DrawString( XtDisplay(w), XtWindow(w), gc,
1198                        ixa, iya, str, strlen(str) );
1199
1200        } /*endif*/
1201
1202        if  (MsfGMT & msv_flags)  {
1203                printf( "psbasemap -R0/5000/0/30 -JX6/4 -Bf1000/f5 -K\n" );
1204        } /*endif*/
1205
1206} /* end of ms_draw_axes */
1207
1208
1209
1210/*--------------------------------------------------------------------------*/
1211
1212
1213
1214static ms_put_phases( Widget w, GC gc, float dist, float depth,
1215        TSyBoolean lab )
1216
1217/* Puts theoretical phases on the display
1218 *
1219 * parameters of the routine
1220 * Widget     w;      input; drawing widget
1221 * GC         gc;     input; attributes
1222 * MstDetPar  par[];  input; display parameters (color)
1223 * float      dist;   input; distance of event
1224 * float      depth;  input; depth of event
1225 */
1226{
1227        /* local variables */
1228        int      i;        /* phase counter */
1229        TSyStatus status;  /* return status */
1230        float    travt;    /* travel time of phase */
1231        float    slo;      /* slowness of phase */
1232        int      ix, iy;   /* output coordinates */
1233        char     str[cBcLineLth+1]; /* output string */
1234        int      xoff, yoff; /* x, yoffset */
1235
1236        /* executable code */
1237
1238        i = 0;
1239        while  (msv_phases[i][0] != '\0')  {
1240                /*printf( "--> %s ", msv_phases[i] );*/
1241                /* show PKiKP only, if it is closer than 113 deg */
1242                if  (strcmp(msv_phases[i],"PKiKP") == 0 && dist > 113.0)  {
1243                        i++;
1244                        continue;
1245                } /*endif*/
1246                status = cBcNoError;
1247                travt = pt_travel( msv_phases[i], dist, depth, &status );
1248                if  (status == cBcNoError)
1249                        slo = pt_slowness( msv_phases[i], dist, depth, &status );
1250                        if  (msv_area.minslow == 0.0)
1251                                slo = fabs( slo );
1252                if  (status == cBcNoError)  {
1253                        /*printf( "%f %f", travt, slo );*/
1254                        if  (travt < msv_area.timewidth && slo < msv_area.slowheight)  {
1255                                if  (MsfGMT & msv_flags)  {
1256                                        printf( "pstext -K -O -R -G#PHASECOL# -JX6/4 <<END\n" );
1257                                        printf( "%f %f 10 0.0 4 9 %s\n", travt, slo, msv_phases[i] );
1258                                        printf( "END\n" );
1259                                        printf( "psxy -K -O -Sc0.1 -R -G#PHASECOL# -JX6/4 <<END\n" );
1260                                        printf( "%f %f\n", travt, slo );
1261                                        printf( "END\n" );
1262                                } /*endif*/
1263                                if  (MsfXWDW & msv_flags)  {
1264                                        ms_trafo( travt, slo, &ix, &iy );
1265                                        pix_FillRectangle( XtDisplay(w), XtWindow(w), gc, ix-1,
1266                                                iy+1, 3, 3 );
1267                                        if  (lab)  {
1268                                                strcpy( str, msv_phases[i] );
1269                                                xoff = -2;
1270                                                yoff = -2;
1271                                                if  (strncmp(str,"PxPx",4) == 0)  {
1272                                                        str[1] = str[3] = '\'';
1273                                                        xoff = 4;
1274                                                        yoff = 8;
1275                                                } else if  ((strncmp(str,"SKP",3) == 0) ||
1276                                                        (strncmp(str,"SKKP",4) == 0) ||
1277                                                        (strncmp(str,"Sdif",4) == 0))  {
1278                                                        yoff = 14;
1279                                                } /*endif*/
1280                                                pix_DrawString( XtDisplay(w), XtWindow(w), gc,
1281                                                        ix+xoff, iy+yoff, str, strlen(str) );
1282                                        } /*endif*/
1283                                } /*endif*/
1284                        } /*endif*/
1285                } /*endif*/
1286                /*printf( "\n" );*/
1287                i++;
1288        } /*endwhile*/
1289
1290} /* end of ms_put_phases */
1291
1292
1293
1294/*--------------------------------------------------------------------------*/
1295
1296
1297
1298#define MAXAVLTH 50
1299#define LEGENDWIDTH 90
1300
1301
1302static void ms_put_detfile( Widget w, char detfile[], MstDetPar *detpar,
1303        float thbaz, GC gc[] )
1304
1305/* Displays detections
1306 *
1307 * parameters of routine
1308 * Widget     w;            input; display widget
1309 * char       detfile[];    input; detection file
1310 * MstDetPar  *detpar;      input; detection display parameters
1311 * float      thbaz;        input; theoretical back azimuth
1312 * GC         gc[];         input; color table
1313 */
1314{
1315        /* local variables */
1316        static int ypos=200;             /* text y position */
1317        static int lcnt=1;               /* list counter */
1318        FILE     *fp;                    /* pointer to file */
1319        char     line[cBcLineLth+1];     /* current line in file */
1320        char     timestr[cBcLineLth+1];  /* time string */
1321        float    qual;                   /* quality number */
1322        float    slo;                    /* slowness */
1323        float    baz;                    /* back azimuth */
1324        float    relpow;                 /* relative power */
1325        float    abspow;                 /* absolute power */
1326        float    reltime;                /* relative time in s */
1327        float    dt;                     /* time distance between detections */
1328        float    bazdiff;                /* deviation in back azimuth */
1329        float    eval;                   /* evaluation number */
1330        float    movav;                  /* moving average */
1331        float    smpbuf[MAXAVLTH];       /* sample buffer */
1332        int      smpcnt;                 /* sample counter */
1333        int      smpidx;                 /* sample index for sample buffer */
1334        int      i;                      /* counter */
1335        TSyStatus status;                /* return status */
1336        TSyBoolean do_output;            /* plot detection */
1337        int      ixa, ixb, iya, iyb;     /* output coordinates */
1338        int      wd, hg;                 /* width and height of marker */
1339        TSyBoolean negslow;              /* negative slowness = azimuth + 180 */
1340        TSyBoolean debug;                /* debug flag */
1341        /* for XGet Geometry */
1342        Window   root;                   /* root window */
1343        int      w_x, w_y;               /* window position */
1344        unsigned w_w, w_h;               /* size of window */
1345   unsigned border, depth;          /* window pars (not used) */
1346
1347        /* executable code */
1348
1349        debug = (MsfDEBUG & msv_flags);
1350
1351        fp = fopen( detfile, "r" );
1352        if  (fp == NULL)  {
1353                fprintf( stderr, "%s: cannot open detection file %s\n",
1354                        msv_pname, detfile );
1355                return;
1356        } /*endif*/
1357
1358        status = cBcNoError;
1359
1360        /* find time distance between detections */
1361        fgets( line, cBcLineLth, fp );
1362        fgets( line, cBcLineLth, fp );
1363        strcpy( timestr, line+4 );
1364        i = 2;
1365        while  (timestr[i] != ' ' && timestr[i] != '\0')  i++;
1366        timestr[i] = '\0';
1367        fgets( line, cBcLineLth, fp );
1368        i = 6;
1369        while  (line[i] != ' ' && line[i] != '\0')  i++;
1370        line[i] = '\0';
1371        dt = tc_tdiff( line+4, timestr, &status );
1372        if  (SySevere(&status))  {
1373                fprintf( stderr, "%s: error converting time in %s\n",
1374                        msv_pname, detfile );
1375                exit( 1 );
1376        } /*endif*/
1377        rewind( fp );
1378
1379        if  (MsfGMT & msv_flags)  {
1380                printf( "psxy -K -O -JX6/4 -G#COL%02d# -R -Ss <<END\n", lcnt );
1381        } /*endif*/
1382
1383        if  (detpar->eval_avlth > MAXAVLTH)  {
1384                fprintf( stderr, "mapslow: average length too large.  Abort.\n" );
1385                exit( 1 );
1386        } /*endif*/
1387
1388        /* read through all lines of file */
1389        movav = 0.0;
1390        smpcnt = 0;
1391        smpidx = 0;
1392        while  (fgets(line,cBcLineLth,fp) != NULL)  {
1393                if  (sscanf(line+4,"%s %f %f %f %f %f",
1394                        timestr,&qual,&slo,&baz,&relpow,&abspow) != 6)  {
1395                        fprintf( stderr, "%s: error reading file %s\n", msv_pname, detfile );
1396                        exit( 1 );
1397                } /*endif*/
1398                if  (debug)  printf( "%s %d  ", timestr, 8-lcnt );
1399                reltime = tc_tdiff( timestr, msv_abstime, &status );
1400                if  (SySevere(&status))  {
1401                        fprintf( stderr, "%s: error converting time in %s\n",
1402                                msv_pname, detfile );
1403                        exit( 1 );
1404                } /*endif*/
1405                negslow = FALSE;
1406                bazdiff = fabs( baz - thbaz );
1407                if  (bazdiff > 180.0)  bazdiff = fabs(bazdiff - 360.0);
1408                if  (bazdiff > 90.0)  {
1409                        bazdiff = fabs(bazdiff - 180.0);
1410                        negslow = TRUE;
1411                } /*endif*/
1412                do_output = (reltime >= 0.0);
1413                if  (debug)  printf( "%d", do_output );
1414                do_output = do_output && (reltime < msv_area.timewidth);
1415                if  (debug)  printf( "%d", do_output );
1416                do_output = do_output && (qual > detpar->minqual);
1417                if  (debug)  printf( "%d", do_output );
1418                if  (slo > 1.5)  {
1419                        do_output = do_output && (bazdiff < detpar->aztol );
1420                } else if  (slo > 1.0)  {
1421                        do_output = do_output && (bazdiff < 2.0*(detpar->aztol) );
1422                } /*endif*/
1423                if  (debug)  printf( "%d", do_output );
1424                if  (msv_area.minslow != 0.0 && negslow)  slo = -slo;
1425                do_output = do_output && (slo < (msv_area.minslow+msv_area.slowheight));
1426                if  (debug)  printf( "%d", do_output );
1427                if  (msv_area.minslow != 0.0)
1428                        do_output = do_output && (slo > msv_area.minslow);
1429                if  (debug)  printf( "%d", do_output );
1430                do_output = do_output && (relpow > detpar->minrelpow);
1431                if  (debug)  printf( "%d", do_output );
1432                do_output = do_output && (abspow > detpar->minabspow);
1433                if  (debug)  printf( "%d", do_output );
1434                if  (qual > detpar->maxqual)  qual = detpar->maxqual;
1435                eval = detpar->m_q * qual + detpar->m_r * relpow + detpar->m_a * abspow
1436                        + detpar->m_qr * qual * relpow + detpar->m_qa * qual * abspow
1437                        + detpar->m_ra * relpow * abspow + detpar->m_qra * qual * relpow * abspow;
1438                /* remove average of the last n values */
1439                smpcnt++;
1440                if (smpcnt <= detpar->eval_avlth)  {
1441                        if  (smpcnt == 1)  {
1442                                movav = eval;
1443                        } else {
1444                                movav = (movav*(float)(smpcnt-1) + eval) / (float)smpcnt;
1445                        } /*endif*/
1446                        smpbuf[smpidx++] = eval;
1447                } else {
1448                        i = smpidx - detpar->eval_avlth;
1449                        if  (i < 0)  i += detpar->eval_avlth;
1450                        movav += eval/(float)(detpar->eval_avlth)
1451                                - smpbuf[i]/(float)(detpar->eval_avlth);
1452                        if  (smpidx >= detpar->eval_avlth)  smpidx = 0;
1453                        smpbuf[smpidx++] = eval;
1454                } /*endif*/
1455                eval -= movav;
1456                if  (MsfDUMPEVAL & msv_flags)
1457                        printf( "%s %d %g\n", timestr, 8-lcnt, eval );
1458                do_output = do_output && (eval >= detpar->mineval);
1459                if  (do_output)  {
1460                        /*printf( "%f %e %f %f\n", reltime, qual, slo, baz );*/
1461                        if  (MsfXWDW & msv_flags)  {
1462                                ms_trafo( reltime, slo+detpar->sloint, &ixa, &iya );
1463                                ms_trafo( reltime+dt, slo-detpar->sloint, &ixb, &iyb );
1464                                wd = ixb - ixa;
1465                                if  (wd < 1)  wd = 1;
1466                                hg = iyb - iya;
1467                                if  (hg < 1)  hg = 1;
1468                                pix_FillRectangle( XtDisplay(w), XtWindow(w), detpar->gc,
1469                                        ixa, iya, wd, hg );
1470                        } /*endif*/
1471                        if  (MsfGMT & msv_flags)  {
1472                                float wd;  /* width */
1473                                if  (lcnt == 7)  wd = 0.05;
1474                                else if  (lcnt > 3 && lcnt < 7)  wd = 0.1;
1475                                else  wd = 0.15;
1476                                printf( "%f %f %f\n", reltime, slo, wd );
1477                        } /*endif*/
1478                } /*endif*/
1479                if  (debug)  printf( "\n" );
1480        } /*endwhile*/
1481
1482        if  (MsfGMT & msv_flags)  {
1483                printf( "END\n" );
1484        } /*endif*/
1485
1486        fclose( fp );
1487
1488        /* legend */
1489        if  (MsfXWDW & msv_flags)  {
1490                XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h,
1491                        &border, &depth );
1492                ixa = w_w - LEGENDWIDTH;
1493                pix_FillRectangle( XtDisplay(w), XtWindow(w), detpar->gc,
1494                        ixa, ypos, 5, 5 );
1495                pix_DrawString( XtDisplay(w), XtWindow(w), msv_gl[MscBLACK],
1496                        ixa+8, ypos+5, detpar->text, strlen(detpar->text) );
1497                ypos -= 20;
1498        } /*endif*/
1499
1500        lcnt++;
1501
1502} /* end of ms_put_detfile */
1503
1504
1505
1506/*--------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.