File: deltaT.c

package info (click to toggle)
irsim 9.7.104-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,964 kB
  • sloc: ansic: 24,763; sh: 7,499; makefile: 418; csh: 269; tcl: 88
file content (253 lines) | stat: -rw-r--r-- 5,304 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 *     ********************************************************************* 
 *     * Copyright (C) 1988, 1990 Stanford University.                     * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  Stanford University                 * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 */

#include "ana.h"
#include "ana_glob.h"
#include "graphics.h"


private TimeType FindPreviousEdge( t, tm, edgeH )
  Trptr              t;
  register TimeType  tm;
  hptr               *edgeH;
  {
    register hptr      h;
    register int       val;
    register TimeType  edgeT;

    edgeT = tims.start;
    *edgeH = NULL;
    if( IsVector( t ) )
      {
	register int  i;

	for( i = t->n.vec->nbits - 1; i >= 0; i-- )
	  {
	    h = t->cache[i].wind;
	    val = h->val;
	    while( h->time <= tm )
	      {
		if( val != h->val )
		  {
		    val = h->val;
		    if( h->time > edgeT )
			edgeT = h->time;
		  }
		NEXTH( h, h );
	      }
	  }
      }
    else
      {
	h = t->cache[0].wind;
	val = h->val;
	while( h->time <= tm )
	  {
	    if( val != h->val )
	      {
		val = h->val;
		edgeT = h->time;
		*edgeH = h;
	      }
	    NEXTH( h, h );
	  }
      }
    return( edgeT );
  }


private TimeType FindNextEdge( t, tm, edgeH )
  Trptr              t;
  register TimeType  tm;
  hptr               *edgeH;
  {
    register hptr      h, p;
    register int       val;
    register TimeType  edgeT, endT;

    endT = edgeT = min( tims.end, tims.last );
    *edgeH = NULL;
    if( IsVector( t ) )
      {
	register int  i;

	for( i = t->n.vec->nbits - 1; i >= 0; i-- )
	  {
	    p = h = t->cache[i].wind;
	    while( h->time <= tm )
	      {
		p = h;
		NEXTH( h, h );
	      }
	    val = p->val;
	    while( h->time <= endT )
	      {
		if( val != h->val )
		  {
		    if( h->time < edgeT )
			edgeT = h->time;
		    break;
		  }
		NEXTH( h, h );
	      }
	  }
      }
    else
      {
	p = h = t->cache[0].wind;
	while( h->time <= tm )
	  {
	    p = h;
	    NEXTH( h, h );
	  }
	val = p->val;
	while( h->time <= endT )
	  {
	    if( val != h->val )
	      {
		edgeT = h->time;
		*edgeH = h;
		break;
	      }
	    NEXTH( h, h );
	  }
      }
    return( edgeT );
  }


private void WaitForRelease()
  {
    XEvent  e;
    
    GrabMouse( window, ButtonPressMask | ButtonReleaseMask, None );

    do
	XNextEvent( display, &e );
    while( e.type != ButtonRelease );

    XUngrabPointer( display, CurrentTime );
  }


private	Trptr       t1;
private Coord       x1;
private TimeType    time1;
private void        SetEdge2();


private void Terminate( cancel )
  int  cancel;
  {
    if( cancel )
	PRINT( "(canceled: click on a trace)" );
    SendEventTo( NULL );
    XDefineCursor( display, window, cursors.deflt );
    RestoreScroll();
  }


private void SetEdge1( ev )
  XButtonEvent  *ev;
  {
    TimeType  tm;
    hptr      h;

    if( ev == NULL )
      {
	Terminate( FALSE );
	return;
      }

    if( ev->type != ButtonPress )
	return;
    
    t1 = GetYTrace( ev->y );
    tm = XToTime( ev->x );
    if( t1 == NULL or tm < 0 )
      {
	Terminate( TRUE );
	return;
      }
    time1 = FindPreviousEdge( t1, tm, &h );
    x1 = TimeToX( time1 );
    PRINTF( "%.2f", d2ns( time1 ) );
    if( h != NULL )
	PRINTF( " [%.2f, %.2f]", d2ns( h->t.r.delay ), d2ns( h->t.r.rtime ) );

    FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.hilite );
    WaitForRelease();
    FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.unhilite);

    PRINT( " | t2 = " );
    XDefineCursor( display, window, cursors.right );
    SendEventTo( SetEdge2 );
  }


private void SetEdge2( ev )
  XKeyEvent  *ev;
  {
    TimeType  time2, diff;
    Trptr     t2;
    Coord     x2, y1, y2;
    hptr      h;

    if( ev == NULL )
      {
	Terminate( FALSE );
	return;
      }

    if( ev->type != ButtonPress )
	return;

    t2 = GetYTrace( ev->y );
    time2 = XToTime( ev->x );
    if( t2 == NULL or time2 < 0 )
      {
	Terminate( TRUE );
	return;
      }
    time2 = FindNextEdge( t2, time2, &h );
    x2 = TimeToX( time2 );

    if( time2 < time1 )
	diff = time1 - time2;
    else
	diff = time2 - time1;

    PRINTF( "%.2f", d2ns( time2 ) );
    if( h != NULL )
	PRINTF( " [%.2f, %.2f]", d2ns( h->t.r.delay ), d2ns( h->t.r.rtime ) );
    PRINTF( " | diff = %.2f", d2ns( diff ) );

    y1 = (t1->top + t1->bot) / 2;
    y2 = (t2->top + t2->bot) / 2;
    XDrawLine( display, window, gcs.hilite, x1, y1, x2, y2 );
    WaitForRelease();
    XDrawLine( display, window, gcs.unhilite, x1, y1, x2, y2 );

    Terminate( FALSE );
  }


public void DeltaT( s )
  char *s;			/* menu string => ignore it */
  {
    PRINT( "\nt1 = " );
    SendEventTo( SetEdge1 );
    XDefineCursor( display, window, cursors.left );
    DisableScroll();
  }