Beispiel #1
0
/// This currently works only for Mvir, no enthusiasm of changing it for
/// Mdelta currently
void cosmology::mah_Zhao(double M,double z){
    FILE *mcinp;
    char dirname[100];
    getuuid(dirname);

    char *command;
    command =new char[2000];

    sprintf(command,"mkdir -p %s",dirname);
    system((const char *)command);
    
    char fname[105];
    sprintf(fname,"%s/tmpin",dirname);
    mcinp=fopen(fname,"w");

    fprintf(mcinp,"aumout\n");
    fprintf(mcinp,"%lg %lg \n",Omega0,Omegal);
    fprintf(mcinp,"1 \n");
    fprintf(mcinp,"%lg \n",h);
    fprintf(mcinp,"%lg \n",sigma8);
    fprintf(mcinp,"%lg \n",ns);
    fprintf(mcinp,"%lg %lg \n",Omegab,theta*2.7);
    fprintf(mcinp,"1 \n");
    fprintf(mcinp,"%lg \n",z);
    fprintf(mcinp,"%lg \n",log10(M));
    fclose(mcinp);

    sprintf(command,"cd %s; PATH=$PATH:.. mandc.x < tmpin >> zhao_log; rm s_aumout; rm sigma_aumout; mv mchistory* fileout;",dirname);
    system((const char*)command);

    delete [] command;

    /*
    system("PATH=$PATH:. mandc.x < tmpin >> tmp/zhao_log");
    system("rm s_aumout");
    system("rm sigma_aumout");
    system("mv mchistory* fileout");
    */

}
Beispiel #2
0
void cosmology::init_Zhao(double z){
    /// Create temporary input file
    FILE *mcinp;
    char dirname[100];
    getuuid(dirname);

    char *command;
    command =new char[2000];

    sprintf(command,"mkdir -p %s",dirname);
    system((const char *)command);
    
    char fname[105];
    sprintf(fname,"%s/tmpin",dirname);
    mcinp=fopen(fname,"w");

    fprintf(mcinp,"aumout\n");
    fprintf(mcinp,"%lg %lg \n",Omega0,Omegal);
    fprintf(mcinp,"1 \n");
    fprintf(mcinp,"%lg \n",h);
    fprintf(mcinp,"%lg \n",sigma8);
    fprintf(mcinp,"%lg \n",ns);
    fprintf(mcinp,"%lg %lg \n",Omegab,theta*2.7);
    fprintf(mcinp,"2 \n");
    fprintf(mcinp,"%lg \n",z);

    fclose(mcinp);

    /// Run Zhao code
    //printf("#Running Zhao et al. 2009 code to init cosmology");
    sprintf(command,"cd %s; PATH=$PATH:.. mandc.x < tmpin >> zhao_log; rm s_aumout; rm sigma_aumout; mv mc_aumout* tmpout; awk '{if(NR>1)print log($2)/log(10.), log($3)/log(10.) }' tmpout > c_Zhao",dirname);
    system((const char *)command);

    /*
    system("mkdir -p tmp");
    system("PATH=$PATH:. mandc.x < tmpin >> tmp/zhao_log");
    system("rm s_aumout");
    system("rm sigma_aumout");
    system("mv mc_aumout* tmpout");
    //system("sh proc tmpout");
    system("awk '{if(NR>1)print log($2)/log(10.), log($3)/log(10.) }' tmpout > tmpout2");
    system("cat tmpin >> tmp/zhao_ops");
    system("echo '#####' >> tmp/zhao_ops");
    system("cat tmpout >> tmp/zhao_ops");
    system("echo '#####' >>  tmp/zhao_ops");
    system("cat tmpout2 >>  tmp/zhao_ops");
    system("echo '#####' >>  tmp/zhao_ops");
    system("mv tmpout2 c_Zhao");
    system("rm tmpin tmpout ");
    */

    /// Read Zhao output "c_Zhao" and init spline
    sprintf(fname,"%s/c_Zhao",dirname);
    //std::cout<<"Reading from file "<<fname<<std::endl;
    mcinp=fopen(fname,"r");
    double xx[200],yy[200];
    int fill=0;
    double xM, xc;
    while ( fscanf(mcinp,"%lg %lg",&xM,&xc)==2 ){
	if(xc<0.0||fill>=200) break;
        xx[fill]=xM;
        yy[fill]=xc;
        fill++;
    }
    fclose(mcinp);
    zhao_acc = gsl_interp_accel_alloc ();
    zhao_spline = gsl_spline_alloc (gsl_interp_cspline, fill);
    gsl_spline_init (zhao_spline,xx,yy,fill);

    /// Calculate the derivatives on the outer points
    xMmin=xx[0];
    xMmax=xx[fill-1];
    cMmin=yy[0];
    cMmax=yy[fill-1];
    dymin=(yy[1]-yy[0])/(xx[1]-xx[0]);
    dymax=(yy[fill-1]-yy[fill-2])/(xx[fill-1]-xx[fill-2]);

    /// Zhao et al. concentrations initialised
    if(verbose){
        std::cerr<<"# Zhao concentrations initialized for z: "<<z<<std::endl;
    }
    bool_zhao=true;
    z_zhao=z;

    sprintf(command,"rm -rf %s",dirname);
    system((const char *)command);

    delete [] command;
}
Beispiel #3
0
void cosmology::init_pe_rho_rdelta_phys_Zhao(double M,double z){

    FILE *mcinp;
    char dirname[100];
    getuuid(dirname);

    char *command;
    command =new char[2000];

    sprintf(command,"mkdir -p %s",dirname);
    system((const char *)command);
    
    char fname[105];
    sprintf(fname,"%s/tmpin",dirname);
    mcinp=fopen(fname,"w");
    //mcinp=fopen("tmpin","w");

    fprintf(mcinp,"aumout\n");
    fprintf(mcinp,"%lg %lg \n",Omega0,Omegal);
    fprintf(mcinp,"1 \n");
    fprintf(mcinp,"%lg \n",h);
    fprintf(mcinp,"%lg \n",sigma8);
    fprintf(mcinp,"%lg \n",ns);
    fprintf(mcinp,"%lg %lg \n",Omegab,theta*2.7);
    fprintf(mcinp,"1 \n");
    fprintf(mcinp,"%lg \n",z);
    fprintf(mcinp,"%lg \n",log10(M));
    fclose(mcinp);

    sprintf(command,"cd %s; PATH=$PATH:.. mandc.x < tmpin >> zhao_log; rm s_aumout; rm sigma_aumout; mv mchistory* fileout; awk '{if(NR!=1)print $1,$2,$3}' fileout > fileout.mvir.mah",dirname);
    system((const char *)command);

    /*
    system("PATH=$PATH:. mandc.x < tmpin >> tmp/zhao_log");
    system("rm s_aumout");
    system("rm sigma_aumout");
    system("mv mchistory* fileout");
    system("awk '{if(NR!=1)print $1,$2,$3}' fileout > fileout.mvir.mah");
    */

    
    /// What we want is a spline with rho_boundary(Rvir(z)) all physical 
    /// It allows us to calculate: \int_{R1}^{R2} 4 pi r^2 dr rho(zc,r)
    /// Rho(Rvir)=rhos/cvir/(1+cvir)^2
    /// rho(Rvir)=Mvir/(4 pi rs^3 mu(cvir) )/cvir/(1+cvir)^2

    double zred,mvir,cvir;
    double *xx,*yy,*zz,*xz,*cc;
    int fillmax=125;
    xx=new double [fillmax];
    yy=new double [fillmax];
    xz=new double [fillmax];
    zz=new double [fillmax];
    cc=new double [fillmax];

    sprintf(fname,"%s/fileout.mvir.mah",dirname);
    FILE *fp=fopen(fname,"r");
    int fill=0;
    for (int i=0;i<fillmax;i++){
        fscanf(fp,"%le %le %le",&zred,&mvir,&cvir);
	if(cvir<0.0 || fill>=fillmax){
	    break;
	}
        /// Obtain Rvir from mvir, convert to physical
        double rvir=rvir_from_mvir(mvir, zred);
        rvir=rvir/(1+zred);
        xx[fillmax-fill-1]=rvir;
        double rs=rvir/cvir;
        yy[fillmax-fill-1]=mvir/( 4*M_PI*pow(rs,3)*mu(cvir)*cvir*pow(1.+cvir,2) )*4*M_PI*rvir*rvir;
        zz[fill]=mvir;
        xz[fill]=zred;
        cc[fill]=cvir;
        fprintf(stdout,"%le %le %le\n",zred,mvir,cvir);
	fill++;
    }
    fclose(fp);

    // Shift the arrays yy and xx
    for(int i=0;i<fill;i++){
	yy[i]=yy[fillmax-fill+i];
	xx[i]=xx[fillmax-fill+i];
    }


    pe_rho_rdelta_phys_Zhao_acc=gsl_interp_accel_alloc ();
    pe_rho_rdelta_phys_Zhao_spline=gsl_spline_alloc(gsl_interp_cspline,fill);
    gsl_spline_init(pe_rho_rdelta_phys_Zhao_spline,xx,yy,fill);
    mah_Zhao_acc=gsl_interp_accel_alloc ();
    mah_Zhao_spline=gsl_spline_alloc(gsl_interp_cspline,fill);
    gsl_spline_init(mah_Zhao_spline,xz,zz,fill);
    cvir_mah_Zhao_acc=gsl_interp_accel_alloc ();
    cvir_mah_Zhao_spline=gsl_spline_alloc(gsl_interp_cspline,fill);
    gsl_spline_init(cvir_mah_Zhao_spline,xz,cc,fill);

    Mvir_for_pe=M;
    z_for_pe=z;
    bool_pe_rho_rdelta_phys_Zhao=true;

    delete []xx;
    delete []yy;
    delete []zz;

    sprintf(command,"rm -rf %s",dirname);
    system((const char *)command);

    delete [] command;

}
Beispiel #4
0
static void xmlidtag(FILE *fp)
{
	static unsigned char uuid[64] ;
	getuuid(&uuid[0]) ;
	fprintf(fp, "<id>urn:uuid:%s</id>\n", &uuid[0]) ;
}