コード例 #1
0
ファイル: path.c プロジェクト: toksik/edraw
int edraw_line_to(edraw_surface *sr, int x, int y)
{
  edraw_called("edraw_line_to");
  edraw_operation *op;
  if (~sr->flags & EDRAW_READY)
  {
    edraw_fatal("edraw_line_to", "Surface not ready");
    return(-EDRAW_SURFACE);
  }
  if ((op = edraw_addop(sr)) == NULL)
  {
    sr->state->path_x = x;
    sr->state->path_y = y;
    return(EDRAW_MEMORY);
  }
  op->type = EDRAW_LINE;
  op->flags = 0;
  if (DELTA(x, sr->state->path_x) >= DELTA(y, sr->state->path_y))
  {
    if (x < sr->state->path_x)
    {
      op->x = x;
      op->y = y;
      op->x2 = sr->state->path_x;
      op->y2 = sr->state->path_y;
    }
    else
    {
      op->x = sr->state->path_x;
      op->y = sr->state->path_y;
      op->x2 = x;
      op->y2 = y;
    }
    op->gradient = ((op->y2 - op->y) * 1000) / DELTA(op->x, op->x2);
    op->start = (((op->gradient * op->x) / 1000) * -1) + op->y;
  }
  else
  {
    if (y < sr->state->path_y)
    {
      op->x = x;
      op->y = y;
      op->x2 = sr->state->path_x;
      op->y2 = sr->state->path_y;
    }
    else
    {
      op->x = sr->state->path_x;
      op->y = sr->state->path_y;
      op->x2 = x;
      op->y2 = y;
    }
    op->gradient = ((op->x2 - op->x) * 1000) / DELTA(op->y, op->y2);
    op->start = (((op->gradient * op->y) / 1000) * -1) + op->x;
    op->flags |= EDRAW_YGRADIENT;
  }
  sr->state->path_x = x;
  sr->state->path_y = y;
  return(EDRAW_SUCCESS);
}
コード例 #2
0
// equations 28 and 30;
double IonSpectrumInwards(double r, double E)
{
    double flux, dr;
    double term1 = 0, term2 = 0;
    double (*PhiPtr)(double);
    PhiPtr = &Potential_Phi;

    dr = Potential_Phi_Inv( E/q + Potential_Phi(r) );

    if ( dr < r )
        dr = roundf(dr * 10000) / 10000 + 1e-5;

    term1  = 1/q;
    term1 *= pow(dr/r,2);
    term1 *= interpolation(Table->S, dr) / abs(differentiat(*PhiPtr, dr));
    term1 /= 1 - pow(fusor->Tc * g(0,dr),2);

    if ( fusor->a < r )
    {
        // inwards flux outside the cathode
        if ( dr < r || fusor->b < dr )
        {
            printf("IonSpectrumInwards error: dr < r or b < dr:\n \tr = %E\n \tdr = %E\n \tE = %E\n", r, dr, E);

            return NAN;
        }

        term1  *= g(r,dr);

        if ( DELTA(E - ParticleEnergy1(r)) )
            term2  = pow(fusor->b/r,2) * EdgeIonFlux * f(r);

        flux = term1 + term2;
    }
    else
    {
        if ( dr < fusor->a || fusor->b < dr )
        {
            printf("IonSpectrumInwards error: dr < a or b < dr:\n \tr = %E\n \tdr = %E\n \tE = %E\n", r, dr, E);

            return NAN;
        }

        // inwards flux inside the cathode
        term1 *= g(fusor->a,dr) * exp(fusor->ngas* CrosssecCX(ParticleEnergy2(fusor->a,dr)) * (r - fusor->a));

        if ( DELTA(E - ParticleEnergy1(r)) )
        {
            term2  = pow(fusor->b/r,2) * EdgeIonFlux ;
            term2 *= f(fusor->a) * exp(fusor->ngas* CrosssecCX(ParticleEnergy1(fusor->a)) * (r - fusor->a));
        }

        flux = fusor->Tc * (term1 + term2);
    }

    return flux;
}
コード例 #3
0
ファイル: rcapd_main.c プロジェクト: AlainODea/illumos-gate
/*ARGSUSED*/
static int
simple_report_collection_cb(lcollection_t *lcol, void *arg)
{
#define	DELTA(field) \
	(unsigned long long)( \
	    (lcol->lcol_stat.field - lcol->lcol_stat_old.field))

	debug("%s %s status: succeeded/attempted (k): %llu/%llu, "
	    "ineffective/scans/unenforced/samplings:  %llu/%llu/%llu/%llu, RSS "
	    "min/max (k): %llu/%llu, cap %llu kB, processes/thpt: %llu/%llu, "
	    "%llu scans over %llu ms\n",
	    (lcol->lcol_id.rcid_type == RCIDT_PROJECT ? "project" : "zone"),
	    lcol->lcol_name,
	    DELTA(lcols_pg_eff), DELTA(lcols_pg_att),
	    DELTA(lcols_scan_ineffective), DELTA(lcols_scan),
	    DELTA(lcols_unenforced_cap), DELTA(lcols_rss_sample),
	    (unsigned long long)lcol->lcol_stat.lcols_min_rss,
	    (unsigned long long)lcol->lcol_stat.lcols_max_rss,
	    (unsigned long long)lcol->lcol_rss_cap,
	    (unsigned long long)(lcol->lcol_stat.lcols_proc_in -
	    lcol->lcol_stat.lcols_proc_out), DELTA(lcols_proc_out),
	    DELTA(lcols_scan_count),
	    NSEC2MSEC(DELTA(lcols_scan_time_complete)));

#undef DELTA

	return (0);
}
コード例 #4
0
ファイル: fsstat.c プロジェクト: drscream/illumos-joyent
static void
io_display(char *name, vopstats_t *oldvsp, vopstats_t *newvsp, int dispflag)
{
	int		niceflag = ((dispflag & DISP_RAW) == 0);
	char		buf[LBUFSZ];

	if (dispflag & DISP_HEADER) {
		(void) printf(
" read read  write write rddir rddir rwlock rwulock\n"
"  ops bytes   ops bytes   ops bytes    ops     ops\n");
	}

	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nread), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(read_bytes), buf);

	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nwrite), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(write_bytes), buf);

	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nreaddir), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(readdir_bytes), buf);

	PRINTSTAT(niceflag, " %5s   ", "%lld:", DELTA(nrwlock), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nrwunlock), buf);

	(void) printf("%s\n", name);
}
コード例 #5
0
ファイル: d4swap.c プロジェクト: dschwen/libmesh
/*
Assumes that compiler->swap is true; does necessary
byte swapping.
*/
int
NCD4_swapdata(NCD4meta* compiler, NClist* topvars)
{
    int ret = NC_NOERR;
    int i;
    void* offset;

    offset = compiler->serial.dap;
    for(i=0;i<nclistlength(topvars);i++) {
	NCD4node* var = (NCD4node*)nclistget(topvars,i);
	var->data.dap4data.memory = offset;
	switch (var->subsort) {
	default:
	    if((ret=walkAtomicVar(compiler,var,var,&offset))) goto done;
	    break;
	case NC_OPAQUE:
	    /* The only thing we need to do is swap the counts */
	    if((ret=walkOpaqueVar(compiler,var,var,&offset))) goto done;
	    break;
	case NC_STRUCT:
	    if((ret=walkStructArray(compiler,var,var,&offset))) goto done;
	    break;
	case NC_SEQ:
	    if((ret=walkSeqArray(compiler,var,var,&offset))) goto done;
	    break;
	}
	var->data.dap4data.size = DELTA(offset,var->data.dap4data.memory);
	/* skip checksum, if there is one */
        if(compiler->serial.remotechecksumming)
	    offset = INCR(offset,CHECKSUMSIZE);
    }
done:
    return THROW(ret);
}
コード例 #6
0
ファイル: fsstat.c プロジェクト: drscream/illumos-joyent
static void
attr_display(char *name, vopstats_t *oldvsp, vopstats_t *newvsp, int dispflag)
{
	int		niceflag = ((dispflag & DISP_RAW) == 0);
	char		buf[LBUFSZ];

	if (dispflag & DISP_HEADER) {
		(void) printf("getattr setattr getsec  setsec\n");
	}

	PRINTSTAT(niceflag, " %5s ", "%lld:", DELTA(ngetattr), buf);
	PRINTSTAT(niceflag, "  %5s ", "%lld:", DELTA(nsetattr), buf);
	PRINTSTAT(niceflag, "  %5s ", "%lld:", DELTA(ngetsecattr), buf);
	PRINTSTAT(niceflag, "  %5s ", "%lld:", DELTA(nsetsecattr), buf);

	(void) printf("%s\n", name);
}
コード例 #7
0
ファイル: gameport.c プロジェクト: froggatt/edimax-br-6528n
static int gameport_measure_speed(struct gameport *gameport)
{
#if defined(__i386__) || defined(__x86_64__)

#define GET_TIME(x)     do { outb(0, 0x43); x = inb(0x40); x |= inb(0x40) << 8; } while (0)
#define DELTA(x,y)      ((y)-(x)+((y)<(x)?1193180L/HZ:0))

	unsigned int i, t, t1, t2, t3, tx;
	unsigned long flags;

	if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW))
		return 0;

	tx = 1 << 30;

	for(i = 0; i < 50; i++) {
		save_flags(flags);	/* Yes, all CPUs */
		cli();
		GET_TIME(t1);
		for(t = 0; t < 50; t++) gameport_read(gameport);
		GET_TIME(t2);
		GET_TIME(t3);
		restore_flags(flags);
		udelay(i * 10);
		if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t;
	}

	return 59659 / (tx < 1 ? 1 : tx);

