Beispiel #1
0
int
main(int argc, char **argv) {
  time_t start,stop,stop2,now,sl;
  struct tm *t;
  int ifindex,i;
  char startstr[64],stopstr[64],stopstr2[64];
  char str[64];

  if(argc<4) {
    printf("Usage: ssb <device> <ifindex> <result path>\n");
    exit(-1);
  }

  sscanf(argv[2],"%d",&ifindex);

  //Find start time for next 5 minute time interval
  start=getNextInterval();
  stop=start+300;
  stop2=stop+300;
  
  t=localtime(&start);
  strftime(startstr,64,"%Y-%m-%d %H:%M:%S",t);
  t=localtime(&stop);
  strftime(stopstr,64,"%Y-%m-%d %H:%M:%S",t);
  t=localtime(&stop2);
  strftime(stopstr2,64,"%Y-%m-%d %H:%M:%S",t);

  createFlows(argv[1],ifindex,startstr,stopstr,argv[3]);
  for(i=0;i<=INTERVALS+1;i++)
    currentfd[i]=nextfd[i];
  createFlows(argv[1],ifindex,stopstr,stopstr2,argv[3]);

  time(&now);
  sl=start-now+310;
  while(1) {
    time(&start);
    t=localtime(&start);
    strftime(str,64,"%Y-%m-%d %H:%M:%S",t);
    sleep(sl);
    for(i=INTERVALS+1;i>=0;i--) {
      mapi_close_flow(currentfd[i]);
      currentfd[i]=nextfd[i];
    }
    renameFile(startstr,argv[3]);
    strcpy(startstr,stopstr);
    start=stop;
    stop+=300;
    stop2+=300;
    time(&now);
    sl=start-now+310;
    t=localtime(&stop);
    strftime(stopstr,64,"%Y-%m-%d %H:%M:%S",t);
    t=localtime(&stop2);
    strftime(stopstr2,64,"%Y-%m-%d %H:%M:%S",t);
    createFlows(argv[1],ifindex,stopstr,stopstr2,argv[3]);    
  }

}
Beispiel #2
0
int  computeShapeTables(TShape *shape, TTable *curve)
//
//  Input:   shape = pointer to a TShape object
//           curve = pointer to shape's table of width v. depth
//  Output:  returns TRUE if successful. FALSE if not
//  Purpose: computes the entries in a shape's geometry tables from
//           the shape's width v. height curve normalized with repsect
//           to full height.
//
//  Note:    the shape curve is a user-supplied table of width v. height
//           for a custom x-section of unit height.
{
    int    i, n;
    double dy, y, y1, y2, w, w1, w2;
	double yLast, wLast, wMax;

    // --- get first entry of user's shape curve
    if ( !table_getFirstEntry(curve, &y1, &w1) ) return FALSE;
    if ( y1 < 0.0 || y1 >= 1.0 || w1 < 0.0 ) return FALSE;
    wMax = w1;
    
    // --- if first entry not at zero ht. then add an initial entry
    if ( y1 != 0.0 )
    {
        y2 = y1;
        w2 = w1;
        y1 = 0.0;
        w1 = 0.0;
    }

    // --- otherwise get next entry in the user's shape curve
    else
    {
        if ( !table_getNextEntry(curve, &y2, &w2) ) return FALSE;
        if ( y2 < y1 || w2 < 0.0 ) return FALSE;
        if ( y2 > 1.0 ) y2 = 1.0;
        if ( w2 > wMax ) wMax = w2;
    }

    // --- determine number of entries & interval size in geom. tables
    shape->nTbl = N_SHAPE_TBL;
    n = shape->nTbl - 1;
    dy = 1.0 / (double)(n);

    // --- initialize geometry tables
    shape->areaTbl[0] = 0.0;
    shape->hradTbl[0] = 0.0;
    shape->widthTbl[0] = w1;
    Ptotal = w1;
    Atotal = 0.0;

    // --- fill in rest of geometry tables
    y = 0.0;
    w = w1;
    for ( i = 1; i <= n; i++ )
    {
        // --- advance to next relative height level
        yLast = y;
        wLast = w;
        y = y + dy;

        // --- do not allow height to exceed 1.0
        if ( fabs(y - 1.0) < TINY ) y = 1.0;

        // --- if height exceeds current shape curve interval,
        //     move to next interval of shape curve
        if ( y > y2 )
        {
            if ( !getNextInterval(curve, y, yLast, wLast, &y1, &y2, &w1,
                                  &w2, &wMax) )
                return FALSE;
            yLast = y1;
            wLast = w1;
        }

        // --- get top width, area, & perimeter of current interval
        w = getWidth(y, y1, y2, w1, w2);
        Atotal += getArea(y, w, yLast, wLast); 
        Ptotal += getPerim(y, w, yLast, wLast);

        // --- add top width to total perimeter if at top of shape
        if ( y == 1.0 ) Ptotal += w2;

        // --- update table values
        shape->widthTbl[i] = w;
        shape->areaTbl[i] = Atotal;
        if ( Ptotal > 0.0) shape->hradTbl[i] = Atotal / Ptotal;
        else               shape->hradTbl[i] = 0.0;
    }

    // --- assign values to shape'a area and hyd. radius when full
    shape->aFull = shape->areaTbl[n];
    shape->rFull = shape->hradTbl[n];

    // --- assign values to shape's max. width and section factor
    shape->wMax  = wMax;
    getSmax(shape);
    return TRUE;
}