Пример #1
0
int seg_fill_basins(OUTLET outlet, SEGMENT * distance, SEGMENT * dirs)
{
    /* fill empty spaces with zeros but leave -1 as a markers of NULL */
    int r, c, i, j;
    int next_r, next_c;
    double stop, val;
    POINT n_cell;
    CELL dirs_cell;
    DCELL distance_cell;

    tail = 0;
    head = -1;
    r = outlet.r;
    c = outlet.c;
    val = 1;
    stop = 0;

    Segment_put(distance, &stop, r, c);

    while (tail != head) {

	for (i = 1; i < 9; ++i) {
	    if (NOT_IN_REGION(i))
		continue;	/* out of border */

	    j = DIAG(i);
	    next_r = NR(i);
	    next_c = NC(i);

	    Segment_get(dirs, &dirs_cell, next_r, next_c);

	    if (dirs_cell == j) {	/* countributing cell */

		Segment_get(distance, &distance_cell, next_r, next_c);
		distance_cell = (distance_cell == stop) ? stop : val;
		Segment_put(distance, &distance_cell, next_r, next_c);
		n_cell.r = next_r;
		n_cell.c = next_c;
		fifo_insert(n_cell);

	    }
	}			/* end for i... */

	n_cell = fifo_return_del();
	r = n_cell.r;
	c = n_cell.c;
    }

    return 0;
}
Пример #2
0
static inline void tx_xmit_pkt(struct fm10k_tx_queue *q, struct rte_mbuf *mb)
{
	uint16_t last_id;
	uint8_t flags;

	/* always set the LAST flag on the last descriptor used to
	 * transmit the packet */
	flags = FM10K_TXD_FLAG_LAST;
	last_id = q->next_free + mb->nb_segs - 1;
	if (last_id >= q->nb_desc)
		last_id = last_id - q->nb_desc;

	/* but only set the RS flag on the last descriptor if rs_thresh
	 * descriptors will be used since the RS flag was last set */
	if ((q->nb_used + mb->nb_segs) >= q->rs_thresh) {
		flags |= FM10K_TXD_FLAG_RS;
		fifo_insert(&q->rs_tracker, last_id);
		q->nb_used = 0;
	} else {
		q->nb_used = q->nb_used + mb->nb_segs;
	}

	q->hw_ring[last_id].flags = flags;
	q->nb_free -= mb->nb_segs;

	/* set checksum flags on first descriptor of packet. SCTP checksum
	 * offload is not supported, but we do not explicitly check for this
	 * case in favor of greatly simplified processing. */
	if (mb->ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK))
		q->hw_ring[q->next_free].flags |= FM10K_TXD_FLAG_CSUM;

	/* set vlan if requested */
	if (mb->ol_flags & PKT_TX_VLAN_PKT)
		q->hw_ring[q->next_free].vlan = mb->vlan_tci;

	/* fill up the rings */
	for (; mb != NULL; mb = mb->next) {
		q->sw_ring[q->next_free] = mb;
		q->hw_ring[q->next_free].buffer_addr =
				rte_cpu_to_le_64(MBUF_DMA_ADDR(mb));
		q->hw_ring[q->next_free].buflen =
				rte_cpu_to_le_16(rte_pktmbuf_data_len(mb));
		if (++q->next_free == q->nb_desc)
			q->next_free = 0;
	}
}
Пример #3
0
int ram_fill_basins(OUTLET outlet, DCELL ** distance, CELL ** dirs)
{
    /* fill empty spaces with zeros but leave -1 as a markers of NULL */
    int r, c, i, j;
    int next_r, next_c;
    double stop, val;
    POINT n_cell;

    tail = 0;
    head = -1;
    r = outlet.r;
    c = outlet.c;
    val = 1;
    stop = 0;

    distance[r][c] = stop;

    while (tail != head) {
	for (i = 1; i < 9; ++i) {
	    if (NOT_IN_REGION(i))
		continue;	/* out of border */

	    j = DIAG(i);
	    next_r = NR(i);
	    next_c = NC(i);

	    if (dirs[next_r][next_c] == j) {	/* countributing cell */

		distance[next_r][next_c] =
		    (distance[next_r][next_c] == stop) ? stop : val;
		n_cell.r = next_r;
		n_cell.c = next_c;
		fifo_insert(n_cell);
	    }

	}			/* end for i... */

	n_cell = fifo_return_del();
	r = n_cell.r;
	c = n_cell.c;
    }

    return 0;
}
Пример #4
0
int ram_calculate_downstream(CELL ** dirs, DCELL ** distance,
			     DCELL ** elevation, OUTLET outlet, int outs)
{

    int r, c, i, j;
    int next_r, next_c;
    POINT n_cell;
    double cur_dist = 0;
    double tmp_dist = 0;
    double target_elev;		/* eleavation at stream or outlet */
    double easting, northing;
    double cell_easting, cell_northing;
    struct Cell_head window;

    Rast_get_window(&window);

    tail = 0;
    head = -1;
    r = outlet.r;
    c = outlet.c;

    if (elevation) {
	target_elev = elevation[r][c];
	elevation[r][c] = 0.;
    }

    while (tail != head) {
	easting = window.west + (c + .5) * window.ew_res;
	northing = window.north - (r + .5) * window.ns_res;

	for (i = 1; i < 9; ++i) {

	    if (NOT_IN_REGION(i))
		continue;	/* border */

	    j = DIAG(i);
	    next_r = NR(i);
	    next_c = NC(i);
	    if (dirs[NR(i)][NC(i)] == j) {	/* countributing cell, reset distance and elevation */

		if (outs) {	/* outlet mode */

		    if (distance[NR(i)][NC(i)] == 0)
			continue;	/* continue loop, point is not added to the queue! */
		    else {
			cell_northing =
			    window.north - (next_r + .5) * window.ns_res;
			cell_easting =
			    window.west + (next_c + .5) * window.ew_res;
			cur_dist =
			    tmp_dist + G_distance(easting, northing,
						  cell_easting,
						  cell_northing);
			distance[NR(i)][NC(i)] = cur_dist;
		    }

		}
		else {		/* stream mode */

		    if (distance[next_r][next_c] == 0) {
			cur_dist = 0;
			if (elevation)
			    target_elev = elevation[next_r][next_c];
		    }
		    else {
			cell_northing =
			    window.north - (next_r + .5) * window.ns_res;
			cell_easting =
			    window.west + (next_c + .5) * window.ew_res;
			cur_dist =
			    tmp_dist + G_distance(easting, northing,
						  cell_easting,
						  cell_northing);
			distance[NR(i)][NC(i)] = cur_dist;
		    }
		}		/* end stream mode */

		if (elevation) {
		    elevation[next_r][next_c] =
			elevation[next_r][next_c] - target_elev;
		    n_cell.target_elev = target_elev;
		}

		n_cell.r = next_r;
		n_cell.c = next_c;
		n_cell.cur_dist = cur_dist;
		fifo_insert(n_cell);
	    }
	}			/* end for i... */

	n_cell = fifo_return_del();
	r = n_cell.r;
	c = n_cell.c;
	tmp_dist = n_cell.cur_dist;
	target_elev = n_cell.target_elev;

    }				/* end while */
    return 0;
}
Пример #5
0
int seg_calculate_downstream(SEGMENT *dirs, SEGMENT * distance,
			     SEGMENT *elevation, OUTLET outlet, int outs)
{

    int r, c, i, j;
    int next_r, next_c;
    POINT n_cell;
    double cur_dist = 0;
    double tmp_dist = 0;
    double target_elev;		/* eleavation at stream or outlet */
    double easting, northing;
    double cell_easting, cell_northing;
    CELL dirs_cell;
    DCELL distance_cell, elevation_cell;
    DCELL zero_cell = 0;
    struct Cell_head window;

    Rast_get_window(&window);

    tail = 0;
    head = -1;
    r = outlet.r;
    c = outlet.c;

    if (elevation) {
	Segment_get(elevation, &target_elev, r, c);
	Segment_put(elevation, &zero_cell, r, c);
    }

    while (tail != head) {
	easting = window.west + (c + .5) * window.ew_res;
	northing = window.north - (r + .5) * window.ns_res;

	for (i = 1; i < 9; ++i) {

	    if (NOT_IN_REGION(i))
		continue;	/* border */

	    j = DIAG(i);
	    next_r = NR(i);
	    next_c = NC(i);

	    Segment_get(dirs, &dirs_cell, next_r, next_c);
	    if (dirs_cell == j) {	/* countributing cell, reset distance and elevation */

		if (outs) {	/* outlet mode */
		    Segment_get(distance, &distance_cell, next_r, next_c);
		    if (distance_cell == 0)
			continue;	/* continue loop, point is not added to the queue! */
		    else {
			cell_northing =
			    window.north - (next_r + .5) * window.ns_res;
			cell_easting =
			    window.west + (next_c + .5) * window.ew_res;
			cur_dist =
			    tmp_dist + G_distance(easting, northing,
						  cell_easting,
						  cell_northing);
			Segment_put(distance, &cur_dist, next_r, next_c);

		    }

		}
		else {		/* stream mode */
		    Segment_get(distance, &distance_cell, next_r, next_c);
		    if (distance_cell == 0) {
			cur_dist = 0;
			if (elevation)
			    Segment_get(elevation, &target_elev, next_r,
					next_c);
		    }
		    else {
			cell_northing =
			    window.north - (next_r + .5) * window.ns_res;
			cell_easting =
			    window.west + (next_c + .5) * window.ew_res;
			cur_dist =
			    tmp_dist + G_distance(easting, northing,
						  cell_easting,
						  cell_northing);
			Segment_put(distance, &cur_dist, next_r, next_c);
		    }
		}		/* end stream mode */

		if (elevation) {
		    Segment_get(elevation, &elevation_cell, next_r, next_c);
		    elevation_cell -= target_elev;
		    Segment_put(elevation, &elevation_cell, next_r, next_c);
		    n_cell.target_elev = target_elev;
		}

		n_cell.r = next_r;
		n_cell.c = next_c;
		n_cell.cur_dist = cur_dist;
		fifo_insert(n_cell);
	    }
	}			/* end for i... */

	n_cell = fifo_return_del();
	r = n_cell.r;
	c = n_cell.c;
	tmp_dist = n_cell.cur_dist;
	target_elev = n_cell.target_elev;

    }				/* end while */
    return 0;
}