#else

	unsigned int j, t = 0;

	j = jiffies; while (j == jiffies);
	j = jiffies; while (j == jiffies) { t++; gameport_read(gameport); }

	return t * HZ / 1000;

#endif

	gameport_close(gameport);
}
コード例 #8
0
ファイル: fsstat.c プロジェクト: drscream/illumos-joyent
static void
naming_display(char *name, vopstats_t *oldvsp, vopstats_t *newvsp, int dispflag)
{
	int		niceflag = ((dispflag & DISP_RAW) == 0);
	char		buf[LBUFSZ];

	if (dispflag & DISP_HEADER) {
		(void) printf(
	"lookup creat remov  link renam mkdir rmdir rddir symlnk rdlnk\n");
	}

	PRINTSTAT(niceflag, "%5s  ", "%lld:", DELTA(nlookup), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(ncreate), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nremove), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nlink), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nrename), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nmkdir), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nrmdir), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nreaddir), buf);
	PRINTSTAT(niceflag, " %5s ", "%lld:", DELTA(nsymlink), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nreadlink), buf);
	(void) printf("%s\n", name);
}
コード例 #9
0
static void monitor(longoutRecord *prec)
{
    unsigned short monitor_mask = recGblResetAlarms(prec);

    if (prec->mdel < 0 ||
        DELTA(prec->mlst, prec->val) > (epicsUInt32) prec->mdel) {
        /* post events for value change */
        monitor_mask |= DBE_VALUE;
        /* update last value monitored */
        prec->mlst = prec->val;
    }

    if (prec->adel < 0 ||
        DELTA(prec->alst, prec->val) > (epicsUInt32) prec->adel) {
        /* post events for archive value change */
        monitor_mask |= DBE_LOG;
        /* update last archive value monitored */
        prec->alst = prec->val;
    }

    /* send out monitors connected to the value field */
    if (monitor_mask)
        db_post_events(prec, &prec->val, monitor_mask);
}
コード例 #10
0
ファイル: t40f.c プロジェクト: AgamAgarwal/minix
float compute_diff(struct timeval start, struct timeval end, float compare) {
  /* Compute time difference. It is assumed that the value of start <= end. */
  clock_t delta;
  int seconds, hundreths;
  float diff;

  delta = DELTA(end, start); /* delta is in ticks */
  seconds = (int) (delta / CLOCKS_PER_SEC);
  hundreths = (int) (delta * 100 / CLOCKS_PER_SEC) - (seconds * 100);

  diff = seconds + (hundreths / 100.0);
  diff -= compare;
  if(diff < 0) diff *= -1; /* Make diff a positive value */

  return diff;
}
コード例 #11
0
ファイル: rcapstat.c プロジェクト: AlainODea/illumos-gate
/*ARGSUSED*/
static void
print_unformatted_stats(void)
{
	col_t *col;

#define	DELTA(field) \
	(col->col_src_stat.field - col->col_old_stat.field)

	col = col_head;
	while (col != NULL) {
		if (bcmp(&col->col_src_stat, &col->col_old_stat,
		    sizeof (col->col_src_stat)) == 0) {
			col = col->col_next;
			continue;
		}
		(void) printf("%s %s status: succeeded/attempted (k): "
		    "%llu/%llu, ineffective/scans/unenforced/samplings:  "
		    "%llu/%llu/%llu/%llu, RSS min/max (k): %llu/%llu, cap %llu "
		    "kB, processes/thpt: %llu/%llu, %llu scans over %lld ms\n",
		    mode, col->col_name, DELTA(lcols_pg_eff),
		    DELTA(lcols_pg_att), DELTA(lcols_scan_ineffective),
		    DELTA(lcols_scan), DELTA(lcols_unenforced_cap),
		    DELTA(lcols_rss_sample), col->col_src_stat.lcols_min_rss,
		    col->col_src_stat.lcols_max_rss, col->col_rsslimit,
		    (col->col_src_stat.lcols_proc_in -
		    col->col_old_stat.lcols_proc_out), DELTA(lcols_proc_out),
		    DELTA(lcols_scan_count),
		    NSEC2MSEC(DELTA(lcols_scan_time_complete)));
		col->col_old_stat = col->col_src_stat;

		col = col->col_next;
	}

	if (global)
		(void) printf(gettext("physical memory utilization: %3u%%   "
		    "cap enforcement threshold: %3u%%\n"), hdr.rs_pressure_cur,
		    hdr.rs_pressure_cap);
#undef DELTA
}
コード例 #12
0
ファイル: hash.c プロジェクト: BioinformaticsArchive/pbwt
static void hashDouble (TRUE_HASH *h)
{
  int oldsize, newsize ;
  long int hash, delta = 0 ;
  int *oldKeys, *kp ;
  int *oldValues, i ;
  HASHKEY hk ;

  oldsize = 1 << h->nbits ;
  ++h->nbits ;
  newsize = 1 << h->nbits ;
  h->mask = (1 << h->nbits) - 1 ;
  h->guard = (1 << (h->nbits - 1)) ;

  oldKeys = h->keys ;
  h->keys  = mycalloc (newsize,int) ;
  oldValues = h->values ;
  h->values = myalloc (newsize,int) ;

  for (i = 0, kp = oldKeys ; i < oldsize ; i++)
    if (*kp && *kp != REMOVED)
      { hk.i = *kp ; HASH_FUNC(hk) ;
        while (TRUE)
          if (!h->keys[hash])  /* don't need to test REMOVED */
	    { h->keys[hash] = *kp ;
	      h->values[hash] = oldValues[i] ;
	      --h->guard ;	/* NB don't need to change h->n */
	      ++nAdded ;
	      break ;
	    }
	  else
            { nBounced++ ;
	      if (!delta) DELTA(hk) ;
	      hash = (hash + delta) & h->mask ;
	    }
      }

  free (oldKeys) ;
  free (oldValues) ;
}
コード例 #13
0
ファイル: hash.c プロジェクト: BioinformaticsArchive/pbwt
int hashFind (HASH hx, HASHKEY k)
/* if found, returns index, else returns 0 */
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  long int hash, delta = 0 ;

  HASH_FUNC(k) ;
  while (TRUE)
    if (h->keys[hash] == k.i)
      { nFound++ ;
	return h->values[hash] ;
      }
    else if (!h->keys[hash])
      { nNotFound++ ;
	return 0 ;
      }
    else 
      { nBounced++ ;
	if (!delta) DELTA(k) ;
	hash = (hash + delta) & h->mask ;
      }
}
コード例 #14
0
ファイル: fsstat.c プロジェクト: drscream/illumos-joyent
static void
vm_display(char *name, vopstats_t *oldvsp, vopstats_t *newvsp, int dispflag)
{
	int		niceflag = ((dispflag & DISP_RAW) == 0);
	char		buf[LBUFSZ];

	if (dispflag & DISP_HEADER) {
		(void) printf("  map addmap delmap getpag putpag pagio\n");
	}

	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(nmap), buf);
	PRINTSTAT(niceflag, " %5s ", "%lld:", DELTA(naddmap), buf);
	PRINTSTAT(niceflag, " %5s ", "%lld:", DELTA(ndelmap), buf);
	PRINTSTAT(niceflag, " %5s ", "%lld:", DELTA(ngetpage), buf);
	PRINTSTAT(niceflag, " %5s ", "%lld:", DELTA(nputpage), buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", DELTA(npageio), buf);
	(void) printf("%s\n", name);
}
コード例 #15
0
ファイル: xContour.c プロジェクト: gwowen/seismicunix
static int connect (Display *dpy, Window win,GC gcc,
		    float c, int nx, float *x, int ny, float *y, float *z, 
		    int *pcell, float *pxd, float *pyd,float *x0, float *y0)
