Пример #1
0
bg * fact(long n){
	puts("begin");
	bg * res;
	bg * m;
	res = get_bg(1);
	while(n > 1){
		m = get_bg(n);
		mult_bg(res, m);
		free(m->data); free(m);
		n--;
	}
	puts("done");
	return res;
}
Пример #2
0
void mult_bg(bg *n, bg *m){
	int ms = m->size;
	int ns = n->size;
	int * temp;
	bg * res = get_bg(0);
	int iii, jjj, carry;

	res->size = ms + ns - 1;
	if (res->size >= res->len){
		resize_bg(res, res->size + 1);
	}

	for (iii = 0; iii < ns; ++iii){
		carry = 0;
		for (jjj = 0; jjj < ms; ++jjj){
			res->data[iii + jjj] = res->data[iii + jjj] + carry + n->data[iii]*m->data[jjj];
			carry = res->data[iii + jjj]/10;
			res->data[iii+jjj] = res->data[iii +jjj]%10;
		}
		if (carry > 0){
			res->data[iii + jjj] = carry;
		}
	}
	if (carry > 0){
		res->size++;
	}

	free(n->data);
	n->data = res->data;
	n->size = res->size;
	n->len = res->len;
	free(res);
}
Пример #3
0
// Shift the text several lines up the screen
void VGA_Text_Buffer::scroll(size_t lines, vga_color fill) {
  for (size_t row = 0; row + lines < rows; ++row) {
    for (size_t col = 0; col < cols; ++ col) {
      at(row,col) = at(row+lines,col);
    }
  }

  // Save the color
  vga_color bg = get_bg();
  vga_color fg = get_fg();
  // Make the foreground and background the same color
  set_color(fill,fill);
  for (size_t row = rows > lines ? rows - lines : 0;
       row < rows;
       ++row) {
    for (size_t col = 0; col < cols; ++col) {
      at(row,col) = make_entry(' ');
    }
  }
  // Restore the color
  set_color(fg,bg);
  row = row >= lines ? row - lines : 0;
}
Пример #4
0
void isw_get_beam_properties(ParamCoLoRe *par)
{
  HealpixShells *pd_map=par->pd_map;

#ifdef _HAVE_OMP
#pragma omp parallel default(none)		\
  shared(par,pd_map)
#endif //_HAVE_OMP
  {
    double idx=par->n_grid/par->l_box;

    //Setup radial decomposition
    int i_r,nr;
    double idr,dr;
    get_radial_params(par->r_max,par->n_grid,&nr,&dr);
    idr=1./dr;
  
    //Compute index of each source plane
    int *i_r_max_arr=my_malloc(pd_map->nr*sizeof(int));
    int *i_r_min_arr=my_malloc(pd_map->nr*sizeof(int));
    for(i_r=0;i_r<pd_map->nr;i_r++) {
      int i_r_here=(int)(pd_map->rf[i_r]*idr+0.5);
      i_r_max_arr[i_r]=MIN(i_r_here,nr-1);
    }
    i_r_min_arr[0]=0;
    for(i_r=1;i_r<pd_map->nr;i_r++)
      i_r_min_arr[i_r]=i_r_max_arr[i_r-1]+1;

    //Fill up integral kernels
    double *fac_r=my_malloc(nr*sizeof(double));
    for(i_r=0;i_r<nr;i_r++) {
      double rm=(i_r+0.5)*dr;
      double pdg=get_bg(par,rm,BG_PD,0);
      fac_r[i_r]=2*pdg*dr;
    }

    long ip;
#ifdef _HAVE_OMP
#pragma omp for
#endif //_HAVE_OMP
    for(ip=0;ip<pd_map->num_pix;ip++) {
      int ax,added;
      flouble pd;
      double xn[3];
      double isw=0;
      double *u=&(pd_map->pos[3*ip]);

      for(i_r=0;i_r<pd_map->nr;i_r++) {
	int irr;
	int irmin=i_r_min_arr[i_r];
	int irmax=i_r_max_arr[i_r];
	for(irr=irmin;irr<=irmax;irr++) {
	  double rm=(irr+0.5)*dr;
	  for(ax=0;ax<3;ax++)
	    xn[ax]=(rm*u[ax]+par->pos_obs[ax])*idx;
	  added=interpolate_from_grid(par,xn,NULL,NULL,NULL,&pd,RETURN_PDOT,INTERP_TYPE_SHEAR);
	  if(added)
	    isw+=pd*fac_r[irr];
	}
	pd_map->data[i_r*pd_map->num_pix+ip]+=isw;
      }	
    } //end omp for

    free(fac_r);
    free(i_r_max_arr);
    free(i_r_min_arr);
  } //end omp parallel

  return;
}