Beispiel #1
0
int
boxcheck(int *board)
{
	int i,j,d,sum,last,last2;

	for (i = 0; i < 9; i++) {
		for (d = 0;d < 9; d++) {
			sum=0;
			last=-1;
			last2=-1;
			for (j = 0; j < 9; j++) {
				if (board[boxind[i][j]] & allowbits[d]) {
					sum++;
					last2=last;
					last=boxind[i][j];
				} else
					sum += ((board[boxind[i][j]] & Solve)==(d << 4)) ? 1: 0;
			}
			if (sum==0) 
				return(0);
			if ((sum==1)&&(last>=0))
				if (!setallowed(board,last,d)) 
					return(0);

			if((sum == 2) && (last >= 0) && ( last2 >= 0) && 
					(getrow(last) == getrow(last2))) {
				for (j = 0; j < 9; j++) {
					int c = rowind[getrow(last)][j];
					if ((c != last)&&(c != last2)) {
						if (board[c] & allowbits[d]) {
							board[c] &= ~allowbits[d];
							if ((board[c] & Allow)==0) 
								return(0);
						}
					}
				}
			}
			if((sum == 2) && (last >= 0) && (last2 >= 0) &&
					(getcol(last) == getcol(last2))) {
				for (j = 0;j  <9;j++) {
					int c = colind[getcol(last)][j];
					if ((c != last) && (c != last2)) {
						if (board[c] & allowbits[d]) {
							board[c] &= ~allowbits[d];
							if ((board[c] & Allow) == 0) 
								return(0);
						}
					}
				}
			}
		}
	}
	return(1);
}
Beispiel #2
0
static int find_rlen(int pos, int plen) 
{
	int col;
	int pos0;
	
	col = getcol(pos);
	pos0 = pos;

	while(getcol(pos) == col && pos < plen)
		pos ++;
	
	return pos-pos0;
}
Beispiel #3
0
int main()
{
	int n = 23;
	int lda = 30;
	int nth = 3;
	double* a = (double*)malloc(sizeof(double)*lda*n);
	double* a2 = (double*)malloc(sizeof(double)*lda*n);
	double** bb = (double**)malloc(sizeof(double*)*nth);
	double* b = 0;
	size_t bsz = address_tile_buf(bb, b, n, nth);
	b = (double*)malloc(sizeof(double)*(bsz));
	address_tile_buf(bb, b, n, nth);

	for(int i=0; i<n; ++i)
		for(int j=0; j<=i; ++j) a[i*lda+j] = (int)((double)std::rand()/RAND_MAX*100);
	std::printf("from:\n");
	for(int i=0; i<n; ++i){
		std::printf("   ");
		for(int j=0; j<=i; ++j) std::printf(" %3d", (int)a[i*lda+j]);
		std::printf("\n");
	}
	for(int id=0; id<nth; ++id)
		convert_to_tile(n, a, lda, bb, id, nth);
	for(int i=0; i<n; ++i)
		getcol(i, a2+i*lda, bb, nth);
	std::printf("\n\nto:\n");
	for(int i=0; i<n; ++i){
		std::printf("   ");
		for(int j=0; j<=i; ++j) std::printf(" %3d", (int)a2[i*lda+j]);
		std::printf("\n");
	}
	free(b); free(bb); free(a2); free(a);
	return 0;
}
void work()
{
	// convert from rgb to lab
	for(int i = 0; i < n; ++i)
	{
		rgb2lab(getcol(img, i/h, i%h), ori[i]);
		res[i] = delta[i] = 0;
	}

	// calculate delta
	HANDLE thd[8];
	now = 0;
	for(int i = 0; i < 8; ++i)
		thd[i] = CreateThread(0, 0, calcDelta, 0, 0, 0);
	for(int i = 0; i < 8; ++i)
		WaitForSingleObject(thd[i], INFINITE);
	// calculate result
	for(int i = 1; i < n; ++i)
		res[i] = ( delta[i] - delta[i-1] + n * res[i-1]) / n;
	double sum = 0;
	for(int i = 0; i < n; i++) 
		sum += res[i] - ori[i][0];
	sum /= n;
	for(int i = 0; i < n; i++)
		res[i] = res[i] - sum;

	// output img
	for(int i = 0; i < n; ++i)
	{
		imgRes.at<uchar>(Point(i/h, i%h)) = lab2rgb(res[i]);
	}
}
Beispiel #5
0
int fitstable_add_fits_columns_as_struct3(const fitstable_t* intab,
					  fitstable_t* outtab,
					  const sl* colnames,
					  int c_offset) {
	int i, NC;
	int noc = ncols(outtab);
	NC = sl_size(colnames);
	for (i=0; i<NC; i++) {
		const qfits_col* qcol;
		fitscol_t* col;
		const char* name = sl_get_const(colnames, i);
		int j = fits_find_column(intab->table, name);
		int off;
		if (j == -1) {
			ERROR("Failed to find FITS column \"%s\"", name);
			return -1;
		}
		qcol = qfits_table_get_col(intab->table, j);
		// We give the offset of the column in the *input* table, so that
		// the resulting "outtab" can handle raw data from the "intab".
		off = fits_offset_of_column(intab->table, j);
		fitstable_add_read_column_struct(outtab, qcol->atom_type, qcol->atom_nb,
						 c_offset + off, qcol->atom_type, qcol->tlabel, TRUE);
		// set the FITS column number.
		col = getcol(outtab, ncols(outtab)-1);
		col->col = noc + i;
	}
	return 0;
}
Beispiel #6
0
/*
 * is_unique: return 1 if grid (r, c) not empty and
 * grid (r, c)'s number is unique among line r, col c and
 * the corresponding box. 0 if not.
 */
