示例#1
0
// -----------------------------------------------------------------------
// Is called if the user changed the impedance. -> The reflexion
// coefficient is calculated.
void MatchDialog::slotImpedanceChanged(const QString&)
{
  if(TwoCheck->isChecked())  return;

  double Z0   = Ref1Edit->text().toDouble();
  double Real = S21magEdit->text().toDouble();
  double Imag = S21degEdit->text().toDouble();
  z2r(Real, Imag, Z0);
  S11magEdit->blockSignals(true); // do not call "changed-slot"
  S11magEdit->setText(QString::number(Real));
  S11magEdit->blockSignals(false);
  S11degEdit->blockSignals(true); // do not call "changed-slot"
  S11degEdit->setText(QString::number(Imag));
  S11degEdit->blockSignals(false);
}
示例#2
0
Catalog_f mk_random_cat_f(int np)
{
  //////
  // Returns random catalog with np particles
  // (with normalized radii for angular corr)
  int ir;
  Catalog_f cat;

  print_info("*** Creating random catalog ");
#ifdef _VERBOSE
  print_info("with %d objects",np);
#endif
  print_info("\n");

  //Allocate memory for catalog
  cat.np=np;
  cat.pos=(float *)my_malloc(3*cat.np*sizeof(float));

  //Generate positions
  ir=0;
  while(ir<np) {
    double cth,phi,zz;

    if(corr_type!=1)
      zz=rand_dndz_dist();
    else
      zz=0.5*(red_max_mask+red_min_mask);
    cth=cth_min_mask+(cth_max_mask-cth_min_mask)*rand01();
    phi=phi_min_mask+(phi_max_mask-phi_min_mask)*rand01();

    if(in_mask(zz,cth,phi)) {
      double sth=sqrt(1-cth*cth);
      double rr;
      if(corr_type!=1) rr=z2r(zz);
      else rr=1;
      cat.pos[3*ir]=(float)(rr*sth*cos(phi));
      cat.pos[3*ir+1]=(float)(rr*sth*sin(phi));
      cat.pos[3*ir+2]=(float)(rr*cth);
      ir++;
    }
  }

  return cat;
}
示例#3
0
文件: io.c 项目: flaviasobreira/CUTE
Catalog_f read_catalog_f(char *fname,int *np)
{
  //////
  // Creates catalog from file fname
  FILE *fd;
  int ng;
  int ii;
  double z_mean=0;
  Catalog_f cat;

  print_info("*** Reading catalog ");
#ifdef _VERBOSE
  print_info("from file %s",fname);
#endif
  print_info("\n");

  //Open file and count lines
  fd=fopen(fname,"r");
  if(fd==NULL) error_open_file(fname);
  if(n_objects==-1) 
    ng=linecount(fd);
  else
    ng=n_objects;
  *np=ng;
  rewind(fd);

  //Allocate catalog memory
  cat.np=ng;
  cat.pos=(float *)my_malloc(3*cat.np*sizeof(float));

  rewind(fd);
  //Read galaxies in mask
  int i_dat=0;
  for(ii=0;ii<ng;ii++) {
    double zz,cth,phi,rr,sth,dum_weight;
    int st=read_line(fd,&zz,&cth,&phi,&dum_weight);
    if(st) error_read_line(fname,ii+1);
    z_mean+=zz;
    
    sth=sqrt(1-cth*cth);
    if(corr_type!=1)
      rr=z2r(zz);
    else
      rr=1;

    cat.pos[3*i_dat]=(float)(rr*sth*cos(phi));
    cat.pos[3*i_dat+1]=(float)(rr*sth*sin(phi));
    cat.pos[3*i_dat+2]=(float)(rr*cth);
    i_dat++;
  }
  fclose(fd);

  if(i_dat!=ng) {
    fprintf(stderr,"CUTE: Something went wrong !!\n");
    exit(1);
  }

  z_mean/=ng;
#ifdef _VERBOSE
  print_info("  The average redshift is %lf\n",z_mean);
#endif //_VERBOSE

  print_info("\n");
  return cat;
}
示例#4
0
void init_3D_params(Catalog cat_dat,Catalog cat_ran,int ctype)
{
    int ii;

    for(ii=0; ii<cat_dat.np; ii++) {
        double cth=cat_dat.cth[ii];
        double phi=cat_dat.phi[ii];
        double sth=sqrt(1-cth*cth);
        double rr=z2r(cat_dat.red[ii]);
        double x=rr*sth*cos(phi);
        double y=rr*sth*sin(phi);
        double z=rr*cth;

        if(ii==0) {
            x_min_bound=x;
            x_max_bound=x;
            y_min_bound=y;
            y_max_bound=y;
            z_min_bound=z;
            z_max_bound=z;
        }

        if(x<x_min_bound) x_min_bound=x;
        if(x>x_max_bound) x_max_bound=x;
        if(y<y_min_bound) y_min_bound=y;
        if(y>y_max_bound) y_max_bound=y;
        if(z<z_min_bound) z_min_bound=z;
        if(z>z_max_bound) z_max_bound=z;

        cat_dat.red[ii]=x;
        cat_dat.cth[ii]=y;
        cat_dat.phi[ii]=z;
    }

    for(ii=0; ii<cat_ran.np; ii++) {
        double cth=cat_ran.cth[ii];
        double phi=cat_ran.phi[ii];
        double sth=sqrt(1-cth*cth);
        double rr=z2r(cat_ran.red[ii]);
        double x=rr*sth*cos(phi);
        double y=rr*sth*sin(phi);
        double z=rr*cth;

        if(x<x_min_bound) x_min_bound=x;
        if(x>x_max_bound) x_max_bound=x;
        if(y<y_min_bound) y_min_bound=y;
        if(y>y_max_bound) y_max_bound=y;
        if(z<z_min_bound) z_min_bound=z;
        if(z>z_max_bound) z_max_bound=z;

        cat_ran.red[ii]=x;
        cat_ran.cth[ii]=y;
        cat_ran.phi[ii]=z;
    }

    double ex=FRACTION_EXTEND*(x_max_bound-x_min_bound);
    double ey=FRACTION_EXTEND*(y_max_bound-y_min_bound);
    double ez=FRACTION_EXTEND*(z_max_bound-z_min_bound);
    x_max_bound+=ex;
    y_max_bound+=ey;
    z_max_bound+=ez;
    x_min_bound-=ex;
    y_min_bound-=ey;
    z_min_bound-=ez;

    l_box[0]=x_max_bound-x_min_bound;
    l_box[1]=y_max_bound-y_min_bound;
    l_box[2]=z_max_bound-z_min_bound;

    double l_box_max=l_box[0];
    if(l_box[1]>l_box_max) l_box_max=l_box[1];
    if(l_box[2]>l_box_max) l_box_max=l_box[2];

    double rmax=0;
    int nside;
    if(ctype==2) rmax=1/i_r_max;
    else if(ctype==3) rmax=sqrt(1/(i_rt_max*i_rt_max)+1/(i_rl_max*i_rl_max));
    else if(ctype==4) rmax=1/i_r_max;
    else {
        fprintf(stderr,"WTF?? \n");
        exit(1);
    }
    nside=optimal_nside(l_box_max,rmax,cat_dat.np);

    n_side[0]=(int)(nside*l_box[0]/l_box_max)+1;
    n_side[1]=(int)(nside*l_box[1]/l_box_max)+1;
    n_side[2]=(int)(nside*l_box[2]/l_box_max)+1;
    n_boxes3D=n_side[0]*n_side[1]*n_side[2];

    double dx=l_box[0]/n_side[0];
    double dy=l_box[1]/n_side[1];
    double dz=l_box[2]/n_side[2];

    print_info("  There will be (%d,%d,%d) = %d boxes in total\n",
               n_side[0],n_side[1],n_side[2],n_boxes3D);
    print_info("  Boxes will be (dx,dy,dz) = (%.3lf,%.3lf,%.3lf) \n",
               dx,dy,dz);
}