Example #1
0
static void doplusloop(void)
{
    ucell high, low;
    cell increment, startval, endval, offset;

    increment = POP();

    startval = POPR();
    endval = POPR();

    low = (ucell) startval;
    startval += increment;

    PC += sizeof(cell);

    if (increment >= 0) {
        high = (ucell) startval;
    } else {
        high = low;
        low = (ucell) startval;
    }

    if (endval - (low + 1) >= high - low) {
        offset = read_cell(cell2pointer(PC));
        PC += offset;

        PUSHR(endval);
        PUSHR(startval);
    }
}
Example #2
0
 void write_cell_data(Index_t row, Index_t column, Stream_out_visitor &stream_out_visitor) const {
   Cell_contents_t cell_contents;
   read_cell(row, column, cell_contents);
   try {
     boost::apply_visitor(stream_out_visitor, cell_contents);
   } catch(...) {
     // TODO: exception policy
   }
 }
Example #3
0
static void docbranch(void)
{                               /* conditional branch */
    PC += sizeof(cell);
    if (POP()) {
        dbg_internal_printk("  ?branch: end loop\n");
    } else {
        dbg_internal_printk("  ?branch: follow branch\n");
        PC += read_cell(cell2pointer(PC));
    }
}
/*!
 * Update the counters of the neighbours cells
 * From a single cell
 *
 * \param x The x position of the cell
 * \param y The y position of the cell
 * \param dx The x translation
 * \param dy The y translation
 * \param *world The world in which we'll read
 * \param *nn The pointer where to write the number of living neighbours
 * \param *n1 The pointer where to write the number of living neighbours of 'x' type
 * \param *n2 The pointer where to write the number of living neighbours of 'o' type
 */
void update(int x, int y, int dx, int dy, unsigned int *world, int *nn, int *n1, int *n2) {
	
	// Get the value of the cell
	unsigned int cell = read_cell(x, y, dx, dy, world);

	// In a living cell
	if (cell != 0) {
		(*nn)++;
		if (cell == 1) (*n1)++;  // 'x' type
		else (*n2)++;  // 'o' type
	}
}
Example #5
0
rc_t read_cells( const VCursor *my_cursor, int64_t row_id,
                 col *columns, const char **names, uint32_t n_columns )
{
    rc_t rc = 0;
    uint32_t idx;

    for ( idx = 0; idx < n_columns && rc == 0; ++idx )
    {
        rc = read_cell( my_cursor, row_id, &columns[ idx ], names[ idx ] );
    }
    return rc;
}
Example #6
0
void bb_create_board_from_string(const char *str, bb_board **b, bb_pawn_state ps)
{
	bb_board *board;
	long width, height, i, j;
	char *cur;
	
	width = strtol(str, &cur, 0);
	height = strtol(cur, &cur, 0);
	
	if ((width < 1) || (height < 1) || (width > BB_MAX_DIMENSION) || (height > BB_MAX_DIMENSION)) {
		*b = NULL;
		return;
	}
	
	board = bb_board_alloc(width, height);
	if (board == NULL) {
		*b = NULL;
		return;
	}
	bb_init_pawn_state(ps);
	
	cur = skip_whitespace(cur);
	
	for (i = 0; i < height; i++) {
		for (j = 0; j < width; j++) {	
			bb_bool success;
			bb_pawn pawn;
			bb_cell *cell = bb_get_cell(board, i, j);
			
			pawn = 0;
			cur = read_cell(cur, cell, &success, &pawn);
						
			if (!success) {
				bb_board_dealloc(board);
				*b = NULL;
				return;
			}
			
			/* Make sure we record where the pawn is */
			if (pawn != 0) {
				ps[pawn - 1].row = i;
				ps[pawn - 1].col = j;
			}
		}
	}
	
	*b = board;
}
Example #7
0
static void doisdo(void)
{
    cell startval, endval, offset;

    startval = POP();
    endval = POP();

    PC += sizeof(cell);

    if (startval == endval) {
        offset = read_cell(cell2pointer(PC));
        PC += offset;
    } else {
        PUSHR(endval);
        PUSHR(startval);
    }
}
Example #8
0
static void doloop(void)
{
    cell offset, startval, endval;

    startval = POPR() + 1;
    endval = POPR();

    PC += sizeof(cell);

    if (startval < endval) {
        offset = read_cell(cell2pointer(PC));
        PC += offset;
        PUSHR(endval);
        PUSHR(startval);
    }

}
Example #9
0
void scroll()
{
  u32 r, c, pos;
  char buffer[FB_NUM_TOTAL];
  for(r=1; r<FB_NUM_ROWS; r++) {
    for(c=0; c<FB_NUM_COLS; c++) {
      pos = (r * FB_NUM_COLS + c);
      buffer[pos - FB_NUM_COLS] = read_cell(r, c);
    }
  }

  for(c=FB_NUM_TOTAL-FB_NUM_COLS; c<FB_NUM_TOTAL; c++) {
    buffer[c] = NULL_CHAR;
  }

  cursor_pos = 0;
  for(pos=0; pos<FB_NUM_TOTAL; pos++) {
    write_at(pos, buffer[pos]);
  }
  cursor_pos = FB_NUM_TOTAL - FB_NUM_COLS;
}
Example #10
0
ucell findxtfromcell(ucell incell)
{
	ucell usesvocab = findword("vocabularies?") + sizeof(cell);
	unsigned int i;

	if (read_ucell(cell2pointer(usesvocab))) {
		/* Vocabularies are in use, so search each one in turn */
		ucell numvocabs = findword("#order") + sizeof(cell);

		for (i = 0; i < read_ucell(cell2pointer(numvocabs)); i++) {
			ucell vocabs = findword("vocabularies") + 2 * sizeof(cell);
			ucell semis = findxtfromcell_wordlist(incell, read_cell(cell2pointer(vocabs + (i * sizeof(cell))))); 	

			/* If we get a non-zero result, we found the xt in this vocab */
			if (semis)
				return semis;
		}
	} else { 
		/* Vocabularies not in use */
		return findxtfromcell_wordlist(incell, read_ucell(last));
	}

	return 0;
}
Example #11
0
/***********************************************************************
 * Read a universe from 'filename'.
 *
 * We're reading photon ascii. So the basic algorithm is to read
 * 'Photon Ascii Instances' and then switch on the type and read the fields.
 * Ignore unknown instances.
 *
 * RETURNS:
 *	On Success, a universe object is returned.
 *	On Failure, NULL is returned and errbuf contains a error message.
 *
 */