/*
connect draws a line from one intersection of the cell(ix,iy) =  z[*pcell]
to another intersection of the cell, provided the latter intersection exists,
and then clears the latter intersection and updates the cell pointer
connect returns 0 if the latter intersection does not exist or if the 
latter intersection is a grid boundary; otherwise returns 1.
*/
{
	int cell= *pcell, ix=cell%nx, iy=cell/nx;
	float d;

	/* if exiting north */
	if (SSET(z[cell+nx])) {
		cell += nx;  iy++;
		d = DELTA(c,z[cell],z[cell+1]);
		*pxd = (1.0-d)*x[ix]+d*x[ix+1];
		*pyd = y[iy];
		XDrawLine(dpy,win,gcc,NINT(*x0),NINT(*y0),
				NINT(*pxd),NINT(*pyd));
		CLRS(z[cell]);
		*pcell = cell;
		if (iy<ny-1)
			return(1);
		else
			return(0);

	/* else if exiting east */
	} else if (WSET(z[cell+1])) {
		cell += 1;  ix++;
		d = DELTA(c,z[cell],z[cell+nx]);
		*pxd = x[ix];
		*pyd = (1.0-d)*y[iy]+d*y[iy+1];
		XDrawLine(dpy,win,gcc,NINT(*x0),NINT(*y0),
				NINT(*pxd),NINT(*pyd));
		CLRW(z[cell]);
		*pcell = cell;
		if (ix<nx-1)
			return(1);
		else
			return(0);

	/* else if exiting south */
	} else if (SSET(z[cell])) {
		d = DELTA(c,z[cell],z[cell+1]);
		*pxd = (1.0-d)*x[ix]+d*x[ix+1];
		*pyd = y[iy];
		XDrawLine(dpy,win,gcc,NINT(*x0),NINT(*y0),
				NINT(*pxd),NINT(*pyd));
		CLRS(z[cell]);
		*pcell = cell-nx;
		if (iy>0)
			return(1);
		else
			return(0);

	/* else if exiting west */
	} else if (WSET(z[cell])) {
		d = DELTA(c,z[cell],z[cell+nx]);
		*pxd = x[ix];
		*pyd = (1.0-d)*y[iy]+d*y[iy+1];
		XDrawLine(dpy,win,gcc,NINT(*x0),NINT(*y0),
				NINT(*pxd),NINT(*pyd));
		CLRW(z[cell]);
		*pcell = cell-1;
		if (ix>0)
			return(1);
		else
			return(0);

	/* else if no intersection exists */
	} else {
		return(0);
	}
}
コード例 #16
0
ファイル: xContour.c プロジェクト: gwowen/seismicunix
/* function */
void xContour(Display *dpy, Window win,GC gcc, GC gcl, 
	       float *cp,int nx, float x[], int ny, float y[], float z[], 
	       char lcflag,char *lcf,char *lcc, float *w, int nplaces)
/**************************************************************************
xContour - draw contour of a two-dimensional array via X
***************************************************************************
Input:
dpy                     the display to make the contour
win                     the window to draw in
gcc                     GC for the contour lines
gcl                     GC for the contour labels
cp			pointer to the contour value
nx			number of x-coordinates
x			array of x-coordinates (see notes below)
ny			number of y-coordinates
y			array of y-coordinates (see notes below)
lcflag                  flag that defines if we actually are going to have labels 
Least Significat Bits:
z			array of nx*ny z(x,y) values (see notes below)
w			array of nx*ny z(x,y) values (see notes below)
***************************************************************************
Notes:
The two-dimensional array z is actually passed as a one-dimensional
array containing nx*ny values, stored with nx fast and ny slow.

The x and y arrays define a grid that is not necessarily 
uniformly-sampled.  Linear interpolation of z values on the 
grid defined by the x and y arrays is used to determine z values 
between the gridpoints.
		 
The two least significant bits of z are used to mark intersections
of the contour with the x,y grid; therefore, the z values will
almost always be altered (slightly) by contour.

xContour is a modified version of psContour where the use of conmove
and condraw call have been changed to match X-Windows.

Since XDrawLine requires a start and end point, the use of a manually update
of the position variables x0 and y0 is used instead of conmove.

if lcflag is zero no labels are drawn

The w array is used to restrict the range of contour labeling that 
occurs only if w<1. 

As suggested in the reference, the following scheme is used to refer
to a cell of the two-dimensional array z:

                north (0)
      (ix,iy+1)	--------- (ix+1,iy+1)
                | cell  |
       west (3)	| ix,iy	| east (1)
                |       |
        (ix,iy) --------- (ix+1,iy)
                south (2)

***************************************************************************
Reference:
Cottafava, G. and Le Moli, G., 1969, Automatic contour map:
Commuincations of the ACM, v. 12, n. 7, July, 1969.

***************************************************************************
Author:  Morten Wendell Pedersen Aarhus University 07/20/96
Heavily based on psContour by
  Dave Hale, Colorado School of Mines, 06/28/89
  and with contour labeling added by: Zhenyue Liu, June 1993
(actually most of the credit should go to these two guys)
***************************************************************************/
{
	int ix,iy,non,cell,startcell;
	float d;
	float xmin = MIN(x[0],x[nx-1]), xmax = MAX(x[0],x[nx-1]);
	float ymin = MIN(y[0],y[ny-1]), ymax = MAX(y[0],y[ny-1]);
	float xc=0.0, yc=0.0;	/* contour labeling centered at (xc,yc)	*/
 	float xw, yw;	/* width and length of contour labeling */
	float xd, yd;	/* point on contour			*/
	float x0, y0;    /* start plot values (instead of move operation )*/   
	float xdmin, xdmax, ydmin, ydmax; /* range of contour	*/
	int id;	/* =0 if a point on contour has been used as (xc,yc) */
	int cells=0;
	char str[20];
	XCharStruct overall;
	int dummy;
	float c=*cp; /* stupid thing I had to do since I couldn't transfer
			a float without messing up everything 
			but I could transfer a pointer....strange thing
			I will have to track this thing down one day*/

	/* convert a number into a string */
	sprintf(str,"%.*g",nplaces,c);

	/* determine length and width for printing the string */
	XQueryTextExtents(dpy,XGContextFromGC(gcl),str,(int) strlen(str),&dummy,&dummy,&dummy,&overall);
	xw=overall.width;
        yw=overall.ascent+overall.descent;

	/* restrict contour labeling from edges */
	for (iy=0; iy<ny-1; iy++)  
		for (ix=0,cell=iy*nx; ix<nx-1; ix++,cell++) {
			if(x[ix]<xmin+2.0*xw || x[ix]>xmax-2.0*xw 
 				|| y[iy]<ymin+yw || y[iy]>ymax-yw)
  				w[cell] += 1.;
 		}
 
	/* count intersections with cell boundaries */
	non = 0;

	/* find all the intersections */
	for (iy=0; iy<ny; iy++) {
		for (ix=0,cell=iy*nx; ix<nx; ix++,cell++) {

			/* check for intersection with west edge of cell */
			if (iy<ny-1 && BTWN(c,z[cell],z[cell+nx])) {
				SETW(z[cell]);  non++;
			} else {
				CLRW(z[cell]);
			}

			/* check for intersection with south edge of cell */
			if (ix<nx-1 && BTWN(c,z[cell],z[cell+1])) {
				SETS(z[cell]);  non++;
			} else {
				CLRS(z[cell]);
			}
		}
	}


	/* follow contours intersecting north boundary */
	for (ix=0,startcell=(ny-1)*nx; non>0&&ix<nx-1; ix++,startcell++) {
		if (SSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+1]);
			x0=(1.0-d)*x[ix]+d*x[ix+1];
			y0=y[ny-1];
			CLRS(z[startcell]);  non--;
			cell = startcell-nx;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){
			  x0=xd;y0=yd;
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc);
			}
		}
	}

	/* follow contours intersecting east boundary */
	for (iy=0,startcell=nx-1; non>0&&iy<ny-1; iy++,startcell+=nx) {
		if (WSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+nx]);
			x0=x[nx-1];
			y0=(1.0-d)*y[iy]+d*y[iy+1];
			CLRW(z[startcell]);  non--;
			cell = startcell-1;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){
			  x0=xd;y0=yd;
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc);
			}
		}
	}

	/* follow contours intersecting south boundary */
	for (ix=0,startcell=0; non>0&&ix<nx-1; ix++,startcell++) {
		if (SSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+1]);
			x0=(1.0-d)*x[ix]+d*x[ix+1];
			y0=y[0];
			CLRS(z[startcell]);  non--;
			cell = startcell;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){
			  x0=xd;y0=yd;
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc);
			}
		}		 
	}

	/* follow contours intersecting west boundary */
	for (iy=0,startcell=0; non>0&&iy<ny-1; iy++,startcell+=nx) {
		if (WSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+nx]);
			x0=x[0];
			y0=(1.0-d)*y[iy]+d*y[iy+1];
			CLRW(z[startcell]);  non--;
			cell = startcell;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){
			  x0=xd;y0=yd;
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc);
			}
		}
	}

	/* follow interior contours */
	for (iy=1; iy<ny-1; iy++) {
		for (ix=0,startcell=iy*nx; non>0&&ix<nx-1; ix++,startcell++) {

			/* check south edge of cell */
			if (SSET(z[startcell])) {
				d = DELTA(c,z[startcell],z[startcell+1]);
				x0=(1.0-d)*x[ix]+d*x[ix+1];
				y0=y[iy];

				/* clear south edge where we started */
				CLRS(z[startcell]);  non--;

				cell = startcell;

				/* if another intersection exists in this cell */
				if (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)) {
				  x0=xd;y0=yd;
			  
				  /* set south edge so that we finish where we started */
					SETS(z[startcell]);  non++;
			
					/* follow the contour */
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){
			  x0=xd;y0=yd;
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc);
			}	
				} 		 
			}
		}
	}
	/* contour drawing is done */
}
コード例 #17
0
ファイル: psContour.c プロジェクト: gwowen/seismicunix
/* function */
void psContour (float c, int nx, float x[], int ny, float y[], float z[], 
		float lcs, char *lcf, char *lcc, float *w, int nplaces)
