source: SH_SHM/trunk/source/motif/motifgraph.c @ 344

Revision 344, 121.0 KB checked in by marcus, 13 years ago (diff)

r183 | walther | 2011-03-10 15:03:12 +0100 (Do, 10 Mär 2011) | 1 line

Added configuration parameter show_evt_info

Line 
1
2/* file motifgraph.c
3 *      ============
4 *
5 * version 63, 11-Jan-2007
6 *
7 * trace display manager
8 * K. Stammler, 18-Feb-93
9 */
10
11
12/*
13 *
14 *  SeismicHandler, seismic analysis software
15 *  Copyright (C) 1996,  Klaus Stammler, Federal Institute for Geosciences
16 *                                       and Natural Resources (BGR), Germany
17 *
18 *  This program is free software; you can redistribute it and/or modify
19 *  it under the terms of the GNU General Public License as published by
20 *  the Free Software Foundation; either version 2 of the License, or
21 *  (at your option) any later version.
22 *
23 *  This program is distributed in the hope that it will be useful,
24 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 *  GNU General Public License for more details.
27 *
28 *  You should have received a copy of the GNU General Public License
29 *  along with this program; if not, write to the Free Software
30 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
31 *
32 */
33
34
35#include <stdio.h>
36#include <string.h>
37#include <math.h>
38#include "basecnst.h"
39#undef BC_DEFINE_TRUE_FALSE
40#ifdef BC_INC_STDLIB
41#include BC_INC_STDLIB
42#endif
43#include <Xm/Xm.h>
44#include <Mrm/MrmPublic.h>
45#include <X11/cursorfont.h>
46#include BC_SYSBASE
47#include "infoidx.h"
48#include "fctxdm.h"
49#include "trusrdef.h"
50#include "tcusrdef.h"
51#include "ffusrdef.h"
52#include "phaseinf.h"
53#include "phasemgr.h"
54#include "pixmaps.h"
55#include "motifgraph.h"
56#include "trcselect.h"
57#include "globalparams.h"
58
59
60#define MGC_CHMAP 0
61        /* gc_... channel map (for module shdataba.c) */
62#define WAVE_DRAW 1
63#define WAVE_CLEAR 2
64#define WAVE_SIGN 3
65#define WAVE_HILB 4
66
67
68/* text positions of status printouts, y-position realtive to margin_t */
69#define TEXT_X_TIME 20
70#define TEXT_Y_TIME 0
71#define TEXT_X_FILTER 235
72#define TEXT_Y_FILTER 0
73#define TEXT_X_SORT 350
74#define TEXT_Y_SORT 0
75#define TEXT_X_DETEC 56
76#define TEXT_Y_DETEC (-25)
77#define TEXT_X_STATUS 400
78#define TEXT_Y_STATUS 0
79#define TEXT_X_LASTCMD 620
80#define TEXT_Y_LASTCMD 0
81#define TEXT_X_BUSY 800
82#define TEXT_Y_BUSY 0
83#define TEXT_Y_SPAN_SINGLE 20
84
85/* flag value for plot-single routine not to use 3-trace display */
86#define NO3TRACES -30000
87
88/* maximum number of windows where cursor form may be changed */
89#define MAXCRSRDSP 5
90
91
92/* trace X Environment (display parameters) */
93typedef struct {
94        GC          gc;     /* graphics context */
95        XFontStruct *font;  /* font pointer */
96        XPoint      orig;   /* origin */
97} MGT_TRCXENV;
98
99typedef struct {
100        MGT_TRCXENV    *xenv;    /* drawing parameters */
101        float          zoom;     /* zoom factor */
102        float          maxampl;  /* maximum amplitude on trace */
103        float          *smp;     /* pointer to sample data */
104        long           length;   /* number of samples to plot */
105        float          dt;       /* sample distance */
106        void           *trc;     /* trace pointer */
107} MGT_TRCINFO;
108
109typedef struct {
110        int      trcno;       /* number of traces */
111        float    maxampl;     /* maximum amplitude */
112        float    totslth;     /* total length in seconds */
113        long     totnlth;     /* total length in samples */
114        float    unitheight;  /* height per trace in pixels */
115        float    pixpersec;   /* horizontal scaling (pixels/second) */
116        int      wdweff_w;    /* effective window width */
117        int      wdweff_h;    /* effective window height */
118        int      wdweff_x;    /* x-offset of effective window */
119        int      wdweff_y;    /* y-offset of effective window */
120        int      wdw_w;       /* total window width */
121        int      wdw_h;       /* total window height */
122        BOOLEAN  tw_set;      /* time window set */
123        float    tw_start;    /* start of time window */
124        float    tw_end;      /* end of time window */
125        int      type;        /* window type (main or single trace) */
126} MGT_DSPINFO;
127
128typedef struct {
129        int      margin_r;    /* right margin */
130        int      margin_l;    /* left margin */
131        int      margin_t;    /* top margin */
132        int      margin_b;    /* bottom margin */
133} MGT_WDWSETUP;
134
135/* axis descriptor */
136typedef struct {
137        BOOLEAN  init;          /* structure initialized ? */
138        BOOLEAN  plot;          /* plot axis ? */
139        float    vpos;          /* vertical position */
140        float    line_s;        /* start position of axis line */
141        float    line_e;        /* end position of line */
142        float    tick_s;        /* position of first tick */
143        float    tick_intv;     /* interval between ticks */
144        float    lab1val;       /* value of first label */
145        float    lab_intv;      /* label interval */
146        int      lab1cnt;       /* number of first labelled tick */
147        int      labcnt;        /* every "labcnt"-th tick is labelled */
148        int      tick_lth;      /* length of an unlabelled tick in pixel */
149        int      ltick_lth;     /* length of a labelled tick in pixel */
150        float    labshift;      /* tick-relative (x-) position of label */
151        float    labdist;       /* distance of label from axis */
152        GC       style;         /* axis style */
153        char     labfmt[16];    /* format string of label */
154        BOOLEAN  use_abstime;   /* use absolute time */
155        TIME     abstime;       /* absolute time */
156} MGT_AXIS;
157
158typedef struct {
159        int      x1, y1;    /* lower left corner */
160        int      x2, y2;    /* upper right corner */
161        BOOLEAN  on;        /* box drawn */
162} MGT_DRAGBOX;
163
164
165
166/* prototypes of local routines */
167static MGT_TRCXENV *mg_create_trcxenv( Widget w, STATUS *status );
168static MGT_TRCINFO *mg_trcsetup( Widget w, MGT_DSPINFO *di, STATUS *status );
169static void mgh_plot_traces( Widget w, MGT_DSPCTRL *ctrl, MGT_DSPINFO *di,
170        MGT_TRCINFO *ti, STATUS *status );
171static void mg_haxis( Widget w, MGT_AXIS *ax, MGT_DSPINFO *di );
172static void mg_autoaxis( float start, float end, int labelmul, float *ticks,
173        float *ticki, float *labs, float *labi, int *labelcnt );
174static void mg_print_trcinfo( Widget w, MGT_DSPINFO *di, MGT_TRCINFO ti[],
175        STATUS *status );
176static void mg_print_s_trcinfo( Widget w, MGT_DSPINFO *di, MGT_TRCINFO ti[],
177        int t, int pixoff, STATUS *status );
178static void mgh_wave_cursor( Widget w, int mode, MGT_DSPINFO *di,
179        MGT_DSPCTRL *ctrl, int px, int py );
180static void mgh_get_pixelpos_single( int trcno, float time, int *x, int *y,
181        BOOLEAN *ok );
182static void mgh_find_phase( int trcno, float reftime, float resol,
183        TPiPhase *phase, BOOLEAN *found );
184static void mgh_get_colormap( Screen *s );
185static void mgh_init_graphic_contexts( Widget w, BOOLEAN *ok );
186static void mgh_plot_bold( Widget w, MGT_DSPCTRL *ctrl, MGT_DSPINFO *di,
187        MGT_TRCINFO *ti, long startidx, long wdwlth, MGT_GRAPHIC_INTERP *ip,
188        STATUS *status );
189static void mgh_mark_selected_trace( Widget w, unsigned number );
190static void mgh_set_fg_color( Display *dsp, GC gc, unsigned long fg );
191static void mgh_set_bg_color( Display *dsp, GC gc, unsigned long bg );
192static void mgh_label_rounding( float accuracy, TIME *atime );
193
194
195
196/* global variables */
197static MGT_WDWSETUP    mgv_wdwsetup;                    /* window parameters */
198static MGT_AXIS        mgv_t_axis;                         /* main time axis */
199static MGT_AXIS        mgv_ts_axis;                /* single trace time axis */
200static MGT_TRCINFO     *mgv_ti=NULL;   /* current trace info's (mg_trcsetup) */
201static MGT_DSPINFO     mgv_di;           /* display info, set by mg_trcsetup */
202static MGT_DSPINFO     mgv_sdi;           /* info about single trace display */
203static BOOLEAN         mgv_gc_init=FALSE;                /* GC`s initialized */
204static GC              mgv_mark_gc;           /* line attributes for marking */
205static GC              mgv_mark0_gc;     /* attributes for marking quality 0 */
206static GC              mgv_theo_gc;      /* line attributes for theo marking */
207static GC              mgv_auto_gc;      /* line attributes for auto marking */
208static GC              mgv_xor_gc;                       /* for XOR drawings */
209static GC              mgv_single_gc;           /* for single trace drawings */
210static GC              mgv_single2_gc;          /* for single trace drawings */
211static GC              mgv_single3_gc;          /* for single trace drawings */
212static GC              mgv_phase_gc;                        /* phase markers */
213static GC              mgv_over_gc;                          /* overwrite GC */
214static GC              mgv_clear_gc;                             /* clear GC */
215static GC              mgv_trcalert_gc;                    /* alert trace GC */
216static GC              mgv_addfil_gc;          /* additional filter alert GC */
217static MGT_DRAGBOX     mgv_drag;                                 /* drag box */
218static BOOLEAN         mgv_phase_sel;   /* phase cursor active (mg_do_phase) */
219static BOOLEAN         mgv_colored;                     /* screen is colored */
220static Colormap        mgv_cmap;                                /* color map */
221static char            mgv_filter[BC_LINELTH+1];              /* filter name */
222static BOOLEAN         mgv_reverse_xors=FALSE; /* rev. back/foregr. on XOR's */
223static Font            mgv_fixed_font=(Font)0;      /* fixed font to be used */
224static BOOLEAN         mgv_disable_rd=FALSE;   /* disables redraw of display */
225static BOOLEAN         mgv_show_3_traces=FALSE;  /* 3 trcs in single trc wdw */
226static Cursor          mgv_crsr[MGC_XCRSR_MAX+1];           /* mouse cursors */
227static Widget          mgv_crsrdsp[MAXCRSRDSP];      /* drawing area widgets */
228static int             mgv_crsrdspnum=0;            /* length of above array */
229                                          /* min/max in single trace display */
230
231
232
233/*----------------------------------------------------------------------------*/
234
235
236
237void mg_init_tracedisplay( Widget w, int r, int l, int t, int b )
238
239/* initializes display parameters.  Input r,l,t,b valid only if >=0.
240 *
241 * parameters of routine
242 * Widget     w;           input; Widget of trace display (DrawingArea)
243 * int        r, l, t, b;  input; right, left, top, bottom margin in pixel
244 */
245{
246        /* executable code */
247
248        mgv_wdwsetup.margin_r = (r < 0) ? 50 : r;
249        mgv_wdwsetup.margin_l = (l < 0) ? 80 : l;
250        mgv_wdwsetup.margin_t = (t < 0) ? 20 : t; /*50*/;
251        mgv_wdwsetup.margin_b = (b < 0) ? 50 : b;
252
253} /* end of mg_init_tracedisplay */
254
255
256
257/*----------------------------------------------------------------------------*/
258
259
260
261void mg_set_reverse_xors( BOOLEAN val )
262
263/* on some screens XOR GC's should use reversed background/foreground
264 *
265 * parameters of routine
266 * BOOLEAN    val;       input; reverse XOR's or not
267 */
268{
269        /* executable code */
270
271        mgv_reverse_xors = val;
272
273} /* end of mg_set_reverse_xors */
274
275
276
277/*----------------------------------------------------------------------------*/
278
279
280
281void mg_show_3_traces( BOOLEAN val )
282
283/* Switch on/off 3 trace display in single trace window
284 *
285 * parameters of routine
286 * BOOLEAN    val;       input; value of switch
287 */
288{
289        /* executable code */
290
291        mgv_show_3_traces = val;
292
293} /* end of mg_show_3_traces */
294
295
296
297/*----------------------------------------------------------------------------*/
298
299
300
301void mg_tracedisplay( Widget w, MGT_DSPCTRL *ctrl, STATUS *status )
302
303/* draws traces on DrawingArea "w"
304 *
305 * parameters of routine
306 * Widget        w;         input; DrawingArea Widget
307 * MGT_DSPCTRL   *ctrl;     input; display control parameters
308 * STATUS        *status;   output; return status
309 *
310 * changes global variables mgv_di, mgv_ti.
311 */
312{
313        /* local variables */
314        TIME     abstime;             /* absolute time for time axis */
315        STATUS   locstat=BC_NOERROR;  /* local status variable */
316
317        /* executable code */
318
319        if  (mgv_ti != NULL)  sy_deallocmem( mgv_ti );
320        mgv_ti = mg_trcsetup( w, &mgv_di, status );
321        mgv_di.type = MGC_WDW_MAIN;
322        if  (GpGetInt(cGpI_debug_level) > 4)
323                printf( "SHM-dgb5: mgv_ti set to %x\n", mgv_ti );
324        if  (Severe(status))  return;
325
326        pix_set_max_drawlth( GpGetInt(cGpI_x_max_drawlth) );
327        pix_ClearWindow( XtDisplay(w), XtWindow(w) );
328        if  (mgv_di.trcno == 0)  {
329                if  (mgv_ti != NULL)  sy_deallocmem( mgv_ti );
330                mgv_ti = NULL;
331                if  (GpGetInt(cGpI_debug_level) > 4)
332                        printf( "SHM-dgb5: mgv_ti set to NULL\n" );
333                mg_draw_cursor( w, MGC_WDW_MAIN, ctrl, MGC_CRSR_REFRESH, 0, 0, NULL );
334                return;
335        } /*endif*/
336
337        db_gett( mgv_ti[0].trc, ET_START, &abstime, &locstat );
338        mgv_t_axis.abstime = abstime;
339        tc_aadd( &mgv_t_axis.abstime, -db_getr(mgv_ti[0].trc,ER_TORIG,&locstat),
340                &mgv_t_axis.abstime );
341        mgv_t_axis.use_abstime = (locstat == BC_NOERROR);
342        mg_haxis( w, &mgv_t_axis, &mgv_di );
343        mg_print_trcinfo( w, &mgv_di, mgv_ti, status );
344        if  (Severe(status))  {
345                sy_deallocmem( mgv_ti );
346                mgv_ti = NULL;
347                mg_draw_cursor( w, MGC_WDW_MAIN, ctrl, MGC_CRSR_REFRESH, 0, 0, NULL );
348                if  (GpGetInt(cGpI_debug_level) > 4)
349                        printf( "SHM-dgb5: mgv_ti set to NULL (2)\n" );
350                return;
351        } /*endif*/
352        if  (!mgv_disable_rd)
353                mgh_plot_traces( w, ctrl, &mgv_di, mgv_ti, status );
354        if  (Severe(status))  {
355                sy_deallocmem( mgv_ti );
356                mgv_ti = NULL;
357                mg_draw_cursor( w, MGC_WDW_MAIN, ctrl, MGC_CRSR_REFRESH, 0, 0, NULL );
358                if  (GpGetInt(cGpI_debug_level) > 4)
359                        printf( "SHM-dgb5: mgv_ti set to NULL (3)\n" );
360                return;
361        } /*endif*/
362        if  (!mgv_disable_rd)
363                mg_plot_phases( w, ctrl->show_phase_acc, status );
364
365        mg_do_drag( w, MGC_DRAG_REFRESH, 0, 0 );
366        mg_draw_cursor( w, MGC_WDW_MAIN, ctrl, MGC_CRSR_REFRESH, 0, 0, NULL );
367        mg_do_phase( w, MGC_WDW_MAIN, MGC_PHASE_REFRESH, 0, 0, NULL, NULL, NULL );
368        mg_print_filter( w, mgv_filter );
369        mg_print_detecinfo( w, "--redraw--" );
370
371        XFlush( XtDisplay(w) );
372
373} /* end of mg_tracedisplay */
374
375
376
377/*----------------------------------------------------------------------------*/
378
379
380
381static MGT_TRCXENV *mg_create_trcxenv( Widget w, STATUS *status )
382
383/* creates display parameter block for a new trace
384 *
385 * parameters of routine
386 * Widget     w;          input; Widget ID
387 * STATUS     *status;    output; return status
388 *                        returns pointer to parameter block
389 */
390{
391        /* local variables */
392        MGT_TRCXENV   *p;     /* pointer to structure */
393
394        /* executable code */
395
396        p = (MGT_TRCXENV *)sy_allocmem( 1, (int)sizeof(MGT_TRCXENV), status );
397        if  (Severe(status))  return NULL;
398
399        p->gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
400        mgh_set_fg_color( XtDisplay(w), p->gc, pix_colour(PIXC_COL_FOREGROUND) );
401        mgh_set_bg_color( XtDisplay(w), p->gc, pix_colour(PIXC_COL_BACKGROUND) );
402        if  (mgv_fixed_font != (Font)0)
403                XSetFont( XtDisplay(w), p->gc, mgv_fixed_font );
404        p->font = XQueryFont( XtDisplay(w), XGContextFromGC(p->gc) );
405
406        return p;
407
408} /* end of mg_create_trcxenv */
409
410
411
412/*----------------------------------------------------------------------------*/
413
414
415
416static MGT_TRCINFO *mg_trcsetup( Widget w, MGT_DSPINFO *di, STATUS *status )
417
418/* returns pointer to array of TRCINFO blocks.  Informations are set
419 * so the traces are ready to be displayed.  The pointer returned should
420 * be freed after displaying the data.
421 *
422 * parameters of routine
423 * Widget        w;          input; widget ID
424 * MGT_DSPINFO   *di;        output; display info
425 * STATUS        *status;    output; return status
426 */
427{
428        /* local variables */
429        MGT_TRCINFO  *p;      /* pointer to structure */
430        void     *trc;        /* current trace pointer */
431        int      t;           /* trace counter */
432        float    y_orig;      /* y origin */
433        float    dt;          /* sample distance im sec */
434        long     firstsmp;    /* first sample to be displayed */
435        float    x_correct;   /* correction of x-position */
436        float    tmp;         /* scratch */
437
438        /* executable code */
439
440        mg_get_windowsize( w, &(di->wdw_w), &(di->wdw_h) );
441        di->wdweff_w = di->wdw_w - mgv_wdwsetup.margin_r -
442                mgv_wdwsetup.margin_l;
443        di->wdweff_h = di->wdw_h - mgv_wdwsetup.margin_b -
444                mgv_wdwsetup.margin_t;
445        if  (di->wdweff_w < 2 || di->wdweff_h < 2)  {
446                printf( "*SHM: zero window ***\n" );
447                di->trcno = 0;
448                return NULL;
449        } /*endif*/
450        di->wdweff_x = mgv_wdwsetup.margin_l;
451        di->wdweff_y = mgv_wdwsetup.margin_t/*b*/;
452
453        dm_get_timewdw( &(di->tw_start), &(di->tw_end) );
454        di->tw_set = (di->tw_start != 0.0 || di->tw_end != 0.0);
455
456        di->trcno = db_dsplth( MGC_CHMAP );
457        if  (di->trcno == 0)  return NULL;
458
459        di->unitheight = (float)(di->wdweff_h) / (float)(di->trcno);
460
461        p = (MGT_TRCINFO *)sy_allocmem( di->trcno, (int)sizeof(MGT_TRCINFO),
462                status );
463        if  (Severe(status))  return NULL;
464
465        if  (GpGetBoolean(cGpB_top_down_order))  {
466                y_orig = mgv_wdwsetup.margin_t/*b*/ + di->unitheight / 2.0;
467        } else {
468                y_orig = mgv_wdwsetup.margin_t/*b*/ + di->unitheight / 2.0 +
469                        di->unitheight * (float)(di->trcno-1);
470        } /*endif*/
471        di->maxampl = 0.0;
472        di->totslth = 0.0;
473        di->totnlth = 0;
474        for  (t=0; t<(di->trcno); t++)  {
475                if  (t == 0)  {
476                        trc = db_dspfirst( MGC_CHMAP, NULL );
477                } else {
478                        trc = db_getp( trc, EP_DSPN, NULL );
479                } /*endif*/
480                p[t].trc = trc;
481                p[t].xenv = (MGT_TRCXENV *)db_getp( trc, EP_USR1, NULL );
482                if  (p[t].xenv == NULL)  {
483                        p[t].xenv = mg_create_trcxenv( w, status );
484                        if  (Severe(status))  {
485                                sy_deallocmem( p );
486                                return NULL;
487                        } /*endif*/
488                        if  (db_getf(trc,EF_NOCALIB,NULL) || db_getf(trc,EF_QUAL,NULL))
489                                p[t].xenv->gc = mgv_trcalert_gc;
490                        db_setp( trc, EP_USR1, p[t].xenv, status );
491                        if  (Severe(status))  {
492                                sy_deallocmem( p );
493                                return NULL;
494                        } /*endif*/
495                } /*endif*/
496                p[t].zoom = db_getr( trc, ER_ZOOM, NULL );
497                tmp = db_getr( trc, ER_MINVAL, NULL );
498                p[t].maxampl = db_getr( trc, ER_MAXVAL, NULL );
499                tmp = Abs( tmp );
500                p[t].maxampl = Abs( p[t].maxampl );
501                if  (tmp > p[t].maxampl)  p[t].maxampl = tmp;
502                /*
503                p[t].smp = (float *)db_getp( trc, EP_DATA, NULL );
504                p[t].length = db_getl( trc, EL_LENGTH, NULL );
505                */
506                p[t].smp = (float *)db_getp( trc, EP_DATA, NULL ) +
507                        db_getl( trc, EL_DSPFST, NULL );
508                p[t].length = db_getl( trc, EL_DSPCNT, NULL );
509                p[t].dt = db_getr( trc, ER_DELTA, NULL );
510                p[t].xenv->orig.y = Nint( y_orig );
511                /* x-orig is set below in separate loop */
512                if  (GpGetBoolean(cGpB_top_down_order))  {
513                        y_orig += di->unitheight;
514                } else {
515                        y_orig -= di->unitheight;
516                } /*endif*/
517                tmp = Abs( p[t].maxampl );
518                if  (tmp > di->maxampl)  di->maxampl = tmp;
519#ifdef XXX
520                tmp = (float)(p[t].length) * (float)(p[t].dt);
521                if  (!di->tw_set)
522                        tmp += db_getr( trc, ER_TORIG, NULL );
523                if  (tmp > di->totslth)  di->totslth = tmp;
524#endif
525                if  (p[t].length > di->totnlth)  di->totnlth = p[t].length;
526        } /*endfor*/
527
528        dm_dspcoo( NULL, NULL, &(di->totslth), NULL );
529        di->pixpersec = (float)(di->wdweff_w)/di->totslth;
530
531        /* set x-origins */
532        for  (t=0; t<(di->trcno); t++)  {
533                firstsmp = db_getl( p[t].trc, EL_DSPFST, status );
534                if  (Severe(status))  {sy_deallocmem(p); return NULL;}
535                if  (firstsmp > 0)  {
536                        dt = db_getr( p[t].trc, ER_DELTA, status );
537                        if  (Severe(status))  {sy_deallocmem(p); return NULL;}
538                        x_correct = (float)firstsmp*dt +
539                                db_getr(p[t].trc,ER_TORIG,status) - di->tw_start;
540                        if  (Severe(status))  {sy_deallocmem(p); return NULL;}
541                        if  (GpGetInt(cGpI_debug_level) > 0)
542                                if  (Abs(x_correct) > dt)
543                                        printf( "SHM-dbg1: x_correct %f, dt %f, trc %d\n", x_correct, dt, t+1 );
544                        p[t].xenv->orig.x = mgv_wdwsetup.margin_l +
545                                Nint(x_correct*(di->pixpersec));
546                } else {
547                        if  (di->tw_set)  {
548                                tmp = di->tw_start;
549                        } else {
550                                dm_dspcoo( &tmp, NULL,NULL,NULL );
551                        } /*endif*/
552                        p[t].xenv->orig.x = mgv_wdwsetup.margin_l +
553                                Nint((db_getr(p[t].trc,ER_TORIG,NULL) - tmp) *
554                                di->pixpersec);
555                } /*endif*/
556        } /*endfor*/
557
558        return p;
559
560} /* end of mg_trcsetup */
561
562
563
564/*----------------------------------------------------------------------------*/
565
566
567
568void mg_get_windowsize( Widget w, int *width, int *height )
569
570/* returns size of window in pixels
571 *
572 * parameters of routine
573 * Widget     w;         input; widget ID
574 * int        *width;    output; window width
575 * int        *height;   output; window height
576 */
577{
578        /* local variables */
579        Window   root_ret;   /* root window */
580        int      x, y;       /* position within root window */
581        unsigned bw, dp;     /* border width & depth */
582        unsigned xw, xh;
583
584        /* executable code */
585
586        XGetGeometry( XtDisplay(w), XtWindow(w), &root_ret, &x, &y, &xw, &xh, &bw, &dp );
587        *width = xw;
588        *height = xh;
589
590} /* end of mg_get_windowsize */
591
592
593
594/*----------------------------------------------------------------------------*/
595
596
597
598static void mgh_plot_traces( Widget w, MGT_DSPCTRL *ctrl, MGT_DSPINFO *di,
599        MGT_TRCINFO *ti, STATUS *status )
600
601/* plots traces in drawing area
602 *
603 * parameters of routine
604 * Widget        w;        input; widget ID
605 * MGT_DSPCTRL   *ctrl;    input; display control parameters
606 * MGT_DSPINFO   *di;      input; display info
607 * MGT_TRCINFO   *ti;      input; trace infos
608 * STATUS        *status;  output; return status
609 */
610{
611        /* local variables */
612        Display  *dsp;        /* Display */
613        Window   *wdw;        /* window */
614        XPoint   *pxy;        /* plot array */
615        XPoint   *p;          /* movin pointer */
616        float    *dat;        /* sample pointer */
617        int      t;           /* trace counter */
618        long     s;           /* sample counter */
619        float    vnorm;       /* vertical normalization */
620        float    xinc;        /* x increment */
621        int      xoff, yoff;  /* trace origin */
622        long     efflth;      /* effective length */
623        int      oldx, oldy;  /* last coordinates */
624        int      newx, newy;  /* new coordinates */
625        unsigned filent;      /* additional filter entry */
626        char     filname[cBcFileLth+1]; /* additional filter name */
627        TSyStatus locstat;    /* local status */
628        GC       locgc;       /* local GC */
629
630        /* executable code */
631
632        dsp = XtDisplay( w );
633
634        if  (di->totslth == 0.0 || di->totnlth == 0)  {
635                if  (GpGetInt(cGpI_debug_level) > 0)
636                        printf( "SHM-dbg1: zero display window\n" );
637                return;
638        } /*endif*/
639
640        pxy = (XPoint *)sy_allocmem( di->totnlth, (int)sizeof(XPoint), status );
641        if  (Severe(status))  return;
642
643        /* get index number of filter entry */
644        db_ident( "FILTER", &filent, status );
645        if  (SySevere(status))  return;
646
647        for  (t=0; t<(di->trcno); t++)  {
648                if  (ti[t].length > 1)  {
649                        p = pxy;
650                        dat = ti[t].smp;
651                        xoff = ti[t].xenv->orig.x;
652                        yoff = ti[t].xenv->orig.y;
653                        xinc = (float)(di->wdweff_w)/di->totslth * ti[t].dt;
654                        vnorm = db_getr( ti[t].trc, ER_NORM, NULL );
655                        vnorm *= db_getr( ti[t].trc, ER_ZOOM, NULL );
656                        vnorm *= di->unitheight * ctrl->zoom;
657                        efflth = 1;
658                        oldx = p->x = xoff;
659                        oldy = p->y = yoff - Nint( *dat * vnorm );
660                        p++; dat++;
661                        for  (s=1; s<(ti[t].length); s++)  {
662                                newx = xoff + Nint( s*xinc );
663                                newy = yoff - Nint( *dat * vnorm );
664                                if  (newx != oldx || newy != oldy)  {
665                                        p->x = newx;
666                                        p->y = newy;
667                                        p++;
668                                        efflth++;
669                                        oldx = newx;
670                                        oldy = newy;
671                                } /*endif*/
672                                dat++;
673                        } /*endfor*/
674                        /* check for additional file, mark trace with addfilgc, */
675                        locstat = cBcNoError;
676                        db_gets( ti[t].trc, filent, cBcFileLth, filname, &locstat );
677                        if  (locstat == cBcNoError && *filname != '\0')  {
678                                locgc = mgv_addfil_gc;
679                        } else {
680                                locgc = ti[t].xenv->gc;
681                        } /*endif*/
682                        pix_DrawLines( dsp, XtWindow(w), locgc, pxy, efflth,
683                                CoordModeOrigin );
684                } /*endif*/
685        } /*endfor*/
686
687        sy_deallocmem( pxy );
688
689} /* end of mgh_plot_traces */
690
691
692
693/*----------------------------------------------------------------------------*/
694
695
696
697void mg_plot_bold( Widget wm, Widget ws, MGT_DSPCTRL *ctrl, int wdwno,
698        int trcno, long startidx, long wdwlth, MGT_GRAPHIC_INTERP *ip,
699        STATUS *status )
700
701/* plots part of a trace bold in drawing area
702 *
703 * parameters of routine
704 * Widget        wm;       input; widget ID of main drawing area
705 * Widget        ws;       input; widget ID of single trace drawing area
706 * MGT_DSPCTRL   *ctrl;    input; display control
707 * int           wdwno;    input window number
708 * int           trcno;    input; trace number
709 * long          startidx; input; start index of trace
710 * long          wdwlth;   input; window length in samples
711 * MGT_GRAPHIC_INTERP *ip; input; graphic interpolation
712 * STATUS        *status;  output; return status
713 */
714{
715        /* executable code */
716
717        trcno--;
718        if  (trcno >= mgv_di.trcno || trcno < 0)  {
719                printf("*SHM: mg_plot_bold: illegal trace (bug in program)***\n");
720                return;
721        } /*endif*/
722
723        if  (wdwno == MGC_WDW_MAIN)  {
724                mgh_plot_bold( wm, ctrl, &mgv_di, mgv_ti+trcno, startidx,
725                        wdwlth, ip, status );
726        } else if  (wdwno == MGC_WDW_SINGLE)  {
727                mgh_plot_bold( ws, ctrl, &mgv_sdi, mgv_ti+trcno, startidx,
728                        wdwlth, ip, status );
729        } else {
730                printf( "*SHM: mg_plot_bold: this cannot happen ***\n" );
731                return;
732        } /*endif*/
733
734} /* end of mg_plot_bold */
735
736
737
738/*----------------------------------------------------------------------------*/
739
740
741
742static void mgh_plot_bold( Widget w, MGT_DSPCTRL *ctrl, MGT_DSPINFO *di,
743        MGT_TRCINFO *ti, long startidx, long wdwlth, MGT_GRAPHIC_INTERP *ip,
744        STATUS *status )
745
746/* plots part of a trace bold in drawing area
747 *
748 * parameters of routine
749 * Widget        w;        input; widget ID
750 * MGT_DSPCTRL   *ctrl;    input; display control parameters
751 * MGT_DSPINFO   *di;      input; display info
752 * MGT_TRCINFO   *ti;      input; trace info
753 * long          startidx; input; start index
754 * long          wdwlth;   input; length of trace window
755 * MGT_GRAPHIC_INTERP *ip; input; graphic interpolation
756 * STATUS        *status;  output; return status
757 */
758{
759        /* local variables */
760        Display  *dsp;        /* Display */
761        Window   *wdw;        /* window */
762        XPoint   *pxy;        /* plot array */
763        XPoint   *p;          /* moving pointer */
764        float    *dat;        /* sample pointer */
765        long     s;           /* sample counter */
766        float    vnorm;       /* vertical normalization */
767        float    xinc;        /* x increment */
768        int      xoff, yoff;  /* trace origin */
769        long     efflth;      /* effective length */
770        int      oldx, oldy;  /* last coordinates */
771        int      newx, newy;  /* new coordinates */
772        long     trclth;      /* length of trace in single trace window */
773        float    maxval;      /* maximum value in single trace window */
774        float    meanval;     /* mean value in single trace window */
775        GC       bold_gc;     /* bold GC */
776        XGCValues gc_val;     /* GC values */
777        int      i;           /* counter */
778        int      xstatus;     /* X return value */
779        XColor   screen_color, exact_color;  /* colors */
780
781        /* executable code */
782
783        dsp = XtDisplay( w );
784
785        if  (di->totslth == 0.0)  {
786                if  (GpGetInt(cGpI_debug_level) > 0)
787                        printf( "SHM-dbg1: zero display window\n" );
788                return;
789        } /*endif*/
790
791        pxy = (XPoint *)sy_allocmem( wdwlth, (int)sizeof(XPoint), status );
792        if  (Severe(status))  return;
793
794        bold_gc = XCreateGC( dsp, XtWindow(w), 0, NULL );
795        XCopyGC( dsp, ti->xenv->gc, GCFunction|GCForeground|
796                GCBackground|GCLineWidth|GCLineStyle|GCCapStyle|GCJoinStyle|
797                GCFont, bold_gc );
798        gc_val.line_width = 3;
799        gc_val.cap_style = CapRound;
800        gc_val.join_style = JoinRound;
801        XChangeGC( dsp, bold_gc, GCLineWidth|GCCapStyle|GCJoinStyle, &gc_val );
802        if  (mgv_colored)  {
803                xstatus = XAllocNamedColor( dsp, mgv_cmap, "magenta",
804                        &screen_color, &exact_color );
805                if  (xstatus != 0)
806                        mgh_set_fg_color( XtDisplay(w), bold_gc,
807                                screen_color.pixel );
808        } /*endif*/
809
810        /* get pointer to data at beginning of window */
811        dat = (float *)db_getp( ti->trc, EP_DATA, NULL );
812        if  (di->tw_set)
813                dat += dm_getsample( ti->trc, di->tw_start, TRUE );
814
815        xinc = (float)(di->wdweff_w)/di->totslth * ti->dt;
816        if  (di->type == MGC_WDW_MAIN)  {
817                xoff = ti->xenv->orig.x + Nlong( startidx * xinc );
818                yoff = ti->xenv->orig.y;
819                meanval = 0.;
820                vnorm = db_getr( ti->trc, ER_NORM, NULL );
821                vnorm *= db_getr( ti->trc, ER_ZOOM, NULL );
822                vnorm *= di->unitheight * ctrl->zoom;
823        } else {
824                startidx += db_getl( ti->trc, EL_DSPFST, NULL );
825                startidx -= dm_getsample( ti->trc, di->tw_start, TRUE );
826                xoff = mgv_sdi.wdweff_x + Nlong( startidx * xinc );
827                yoff = mgv_wdwsetup.margin_t/*b*/ + mgv_sdi.unitheight / 2.0;
828                trclth = dm_getsample( ti->trc, di->tw_end, TRUE );
829                trclth -= dm_getsample( ti->trc, di->tw_start, TRUE ) - 1;
830                if  (trclth < 1)  {
831                        printf( "*SHM: plot_bold: short trace (bug) ***\n" );
832                        XFreeGC( dsp, bold_gc );
833                        sy_deallocmem( pxy );
834                        return;
835                } /*endif*/
836                maxval = Abs( *dat );
837                meanval = 0.;
838                for  (i=1; i<trclth; i++)  {
839                        if  (Abs(dat[i]) > maxval)  maxval = Abs(dat[i]);
840                        meanval += dat[i];
841                } /*endfor*/
842                meanval /= (float)trclth;
843                maxval -= meanval;
844                vnorm = di->unitheight / maxval * 0.5;
845        } /*endif*/
846
847        /* set data pointer to beginning of selection */
848        dat += startidx;
849
850        if  (ti->length > 1)  {
851                p = pxy;
852                /* dat = ti->smp + startidx; */
853                efflth = 1;
854                if  (ip->do_interpolation)  {
855                        oldx = p->x = xoff + ip->frac_1*xinc;
856                        oldy = p->y = yoff - Nint( (ip->ampl_1-meanval)*vnorm );
857                } else {
858                        oldx = p->x = xoff;
859                        oldy = p->y = yoff - Nint( (*dat-meanval) * vnorm );
860                } /*endif*/
861                p++; dat++;
862                for  (s=1; s<wdwlth; s++)  {
863                        newx = xoff + Nint( s*xinc );
864                        newy = yoff - Nint( (*dat-meanval) * vnorm );
865                        if  (newx != oldx || newy != oldy)  {
866                                p->x = newx;
867                                p->y = newy;
868                                p++;
869                                efflth++;
870                                oldx = newx;
871                                oldy = newy;
872                        } /*endif*/
873                        dat++;
874                } /*endfor*/
875                if  (ip->do_interpolation)  {
876                        pxy[efflth-1].x = xoff + Nint( ((float)(wdwlth-1) +
877                                ip->frac_e) * xinc );
878                        pxy[efflth-1].y = yoff -
879                                Nint( (ip->ampl_e-meanval) * vnorm );
880                } /*endif*/
881                pix_DrawLines( dsp, XtWindow(w), bold_gc, pxy, efflth,
882                        CoordModeOrigin );
883        } /*endif*/
884
885        XFreeGC( dsp, bold_gc );
886        sy_deallocmem( pxy );
887
888} /* end of mgh_plot_bold */
889
890
891
892/*------------------------------------------------------------------------*/
893
894
895
896static void mg_haxis( Widget w, MGT_AXIS *ax, MGT_DSPINFO *di )
897
898/* draws a horizontal axis
899 *
900 * parameters of routine
901 * Widget        w;         input; widget of DrawingArea
902 * MGT_AXIS      ax;        input; axis parameter
903 * MGT_DSPINFO   *di;       input; display info
904 */
905{
906        /* local variables */
907        static XFontStruct *font;      /* pointer to font structure */
908        char     label[30];     /* labelling of axis */
909        float    currpos;       /* current position */
910        int      currpos_i;     /* current position in pixels */
911        int      ticklth;       /* current tick length */
912        float    currval;       /* current label value */
913        int      labelcnt;      /* label counter */
914        float    lshift;        /* label shift */
915        float    ldist;         /* label distance */
916        float    lines, linee;  /* axis start & end (in coo's) */
917        float    lines_pos;     /* position of lines */
918        float    linee_pos;     /* position of linee */
919        float    ticks, ticki;  /* tick start & interval */
920        float    labs, labi;    /* label start & interval */
921        int      vertpos;       /* vertical position */
922        float    hnorm;         /* horizontal normalization */
923        int      textw;         /* text width in pixel */
924        int      texth;         /* text height in pixel */
925        TIME     abscurr;       /* current absolute time */
926        STATUS   locstat;       /* local status */
927        int      label_x;       /* x-position of label */
928        int      label_x_end;   /* end of last label */
929
930        /* executable code */
931
932        if  (!ax->init)  {
933                ax->style = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
934                mgh_set_fg_color( XtDisplay(w), ax->style,
935                        pix_colour(PIXC_COL_FOREGROUND) );
936                mgh_set_bg_color( XtDisplay(w), ax->style,
937                        pix_colour(PIXC_COL_BACKGROUND) );
938                if  (mgv_fixed_font != (Font)0)
939                        XSetFont( XtDisplay(w), ax->style, mgv_fixed_font );
940                ax->vpos = di->wdw_h - mgv_wdwsetup.margin_b;  /* di->wdweff_y; */
941                ax->ltick_lth = 10;
942                ax->tick_lth = 5;
943                ax->labcnt = 5;
944                ax->plot = TRUE;
945                strcpy( ax->labfmt, "%3.1f" );
946                ax->init = TRUE;
947                font = XQueryFont( XtDisplay(w),
948                        XGContextFromGC(ax->style) );
949                ax->use_abstime = TRUE;
950        } /*endif*/
951
952        texth = font->ascent + font->descent;
953
954        if  (!(ax->plot))  return;
955
956        ax->vpos = di->wdw_h - mgv_wdwsetup.margin_b;  /* di->wdweff_y; */ /* ins */
957        vertpos = Nint( ax->vpos );
958
959        if  ((ax->line_s == 0.0) && (ax->line_e == 0.0))  {
960                if  (di->tw_set)  {
961                        lines = di->tw_start;
962                        linee = di->tw_end;
963                } else {
964                        /*
965                        lines = 0.0;
966                        linee = di->totslth;
967                        */
968                        dm_dspcoo( &lines, NULL, &linee, NULL );
969                        linee += lines;
970                } /*endif*/
971        } else {
972                lines = ax->line_s;
973                linee = ax->line_e;
974        } /*endif*/
975        if  ((ax->tick_intv == 0.0) && (ax->lab_intv == 0.0))  {
976                mg_autoaxis( lines, linee, ax->labcnt, &ticks, &ticki,
977                        &labs, &labi, &labelcnt );
978        } else {
979                if  (ax->tick_intv == 0.0)  {
980                        ticks = lines;
981                        ticki = (linee-lines) / 10.;
982                } else {
983                        ticks = ax->tick_s;
984                        ticki = ax->tick_intv;
985                } /*endif*/
986                if  (ax->lab_intv == 0.0)  {
987                        labs = ticks;
988                        labi = ticki;
989                } else {
990                        if  (GpGetInt(cGpI_debug_level) > 0)
991                                printf( "SHM-dbg1: undefined lab1val %f5.2 used\n", ax->lab1val );
992                        labs = ax->lab1val;
993                        labi = ax->lab_intv;
994                } /*endif*/
995                labelcnt = ax->lab1cnt;
996        } /*endif*/
997
998        hnorm = di->pixpersec;
999        if  (di->tw_set)  {
1000                lines_pos = lines - di->tw_start;
1001                linee_pos = linee - di->tw_start;
1002        } else {
1003                lines_pos = lines;
1004                linee_pos = linee;
1005        } /*endif*/
1006
1007        pix_DrawLine( XtDisplay(w), XtWindow(w), ax->style,
1008                di->wdweff_x+Nint(hnorm*lines_pos), vertpos,
1009                di->wdweff_x+Nint(hnorm*linee_pos), vertpos );
1010
1011        lshift = ax->labshift;
1012        ldist = ax->labdist;
1013        currval = labs;
1014        label_x_end = SYC_MININT;
1015
1016        for  (currpos=ticks;currpos<=linee; currpos += ticki)  {
1017                currpos_i = di->wdweff_x + Nint( hnorm * (currpos-di->tw_start) );
1018                if  (--labelcnt == 0)  {  /* labelled tick */
1019                        ticklth = ax->ltick_lth;
1020                        labelcnt = ax->labcnt;
1021                        if  (ax->use_abstime)  {
1022                                locstat = BC_NOERROR;
1023                                tc_aadd( &(ax->abstime), currval, &abscurr );
1024                                mgh_label_rounding( ticki*GpGetFloat(cGpF_axis_label_rounding),
1025                                        &abscurr );
1026                                tc_a2t( &abscurr, label, &locstat );
1027                                if  (locstat == BC_NOERROR)  {
1028                                        strncpy( label, label+12, 12 );
1029                                        label[12] = '\0';
1030                                        if  (strcmp(label+8,".000") == 0)
1031                                                label[8] = '\0';
1032                                } else {
1033                                        sprintf( label, ax->labfmt, currval );
1034                                } /*endif*/
1035                        } else {
1036                                sprintf( label, ax->labfmt, currval );
1037                        } /*endif*/
1038                        textw = XTextWidth( font, label, (int)strlen(label) );
1039                        label_x = currpos_i-textw/2+Nint(lshift);
1040                        if  (label_x > label_x_end)  {
1041                                pix_DrawString( XtDisplay(w), XtWindow(w),
1042                                        ax->style, label_x,
1043                                        vertpos+ticklth+texth+Nint(ldist),
1044                                        label, (int)strlen(label) );
1045                                label_x_end = label_x + textw;
1046                        } /*endif*/
1047                } else {
1048                        ticklth = ax->tick_lth;
1049                } /*endif*/
1050                pix_DrawLine( XtDisplay(w), XtWindow(w), ax->style,
1051                        currpos_i, vertpos, currpos_i, vertpos+ticklth );
1052                currval += labi;
1053        } /*endfor*/
1054
1055} /* end of mg_haxis */
1056
1057
1058
1059/*------------------------------------------------------------------------*/
1060
1061
1062
1063static void mg_autoaxis( float start, float end, int labelmul, float *ticks,
1064        float *ticki, float *labs, float *labi, int *labelcnt )
1065
1066/* computes axis parameters
1067 *
1068 * parameters of routine
1069 * float      start;      input; start coo
1070 * float      end;        input; end coo
1071 * int        labelmul;   input; every "labelmul"-th tick is labelled
1072 * float      *ticks;     output; position of first tick
1073 * float      *ticki;     output; interval of ticks
1074 * float      *labs;      output; value of first label
1075 * float      *labi;      output; label interval
1076 * int        *labelcnt;  output; number of first labelled tick
1077 */
1078{
1079        /* local variables */
1080        float    width;    /* width of axis */
1081        int      labnum, ticknum;
1082
1083        /* executable code */
1084
1085        /* compute labelled intervals */
1086        width = end - start;
1087        *labi = pow( 10., floor(log10(width)) );
1088        while  ((width / *labi) < 3.0)
1089                *labi /= 2.0;
1090        *ticki = *labi / (float)labelmul;
1091
1092        if  (start == 0.0)  {
1093                *labs = 0.0;
1094                *labelcnt = 1;
1095        } else if  ((start < 0.0) && (end > 0.0))  {
1096                labnum = Nint(floor((-start+0.01) / *labi));
1097                ticknum = Nint(floor((-start+0.01) / *ticki));
1098                *labelcnt = ticknum - labelmul*labnum + 1;
1099                *labs = -(float)ticknum * (*ticki);
1100        } else if  (start > 0.0)  {
1101                labnum = 1;
1102                while  (((float)labnum * *labi) < start)
1103                        labnum++;
1104                ticknum = labnum * labelmul;
1105                while  (((float)ticknum * *ticki) >= start)
1106                        ticknum--;
1107                *labelcnt = labelmul*labnum - (++ticknum) + 1;
1108                *labs = (float)ticknum * (*ticki);
1109        } else {
1110                labnum = -1;
1111                while  (((float)labnum * *labi) >= start)
1112                        labnum--;
1113                ticknum = ++labnum * labelmul;
1114                while  (((float)ticknum * *ticki) >= start)
1115                        ticknum--;
1116                *labelcnt = labelmul*labnum - (++ticknum) + 1;
1117                *labs = (float)ticknum * (*ticki);
1118        } /*endif*/
1119
1120        *labi /= (float)labelmul;
1121        *ticki = *labi;
1122        *ticks = *labs;
1123
1124} /* end of mg_autoaxis */
1125
1126
1127
1128/*----------------------------------------------------------------------------*/
1129
1130
1131
1132static void mg_print_trcinfo( Widget w, MGT_DSPINFO *di, MGT_TRCINFO ti[],
1133        STATUS *status )
1134
1135/* prints trace informations on DrawingArea
1136 *
1137 * parameters of routine
1138 * Widget        w;        input; DrawingArea widget
1139 * MGT_DSPINFO   *di;      input; display info
1140 * MGT_TRCINFO   ti[];     input; trace infos
1141 * STATUS        *status;  output; return status
1142 */
1143{
1144        /* local variables */
1145        int      t;                  /* trace counter */
1146        int      charw;              /* char width in pixels */
1147        int      texth;              /* text height in pixels */
1148        char     str[BC_LINELTH+1];  /* scratch string */
1149        int      x, y;               /* text position */
1150
1151        /* executable code */
1152
1153        for  (t=0; t<(di->trcno); t++)  {
1154                texth = ti[t].xenv->font->ascent + ti[t].xenv->font->descent;
1155                charw = ti[t].xenv->font->max_bounds.rbearing -
1156                        ti[t].xenv->font->min_bounds.lbearing;
1157                x = di->wdweff_x - 10*charw;
1158                y = ti[t].xenv->orig.y + texth/2;
1159                tr_setruntrc( ti[t].trc, t+1 );
1160                *str = '\0';  /* first call to dm_infstr */
1161                while  (dm_infstr(BC_LINELTH,str,status))  {
1162                        if  (Severe(status))  return;
1163                        pix_DrawString( XtDisplay(w), XtWindow(w),
1164                                ti[t].xenv->gc, x, y, str, (int)strlen(str) );
1165                        y += texth;
1166                } /*endwhile*/
1167                tr_setruntrc( NULL, 0 );
1168                /* plot zero line */
1169                pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_xor_gc,
1170                        ti[t].xenv->orig.x+di->wdweff_w+10, ti[t].xenv->orig.y,
1171                        ti[t].xenv->orig.x+di->wdweff_w+18, ti[t].xenv->orig.y );
1172        } /*endfor*/
1173
1174} /* end of mg_print_trcinfo */
1175
1176
1177
1178/*----------------------------------------------------------------------------*/
1179
1180
1181
1182static void mg_print_s_trcinfo( Widget w, MGT_DSPINFO *di, MGT_TRCINFO ti[],
1183        int t, int pixoff, STATUS *status )
1184
1185/* prints trace informations in single trace window
1186 *
1187 * parameters of routine
1188 * Widget        w;        input; Single Trace Box widget
1189 * MGT_DSPINFO   *di;      input; display info
1190 * MGT_TRCINFO   ti[];     input; trace infos
1191 * int           t;        input; trace number
1192 * STATUS        *status;  output; return status
1193 */
1194{
1195        /* local variables */
1196        int      charw;              /* char width in pixels */
1197        int      texth;              /* text height in pixels */
1198        char     str[BC_LINELTH+1];  /* scratch string */
1199        int      x, y;               /* text position */
1200        GC       locgc;              /* local GC */
1201
1202        /* executable code */
1203
1204        locgc = mgv_single_gc;
1205        if  (pixoff == NO3TRACES)  pixoff = 0;
1206        if  (pixoff > 0)  locgc = mgv_single2_gc;
1207        if  (pixoff < 0)  locgc = mgv_single3_gc;
1208
1209        texth = ti[t].xenv->font->ascent + ti[t].xenv->font->descent;
1210        charw = ti[t].xenv->font->max_bounds.rbearing -
1211                ti[t].xenv->font->min_bounds.lbearing;
1212        x = di->wdweff_x - 10*charw;
1213        y = di->wdweff_y + di->wdweff_h/2 + texth/2 + pixoff;
1214        tr_setruntrc( ti[t].trc, t+1 );
1215        *str = '\0';  /* first call to dm_infstr */
1216        while  (dm_infstr(BC_LINELTH,str,status))  {
1217                if  (Severe(status))  return;
1218                pix_DrawString( XtDisplay(w), XtWindow(w),
1219                        locgc, x, y, str, (int)strlen(str) );
1220                y += texth;
1221        } /*endwhile*/
1222        tr_setruntrc( NULL, 0 );
1223
1224} /* end of mg_print_s_trcinfo */
1225
1226
1227
1228/*----------------------------------------------------------------------------*/
1229
1230
1231
1232void mg_get_time_and_trace( int x, int y, float *time, int *trcno, BOOLEAN *ok )
1233
1234/* returns time and trace selected by pixels (x,y)
1235 *
1236 * parameters of routine
1237 * int        x, y;        input; pixel coordinates
1238 * float      *time;       output; time in sec
1239 * int        *trcno;      output; trace number
1240 * BOOLEAN    *ok;         output; validitation
1241 */
1242{
1243        /* local variables */
1244        int      t;       /* trace counter */
1245
1246        /* executable code */
1247
1248        if  (trcno != NULL)  *trcno = 0;
1249        *ok = (mgv_di.pixpersec != 0.0 && mgv_di.trcno > 0 && mgv_ti != NULL);
1250        if  (!(*ok))  return;
1251
1252        *time = mgv_di.tw_start + (float)(x-mgv_di.wdweff_x)/mgv_di.pixpersec;
1253        if  (trcno == NULL)  return;
1254        for  (t=0; t<mgv_di.trcno; t++)  {
1255                if  (Abs(y-mgv_ti[t].xenv->orig.y) < mgv_di.unitheight/2)  {
1256                        *trcno = t + 1;
1257                        return;
1258                } /*endif*/
1259        } /*endfor*/
1260        *ok = FALSE;
1261
1262} /* end of mg_get_time_and_trace */
1263
1264
1265
1266/*----------------------------------------------------------------------------*/
1267
1268
1269
1270void mg_get_time_and_trace_single( int x, int y, float *time,
1271        int *trcno, BOOLEAN *ok )
1272
1273/* returns time and trace selected by pixels (x,y) in single trace window
1274 *
1275 * parameters of routine
1276 * int        x, y;        input; pixel coordinates
1277 * float      *time;       output; time in sec
1278 * int        *trcno;      output; trace number
1279 * BOOLEAN    *ok;         output; validitation
1280 */
1281{
1282        /* local variables */
1283        float    dummy;
1284
1285        /* executable code */
1286
1287        if  (trcno != NULL)  *trcno = 0;
1288        *ok = (mgv_sdi.pixpersec != 0.0 && mgv_sdi.trcno > 0 && mgv_ti != NULL);
1289        if  (!(*ok))  return;
1290
1291        *time = mgv_sdi.tw_start + (float)(x-mgv_sdi.wdweff_x)/mgv_sdi.pixpersec;
1292        if  (trcno == NULL)  return;
1293        mg_get_time_and_trace( mgv_drag.x1, (mgv_drag.y1+mgv_drag.y2)/2,
1294                &dummy, trcno, ok );
1295
1296} /* end of mg_get_time_and_trace_single */
1297
1298
1299
1300/*----------------------------------------------------------------------------*/
1301
1302
1303
1304void mg_get_pixelpos( int trcno, float time, int *x, int *y, BOOLEAN *ok )
1305
1306/* returns pixel position of trace "trcno" at time "time" (y-coordinate is
1307 * given at zero line
1308 *
1309 * parameters of routine
1310 * int        trcno;     input; trace number on display
1311 * float      time;      input; time position
1312 * int        *x, *y;    output; pixel position
1313 * BOOLEAN    *ok;       output; validitation
1314 */
1315{
1316        /* executable code */
1317
1318        *ok = FALSE;
1319        trcno--;
1320        if  (trcno < 0 || trcno >= mgv_di.trcno)  return;
1321        if  (time < mgv_di.tw_start || time > mgv_di.tw_end)  return;
1322        *ok = TRUE;
1323        if  (x != NULL)
1324                *x = Nint( (time-mgv_di.tw_start)*mgv_di.pixpersec +
1325                        mgv_di.wdweff_x );
1326        if  (y != NULL)
1327                *y = mgv_ti[trcno].xenv->orig.y;
1328
1329} /* end of mg_get_pixelpos */
1330
1331
1332
1333/*----------------------------------------------------------------------------*/
1334
1335
1336
1337static void mgh_get_pixelpos_single( int trcno, float time, int *x, int *y,
1338        BOOLEAN *ok )
1339
1340/* returns pixel position of trace "trcno" at time "time" (y-coordinate is
1341 * given at zero line in single trace window
1342 *
1343 * parameters of routine
1344 * int        trcno;     input; trace number on display
1345 * float      time;      input; time position
1346 * int        *x, *y;    output; pixel position
1347 * BOOLEAN    *ok;       output; validitation
1348 */
1349{
1350        /* local variables */
1351        int      loctrcno;       /* local trace number */
1352        float    dummy;          /* dummy */
1353
1354        /* executable code */
1355
1356        if  (!mgv_drag.on)  {
1357                *ok = FALSE;
1358                return;
1359        } /*endif*/
1360
1361        mg_get_time_and_trace( mgv_drag.x1, (mgv_drag.y1+mgv_drag.y2)/2,
1362                &dummy, &loctrcno, ok );
1363        if  (!ok)  return;
1364        if  (loctrcno != trcno)  {*ok = FALSE; return;}
1365
1366        if  (time < mgv_sdi.tw_start || time > mgv_sdi.tw_end)  {
1367                *ok = FALSE;
1368                return;
1369        } /*endif*/
1370        *ok = TRUE;
1371        if  (x != NULL)
1372                *x = Nint( (time-mgv_sdi.tw_start)*mgv_sdi.pixpersec +
1373                        mgv_sdi.wdweff_x );
1374        if  (y != NULL)
1375                *y = mgv_wdwsetup.margin_t/*b*/ + mgv_sdi.unitheight / 2.0;
1376
1377} /* end of mgh_get_pixelpos_single */
1378
1379
1380
1381/*----------------------------------------------------------------------------*/
1382
1383
1384
1385void mg_get_drag_window( float *start, float *end, BOOLEAN *set )
1386
1387/* returns current drag window in sec
1388 *
1389 * parameters of routine
1390 * float      *start;      output; start of time window
1391 * float      *end;        output; end of time window
1392 * BOOLEAN    *set;        output; time window set
1393 */
1394{
1395        /* executable code */
1396
1397        *set = mgv_drag.on;
1398        if  (!(*set))  return;
1399
1400        mg_get_time_and_trace( mgv_drag.x1, mgv_drag.y1, start, NULL, set );
1401        if  (!(*set))  return;
1402        mg_get_time_and_trace( mgv_drag.x2, mgv_drag.y1, end, NULL, set );
1403        if  (!(*set))  return;
1404
1405} /* end of mg_get_drag_window */
1406
1407
1408
1409/*----------------------------------------------------------------------------*/
1410
1411
1412
1413void mg_get_drag_trace( int *trcno, BOOLEAN *set )
1414
1415/* returns trace number which is selected by drag window
1416 *
1417 * parameters of routine
1418 * int        *trcno;  output; trace number on display (valid only if *set=TRUE)
1419 * BOOLEAN    *set;    output; drag window is set
1420 */
1421{
1422        /* local variables */
1423        float    dummy;
1424
1425        /* executable code */
1426
1427        mg_get_time_and_trace( mgv_drag.x1, (mgv_drag.y1+mgv_drag.y2)/2,
1428                &dummy, trcno, set );
1429
1430} /* end of mg_get_drag_trace */
1431
1432
1433
1434/*----------------------------------------------------------------------------*/
1435
1436
1437
1438void mg_mark_trace( Widget wm, Widget ws, int trcno, float time, char label[],
1439        int kind, float left_acc, float right_acc )
1440
1441/* marks trace "trcno" at time "time"
1442 *
1443 * parameters of routine
1444 * Widget     ws;         input; widget ID of main window
1445 * Widget     wm;         input; widget ID of single trace window
1446 * int        trcno;      input; trace number on display
1447 * float      time;       input; time position
1448 * char       label;      input; label text
1449 * char       kind;       input; phase kind
1450 * float      left_acc;   input; left accuracy in sec
1451 * float      right_acc;  input; right accuracy in sec
1452 */
1453{
1454        /* local variables */
1455        BOOLEAN  ok;        /* validitation */
1456        int      x, y;      /* pixel coordinates */
1457        int      xal, xar;  /* x coordinates for accuracies */
1458        int      halflth;   /* half length of mark */
1459        GC       lgc;       /* local GC */
1460
1461        /* executable code */
1462
1463        if  (!mgv_gc_init)  mgh_init_graphic_contexts( wm, &mgv_gc_init );
1464        switch (kind)  {
1465        case MGC_PHASE_KIND_THEO:         lgc = mgv_theo_gc;   break;
1466        case MGC_PHASE_KIND_AUTO:         lgc = mgv_auto_gc;   break;
1467        case MGC_PHASE_KIND_MANUALLY_0:   lgc = mgv_mark0_gc;  break;
1468        default:                          lgc = mgv_mark_gc;   break;
1469        } /*endswitch*/
1470
1471        if  (wm != (Widget)0)  {
1472                mg_get_pixelpos( trcno, time, &x, &y, &ok );
1473                if  (!ok)  return;
1474
1475                halflth = Nint( mgv_di.unitheight/2.0 );
1476                pix_DrawLine( XtDisplay(wm), XtWindow(wm), lgc,
1477                        x, y-halflth, x, y+halflth );
1478                pix_DrawString( XtDisplay(wm), XtWindow(wm), lgc, x+2,
1479                        y-halflth+3, label, (int)strlen(label) );
1480                if  (left_acc > 0.0 || right_acc > 0.0)  {
1481                        xal = mgv_di.wdweff_x;
1482                        xar = mgv_di.wdweff_x+mgv_di.wdweff_w;
1483                        mg_get_pixelpos( trcno, time-left_acc, &xal, &y, &ok );
1484                        mg_get_pixelpos( trcno, time+right_acc, &xar, &y, &ok );
1485                        pix_DrawLine( XtDisplay(wm), XtWindow(wm), lgc, xal, y, xar, y );
1486                } /*endif*/
1487                if  (ws == (Widget)0)  XFlush( XtDisplay(wm) );
1488        } /*endif*/
1489
1490        if  (ws == (Widget)0)  return;
1491        if  (!mgv_drag.on)  return;
1492
1493        mgh_get_pixelpos_single( trcno, time, &x, &y, &ok );
1494        if  (!ok)  return;
1495
1496        halflth = Nint( mgv_sdi.unitheight/2.0 );
1497        pix_DrawLine( XtDisplay(ws), XtWindow(ws), lgc,
1498                x, y-halflth, x, y+halflth );
1499        pix_DrawString( XtDisplay(ws), XtWindow(ws), lgc, x+2, y-halflth+3,
1500                label, (int)strlen(label) );
1501        if  (left_acc > 0.0 || right_acc > 0.0)  {
1502                xal = mgv_sdi.wdweff_x;
1503                xar = mgv_sdi.wdweff_x+mgv_di.wdweff_w;
1504                mgh_get_pixelpos_single( trcno, time-left_acc, &xal, &y, &ok );
1505                mgh_get_pixelpos_single( trcno, time+right_acc, &xar, &y, &ok );
1506                pix_DrawLine( XtDisplay(ws), XtWindow(ws), lgc, xal, y, xar, y );
1507        } /*endif*/
1508
1509        XFlush( XtDisplay(ws) );
1510
1511} /* end of mg_mark_trace */
1512
1513
1514
1515/*----------------------------------------------------------------------------*/
1516
1517
1518
1519void mg_do_drag( Widget w, int mode, int x, int y )
1520
1521/* draws dragging lines and boxes
1522 *
1523 * parameters of routine
1524 * Widget     w;         input; widget ID
1525 * int        mode;      input; which item
1526 * int        x, y;      input; new position
1527 */
1528{
1529        /* local variables */
1530        static int last_mode;   /* last drag mode */
1531        XPoint   box[5];        /* box coo's */
1532        BOOLEAN  visible;       /* box is visible */
1533        int      tmp;           /* scratch */
1534        int      bw, bh;        /* width & height of box */
1535        float    timpos;        /* time position */
1536        int      trcno;         /* trace number */
1537        BOOLEAN  ok;            /* status flag */
1538
1539        /* executable code */
1540
1541        if  (!mgv_gc_init)  mgh_init_graphic_contexts( w, &mgv_gc_init );
1542
1543        /* erase old box if visible or refresh it */
1544        visible = mgv_drag.on;
1545        if  (mgv_drag.on)  {  /* erase old box */
1546                box[0].x = mgv_drag.x1;   box[0].y = mgv_drag.y1;
1547                box[1].x = mgv_drag.x1;   box[1].y = mgv_drag.y2;
1548                box[2].x = mgv_drag.x2;   box[2].y = mgv_drag.y2;
1549                box[3].x = mgv_drag.x2;   box[3].y = mgv_drag.y1;
1550                box[4].x = mgv_drag.x1;   box[4].y = mgv_drag.y1;
1551                pix_DrawLines( XtDisplay(w), XtWindow(w), mgv_xor_gc,
1552                        box, 5, CoordModeOrigin );
1553                mgv_drag.on = FALSE;
1554        } /*endif*/
1555
1556        if  (mode == MGC_DRAG_REFRESH)  {
1557                mgv_drag.on = visible;
1558                return;
1559        } /*endif*/
1560        if  (mode == MGC_DRAG_CLEAR)
1561                return;
1562        if  (mode == MGC_DRAG_CONTINUE)
1563                mode = last_mode;
1564
1565        /* modify input coordinates */
1566        mg_get_time_and_trace( x, y, &timpos, &trcno, &ok );
1567        if  (!ok)  return;
1568
1569        /* do not accept x coordinate outside of trace area */
1570        if  (x < mgv_di.wdweff_x)  x = mgv_di.wdweff_x;
1571        if  (x > mgv_di.wdweff_x+mgv_di.wdweff_w)
1572                x = mgv_di.wdweff_x+mgv_di.wdweff_w;
1573
1574        switch  (mode)  {
1575        case MGC_DRAG_START:
1576                y = mgv_ti[trcno-1].xenv->orig.y-mgv_di.unitheight/2+1;
1577                break;
1578        case MGC_DRAG_RUBBER_BOX:
1579                y = mgv_ti[trcno-1].xenv->orig.y+mgv_di.unitheight/2+1;
1580                mgv_drag.y1 = y - mgv_di.unitheight;
1581                break;
1582        case MGC_DRAG_MOVE_BOX:
1583                y = mgv_ti[trcno-1].xenv->orig.y;
1584                break;
1585        } /*endswitch*/
1586
1587        switch  (mode)  {
1588        case MGC_DRAG_START:
1589                if  (visible)  {
1590                        if  (mgv_drag.x1 > mgv_drag.x2)  {
1591                                tmp = mgv_drag.x1;
1592                                mgv_drag.x1 = mgv_drag.x2;
1593                                mgv_drag.x2 = tmp;
1594                        } /*endif*/
1595                        if  (mgv_drag.y1 > mgv_drag.y2)  {
1596                                tmp = mgv_drag.y1;
1597                                mgv_drag.y1 = mgv_drag.y2;
1598                                mgv_drag.y2 = tmp;
1599                        } /*endif*/
1600                        if  (y >= mgv_drag.y1 && y <= mgv_drag.y2 &&
1601                                x > mgv_drag.x2-GpGetInt(cGpI_drag_box_rubber_val)
1602                                && x < mgv_drag.x2+GpGetInt(cGpI_drag_box_rubber_val))  {
1603                                mode = MGC_DRAG_RUBBER_BOX;
1604                        } else {
1605                                mode = MGC_DRAG_MOVE_BOX;
1606                        } /*endif*/
1607                } else {
1608                        mgv_drag.x1 = mgv_drag.x2 = x;
1609                        mgv_drag.y1 = mgv_drag.y2 = y;
1610                        mode = MGC_DRAG_RUBBER_BOX;
1611                } /*endif*/
1612                mgv_drag.on = TRUE;
1613                break;
1614        case MGC_DRAG_RUBBER_BOX:
1615                mgv_drag.x2 = x;
1616                mgv_drag.y2 = y;
1617                mgv_drag.on = TRUE;
1618                if  (mgv_drag.x2-mgv_drag.x1 < GpGetInt(cGpI_min_drag_box_width))
1619                        mgv_drag.x2 = mgv_drag.x1 + GpGetInt(cGpI_min_drag_box_width);
1620                break;
1621        case MGC_DRAG_MOVE_BOX:
1622                bw = mgv_drag.x2 - mgv_drag.x1;
1623                bh = mgv_drag.y2 - mgv_drag.y1;
1624                bw /= 2;  bh /= 2;
1625                mgv_drag.x1 = x - bw;
1626                mgv_drag.x2 = x + bw;
1627                mgv_drag.y1 = y - bh;
1628                mgv_drag.y2 = y + bh;
1629                mgv_drag.on = TRUE;
1630                if  (mgv_drag.x1 < mgv_di.wdweff_x)  {
1631                        mgv_drag.x1 = mgv_di.wdweff_x;
1632                        mgv_drag.x2 = mgv_drag.x1 + 2*bw;
1633                } else if  (mgv_drag.x2 > (mgv_di.wdweff_x+mgv_di.wdweff_w))  {
1634                        mgv_drag.x2 = mgv_di.wdweff_x + mgv_di.wdweff_w;
1635                        mgv_drag.x1 = mgv_drag.x2 - 2*bw;
1636                } /*endif*/
1637                break;
1638        case MGC_DRAG_END:
1639                mgv_drag.on = TRUE;
1640                break;
1641        default:
1642                printf( "*SHM: mg_do_drag: illegal drag mode ***\n" );
1643        } /*endswitch*/
1644
1645        if  (mgv_drag.on)  {  /* draw new box */
1646                box[0].x = mgv_drag.x1;   box[0].y = mgv_drag.y1;
1647                box[1].x = mgv_drag.x1;   box[1].y = mgv_drag.y2;
1648                box[2].x = mgv_drag.x2;   box[2].y = mgv_drag.y2;
1649                box[3].x = mgv_drag.x2;   box[3].y = mgv_drag.y1;
1650                box[4].x = mgv_drag.x1;   box[4].y = mgv_drag.y1;
1651                pix_DrawLines( XtDisplay(w), XtWindow(w), mgv_xor_gc,
1652                        box, 5, CoordModeOrigin );
1653        } /*endif*/
1654
1655        XFlush( XtDisplay(w) );
1656
1657        last_mode = mode;
1658
1659} /* end of mg_do_drag */
1660
1661
1662
1663/*----------------------------------------------------------------------------*/
1664
1665
1666
1667void mg_plot_single( Widget w, int trcno, float t_start, float t_end,
1668        BOOLEAN acc, int pixoff, STATUS *status )
1669
1670/* plots a single trace into the single trace window
1671 *
1672 * parameters of routine
1673 * Widget     w;         input; widget ID of single trace window
1674 * int        trcno;     input; trace number
1675 * float      t_start;   input; window start (sec)
1676 * float      t_end;     input; window end (sec)
1677 * BOOLEAN    acc;       input; show accuracies
1678 * int        pixoff;    input; pixel offset; if 0, then main trace
1679 * STATUS     *status;   output; return status
1680 */
1681{
1682        /* local variables */
1683        static float    vnorm;  /* vertical normalization */
1684        float    *smp;          /* pointer to samples */
1685        long     firstsmp;      /* first sample to be plotted */
1686        long     trclth;        /* length of trace in samples */
1687        int      x_orig;        /* x-position of trace */
1688        int      y_orig;        /* y-position of trace */
1689        float    x_correct;     /* correction of origin */
1690        float    maxval;        /* absolute maximum amplitude of trace */
1691        float    minsmp, maxsmp;/* minimum and maximum values of samples */
1692        long     i, s;          /* sample counter */
1693        XPoint   *pxy;          /* pixel array */
1694        XPoint   *p;            /* moving pointer */
1695        float    xinc;          /* x-increment */
1696        int      efflth;        /* effective plot length */
1697        int      oldx, oldy;    /* pixel coo's of previous sample */
1698        int      newx, newy;    /* pixel coo's of current sample */
1699        STATUS   locstat;       /* local status */
1700        float    meanval;       /* mean value */
1701        float    dt;            /* sample distance in sec */
1702        TPiPhaseList *phaselist;/* phase list */
1703        TPiPhase phase;         /* phase info */
1704        GC       locgc;         /* local GC */
1705        char     spanstr[cBcLineLth+1]; /* string for time span info */
1706        char     fmtstr[cBcLineLth+1]; /* format string */
1707        char     *minmaxfmt;    /* pointer to minmax format string */
1708
1709        /* executable code */
1710
1711        if  (!mgv_gc_init)  mgh_init_graphic_contexts( w, &mgv_gc_init );
1712
1713        locgc = mgv_single_gc;
1714        if  (pixoff != NO3TRACES)  {
1715                if  (pixoff > 0)  locgc = mgv_single2_gc;
1716                if  (pixoff < 0)  locgc = mgv_single3_gc;
1717        } /*endif*/
1718
1719        trcno--;
1720        if  (trcno >= mgv_di.trcno)  return;
1721
1722        if  (pixoff == 0 || pixoff == NO3TRACES)
1723                pix_ClearWindow( XtDisplay(w), XtWindow(w) );
1724        mgv_sdi.type = MGC_WDW_SINGLE;
1725        mg_get_windowsize( w, &(mgv_sdi.wdw_w), &(mgv_sdi.wdw_h) );
1726        mgv_sdi.wdweff_w = mgv_sdi.wdw_w - mgv_wdwsetup.margin_r -
1727                mgv_wdwsetup.margin_l;
1728        mgv_sdi.wdweff_h = mgv_sdi.wdw_h - mgv_wdwsetup.margin_b -
1729                mgv_wdwsetup.margin_t;
1730        if  (mgv_sdi.wdweff_w < 2 || mgv_sdi.wdweff_h < 2)  {
1731                printf( "*SHM: zero window ***\n" );
1732                mgv_sdi.trcno = 0;
1733                return;
1734        } /*endif*/
1735        mgv_sdi.wdweff_x = mgv_wdwsetup.margin_l;
1736        mgv_sdi.wdweff_y = mgv_wdwsetup.margin_t/*b*/;
1737        mgv_sdi.tw_start = t_start;
1738        mgv_sdi.tw_end = t_end;
1739        mgv_sdi.tw_set = TRUE;
1740        mgv_sdi.trcno = 1;
1741        mgv_sdi.unitheight = (float)(mgv_sdi.wdweff_h) / (float)(mgv_sdi.trcno);
1742
1743        dt = db_getr( mgv_ti[trcno].trc, ER_DELTA, status );
1744        firstsmp = dm_getsample( mgv_ti[trcno].trc, mgv_sdi.tw_start, TRUE );
1745        smp = (float *)db_getp( mgv_ti[trcno].trc, EP_DATA, status ) + firstsmp;
1746        if  (Severe(status))  return;
1747        trclth = dm_getsample( mgv_ti[trcno].trc, mgv_sdi.tw_end, TRUE );
1748        trclth -= firstsmp - 1;
1749        if  (trclth <= 1)  return;
1750
1751        if  (Severe(status))  return;
1752        mgv_sdi.totslth = (float)trclth * dt;
1753        mgv_sdi.pixpersec = (float)(mgv_sdi.wdweff_w) / mgv_sdi.totslth;
1754
1755        /* find maximum amplitude and mean value */
1756        maxval = minsmp = maxsmp = Abs(*smp);
1757        meanval = 0.;
1758        for  (i=1; i<trclth; i++)  {
1759                if  (Abs(smp[i]) > maxval)  maxval = Abs(smp[i]);
1760                if  (smp[i] > maxsmp)  maxsmp = smp[i];
1761                if  (smp[i] < minsmp)  minsmp = smp[i];
1762                meanval += smp[i];
1763        } /*endfor*/
1764        meanval /= (float)trclth;
1765        maxval -= meanval;
1766
1767        x_correct = (float)firstsmp*dt + db_getr(mgv_ti[trcno].trc,ER_TORIG,status)
1768                - mgv_sdi.tw_start;
1769        if  (Severe(status))  return;
1770        if  (GpGetInt(cGpI_debug_level) > 0)
1771                if  (Abs(x_correct) > dt)
1772                        printf("SHM-dbg1: x_correct %f, dt %f\n",x_correct,dt);
1773        x_orig = mgv_sdi.wdweff_x + Nint(x_correct*mgv_sdi.pixpersec);
1774        y_orig = mgv_wdwsetup.margin_t/*b*/ + mgv_sdi.unitheight / 2.0;
1775        if  (pixoff != NO3TRACES)  y_orig += pixoff;
1776
1777        pxy = (XPoint *)sy_allocmem( trclth, (int)sizeof(XPoint), status );
1778        if  (Severe(status))  return;
1779
1780        p = pxy;
1781        xinc = mgv_sdi.pixpersec * dt;
1782        if  (pixoff == 0 || pixoff == NO3TRACES)  {
1783                vnorm = mgv_sdi.unitheight / maxval * 0.5;
1784                if  (pixoff != NO3TRACES)  vnorm /= 2.0;
1785        } /*endif*/
1786        efflth = 1;
1787        oldx = p->x = x_orig;
1788        oldy = p->y = y_orig - Nint( (*smp-meanval) * vnorm );
1789        p++; smp++;
1790        for  (s=1; s<trclth; s++)  {
1791                newx = x_orig + Nint( s*xinc );
1792                newy = y_orig - Nint( (*smp-meanval) * vnorm );
1793                if  (newx != oldx || newy != oldy)  {
1794                        p->x = newx;
1795                        p->y = newy;
1796                        p++;
1797                        efflth++;
1798                        oldx = newx;
1799                        oldy = newy;
1800                } /*endif*/
1801                smp++;
1802        } /*endfor*/
1803        pix_DrawLines( XtDisplay(w), XtWindow(w), locgc,
1804                pxy, efflth, CoordModeOrigin );
1805
1806        /* mark zero line */
1807        pxy[0].x = x_orig + mgv_sdi.wdweff_w + 10;
1808        pxy[0].y = y_orig + Nint( meanval * vnorm );
1809        pxy[1].x = pxy[0].x + 10;
1810        pxy[1].y = pxy[0].y;
1811        pix_DrawLines( XtDisplay(w), XtWindow(w), locgc,
1812                pxy, 2, CoordModeOrigin );
1813
1814        sy_deallocmem( pxy );
1815
1816        locstat = BC_NOERROR;
1817        db_gett( mgv_ti[trcno].trc, ET_START, &mgv_ts_axis.abstime, &locstat );
1818        tc_aadd( &mgv_ts_axis.abstime, -db_getr(mgv_ti[trcno].trc,ER_TORIG,&locstat),
1819                &mgv_ts_axis.abstime );
1820        mgv_ts_axis.use_abstime = (locstat == BC_NOERROR);
1821        mg_haxis( w, &mgv_ts_axis, &mgv_sdi );
1822
1823        if  (pixoff == 0 || pixoff == NO3TRACES)  {
1824
1825                /* mark phases */
1826                phaselist = PmGetPhaseList( mgv_ti[trcno].trc );
1827                if  (phaselist != NULL)  {
1828                        for  (i=0; i<PiPhaseListLength(phaselist); i++)  {
1829                                phase = *PiGetPhase( phaselist, i, NULL );
1830                                /*phase.phasetrc = mg_trcptr( trcno+1 );*/
1831                                mg_mark_one_phase( (Widget)0, w, &phase, mgv_ti[trcno].trc, acc );
1832                        } /*endfor*/
1833                } /*endif*/
1834
1835                /* print width of window as text */
1836                minmaxfmt = GpGetString( cGpS_minmax_format );
1837                if  (*minmaxfmt != '\0')  {
1838                        sprintf( fmtstr, "width %%4.2f sec  min:%s max:%s",
1839                                minmaxfmt, minmaxfmt );
1840                        sprintf( spanstr, fmtstr, mgv_sdi.totslth, minsmp, maxsmp );
1841                } else {
1842                        sprintf( spanstr, "width %4.2f sec", mgv_sdi.totslth );
1843                } /*endif*/
1844                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_single_gc,
1845                        x_orig, TEXT_Y_SPAN_SINGLE, spanstr, strlen(spanstr) );
1846
1847        } /*endif*/
1848
1849        /* print trace info */
1850        mg_print_s_trcinfo( w, &mgv_sdi, mgv_ti, trcno, pixoff, &locstat );
1851
1852        XFlush( XtDisplay(w) );
1853
1854} /* end of mg_plot_single */
1855
1856
1857
1858/*----------------------------------------------------------------------------*/
1859
1860
1861
1862void mg_plot_drag_window( Widget w, BOOLEAN acc, STATUS *status )
1863
1864/* plots time window selected by drag box into single trace window
1865 *
1866 * parameters of routine
1867 * Widget     w;        input; widget ID of single trace window
1868 * BOOLEAN    acc;      input; show accuracies on phases
1869 * STATUS     *status;  output; return status */
1870{
1871        /* local variables */
1872        int      trcno;       /* main trace number */
1873        int      trca, trcb;  /* other traces */
1874        float    t_lo, t_hi;  /* time window */
1875        BOOLEAN  ok;          /* window ok */
1876        int      y;           /* y-position of trace */
1877
1878        /* executable code */
1879
1880        if  (!mgv_drag.on)  {
1881                pix_ClearWindow( XtDisplay(w), XtWindow(w) );
1882                XFlush( XtDisplay(w) );
1883                return;
1884        } /*endif*/
1885
1886        y = (mgv_drag.y1 + mgv_drag.y2) / 2;
1887        mg_get_time_and_trace( mgv_drag.x1, y, &t_lo, &trcno, &ok );
1888        if  (!ok)  return;
1889        mg_get_time_and_trace( mgv_drag.x2, y, &t_hi, NULL, &ok );
1890        if  (!ok)  return;
1891
1892        if  (mgv_show_3_traces)  {
1893                mg_plot_single( w, trcno, t_lo, t_hi, acc, 0, status );
1894                y = mgv_sdi.wdweff_h / 4;
1895                mg_find_3_traces( trcno, &trca, &trcb );
1896                if  (trca > 0)
1897                        mg_plot_single( w, trca, t_lo, t_hi, acc, y, status );
1898                if  (trcb > 0)
1899                        mg_plot_single( w, trcb, t_lo, t_hi, acc, -y, status );
1900        } else {
1901                mg_plot_single( w, trcno, t_lo, t_hi, acc, NO3TRACES, status );
1902        } /*endif*/
1903
1904
1905} /* end of mg_plot_drag_window */
1906
1907
1908
1909/*----------------------------------------------------------------------------*/
1910
1911
1912
1913void mg_draw_cursor( Widget w, int wdwno, MGT_DSPCTRL *ctrl, int mode,
1914        int x, int y, BOOLEAN *ok )
1915
1916/* plots graphic cursor
1917 *
1918 * parameters of routine
1919 * Widget     w;       input; widget ID of window
1920 * int        wdwno;   input; window number
1921 * MGT_DSPCTRL *ctrl;  input; display control
1922 * int        mode;    input; cursor mode
1923 * int        x, y;    input; cursor position
1924 * BOOLEAN    *ok;     output; if != NULL, cursor display succeeded ?
1925 */
1926{
1927        /* local variables */
1928        static int      cpos_x;        /* old cursor position */
1929        static int      cpos_y;        /* -- " -- */
1930        static BOOLEAN  cpos_on;       /* cursor visible */
1931        static int      last_mode=MGC_CRSR_NOCURSOR;     /* last mode */
1932        int      curr_mode;            /* current mode */
1933        int      wdw_w;                /* window width */
1934        int      wdw_h;                /* window height */
1935        BOOLEAN  visible;              /* cursor is visible */
1936        MGT_DSPINFO *ldi;              /* pointer to display info */
1937        TSyBoolean set_xcursor;        /* set x-cursor ? */
1938
1939        /* executable code */
1940
1941        if  (ok != NULL)  *ok = TRUE;
1942        set_xcursor = TRUE;
1943
1944        if  (!mgv_gc_init)  mgh_init_graphic_contexts( w, &mgv_gc_init );
1945
1946        ldi = (wdwno == MGC_WDW_MAIN) ? &mgv_di : &mgv_sdi;
1947
1948        if  ((mode == MGC_CRSR_REFRESH || mode == MGC_CRSR_CLEAR) &&
1949                !cpos_on)  /* nothing to do */
1950                return;
1951
1952#ifdef XXX
1953        if  (mode != MGC_CRSR_CROSSHAIR && mode != MGC_CRSR_WAVEFORM &&
1954                mode != MGC_CRSR_NOCURSOR)  {
1955                curr_mode = last_mode;
1956                if  (curr_mode != MGC_CRSR_CROSSHAIR &&
1957                        curr_mode != MGC_CRSR_WAVEFORM &&
1958                        curr_mode != MGC_CRSR_NOCURSOR)
1959                        return;
1960        } else {
1961                curr_mode = mode;
1962        } /*endif*/
1963#endif
1964        if  (mode > MGC_CRSR_LAST)  {
1965                set_xcursor = FALSE;
1966                curr_mode = last_mode;
1967                if  (curr_mode > MGC_CRSR_LAST)
1968                        return;
1969        } else {
1970                curr_mode = mode;
1971        } /*endif*/
1972        visible = cpos_on;
1973
1974        mg_get_windowsize( w, &wdw_w, &wdw_h );
1975
1976        switch  (curr_mode)  {
1977        case MGC_CRSR_NOCURSOR:
1978                if  (set_xcursor)  {
1979                        mg_set_cursor( MGC_XCRSR_NORMAL );
1980                } /*endif*/
1981                break;
1982        case MGC_CRSR_CROSSHAIR:
1983                if  (set_xcursor)
1984                        mg_set_cursor( MGC_XCRSR_CROSS );
1985                if  (cpos_on)  {
1986                        pix_DrawLine(  XtDisplay(w), XtWindow(w), mgv_xor_gc,
1987                                0, cpos_y, wdw_w-1, cpos_y );
1988                        pix_DrawLine(  XtDisplay(w), XtWindow(w), mgv_xor_gc,
1989                                cpos_x, 0, cpos_x, wdw_h-1 );
1990                        cpos_on = FALSE;
1991                } /*endif*/
1992                if  (mode == MGC_CRSR_REFRESH)  {
1993                        if  (visible)  cpos_on = TRUE;
1994                        last_mode = curr_mode;
1995                        return;
1996                } /*endif*/
1997                if  (mode == MGC_CRSR_CLEAR)  {last_mode = curr_mode; return;}
1998                cpos_x = x;
1999                cpos_y = y;
2000                pix_DrawLine(  XtDisplay(w), XtWindow(w), mgv_xor_gc,
2001                        0, cpos_y, wdw_w-1, cpos_y );
2002                pix_DrawLine(  XtDisplay(w), XtWindow(w), mgv_xor_gc,
2003                        cpos_x, 0, cpos_x, wdw_h-1 );
2004                cpos_on = TRUE;
2005                break;
2006        case MGC_CRSR_WAVEFORM:
2007        case MGC_CRSR_WAVEFORM_NEG:
2008        case MGC_CRSR_WAVEFORM_HILB:
2009        case MGC_CRSR_WAVEFORM_NEGHILB:
2010                if  (set_xcursor)
2011                        mg_set_cursor( MGC_XCRSR_WAVE );
2012                if  (!mgv_drag.on)  {
2013                        if  (ok != NULL)  *ok = FALSE;
2014                        last_mode = curr_mode;
2015                        return;
2016                } /*endif*/
2017                if  (cpos_on)  {
2018                        mgh_wave_cursor( w, WAVE_DRAW, ldi, ctrl, cpos_x, cpos_y);
2019                        cpos_on = FALSE;
2020                } /*endif*/
2021                if  (mode == MGC_CRSR_REFRESH)  {
2022                        if  (visible)  cpos_on = TRUE;
2023                        last_mode = curr_mode;
2024                        return;
2025                } /*endif*/
2026                if  (mode == MGC_CRSR_OFF)  {last_mode = curr_mode; return;}
2027                if  (mode == MGC_CRSR_CLEAR)  {
2028                        mgh_wave_cursor( w, WAVE_CLEAR, ldi, ctrl, 0, 0 );
2029                        last_mode = curr_mode;
2030                        return;
2031                } /*endif*/
2032                /* switch to correct waveform */
2033                if  (mode == MGC_CRSR_WAVEFORM)  {
2034                        /* positive sign, no hilbert trafo */
2035                        mgh_wave_cursor( w, WAVE_SIGN, ldi, ctrl, 1, 0 );
2036                        mgh_wave_cursor( w, WAVE_HILB, ldi, ctrl, 0, 0 );
2037                } else if  (mode == MGC_CRSR_WAVEFORM_NEG)  {
2038                        /* negative sign, no hilbert trafo */
2039                        mgh_wave_cursor( w, WAVE_SIGN, ldi, ctrl, -1, 0 );
2040                        mgh_wave_cursor( w, WAVE_HILB, ldi, ctrl, 0, 0 );
2041                } else if  (mode == MGC_CRSR_WAVEFORM_HILB)  {
2042                        /* positive sign, hilbert trafo on */
2043                        mgh_wave_cursor( w, WAVE_SIGN, ldi, ctrl, 1, 0 );
2044                        mgh_wave_cursor( w, WAVE_HILB, ldi, ctrl, 1, 0 );
2045                } else if  (mode == MGC_CRSR_WAVEFORM_NEGHILB)  {
2046                        /* negative sign, hilbert trafo on */
2047                        mgh_wave_cursor( w, WAVE_SIGN, ldi, ctrl, -1, 0 );
2048                        mgh_wave_cursor( w, WAVE_HILB, ldi, ctrl, 1, 0 );
2049                } /*endif*/
2050                cpos_x = x;
2051                cpos_y = y;
2052                mgh_wave_cursor( w, WAVE_DRAW, ldi, ctrl, cpos_x, cpos_y );
2053                cpos_on = TRUE;
2054                break;
2055        default:
2056                mg_set_cursor( MGC_XCRSR_NORMAL );
2057                printf( "*SHM: illegal cursor mode %d\n", curr_mode );
2058                last_mode = curr_mode;
2059                return;
2060        } /*endswitch*/
2061
2062        last_mode = curr_mode;
2063
2064} /* end of mg_draw_cursor */
2065
2066
2067
2068/*----------------------------------------------------------------------------*/
2069
2070
2071
2072static void mgh_wave_cursor( Widget w, int mode, MGT_DSPINFO *di,
2073        MGT_DSPCTRL *ctrl, int px, int py )
2074
2075/* Draws waveform cursor if mode==WAVE_DRAW.  If mode==WAVE_SIGN,
2076 * px contains the waveform sign.  If mode==WAVE_HILB, px contains
2077 * flag for do_hilbert.
2078 *
2079 * parameters of routine
2080 * Widget     w;          input; widget ID
2081 * int        mode;       input; draw or clear
2082 * MGT_DSPINFO *di;       input; display parameters
2083 * MGT_DSPCTRL *ctrl;     input; display control
2084 * int        px, py;     input; plot position
2085 */
2086{
2087        /* local variables */
2088        static float    *wavptr=NULL;     /* waveform pointer */
2089        static long     trclth;           /* length of waveform */
2090        static XPoint   *pxy;             /* plot array */
2091        static float    dt;               /* sample distance */
2092        static float    maxval;           /* maximum amplitude */
2093        static float    g_vnorm;          /* vertical normalization */
2094        static int      w_sign=1;         /* sign of wave */
2095        static BOOLEAN  do_hilbert=FALSE; /* perform Hilbert trafo */
2096        static BOOLEAN  hilbert_done=FALSE;/* Hilbert trafo done */
2097        float    vnorm;                   /* actual used normalization */
2098        int      trcno;                   /* trace number */
2099        STATUS   locstat=BC_NOERROR;      /* return status */
2100        int      y;                       /* y-position */
2101        BOOLEAN  ok;                      /* trcno ok */
2102        float    t_start, t_end;          /* time window */
2103        long     s_first;                 /* first sample */
2104        float    *datptr;                 /* data pointer */
2105        long     i;                       /* counter */
2106        XPoint   *p;                      /* moving pointer */
2107        float    xinc;                    /* x increment */
2108        long     efflth;                  /* effective length */
2109        int      oldx, oldy, newx, newy;  /* plot coordinates */
2110        int      diffx, diffy;            /* difference of coo's */
2111        float    *smp;                    /* moving pointer */
2112        long     s;                       /* sample counter */
2113        float    *hilbptr;                /* temporary storage for Hilbert pointer */
2114        GC       local_gc;                /* local GC */
2115
2116        /* executable code */
2117
2118        if  (mode == WAVE_CLEAR)  {
2119                if  (wavptr != NULL)  {
2120                        sy_deallocmem( wavptr );
2121                        wavptr = NULL;
2122                        sy_deallocmem( pxy );
2123                        pxy = NULL;
2124                        g_vnorm = 0.0;
2125                } /*endif*/
2126                return;
2127        } else if  (mode == WAVE_SIGN)  {
2128                w_sign = px;
2129                return;
2130        } else if  (mode == WAVE_HILB)  {
2131                do_hilbert = (px == 1);
2132                return;
2133        } /*endif*/
2134
2135        /* get waveform if not yet allocated */
2136        if  (wavptr == NULL)  {
2137                if  (!mgv_drag.on)  {
2138                        if  (GpGetInt(cGpI_debug_level) > 0)
2139                                printf( "SHM-dbg1: no waveform available\n" );
2140                        return;
2141                } /*endif*/
2142                if  (mgv_di.trcno == 0)  {
2143                        if  (GpGetInt(cGpI_debug_level) > 0)
2144                                printf( "SHM-dbg1: no trace available\n" );
2145                        return;
2146                } /*endif*/
2147                y = (mgv_drag.y1 + mgv_drag.y2) / 2;
2148                mg_get_time_and_trace( mgv_drag.x1, y, &t_start, &trcno, &ok );
2149                if  (!ok)  {
2150                        if  (GpGetInt(cGpI_debug_level) > 0)
2151                                printf("SHM-dbg1: ts ts ts...\n" );
2152                        return;
2153                } /*endif*/
2154                mg_get_time_and_trace( mgv_drag.x2, y, &t_end, NULL, &ok );
2155                if  (!ok)  {
2156                        if  (GpGetInt(cGpI_debug_level) > 0)
2157                                printf("SHM-dbg1: ts ts ts...\n" );
2158                        return;
2159                } /*endif*/
2160                trcno--;
2161                datptr = (float *)db_getp( mgv_ti[trcno].trc, EP_DATA, NULL );
2162                s_first = dm_getsample( mgv_ti[trcno].trc, t_start, TRUE );
2163                trclth = dm_getsample( mgv_ti[trcno].trc, t_end, TRUE );
2164                trclth -= s_first + 1;
2165                if  (trclth <= 1)  {
2166                        printf( "*SHM: waveform too short\n" );
2167                        return;
2168                } /*endif*/
2169                datptr += s_first;
2170                wavptr = (float *)sy_allocmem( trclth, (int)sizeof(float),
2171                        &locstat );
2172                if  (Severe(&locstat))  {
2173                        wavptr = NULL;
2174                        printf( "*SHM: waveform allocation error (1)\n" );
2175                        return;
2176                } /*endif*/
2177                pxy = (XPoint *)sy_allocmem( trclth, (int)sizeof(XPoint),
2178                        &locstat );
2179                if  (Severe(&locstat))  {
2180                        sy_deallocmem( wavptr );
2181                        wavptr = NULL;
2182                        pxy = NULL;
2183                        printf( "*SHM: waveform allocation error (2)\n" );
2184                        return;
2185                } /*endif*/
2186                maxval = *datptr;
2187                for (i=0; i<trclth; i++)  {
2188                        wavptr[i] = datptr[i];
2189                        if  (Abs(datptr[i]) > maxval)  maxval = Abs(datptr[i]);
2190                } /*endfor*/
2191                dt = db_getr( mgv_ti[trcno].trc, ER_DELTA, NULL );
2192                g_vnorm = db_getr( mgv_ti[trcno].trc, ER_NORM, NULL );
2193                g_vnorm *= db_getr( mgv_ti[trcno].trc, ER_ZOOM, NULL );
2194                g_vnorm *= di->unitheight * ctrl->zoom;
2195                hilbert_done = FALSE;
2196        } /*endif*/
2197
2198        if  (do_hilbert && !hilbert_done)  {
2199                hilbptr = (float *)sy_allocmem( trclth, (int)sizeof(float),
2200                        &locstat );
2201                if  (Severe(&locstat))  {
2202                        sy_deallocmem( wavptr );
2203                        wavptr = NULL;
2204                        pxy = NULL;
2205                        printf( "*SHM: waveform allocation error (3)\n" );
2206                        return;
2207                } /*endif*/
2208                ff_hilbert( wavptr, trclth, hilbptr, &locstat );
2209                if  (Severe(&locstat))  {
2210                        printf( "*SHM: hilbert trafo error ***\n" );
2211                        sy_deallocmem( hilbptr );
2212                        locstat = BC_NOERROR;
2213                } else {
2214                        sy_deallocmem( wavptr );
2215                        wavptr = hilbptr;
2216                } /*endif*/
2217                hilbert_done = TRUE;
2218        } /*endif*/
2219
2220        local_gc = mgv_xor_gc;
2221        if  (do_hilbert)  local_gc = mgv_theo_gc;
2222        if  (w_sign == -1)  local_gc = mgv_auto_gc;
2223
2224        /* plot waveform */
2225        smp = wavptr;
2226        p = pxy;
2227        xinc = di->pixpersec * dt;
2228        vnorm = (di->type == MGC_WDW_SINGLE) ? di->unitheight/maxval * 0.5 : g_vnorm;
2229        efflth = 1;
2230        oldx = p->x = px;
2231        oldy = p->y = py - w_sign * Nint( *smp * vnorm );
2232        p++; smp++;
2233        for  (s=1; s<trclth; s++)  {
2234                newx = px + Nint( s*xinc );
2235                newy = py - w_sign * Nint( *smp * vnorm );
2236                diffx = newx - oldx;
2237                diffy = newy - oldy;
2238                diffx = Abs( diffx );
2239                diffy = Abs( diffy );
2240                if  (diffx > 1 || diffy > 1)  {
2241                        p->x = newx;
2242                        p->y = newy;
2243                        p++;
2244                        efflth++;
2245                        oldx = newx;
2246                        oldy = newy;
2247                } /*endif*/
2248                smp++;
2249        } /*endfor*/
2250        pix_DrawLines( XtDisplay(w), XtWindow(w), local_gc,
2251                pxy, efflth, CoordModeOrigin );
2252
2253} /* end of mgh_wave_cursor */
2254
2255
2256
2257/*----------------------------------------------------------------------------*/
2258
2259
2260
2261void mg_do_phase( Widget w, int wdwno, int mode, int x, int y, char onset[],
2262        int *no, TPiPhase *close )
2263
2264/* manages selecting, moving and deleting of phases
2265 *
2266 * parameters of routine
2267 * Widget     w;      input; widget of trace window
2268 * int        wdwno;  input; window number
2269 * int        mode;   input; selection mode
2270 * int        x, y;   input; position of pointer
2271 * char       onset[];output; if != NULL returns onset time string
2272 * int        *no;    output; if != NULL returns trace number
2273 * TPiPhase  *close; output; if != NULL returns close phase
2274 */
2275{
2276        /* local variables */
2277        static int      phase_x;       /* position of mark (x) */
2278        static int      phase_y;       /* position of mark (y) */
2279        static Widget   lastwid;       /* last widget */
2280        static int      lastwdw=0;     /* last window number */
2281        MGT_DSPINFO     *ldi;          /* pointer to display info */
2282        float           phase_pos;     /* time position */
2283        int             phase_trc;     /* phase trace */
2284        int             halflth;       /* half length of mark */
2285        TIME            tstart;        /* start time */
2286        STATUS          locstat=BC_NOERROR; /* local status */
2287        float           close_pos;     /* variable for close phase */
2288        int             close_trc;     /* -- " -- */
2289        BOOLEAN         close_ok;      /* -- " -- */
2290        TPiPhase        close_phase;   /* -- " -- */
2291
2292        /* executable code */
2293
2294        /* check for appropriate x coo */
2295        if  (x <= mgv_di.wdweff_x)  x = mgv_di.wdweff_x + 1;
2296        if  (x >= (mgv_di.wdweff_x+mgv_di.wdweff_w))
2297                x = mgv_di.wdweff_x + mgv_di.wdweff_w - 1;
2298
2299        if  (wdwno == MGC_WDW_LAST)  {
2300                if  (lastwdw == 0)  return;
2301                wdwno = lastwdw;
2302                w = lastwid;
2303        } else if  (wdwno != lastwdw && lastwdw != 0)  {
2304                mg_do_phase( lastwid, lastwdw, MGC_PHASE_CLEAR, 0, 0, NULL,NULL,NULL);
2305        } /*endif*/
2306        lastwdw = wdwno;
2307        lastwid = w;
2308
2309        if  ((mode == MGC_PHASE_CLEAR || mode == MGC_PHASE_REFRESH) &&
2310                !mgv_phase_sel)  {
2311                if  (close != NULL)  close->name[0] = '\0';
2312                if  (onset != NULL)  onset[0] = '\0';
2313                return;
2314        } /*endif*/
2315        if  ((mgv_di.trcno == 0) || (wdwno == MGC_WDW_SINGLE && !mgv_drag.on))  {
2316                if  (close != NULL)  close->name[0] = '\0';
2317                if  (onset != NULL)  onset[0] = '\0';
2318                if  (no != NULL)  *no = 0;
2319                return;
2320        } /*endif*/
2321
2322        if  (!mgv_gc_init)  mgh_init_graphic_contexts( w, &mgv_gc_init );
2323
2324        ldi = (wdwno == MGC_WDW_SINGLE) ? &mgv_sdi : &mgv_di;
2325        halflth = Nint( (ldi->unitheight) / 2.0 );
2326
2327        /* if a close phase exists already, delete it */
2328        if  (mode == MGC_PHASE_START && !mgv_phase_sel)  {
2329                if  (wdwno == MGC_WDW_SINGLE)  {
2330                        mg_get_time_and_trace_single( x, y, &close_pos,
2331                                &close_trc, &close_ok );
2332                } else {
2333                        mg_get_time_and_trace( x, y, &close_pos,
2334                                &close_trc, &close_ok );
2335                } /*endif*/
2336                if  (close_ok)  {
2337                        mgh_find_phase( close_trc, close_pos,
2338                                GpGetFloat(cGpF_close_phase_resol)/(ldi->pixpersec),
2339                                &close_phase, &close_ok );
2340                        if  (close_ok && close != NULL)  {
2341                                PmRemovePhase( mgv_ti[close_trc-1].trc, &close_phase, &locstat );
2342                                locstat = BC_NOERROR;
2343                                *close = close_phase;
2344                                /*close->phasetrc = mg_trcptr( close_trc );*/
2345                        } else if  (close != NULL)  {
2346                                /*close->phasetrc = NULL;*/
2347                                close->name[0] = '\0';
2348                        } /*endif*/
2349                } /*endif*/
2350        } else {
2351                if  (close != NULL)
2352                        close->name[0] = '\0';
2353        } /*endif*/
2354
2355        switch  (mode)  {
2356        case MGC_PHASE_START:
2357        case MGC_PHASE_REFRESH:
2358        case MGC_PHASE_CLEAR:
2359                if  (mgv_phase_sel)  {  /* delete old mark */
2360                        pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_phase_gc,
2361                                phase_x, phase_y-halflth, phase_x, phase_y+halflth );
2362                        mgv_phase_sel = FALSE;
2363                } /*endif*/
2364                if  (mode == MGC_PHASE_REFRESH)  {
2365                        mgv_phase_sel = TRUE;
2366                        return;
2367                } /*endif*/
2368                if  (mode == MGC_PHASE_CLEAR)  return;
2369                if  (wdwno == MGC_WDW_SINGLE)  {
2370                        mg_get_time_and_trace_single( x, y, &phase_pos,
2371                                &phase_trc, &mgv_phase_sel );
2372                } else {
2373                        mg_get_time_and_trace( x, y, &phase_pos,
2374                                &phase_trc, &mgv_phase_sel );
2375                } /*endif*/
2376                if  (!mgv_phase_sel)  return;
2377                phase_trc--;
2378                phase_x = x;
2379                if  (wdwno == MGC_WDW_SINGLE)  {
2380                        phase_y = mgv_wdwsetup.margin_t/*b*/ + mgv_sdi.unitheight / 2.0;
2381                } else {
2382                        phase_y = mgv_ti[phase_trc].xenv->orig.y;
2383                } /*endif*/
2384                pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_phase_gc,
2385                        phase_x, phase_y-halflth, phase_x, phase_y+halflth );
2386                mgv_phase_sel = TRUE;
2387                break;
2388        default:
2389                printf( "*SHM: mg_do_phase:  illegal phase mode\n" );
2390                return;
2391        } /*endswitch*/
2392
2393        if  (onset == NULL)  return;
2394
2395        *onset = '\0';
2396        db_gett( mgv_ti[phase_trc].trc, ET_START, &tstart, &locstat );
2397        if  (Severe(&locstat))  return;
2398        tc_a2t( &tstart, onset, &locstat );
2399        if  (Severe(&locstat))  return;
2400        phase_pos -= db_getr( mgv_ti[phase_trc].trc, ER_TORIG, &locstat );
2401        tc_tadd( onset, phase_pos, onset, &locstat );
2402        if  (no != NULL)  *no = phase_trc + 1;
2403
2404} /* end of mg_do_phase */
2405
2406
2407
2408/*----------------------------------------------------------------------------*/
2409
2410
2411
2412void mg_mark_one_phase( Widget wm, Widget ws, TPiPhase *phase, TPmTrace *phtrc,
2413        TSyBoolean acc )
2414
2415/* marks a phase on a specified trace
2416 *
2417 * parameters of routine
2418 * Widget     wm;        input; widget of main window
2419 * Widget     ws;        input; widget of single trace window
2420 * int        trcno;     input; trace number
2421 * TPiPhase   *phase;    input; pointer to phase info
2422 * TPmTrace   *phtrc;    input; pointer to phase trace
2423 * TSyBoolean acc;       input; draw accuracies
2424 */
2425{
2426        /* local variables */
2427        float    reltime;                 /* relative time */
2428        char     label[BC_LINELTH+1];     /* label string */
2429        TIME     tstart;                  /* start time */
2430        TIME     onset;                   /* onset time */
2431        STATUS   locstat=BC_NOERROR;      /* local status */
2432        /* int      trcno;         */          /* trace number */
2433        int      phase_kind;              /* kind of phase */
2434        float    acc_l, acc_r;            /* accuracies */
2435        char     *cptr;                   /* moving pointer */
2436
2437        /* executable code */
2438
2439        if  (phtrc == NULL)  {
2440                if  (GpGetInt(cGpI_debug_level) > 1)
2441                        printf( "SHM-dbg2: mg_mark_one_phase: NULL phtrc\n" );
2442                return;
2443        } /*endif*/
2444
2445        db_gett( phtrc, ET_START, &tstart, &locstat );
2446        if  (Severe(&locstat))  return;
2447        tc_t2a( phase->onset, &onset, &locstat );
2448        if  (Severe(&locstat))  return;
2449        reltime = tc_adiff( &onset, &tstart ) +
2450                db_getr( phtrc, ER_TORIG, &locstat );
2451
2452        if  (acc)  {
2453                acc_l = phase->onset_acc_l;
2454                acc_r = phase->onset_acc_r;
2455        } else {
2456                acc_l = acc_r = 0.0;
2457        } /*endif*/
2458
2459        if  (GpGetBoolean(cGpB_full_phase_names))  {
2460                cptr = label;
2461                if  (! phase->reliable)  *cptr++ = '(';
2462                *cptr++ = phase->spec;
2463                strcpy( cptr, phase->name );
2464                cptr += strlen( phase->name );
2465                if  (phase->sign == 1)  *cptr++ = 'c';
2466                else if  (phase->sign == -1)  *cptr++ = 'd';
2467                if  (! phase->reliable)  *cptr++ = ')';
2468                *cptr = '\0';
2469        } else {
2470                if  (phase->reliable)  {
2471                        strcpy( label, phase->name );
2472                } else {
2473                        sprintf( label, "(%s)", phase->name );
2474                } /*endif*/
2475        } /*endif*/
2476        if  (phase->source == cPiSourceTheo)  {
2477                if  (!mgv_colored)  strcat( label, "(t)" );
2478                phase_kind = MGC_PHASE_KIND_THEO;
2479        } else if  (phase->source == cPiSourceAuto)  {
2480                if  (!mgv_colored)  strcat( label, "(a)" );
2481                phase_kind = MGC_PHASE_KIND_AUTO;
2482        } else {
2483                if  (phase->quality < 2)  {
2484                        phase_kind = MGC_PHASE_KIND_MANUALLY_0;
2485                } else {
2486                        phase_kind = MGC_PHASE_KIND_MANUALLY;
2487                } /*endif*/
2488        } /*endif*/
2489        mg_mark_trace( wm, ws, mg_trcnum(phtrc), reltime, label,
2490                phase_kind, acc_l, acc_r );
2491
2492} /* end of mg_mark_one_phase */
2493
2494
2495
2496/*----------------------------------------------------------------------------*/
2497
2498
2499
2500void mg_plot_phases( Widget wm, BOOLEAN acc, STATUS *status )
2501
2502/* marks all phases
2503 *
2504 * parameters of routine
2505 * Widget     wm;      input; widget ID of main window
2506 * BOOLEAN    acc;     input; show accuracies
2507 * STATUS     *status; output; return status
2508 */
2509{
2510        /* local variables */
2511        int      t;                   /* trace counter */
2512        int      p;                   /* phase counter */
2513        TPiPhase  phase;             /* phase info */
2514        TPiPhaseList *phaselist;     /* phase list */
2515        STATUS   locstat;             /* local status */
2516
2517        /* executable code */
2518
2519        for  (t=0; t<mgv_di.trcno; t++)  {
2520                locstat = BC_NOERROR;
2521                phaselist = PmGetPhaseList( mgv_ti[t].trc );
2522                if  (phaselist != NULL)  {
2523                        for  (p=0; p<PiPhaseListLength(phaselist); p++)  {
2524                                phase = *PiGetPhase( phaselist, p, NULL );
2525                                /*phase.phasetrc = mgv_ti[t].trc;*/
2526                                mg_mark_one_phase( wm, (Widget)0, &phase, mgv_ti[t].trc, acc );
2527                        } /*endfor*/
2528                } /*endif*/
2529        } /*endfor*/
2530
2531} /* end of mg_plot_phases */
2532
2533
2534
2535/*----------------------------------------------------------------------------*/
2536
2537
2538
2539static void mgh_find_phase( int trcno, float reftime, float resol,
2540                                TPiPhase *phase, BOOLEAN *found )
2541
2542/* finds phase close to specified time
2543 *
2544 * parameters of routine
2545 * int        trcno;         input; trace number
2546 * float      reftime;       input; reference time
2547 * float      resol;         input; resolution (allowed deviation)
2548 * TPiPhase  *phase;        output; phase info about phase found
2549 * BOOLEAN    *found;        output; a phase was found
2550 */
2551{
2552        /* local variables */
2553        TPiPhaseList *phaselist;       /* phase list */
2554        TPiPhase *cph;                 /* current phase */
2555        STATUS   locstat;              /* local status */
2556        int      p;                    /* phase counter */
2557        TIME     tstart, tcurr;        /* start time and current time */
2558        float    difftime;             /* difference time */
2559        float    torig;                /* origin time of trace */
2560
2561        /* executable code */
2562
2563        *found = FALSE;
2564        trcno--;
2565        locstat = cBcNoError;
2566        phaselist = PmGetPhaseList( mgv_ti[trcno].trc );
2567        if  (phaselist == NULL)  return;
2568
2569        locstat = cBcNoError;
2570        db_gett( mgv_ti[trcno].trc, ET_START, &tstart, &locstat );
2571        if  (Severe(&locstat))  return;
2572        torig = db_getr( mgv_ti[trcno].trc, ER_TORIG, &locstat );
2573
2574        for  (p=0; p<PiPhaseListLength(phaselist); p++)  {
2575                cph = PiGetPhase( phaselist, p, &locstat );
2576                tc_t2a( cph->onset, &tcurr, &locstat );
2577                difftime = tc_adiff( &tcurr, &tstart ) - reftime + torig;
2578                difftime = Abs( difftime );
2579                if  (difftime <= resol)  {
2580                        *phase = *cph;
2581                        *found = TRUE;
2582                        return;
2583                } /*endif*/
2584        } /*endfor*/
2585
2586} /* end of mgh_find_phase */
2587
2588
2589
2590/*----------------------------------------------------------------------------*/
2591
2592
2593
2594BOOLEAN mg_toggle_trace_selection( Widget w, int x, int y )
2595
2596/* Toggles trace selection if mouse position on button event is in left margin of main
2597 * window
2598 *
2599 * parameters of routine
2600 * Widget     w;         input; drawing area widget
2601 * int        x, y;      input; position of mouse
2602 *                       returns TRUE if a trace was selected
2603 */
2604{
2605        /* local variables */
2606        float    dummy_time;         /* dummy */
2607        int      trcno;              /* trace number */
2608        BOOLEAN  ok;                 /* selection ok */
2609
2610        /* executable code */
2611
2612        if (x > mgv_di.wdweff_x)  return FALSE;
2613
2614        mg_get_time_and_trace( x, y, &dummy_time, &trcno, &ok );
2615        if  (!ok)  {
2616                printf( "*SHM: trace selection not ok\n" );
2617                return FALSE;
2618        } /*endif*/
2619
2620        ts_toggle_selection( trcno );
2621        mgh_mark_selected_trace( w, trcno );
2622
2623        return TRUE;
2624
2625} /* end of mg_toggle_trace_selection */
2626
2627
2628
2629/*----------------------------------------------------------------------------*/
2630
2631
2632
2633BOOLEAN mg_select_trace( Widget w, int x, int y )
2634
2635/* selects trace if mouse position on button event is in left margin of main
2636 * window
2637 *
2638 * parameters of routine
2639 * Widget     w;         input; drawing area widget
2640 * int        x, y;      input; position of mouse
2641 *                       returns TRUE if a trace was selected
2642 */
2643{
2644        /* local variables */
2645        float    dummy_time;         /* dummy */
2646        int      trcno;              /* trace number */
2647        BOOLEAN  ok;                 /* selection ok */
2648
2649        /* executable code */
2650
2651        if (x > mgv_di.wdweff_x)  return FALSE;
2652
2653        mg_get_time_and_trace( x, y, &dummy_time, &trcno, &ok );
2654        if  (!ok)  {
2655                printf( "*SHM: trace selection not ok\n" );
2656                return FALSE;
2657        } /*endif*/
2658
2659        if  (!ts_is_selected(trcno))  {
2660                ts_select( trcno );
2661                mgh_mark_selected_trace( w, trcno );
2662        } /*endif*/
2663
2664        return TRUE;
2665
2666} /* end of mg_select_trace */
2667
2668
2669
2670/*----------------------------------------------------------------------------*/
2671
2672
2673
2674BOOLEAN mg_deselect_trace( Widget w, int x, int y )
2675
2676/* deselects trace if mouse position on button event is in left margin of main
2677 * window
2678 *
2679 * parameters of routine
2680 * Widget     w;         input; drawing area widget
2681 * int        x, y;      input; position of mouse
2682 *                       returns TRUE if a trace was selected
2683 */
2684{
2685        /* local variables */
2686        float    dummy_time;         /* dummy */
2687        int      trcno;              /* trace number */
2688        BOOLEAN  ok;                 /* selection ok */
2689
2690        /* executable code */
2691
2692        if (x > mgv_di.wdweff_x)  return FALSE;
2693
2694        mg_get_time_and_trace( x, y, &dummy_time, &trcno, &ok );
2695        if  (!ok)  {
2696                printf( "*SHM: trace selection not ok\n" );
2697                return FALSE;
2698        } /*endif*/
2699
2700        if  (ts_is_selected(trcno))  {
2701                ts_deselect( trcno );
2702                mgh_mark_selected_trace( w, trcno );
2703        } /*endif*/
2704
2705        return TRUE;
2706
2707} /* end of mg_deselect_trace */
2708
2709
2710
2711/*----------------------------------------------------------------------------*/
2712
2713
2714
2715void mg_clear_selections( Widget w )
2716
2717/* Clears all selections on display
2718 *
2719 * parameters of routine
2720 * Widget     w;        input; display widget
2721 */
2722{
2723        /* local variables */
2724        void     *trc;        /* pointer to trace */
2725        int      trcno;       /* number of trace on display */
2726
2727        /* executable code */
2728
2729        trcno = 1;
2730        trc = NULL;
2731        FOREVER {
2732                trc = db_getp( trc, EP_DSPN, NULL );
2733                if  (trc == NULL)  break;
2734                if  (ts_is_selected(trcno))  mgh_mark_selected_trace( w, trcno );
2735                trcno++;
2736        } /*endfor*/
2737        ts_clear_selections();
2738
2739} /* end of mg_clear_selections */
2740
2741
2742
2743/*----------------------------------------------------------------------------*/
2744
2745
2746
2747static void mgh_mark_selected_trace( Widget w, unsigned number )
2748
2749/* marks trace number "number" on screen
2750 *
2751 * parameters of routine
2752 * Widget     w;              input; drawing area widget
2753 * unsigned   number          input; trace number
2754 */
2755{
2756        /* local variables */
2757
2758        /* executable code */
2759
2760        if  (number == 0 || number > mg_dsptrcs())  return;
2761
2762        pix_FillRectangle( XtDisplay(w), XtWindow(w), mgv_xor_gc,
2763                mgv_di.wdweff_x-65, mgv_ti[number-1].xenv->orig.y-3, 15, 12 );
2764
2765} /* end of mgh_mark_selected_trace */
2766
2767
2768
2769/*----------------------------------------------------------------------------*/
2770
2771
2772
2773int mg_dsptrcs( void )
2774
2775/* returns number of traces on display
2776 *
2777 * no parameters
2778 */
2779{
2780        /* executable code */
2781
2782        return mgv_di.trcno;
2783
2784} /* end of mg_dsptrcs */
2785
2786
2787
2788/*----------------------------------------------------------------------------*/
2789
2790
2791
2792void *mg_trcptr( int trcno )
2793
2794/* returns TRACE pointer of trace number "trcno"
2795 *
2796 * parameters of routine
2797 * int        trcno;       input; trace number on display
2798 *                         returns pointer to trace info
2799 */
2800{
2801        /* executable code */
2802
2803        trcno--;
2804        if  (trcno < 0 || trcno >= mgv_di.trcno)  return NULL;
2805        return mgv_ti[trcno].trc;
2806
2807} /* end of mg_trcptr */
2808
2809
2810
2811/*----------------------------------------------------------------------------*/
2812
2813
2814
2815int mg_trcnum( void *trcptr )
2816
2817/* returns trace number on display from pointer to trace.  Returns 0 if trace
2818 * is not on display
2819 *
2820 * parameters of routine
2821 * void       *trcptr;        input; pointer to trace
2822 */
2823{
2824        /* local variables */
2825        int      i;          /* counter */
2826
2827        /* executable code */
2828
2829        for  (i=1; i<=mg_dsptrcs(); i++)
2830                if  (trcptr == mg_trcptr(i))  return i;
2831        return 0;
2832
2833} /* end of mg_trcnum */
2834
2835
2836
2837/*----------------------------------------------------------------------------*/
2838
2839
2840
2841static void mgh_get_colormap( Screen *s )
2842
2843/* gets color map
2844 *
2845 */
2846{
2847        /* local variables */
2848
2849        /* executable code */
2850
2851        mgv_colored = ((XDefaultVisualOfScreen(s))->class == TrueColor
2852                || (XDefaultVisualOfScreen(s))->class == PseudoColor
2853                || (XDefaultVisualOfScreen(s))->class == DirectColor
2854                || (XDefaultVisualOfScreen(s))->class == StaticColor);
2855        if  (mgv_colored)
2856                mgv_cmap = XDefaultColormapOfScreen( s );
2857
2858} /* end of mgh_get_colormap */
2859
2860
2861
2862/*----------------------------------------------------------------------------*/
2863
2864
2865
2866static void mgh_init_graphic_contexts( Widget w, BOOLEAN *ok )
2867
2868/* initializes global GC's and cursors
2869 *
2870 * parameters of routine
2871 * Widget      w;       input; widget ID
2872 * BOOLEAN    *ok;      output; return flag
2873 */
2874{
2875        /* local variables */
2876        int      xstatus;        /* X return value */
2877        XColor   screen_color;
2878        float    ftmp;           /* scratch */
2879
2880        /* executable code */
2881
2882        mgv_fixed_font = XLoadFont( XtDisplay(w), "fixed" );
2883
2884        if  (w == (Widget)0)  {*ok = FALSE; return;}
2885
2886        mgh_get_colormap( XtScreen(w) );  /* sets mgv_cmap & mgv_colored */
2887
2888        mgv_single_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2889        mgh_set_fg_color( XtDisplay(w), mgv_single_gc,
2890                pix_colour(PIXC_COL_FOREGROUND) );
2891        mgh_set_bg_color( XtDisplay(w), mgv_single_gc,
2892                pix_colour(PIXC_COL_BACKGROUND) );
2893        XSetFont( XtDisplay(w), mgv_single_gc, mgv_fixed_font );
2894
2895        mgv_single2_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2896        mgh_set_fg_color( XtDisplay(w), mgv_single2_gc,
2897                pix_colour(PIXC_COL_FOREGROUND) );
2898        mgh_set_bg_color( XtDisplay(w), mgv_single2_gc,
2899                pix_colour(PIXC_COL_BACKGROUND) );
2900        XSetFont( XtDisplay(w), mgv_single2_gc, mgv_fixed_font );
2901        if  (mgv_colored)  {
2902                screen_color.red = Nint( 0.0 * 65535.0 );
2903                screen_color.green = Nint( 0.7 * 65535.0 );
2904                screen_color.blue = Nint( 0.0 * 65535.0 );
2905                screen_color.flags = DoRed | DoGreen | DoBlue;
2906                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
2907                if  (xstatus == 0)  {
2908                        mgh_set_fg_color( XtDisplay(w), mgv_single2_gc,
2909                                XBlackPixelOfScreen(XtScreen(w)) );
2910                } else {
2911                        mgh_set_fg_color( XtDisplay(w), mgv_single2_gc,
2912                                screen_color.pixel );
2913                } /*endif*/
2914        } else {
2915                mgh_set_fg_color( XtDisplay(w), mgv_single2_gc,
2916                        XBlackPixelOfScreen(XtScreen(w)) );
2917                XSetLineAttributes( XtDisplay(w), mgv_single2_gc, 2, LineSolid,
2918                        CapNotLast, JoinMiter );
2919        } /*endif*/
2920
2921        mgv_single3_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2922        mgh_set_fg_color( XtDisplay(w), mgv_single3_gc,
2923                pix_colour(PIXC_COL_FOREGROUND) );
2924        mgh_set_bg_color( XtDisplay(w), mgv_single3_gc,
2925                pix_colour(PIXC_COL_BACKGROUND) );
2926        XSetFont( XtDisplay(w), mgv_single3_gc, mgv_fixed_font );
2927        if  (mgv_colored)  {
2928                screen_color.red = Nint( 0.0 * 65535.0 );
2929                screen_color.green = Nint( 0.4 * 65535.0 );
2930                screen_color.blue = Nint( 0.2 * 65535.0 );
2931                screen_color.flags = DoRed | DoGreen | DoBlue;
2932                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
2933                if  (xstatus == 0)  {
2934                        mgh_set_fg_color( XtDisplay(w), mgv_single3_gc,
2935                                XBlackPixelOfScreen(XtScreen(w)) );
2936                } else {
2937                        mgh_set_fg_color( XtDisplay(w), mgv_single3_gc,
2938                                screen_color.pixel );
2939                } /*endif*/
2940        } else {
2941                mgh_set_fg_color( XtDisplay(w), mgv_single3_gc,
2942                        XBlackPixelOfScreen(XtScreen(w)) );
2943                XSetLineAttributes( XtDisplay(w), mgv_single3_gc, 2, LineSolid,
2944                        CapNotLast, JoinMiter );
2945        } /*endif*/
2946
2947        mgv_phase_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2948        XSetFunction( XtDisplay(w), mgv_phase_gc, GXxor );
2949        if  (mgv_colored)  {
2950                screen_color.red = Nint( GpGetFloat(cGpF_colour_crsr_red) * 65535.0 );
2951                screen_color.green = Nint( GpGetFloat(cGpF_colour_crsr_green) * 65535.0 );
2952                screen_color.blue = Nint( GpGetFloat(cGpF_colour_crsr_blue) * 65535.0 );
2953                screen_color.flags = DoRed | DoGreen | DoBlue;
2954                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
2955                if  (xstatus == 0)  {
2956                        mgh_set_fg_color( XtDisplay(w), mgv_phase_gc,
2957                                XBlackPixelOfScreen(XtScreen(w)) );
2958                } else {
2959                        mgh_set_fg_color( XtDisplay(w), mgv_phase_gc,
2960                                screen_color.pixel );
2961                } /*endif*/
2962        } else {
2963                mgh_set_fg_color( XtDisplay(w), mgv_phase_gc,
2964                        XBlackPixelOfScreen(XtScreen(w)) );
2965        } /*endif*/
2966        mgh_set_bg_color( XtDisplay(w), mgv_phase_gc,
2967                pix_colour(PIXC_COL_BACKGROUND) );
2968        XSetFont( XtDisplay(w), mgv_phase_gc, mgv_fixed_font );
2969
2970        mgv_over_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2971        XSetFunction( XtDisplay(w), mgv_over_gc, GXcopy/*GXset*/ );
2972        mgh_set_fg_color( XtDisplay(w), mgv_over_gc,
2973                pix_colour(PIXC_COL_FOREGROUND) );
2974        mgh_set_bg_color( XtDisplay(w), mgv_over_gc,
2975                pix_colour(PIXC_COL_BACKGROUND) );
2976        XSetFont( XtDisplay(w), mgv_over_gc, mgv_fixed_font );
2977
2978        mgv_clear_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2979        XSetFunction( XtDisplay(w), mgv_clear_gc, GXcopy/*GXclear*/ );
2980        mgh_set_fg_color( XtDisplay(w), mgv_clear_gc,
2981                pix_colour(PIXC_COL_BACKGROUND) );
2982        mgh_set_bg_color( XtDisplay(w), mgv_clear_gc,
2983                pix_colour(PIXC_COL_FOREGROUND) );
2984        XSetFont( XtDisplay(w), mgv_clear_gc, mgv_fixed_font );
2985
2986        mgv_trcalert_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
2987        XSetFunction( XtDisplay(w), mgv_trcalert_gc, GXcopy/*GXset*/ );
2988        if  (mgv_colored)  {
2989                screen_color.red = Nint( GpGetFloat(cGpF_colour_alert_red) * 65535.0 );
2990                screen_color.green = Nint( GpGetFloat(cGpF_colour_alert_green) * 65535.0 );
2991                screen_color.blue = Nint( GpGetFloat(cGpF_colour_alert_blue) * 65535.0 );
2992                screen_color.flags = DoRed | DoGreen | DoBlue;
2993                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
2994                if  (xstatus == 0)  {
2995                        mgh_set_fg_color( XtDisplay(w), mgv_trcalert_gc,
2996                                XBlackPixelOfScreen(XtScreen(w)) );
2997                } else {
2998                        mgh_set_fg_color( XtDisplay(w), mgv_trcalert_gc,
2999                                screen_color.pixel );
3000                } /*endif*/
3001        } else {
3002                mgh_set_fg_color( XtDisplay(w), mgv_trcalert_gc,
3003                        XBlackPixelOfScreen(XtScreen(w)) );
3004        } /*endif*/
3005        mgh_set_bg_color( XtDisplay(w), mgv_trcalert_gc,
3006                pix_colour(PIXC_COL_BACKGROUND) );
3007        XSetFont( XtDisplay(w), mgv_trcalert_gc, mgv_fixed_font );
3008
3009        mgv_addfil_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
3010        XSetFunction( XtDisplay(w), mgv_addfil_gc, GXcopy/*GXset*/ );
3011        if  (mgv_colored)  {
3012                screen_color.red = Nint( GpGetFloat(cGpF_colour_addfil_red) * 65535.0 );
3013                screen_color.green = Nint( GpGetFloat(cGpF_colour_addfil_green) * 65535.0 );
3014                screen_color.blue = Nint( GpGetFloat(cGpF_colour_addfil_blue) * 65535.0 );
3015                screen_color.flags = DoRed | DoGreen | DoBlue;
3016                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
3017                if  (xstatus == 0)  {
3018                        mgh_set_fg_color( XtDisplay(w), mgv_addfil_gc,
3019                                XBlackPixelOfScreen(XtScreen(w)) );
3020                } else {
3021                        mgh_set_fg_color( XtDisplay(w), mgv_addfil_gc,
3022                                screen_color.pixel );
3023                } /*endif*/
3024        } else {
3025                mgh_set_fg_color( XtDisplay(w), mgv_addfil_gc,
3026                        XBlackPixelOfScreen(XtScreen(w)) );
3027        } /*endif*/
3028        mgh_set_bg_color( XtDisplay(w), mgv_addfil_gc,
3029                pix_colour(PIXC_COL_BACKGROUND) );
3030        XSetFont( XtDisplay(w), mgv_addfil_gc, mgv_fixed_font );
3031
3032        mgv_xor_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
3033        XSetFunction( XtDisplay(w), mgv_xor_gc, GXxor );
3034        if  (mgv_colored)  {
3035                screen_color.red = Nint( GpGetFloat(cGpF_colour_crsr_red) * 65535.0 );
3036                screen_color.green = Nint( GpGetFloat(cGpF_colour_crsr_green) * 65535.0 );
3037                screen_color.blue = Nint( GpGetFloat(cGpF_colour_crsr_blue) * 65535.0 );
3038                screen_color.flags = DoRed | DoGreen | DoBlue;
3039                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
3040                if  (xstatus == 0)  {
3041                        mgh_set_fg_color( XtDisplay(w), mgv_xor_gc,
3042                                XBlackPixelOfScreen(XtScreen(w)) );
3043                } else {
3044                        mgh_set_fg_color( XtDisplay(w), mgv_xor_gc,
3045                                screen_color.pixel );
3046                } /*endif*/
3047        } else {
3048                mgh_set_fg_color( XtDisplay(w), mgv_xor_gc,
3049                        XBlackPixelOfScreen(XtScreen(w)) );
3050        } /*endif*/
3051        mgh_set_bg_color( XtDisplay(w), mgv_xor_gc,
3052                pix_colour(PIXC_COL_BACKGROUND) );
3053        /* XSetLineAttributes( XtDisplay(w), mgv_xor_gc, 1,
3054                LineOnOffDash, CapButt, JoinMiter ); */
3055        XSetFont( XtDisplay(w), mgv_xor_gc, mgv_fixed_font );
3056
3057        mgv_auto_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
3058        XSetFunction( XtDisplay(w), mgv_auto_gc, GXxor );
3059        if  (mgv_colored)  {
3060                screen_color.red = Nint( GpGetFloat(cGpF_colour_auto_red) * 65535.0 );
3061                screen_color.green = Nint( GpGetFloat(cGpF_colour_auto_green) * 65535.0 );
3062                screen_color.blue = Nint( GpGetFloat(cGpF_colour_auto_blue) * 65535.0 );
3063                screen_color.flags = DoRed | DoGreen | DoBlue;
3064                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
3065                if  (xstatus == 0)  {
3066                        mgh_set_fg_color( XtDisplay(w), mgv_auto_gc,
3067                                XBlackPixelOfScreen(XtScreen(w)) );
3068                } else {
3069                        mgh_set_fg_color( XtDisplay(w), mgv_auto_gc,
3070                                screen_color.pixel );
3071                } /*endif*/
3072        } else {
3073                mgh_set_fg_color( XtDisplay(w), mgv_auto_gc,
3074                        XBlackPixelOfScreen(XtScreen(w)) );
3075        } /*endif*/
3076        mgh_set_bg_color( XtDisplay(w), mgv_auto_gc,
3077                pix_colour(PIXC_COL_BACKGROUND) );
3078        XSetFont( XtDisplay(w), mgv_auto_gc, mgv_fixed_font );
3079
3080        mgv_theo_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
3081        XSetFunction( XtDisplay(w), mgv_theo_gc, GXxor );
3082        if  (mgv_colored)  {
3083                screen_color.red = Nint( GpGetFloat(cGpF_colour_theo_red) * 65535.0 );
3084                screen_color.green = Nint( GpGetFloat(cGpF_colour_theo_green) * 65535.0 );
3085                screen_color.blue = Nint( GpGetFloat(cGpF_colour_theo_blue) * 65535.0 );
3086                screen_color.flags = DoRed | DoGreen | DoBlue;
3087                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
3088                if  (xstatus == 0)  {
3089                        mgh_set_fg_color( XtDisplay(w), mgv_theo_gc,
3090                                XBlackPixelOfScreen(XtScreen(w)) );
3091                } else {
3092                        mgh_set_fg_color( XtDisplay(w), mgv_theo_gc,
3093                                screen_color.pixel );
3094                } /*endif*/
3095        } else {
3096                mgh_set_fg_color( XtDisplay(w), mgv_theo_gc,
3097                        XBlackPixelOfScreen(XtScreen(w)) );
3098        } /*endif*/
3099        mgh_set_bg_color( XtDisplay(w), mgv_theo_gc,
3100                pix_colour(PIXC_COL_BACKGROUND) );
3101        XSetFont( XtDisplay(w), mgv_theo_gc, mgv_fixed_font );
3102
3103        mgv_mark_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
3104        XSetFunction( XtDisplay(w), mgv_mark_gc, GXxor );
3105        if  (mgv_colored)  {
3106                screen_color.red = Nint( GpGetFloat(cGpF_colour_mark_red) * 65535.0 );
3107                screen_color.green = Nint( GpGetFloat(cGpF_colour_mark_green) * 65535.0 );
3108                screen_color.blue = Nint( GpGetFloat(cGpF_colour_mark_blue) * 65535.0 );
3109                screen_color.flags = DoRed | DoGreen | DoBlue;
3110                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
3111                if  (xstatus == 0)  {
3112                        mgh_set_fg_color( XtDisplay(w), mgv_mark_gc,
3113                                XBlackPixelOfScreen(XtScreen(w)) );
3114                } else {
3115                        mgh_set_fg_color( XtDisplay(w), mgv_mark_gc,
3116                                screen_color.pixel );
3117                } /*endif*/
3118        } else {
3119                mgh_set_fg_color( XtDisplay(w), mgv_mark_gc,
3120                        XBlackPixelOfScreen(XtScreen(w)) );
3121                XSetLineAttributes( XtDisplay(w), mgv_mark_gc, 2, LineSolid,
3122                        CapNotLast, JoinMiter );
3123        } /*endif*/
3124        mgh_set_bg_color( XtDisplay(w), mgv_mark_gc,
3125                pix_colour(PIXC_COL_BACKGROUND) );
3126        XSetFont( XtDisplay(w), mgv_mark_gc, mgv_fixed_font );
3127
3128        mgv_mark0_gc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL );
3129        XSetFunction( XtDisplay(w), mgv_mark0_gc, GXxor );
3130        if  (mgv_colored)  {
3131                screen_color.red = Nint( GpGetFloat(cGpF_colour_mark0_red) * 65535.0 );
3132                screen_color.green = Nint( GpGetFloat(cGpF_colour_mark0_green) * 65535.0 );
3133                screen_color.blue = Nint( GpGetFloat(cGpF_colour_mark0_blue) * 65535.0 );
3134                screen_color.flags = DoRed | DoGreen | DoBlue;
3135                xstatus = XAllocColor( XtDisplay(w), mgv_cmap, &screen_color );
3136                if  (xstatus == 0)  {
3137                        mgh_set_fg_color( XtDisplay(w), mgv_mark0_gc,
3138                                XBlackPixelOfScreen(XtScreen(w)) );
3139                } else {
3140                        mgh_set_fg_color( XtDisplay(w), mgv_mark0_gc,
3141                                screen_color.pixel );
3142                } /*endif*/
3143        } else {
3144                mgh_set_fg_color( XtDisplay(w), mgv_mark0_gc,
3145                        XBlackPixelOfScreen(XtScreen(w)) );
3146                XSetLineAttributes( XtDisplay(w), mgv_mark0_gc, 2, LineSolid,
3147                        CapNotLast, JoinMiter );
3148        } /*endif*/
3149        mgh_set_bg_color( XtDisplay(w), mgv_mark0_gc,
3150                pix_colour(PIXC_COL_BACKGROUND) );
3151        XSetFont( XtDisplay(w), mgv_mark0_gc, mgv_fixed_font );
3152
3153        mgv_crsr[MGC_XCRSR_NORMAL] =
3154                XCreateFontCursor( XtDisplay(w), XC_sb_left_arrow );
3155        mgv_crsr[MGC_XCRSR_CROSS] = XCreateFontCursor( XtDisplay(w), XC_crosshair );
3156        mgv_crsr[MGC_XCRSR_BUSY] = XCreateFontCursor( XtDisplay(w), XC_watch );
3157        mgv_crsr[MGC_XCRSR_WAVE] = XCreateFontCursor( XtDisplay(w), XC_draft_small );
3158        mgv_crsr[MGC_XCRSR_LEFT] = XCreateFontCursor( XtDisplay(w), XC_left_tee );
3159        mgv_crsr[MGC_XCRSR_RIGHT] = XCreateFontCursor( XtDisplay(w), XC_right_tee );
3160
3161        *ok = TRUE;
3162
3163} /* end of mgh_init_graphic_contexts */
3164
3165
3166
3167/*----------------------------------------------------------------------------*/
3168
3169
3170#define NO_TIME " --:--:--.---"
3171
3172
3173void mg_print_time( Widget w, int wdwno, int x, int y )
3174
3175/* prints absolute time in window
3176 *
3177 * parameters of routine
3178 * Widget     w;         input; Widget ID of window where to write time string
3179 * int        wdwno;     input; number of window which caused MotionNotify
3180 * int        x, y;      input; cursor position
3181 */
3182{
3183        /* local variables */
3184        static char oldstr[BC_LINELTH+1]; /* old text */
3185        float    reltime;                 /* relative time */
3186        int      trcno;                   /* trace number */
3187        BOOLEAN  ok;                      /* return flag */
3188        char     timestr[BC_LINELTH+1];   /* time string */
3189        TIME     trctime;                 /* start time of trace */
3190        float    torig;                   /* time offset */
3191        STATUS   locstat;                 /* local status */
3192        int      slen;                    /* string length */
3193
3194        /* executable code */
3195
3196        if  (mgv_di.trcno == 0)  return;
3197
3198        if  (wdwno == MGC_WDW_SINGLE)  {
3199                mg_get_time_and_trace_single( x, y, &reltime, &trcno, &ok );
3200        } else {
3201                mg_get_time_and_trace( x, y, &reltime, &trcno, &ok );
3202        } /*endif*/
3203        if  (ok)  {
3204                locstat = BC_NOERROR;
3205                db_gett( mgv_ti[trcno-1].trc, ET_START, &trctime, &locstat );
3206                if  (locstat == BC_NOERROR)  {
3207                        tc_aadd( &trctime, reltime, &trctime );
3208                        torig = 0.0;
3209                        torig = db_getr( mgv_ti[trcno-1].trc, ER_TORIG, &locstat );
3210                        tc_aadd( &trctime, -torig, &trctime );
3211                        tc_a2t( &trctime, timestr, &locstat );
3212                        if  (locstat != BC_NOERROR)  printf("*SHM: mg_print_time\n");
3213                } else {
3214                        strncpy( timestr, oldstr, 11 );
3215                        timestr[11] = '\0';
3216                        strcat( timestr, NO_TIME );
3217                } /*endif*/
3218        } else {
3219                strncpy( timestr, oldstr, 11 );
3220                timestr[11] = '\0';
3221                strcat( timestr, NO_TIME );
3222        } /*endif*/
3223
3224        /* append time span info in min */
3225        slen = strlen( timestr );
3226        sprintf( timestr+slen, "  >%4.2f<", mgv_di.totslth/60.0 );
3227
3228        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3229                TEXT_X_TIME, mgv_wdwsetup.margin_t+TEXT_Y_TIME,
3230                oldstr, (int)strlen(oldstr) );
3231        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3232                TEXT_X_TIME, mgv_wdwsetup.margin_t+TEXT_Y_TIME,
3233                timestr, (int)strlen(timestr) );
3234        strcpy( oldstr, timestr );
3235
3236} /* end of mg_print_time */
3237
3238
3239
3240/*----------------------------------------------------------------------------*/
3241
3242
3243
3244void mg_current_time_window( char stime[], float *width )
3245
3246/* returns current time window of main display (using first trace of display)
3247 *
3248 * parameters of routine
3249 * char       stime[];     output; absolute start time of window
3250 * float      *width;      output; width of display in s
3251 */
3252{
3253        /* local variables */
3254        int      trcno;                   /* trace number */
3255        BOOLEAN  ok;                      /* return flag */
3256        char     timestr[BC_LINELTH+1];   /* time string */
3257        TIME     trctime;                 /* start time of trace */
3258        float    torig;                   /* time offset */
3259        STATUS   locstat;                 /* local status */
3260        int      slen;                    /* string length */
3261
3262        /* executable code */
3263
3264        if  (mgv_di.trcno == 0)  {
3265                strcpy( stime, "1-Jan-1970_00:00" );
3266                *width = 0.0;
3267                return;
3268        } /*endif*/
3269
3270        locstat = BC_NOERROR;
3271        db_gett( mgv_ti[0].trc, ET_START, &trctime, &locstat );
3272        if  (locstat == BC_NOERROR)  {
3273                torig = db_getr( mgv_ti[0].trc, ER_TORIG, &locstat );
3274                tc_aadd( &trctime, -torig, &trctime );
3275                tc_a2t( &trctime, stime, &locstat );
3276                if  (locstat != BC_NOERROR)  printf("*SHM: mg_current_time_window\n");
3277        } else {
3278                strcpy( stime, "1-Jan-1970_00:00" );
3279                *width = 0.0;
3280                return;
3281        } /*endif*/
3282
3283        *width = (float)(mgv_di.wdweff_w)/mgv_di.pixpersec;
3284
3285} /* end of mg_current_time_window */
3286
3287
3288
3289/*----------------------------------------------------------------------------*/
3290
3291
3292#define BUSY_STRING "Computing..."
3293
3294
3295void mg_print_busy( Widget w, BOOLEAN busy )
3296
3297/* prints busy message on window
3298 *
3299 * parameters of routine
3300 * Widget     w;         input; widget of DrawingArea
3301 * BOOLEAN    busy;      input; busy flag on/off
3302 */
3303{
3304        /* executable code */
3305
3306        if  (busy)  {
3307                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3308                        TEXT_X_BUSY, mgv_wdwsetup.margin_t+TEXT_Y_BUSY,
3309                        BUSY_STRING, (int)strlen(BUSY_STRING) );
3310        } else {
3311                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3312                        TEXT_X_BUSY, mgv_wdwsetup.margin_t+TEXT_Y_BUSY,
3313                        BUSY_STRING, (int)strlen(BUSY_STRING) );
3314        } /*endif*/
3315        XFlush( XtDisplay(w) );
3316
3317} /* end of mg_print_busy */
3318
3319
3320
3321/*----------------------------------------------------------------------------*/
3322
3323
3324
3325void mg_print_status( Widget w, char text[], BOOLEAN on_off )
3326
3327/* prints/clears status message on window
3328 *
3329 * parameters of routine
3330 * Widget     w;         input; widget of DrawingArea
3331 * char       text[];    input; text to print
3332 * BOOLEAN    on_off;    input; print/clear
3333 */
3334{
3335        /* executable code */
3336
3337        if  (on_off)  {
3338                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3339                        TEXT_X_STATUS, mgv_wdwsetup.margin_t+TEXT_Y_STATUS,
3340                        text, (int)strlen(text) );
3341        } else {
3342                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3343                        TEXT_X_STATUS, mgv_wdwsetup.margin_t+TEXT_Y_STATUS,
3344                        text, (int)strlen(text) );
3345        } /*endif*/
3346        XFlush( XtDisplay(w) );
3347
3348} /* end of mg_print_status */
3349
3350
3351
3352/*----------------------------------------------------------------------------*/
3353
3354
3355
3356
3357void mg_print_filter( Widget w, char filter[] )
3358
3359/* prints busy message on window
3360 *
3361 * parameters of routine
3362 * Widget     w;         input; widget of DrawingArea
3363 * char       filter[];  input; name of filter
3364 */
3365{
3366        /* local variables */
3367        char     str[BC_LINELTH+1];      /* scratch string */
3368        static char oldstr[BC_LINELTH+1];  /* last name printed */
3369
3370        /* executable code */
3371
3372        if  (strncmp(filter,"S+",2) == 0)  filter += 2;
3373
3374        if  (strlen(filter) > BC_LINELTH-10)  {
3375                strcpy( str, "Filter: name too long" );
3376        } else if  (*filter == '\0')  {
3377                strcpy( str, "Filter: None" );
3378                *mgv_filter = '\0';
3379        } else {
3380                sprintf( str, "Filter: %s", filter );
3381                strcpy( mgv_filter, filter );
3382        } /*endif*/
3383
3384        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3385                TEXT_X_FILTER, mgv_wdwsetup.margin_t+TEXT_Y_FILTER,
3386                oldstr, (int)strlen(oldstr) );
3387        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3388                TEXT_X_FILTER, mgv_wdwsetup.margin_t+TEXT_Y_FILTER,
3389                str, (int)strlen(str) );
3390        strcpy( oldstr, str );
3391        XFlush( XtDisplay(w) );
3392
3393} /* end of mg_print_filter */
3394
3395
3396
3397/*----------------------------------------------------------------------------*/
3398
3399
3400
3401
3402void mg_print_lastcmd( Widget w, char lastcmd[] )
3403
3404/* prints last command in window
3405 *
3406 * parameters of routine
3407 * Widget     w;          input; widget of DrawingArea
3408 * char       lastcmd[];  input; name of filter
3409 */
3410{
3411        /* local variables */
3412        char     str[BC_LINELTH+1];      /* scratch string */
3413        static char oldstr[BC_LINELTH+1];  /* last name printed */
3414
3415        /* executable code */
3416
3417        if  (strlen(lastcmd) > BC_LINELTH-10)  {
3418                strcpy( str, "LastCmd: name too long" );
3419        } else if  (*lastcmd == '\0' || *lastcmd == ' ')  {
3420                strcpy( str, "LastCmd: Empty" );
3421                *mgv_filter = '\0';
3422        } else {
3423                sprintf( str, "LastCmd: %s", lastcmd );
3424        } /*endif*/
3425
3426        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3427                TEXT_X_LASTCMD, mgv_wdwsetup.margin_t+TEXT_Y_LASTCMD,
3428                oldstr, (int)strlen(oldstr) );
3429        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3430                TEXT_X_LASTCMD, mgv_wdwsetup.margin_t+TEXT_Y_LASTCMD,
3431                str, (int)strlen(str) );
3432        strcpy( oldstr, str );
3433        XFlush( XtDisplay(w) );
3434
3435} /* end of mg_print_lastcmd */
3436
3437
3438
3439/*----------------------------------------------------------------------------*/
3440
3441
3442
3443void mg_print_sortinfo( Widget w, char sortinfo[] )
3444
3445/* prints sort info in window
3446 *
3447 * parameters of routine
3448 * Widget     w;          input; widget of DrawingArea
3449 * char       sortinfo[]; input; sort info
3450 */
3451{
3452        /* local variables */
3453        char     str[BC_LINELTH+1];      /* scratch string */
3454        static char oldstr[BC_LINELTH+1];  /* last name printed */
3455
3456        /* executable code */
3457
3458        if  (strlen(sortinfo) > BC_LINELTH-10)  {
3459                strcpy( str, "sort:?" );
3460        } else {
3461                strcpy( str, sortinfo );
3462        } /*endif*/
3463
3464        if  (*oldstr != '\0')
3465                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3466                        TEXT_X_SORT, mgv_wdwsetup.margin_t+TEXT_Y_SORT,
3467                        oldstr, (int)strlen(oldstr) );
3468        if  (*str != '\0')
3469                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3470                        TEXT_X_SORT, mgv_wdwsetup.margin_t+TEXT_Y_SORT,
3471                        str, (int)strlen(str) );
3472        strcpy( oldstr, str );
3473        XFlush( XtDisplay(w) );
3474
3475} /* end of mg_print_sortinfo */
3476
3477
3478
3479/*----------------------------------------------------------------------------*/
3480
3481
3482
3483void mg_print_detecinfo( Widget w, char detecinfo[] )
3484
3485/* prints detection line in window
3486 *
3487 * parameters of routine
3488 * Widget     w;          input; widget of DrawingArea
3489 * char       detecinfo[]; input; detection info
3490 */
3491{
3492        /* local variables */
3493        static int  ypos=(-1);            /* text y position */
3494        static char oldstr[BC_LINELTH+1]; /* last name printed */
3495        char        str[BC_LINELTH+1];    /* scratch string */
3496        int         i;                    /* counter */
3497
3498        /* executable code */
3499
3500        /* check configuration parameter */
3501        if  (!GpGetBoolean(cGpB_show_evt_info))
3502            return;
3503
3504        if  (ypos < 0)  {
3505                Window   root_ret;   /* root window */
3506                int      x, y;       /* position within root window */
3507                unsigned bw, dp;     /* border width & depth */
3508                unsigned xw, xh;
3509                /* not yet initialised */
3510                XGetGeometry( XtDisplay(w), XtWindow(w), &root_ret,
3511                        &x, &y, &xw, &xh, &bw, &dp );
3512                ypos = xh + TEXT_Y_DETEC;
3513        } /*endif*/
3514
3515        if  (strcmp(detecinfo,"--redraw--") == 0)  {
3516                if  (*oldstr != '\0')  {
3517                        strcpy( str, oldstr );
3518                        pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3519                                TEXT_X_DETEC, mgv_wdwsetup.margin_t+ypos,
3520                                str, (int)strlen(str) );
3521                        XFlush( XtDisplay(w) );
3522                } /*endif*/
3523                return;
3524        } /*endif*/
3525
3526        if  (strlen(detecinfo) > BC_LINELTH-10)  {
3527                strcpy( str, "detec:?" );
3528        } else {
3529                strcpy( str, detecinfo );
3530                i = strlen( str );
3531                if  (i>0 && str[i-1] == '\n')
3532                        str[i-1] = '\0';
3533        } /*endif*/
3534
3535        if  (*oldstr != '\0')
3536                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_clear_gc,
3537                        TEXT_X_DETEC, mgv_wdwsetup.margin_t+ypos,
3538                        oldstr, (int)strlen(oldstr) );
3539        if  (*str != '\0')
3540                pix_DrawString( XtDisplay(w), XtWindow(w), mgv_over_gc,
3541                        TEXT_X_DETEC, mgv_wdwsetup.margin_t+ypos,
3542                        str, (int)strlen(str) );
3543        strcpy( oldstr, str );
3544        XFlush( XtDisplay(w) );
3545
3546} /* end of mg_print_detecinfo */
3547
3548
3549
3550/*----------------------------------------------------------------------------*/
3551
3552
3553
3554void mg_selected_wave( float **wavptr, int *lth, char stime[], float *dt,
3555        char station[], char chan[], char *comp )
3556
3557/* Returns pointer to selected waveform or NULL if nothing selected.
3558 * Copies the waveform, so the data at '*wavptr' must not be freed after use.
3559 *
3560 * parameters of routine
3561 * float      **wavptr;    output; pointer to waveform or NULL
3562 * int        *lth;        output; length of trace in samples
3563 * char       stime[];     output; start time of waveform
3564 * float      *dt;         output; sample distance of trace
3565 * char       station[];   output; station name (min length cBcShortStrLth)
3566 * char       chan[];      output; channel name (min length 3)
3567 * char       *comp;       output; component (min length 1)
3568 */
3569{
3570        /* local variables */
3571        int      y;               /* y-position of trace */
3572        int      trcno;           /* trace number */
3573        float    t_start, t_end;  /* start and end time of trace (in sec) */
3574        TSyBoolean ok;            /* return status */
3575        float    *datptr;         /* pointer to sample data */
3576        int      s_first;         /* first sample wanted */
3577        TSyStatus locstat;        /* local status variable */
3578        int      i;               /* counter */
3579        TIME     abstime;         /* start time */
3580
3581        /* executable code */
3582
3583        /* initialize */
3584        *wavptr = NULL;
3585        *lth = 0;
3586        *stime = '\0';
3587        ok = TRUE;
3588        locstat = cBcNoError;
3589
3590        if  (mgv_di.trcno == 0)  {
3591                printf( "*SHM: mg_selected_wave: no trace available\n" );
3592                return;
3593        } /*endif*/
3594        if  (!mgv_drag.on)  {
3595                printf( "*SHM: mg_selected_wave: no waveform available\n" );
3596                return;
3597        } /*endif*/
3598        y = (mgv_drag.y1 + mgv_drag.y2) / 2;
3599        mg_get_time_and_trace( mgv_drag.x1, y, &t_start, &trcno, &ok );
3600        if  (!ok)  {printf("*SHM: mg_selected_wave: error 1\n" ); return;}
3601        mg_get_time_and_trace( mgv_drag.x2, y, &t_end, NULL, &ok );
3602        if  (!ok)  {printf("*SHM: mg_selected_wave: error 2\n" ); return;}
3603        trcno--;
3604        datptr = (float *)db_getp( mgv_ti[trcno].trc, EP_DATA, NULL );
3605        s_first = dm_getsample( mgv_ti[trcno].trc, t_start, TRUE );
3606        *lth = dm_getsample( mgv_ti[trcno].trc, t_end, TRUE );
3607        *lth -= s_first + 1;
3608        if  (*lth <= 1)  {
3609                printf( "*SHM: mg_selected_wave: waveform too short\n" );
3610                return;
3611        } /*endif*/
3612        datptr += s_first;
3613
3614        /* *wavptr = datptr; */
3615
3616        /* this makes a copy of the data */
3617        *wavptr = (float *)sy_allocmem( *lth, (int)sizeof(float), &locstat );
3618        if  (Severe(&locstat))  {
3619                *wavptr = NULL;
3620                printf( "*SHM: mg_selected_wave: waveform allocation error\n" );
3621                return;
3622        } /*endif*/
3623        for (i=0; i<(*lth); i++)
3624                (*wavptr)[i] = datptr[i];
3625
3626        *dt = db_getr( mgv_ti[trcno].trc, ER_DELTA, NULL );
3627        *comp = db_getc( mgv_ti[trcno].trc, EC_COMP, NULL );
3628        chan[0] = db_getc( mgv_ti[trcno].trc, EC_CHAN1, NULL );
3629        chan[1] = db_getc( mgv_ti[trcno].trc, EC_CHAN2, NULL );
3630        chan[2] = '\0';
3631        db_gets( mgv_ti[trcno].trc, ES_STATION, cBcShortStrLth, station, &locstat );
3632
3633        db_gett( mgv_ti[trcno].trc, ET_START, &abstime, &locstat );
3634        if  (SySevere(&locstat))  return;
3635        tc_aadd( &abstime, t_start, &abstime );
3636        tc_a2t( &abstime, stime, &locstat );
3637
3638} /* end of mg_selected_wave */
3639
3640
3641
3642/*----------------------------------------------------------------------------*/
3643
3644
3645
3646void mg_set_cursor_widgets( Widget w[], int num )
3647
3648/* Sets widgets of drawing areas where cursor form may be changed
3649 *
3650 * parameters of routine
3651 * Widget        w[];       input; drawing area widgets
3652 * int           num;       input; length of above array (<= MAXCRSRDSP)
3653 */
3654{
3655        /* local variables */
3656        int      i;               /* counter */
3657
3658        /* executable code */
3659
3660        if  (num > MAXCRSRDSP)  {
3661                printf( "*SHM: number of cursor windows exceeded.  Truncated.\n" );
3662                num = MAXCRSRDSP;
3663        } /*endif*/
3664
3665        mgv_crsrdspnum = num;
3666        for  (i=0; i<num; i++)
3667                mgv_crsrdsp[i] = w[i];
3668
3669} /* end of mg_set_cursor_widgets */
3670
3671
3672
3673/*----------------------------------------------------------------------------*/
3674
3675
3676
3677void mg_add_cursor_widget( Widget w )
3678
3679/* Adds widget to list of drawing areas where cursor form may be changed
3680 *
3681 * parameters of routine
3682 * Widget        w;       input; drawing area widgets
3683 * int           num;       input; length of above array (<= MAXCRSRDSP)
3684 */
3685{
3686        /* local variables */
3687
3688        /* executable code */
3689
3690        if  (mgv_crsrdspnum >= MAXCRSRDSP)  {
3691                printf( "*SHM: number of cursor windows exceeded.  Ignored.\n" );
3692                return;
3693        } /*endif*/
3694
3695        mgv_crsrdsp[mgv_crsrdspnum++] = w;
3696
3697} /* end of mg_add_cursor_widget */
3698
3699
3700
3701/*----------------------------------------------------------------------------*/
3702
3703
3704
3705void mg_set_cursor( int cursor )
3706
3707/* Sets cursor form in all windows passed in mg_set_cursor_widgets.
3708 *
3709 * parameters of routine
3710 * Display    *dsp;        input; pointer to display
3711 * Window     w;           input; window of cursor
3712 * int        cursor;      input; corsor ID
3713 */
3714{
3715        /* local variables */
3716        static int crsr_defined=FALSE;  /* is a cursor defined ? */
3717        int      i;          /* counter */
3718
3719        /* executable code */
3720
3721        if  (cursor < 0 || cursor > MGC_XCRSR_MAX)  {
3722                printf( "*SHM: mg_set_cursor: bug in program\n" );
3723                return;
3724        } /*endif*/
3725
3726        if  (cursor == MGC_XCRSR_NORMAL)  {
3727                /*XDefineCursor( dsp, w, mgv_crsr[cursor] );*/
3728                if  (crsr_defined)  {
3729                        for  (i=0; i<mgv_crsrdspnum; i++)
3730                                if  (XtIsManaged(mgv_crsrdsp[i]))
3731                                        XUndefineCursor( XtDisplay(mgv_crsrdsp[i]),
3732                                                XtWindow(mgv_crsrdsp[i]) );
3733                        crsr_defined = FALSE;
3734                } else {
3735                        printf( "*SHM: cursor already undefined\n" );
3736                } /*endif*/
3737        } else {
3738                if  (crsr_defined)  {
3739                        printf( "*SHM: cursor already defined, undefine first\n" );
3740                        for  (i=0; i<mgv_crsrdspnum; i++)
3741                                if  (XtIsManaged(mgv_crsrdsp[i]))
3742                                        XUndefineCursor( XtDisplay(mgv_crsrdsp[i]),
3743                                                XtWindow(mgv_crsrdsp[i]) );
3744                } /*endif*/
3745                for  (i=0; i<mgv_crsrdspnum; i++)
3746                        if  (XtIsManaged(mgv_crsrdsp[i]))
3747                                XDefineCursor( XtDisplay(mgv_crsrdsp[i]), XtWindow(mgv_crsrdsp[i]),
3748                                        mgv_crsr[cursor] );
3749                crsr_defined = TRUE;
3750        } /*endif*/
3751
3752} /* end of mg_set_cursor */
3753
3754
3755
3756/*----------------------------------------------------------------------------*/
3757
3758
3759
3760void mg_rubber_line( Widget w, int wdwno, int mode, int x, int y )
3761
3762/* Draws rubber line
3763 *
3764 * parameters of routine
3765 * Widget     w;             input; widget ID of drawing area
3766 * int        wdwno;         input; window number
3767 * int        mode;          input; mode (START,CONT,END)
3768 * int        x, y;          input; mouse position
3769 */
3770{
3771        /* local variables */
3772        static int  init_wdwno;       /* window number of first call */
3773        static BOOLEAN drawn;         /* line is drawn */
3774        static int  init_x, init_y;   /* first position */
3775        static int  old_x, old_y;     /* last position */
3776        int         new_x, new_y;     /* current position */
3777        float       time;             /* selected time (not used) */
3778        int         trcno;            /* number of selected trace */
3779        BOOLEAN     ok;               /* selection ok ? */
3780
3781        /* executable code */
3782
3783        switch  (mode)  {
3784        case MGC_RUBBER_START:
3785                if  (wdwno == MGC_WDW_SINGLE)  {
3786                        mg_get_time_and_trace_single( x, y, &time, &trcno, &ok );
3787                        init_y = old_y = mgv_wdwsetup.margin_t/*b*/ + mgv_sdi.unitheight / 2.0;
3788                } else {
3789                        mg_get_time_and_trace( x, y, &time, &trcno, &ok );
3790                        init_y = old_y = mgv_ti[trcno-1].xenv->orig.y;
3791                } /*endif*/
3792                if  (!ok)  {
3793                        printf( "*SHM: mg_rubber_line: couldn't get trace\n" );
3794                        return;
3795                } /*endif*/
3796                init_x = old_x = x;
3797                init_wdwno = wdwno;
3798                drawn = FALSE;
3799                break;
3800        case MGC_RUBBER_CONT_L:
3801                if  (wdwno != init_wdwno)  return;
3802                if  (drawn)  {
3803                        pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_mark_gc,
3804                                init_x, init_y, old_x, old_y );
3805                } /*endif*/
3806                new_x = x;
3807                new_y = old_y;
3808                if  (new_x < init_x)  {
3809                        pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_mark_gc,
3810                                init_x, init_y, new_x, new_y );
3811                        drawn = TRUE;
3812                        old_x = new_x;
3813                        old_y = new_y;
3814                } else {
3815                        drawn = FALSE;
3816                } /*endif*/
3817                break;
3818        case MGC_RUBBER_CONT_R:
3819                if  (wdwno != init_wdwno)  return;
3820                if  (drawn)  {
3821                        pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_mark_gc,
3822                                init_x, init_y, old_x, old_y );
3823                } /*endif*/
3824                new_x = x;
3825                new_y = old_y;
3826                if  (new_x > init_x)  {
3827                        pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_mark_gc,
3828                                init_x, init_y, new_x, new_y );
3829                        drawn = TRUE;
3830                        old_x = new_x;
3831                        old_y = new_y;
3832                } else {
3833                        drawn = FALSE;
3834                } /*endif*/
3835                break;
3836        case MGC_RUBBER_END:
3837                if  (wdwno != init_wdwno)  return;
3838                if  (drawn)  {
3839                        pix_DrawLine( XtDisplay(w), XtWindow(w), mgv_mark_gc,
3840                                init_x, init_y, old_x, old_y );
3841                } /*endif*/
3842                drawn = FALSE;
3843                break;
3844        default:
3845                printf( "*SHM: illegal rubber_line mode %d\n", mode );
3846                return;
3847        } /*endswitch*/
3848
3849        XFlush( XtDisplay(w) );
3850
3851} /* end of mg_rubber_line */
3852
3853
3854
3855/*----------------------------------------------------------------------------*/
3856
3857
3858
3859static void mgh_set_bg_color( Display *dsp, GC gc, unsigned long bg )
3860
3861/* sets background color
3862 *
3863 * parameters of routine
3864 * same as in XSetBackground;
3865 */
3866{
3867        /* local variables */
3868        XGCValues  val;      /* values of GC */
3869
3870        /* executable code */
3871
3872        XSetBackground( dsp, gc, bg );
3873
3874#ifdef XXX
3875        if  (mgv_reverse_xors)  {
3876                XGetGCValues( dsp, gc, GCFunction, &val );
3877                if  (val.function == GXxor)  {
3878                        XSetForeground( dsp, gc, bg );
3879                } else {
3880                        XSetBackground( dsp, gc, bg );
3881                } /*endif*/
3882        } else {
3883                XSetBackground( dsp, gc, bg );
3884        } /*endif*/
3885#endif
3886
3887} /* end of mgh_set_bg_color */
3888
3889
3890
3891/*----------------------------------------------------------------------------*/
3892
3893
3894
3895static void mgh_set_fg_color( Display *dsp, GC gc, unsigned long fg )
3896
3897/* sets foreground color
3898 *
3899 * parameters of routine
3900 * same as in XSetForeground;
3901 */
3902{
3903        /* local variables */
3904        XGCValues  val;      /* values of GC */
3905
3906        /* executable code */
3907
3908        if  (mgv_reverse_xors)  {
3909                XGetGCValues( dsp, gc, GCFunction, &val );
3910                if  (val.function == GXxor)  {
3911                        XSetForeground( dsp, gc, ~fg );
3912                } else {
3913                        XSetForeground( dsp, gc, fg );
3914                } /*endif*/
3915        } else {
3916                XSetForeground( dsp, gc, fg );
3917        } /*endif*/
3918
3919#ifdef XXX
3920        if  (mgv_reverse_xors)  {
3921                XGetGCValues( dsp, gc, GCFunction, &val );
3922                if  (val.function == GXxor)  {
3923                        XSetBackground( dsp, gc, fg );
3924                } else {
3925                        XSetForeground( dsp, gc, fg );
3926                } /*endif*/
3927        } else {
3928                XSetForeground( dsp, gc, fg );
3929        } /*endif*/
3930#endif
3931
3932} /* end of mgh_set_fg_color */
3933
3934
3935
3936/*----------------------------------------------------------------------------*/
3937
3938
3939
3940void mg_disable_redraw( BOOLEAN on_off )
3941
3942/* Disables/Enables redraw with mg_tracedisplay
3943 *
3944 * parameters of routine
3945 * BOOLEAN    on_off;     input; switch value
3946 */
3947{
3948        /* executable code */
3949
3950        mgv_disable_rd = on_off;
3951
3952} /* end of mg_disable_redraw */
3953
3954
3955
3956/*----------------------------------------------------------------------------*/
3957
3958
3959
3960void mg_find_3_traces( int tmain, int *ta, int *tb )
3961
3962/* Finds associated traces to tmain (traces of same station and different
3963 * components.  Returns -1 if no traces found
3964 *
3965 * parameters of routine
3966 * int        tmain;        input; number of main trace
3967 * int        *ta, *tb;     output; associated traces
3968 */
3969{
3970        /* local variables */
3971        void     *pmain, *pa, *pb;            /* trace pointers */
3972        TSyStatus locstat;                    /* local status */
3973        char     mstation[cBcShortStrLth+1];  /* station name of main trace */
3974        char     astation[cBcShortStrLth+1];  /* station name of trace a */
3975        int      idx[4];                      /* 4 traces are searched */
3976        int      i;                           /* counter */
3977
3978        /* executable code */
3979
3980        *ta = *tb = -1;
3981
3982        pmain = mg_trcptr( tmain );
3983        if  (pmain == NULL)  {
3984                printf( "*SHM: no trcptr for main trace (%d) found\n", tmain );
3985                return;
3986        } /*endif*/
3987        locstat = cBcNoError;
3988        db_gets( pmain, ES_STATION, cBcShortStrLth, mstation, &locstat );
3989        if  (*mstation == '\0')  return;
3990
3991        /* set search list */
3992        for  (i=0; i<4; i++)  idx[i] = 0;
3993        i = 0;
3994        if  (tmain > 2)  idx[i++] = tmain - 2;
3995        if  (tmain > 1)  idx[i++] = tmain - 1;
3996        if  (tmain < mgv_di.trcno)  idx[i++] = tmain + 1;
3997        if  (tmain < mgv_di.trcno-1)  idx[i++] = tmain + 2;
3998
3999        /* look all traces in search list */
4000        for  (i=0; i<4; i++)  {
4001                if  (idx[i] == 0)  continue;
4002                pa = mg_trcptr( idx[i] );
4003                if  (pa == NULL)  {
4004                        printf( "*SHM: no trcptr for trace %d found.\n", idx[i] );
4005                        continue;
4006                } /*endif*/
4007                db_gets( pa, ES_STATION, cBcShortStrLth, astation, &locstat );
4008                if  (strcmp(astation,mstation) == 0)  {
4009                        if  (*ta == -1)  {
4010                                *ta = idx[i];
4011                        } else {
4012                                *tb = idx[i];
4013                                return;
4014                        } /*endif*/
4015                } /*endif*/
4016        } /*endfor*/
4017
4018} /* end of mg_find_3_traces */
4019
4020
4021
4022/*----------------------------------------------------------------------------*/
4023
4024
4025
4026void mg_make_alert_trace( Widget w, void *trcptr, TSyStatus *status )
4027
4028/* makes alert trace
4029 *
4030 * parameters of routine
4031 * Widget     w;        input; widget of drawing area
4032 * void       *trcptr;  input; pointer to trace
4033 * TSyStatus  *status;  output; return status
4034 */
4035{
4036        /* local variables */
4037        MGT_TRCXENV *xenv;                     /* pointer to trace environment */
4038
4039        /* executable code */
4040
4041        xenv = (MGT_TRCXENV *)db_getp( trcptr, EP_USR1, NULL );
4042        if  (xenv == NULL)  xenv = mg_create_trcxenv( w, status );
4043        if  (xenv != NULL)  {
4044                db_setp( trcptr, EP_USR1, xenv, status );
4045                xenv->gc = mgv_trcalert_gc;
4046        } /*endif*/
4047
4048} /* end of mg_make_alert_trace */
4049
4050
4051
4052/*----------------------------------------------------------------------------*/
4053
4054
4055
4056void mg_get_last_drag_box( TSyBoolean *valid,
4057        int *x1, int *y1, int *x2, int *y2 )
4058
4059/* returns position and size of last dragbox
4060 *
4061 * parameters of routine
4062 * TSyBoolean    *valid;    output; drag box visible? if FALSE x,y's are void
4063 * int           *x1, *y1;  output; lower left corner
4064 * int           *x2, *y2;  output; upper right corner
4065 */
4066{
4067        /* executable code */
4068
4069        *valid = mgv_drag.on;
4070        *x1 = mgv_drag.x1;
4071        *y1 = mgv_drag.y1;
4072        *x2 = mgv_drag.x2;
4073        *y2 = mgv_drag.y2;
4074
4075} /* end of mg_get_last_drag_box */
4076
4077
4078
4079/*----------------------------------------------------------------------------*/
4080
4081
4082
4083static void mgh_label_rounding( float accuracy, TIME *atime )
4084
4085/* makes 'nice' numbers on time axis
4086 *
4087 * parameters of routine
4088 * float      accuracy; input; maximum time to modify atime to get nice number
4089 * TIME       *atime;   modify; time to be rounded
4090 */
4091{
4092        /* local variables */
4093        TSyStatus locstat;             /* local status */
4094        NTIME    ntime;                /* numeric time */
4095        int      iacc;                 /* accuracy in ms */
4096        char     stime[cBcTimeLth+1];  /* time string */
4097        int      msecs;                /* milliseconds of time to be rounded */
4098        float    corrtime;             /* time correction to get nice number */
4099
4100        /* executable code */
4101
4102        locstat = cBcNoError;
4103
4104        if  (GpGetInt(cGpI_debug_level) > 8)  {
4105                tc_a2t( atime, stime, &locstat );
4106                printf( "SHM-dbg9: round %s acc %f -> ", stime, accuracy );
4107        } /*endif*/
4108
4109        tc_a2n( atime, &ntime, &locstat );
4110        if  (SySevere(&locstat))  return;
4111        iacc = Nint( accuracy*1000.0 );
4112        msecs = ntime.ms;
4113        if  (msecs > 500)  msecs = ntime.ms - 1000;
4114
4115        if  (Abs(msecs) < iacc)  {
4116                corrtime = (float)msecs/1000.0;
4117        } else if  (iacc >= 100)  {
4118                corrtime = (float)(msecs % 100)/1000.0;
4119        } else if  (iacc >= 10)  {
4120                corrtime = (float)(msecs % 10)/1000.0;
4121        } else {
4122                corrtime = 0.0;
4123        } /*endif*/
4124
4125        tc_aadd( atime, -corrtime, atime );
4126
4127        if  (GpGetInt(cGpI_debug_level) > 8)  {
4128                tc_a2t( atime, stime, &locstat );
4129                printf( "%s\n", stime );
4130        } /*endif*/
4131
4132} /* end of mgh_label_rounding */
4133
4134
4135
4136/*----------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.