UNIVERSE *Universe_ReadAscii(const char *filename, char *errbuf)
{
	PHASCII_FILE phf;
	PHASCII_INSTANCE pi;
	char errmsg[1000];
	int success;
	UNIVERSE *u;

	ASSERT( filename != NULL );
	ASSERT( errbuf != NULL );

	phf = Phascii_Open(filename, "r");
	if( phf == NULL ) {
		strcpy(errbuf, Phascii_GetError());
		return NULL;
	}

	u = NULL;

	while( pi = Phascii_GetInstance(phf) ) {

		if( Phascii_IsInstance(pi, "ORGANIC") ) {
			success = read_organic(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "BARRIER") ) {
			success = read_barrier(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "ER") ) {
			success = read_er(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "KFMO") ) {
			success = read_kfmo(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "KEYLIST") ) {
			success = read_keylist(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "SPORE") ) {
			success = read_spore(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "CELL") ) {
			success = read_cell(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "ORGANISM") ) {
			success = read_organism(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "PLAYER") ) {
			success = read_player(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "UNIVERSE") ) {
			success = read_universe(pi, &u, errmsg);

		} else {
			success = 1;
		}

		Phascii_FreeInstance(pi);

		if( ! success ) {
			sprintf(errbuf, "%s", errmsg);
			Phascii_Close(phf);
			return NULL;
		}
	}

	if( ! Phascii_Eof(phf) ) {
		sprintf(errbuf, "%s\n", Phascii_Error(phf));
		Phascii_Close(phf);
		return NULL;
	}

	Phascii_Close(phf);

	if( u == NULL ) {
		sprintf(errbuf, "%s: No UNIVERSE instance", filename);
		return NULL;
	}

	return u;
}
Example #12
0
static bool read_data(int dataset, VarInfo6& info)
{
    bool bRet = false;

    char* ctype = getScilabTypeFromDataSet6(dataset);
    std::string type(ctype);
    FREE(ctype);
    info.ctype = type;

    if (type == g_SCILAB_CLASS_DOUBLE)
    {
        info.type = sci_matrix;
        return read_double(dataset, info);
    }

    if (type == g_SCILAB_CLASS_STRING)
    {
        info.type = sci_strings;
        return read_string(dataset, info);
    }

    if (type == g_SCILAB_CLASS_LIST)
    {
        info.type = sci_list;
        return read_list(dataset, info, "list");
    }

    if (type == g_SCILAB_CLASS_TLIST)
    {
        info.type = sci_tlist;
        return read_list(dataset, info, "tlist");
    }

    if (type == g_SCILAB_CLASS_MLIST)
    {
        info.type = sci_mlist;
        return read_list(dataset, info, "mlist");
    }

    if (type == g_SCILAB_CLASS_BOOLEAN)
    {
        info.type = sci_boolean;
        return read_boolean(dataset, info);
    }

    if (type == g_SCILAB_CLASS_POLY)
    {
        info.type = sci_poly;
        return read_poly(dataset, info);
    }

    if (type == g_SCILAB_CLASS_INT)
    {
        info.type = sci_ints;
        return read_integer(dataset, info);
    }

    if (type == g_SCILAB_CLASS_SPARSE)
    {
        info.type = sci_sparse;
        return read_sparse(dataset, info);
    }

    if (type == g_SCILAB_CLASS_BSPARSE)
    {
        info.type = sci_boolean_sparse;
        return read_boolean_sparse(dataset, info);
    }

    if (type == g_SCILAB_CLASS_VOID)
    {
        info.type = sci_void;
        return read_void(dataset, info);
    }

    if (type == g_SCILAB_CLASS_UNDEFINED)
    {
        info.type = sci_undefined;
        return read_undefined(dataset, info);
    }

    if (type == g_SCILAB_CLASS_STRUCT)
    {
        info.type = sci_mlist;
        return read_struct(dataset, info);
    }

    if (type == g_SCILAB_CLASS_CELL)
    {
        info.type = sci_mlist;
        return read_cell(dataset, info);
    }

    if (type == g_SCILAB_CLASS_HANDLE)
    {
        info.type = sci_handles;
        return read_handles(dataset, info);
    }

    if (type == g_SCILAB_CLASS_MACRO)
    {
        info.type = sci_c_function;
        return read_macro(dataset, info);
    }

    Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5");
    return false;
}
Example #13
0
int main(int argc, char *argv[])
{
    int r, c;
    DCELL con1, con2;
    double d1, d2;
    DCELL *alt_row;
    const char *con_name, *alt_name;
    int file_fd;
    DCELL value;
    struct History history;
    struct GModule *module;
    struct Option *opt1, *opt2;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("surface"));
    G_add_keyword(_("interpolation"));
    module->description =
	_("Generates surface raster map from rasterized contours.");

    opt1 = G_define_standard_option(G_OPT_R_INPUT);
    opt1->description = _("Name of input raster map containing contours");

    opt2 = G_define_standard_option(G_OPT_R_OUTPUT);

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);
    
    con_name = opt1->answer;
    alt_name = opt2->answer;

    nrows = Rast_window_rows();
    ncols = Rast_window_cols();
    i_val_l_f = nrows + ncols;
    con = read_cell(con_name);
    alt_row = (DCELL *) G_malloc(ncols * sizeof(DCELL));
    seen = flag_create(nrows, ncols);
    mask = flag_create(nrows, ncols);
    if (NULL != G_find_file("cell", "MASK", G_mapset())) {
	file_fd = Rast_open_old("MASK", G_mapset());
	for (r = 0; r < nrows; r++) {
	    Rast_get_d_row_nomask(file_fd, alt_row, r);
	    for (c = 0; c < ncols; c++)
		if (Rast_is_d_null_value(&(alt_row[c])) || alt_row[c] == 0)
		    FLAG_SET(mask, r, c);
	}
	Rast_close(file_fd);
    }
    zero = (NODE *) G_malloc(INIT_AR * sizeof(NODE));
    minc = minr = 0;
    maxc = ncols - 1;
    maxr = nrows - 1;
    array_size = INIT_AR;
    file_fd = Rast_open_new(alt_name, DCELL_TYPE);
    for (r = 0; r < nrows; r++) {
	G_percent(r, nrows, 1);
	Rast_set_d_null_value(alt_row, ncols);
	for (c = 0; c < ncols; c++) {
	    if (FLAG_GET(mask, r, c))
		continue;
	    value = con[r][c];
	    if (!Rast_is_d_null_value(&value)) {
		alt_row[c] = value;
		continue;
	    }
	    find_con(r, c, &d1, &d2, &con1, &con2);
	    if (!Rast_is_d_null_value(&con2))
		alt_row[c] = d2 * con1 / (d1 + d2) + 
		             d1 * con2 / (d1 + d2);
	    else
		alt_row[c] = con1;
	}
	Rast_put_row(file_fd, alt_row, DCELL_TYPE);
    }
    G_percent(1, 1, 1);
    
    free_cell(con);
    flag_destroy(seen);
    flag_destroy(mask);
    Rast_close(file_fd);
    
    Rast_short_history(alt_name, "raster", &history);
    Rast_command_history(&history);
    Rast_write_history(alt_name, &history);

    exit(EXIT_SUCCESS);
}
Example #14
0
int main(int argc, char *argv[])
{
    int fd, maskfd;
    CELL *cell, *mask;
    struct Cell_head window;
    int row, col;
    double north, east;
    double dx, dy;
    double maxdist, dist;
    double sum1, sum2;
    int i, n, max;
    struct GModule *module;
    struct History history;
    struct
    {
	struct Option *input, *npoints, *output;
    } parm;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("surface"));
    G_add_keyword(_("interpolation"));
    G_add_keyword(_("IDW"));
    module->description = _("Surface generation program.");

    parm.input = G_define_standard_option(G_OPT_R_INPUT);

    parm.output = G_define_standard_option(G_OPT_R_OUTPUT);

    parm.npoints = G_define_option();
    parm.npoints->key = "npoints";
    parm.npoints->key_desc = "count";
    parm.npoints->type = TYPE_INTEGER;
    parm.npoints->required = NO;
    parm.npoints->description = _("Number of interpolation points");
    parm.npoints->answer = "12";

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    /* Make sure that the current projection is not lat/long */
    if ((G_projection() == PROJECTION_LL))
	G_fatal_error(_("Lat/long databases not supported by r.surf.idw2. Use r.surf.idw instead!"));

    if (sscanf(parm.npoints->answer, "%d", &search_points) != 1 ||
	search_points < 1)
	G_fatal_error(_("%s=%s - illegal number of interpolation points"),
		      parm.npoints->key, parm.npoints->answer);

    list = (struct Point *)G_calloc(search_points, sizeof(struct Point));

    /* read the elevation points from the input raster map */
    read_cell(parm.input->answer);

    if (npoints == 0)
	G_fatal_error(_("%s: no data points found"), G_program_name());
    nsearch = npoints < search_points ? npoints : search_points;

    /* get the window, allocate buffers, etc. */
    G_get_set_window(&window);

    cell = Rast_allocate_c_buf();

    if ((maskfd = Rast_maskfd()) >= 0)
	mask = Rast_allocate_c_buf();
    else
	mask = NULL;

    fd = Rast_open_c_new(parm.output->answer);

    G_message(_("Interpolating raster map <%s>... %d rows... "),
	      parm.output->answer, window.rows);

    north = window.north - window.ns_res / 2.0;
    for (row = 0; row < window.rows; row++) {
	G_percent(row, window.rows, 2);

	if (mask)
	    Rast_get_c_row(maskfd, mask, row);

	north += window.ns_res;
	east = window.west - window.ew_res / 2.0;
	for (col = 0; col < window.cols; col++) {
	    east += window.ew_res;
	    /* don't interpolate outside of the mask */
	    if (mask && mask[col] == 0) {
		cell[col] = 0;
		continue;
	    }
	    /* fill list with first nsearch points */
	    for (i = 0; i < nsearch; i++) {
		dy = points[i].north - north;
		dx = points[i].east - east;
		list[i].dist = dy * dy + dx * dx;
		list[i].z = points[i].z;
	    }
	    /* find the maximum distance */
	    maxdist = list[max = 0].dist;
	    for (n = 1; n < nsearch; n++) {
		if (maxdist < list[n].dist)
		    maxdist = list[max = n].dist;
	    }
	    /* go thru rest of the points now */
	    for (; i < npoints; i++) {
		dy = points[i].north - north;
		dx = points[i].east - east;
		dist = dy * dy + dx * dx;

		if (dist < maxdist) {
		    /* replace the largest dist */
		    list[max].z = points[i].z;
		    list[max].dist = dist;
		    maxdist = list[max = 0].dist;
		    for (n = 1; n < nsearch; n++) {
			if (maxdist < list[n].dist)
			    maxdist = list[max = n].dist;
		    }
		}
	    }

	    /* interpolate */
	    sum1 = 0.0;
	    sum2 = 0.0;
	    for (n = 0; n < nsearch; n++) {
		if ((dist = list[n].dist)) {
		    sum1 += list[n].z / dist;
		    sum2 += 1.0 / dist;
		}
		else {
		    sum1 = list[n].z;
		    sum2 = 1.0;
		    break;
		}
	    }
	    cell[col] = (CELL) (sum1 / sum2 + 0.5);
	}

	Rast_put_row(fd, cell, CELL_TYPE);
    }

    G_free(points);
    G_free(cell);
    Rast_close(fd);

    /* writing history file */
    Rast_short_history(parm.output->answer, "raster", &history);
    Rast_command_history(&history);
    Rast_write_history(parm.output->answer, &history);
    G_done_msg(" ");

    exit(EXIT_SUCCESS);
}
Example #15
0
static void bin_to_raster3d(char *null, int map_type, int is_integer,
		int is_signed, int bytes, int byte_swap, int row_swap, int depth_swap) {
	int x, y, z;
	int col, row, depth;
	DCELL value;
	FCELL fvalue;
	DCELL null_value;
	int tileX, tileY, tileZ;

	if (null)
		null_value = atof(null);

	Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
	Rast3d_min_unlocked(map, RASTER3D_USE_CACHE_X);

	Rast3d_autolock_on(map);
	Rast3d_unlock_all(map);
	G_message(_("Loading %s data with %i  bytes ...  (%dx%dx%d)"),
			(is_integer? "integer":"floating point "), bytes, region.cols,
			region.rows, region.depths);

	for (z = 0; z < region.depths; z++) {
		G_percent(z, region.depths, 1);

		if ((z % tileZ) == 0)
			Rast3d_unlock_all(map);

		for (y = 0; y < region.rows; y++) {/* go south to north */
			for (x = 0; x < region.cols; x++) {

				/* From west to east */
				col = x;
				/* The default is to read rows from north to south */
				row = y;
				/* From bottom to the top */
				depth = z;

				/* Read rows as from south to north */
				if (row_swap)
					row = region.rows - y - 1;

				/* Read XY layer from top to bottom */
				if (depth_swap)
					depth = region.depths - z - 1;

				/* Read value from binary file */
				read_cell(&value, is_integer, is_signed, bytes, byte_swap);

				/* Write value to the 3D raster map */
				if (map_type == DCELL_TYPE) {
					if (null && value == null_value)
						Rast3d_set_null_value(&value, 1, DCELL_TYPE);
					Rast3d_put_double(map, col, row, depth, value);
				} else {
					fvalue = (FCELL) value;
					if (null && value == null_value)
						Rast3d_set_null_value(&fvalue, 1, FCELL_TYPE);
					Rast3d_put_double(map, col, row, depth, fvalue);

				}
			}
		}
	}

	if (!Rast3d_flush_all_tiles(map))
		G_fatal_error(_("Error flushing tiles"));

	Rast3d_autolock_off(map);
	Rast3d_unlock_all(map);

	G_percent(1, 1, 1);
}
Example #16
0
static void dobranch(void)
{                               /* unconditional branch */
    PC += sizeof(cell);
    PC += read_cell(cell2pointer(PC));
}
Example #17
0
static void plusstore(void)
{
	const ucell *aaddr = (ucell *)cell2pointer(POP());
	const cell nu = POP();
	write_cell(aaddr,read_cell(aaddr)+nu);
}