/**************************************************************************
psContour - draw contour of a two-dimensional array via PostScript
***************************************************************************
Input:
c			contour value
nx			number of x-coordinates
x			array of x-coordinates (see notes below)
ny			number of y-coordinates
y			array of y-coordinates (see notes below)
lcs			font size of contour label
lcf			font name of contour label
lcc			color of contour label
Least Significat Bits:
z			array of nx*ny z(x,y) values (see notes below)
w			array of nx*ny z(x,y) values (see notes below)
***************************************************************************
Notes:
The two-dimensional array z is actually passed as a one-dimensional
array containing nx*ny values, stored with nx fast and ny slow.

The x and y arrays define a grid that is not necessarily 
uniformly-sampled.  Linear interpolation of z values on the 
grid defined by the x and y arrays is used to determine z values 
between the gridpoints.
		 
The two least significant bits of z are used to mark intersections
of the contour with the x,y grid; therefore, the z values will
almost always be altered (slightly) by contour.

pscontour isolates the use of PostScript to four internal functions:

void coninit(void) - called before any contour drawing
void conmove(float x, float y) - moves current position to x,y
void condraw(float x, float y) - draws from current position to x,y
void condone(void) - called when contour drawing is done

These functions can usually be replaced with equivalent functions in
other graphics environments.

The w array is used to restrict the range of contour labeling that 
occurs only if w<1. 

As suggested in the reference, the following scheme is used to refer
to a cell of the two-dimensional array z:

                north (0)
      (ix,iy+1)	--------- (ix+1,iy+1)
                | cell  |
       west (3)	| ix,iy	| east (1)
                |       |
        (ix,iy) --------- (ix+1,iy)
                south (2)

***************************************************************************
Reference:
Cottafava, G. and Le Moli, G., 1969, Automatic contour map:
Commuincations of the ACM, v. 12, n. 7, July, 1969.

***************************************************************************
Author:  Dave Hale, Colorado School of Mines, 06/28/89
contour labeling added by: Zhenyue Liu, June 1993
***************************************************************************/
{
	int ix,iy,non,cell,startcell;
	float d;
	float xmin = MIN(x[0],x[nx-1]), xmax = MAX(x[0],x[nx-1]);
	float ymin = MIN(y[0],y[ny-1]), ymax = MAX(y[0],y[ny-1]);
	float xc=0.0, yc=0.0;	/* contour labeling centered at (xc,yc)	*/
 	float xw, yw;	/* width and length of contour labeling */
	float xd, yd;	/* point on contour			*/
	float xdmin, xdmax, ydmin, ydmax; /* range of contour	*/
	int id;	/* =0 if a point on contour has been used as (xc,yc) */
	int cells=0;
	char str[20];

	/* convert a number into a string */
	sprintf(str,"%.*g",nplaces,c);

	/* determine length and width for printing the string */
 	yw = lcs*0.55*((unsigned int) strlen(str));
	xw = lcs*0.8;
	

	/* restrict contour labeling from edges */
	for (iy=0; iy<ny-1; iy++)  
		for (ix=0,cell=iy*nx; ix<nx-1; ix++,cell++) {
			if(x[ix]<xmin+2.0*xw || x[ix]>xmax-2.0*xw 
 				|| y[iy]<ymin+yw || y[iy]>ymax-yw)
  				w[cell] += 1.;
 		}
 
	/* count intersections with cell boundaries */
	non = 0;

	/* find all the intersections */
	for (iy=0; iy<ny; iy++) {
		for (ix=0,cell=iy*nx; ix<nx; ix++,cell++) {

			/* check for intersection with west edge of cell */
			if (iy<ny-1 && BTWN(c,z[cell],z[cell+nx])) {
				SETW(z[cell]);  non++;
			} else {
				CLRW(z[cell]);
			}

			/* check for intersection with south edge of cell */
			if (ix<nx-1 && BTWN(c,z[cell],z[cell+1])) {
				SETS(z[cell]);  non++;
			} else {
				CLRS(z[cell]);
			}
		}
	}

	/* initialize contour drawing */
	coninit();

	/* follow contours intersecting north boundary */
	for (ix=0,startcell=(ny-1)*nx; non>0&&ix<nx-1; ix++,startcell++) {
		if (SSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+1]);
			conmove((1.0-d)*x[ix]+d*x[ix+1],y[ny-1]);
			CLRS(z[startcell]);  non--;
			cell = startcell-nx;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(c,nx,x,ny,y,z,&cell,&xd,&yd)){
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcs>1 && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(xc-xw/2,yc-yw/2,xw,yw,str,lcs,lcf,lcc);
			}
		}
	}

	/* follow contours intersecting east boundary */
	for (iy=0,startcell=nx-1; non>0&&iy<ny-1; iy++,startcell+=nx) {
		if (WSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+nx]);
			conmove(x[nx-1],(1.0-d)*y[iy]+d*y[iy+1]);
			CLRW(z[startcell]);  non--;
			cell = startcell-1;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(c,nx,x,ny,y,z,&cell,&xd,&yd)){
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcs>1 && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(xc-xw/2,yc-yw/2,xw,yw,str,lcs,lcf,lcc);
			}
		}
	}

	/* follow contours intersecting south boundary */
	for (ix=0,startcell=0; non>0&&ix<nx-1; ix++,startcell++) {
		if (SSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+1]);
			conmove((1.0-d)*x[ix]+d*x[ix+1],y[0]);
			CLRS(z[startcell]);  non--;
			cell = startcell;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(c,nx,x,ny,y,z,&cell,&xd,&yd)){
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcs>1 && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(xc-xw/2,yc-yw/2,xw,yw,str,lcs,lcf,lcc);
			}
		}		 
	}

	/* follow contours intersecting west boundary */
	for (iy=0,startcell=0; non>0&&iy<ny-1; iy++,startcell+=nx) {
		if (WSET(z[startcell])) {
			d = DELTA(c,z[startcell],z[startcell+nx]);
			conmove(x[0],(1.0-d)*y[iy]+d*y[iy+1]);
			CLRW(z[startcell]);  non--;
			cell = startcell;
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(c,nx,x,ny,y,z,&cell,&xd,&yd)){
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcs>1 && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(xc-xw/2,yc-yw/2,xw,yw,str,lcs,lcf,lcc);
			}		
		}
	}

	/* follow interior contours */
	for (iy=1; iy<ny-1; iy++) {
		for (ix=0,startcell=iy*nx; non>0&&ix<nx-1; ix++,startcell++) {

			/* check south edge of cell */
			if (SSET(z[startcell])) {
				d = DELTA(c,z[startcell],z[startcell+1]);
				conmove((1.0-d)*x[ix]+d*x[ix+1],y[iy]);

				/* clear south edge where we started */
				CLRS(z[startcell]);  non--;

				cell = startcell;

				/* if another intersection exists in this cell */
				if (connect(c,nx,x,ny,y,z,&cell,&xd,&yd)) {

					/* set south edge so that we finish where we started */
					SETS(z[startcell]);  non++;
			
					/* follow the contour */
			id = 1; 
			xdmin = xmax;
			xdmax = xmin;
			ydmin = ymax;
			ydmax = ymin;
			while (connect(c,nx,x,ny,y,z,&cell,&xd,&yd)){
				 non--;
				if(w[cell]<0.5 && id) {
					xc = xd; yc = yd;
					cells = cell;
					id = 0;
				}
				xdmin = MIN(xdmin,xd);
				xdmax = MAX(xdmax,xd);
				ydmin = MIN(ydmin,yd);
				ydmax = MAX(ydmax,yd);
			}
			if(lcs>1 && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) {
				wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw);
 				labelc(xc-xw/2,yc-yw/2,xw,yw,str,lcs,lcf,lcc);
			}	
				} 		 
			}
		}
	}
	/* contour drawing is done */
	condone();
}
コード例 #18
0
ファイル: gstvdpsink.c プロジェクト: spunktsch/svtplayer
/* This function calculates the pixel aspect ratio */
static GValue *
gst_vdp_sink_calculate_par (Display * display)
{
  static const gint par[][2] = {
    {1, 1},                     /* regular screen */
    {16, 15},                   /* PAL TV */
    {11, 10},                   /* 525 line Rec.601 video */
    {54, 59},                   /* 625 line Rec.601 video */
    {64, 45},                   /* 1280x1024 on 16:9 display */
    {5, 3},                     /* 1280x1024 on 4:3 display */
    {4, 3}                      /*  800x600 on 16:9 display */
  };
  gint screen_num;
  gint width, height;
  gint widthmm, heightmm;
  gint i;
  gint index;
  gdouble ratio;
  gdouble delta;
  GValue *par_value;

#define DELTA(idx) (ABS (ratio - ((gdouble) par[idx][0] / par[idx][1])))

  screen_num = DefaultScreen (display);
  width = DisplayWidth (display, screen_num);
  height = DisplayHeight (display, screen_num);
  widthmm = DisplayWidthMM (display, screen_num);
  heightmm = DisplayHeightMM (display, screen_num);

  /* first calculate the "real" ratio based on the X values;
   * which is the "physical" w/h divided by the w/h in pixels of the display */
  ratio = (gdouble) (widthmm * height)
      / (heightmm * width);

  /* DirectFB's X in 720x576 reports the physical dimensions wrong, so
   * override here */
  if (width == 720 && height == 576) {
    ratio = 4.0 * 576 / (3.0 * 720);
  }
  GST_DEBUG ("calculated pixel aspect ratio: %f", ratio);

  /* now find the one from par[][2] with the lowest delta to the real one */
  delta = DELTA (0);
  index = 0;

  for (i = 1; i < sizeof (par) / (sizeof (gint) * 2); ++i) {
    gdouble this_delta = DELTA (i);

    if (this_delta < delta) {
      index = i;
      delta = this_delta;
    }
  }

  GST_DEBUG ("Decided on index %d (%d/%d)", index,
      par[index][0], par[index][1]);

  par_value = g_new0 (GValue, 1);
  g_value_init (par_value, GST_TYPE_FRACTION);
  gst_value_set_fraction (par_value, par[index][0], par[index][1]);
  GST_DEBUG ("set X11 PAR to %d/%d",
      gst_value_get_fraction_numerator (par_value),
      gst_value_get_fraction_denominator (par_value));

  return par_value;
}
コード例 #19
0
ファイル: SeedFinder.cpp プロジェクト: ewernli/zipcrack
void guess_enc( int level, int timeg, int ticksg)
{
	int		p1[P1SIZE];
	int		p2[P2SIZE];
	int		p3[P3SIZE];
	int*	saved_ptr;

	unsigned int  dt;
	unsigned int  v;
	unsigned char b;
	unsigned int  saved_t;
	int			  i,k;

	unsigned int size = sizes[ level ];
	int lw = PROCESS_TIME(size) - DELTA(size) ;
	unsigned int low_t;
	unsigned int up_t = PROCESS_TIME(size) + DELTA(size) ;

	low_t = lw <= 0 ? 0 : lw;

	low_t = ROUND( low_t );
	up_t =  ROUND( up_t ) + 10;

	delta_history[level] = (up_t-low_t);

//	printf("low %d up %d \n",low_t, up_t);

	for(dt=low_t;dt<=up_t;dt+=10)
	{
		saved_t = t;
		save_buffers(p1,p2,p3);		
		saved_ptr = ptr;
		

		t = t+dt;
		randomize(timeg, ticksg);
		//memcpy( rand_data[level+2], ptr, 4*10 );

		dt_history[level] = dt;
		ticks_history[ level ] = (ticksg == NO_TICKS_GLITCH ? 0 : 1);
		time_history[ level ] = (timeg == NO_TIME_GLITCH ? 0 : 1);

		for(i=0;i<10;i++)
		{
			if( *ptr < 0)
				initialize_P2();
			if(i==0) v=*ptr;
			rand_data[level+2][i]=*ptr;
			ptr++;
		}

		_asm{ 
			sar v,16h
		}
		b = (v&0x000000FF) ^ k3;
		if( b == seeds[level+2] )
		{		
			stat[level+2]++;

			if( level == MAX_LEVEL - 3)
			{
				/* candidate succeded */
				printf("----\n");
				printf("Succes for (time + ticks) = %X and PID = %d\n", init_time + init_ticks, pid);
				
				printf("dt sequence:   ");
				for(i=0;i<(MAX_LEVEL-2);i++)
					printf("%02d ",dt_history[i]);
				printf("\n");
				
				printf("delta:         ");
				for(i=0;i<(MAX_LEVEL-2);i++)
					printf("%02d ",delta_history[i]);
				printf("\n");

				printf("ticks glitches:");
				for(i=0;i<(MAX_LEVEL-2);i++)
					printf("%02d ",ticks_history[i]);
				printf("\n");

				printf("time glitches: ");
				for(i=0;i<(MAX_LEVEL-2);i++)
					printf("%02d ",time_history[i]);
				printf("\n");

				printf("random data for file 1:");
				for(k=0;k<5;k++)
				{
					for(i=0;i<10;i++)
					{
						v = rand_data[k][i];
						_asm{ 
							sar v,16h
						}
						b=v&0x000000FF;
						rand_suc[k][i]=b;
					}
				}
				for(i=0;i<10;i++)
					printf("%02X ",rand_suc[0][i]);
				printf("\n");



				success++;

				return;
			}

			/* propagate or generate glitches */

			if( timeg == NO_TIME_GLITCH )
			{
				if( ticksg == NO_TICKS_GLITCH )
					guess_enc( level+1, NO_TIME_GLITCH, NO_TICKS_GLITCH );
				guess_enc( level+1, NO_TIME_GLITCH, TICKS_GLITCH );
			}
			if( ticksg == NO_TICKS_GLITCH )
				guess_enc( level+1, TIME_GLITCH, NO_TICKS_GLITCH );
			guess_enc( level+1, TIME_GLITCH, TICKS_GLITCH );
			
		
		}	
		
		restore_buffers(p1,p2,p3);
		t = saved_t;
		ptr = saved_ptr;
	}
	return;
}
コード例 #20
0
ファイル: idxcr.c プロジェクト: bojifengyu/TurboPFor
int main(int argc, char *argv[]) { 
  int fno,c, digit_optind = 0, this_option_optind = optind ? optind : 1, option_index = 0; char *path="";
  static struct option long_options[] = { {"r", 	0, 0, 'r'}, {0,0, 0, 0}  };
  for(;;) {
    if((c = getopt_long(argc, argv, "xv:", long_options, &option_index)) == -1) break;
    switch(c) {
      case  0 : printf("Option %s", long_options[option_index].name); 
	            if(optarg) printf (" with arg %s", optarg);  printf ("\n"); break;								
      case 'v': verb = atoi(optarg); 		break;
      default:  die("unknown option: %c \n", optopt);
    }
  }	
  if(argc - optind < 2) usage();
  path = argv[--argc];

  for(fno = optind; fno < argc; fno++) { 
    char outname[257], *inname = argv[fno]; 
    strcpy(outname, path); 
    char *p = strrchr(inname,'/'); 
    if(!p) p = strrchr(inname,'\\'); if(!p) p=inname; 
    strcat(outname, p); strcat(outname,".i");

    FILE *fi = fopen64(inname, "rb");     if(!fi) { fprintf(stderr, "open error '%s'", inname);   perror(inname); exit(-1); }  int fdi = fileno(fi);
    FILE *fo = fopen64(outname,"wb"),*fm; if(!fo) { fprintf(stderr, "creat error '%s'", outname); perror(outname); exit(-1); } fprintf(stderr, "file='%s'", outname);
    fseeko(fo, sizeof(unsigned)+sizeof(unsigned long long), SEEK_SET);

    tmap_t *tmap = calloc(1, TERMNUM*sizeof(tmap_t)); 
    if(!tmap) die("malloc error\n"); 
    unsigned *in = NULL,*ip,*ep,num,tid=0,numx=0,outsize;
    unsigned char *out = NULL; 
    unsigned long long fofs;												unsigned long long postsize=0,skipsize = 0; 																

    while(fread(&num, 1, 4, fi) == 4) {										// read number of docid in term
      if(!num) { ++tid; continue; }
      unsigned bnum = (num+BLK_DIDNUM-1)/BLK_DIDNUM; 
	  if(num > numx) { 
	    numx    = num;  						
	    in      = realloc(in,  num*4+64); 
	    outsize = num*4+bnum*sizeof(unsigned)*SKIP_SIZE+1024; 
        out     = realloc(out, outsize);
		if(!in || !out) die("malloc err=%u", num); 
	  }
      if(fread(in, 4, num, fi) != num) break;								// read docid list
      
      unsigned char *op = out,*_op; 
      vbput32(op, num);														// store f_t
  
      unsigned *pix = (unsigned *)op; 
      if(num > BLK_DIDNUM) { 
	    op += bnum*sizeof(unsigned)*SKIP_SIZE; 								skipsize += op-out; 
	  }
      for(_op = op, ip = in, ep = ip+num; ip < ep; ) {
        unsigned n = min(ep-ip, BLK_DIDNUM), b = 0,bx;					    if(op+5*n > out+outsize) die("output buffer too small\n"); 
        if(n > 1) { 
		  DELTA(ip, n, b); //bitdelta32( in+1, --n, pa, in[0], mode);
		    #ifdef _TURBOPFOR 
		  b = p4d32(ip+1, n-1, &bx);
	        #endif
		} 	
		    #ifdef SKIP_S
		  unsigned u = ip[0]<<SKIP_S|b;						// save width 
		    #else
          unsigned u = ip[0]; 								// First docid
		    #endif
			
        if(num > BLK_DIDNUM) {                             	// skip/index. docid[0] and offset to compressed block
		  *pix = u;
			#if SKIP_SIZE == 2	  							
          pix[bnum] = op - _op; 							// save posting offset
		    #endif
          pix++;
        } else vbput32(op, u);						   		// skip not needed
 
	    if(n > 1) {
		    #ifndef SKIP_S
		  *op++ = b; 	
			#endif
            #ifdef _TURBOPFOR
          *op++ = bx; 
		  op = n==129?p4dev32(    ip+1, n-1, op, b, bx):p4de32(   ip+1, n-1, op, b, bx);
            #else
		  op = n==129?bitpackv32( ip+1, n-1, op, b)    :bitpack32(ip+1, n-1, op, b);
            #endif
        }
		ip += n;	
      } 
	  fofs 		= ftello(fo);
      tmap_t *t = &tmap[tid++]; 
      TIDMAPSET(t, fofs);
	  if(fwrite(out, 1, op-out, fo) != op-out) die("fwrite error\n");				  	postsize += op-out;
    }
    fofs = ftello(fo);															// write termmap
	if(fwrite(tmap, sizeof(tmap_t), tid, fo) != tid) die("fwrite error\n");

    fseeko(fo, 0, SEEK_SET);
	if(fwrite(&fofs, sizeof(unsigned long long), 1, fo) != 1) die("fwrite error\n");
	if(fwrite(&tid,  sizeof(unsigned), 1, fo) != 1) die("fwrite error\n");      fofs = ftello(fi); 
	fclose(fi); fclose(fo);
	if(in) { free(in); free(out); }
    free(tmap);
																				printf("\nterms=%u size=[tmap=%u skip=%llu post=%llu total=%llu, ratio=%.2f %%\n", tid, (unsigned)(tid*sizeof(tmap_t)), 
                                                                                  skipsize, postsize-skipsize, postsize+tid*sizeof(tmap_t)+12, (double)postsize*100/(double)fofs );
  }
}
コード例 #21
0
ファイル: fsstat.c プロジェクト: drscream/illumos-joyent
static void
dflt_display(char *name, vopstats_t *oldvsp, vopstats_t *newvsp, int dispflag)
{
	int		niceflag = ((dispflag & DISP_RAW) == 0);
	longlong_t	nnewfile;
	longlong_t	nnamerm;
	longlong_t	nnamechg;
	longlong_t	nattrret;
	longlong_t	nattrchg;
	longlong_t	nlookup;
	longlong_t	nreaddir;
	longlong_t	ndataread;
	longlong_t	ndatawrite;
	longlong_t	readthruput;
	longlong_t	writethruput;
	char		buf[LBUFSZ];

	nnewfile = DELTA(ncreate) + DELTA(nmkdir) + DELTA(nsymlink);
	nnamerm = DELTA(nremove) + DELTA(nrmdir);
	nnamechg = DELTA(nrename) + DELTA(nlink) + DELTA(nsymlink);
	nattrret = DELTA(ngetattr) + DELTA(naccess) +
	    DELTA(ngetsecattr) + DELTA(nfid);
	nattrchg = DELTA(nsetattr) + DELTA(nsetsecattr) + DELTA(nspace);
	nlookup = DELTA(nlookup);
	nreaddir = DELTA(nreaddir);
	ndataread = DELTA(nread);
	ndatawrite = DELTA(nwrite);
	readthruput = DELTA(read_bytes);
	writethruput = DELTA(write_bytes);

	if (dispflag & DISP_HEADER) {
		(void) printf(
" new  name   name  attr  attr lookup rddir  read read  write write\n"
" file remov  chng   get   set    ops   ops   ops bytes   ops bytes\n");
	}

	PRINTSTAT(niceflag, "%5s ", "%lld:", nnewfile, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", nnamerm, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", nnamechg, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", nattrret, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", nattrchg, buf);
	PRINTSTAT(niceflag, " %5s ", "%lld:", nlookup, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", nreaddir, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", ndataread, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", readthruput, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", ndatawrite, buf);
	PRINTSTAT(niceflag, "%5s ", "%lld:", writethruput, buf);
	(void) printf("%s\n", name);
}
コード例 #22
0
ファイル: nfsstat.c プロジェクト: AhmadTux/freebsd
/*
 * Print a running summary of nfs statistics.
 * Repeat display every interval seconds, showing statistics
 * collected over that interval.  Assumes that interval is non-zero.
 * First line printed at top of screen is always cumulative.
 */