int is_unique(int r, int c, int puzzle[][9])
{
	int i, flag[9];

	// make sure (r,c) not empty!
	if (!is_filled(puzzle, r, c))
		return 0;
	for (i=0; i<9; i++)
		flag[i] = 0;
	
	i = puzzle[r-1][c-1];
	puzzle[r-1][c-1] = 0;
	getbox(puzzle, r, c);
	getrow(puzzle, r, c);
	getcol(puzzle, r, c);
	puzzle[r-1][c-1] = i;
	
	flag[puzzle[r-1][c-1] - 1] = 1;
	for (i=0; i<9; i++) {
		if (box[i] >= 1 && box[i] <= 9)
			flag[box[i]-1]++;
		if (row[i] >= 1 && row[i] <= 9)
			flag[row[i]-1]++;
		if (col[i] >= 1 && col[i] <= 9)
			flag[col[i]-1]++;
	}

	for (i=0; i<9; i++)
		if (flag[i] > 1)
			return 0;
	return 1;
}
Beispiel #7
0
int fitstable_write_one_column(fitstable_t* table, int colnum,
                               int rowoffset, int nrows,
                               const void* src, int src_stride) {
	anbool flip = TRUE;
    off_t foffset = 0;
    off_t start = 0;
    int i;
    char* buf = NULL;
    fitscol_t* col;
	int off;

	off = offset_of_column(table, colnum);
	if (!in_memory(table)) {
		foffset = ftello(table->fid);
		// jump to row start...
		start = get_row_offset(table, rowoffset) + off;
		if (fseeko(table->fid, start, SEEK_SET)) {
			SYSERROR("Failed to fseeko() to the start of the file.");
			return -1;
		}
	}

    col = getcol(table, colnum);
    if (col->fitstype != col->ctype) {
		int sz = col->fitssize * col->arraysize * nrows;
        buf = malloc(sz);
        fits_convert_data(buf, col->fitssize * col->arraysize, col->fitstype,
                          src, src_stride, col->ctype,
                          col->arraysize, nrows);
        src = buf;
        src_stride = col->fitssize * col->arraysize;
    }

	if (in_memory(table)) {
		for (i=0; i<nrows; i++) {
			memcpy(((char*)bl_access(table->rows, rowoffset + i)) + off,
				   src, col->fitssize * col->arraysize);
			src = ((const char*)src) + src_stride;
		}
	} else {
		for (i=0; i<nrows; i++) {
			if (fseeko(table->fid, start + i * table->table->tab_w, SEEK_SET) ||
				fits_write_data_array(table->fid, src, col->fitstype, col->arraysize, flip)) {
				SYSERROR("Failed to write row %i of column %i", rowoffset+i, colnum);
				return -1;
			}
			src = ((const char*)src) + src_stride;
		}
	}
    free(buf);

	if (!in_memory(table)) {
		if (fseeko(table->fid, foffset, SEEK_SET)) {
			SYSERROR("Failed to restore file offset.");
			return -1;
		}
	}
    return 0;
}
Beispiel #8
0
void video_backspace(){
    vidmem=(char *)MAIN_SCREEN_ADDRESS;
    if(maxpos>0){
        vidmem[--writepos]=WHITE_TXT;
        vidmem[--writepos]=' ';
    }
    set_cursor(getrow(),getcol());
}
Beispiel #9
0
static void
show_selection_position(int yanked)
{
#ifdef WMDTERSELECT
    if (!w_val(curwp, WMDTERSELECT)) {
	mlwrite("(%d,%d) thru (%d,%d) %s",
		line_no(selbufp, selregion.ar_region.r_orig.l),
		getcol(selregion.ar_region.r_orig, FALSE) + 1,
		line_no(selbufp, selregion.ar_region.r_end.l),
		getcol(selregion.ar_region.r_end, FALSE),
		yanked ? "yanked" : "selected");

    }
#endif /* WMDTERSELECT */
    show_mark_is_set('<');
    show_mark_is_set('>');
}
Beispiel #10
0
int
getbox(int cell)
{
	int row = getrow(cell);
	int col = getcol(cell);

	return 3*(row/3)+ col/3;
}
Beispiel #11
0
void fitstable_print_columns(fitstable_t* tab) {
	int i;
	printf("Table columns:\n");
	for (i=0; i<ncols(tab); i++) {
		fitscol_t* col = getcol(tab, i);
		printf("  %i: %s: fits type %i, C type %i, arraysize %i, fitssize %i, C size %i, C offset %i (if in a struct), FITS column num: %i\n",
			   i, col->colname, col->fitstype, col->ctype, col->arraysize, col->fitssize, col->csize, col->coffset, col->col);
	}
}
Beispiel #12
0
void fitstable_clear_table(fitstable_t* tab) {
    int i;
    for (i=0; i<ncols(tab); i++) {
        fitscol_t* col = getcol(tab, i);
        free(col->colname);
        free(col->units);
    }
    bl_remove_all(tab->cols);
}
Beispiel #13
0
void make_P(double ** U, int NT, double * Press){
  Press[0] = 1.;
  int i;for(i=1;i<NT-1;++i){
    double Ui[3]; getcol(U, i, Ui);
    Press[i] = Pressure(Ui);
    //printf("Ui_%d %f  %f P=%f\n", i, Ui[0], Ui[1], Press[i]);
  }
  Press[NT] = 0.1;
  //printf("%f\n", Press[NT]);
}
void EffectsExporter::writeBlinn(COLLADASW::EffectProfile &ep, Material *ma)
{
	COLLADASW::ColorOrTexture cot;
	ep.setShaderType(COLLADASW::EffectProfile::BLINN);
	// shininess
	ep.setShininess(ma->har, false, "shininess");
	// specular
	cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
	ep.setSpecular(cot, false, "specular");
}
Beispiel #15
0
void fitstable_print_missing(fitstable_t* tab, FILE* f) {
    int i;
    fprintf(f, "Missing required columns: ");
    for (i=0; i<ncols(tab); i++) {
        fitscol_t* col = getcol(tab, i);
        if (col->col == -1 && col->required) {
            fprintf(f, "%s ", col->colname);
        }
    }
}
Beispiel #16
0
void fitstable_add_fits_columns_as_struct(fitstable_t* tab) {
	int i;
	int off = 0;
	for (i=0; i<tab->table->nc; i++) {
		qfits_col* qcol = tab->table->col + i;
		fitscol_t* col;
		/*
		 if (qcol->atom_type == TFITS_BIN_TYPE_X) {
		 }
		 */
		fitstable_add_read_column_struct(tab, qcol->atom_type, qcol->atom_nb,
										 off, qcol->atom_type, qcol->tlabel, TRUE);
		// set the FITS column number.
		col = getcol(tab, ncols(tab)-1);
		col->col = i;

		off += fitscolumn_get_size(getcol(tab, ncols(tab)-1));
	}
}
Beispiel #17
0
void fitstable_copy_columns(const fitstable_t* src, fitstable_t* dest) {
	int i;
	for (i=0; i<ncols(src); i++) {
		fitscol_t* col = getcol(src, i);
		fitscol_t* newcol = fitstable_add_column(dest, col);
		// fix string fields...
		newcol->colname = strdup_safe(newcol->colname);
		newcol->units   = strdup_safe(newcol->units);
	}
}
Beispiel #18
0
void make_F(double ** U, double ** F, double **alpha, int NT, double * P){
  double alphas[2];
  F[0][0] = 0.; F[1][0] = 1.; F[2][0] = 0.;
  int i,j; for(i=1;i<NT;++i){
    double Ui[3], Uimo[3]; getcol(U, i, Ui); getcol(U, i-1, Uimo);
    double Fimh[3]; Fi_mh(Ui, Uimo, Fimh, alphas, P[i], P[i-1]);
    for(j=0;j<2;++j){
      if(i>0 && i<NT){
	alpha[j][i-1]=alphas[j];
      }
      //printf("alphas %f   %f\n", alpha[j][i], alphas[j]); 
    }
    for(j=0;j<3;++j){
      if(i>0 && i<NT){
      F[j][i] = Fimh[j];
      }      
    }
    // printf("Fi_%d = %f  %f  %f\n",i, F[0][i],F[1][i],F[2][i]);
  }
}
Beispiel #19
0
static int offset_of_column(const fitstable_t* table, int colnum) {
	int i;
	int offset = 0;
	assert(colnum <= ncols(table));
	for (i=0; i<colnum; i++) {
		fitscol_t* col;
		col = getcol(table, i);
		offset += fitscolumn_get_size(col);
	}
	return offset;
}
Beispiel #20
0
int
setallowed(int *board, int cc, int num)
{
	int j, d;
	int row, col, box;

	board[cc] &= ~Allow;
	board[cc] = (board[cc] & ~Solve) | (num << 4);

	row = getrow(cc);
	for (j = 0; j < 9; j++) {
		if (board[rowind[row][j]] & allowbits[num]) {
			board[rowind[row][j]] &= ~allowbits[num];
			if ((board[rowind[row][j]] & Allow) == 0) 
				return(0);
		}
	}

	col = getcol(cc);
	for (j = 0; j < 9; j++) {
		if (board[colind[col][j]] & allowbits[num]) {
			board[colind[col][j]] &= ~allowbits[num];
			if ((board[colind[col][j]] & Allow) == 0) 
				return(0);
		}
	}

	box = getbox(cc);
	for (j = 0;j < 9;j++) {
		if (board[boxind[box][j]] & allowbits[num]) {
			board[boxind[box][j]] &= ~allowbits[num];
			if ((board[boxind[box][j]] & Allow)==0) 
				return(0);
		}
	}

	for (j = 0;j < 81; j++)
		for (d = 0; d < 9; d++)
			if ((board[j] & Allow) == allowbits[d])
				if (!setallowed(board, j, d)) 
					return(0);

	if (!boxcheck(board)||!rowcheck(board)||!colcheck(board))
		return(0);

	for (j = 0; j < 81; j++)
		for (d = 0; d < 9; d++)
			if ((board[j] & Allow) == allowbits[d])
				if (!setallowed(board, j, d)) 
					return(0);

	return(1);
}
Beispiel #21
0
void make_F(double ** U, double ** F, double **alpha, int NT, double * P){
  double alphas[2];

  int i,j; for(i=1;i<NT;++i){
    double Ui[3], Uimo[3]; getcol(U, i, Ui); getcol(U, i-1, Uimo);
    double Fimh[3]; Fi_mh(Ui, Uimo, Fimh, alphas, P[i], P[i-1]);
    for(j=0;j<2;++j){
      if(i>0 && i<NT-1){
	alpha[j][i-1]=alphas[j];
      }
    }
    for(j=0;j<3;++j){
      if(i>0 && i<NT){
      F[j][i] = Fimh[j];
      }      
    }
  }
  for(j=0;j<3;++j){
    F[j][0] = F[j][NT-1];
    F[j][NT] = F[j][1];
  }
}
Beispiel #22
0
int fitstable_remove_column(fitstable_t* tab, const char* name) {
    int i;
    for (i=0; i<ncols(tab); i++) {
        fitscol_t* col = getcol(tab, i);
        if (strcasecmp(name, col->colname) == 0) {
			free(col->colname);
			free(col->units);
            bl_remove_index(tab->cols, i);
            return 0;
        }
    }
    return -1;
}
Beispiel #23
0
int fitstable_close(fitstable_t* tab) {
    int i;
    int rtn = 0;
    if (!tab) return 0;
	if (is_writing(tab)) {
        if (fclose(tab->fid)) {
            SYSERROR("Failed to close output file %s", tab->fn);
            rtn = -1;
        }
    }
	if (tab->anq) {
		anqfits_close(tab->anq);
	}
	if (tab->readfid) {
		fclose(tab->readfid);
	}
    if (tab->primheader)
        qfits_header_destroy(tab->primheader);
    if (tab->header)
        qfits_header_destroy(tab->header);
    if (tab->table)
        qfits_table_close(tab->table);
    free(tab->fn);
    for (i=0; i<ncols(tab); i++) {
        fitscol_t* col = getcol(tab, i);
        free(col->colname);
        free(col->units);
    }
    bl_free(tab->cols);
    if (tab->br) {
        buffered_read_free(tab->br);
        free(tab->br);
    }
	if (tab->rows) {
		bl_free(tab->rows);
	}
	if (tab->extensions) {
		for (i=0; i<bl_size(tab->extensions); i++) {
			fitsext_t* ext = bl_access(tab->extensions, i);
			if (ext->rows != tab->rows)
				bl_free(ext->rows);
			if (ext->header != tab->header)
				qfits_header_destroy(ext->header);
			if (ext->table != tab->table)
				qfits_table_close(ext->table);
		}
		bl_free(tab->extensions);
	}
    free(tab);
    return rtn;
}
Beispiel #24
0
double Entropy(double ** U, int NT, double dx, double * sumv, double * sump){
  double vsum = 0;
  double psum = 0;
  int i;for(i=1;i<NT-1;++i){
    double Ui[3]; getcol(U, i, Ui);
    double P = Pressure(Ui);
    double V = Velocity(Ui);
    double Pi = Pressurei(Ui[0]);
    double Vi = Velocityi(Ui[0]);
    vsum += dx*fabs(V - Vi);
    psum += dx*fabs(P - Pi);
  }
  *sumv = vsum; *sump = psum;
}
Beispiel #25
0
void fitstable_error_report_missing(fitstable_t* tab) {
    int i;
    sl* missing = sl_new(4);
    char* mstr;
    for (i=0; i<ncols(tab); i++) {
        fitscol_t* col = getcol(tab, i);
        if (col->col == -1 && col->required)
            sl_append(missing, col->colname);
    }
    mstr = sl_join(missing, ", ");
    sl_free2(missing);
    ERROR("Missing required columns: %s", mstr);
    free(mstr);
}
Beispiel #26
0
void fitstable_close_table(fitstable_t* tab) {
    int i;
    if (tab->table) {
        qfits_table_close(tab->table);
        tab->table = NULL;
    }
    for (i=0; i<ncols(tab); i++) {
        fitscol_t* col = getcol(tab, i);
        col->col = -1;
        col->fitssize = 0;
        col->arraysize = 0;
        col->fitstype = fitscolumn_any_type();
    }
}
Beispiel #27
0
void fillsquare(int x,int y,int w,int h) {
//  printf("fs\n");
//  b->setrectangle(indent+x,y,w,h,myrnd()*255);
//  b->writetoscreen();
        if (key[KEY_SPACE])
          exit(0);
  int nwcol=getcol(x,y);
  int necol=getcol(x+w,y);
  int swcol=getcol(x,y+h);
  int secol=getcol(x+w,y+h);
  int cx=x+w/2;
  int cy=y+h/2;
  int ave=(nwcol+necol+swcol+secol)/4;
  int m=max(max(diff(nwcol,ave),diff(necol,ave)),max(diff(swcol,ave),diff(secol,ave)));
  if (m<coldifftol || max(w,h)<=res) {
    b->interpolate(indent+x,y,indent+x+w,y+h,nwcol,necol,swcol,secol);
//    b->writetoscreen();
  } else {
    fillsquare(x,y,w/2,h/2);
    fillsquare(cx,y,w/2,h/2);
    fillsquare(x,cy,w/2,h/2);  
    fillsquare(cx,cy,w/2,h/2);
  }
}
Beispiel #28
0
void fitstable_endian_flip_row_data(fitstable_t* table, void* data) {
	int i;
	char* cursor;
	if (!need_endian_flip())
		return;
	cursor = data;
	for (i=0; i<ncols(table); i++) {
		int j;
		fitscol_t* col = getcol(table, i);
		for (j=0; j<col->arraysize; j++) {
			endian_swap(cursor, col->fitssize);
			cursor += col->fitssize;
		}
	}
}
Beispiel #29
0
void drawcellCB(Widget w, XtPointer client_data, XtPointer calld)
{
    double *datap;
    EditPoints *ep = (EditPoints *) client_data;
    static char buf[128];
    int i, j;
    XbaeMatrixDrawCellCallbackStruct *cs =
    	    (XbaeMatrixDrawCellCallbackStruct *) calld;
    i = cs->row;
    j = cs->column;
    datap = getcol(ep->gno, ep->setno, j);
    sprintf(buf, scformat[(ep->cformat[j])], ep->cprec[j], datap[i]);
    cs->type = XbaeString;
    cs->string = XtNewString(buf);
}
Beispiel #30
0
void EffectsExporter::exportEffects(Scene *sce)
{
	this->scene = sce;

	if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
		if (hasEffects(sce)) {
				MaterialFunctor mf;
				openLibrary();
				mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
				closeLibrary();
		}
	}
	else {
		std::set<Object *> uv_textured_obs = bc_getUVTexturedObjects(sce, !this->export_settings->active_uv_only);
		std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
		if (uv_images.size() > 0) {
			openLibrary();
			std::set<Image *>::iterator uv_images_iter;
			for (uv_images_iter = uv_images.begin();
			     uv_images_iter != uv_images.end();
			     uv_images_iter++)
			{

				Image *ima = *uv_images_iter;
				std::string key(id_name(ima));
				key = translate_id(key);
				COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
					key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
					key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
				sampler.setImageId(key);

				openEffect(key + "-effect");
				COLLADASW::EffectProfile ep(mSW);
				ep.setProfileType(COLLADASW::EffectProfile::COMMON);
				ep.setShaderType(COLLADASW::EffectProfile::PHONG);
				ep.setDiffuse(createTexture(ima, key, &sampler), false, "diffuse");
				COLLADASW::ColorOrTexture cot = getcol(0, 0, 0, 1.0f);
				ep.setSpecular(cot, false, "specular");
				ep.openProfile();
				ep.addProfileElements();
				ep.addExtraTechniques(mSW);
				ep.closeProfile();
				closeEffect();
			}
			closeLibrary();
		}
	}
}