void
sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
{
	struct nfsstats nfsstats, lastst, *nfsstatsp;
	struct nfsrvstats nfsrvstats, lastsrvst, *nfsrvstatsp;
	int hdrcnt = 1;

	nfsstatsp = &lastst;
	nfsrvstatsp = &lastsrvst;
	readstats(&nfsstatsp, &nfsrvstatsp, 0);
	if (clientOnly && !nfsstatsp) {
		printf("Client not present!\n");
		clientOnly = 0;
	}
	if (serverOnly && !nfsrvstatsp) {
		printf("Server not present!\n");
		serverOnly = 0;
	}
	sleep(interval);

	for (;;) {
		nfsstatsp = &nfsstats;
		nfsrvstatsp = &nfsrvstats;
		readstats(&nfsstatsp, &nfsrvstatsp, 0);

		if (--hdrcnt == 0) {
			printhdr(clientOnly, serverOnly);
			if (clientOnly && serverOnly)
				hdrcnt = 10;
			else
				hdrcnt = 20;
		}
		if (clientOnly) {
		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
			((clientOnly && serverOnly) ? "Client:" : ""),
			DELTA(attrcache_hits) + DELTA(attrcache_misses),
			DELTA(lookupcache_hits) + DELTA(lookupcache_misses),
			DELTA(biocache_readlinks),
			DELTA(biocache_reads),
			DELTA(biocache_writes),
			nfsstats.rpccnt[NFSPROC_RENAME]-lastst.rpccnt[NFSPROC_RENAME],
			DELTA(accesscache_hits) + DELTA(accesscache_misses),
			DELTA(biocache_readdirs)
		    );
		    if (widemode) {
			    printf(" %s %s %s %s %s %s",
				sperc1(DELTA(attrcache_hits),
				    DELTA(attrcache_misses)),
				sperc1(DELTA(lookupcache_hits), 
				    DELTA(lookupcache_misses)),
				sperc2(DELTA(biocache_reads),
				    DELTA(read_bios)),
				sperc2(DELTA(biocache_writes),
				    DELTA(write_bios)),
				sperc1(DELTA(accesscache_hits),
				    DELTA(accesscache_misses)),
				sperc2(DELTA(biocache_readdirs),
				    DELTA(readdir_bios))
			    );
		    }
		    printf("\n");
		    lastst = nfsstats;
		}
		if (serverOnly) {
		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
			((clientOnly && serverOnly) ? "Server:" : ""),
			nfsrvstats.srvrpccnt[NFSPROC_GETATTR]-lastsrvst.srvrpccnt[NFSPROC_GETATTR],
			nfsrvstats.srvrpccnt[NFSPROC_LOOKUP]-lastsrvst.srvrpccnt[NFSPROC_LOOKUP],
			nfsrvstats.srvrpccnt[NFSPROC_READLINK]-lastsrvst.srvrpccnt[NFSPROC_READLINK],
			nfsrvstats.srvrpccnt[NFSPROC_READ]-lastsrvst.srvrpccnt[NFSPROC_READ],
			nfsrvstats.srvrpccnt[NFSPROC_WRITE]-lastsrvst.srvrpccnt[NFSPROC_WRITE],
			nfsrvstats.srvrpccnt[NFSPROC_RENAME]-lastsrvst.srvrpccnt[NFSPROC_RENAME],
			nfsrvstats.srvrpccnt[NFSPROC_ACCESS]-lastsrvst.srvrpccnt[NFSPROC_ACCESS],
			(nfsrvstats.srvrpccnt[NFSPROC_READDIR]-lastsrvst.srvrpccnt[NFSPROC_READDIR])
			+(nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS]-lastsrvst.srvrpccnt[NFSPROC_READDIRPLUS]));
		    printf("\n");
		    lastsrvst = nfsrvstats;
		}
		fflush(stdout);
		sleep(interval);
	}
	/*NOTREACHED*/
}
コード例 #23
0
ファイル: qwmeasure.c プロジェクト: Marquezino/qwalk
int measureState2D(double complex *****A, double complex *****Atemp, 
		   options2D_t opts){
  int j, k, m, n;
  int det, dice, result, error;
  double *p, *sp;
  double complex ****aux;

  int max = opts.max;
  int detectors = opts.detectors;
  int **detector_pts = opts.detector_pts;

  const int lbound   = (opts.lattType == CYCLE_LATT) ? 0 : -max;
  const int rbound   = (opts.lattType == CYCLE_LATT) ? max-1 : max;
  const int aux_size = (opts.lattType == CYCLE_LATT) ? max : 2*max+1;

  /* Detectors are described by a collection M_m of measurement 
   * operators which satisfy the completeness equation. The index m
   * indicates the result of the measurement. Before state |Psi> is 
   * measured the probability that result m occurs is given by 
   * p(m)= <Psi| Mdagger_m M_m |Psi>, and after the measurement the state 
   * collapses to |Psi'>= 1/sqrt(p(m)) M_m|Psi>. In qw2d we may define an 
   * arbitrary number of detectors specifying a list of coordinates 
   * (m_1, n_1), ..., (m_N,n_N) [that is, int **detector_pts]. The measurement 
   * operators are M_0 = I_4 tensor I_\infty - sum(M_i, i from 1 to N) and 
   * M_i = I_4 tensor |m_i, n_i><m_i, n_i|, for 1 <= i <= N. 
   *
   * To perform the measurement we (1) generate a random number r; and 
   * (2) determine an integer m, 0 <= m <= N, such that
   * sum(p(j), j from 0 to m-1) <= m < sum(p(j), j from 0 to m)
   */


  if( (!*A) || (!*Atemp))
    return -1;
  if(max<1)
    return -2;
  if(detectors<0)
    return -3;
  if(!detector_pts)
    return -4;

  p = allocReal1D(detectors+1);
  if(!p)
    return -5;
  error = cleanReal1D(p, detectors+1);
  if(error)
    return -6;

  sp = allocReal1D(detectors+1);
  if(!sp)
    return -5;
  error = cleanReal1D(sp, detectors+1);
  if(error)
    return -6;

  /* Here we evaluate the probability of each detection... */
  for(det=1; det<=detectors; det++ ){  
    if(opts.lattType == CYCLE_LATT){
      m = detector_pts[det][0];
      n = detector_pts[det][1];
    }else{
      m = max + detector_pts[det][0];
      n = max + detector_pts[det][1];
    }

    for(j=0; j<2; j++)
      for(k=0; k<2; k++)
	p[det] += (*A)[j][k][m][n]*conj((*A)[j][k][m][n]);
  }

  /* ...and the probability of measuring the complement */
  p[0] = 1.0;
  for(j=1; j<=detectors; j++)
    p[0] -= p[j];

  /* ...  */
  sp[0] = p[0];
  for(det=1; det<=detectors; det++)
    sp[det] = sp[det-1] + p[det];

  /* We get a new random number */
  dice = rand();

  /* Based on this number we identify the corresponding result */
  for(result=0; result<=detectors; result++)
    if(dice < sp[result]*RAND_MAX) break;

  for(m=lbound; m<rbound; m++){
    for(n=lbound; n<rbound; n++){
      int delta;
      const int auxm = (opts.lattType == CYCLE_LATT) ? m : max+m;
      const int auxn = (opts.lattType == CYCLE_LATT) ? n : max+n;

      if(result==0){
	delta = 1;
	for(det=1; det<=detectors; det++)
	  delta *= (1-DELTA(m, detector_pts[det][0])*
		    DELTA(n, detector_pts[det][1]));
      }
      else{
	delta = DELTA(m, detector_pts[result][0])*
	  DELTA(n, detector_pts[result][1]);
      }
      
      for(j=0; j<2; j++)
	for(k=0; k<2; k++)
	  (*Atemp)[j][k][auxm][auxn] = 
	    delta*((*A)[j][k][auxm][auxn])/sqrt(p[result]);
    }
  }

  free(p);
  free(sp);

  /* Now we quicky exchange matrices A and Atemp */
  aux = *A;
  *A = *Atemp;
  *Atemp = aux;

  error = cleanComplex4D(*Atemp, 2, 2, aux_size, aux_size);
  if(error)
    return -6;

  return result;
}
コード例 #24
0
ファイル: nfsstat.c プロジェクト: AhmadTux/freebsd
/*
 * Print a running summary of nfs statistics for the experimental client and/or
 * server.
 * Repeat display every interval seconds, showing statistics
 * collected over that interval.  Assumes that interval is non-zero.
 * First line printed at top of screen is always cumulative.
 */
void
exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
{
	struct ext_nfsstats nfsstats, lastst, *ext_nfsstatsp;
	int hdrcnt = 1;

	ext_nfsstatsp = &lastst;
	if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
		err(1, "Can't get stats");
	sleep(interval);

	for (;;) {
		ext_nfsstatsp = &nfsstats;
		if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
			err(1, "Can't get stats");

		if (--hdrcnt == 0) {
			printhdr(clientOnly, serverOnly);
			if (clientOnly && serverOnly)
				hdrcnt = 10;
			else
				hdrcnt = 20;
		}
		if (clientOnly) {
		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
			((clientOnly && serverOnly) ? "Client:" : ""),
			DELTA(attrcache_hits) + DELTA(attrcache_misses),
			DELTA(lookupcache_hits) + DELTA(lookupcache_misses),
			DELTA(biocache_readlinks),
			DELTA(biocache_reads),
			DELTA(biocache_writes),
			nfsstats.rpccnt[NFSPROC_RENAME] -
			lastst.rpccnt[NFSPROC_RENAME],
			DELTA(accesscache_hits) + DELTA(accesscache_misses),
			DELTA(biocache_readdirs)
		    );
		    if (widemode) {
			    printf(" %s %s %s %s %s %s",
				sperc1(DELTA(attrcache_hits),
				    DELTA(attrcache_misses)),
				sperc1(DELTA(lookupcache_hits), 
				    DELTA(lookupcache_misses)),
				sperc2(DELTA(biocache_reads),
				    DELTA(read_bios)),
				sperc2(DELTA(biocache_writes),
				    DELTA(write_bios)),
				sperc1(DELTA(accesscache_hits),
				    DELTA(accesscache_misses)),
				sperc2(DELTA(biocache_readdirs),
				    DELTA(readdir_bios))
			    );
		    }
		    printf("\n");
		    lastst = nfsstats;
		}
		if (serverOnly) {
		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
			((clientOnly && serverOnly) ? "Server:" : ""),
			nfsstats.srvrpccnt[NFSV4OP_GETATTR] -
			lastst.srvrpccnt[NFSV4OP_GETATTR],
			nfsstats.srvrpccnt[NFSV4OP_LOOKUP] -
			lastst.srvrpccnt[NFSV4OP_LOOKUP],
			nfsstats.srvrpccnt[NFSV4OP_READLINK] -
			lastst.srvrpccnt[NFSV4OP_READLINK],
			nfsstats.srvrpccnt[NFSV4OP_READ] -
			lastst.srvrpccnt[NFSV4OP_READ],
			nfsstats.srvrpccnt[NFSV4OP_WRITE] -
			lastst.srvrpccnt[NFSV4OP_WRITE],
			nfsstats.srvrpccnt[NFSV4OP_RENAME] -
			lastst.srvrpccnt[NFSV4OP_RENAME],
			nfsstats.srvrpccnt[NFSV4OP_ACCESS] -
			lastst.srvrpccnt[NFSV4OP_ACCESS],
			(nfsstats.srvrpccnt[NFSV4OP_READDIR] -
			 lastst.srvrpccnt[NFSV4OP_READDIR]) +
			(nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS] -
			 lastst.srvrpccnt[NFSV4OP_READDIRPLUS]));
		    printf("\n");
		    lastst = nfsstats;
		}
		fflush(stdout);
		sleep(interval);
	}
	/*NOTREACHED*/
}
コード例 #25
0
ファイル: nfsstat.c プロジェクト: FreeBSDFoundation/freebsd
/*
 * Print a running summary of nfs statistics for the experimental client and/or
 * server.
 * Repeat display every interval seconds, showing statistics
 * collected over that interval.  Assumes that interval is non-zero.
 * First line printed at top of screen is always cumulative.
 */
static void
exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly,
    int newStats)
{
	struct nfsstatsv1 nfsstats, lastst, *ext_nfsstatsp;
	struct nfsstatsv1 curtotal, lasttotal;
	struct timespec ts, lastts;
	int hdrcnt = 1;

	ext_nfsstatsp = &lastst;
	ext_nfsstatsp->vers = NFSSTATS_V1;
	if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) < 0)
		err(1, "Can't get stats");
	clock_gettime(CLOCK_MONOTONIC, &lastts);
	compute_totals(&lasttotal, ext_nfsstatsp);
	sleep(interval);

	for (;;) {
		ext_nfsstatsp = &nfsstats;
		ext_nfsstatsp->vers = NFSSTATS_V1;
		if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp)
		    < 0)
			err(1, "Can't get stats");
		clock_gettime(CLOCK_MONOTONIC, &ts);

		if (--hdrcnt == 0) {
			printhdr(clientOnly, serverOnly, newStats);
			if (newStats)
				hdrcnt = 20;
			else if (clientOnly && serverOnly)
				hdrcnt = 10;
			else
				hdrcnt = 20;
		}
		if (clientOnly && newStats == 0) {
		    printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju",
			((clientOnly && serverOnly) ? "Client:" : ""),
			(uintmax_t)DELTA(rpccnt[NFSPROC_GETATTR]),
			(uintmax_t)DELTA(rpccnt[NFSPROC_LOOKUP]),
			(uintmax_t)DELTA(rpccnt[NFSPROC_READLINK]),
			(uintmax_t)DELTA(rpccnt[NFSPROC_READ]),
			(uintmax_t)DELTA(rpccnt[NFSPROC_WRITE]),
			(uintmax_t)DELTA(rpccnt[NFSPROC_RENAME]),
			(uintmax_t)DELTA(rpccnt[NFSPROC_ACCESS]),
			(uintmax_t)(DELTA(rpccnt[NFSPROC_READDIR]) +
			DELTA(rpccnt[NFSPROC_READDIRPLUS]))
		    );
		    if (widemode) {
			    printf(" %s %s %s %s %s %s",
				sperc1(DELTA(attrcache_hits),
				    DELTA(attrcache_misses)),
				sperc1(DELTA(lookupcache_hits), 
				    DELTA(lookupcache_misses)),
				sperc2(DELTA(biocache_reads),
				    DELTA(read_bios)),
				sperc2(DELTA(biocache_writes),
				    DELTA(write_bios)),
				sperc1(DELTA(accesscache_hits),
				    DELTA(accesscache_misses)),
				sperc2(DELTA(biocache_readdirs),
				    DELTA(readdir_bios))
			    );
		    }
		    printf("\n");
		}

		if (serverOnly && newStats) {
			long double cur_secs, last_secs, etime;
			long double mbsec;
			long double kb_per_transfer;
			long double transfers_per_second;
			long double ms_per_transfer;
			uint64_t queue_len;
			long double busy_pct;
			int i;

			cur_secs = ts.tv_sec +
			    ((long double)ts.tv_nsec / 1000000000);
			last_secs = lastts.tv_sec +
			    ((long double)lastts.tv_nsec / 1000000000);
			etime = cur_secs - last_secs;

			compute_totals(&curtotal, &nfsstats);

			for (i = 0; i < NUM_STAT_TYPES; i++) {
				compute_new_stats(&nfsstats, &lastst,
				    STAT_TYPE_TO_NFS(i), etime, &mbsec,
				    &kb_per_transfer,
				    &transfers_per_second,
				    &ms_per_transfer, &queue_len,
				    &busy_pct);

				if (i == STAT_TYPE_COMMIT) {
					if (widemode == 0)
						continue;

					printf("%2.0Lf %7.2Lf ",
					    transfers_per_second,
					    ms_per_transfer);
				} else {
					printf("%5.2Lf %5.0Lf %7.2Lf ",
					    kb_per_transfer,
					    transfers_per_second, mbsec);
					if (widemode)
						printf("%5.2Lf ",
						    ms_per_transfer);
				}
			}

			compute_new_stats(&curtotal, &lasttotal, 0, etime,
			    &mbsec, &kb_per_transfer, &transfers_per_second,
			    &ms_per_transfer, &queue_len, &busy_pct);

			printf("%5.2Lf %5.0Lf %7.2Lf %5.2Lf %3ju %3.0Lf\n",
			    kb_per_transfer, transfers_per_second, mbsec,
			    ms_per_transfer, queue_len, busy_pct);
		} else if (serverOnly) {
		    printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju",
			((clientOnly && serverOnly) ? "Server:" : ""),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_GETATTR]),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_LOOKUP]),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_READLINK]),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_READ]),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_WRITE]),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_RENAME]),
			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_ACCESS]),
			(uintmax_t)(DELTA(srvrpccnt[NFSV4OP_READDIR]) +
			DELTA(srvrpccnt[NFSV4OP_READDIRPLUS])));
		    printf("\n");
		}
		bcopy(&nfsstats, &lastst, sizeof(lastst));
		bcopy(&curtotal, &lasttotal, sizeof(lasttotal));
		lastts = ts;
		fflush(stdout);
		sleep(interval);
	}
	/*NOTREACHED*/
}
コード例 #26
0
static int gameport_measure_speed(struct gameport *gameport)
{
#if defined(__i386__)

	unsigned int i, t, t1, t2, t3, tx;
	unsigned long flags;

	if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW))
		return 0;

	tx = 1 << 30;

	for(i = 0; i < 50; i++) {
		local_irq_save(flags);
		GET_TIME(t1);
		for (t = 0; t < 50; t++) gameport_read(gameport);
		GET_TIME(t2);
		GET_TIME(t3);
		local_irq_restore(flags);
		udelay(i * 10);
		if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t;
	}

	gameport_close(gameport);
	return 59659 / (tx < 1 ? 1 : tx);

#elif defined (__x86_64__)

	unsigned int i, t;
	unsigned long tx, t1, t2, flags;

	if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW))
		return 0;

	tx = 1 << 30;

	for(i = 0; i < 50; i++) {
		local_irq_save(flags);
		rdtscl(t1);
		for (t = 0; t < 50; t++) gameport_read(gameport);
		rdtscl(t2);
		local_irq_restore(flags);
		udelay(i * 10);
		if (t2 - t1 < tx) tx = t2 - t1;
	}

	gameport_close(gameport);
	return (this_cpu_read(cpu_info.loops_per_jiffy) *
		(unsigned long)HZ / (1000 / 50)) / (tx < 1 ? 1 : tx);

#else

	unsigned int j, t = 0;

	if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW))
		return 0;

	j = jiffies; while (j == jiffies);
	j = jiffies; while (j == jiffies) { t++; gameport_read(gameport); }

	gameport_close(gameport);
	return t * HZ / 1000;

#endif
}
コード例 #27
0
ファイル: slaed5.c プロジェクト: deepakantony/vispack
/* Subroutine */ int slaed5_(integer *i, real *d, real *z, real *delta, real *
	rho, real *dlam)
{
/*  -- LAPACK routine (version 2.0) --   
       Univ. of Tennessee, Oak Ridge National Lab, Argonne National Lab, 
  
       Courant Institute, NAG Ltd., and Rice University   
       September 30, 1994   


    Purpose   
    =======   

    This subroutine computes the I-th eigenvalue of a symmetric rank-one 
  
    modification of a 2-by-2 diagonal matrix   

               diag( D )  +  RHO *  Z * transpose(Z) .   

    The diagonal elements in the array D are assumed to satisfy   

               D(i) < D(j)  for  i < j .   

    We also assume RHO > 0 and that the Euclidean norm of the vector   
    Z is one.   

    Arguments   
    =========   

    I      (input) INTEGER   
           The index of the eigenvalue to be computed.  I = 1 or I = 2.   

    D      (input) REAL array, dimension (2)   
           The original eigenvalues.  We assume D(1) < D(2).   

    Z      (input) REAL array, dimension (2)   
           The components of the updating vector.   

    DELTA  (output) REAL array, dimension (2)   
           The vector DELTA contains the information necessary   
           to construct the eigenvectors.   

    RHO    (input) REAL   
           The scalar in the symmetric updating formula.   

    DLAM   (output) REAL   
           The computed lambda_I, the I-th updated eigenvalue.   

    ===================================================================== 
  


    
   Parameter adjustments   
       Function Body */
    /* System generated locals */
    real r__1;
    /* Builtin functions */
    double sqrt(doublereal);
    /* Local variables */
    static real temp, b, c, w, del, tau;


#define DELTA(I) delta[(I)-1]
#define Z(I) z[(I)-1]
#define D(I) d[(I)-1]


    del = D(2) - D(1);
    if (*i == 1) {
	w = *rho * 2.f * (Z(2) * Z(2) - Z(1) * Z(1)) / del + 1.f;
	if (w > 0.f) {
	    b = del + *rho * (Z(1) * Z(1) + Z(2) * Z(2));
	    c = *rho * Z(1) * Z(1) * del;

/*           B > ZERO, always */

	    tau = c * 2.f / (b + sqrt((r__1 = b * b - c * 4.f, dabs(r__1))));
	    *dlam = D(1) + tau;
	    DELTA(1) = -(doublereal)Z(1) / tau;
	    DELTA(2) = Z(2) / (del - tau);
	} else {
	    b = -(doublereal)del + *rho * (Z(1) * Z(1) + Z(2) * Z(2));
	    c = *rho * Z(2) * Z(2) * del;
	    if (b > 0.f) {
		tau = c * -2.f / (b + sqrt(b * b + c * 4.f));
	    } else {
		tau = (b - sqrt(b * b + c * 4.f)) / 2.f;
	    }
	    *dlam = D(2) + tau;
	    DELTA(1) = -(doublereal)Z(1) / (del + tau);
	    DELTA(2) = -(doublereal)Z(2) / tau;
	}
	temp = sqrt(DELTA(1) * DELTA(1) + DELTA(2) * DELTA(2));
	DELTA(1) /= temp;
	DELTA(2) /= temp;
    } else {

/*     Now I=2 */

	b = -(doublereal)del + *rho * (Z(1) * Z(1) + Z(2) * Z(2));
	c = *rho * Z(2) * Z(2) * del;
	if (b > 0.f) {
	    tau = (b + sqrt(b * b + c * 4.f)) / 2.f;
	} else {
	    tau = c * 2.f / (-(doublereal)b + sqrt(b * b + c * 4.f));
	}
	*dlam = D(2) + tau;
	DELTA(1) = -(doublereal)Z(1) / (del + tau);
	DELTA(2) = -(doublereal)Z(2) / tau;
	temp = sqrt(DELTA(1) * DELTA(1) + DELTA(2) * DELTA(2));
	DELTA(1) /= temp;
	DELTA(2) /= temp;
    }
    return 0;

/*     End OF SLAED5 */

} /* slaed5_ */