int main(int argc, char** argv) { char *infile; infile=argv[1]; char *outfile; outfile=argv[2]; if(argc!=3) { printf("Usage: ./convert2gadgetformat2 <infile> <outfile>\n"); return 0; } /* load snapshot file */ io_header header; particle_data * P; int nTot; nTot = load_snapshot(infile, &header, &P); /* output information about the simulation */ printf(">> Output from Header \n"); printf("Boxsize of Simulation: %g\n", header.BoxSize); printf("Number of gas particles: %i\n", header.npart[0]); printf("Number of high-res dm particles: %i\n", header.npart[1]); printf("Number of low-res dm particles: %i\n", header.npart[5]); printf("Number of star particles: %i\n", header.npart[4]); /* write reduced snapshot file */ write_snapshot2(outfile, &header, P); return 0; }
int load_init_snapshot(void) { if (!umxfile) return 0; if (load_snapshot(umxfile) == -1) return -1; fclose(umxfile); io_print_backlog(); return 0; }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char path[200], input_fname[200], basename[200]; int type, snapshot_number, files; sprintf(path, "/home/tczhang/desktop/C"); sprintf(basename, "snapshot"); snapshot_number = 6; /* number of snapshot */ files = 1; /* number of files per snapshot */ sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number); load_snapshot(input_fname, files); reordering(); /* call this routine only if your ID's are set properly */ unit_conversion(); /* optional stuff */ do_what_you_want(); }
/* Here we load one block of a snapshot file. It can be distributed * onto several files (for files>1). It then gets output as an array file. */ int main(int argc, char **argv) { char basename[200]; int type, files; int block_nr; int iDim; int i; int j; if(argc != 3 && argc != 4) { fprintf(stderr, "usage: snap2arr block snapbase [N_files]\n"); exit(-1); } block_nr = atoi(argv[1]); strcpy(basename, argv[2]); if(argc == 4 ) { files = atoi(argv[3]); /* # of files per snapshot */ } else files = 1; iDim = load_snapshot(basename, block_nr, files); for(i=1; i<=NumPart; i++) { for(j = 0; j < iDim; j++) { printf("%g\n", P[i].Pos[j]); } } free_memory(); return 0; }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200]; int j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2; double x,y,z,x1,y1, z1, delr; double nh, nhmax, nhmax2, mass, mmax, mmax2, dis, xmax, xmax2, ymax, ymax2, zmax, zmax2, sl, masstot, temp, tmax, h2, h2max, gam, gammin; double sinkposx, sinkposy, sinkposz, disAU, vrad, vrotx, vroty, vrotz, vrot; double velx, vely, velz; double dum_num; FILE *outfile; sprintf(path, "/work/utexas/ao/minerva"); sprintf(basename, "hires_am2"); sprintf(basenameout, "snaphires_am2_chem"); for(j=2;j<=2;j++){ snapshot_number= j; /* number of snapshot */ files=1; /* number of files per snapshot */ sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number); sprintf(output_fname, "%s/%s_%03d", path, basenameout, snapshot_number); Ngas = load_snapshot(input_fname, files); /* reordering();*/ /* call this routine only if your ID's are set properly */ unit_conversion(); outfile=fopen(output_fname, "w"); ncount = 0; ncount2 = 0; nhmax = nhmax2 = 0; mmax= mmax2 = 0; xmax= xmax2 = 0; ymax= ymax2 = 0; zmax= zmax2 = 0; sl = 0; tmax=0; h2max=0; for(n = 1; n <= Ngas; n++) { if(P[n].Id == 3755078) { sinkposx = P[n].Pos[0]; sinkposy = P[n].Pos[1]; sinkposz = P[n].Pos[2]; } } for(n=1;n<=Ngas;n++) { x=P[n].Pos[0]; y=P[n].Pos[1]; z=P[n].Pos[2]; x1=x/(0.7e0*(1.e0 + 18.9e0)); y1=y/(0.7e0*(1.e0 + 18.9e0)); z1=z/(0.7e0*(1.e0 + 18.9e0)); nh = P[n].nh; mass=P[n].Mass; masstot=masstot+mass; h2 = P[n].H2I; if(nh > nhmax2 && mass < 3.e-12) { nhmax2 = nh; mmax2=mass; xmax2=P[n].Pos[0]; ymax2=P[n].Pos[1]; zmax2=P[n].Pos[2]; } if(nh > nhmax) { nhmax = nh; mmax=mass; xmax=P[n].Pos[0]; ymax=P[n].Pos[1]; zmax=P[n].Pos[2]; h2max=P[n].H2I; } } random = rand(); dum_num = 5.0; sinkposx=xmax; sinkposy=ymax; sinkposz=zmax; printf("sinkposx = %g, sinkposy = %g, sinkposz = %g\n", sinkposx, sinkposy, sinkposz); printf("nhmax2 = %lg, maxmass2 = %lg, xmax2 = %lg, ymax2 = %lg, zmax2 = %lg\n", nhmax2, mmax2, xmax2, ymax2, zmax2); for(n = 1; n <= Ngas; n++) { dis = pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5); dis=dis*1.e3*Time/(0.7); disAU=dis*206264.806; if (/*(random*(1.e0/RAND_MAX))< 0.1e0*/ /* P[n].nh > 1.e4 || P[n].sink > 0.5*/ P[n].Id % 100 == 0) { //fprintf(outfile,"%15.13g %8d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g\n", P[n].sink, Id[n],x,y,z,P[n].Temp,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, P[n].gam, P[n].Vel[0],P[n].Vel[1],P[n].Vel[2],P[n].hsm, P[n].Mass); fprintf(outfile,"%15.13g %8d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g\n", dum_num, P[n].Id,P[n].Pos[0],P[n].Pos[1],P[n].Pos[2],dum_num,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, dum_num, disAU, vrad, vrot,dum_num, P[n].Mass); ncount = ncount + 1; } delr = sqrt((226.791-x)*(226.791-x) + (230.096-y)*(230.096-y) + (230.16-z)*(230.16-z))/(0.7e0*19.98); } printf("ncount = %d.\n", ncount); printf("ncount2 = %d.\n", ncount2); printf("nhmax= %g\n", nhmax); printf("mmax= %g\n", mmax); printf("xmax= %g\n", xmax); printf("ymax= %g\n", ymax); printf("zmax= %g\n", zmax); printf("sl = %g\n", sl); printf("tmax = %g\n", tmax); printf("h2max = %g\n", h2max); fclose(outfile); } do_what_you_want(); }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200]; int i, j, jnum, n, type, snapshot_number, files, random, ncount, ncounthalo1, ncount2, idmax; double x,y,z,x1,y1, z1, delr, vx, vy, vz, vel, typemax, dismax; double nh, nhmax, mass, mmax, dis, xmax, ymax, zmax, sl, masstot, temp, tmax, h2, h2max, gam, gammin; double sinkposx, sinkposy, sinkposz, disAU, vrad, vrotx, vroty, vrotz, vrot, mh_mass; double xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, disCOM, vCOM, ncount_doub; double hubble_param; FILE *outfile; sprintf(path, "/work/00863/minerva/strom"); sprintf(basename, "strom"); sprintf(basenameout, "snapstrom"); jnum = 800; for(j=jnum;j<=jnum;j=j+5){ snapshot_number= j; /* number of snapshot */ files=1; /* number of files per snapshot */ if(j<=999) { sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number); sprintf(output_fname, "%s/%s_%04d", path, basenameout, snapshot_number); } if(j>999) { sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number); sprintf(output_fname, "%s/%s_%04d", path, basenameout, snapshot_number); } Ngas = load_snapshot(input_fname, files); //for NON-comoving integrations Time = hubble_param = 1.0; /* reordering();*/ /* call this routine only if your ID's are set properly */ printf("hi 1, Ngas = %d, NumPart = %d\n", Ngas, NumPart); unit_conversion(); printf("hi 2\n"); outfile=fopen(output_fname, "w"); ncount = 0; ncount2 = 0; printf("hi 3\n"); nhmax = 0; mmax = mh_mass = 0; xmax = ymax = zmax = 0; sl = tmax = h2max = gammin=0; masstot = dismax = 0; typemax = 5; xCOM = yCOM = zCOM = vxCOM = vyCOM = vzCOM = ncount_doub = 0.0; printf("hi 4\n"); for(n=0;n<Ngas;n++) { nh = P[n].nh; mass=P[n].Mass; temp = P[n].Temp; h2 = P[n].H2I; gam=P[n].gam; if(nh > nhmax) //if(mass > mmax) { //printf("Found the sink!\n"); nhmax = nh; mmax=mass; xmax=P[n].Pos[0]; ymax=P[n].Pos[1]; zmax=P[n].Pos[2]; sl = P[n].hsm; tmax=P[n].Temp; h2max=P[n].H2I; gammin=P[n].gam; typemax = P[n].Type; idmax = P[n].Id; vx = P[n].Vel[0]; vy = P[n].Vel[1]; vz = P[n].Vel[2]; } } for(n=0;n<=Ngas;n++) { nh = P[n].nh; if(nh > nhmax/1e8) { vxCOM = vxCOM + P[n].Vel[0]*P[n].Mass; vyCOM = vyCOM + P[n].Vel[1]*P[n].Mass; vzCOM = vzCOM + P[n].Vel[2]*P[n].Mass; xCOM = xCOM + P[n].Pos[0]*P[n].Mass; yCOM = yCOM + P[n].Pos[1]*P[n].Mass; zCOM = zCOM + P[n].Pos[2]*P[n].Mass; ncount_doub = ncount_doub + P[n].Mass; } //if(nh > 1.e6) //if(nh > 1e3 && nh < 1e5) //printf("ID = %d, nh = %lg\n", P[n].Id, P[n].nh); //printf("%d\n", P[n].Id); } vx = vxCOM/ncount_doub; vy = vyCOM/ncount_doub; vz = vzCOM/ncount_doub; sinkposx=xmax; sinkposy=ymax; sinkposz=zmax; printf("sinkposx = %15.11g, sinkposy = %15.11g, sinkposz = %15.11g, nhmax = %15.11g, mmax = %15.11g\n", sinkposx, sinkposy, sinkposz, nhmax, mmax); vx = vy = vz = 0; sinkposx = sinkposy = sinkposz = header1.BoxSize/2.0; if(nhmax < 1.e1) { sinkposx=header1.BoxSize/2.0; sinkposy=header1.BoxSize/2.0; sinkposz=header1.BoxSize/2.0; } printf("sinkposx = %15.11g, sinkposy = %15.11g, sinkposz = %15.11g\n", sinkposx, sinkposy, sinkposz); printf("vx = %lg, vy = %lg, vz = %lg\n", vx, vy, vz); for(n = 0; n < NumPart; n++) //for(n = 0; n < Ngas; n++) { P[n].Vel[0] = P[n].Vel[0] - vx; P[n].Vel[1] = P[n].Vel[1] - vy; P[n].Vel[2] = P[n].Vel[2] - vz; x = P[n].Pos[0]; y = P[n].Pos[1]; z = P[n].Pos[2]; dis = pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5); //dis = pow(((P[n].Pos[0]-xmax)*(P[n].Pos[0]-xmax) + (P[n].Pos[1]-ymax)*(P[n].Pos[1]-ymax) + (P[n].Pos[2]-zmax)*(P[n].Pos[2]-zmax)), 0.5); if(dis > dismax) dismax = dis; dis=dis*1.e3*Time/hubble_param; disAU=dis*206264.806; vel = P[n].Vel[0]*P[n].Vel[0] + P[n].Vel[1]*P[n].Vel[1] + P[n].Vel[2]*P[n].Vel[2]; vel = pow(vel,0.5)*pow(Time, 0.5); vrad = (P[n].Vel[0]*(P[n].Pos[0]-sinkposx) + P[n].Vel[1]*(P[n].Pos[1]-sinkposy) + P[n].Vel[2]*(P[n].Pos[2]-sinkposz))/pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5); vrad = vrad*pow(Time, 0.5); vrotx = (P[n].Pos[1]-sinkposy)*P[n].Vel[2] - (P[n].Pos[2]-sinkposz)*P[n].Vel[1]; vroty = (P[n].Pos[2]-sinkposz)*P[n].Vel[0] - (P[n].Pos[0]-sinkposx)*P[n].Vel[2]; vrotz = (P[n].Pos[0]-sinkposx)*P[n].Vel[1] - (P[n].Pos[1]-sinkposy)*P[n].Vel[0]; vrot = pow(vrotx*vrotx + vroty*vroty + vrotz*vrotz, 0.5); vrot = vrot*pow(Time, 0.5)/pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5); ; //convert to km/s if(n%10000 == 0) printf("ID = %d, nh = %lg, temp = %lg, elec %lg, H2 = %lg HeII = %lg mass = %lg\n", P[n].Id, P[n].nh, P[n].Temp, P[n].HII, P[n].H2I, P[n].HeII, P[n].Mass); //f(P[n].nh > 1.e10 && P[n].sink > -4) if(disAU <= 1.e2 /*&& P[n].sink < -4*/) masstot = masstot + P[n].Mass/1.e-10/hubble_param; if(P[n].sink > 0 && P[n].nh > 8.0e13) printf("Mass = %g sink = %g ID = %d nh = %lg Dens = %lg Temp = %lg dis = %lg, vel = %lg, vrad = %lg, vrot = %lg\n", P[n].Mass, P[n].sink, P[n].Id, P[n].nh, P[n].Rho, P[n].Temp, disAU, vel, vrad, vrot); random = rand(); if((random*(1.e0/RAND_MAX)< 0.2 && P[n].nh > 3.e-2) /*|| P[n].nh > 2.e1*/ /*&& P[n].sink < 0*/ /* || P[n].sink > 0.5*/ || P[n].Id < 3 ) //if(P[n].nh > 1.e4 /*&& random*(1.e0/RAND_MAX)< 0.1e0*/ /*|| P[n].sink > 0.5 || (random*(1.e0/RAND_MAX))< 0.02e0*/) //if(dis < 1.e1) { fprintf(outfile,"%15.13g %12d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g\n", P[n].sink, P[n].Id,x,y,z,P[n].Temp,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, P[n].gam, disAU, vrad, vrot,P[n].Vel[0], P[n].Mass); //fprintf(outfile,"%15.13g %12d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %lg %lg %15.6g %15.6g\n", P[n].sink, Id[n],x,y,z,P[n].Temp,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, P[n].gam, disAU, P[n].Vel[0]*pow(Time, 0.5), P[n].Vel[2]*pow(Time, 0.5), P[n].hsm, P[n].Mass); ncount = ncount + 1; } } printf("ncount = %d.\n", ncount); printf("ncount2 = %d.\n", ncount2); printf("nhmax= %g\n", nhmax); printf("mmax= %g\n", mmax); printf("xmax= %15.11g\n", xmax); printf("ymax= %15.11g\n", ymax); printf("zmax= %15.11g\n", zmax); printf("sl = %g\n", sl); printf("tmax = %g\n", tmax); printf("h2max = %g\n", h2max); printf("gammin = %g\n", gammin); printf("typemax = %lg\n", typemax); printf("idmax = %d\n", idmax); printf("sink = %g\n", P[n-1].sink); printf("masstot = %g\n", masstot); printf("dismax = %g\n", dismax); fclose(outfile); free(P); } do_what_you_want(); }
int main(int argc, char **argv) { int i = 0; int j = 0; int n = 0; int m = 0; int i_min = 0; int i_max = 0; int j_min = 0; int j_max= 0; int flag_i = 0; int flag_j = 0; int N_dm = 0; int N_grid = 700; int N_begin = 3051; int N_end = 3099; //int N_begin = 2550; //int N_end = 2555; // int n_grid1[N_grid][N_grid]; double n_grid1[N_grid][N_grid]; // int n_grid2[N_grid][N_grid]; double n_grid2[N_grid][N_grid]; double center_x = 70.286000395; //hires3 center double center_y = 70.266843068; double center_z = 69.644125951; double width = 140.; double slice = 140.; double entries = 0.0; double temp_pos = 0.0; double min = 1.e-4; double max = 1.e-1; double abs_min = min; double abs_max = max; double time_in_Myr = 0.0; double grid1[N_grid][N_grid]; double grid2[N_grid][N_grid]; double grid3[1][N_grid]; char dir[500]; char buf[500]; FILE *infile; FILE *outfile; int files; int N_gas; double hsml_factor=1.7; double center_i, center_j, W_x, weight, h, x2, x; double nh, nhmax, xmax, ymax, zmax, vx, vy, vz, xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, ncount_doub; files=1; double IDmass=0.0; int IDsink; //sprintf(dir, "/work/00863/minerva/ds_nr6e"); //sprintf(dir, "/nobackupp1/astacy/bin_HR1"); //sprintf(dir, "/nobackupp1/astacy/hires2"); sprintf(dir, "/nobackupp1/astacy/hires_test10"); //sprintf(dir, "/nobackupp1/astacy/hires_nf3"); for(m = N_begin; m < N_end+1; m=m+1) { if(m < 10) { sprintf(buf, "%s_00%d", dir, m); printf("reading 00%d...\n", m); N_gas=load_snapshot(buf, files); sprintf(buf, "%s_00%d.H2xz", dir, m); printf("processing 00%d...\n", m); } else if(m > 9 && m < 100) { sprintf(buf, "%s_0%d", dir, m); printf("reading 0%d...\n", m); N_gas=load_snapshot(buf, files); sprintf(buf, "%s_0%d.H2xz", dir, m); printf("processing 0%d...\n", m); } else { sprintf(buf, "%s_%d", dir, m); printf("reading %d...\n", m); N_gas=load_snapshot(buf, files); sprintf(buf, "%s_%d.H2xz", dir, m); printf("processing %d...\n", m); } //width= 7.5*4.85e-4*header.HubbleParam/(1.e3*header.time); //cut out central 750 AU //slice= 7.5*4.85e-4*header.HubbleParam/(1.e3*header.time); width= 5*4.85e-4*header.HubbleParam/(1.e3*header.time); //500 AU slice= 5*4.85e-4*header.HubbleParam/(1.e3*header.time); //width= 2.4e-2*header.HubbleParam/(1.e3*header.time); //slice= 2.4e-2*header.HubbleParam/(1.e3*header.time); IDmass = 0.0; IDsink = 0; for(n = 0; n < N_gas; n++) { P[n].nh = P[n].Density*unit_mass/pow(unit_length,3.0)*pow(header.HubbleParam,2.0)/pow(header.time,3.0)*X/m_H; if (n%100000 ==0) printf("%lg\n", P[n].nh); } xCOM = yCOM = zCOM = vxCOM = vyCOM = vzCOM = ncount_doub = nhmax = 0; for(n=0;n < N_gas; n++) { nh = P[n].nh; if(nh > nhmax) { nhmax = nh; xmax=P[n].Pos[0]; ymax=P[n].Pos[1]; zmax=P[n].Pos[2]; vx = P[n].Vel[0]; vy = P[n].Vel[1]; vz = P[n].Vel[2]; } } for(n=0;n < N_gas; n++) { nh = P[n].nh; if(nh > nhmax/10.0) { vxCOM = vxCOM + P[n].Vel[0]*P[n].Mass; vyCOM = vyCOM + P[n].Vel[1]*P[n].Mass; vzCOM = vzCOM + P[n].Vel[2]*P[n].Mass; xCOM = xCOM + P[n].Pos[0]*P[n].Mass; yCOM = yCOM + P[n].Pos[1]*P[n].Mass; zCOM = zCOM + P[n].Pos[2]*P[n].Mass; ncount_doub = ncount_doub + P[n].Mass; } } vx = vxCOM/ncount_doub; vy = vyCOM/ncount_doub; vz = vzCOM/ncount_doub; center_x=xCOM/ncount_doub; center_y=yCOM/ncount_doub; center_z=zCOM/ncount_doub; time_in_Myr = 2.0/3.0/Hubble/header.HubbleParam/sqrt(header.Omega0)*pow(header.time,3.0/2.0)/1.0e6/yr; flag_i = 0; flag_j = 0; for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { n_grid1[i][j] = 0; grid1[i][j] = 0.0; } } for(n = 0; n < N_gas; n++) { if(P[n].sink > -1 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < slice/2.0) { h = fmax(hsml_factor * P[n].Hsml, width / N_grid / 2.0); weight = P[n].nh * P[n].nh; if(P[n].sink > 0) //h = hsml_factor * 3.57101e-07; h = hsml_factor * 2.5696e-08; i = 0; j=0; i_min = int((P[n].Pos[0]-h-center_x+width/2.0)/width*N_grid); if(i_min < 0) { i_min = 0; } i_max = int((P[n].Pos[0]+h-center_x+width/2.0)/width*N_grid); if(i_max > N_grid-1) { i_max = N_grid-1; } j_min = int((P[n].Pos[2]-h-center_z+width/2.0)/width*N_grid); if(j_min < 0) { j_min = 0; } j_max = int((P[n].Pos[2]+h-center_z+width/2.0)/width*N_grid); if(j_max > N_grid-1) { j_max = N_grid-1; } do { if(i >= i_min && i <= i_max) { flag_i = 1; center_i = center_x - width / 2.0 + (i + 0.5) * width / (double) N_grid; do { if(j >= j_min && j <= j_max) { flag_j = 1; center_j = center_z - width / 2.0 + (j + 0.5) * width / (double) N_grid; x2 = ((P[n].Pos[0] - center_i) * (P[n].Pos[0] - center_i) + (P[n].Pos[2] - center_j) * (P[n].Pos[2] - center_j)) / h / h; if(x2 <= 1.0) { x = sqrt(x2); if(x <= 0.5) W_x = 1.0 - 6.0 * x * x + 6.0 * x * x * x; else W_x = 2.0 * (1.0 - x) * (1.0 - x) * (1.0 - x); grid1[i][j] += weight * P[n].H2I * W_x; n_grid1[i][j] += weight * W_x; } // n_grid1[i][j] += 1; // grid1[i][j] += P[n].nh; } else if(j > j_max) { flag_j = 2; } else { flag_j = 0; } j++; } while((flag_j == 0 || flag_j == 1) && j < N_grid); j = 0; } else if(i > i_max) { flag_i = 2; } else { flag_i = 0; } i++; } while((flag_i == 0 || flag_i == 1) && i < N_grid); i = 0; } } for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { if(n_grid1[i][j] > 0) { grid1[i][j] /= double(n_grid1[i][j]); } if(grid1[i][j] < min) { grid1[i][j] = min; } if(grid1[i][j] > max) { grid1[i][j] = max; } grid1[i][j] = log10(grid1[i][j]); } } grid1[0][0] = log10(abs_min); grid1[N_grid-1][N_grid-1] = log10(abs_max); flag_i = 0; flag_j = 0; for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { n_grid2[i][j] = 0; grid2[i][j] = 0.0; } } for(n = 0; n < N_gas; n++) { if(double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0 && double(fabs(P[n].Pos[0]-center_x)) < slice/2.0) { h = fmax(hsml_factor * P[n].Hsml, width / N_grid / 2.0); weight = P[n].nh * P[n].nh; i = 0; j=0; i_min = int((P[n].Pos[2]-h-center_z+width/2.0)/width*N_grid); if(i_min < 0) { i_min = 0; } i_max = int((P[n].Pos[2]+h-center_z+width/2.0)/width*N_grid); if(i_max > N_grid-1) { i_max = N_grid-1; } j_min = int((P[n].Pos[1]-h-center_y+width/2.0)/width*N_grid); if(j_min < 0) { j_min = 0; } j_max = int((P[n].Pos[1]+h-center_y+width/2.0)/width*N_grid); if(j_max > N_grid-1) { j_max = N_grid-1; } do { if(i >= i_min && i <= i_max) { flag_i = 1; center_i = center_z - width / 2.0 + (i + 0.5) * width / (double) N_grid; do { if(j >= j_min && j <= j_max) { flag_j = 1; center_j = center_y - width / 2.0 + (j + 0.5) * width / (double) N_grid; x2 = ((P[n].Pos[2] - center_i) * (P[n].Pos[2] - center_i) + (P[n].Pos[1] - center_j) * (P[n].Pos[1] - center_j)) / h / h; if(x2 <= 1.0) { x = sqrt(x2); if(x <= 0.5) W_x = 1.0 - 6.0 * x * x + 6.0 * x * x * x; else W_x = 2.0 * (1.0 - x) * (1.0 - x) * (1.0 - x); grid2[i][j] += weight * P[n].H2I * W_x; n_grid2[i][j] += weight * W_x; } //n_grid2[i][j] += 1; //grid2[i][j] += P[n].nh; } else if(j > j_max) { flag_j = 2; } else { flag_j = 0; } j++; } while((flag_j == 0 || flag_j == 1) && j < N_grid); j = 0; } else if(i > i_max) { flag_i = 2; } else { flag_i = 0; } i++; } while((flag_i == 0 || flag_i == 1) && i < N_grid); i = 0; } } for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { if(n_grid2[i][j] > 0) { grid2[i][j] /= double(n_grid2[i][j]); } if(grid2[i][j] < min) { grid2[i][j] = min; } if(grid2[i][j] > max) { grid2[i][j] = max; } grid2[i][j] = log10(grid2[i][j]); } } grid2[0][0] = log10(abs_min); grid2[N_grid-1][N_grid-1] = log10(abs_max); for(j = 0; j < N_grid; j++) { grid3[0][j] = log10(min)+(2.0*j+1.0)*(log10(max)-log10(min))/double(N_grid)/2.0; } grid3[0][0] = log10(abs_min); outfile = fopen(buf, "w"); fwrite(grid1,sizeof(grid1),1,outfile); fwrite(grid2,sizeof(grid2),1,outfile); fwrite(grid3,sizeof(grid3),1,outfile); fwrite(&header.redshift,sizeof(double),1,outfile); fwrite(&time_in_Myr,sizeof(double),1,outfile); entries = 0.0; for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && P[n].Mass > IDmass) { IDmass = P[n].Mass; IDsink = P[n].Id; } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 /*Id[n]*/ /*P[n].Id == IDsink*/ && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { entries++; } } fwrite(&entries,sizeof(double),1,outfile); for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5*/ /*Id[n]*/ P[n].Id == IDsink && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5*/ /*Id[n]*/ P[n].Id == 4333881 && P[n].sink > 0.5 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && /*Id[n]*/ P[n].Id != IDsink && P[n].Id != 4333881 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == IDsink && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == 4333881 && P[n].sink > 0.5 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && /*Id[n]*/ P[n].Id != IDsink && P[n].Id != 4333881 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == IDsink && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } // for(n = 0; n < N_gas; n++) // { // if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == 4333881 && P[n].sink > 0.5 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) // { // temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); // fwrite(&temp_pos,sizeof(double),1,outfile); // } // } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && /*Id[n]*/ P[n].Id != IDsink && P[n].Id != 4333881 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } fclose(outfile); free(P); } printf("done!\n"); }
int main(int argc, char **argv) { int i = 0; int j = 0; int n = 0; int m = 0; int i_min = 0; int i_max = 0; int j_min = 0; int j_max= 0; int flag_i = 0; int flag_j = 0; int N_dm = 0; int N_grid = 700; int N_begin = 250; int N_end = 250; // int n_grid1[N_grid][N_grid]; double n_grid1[N_grid][N_grid]; int n_grid2[N_grid][N_grid]; double center_x = 50.339339267; double center_y = 50.121980449; double center_z = 49.486589836; //double center_x = 50.339110394; //double center_y = 50.122129369; //double center_z = 49.486652645; //double center_x = 1.1711596704; //double center_y = 67.550984743; //double center_z = 45.119393665; //double center_x = 70.0; //double center_y = 70.0; //double center_z = 70.0; double width = 140.0; double slice = 140.0; double entries = 0.0; double temp_pos = 0.0; double min = 1.0e-4; double max = 1.0e-1; double abs_min = min; double abs_max = max; double time_in_Myr = 0.0; double grid1[N_grid][N_grid]; double grid2[N_grid][N_grid]; double grid3[1][N_grid]; char dir[500]; char buf[500]; FILE *infile; FILE *outfile; double IDmass=0.0; int IDsink; double mu, u, h2frac, muh2, muh2in, gamma; int files; double hsml_factor=1.7; double center_i, center_j, W_x, weight, h, x2, x; files=1; //sprintf(dir, "/work/00863/minerva/tgridsink_ifront_nr6e"); sprintf(dir, "/work/00863/minerva/ds_nr6e"); for(m = N_begin; m < N_end+1; m++) { if(m < 10) { sprintf(buf, "%s_00%d", dir, m); printf("reading 00%d...\n", m); N_gas=load_snapshot(buf, files); sprintf(buf, "%s_00%d.HIIxz", dir, m); printf("processing 00%d...\n", m); } else if(m > 9 && m < 100) { sprintf(buf, "%s_0%d", dir, m); printf("reading 0%d...\n", m); N_gas=load_snapshot(buf, files); sprintf(buf, "%s_0%d.HIIxz", dir, m); printf("processing 0%d...\n", m); } else { sprintf(buf, "%s_%d", dir, m); printf("reading %d...\n", m); N_gas=load_snapshot(buf, files); sprintf(buf, "%s_%d.HIIxz", dir, m); printf("processing %d...\n", m); } printf("Point 1\n"); width= 2.0*2.4e-2*header.HubbleParam/(1.e3*header.time); slice= 2.0*2.4e-2*header.HubbleParam/(1.e3*header.time); //width= 2e0*header.HubbleParam/(1.e3*header.time); //slice= 2e0*header.HubbleParam/(1.e3*header.time); IDmass = 0.0; IDsink = 0; for(n = 0; n < N_gas; n++) { //P[n].nh = P[n].Density*unit_mass/pow(unit_length,3.0)*pow(header.HubbleParam,2.0)/pow(header.time,3.0)*X/m_H; //mu = 4.0/(3.0*X+1.0+4.0*X*P[n].elec); mu=1.2195; h2frac=2.0*P[n].H2I; muh2in=(0.24/4.0) + ((1.0-h2frac)*0.76) + (h2frac*.76/2.0); muh2=pow(muh2in, -1.0); if(muh2 >= 1.22){ mu=muh2; } gamma = P[n].gam; P[n].Temp = P[n].EgySpec*unit_energy/unit_mass*mu*(gamma-1.0)*m_H/k_B; P[n].nh = P[n].Density*unit_mass/pow(unit_length,3.0)*pow(header.HubbleParam,2.0)/pow(header.time,3.0)*X/m_H; } printf("HII= %lg \n", P[100].HII); time_in_Myr = 2.0/3.0/Hubble/header.HubbleParam/sqrt(header.Omega0)*pow(header.time,3.0/2.0)/1.0e6/yr; flag_i = 0; flag_j = 0; for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { n_grid1[i][j] = 0; grid1[i][j] = 0.0; } } printf("Point 2\n"); for(n = 0; n < N_gas; n++) { if(fabs(P[n].Pos[0]-center_x) < width/2.0 && fabs(P[n].Pos[1]-center_y) < width/2.0 && fabs(P[n].Pos[2]-center_z) < width/2.0 && fabs(P[n].Pos[2]-center_z) < slice/2.0) { h = fmax(hsml_factor * P[n].Hsml, width / N_grid / 2.0); weight = P[n].nh * P[n].nh; if(P[n].sink > 0) h = hsml_factor * 3.57101e-07; i = 0; j=0; i_min = int((P[n].Pos[0]-h-center_x+width/2.0)/width*N_grid); if(i_min < 0) { i_min = 0; } i_max = int((P[n].Pos[0]+h-center_x+width/2.0)/width*N_grid); if(i_max > N_grid-1) { i_max = N_grid-1; } j_min = int((P[n].Pos[2]-h-center_z+width/2.0)/width*N_grid); if(j_min < 0) { j_min = 0; } j_max = int((P[n].Pos[2]+h-center_z+width/2.0)/width*N_grid); if(j_max > N_grid-1) { j_max = N_grid-1; } do { if(i >= i_min && i <= i_max) { flag_i = 1; center_i = center_x - width / 2.0 + (i + 0.5) * width / (double) N_grid; do { if(j >= j_min && j <= j_max) { flag_j = 1; center_j = center_z - width / 2.0 + (j + 0.5) * width / (double) N_grid; x2 = ((P[n].Pos[0] - center_i) * (P[n].Pos[0] - center_i) + (P[n].Pos[2] - center_j) * (P[n].Pos[2] - center_j)) / h / h; if(x2 <= 1.0) { x = sqrt(x2); if(x <= 0.5) W_x = 1.0 - 6.0 * x * x + 6.0 * x * x * x; else W_x = 2.0 * (1.0 - x) * (1.0 - x) * (1.0 - x); grid1[i][j] += weight * P[n].HII * W_x; n_grid1[i][j] += weight * W_x; } } else if(j > j_max) { flag_j = 2; } else { flag_j = 0; } j++; } while((flag_j == 0 || flag_j == 1) && j < N_grid); j = 0; } else if(i > i_max) { flag_i = 2; } else { flag_i = 0; } i++; } while((flag_i == 0 || flag_i == 1) && i < N_grid); i = 0; } } printf("Point 3\n"); for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { if(n_grid1[i][j] > 0) { grid1[i][j] /= double(n_grid1[i][j]); } if(grid1[i][j] < min) { grid1[i][j] = min; } if(grid1[i][j] > max) { grid1[i][j] = max; } grid1[i][j] = log10(grid1[i][j]); } } grid1[0][0] = log10(abs_min); grid1[N_grid-1][N_grid-1] = log10(abs_max); flag_i = 0; flag_j = 0; printf("Point 4\n"); for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { n_grid2[i][j] = 0; grid2[i][j] = 0.0; } } printf("Point 5\n"); for(n = 0; n < N_gas; n++) { if(fabs(P[n].Pos[0]-center_x) < width/2.0 && fabs(P[n].Pos[1]-center_y) < width/2.0 && fabs(P[n].Pos[2]-center_z) < width/2.0 && fabs(P[n].Pos[0]-center_x) < slice/2.0) { i = 0; j=0; i_min = int((P[n].Pos[2]-h-center_z+width/2.0)/width*N_grid); if(i_min < 0) { i_min = 0; } i_max = int((P[n].Pos[2]+h-center_z+width/2.0)/width*N_grid); if(i_max > N_grid-1) { i_max = N_grid-1; } j_min = int((P[n].Pos[1]-h-center_y+width/2.0)/width*N_grid); if(j_min < 0) { j_min = 0; } j_max = int((P[n].Pos[1]+h-center_y+width/2.0)/width*N_grid); if(j_max > N_grid-1) { j_max = N_grid-1; } do { if(i >= i_min && i <= i_max) { flag_i = 1; do { if(j >= j_min && j <= j_max) { flag_j = 1; n_grid2[i][j] += 1; grid2[i][j] += P[n].HII; } else if(j > j_max) { flag_j = 2; } else { flag_j = 0; } j++; } while((flag_j == 0 || flag_j == 1) && j < N_grid); j = 0; } else if(i > i_max) { flag_i = 2; } else { flag_i = 0; } i++; } while((flag_i == 0 || flag_i == 1) && i < N_grid); i = 0; } } printf("Point 6\n"); for(i = 0; i < N_grid; i++) { for(j = 0; j < N_grid; j++) { if(n_grid2[i][j] > 0) { grid2[i][j] /= double(n_grid2[i][j]); } if(grid2[i][j] < min) { grid2[i][j] = min; } if(grid2[i][j] > max) { grid2[i][j] = max; } grid2[i][j] = log10(grid2[i][j]); } } grid2[0][0] = log10(abs_min); grid2[N_grid-1][N_grid-1] = log10(abs_max); for(j = 0; j < N_grid; j++) { grid3[0][j] = log10(min)+(2.0*j+1.0)*(log10(max)-log10(min))/double(N_grid)/2.0; } grid3[0][0] = log10(abs_min); outfile = fopen(buf, "w"); fwrite(grid1,sizeof(grid1),1,outfile); fwrite(grid2,sizeof(grid2),1,outfile); fwrite(grid3,sizeof(grid3),1,outfile); fwrite(&header.redshift,sizeof(double),1,outfile); fwrite(&time_in_Myr,sizeof(double),1,outfile); entries = 0.0; printf("Point 7\n"); /* for(n = 1; n <= N_gas; n++) { if(P[n].flag_split > 0.5 (Id[n] == 4025757 || Id[n] == 3410514 || Id[n] == 4014428) && fabs(P[n].Pos[0]-center_x) < width/2.0 && fabs(P[n].Pos[1]-center_y) < width/2.0 && fabs(P[n].Pos[2]-center_z) < width/2.0) { entries++; } } fwrite(&entries,sizeof(double),1,outfile); for(n = 1; n <= N_gas; n++) { if(P[n].flag_split > 0.5 (Id[n] == 4025757 || Id[n] == 3410514 || Id[n] == 4014428) && fabs(P[n].Pos[0]-center_x) < width/2.0 && fabs(P[n].Pos[1]-center_y) < width/2.0 && fabs(P[n].Pos[2]-center_z) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 1; n <= N_gas; n++) { if(P[n].flag_split > 0.5 (Id[n] == 4025757 || Id[n] == 3410514 || Id[n] == 4014428) && fabs(P[n].Pos[0]-center_x) < width/2.0 && fabs(P[n].Pos[1]-center_y) < width/2.0 && fabs(P[n].Pos[2]-center_z) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 1; n <= N_gas; n++) { if(P[n].flag_split > 0.5 (Id[n] == 4025757 || Id[n] == 3410514 || Id[n] == 4014428) && fabs(P[n].Pos[0]-center_x) < width/2.0 && fabs(P[n].Pos[1]-center_y) < width/2.0 && fabs(P[n].Pos[2]-center_z) < width/2.0) { temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } */ for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && P[n].Mass > IDmass) { IDmass = P[n].Mass; IDsink = P[n].Id; } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 /*Id[n]*/ /*P[n].Id == IDsink*/ && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { entries++; } } fwrite(&entries,sizeof(double),1,outfile); for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5*/ /*Id[n]*/ P[n].Id == IDsink && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5*/ /*Id[n]*/ P[n].Id == 4333881 && P[n].sink > 0.5 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && /*Id[n]*/ P[n].Id != IDsink && P[n].Id != 4333881 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[0]-center_x+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == IDsink && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == 4333881 && P[n].sink > 0.5 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && /*Id[n]*/ P[n].Id != IDsink && P[n].Id != 4333881 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[1]-center_y+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == IDsink && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(/*P[n].flag_split > 0.5 &&*/ /*Id[n]*/ P[n].Id == 4333881 && P[n].sink > 0.5 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } for(n = 0; n < N_gas; n++) { if(P[n].sink > 0.5 && /*Id[n]*/ P[n].Id != IDsink && P[n].Id != 4333881 && double(fabs(P[n].Pos[0]-center_x)) < width/2.0 && double(fabs(P[n].Pos[1]-center_y)) < width/2.0 && double(fabs(P[n].Pos[2]-center_z)) < width/2.0) { temp_pos = double(int((P[n].Pos[2]-center_z+width/2.0)/width*double(N_grid)))/double(N_grid); fwrite(&temp_pos,sizeof(double),1,outfile); } } printf("Point 10\n"); fclose(outfile); printf("Point 11\n"); free(P); } printf("done!\n"); }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char input_fname[200]; int type, files, i, ok; int quiteon= 0; char *p; if(argc<2) { printf("\n>readsnap <filename> <[option]>\n\n"); printf("options\n"); printf("-------\n"); printf(" -info prints byte information for all fields present\n"); printf(" -h only the header information is printed to the screen\n"); printf(" -m prints the mass of a particle when displaying other information\n"); printf(" -id prints the ID for each particle.\n"); printf(" -pot prints the Potential for every particle.\n"); printf(" -tm prints the total mass of each type\n"); printf(" -gm prints the gas mass\n"); printf("\n\n"); exit(0); } files=1; /* number of files per snapshot */ ShowHeader=0; ShowMass=0; ShowId=0; ShowPot=0; Reorder=0; PrintDefault=0; SnapFile=0; strcpy(input_fname, argv[1]); /* problem, what if we give a path rather then just filename if(!strncmp(input_fname, "snapshot", 8)) SnapFile = 1; */ if(strstr(input_fname,"snapshot")!=0) SnapFile = 1; if(argc==2) PrintDefault = 1; for(i=2; i<argc; i++) { ok = 0; if(!(strcmp(argv[i],"-info"))) ok = SnapInfo = 1; if(!(strcmp(argv[i],"-h"))) ok = ShowHeader = 1; if(!(strcmp(argv[i],"-tm"))) ok = PrintTotalMass =1; if(!(strcmp(argv[i],"-gm"))) ok = PrintGasMass = quiteon= 1; if(!(strcmp(argv[i],"-m"))) PrintDefault = ShowMass = 1; if(!(strcmp(argv[i],"-id"))) PrintDefault = ShowId = 1; if(!(strcmp(argv[i],"-pot"))) PrintDefault = ShowPot = 1; if((ok==0) && (PrintDefault==0)) { printf("Unknown parameter: %s\n",argv[i]); printf("Please use correct parameters.\n"); exit(0); } } ok= load_snapshot(input_fname, files, quiteon, ShowHeader); if(Reorder) reordering(); /* call this routine only if your ID's are set properly */ if(!ShowHeader) unit_conversion(); /* optional stuff */ if(PrintDefault) write_std_to_file(); if(ShowHeader) write_header(); if(PrintTotalMass) print_totalmass(); if(PrintGasMass) print_gasmass(); return(0); }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char dir[256]; char *snapshot_fname = NULL, *fof_fname = NULL, *groups_fname = NULL, *gmap_fname = NULL; int files; float fPeriodf1,fPeriodf2,fPeriodf3,fEpsf; int i,nf; int *pmap; /* A map between a particle and the group it is in */ int nGroups, nMapGroups, Ngroups; group_t *groups; gmap_t *gmap; int mode = DO_NOTHING; /*======================================================================= * Parse command line arguments *=====================================================================*/ for (i=1; i < argc; i++) { if (!strcmp("--make-fof", argv[i])) { if (mode != DO_NOTHING) help(); if (++i < argc) snapshot_fname = argv[i]; else help(); if (++i < argc) fof_fname = argv[i]; else help(); mode = MAKE_FOF; } else if (!strcmp("--make-groups", argv[i])) { if (mode != DO_NOTHING) help(); if (++i < argc) snapshot_fname = argv[i]; else help(); if (++i < argc) fof_fname = argv[i]; else help(); mode = MAKE_GROUPS; } else if (!strcmp("--make-tree", argv[i])) { if (mode != DO_NOTHING) help(); if (++i < argc) groups_fname = argv[i]; else help(); if (++i < argc) snapshot_fname = argv[i]; else help(); if (++i < argc) fof_fname = argv[i]; else help(); if (++i < argc) gmap_fname = argv[i]; else help(); mode = MAKE_TREE; } else if (!strcmp("-M", argv[i])) { if (++i < argc) MassMin = atof(argv[i]); else help(); if (++i < argc) MassMax = atof(argv[i]); else help(); } else if (!strcmp("-nmin", argv[i])) { if (++i < argc) nMin = atof(argv[i]); else help(); } } /*======================================================================= * Check that the user gave us sensible parameters *=====================================================================*/ if (mode == DO_NOTHING) help(); /*======================================================================= * Load in the snapshot (GADGET format) *=====================================================================*/ files=1; /* number of files per snapshot */ fprintf(stderr, "Loading snapshot %s.\n", snapshot_fname); load_snapshot(snapshot_fname, files); printf("Npart: %d; Time: %lf; Redshift: %lf\n",NumPart,header1.time, header1.redshift); nf=NumPart; printf("First particle: %f %f %f \n",P[1].Pos[0],P[1].Pos[1],P[1].Pos[2]); printf("Medium particle: %f %f %f \n",P[nf/2].Pos[0],P[nf/2].Pos[1],P[nf/2].Pos[2]); printf("Last particle: %f %f %f \n",P[nf].Pos[0],P[nf].Pos[1],P[nf].Pos[2]); /*======================================================================= * Prepare to either create or load the FOF data *=====================================================================*/ fEpsf = header1.BoxSize/ pow( NumPart, 1./3.); printf("Distanza interparticellare media: %f\n",fEpsf); fEpsf *= 0.2; /* fEpsf *= 0.15; */ /* fEpsf *= 0.1; */ fPeriodf1=fPeriodf2=fPeriodf3=(float) header1.BoxSize; pmap=malloc((NumPart+1)*sizeof(int)); if(pmap==NULL) { printf("Errore di allocazione memoria indici.\n"); exit(-1); } /* LE UNITA' NATURALI GADGET LAVORANO IN 10^10 MSOL. SE SONO STATE CAMBIATE, OCCORRE MODIFICARE QUI */ if (MassMin != -1 && MassMax != -1) { fprintf(stderr, "Mass range: [%2.2e,%2.2e]\n", MassMin, MassMax); MassMin /= UdM; MassMax /= UdM; } else { fprintf(stderr, "Mass range: Unbounded\n"); MassMin = 0; MassMax = 1e33; } switch (mode) { case MAKE_FOF: fprintf(stderr, "Making FOFs.\n"); fof_(fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,P,pmap); write_pmap(fof_fname, fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,pmap); break; case MAKE_GROUPS: fprintf(stderr, "Making Groups.\n"); if (read_pmap(fof_fname, fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,pmap)) exit(1); EvalGroups0(pmap,snapshot_fname); break; case MAKE_TREE: fprintf(stderr, "Making Progenitor Trees.\n"); if (read_groups(groups_fname, &groups, &nGroups)) exit(1); if (read_gmap(gmap_fname, &gmap, &nMapGroups)) exit(1); /*======================================================================= * Sanity check that the group files match up. *=====================================================================*/ #if 0 if (nGroups != nMapGroups) { fprintf(stderr, "Mismatched number of groups between group and map files (%i != %i).\n", nGroups, nMapGroups); exit(1); } #endif #if 0 int nPartInGroups=0, nPartInMap=0; for (i=0; i < nGroups; i++) { nPartInGroups += groups[i].npart; nPartInMap += gmap[i].npart; } fprintf(stderr, "HERE 4\n"); if (nGroups != nMapGroups) { fprintf(stderr, "Mismatched number of particles between group and map files.\n"); exit(1); } #endif /*======================================================================= * Now load the particle->group map. *=====================================================================*/ if (read_pmap(fof_fname, fEpsf,fPeriodf1,fPeriodf2,fPeriodf3,NumPart,pmap)) exit(1); //sonidx=malloc( (NumPart+1)*sizeof(int)); //npson=load_son_idx(sonidx, index_fname); //if(npson <= 0) { printf("ERROR: group non find.\n"); exit(-1); } //printf("<<Son>> group with %d particles loaded.\n",npson); mkdir("GROUPS", -1); assert(!chdir("GROUPS")); Ngroups = EvalGroups1(pmap); chdir(".."); gmap_t *gmap2 = (gmap_t *)calloc(Ngroups+1, sizeof(gmap_t)); for (i=1; i < NumPart+1; i++) gmap2[pmap[i]].npart++; for (i=0; i < Ngroups+1; i++) { gmap2[i].ps = (int *)malloc(gmap2[i].npart * sizeof(int)); assert(gmap2[i].ps != NULL); gmap2[i].npart = 0; } for (i=1; i < NumPart+1; i++) { gmap2[pmap[i]].ps[ gmap2[pmap[i]].npart++ ] = i; } #if 1 printf("Finding progenitors with mass %%: %f\n",PROGPERC); for (i=0; i < nGroups; i++) { //fprintf(stderr, "Group %i [Mass: %f]\n", i, groups[i].Mass); #if 1 if (MassMin != -1 && MassMax != -1) { if (!(MassMin < groups[i].Mass && groups[i].Mass < MassMax)) { fprintf(stderr, "Outside mass range. Group %i/%i.\n", i+1, nGroups+1);; continue; } } snprintf(dir, 256, "%05i", groups[i].id); fprintf(stderr, "Making directory %s. Group %i/%i.\n", dir, i+1, nGroups+1);; mkdir(dir, -1); assert(!chdir(dir)); int *ps = NULL; int npart = 0; int j; for (j=0; j < nMapGroups; j++) { if (groups[i].id == gmap[j].gid) { assert(ps == NULL); ps = gmap[j].ps; npart = gmap[j].npart; assert(groups[i].npart == gmap[j].npart); /* Intentionally not breaking here to check the assert()'ion if there * is somehow a duplicate groups. */ } } assert(ps != NULL); EvalProgenitors(snapshot_fname, pmap, ps, npart, Ngroups, gmap2, Ngroups); chdir(".."); #endif } #endif break; default: fprintf(stderr, "Unknown internal mode: %i\n", mode); exit(1); } return 0; }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200]; int i, k=0, j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2, halo; double x,y,z,x1,y1,z1, delr; double nh, nhmax, mass, mmax, dis, disAU, xmax, ymax, zmax, sl, masstot, temp, tmax, h2, h2max, gam, gammin; double kB, G; double massHIT, diskmass, massin=0.0, massout=0.0; double mass_sink1, mass_sink2, mass_sink3, mass_sink4, mass_tot; double dis12, dis13, x_com, y_com, z_com, vx_com, vy_com, vz_com, vx1, vy1, vz1, vx2, vy2, vz2, vx3, vy3, vz3, vx4, vy4, vz4; double sinkposx1, sinkposy1, sinkposz1, sinkposx2, sinkposy2, sinkposz2, sinkposx3, sinkposy3, sinkposz3, sinkposx4, sinkposy4, sinkposz4; double num, numz, tempz, vz, rhoz, amom, amomtot, amomtotx, amomtoty, amomtotz, amomx, amomy, amomz, amomx1, amomx2, amomy1, amomy2, amomz1, amomz2; double xfac, vrad, vrot, vrotx, vroty, vrotz, omega, nh_avg, temp_avg, vrad_avg, vrot_avg, omega_avg, num_tot; double xtimesm, ytimesm, ztimesm, vxtimesm, vytimesm, vztimesm; double xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, jzcent, jnum; double m_enc_arr[200], d_arr[200], mass_enc; int ID_sink1, ID_sink2, ID_sink3, ID_sink4, sinknum; FILE *outfile; FILE *outfile2; sprintf(path, "/nobackupp1/astacy/hires"); //sprintf(path, "/nobackupp1/astacy/"); //sprintf(path, "/nobackupp1/astacy/binHR"); halo = 0; if(halo == 0) { //sprintf(basename, "hires_test10"); sprintf(basename, "hires_test10b"); sprintf(basename, "hires3"); sprintf(basenameout, "snaphires_test10"); //jnum = 228; jnum = 2; } if(halo == 1) { sprintf(basename, "bin_HR1"); sprintf(basenameout, "snapbin_HR1"); //jnum = 228; jnum = 6; } if(halo == 2) { sprintf(basename, "bin_HR2"); sprintf(basenameout, "snapbin_HR2"); //jnum = 207; jnum = 5; } if(halo == 3) { sprintf(basename, "bin_HR3"); sprintf(basenameout, "snapbin_HR3"); //jnum = 206; jnum = 7; } if(halo == 4) { sprintf(basename, "bin_HR4"); sprintf(basenameout, "snapbin_HR4"); //jnum = 204; jnum = 7; } if(halo == 5) { sprintf(basename, "bin_HR5"); sprintf(basenameout, "snapbin_HR5"); //jnum = 209; jnum = 7; } if(halo == 6) { sprintf(basename, "bin_HR6"); sprintf(basenameout, "snapbin_HR6b"); //jnum = 224; jnum = 7; } if(halo == 7) { sprintf(basename, "bin_HR7b"); sprintf(basenameout, "snapbin_HR7b"); //jnum = 655; jnum = 9; //jnum=38; } if(halo == 8) { sprintf(basename, "bin_HR8"); sprintf(basenameout, "snapbin_HR8"); //jnum = 219; jnum = 7; } if(halo == 9) { sprintf(basename, "bin_HR9"); sprintf(basenameout, "snapbin_HR9"); //jnum = 207; jnum = 5; } if(halo == 10) { //sprintf(basename, "bin_HR10"); sprintf(basename, "bin_HR10_alt"); sprintf(basenameout, "snapbin_HR10"); //jnum = 241; //jnum = 7; jnum=8; //jnum = 24; } for(j=2;j<=50;j=j+1){ //for(j=jnum;j<=jnum;j=j+100){ snapshot_number= j; /* number of snapshot */ files=1; /* number of files per snapshot */ kB = 1.38e-16; G = 6.67e-8; diskmass = 0.0; sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number); sprintf(output_fname, "%s_disk.dat",basename); Ngas = load_snapshot(input_fname, files); ID_sink1 = 4352905; ID_sink2 = 4333881; sinknum = 0; /* reordering();*/ /* call this routine only if your ID's are set properly */ printf("hello line 187\n"); unit_conversion(); printf("hello line 191\n"); nh_avg= vrad_avg = vrot_avg = omega_avg = 0; printf("hello line 195\n"); temp_avg=0; num_tot=0; h2max=0; masstot=0; mmax=0; xtimesm = 0.0; ytimesm = 0.0; ztimesm = 0.0; vxtimesm = 0.0; vytimesm = 0.0; vztimesm = 0.0; for(i = 0; i < Ngas; i++) { if(Id[i] == ID_sink1) { sinkposx1 = P[i].Pos[0]; sinkposy1 = P[i].Pos[1]; sinkposz1 = P[i].Pos[2]; vx1 = P[i].Vel[0]; vy1 = P[i].Vel[1]; vz1 = P[i].Vel[2]; mass_sink1 = P[i].Mass*1.e10/0.7; printf("Found the sink! mass= %lg, nh = %lg\n", mass_sink1, P[i].nh); } if(P[i].nh > 1e9) { diskmass = diskmass + (P[i].Mass*1.e10/0.7); xtimesm = xtimesm + P[i].Pos[0]*(P[i].Mass*1.e10/0.7); ytimesm = ytimesm + P[i].Pos[1]*(P[i].Mass*1.e10/0.7); ztimesm = ztimesm + P[i].Pos[2]*(P[i].Mass*1.e10/0.7); vxtimesm = vxtimesm + P[i].Vel[0]*(P[i].Mass*1.e10/0.7); vytimesm = vytimesm + P[i].Vel[1]*(P[i].Mass*1.e10/0.7); vztimesm = vztimesm + P[i].Vel[2]*(P[i].Mass*1.e10/0.7); } } xCOM = xtimesm/diskmass; yCOM = ytimesm/diskmass; zCOM = ztimesm/diskmass; vxCOM = vxtimesm/diskmass; vyCOM = vytimesm/diskmass; vzCOM = vztimesm/diskmass; printf("%15.11g %15.11g %15.11g\n", xCOM, yCOM, zCOM); printf("%15.11g %15.11g %15.11g\n", vxCOM, vyCOM, vzCOM); // if(j>=4) // { sinkposx1 = xCOM; sinkposy1 = yCOM; sinkposz1 = zCOM; mass_sink1 = diskmass; vx1 = vxCOM; vy1 = vyCOM; vz1 = vzCOM; // } diskmass=0.0; ncount=0; for(n=0; n<200; n++) { m_enc_arr[n] = 0.0; d_arr[n] = (double(n)/199.0)*10000.0; printf("d_arr[%d] = %lg\n", n, d_arr[n]); } for(i = 0; i < Ngas; i++) { if(P[i].nh > 1.e8) { dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); dis=dis*1.e3*Time/(0.7); //dis is in pc disAU = dis*206264.8060; for(n=0; n<200; n++) { if(disAU < d_arr[n] /*|| P[i].sink > 0.5*/) m_enc_arr[n] = m_enc_arr[n] + P[i].Mass*1.e10/0.7; } } } for(n=0; n<200; n++) { printf("m_enc_arr[%d] = %lg\n", n, m_enc_arr[n]); } for(i = 0; i < Ngas; i++) { P[i].Vel[0] = P[i].Vel[0] - vx1; P[i].Vel[1] = P[i].Vel[1] - vy1; P[i].Vel[2] = P[i].Vel[2] - vz1; amomx = (P[i].Pos[1]-sinkposy1)*P[i].Vel[2] - (P[i].Pos[2]-sinkposz1)*P[i].Vel[1]; amomy = (P[i].Pos[2]-sinkposz1)*P[i].Vel[0] - (P[i].Pos[0]-sinkposx1)*P[i].Vel[2]; amomz = (P[i].Pos[0]-sinkposx1)*P[i].Vel[1] - (P[i].Pos[1]-sinkposy1)*P[i].Vel[0]; amomx = amomx*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7); //convert to cgs units amomy = amomy*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7); amomz = amomz*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7); amom = pow(amomx*amomx + amomy*amomy + amomz*amomz, 0.5); dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); //dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); dis=dis*1.e3*Time/(0.7); //dis is in pc disAU = dis*206264.8060; dis=dis*3.086e18; //dis in now in cm vrad = (P[n].Vel[0]*(P[n].Pos[0]-sinkposx1) + P[n].Vel[1]*(P[n].Pos[1]-sinkposy1) + P[n].Vel[2]*(P[n].Pos[2]-sinkposz1))/pow(((P[n].Pos[0]-sinkposx1)*(P[n].Pos[0]-sinkposx1) + (P[n].Pos[1]-sinkposy1)*(P[n].Pos[1]-sinkposy1) + (P[n].Pos[2]-sinkposz1)*(P[n].Pos[2]-sinkposz1)), 0.5); vrad = vrad*pow(Time, 0.5); vrotx = (P[n].Pos[1]-sinkposy1)*P[n].Vel[2] - (P[n].Pos[2]-sinkposz1)*P[n].Vel[1]; vroty = (P[n].Pos[2]-sinkposz1)*P[n].Vel[0] - (P[n].Pos[0]-sinkposx1)*P[n].Vel[2]; vrotz = (P[n].Pos[0]-sinkposx1)*P[n].Vel[1] - (P[n].Pos[1]-sinkposy1)*P[n].Vel[0]; vrot = pow(vrotx*vrotx + vroty*vroty + vrotz*vrotz, 0.5); vrot = vrot*pow(Time, 0.5)/pow(((P[n].Pos[0]-sinkposx1)*(P[n].Pos[0]-sinkposx1) + (P[n].Pos[1]-sinkposy1)*(P[n].Pos[1]-sinkposy1) + (P[n].Pos[2]-sinkposz1)*(P[n].Pos[2]-sinkposz1)), 0.5); omega = vrot/(dis/1.e5); // pi factors CANCEL OUT -- 2 pi r to get circumference CANCELS with the 2 pi radians per circumference if(P[i].nh > 1.e8) { mass_enc = m_enc_arr[0]; for(n=0; n<200; n++) { if(disAU > d_arr[n]) mass_enc = m_enc_arr[n]; } //jzcent = pow(6.67e-8 * mass_sink1 * 1.98892e33*dis, 0.5); jzcent = pow(6.67e-8 * mass_enc * 1.98892e33*dis, 0.5); } //if((fabs(amom - jzcent) <= 0.5*jzcent && P[i].nh > 1.e8) && P[i].sink < 0.5) //if((fabs(amom - jzcent) <= 0.5*jzcent && P[i].nh > 1.e8) || P[i].sink > 0.5) if(P[i].nh > 1.e9 && P[i].H2I > 1.e-3 || P[i].sink > 0.5) //if(P[i].nh > 1.e9 && P[i].H2I > 1.e-3 && P[i].sink < 0.5) //if(P[i].nh > 1.e9 && P[i].H2I <= 1.e-3 && P[i].sink < 0.5) //if(amom > jzcent && P[i].nh > 1.e8 && P[i].sink < 0.5) { //diskmass = diskmass + (P[i].Mass*1.e10/0.7); //nh_avg = nh_avg + P[i].nh*(P[i].Mass/1.03395e-12); //temp_avg = temp_avg + P[i].Temp*(P[i].Mass/1.03395e-12); //num_tot = num_tot + (P[i].Mass/1.03395e-12); diskmass = diskmass + (P[i].Mass*1.e10/0.7); //nh_avg = nh_avg + P[i].nh; nh_avg = nh_avg +(1- 2.*P[i].H2I); if(P[i].sink < 0.5) temp_avg = temp_avg + P[i].Temp; //if(P[i].Temp > 6000) // printf("ID = %d nh = %lg, temp = %lg, elec %lg, H2 = %lg sink = %lg\n", Id[i], P[i].nh, P[i].Temp, P[i].HII, P[i].H2I, P[i].sink); vrad_avg = vrad_avg + fabs(vrad); vrot_avg = vrot_avg + vrot; omega_avg = omega_avg + omega; num_tot = num_tot + 1.0; if(P[i].sink > 0.5) sinknum++; ncount++; //} } } //fclose(outfile2); printf("temp = %lg, num_tot = %lg, temp_avg = %lg\n", temp_avg, num_tot, temp_avg/num_tot); //outfile=fopen("disk_tot_h2_ng9_nr6e_alt", "a"); //outfile=fopen("disk_nosink_h2_ng9_nr6e_alt", "a"); //outfile=fopen("disk_hot_ng9_nr6e_alt", "a"); //outfile=fopen("disk_test", "a"); outfile=fopen(output_fname, "a"); fprintf(outfile, "%15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %d\n", Time, diskmass, nh_avg/num_tot, temp_avg/num_tot, vrad_avg/num_tot, vrot_avg/num_tot, omega_avg/num_tot, sinknum); fclose(outfile); outfile=fopen(output_fname2, "a"); fprintf(outfile, "%15.11g %15.11g \n", Time, fshield); fclose(outfile); free(P); } do_what_you_want(); }
int main(int argc, char **argv) { int i, j, snapshot_number; /* Read input and output files */ i=1; if (argc==1) usage(); while (i<argc) { if (!strcmp(argv[i],"-f")) { i++; strcpy(filename,argv[i]); i++; } else if (*argv[i]!='-') { strcpy(filename,argv[i]); i++; } else if (!strcmp(argv[i],"-i")) { i++; strcpy(filename,argv[i]); i++; } else if (!strcmp(argv[i],"-use")) { i++; use_cm=atoi(argv[i]); i++; } else if (!strcmp(argv[i],"-ind")) { i++; use_ind = 1; } else if (!strcmp(argv[i],"-s")) { i++; StarMassThreshold = atof(argv[i]); i++; } else if (!strcmp(argv[i],"-sfid")) { i++; sfid = atoi(argv[i]); i++; } else if (!strcmp(argv[i],"-m")) { i++; TotalMassThreshold = atof(argv[i]); i++; } else usage(); } char snap_number_dum[4]; sprintf(snap_number_dum, "%.*s", 3, &filename[ strlen(filename)-3]); snapshot_number = atoi( snap_number_dum ); printf("num %d\n", snapshot_number); load_groups(snapshot_number); load_group_ids(snapshot_number); load_snapshot(filename, snapshot_number); write_ascii(snapshot_number); return 0; }
int main(int argc, char** argv) { char *infile; infile=argv[1]; char *outfile; outfile=argv[2]; float clumpx, clumpy, clumpz; sscanf (argv[3],"%f",&clumpx); sscanf (argv[4],"%f",&clumpy); sscanf (argv[5],"%f",&clumpz); if(argc!=6) { printf("Usage: ./cutout <infile> <outfile> <x coordinate of clump [Mpc]> <y coordinate> <z coordinate>\n"); return 0; } printf("Box centered around x: %g y: %g z: %g [Mpc] \n", clumpx, clumpy, clumpz); /* load snapshot file */ io_header header; particle_data * P; int nTot; nTot = load_snapshot(infile, &header, &P); /* output information about the simulation */ printf(">> Output from Header \n"); printf("Boxsize of Simulation: %g\n", header.BoxSize); printf("Number of gas particles: %i\n", header.npart[0]); printf("Number of high-res dm particles: %i\n", header.npart[1]); printf("Number of low-res dm particles: %i\n", header.npart[5]); printf("Number of star particles: %i\n", header.npart[4]); /*cutout region around the center */ float extent=20000; clumpx=clumpx*1000; // Mpc -> kpc clumpy=clumpy*1000; // Mpc -> kpc clumpz=clumpz*1000; // Mpc -> kpc /* check if the cutout region does not extend over boundaries */ if(header.BoxSize-extent/2.<clumpx || extent/2.>clumpx) { printf("Out of bound in x-dimension - chose a more centered clump \n" ); printf(">> ABORTING \n" ); return 0; } if(header.BoxSize-extent/2.<clumpy || extent/2.>clumpy) { printf("Out of bound in y-dimension - chose a more centered clump \n" ); printf(">> ABORTING \n" ); return 0; } if(header.BoxSize-extent/2.<clumpz || extent/2.>clumpz) { printf("Out of bound in z-dimension - chose a more centered clump \n" ); printf(">> ABORTING \n" ); return 0; } int i; /* loop over all particles */ int counter = 0; float center = header.BoxSize/2; for (i=0;i<nTot;i++) { /* test if particle is within our desired volume */ if(P[i].Pos[0]<clumpx+extent/2 && P[i].Pos[0]>clumpx-extent/2 && P[i].Pos[1]<clumpy+extent/2 && P[i].Pos[1]>clumpy-extent/2 && P[i].Pos[2]<clumpz+extent/2 && P[i].Pos[2]>clumpz-extent/2) { /* shift coordinates */ P[i].Pos[0]-= clumpx-extent/2; P[i].Pos[1]-= clumpy-extent/2; P[i].Pos[2]-= clumpz-extent/2; P[counter] = P[i]; counter++; } } int counterType [6] = {0,0,0,0,0,0}; /* get the numbers of the particle types */ for (i=0;i<counter;i++) { if(P[i].Type==0) { counterType[0]+=1; } if(P[i].Type==1) { counterType[1]+=1; } if(P[i].Type==2) { counterType[2]+=1; } if(P[i].Type==3) { counterType[3]+=1; } if(P[i].Type==4) { counterType[4]+=1; } if(P[i].Type==5) { counterType[5]+=1; } } header.npart[0]=counterType[0]; header.npartTotal[0]=counterType[0]; header.npart[1]=counterType[1]; header.npartTotal[1]=counterType[1]; header.npart[4]=counterType[4]; header.npartTotal[4]=counterType[4]; header.npart[5]=counterType[5]; header.npartTotal[5]=counterType[5]; header.BoxSize = extent; /* output information about the simulation */ printf(">> Output Cutout Box\n"); printf("Boxsize: %g\n", header.BoxSize); printf("Number of gas particles: %i\n", header.npart[0]); printf("Number of high-res dm particles: %i\n", header.npart[1]); printf("Number of low-res dm particles: %i\n", header.npart[5]); printf("Number of star particles: %i\n", header.npart[4]); printf("Box centered around x: %g y: %g z: %g \n", clumpx, clumpy, clumpz); /* write reduced snapshot file */ write_snapshot(outfile, &header, P); return 0; }
/* Here we load a snapshot file. It can be distributed * onto several files (for files>1). * The particles are brought back into the order * implied by their ID's. * A unit conversion routine is called to do unit * conversion, and to evaluate the gas temperature. */ int main(int argc, char **argv) { char path[200], input_fname[200], output_fname[200], output_fname2[200], basename[200], basenameout[200]; int i, k=0, j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, arrnum=200; double x,y,z,x1,y1,z1, delr; double nh, nhmax, mass, mmax, dis, dis_sim, disAU, xmax, ymax, zmax, sl, masstot, temp, tmax, h2, h2max, gam, gammin; int IDmax; double rho_b, rho_DM[arrnum], rho_vir, r_vir, v_vir; double kB, G; double bind, diskmass, massin=0.0, massout=0.0; double vrad, vrot, disAUxy, disAUz, disAUxyz, vx_com, vy_com, vz_com, vx1, vy1, vz1, vx2, vy2, vz2, vx3, vy3, vz3, vx4, vy4, vz4; double sinkposx1, sinkposy1, sinkposz1, sinkposx2, sinkposy2, sinkposz2; double sinkposx3, sinkposy3, sinkposz3, sinkposx4, sinkposy4, sinkposz4; double num, amom, amom_arr[arrnum], amomtot, amomx_tot, amomy_tot; double amomz_tot, amomx, amomy, amomz, amomx1, amomx2, amomy1, amomy2, amomz1, amomz2; double xfac, yfac, zfac, kfloat, nh_avg, num_tot, omega, omega0, nthresh; double xtimesm, ytimesm, ztimesm, vxtimesm, vytimesm, vztimesm; double xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, jzcent; double temp_arr[arrnum], mbe_arr[arrnum], omega_arr[arrnum]; double m_enc_arr[arrnum], d_arr[arrnum], mass_enc, n_arr[arrnum], n_arr2[arrnum], surf_dens_arr[arrnum]; double rmin, rmax, nmin, nmax, numdens_arr[arrnum]; double vradx, vrady, vradz, vrotx, vroty, vrotz, vrad_arr[arrnum], vrot_arr[arrnum], dens_arr[arrnum], c_s_arr[arrnum]; double vradx_arr[arrnum], vrady_arr[arrnum], vradz_arr[arrnum], vrotx_arr[arrnum], vroty_arr[arrnum], vrotz_arr[arrnum]; double velx, vely, velz, velx_arr[arrnum], vely_arr[arrnum], velz_arr[arrnum]; double mdm_enc_arr[arrnum], turb_arr[arrnum], disx, disy, disz; double KE, KE_tot, PE, PE_tot, vel, spin_param, ncount_doub; int ID_sink1, ID_sink2, ID_sink3, ID_sink4, sinknumk; FILE *outfile, *outfile2; sprintf(path, "/work/00863/minerva/bin_zoom"); //sprintf(basename, "ifront_hiacc"); //sprintf(path, "/nobackupp1/astacy/binHR"); //sprintf(basename, "bin_HR1"); //sprintf(basename, "bin_HR7"); //sprintf(basename, "bin_HR10"); //sprintf(path, "/nobackupp1/astacy/bin_zoom"); //sprintf(basename, "bin_zoom1"); //sprintf(basename, "bin_zoom2"); //sprintf(basename, "bin_zoom3"); //sprintf(basename, "bin_zoom4"); //sprintf(basename, "bin_zoom5"); //sprintf(basename, "bin_zoom6"); //sprintf(basename, "bin_zoom7"); //sprintf(basename, "bin_zoom9"); //sprintf(basename, "bin_zoom10"); //for(j=453;j<=453;j++) //for(j=6;j<=6;j++) //for(j=9;j<=9;j++) //for(j=1;j<=1;j++) //for(j=90;j<=90;j++) //for(j=77;j<=77;j++) //for(j=86;j<=86;j++) //for(j=127;j<=127;j++) //for(j=112;j<=112;j++) //for(j=139;j<=139;j++) //for(j=91;j<=91;j++) //for(j=113;j<=113;j++) //for(j=101;j<=101;j++) /* sprintf(path, "/scratch/00863/minerva"); sprintf(basename, "bin_zoom9_new_ref3"); for(j=6800;j<=6800;j=j+20) */ sprintf(path, "/scratch/00863/minerva"); sprintf(basename, "bin_zoom10_new_ref3"); for(j=5600;j<=5600;j=j+20) //for(j=40;j<=80;j=j+20) { snapshot_number= j; /* number of snapshot */ files=1; /* number of files per snapshot */ sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number); //sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number); Ngas = load_snapshot(input_fname, files); sprintf(output_fname, "%s_mini_%03d.dat",basename, snapshot_number); if(j > 999) sprintf(output_fname, "%s_mini_%04d.dat",basename, snapshot_number); /* reordering();*/ /* call this routine only if your ID's are set properly */ rho_b = 2.94e-30; //background density of the universe unit_conversion(); nh_avg=ncount_doub=0; num_tot=0; h2max=nhmax=mmax=kfloat=0.0; xtimesm = ytimesm = ztimesm = 0.0; vxtimesm = vytimesm = vztimesm = 0.0; vxCOM=vyCOM=vzCOM=xCOM=yCOM=zCOM=0; amomx_tot = amomy_tot = amomz_tot = 0; amomtot = omega0 = masstot = 0.0; nthresh = 1.e4; for(i = 0; i < Ngas; i++) { if(P[i].nh > nhmax /*&& P[i].sink < 0.5*/) { nhmax = P[i].nh; IDmax = P[i].Id; xmax = P[i].Pos[0]; ymax = P[i].Pos[1]; zmax = P[i].Pos[2]; mmax = P[i].Mass; } } printf("xmax = %lg ymax = %lg zmax = %lg mmax = %lg nhmax = %lg\n", xmax, ymax, zmax, mmax, nhmax); for(n=0;n<=Ngas;n++) { nh = P[n].nh; dis = pow(((P[n].Pos[0]-xmax)*(P[n].Pos[0]-xmax) + (P[n].Pos[1]-ymax)*(P[n].Pos[1]-ymax) + (P[n].Pos[2]-zmax)*(P[n].Pos[2]-zmax)), 0.5); dis=dis*1.e3*Time/(0.7); disx = fabs((P[n].Pos[0]-xmax))*1.e3*Time/(0.7); disy = fabs((P[n].Pos[1]-ymax))*1.e3*Time/(0.7); disz = fabs((P[n].Pos[2]-zmax))*1.e3*Time/(0.7); disAU=dis*206264.806; if(disx < width && disy < width && disz < width) { vxCOM = vxCOM + P[n].Vel[0]*P[n].Mass; vyCOM = vyCOM + P[n].Vel[1]*P[n].Mass; vzCOM = vzCOM + P[n].Vel[2]*P[n].Mass; xCOM = xCOM + P[n].Pos[0]*P[n].Mass; yCOM = yCOM + P[n].Pos[1]*P[n].Mass; zCOM = zCOM + P[n].Pos[2]*P[n].Mass; ncount_doub = ncount_doub + P[n].Mass; } } vx1 = vxCOM/ncount_doub; vy1 = vyCOM/ncount_doub; vz1 = vzCOM/ncount_doub; //vx = vy = vz = 0; sinkposx1 = xmax; sinkposy1 = ymax; sinkposz1 = zmax; printf("vx1 = %lg, vy1 = %lg, vz1 = %lg, sinkposx1 = %lg, sinkposy1 = %lg, sinkposz1 = %lg\n", vx1, vy1, vz1, sinkposx1, sinkposy1, sinkposz1); diskmass=0.0; ncount=0; ncount_doub=0.; rmin = 100.; rmax = 3e8; nmin = 1.e-2; nmax = 1.e12; for(n=0; n<arrnum; n++) { m_enc_arr[n] = amom_arr[n] = n_arr[n] = n_arr2[n] = surf_dens_arr[n] = c_s_arr[n] = 0.0; temp_arr[n] = mbe_arr[n] = omega_arr[n] = 0.0; vrot_arr[n] = vrotx_arr[n] = vroty_arr[n] = vrotz_arr[n] = 0; vrad_arr[n] = vradx_arr[n] = vrady_arr[n] = vradz_arr[n] = 0; rho_DM[n] = 0.0; //d_arr[n] = (double(n)/199.0)*5.e8; //d_arr[n] = pow(5.e8,double(n)/double(arrnum)); d_arr[n] = rmin * pow(rmax/rmin, double(n)/double(arrnum)); numdens_arr[n] = nmin * pow(nmax/nmin, double(n)/double(arrnum)); //printf("d_arr[%d] = %lg\n", n, d_arr[n]); } //for(i = Ngas; i < NumPart; i++) for(i = 0; i < NumPart; i++) { dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); dis=dis*1.e3*Time/(0.7); //dis is in pc disAU = dis*206264.8060; if(disAU < 5.e8) { for(n=0; n<arrnum; n++) { if(disAU < d_arr[n] && P[i].Type == 0) m_enc_arr[n] = m_enc_arr[n] + P[i].Mass*1.e10/0.7; if(disAU < d_arr[n] && P[i].Type == 1) mdm_enc_arr[n] = mdm_enc_arr[n] + P[i].Mass*1.e10/0.7; } } } for(n=0; n<arrnum; n++) { rho_DM[n] = mdm_enc_arr[n]*1.98892e33/((4.0/3.0)*3.14159*pow(d_arr[n]*1.5e13, 3.0)); //DM density in cgs printf("mdm_enc_arr[%d] = %lg\n", n, mdm_enc_arr[n]); //printf("rho_DM[%d] = %lg\n", n, rho_DM[n]/(rho_b*pow(Time, -3.0))); if(rho_DM[n] > 200.0*rho_b*pow(Time, -3.0)) { rho_vir = rho_DM[n]; r_vir = d_arr[n]; } } //rotate(sinkposx1,sinkposy1,sinkposz1, vx1, vy1, vz1); //for(i = Ngas; i < NumPart; i++) for(i = 0; i < Ngas; i++) { P[i].Vel[0] = P[i].Vel[0] - vx1; P[i].Vel[1] = P[i].Vel[1] - vy1; P[i].Vel[2] = P[i].Vel[2] - vz1; amomx = (P[i].Pos[1]-sinkposy1)*P[i].Vel[2] - (P[i].Pos[2]-sinkposz1)*P[i].Vel[1]; amomy = (P[i].Pos[2]-sinkposz1)*P[i].Vel[0] - (P[i].Pos[0]-sinkposx1)*P[i].Vel[2]; amomz = (P[i].Pos[0]-sinkposx1)*P[i].Vel[1] - (P[i].Pos[1]-sinkposy1)*P[i].Vel[0]; amomx = (P[i].Mass*1.e10*1.98892e33/.7)*amomx*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7); //convert to cgs units amomy = (P[i].Mass*1.e10*1.98892e33/.7)*amomy*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7); amomz = (P[i].Mass*1.e10*1.98892e33/.7)*amomz*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7); amom = pow(amomx*amomx + amomy*amomy + amomz*amomz, 0.5); //ang. mom. of particle in cgs vel = pow(P[i].Vel[0]*P[i].Vel[0] + P[i].Vel[1]*P[i].Vel[1] + P[i].Vel[2]*P[i].Vel[2], 0.5); vel = vel*pow(Time, 0.5)*1.e5; //convert vel to cgs KE = 0.5*(P[i].Mass*1.e10*1.98892e33/.7)*pow(vel,2.0); //kinetic energy in cgs velx = P[i].Vel[0]*pow(Time, 0.5); vely = P[i].Vel[1]*pow(Time, 0.5); velz = P[i].Vel[2]*pow(Time, 0.5); dis_sim = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); dis=dis*1.e3*Time/(0.7); //dis is in pc disAU = dis*206264.8060; dis=dis*3.086e18; //dis in now in cm vrot = amom/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5; vrotx = amomx/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5; vroty = amomy/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5; vrotz = amomz/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5; //vrot in km/s omega = (P[i].Mass/1.e-10/.7)*vrot/(disAU*1.5e8); if(P[i].nh > nthresh && disAU > 0) { masstot = masstot + P[i].Mass/1.e-10/.7; omega0 = omega0 + (P[i].Mass/1.e-10/.7)*vrot/(disAU*1.5e8); //divide vrot by distance in km } disAUxyz = pow((P[i].Pos_new[0])*(P[i].Pos_new[0]) + (P[i].Pos_new[1])*(P[i].Pos_new[1]) + (P[i].Pos_new[2])*(P[i].Pos_new[2]), 0.5); disAUxyz = disAUxyz*1.e3*Time/(0.7)*206264.8060; disAUxy = pow(((P[i].Pos_new[0])*(P[i].Pos_new[0]) + (P[i].Pos_new[1])*(P[i].Pos_new[1])), 0.5); disAUxy = disAUxy*1.e3*Time/(0.7)*206264.8060; disAUz = fabs(P[i].Pos_new[2]*1.e3*Time/(0.7)*206264.8060); vrad = (P[i].Vel[0]*(P[i].Pos[0]-sinkposx1) + P[i].Vel[1]*(P[i].Pos[1]-sinkposy1) + P[i].Vel[2]*(P[i].Pos[2]-sinkposz1))/dis_sim; vrad = vrad*pow(Time, 0.5); vradx = (P[i].Vel[0]*(P[i].Pos[0]-sinkposx1))/dis_sim*pow(Time, 0.5); vrady = (P[i].Vel[1]*(P[i].Pos[1]-sinkposy1))/dis_sim*pow(Time, 0.5); vradz = (P[i].Vel[2]*(P[i].Pos[2]-sinkposz1))/dis_sim*pow(Time, 0.5); if(disAU < r_vir /*&& KE + PE < 0.0*/) { KE_tot = KE_tot + KE; PE_tot = PE_tot + PE; amomtot = amomtot + amom; amomx_tot = amomx_tot + amomx; amomy_tot = amomy_tot + amomy; amomz_tot = amomz_tot + amomz; num_tot = num_tot + P[i].Mass; ncount++; } if(P[i].nh > 1.e-2) for(n=0; n<arrnum; n++) { if(disAU > d_arr[n] && disAU < d_arr[n+1] && P[i].sink < 0.5) { amom_arr[n] = amom_arr[n] + amom/(P[i].Mass*1.e10*1.98892e33/.7); dens_arr[n] = dens_arr[n] + P[i].nh; c_s_arr[n] = c_s_arr[n] + pow(1.38e-16*P[i].Temp/1.e-24,0.5)/1.e5; temp_arr[n] = temp_arr[n] + P[i].Temp; mbe_arr[n] = mbe_arr[n] + 1050.*pow(P[i].Temp/200.,1.5)*pow(P[i].nh/1.e4,-0.5); velx_arr[k] = velx_arr[k] + velx; vely_arr[k] = vely_arr[k] + vely; velz_arr[k] = velz_arr[k] + velz; vrad_arr[n] = vrad_arr[n] + vrad; //vrot_arr[n] = vrot_arr[n] + vrot; vradx_arr[n] = vradx_arr[n] + vradx; vrady_arr[n] = vrady_arr[n] + vrady; vradz_arr[n] = vradz_arr[n] + vradz; vrotx_arr[n] = vrotx_arr[n] + vrotx; vroty_arr[n] = vroty_arr[n] + vroty; vrotz_arr[n] = vrotz_arr[n] + vrotz; n_arr[n]=n_arr[n] + 1.0; } if(disAU < d_arr[n+1] && disAU > 0) omega_arr[n] = omega_arr[n] + omega; } if(P[i].nh > 1.e-2) for(n=0; n<arrnum; n++) { if(disAUxy > d_arr[n] && disAUxy < d_arr[n+1] && disAUz < 10. && P[i].sink < 0.5) //if(disAUxyz > d_arr[n] && disAUxyz < d_arr[n+1] && P[i].sink < 0.5) { surf_dens_arr[n] = surf_dens_arr[n] + P[i].Mass*1.e10*1.98892e33/.7; n_arr2[n]=n_arr2[n] + 1.0; } } } outfile=fopen(output_fname, "a"); for(n=0; n<arrnum; n++) { printf("n_arr2 = %lg , c_s = %lg, vrad = %lg, surf_dens = %lg omega = %lg\n", n_arr2[n], c_s_arr[n], vrad_arr[n], surf_dens_arr[n], omega_arr[n]); dens_arr[n] = dens_arr[n]/n_arr[n]; velx_arr[n] = velx_arr[n]/n_arr[n]; vely_arr[n] = vely_arr[n]/n_arr[n]; velz_arr[n] = velz_arr[n]/n_arr[n]; vradx_arr[n] = vradx_arr[n]/n_arr[n]; vrady_arr[n] = vrady_arr[n]/n_arr[n]; vradz_arr[n] = vradz_arr[n]/n_arr[n]; vrotx_arr[n] = vrotx_arr[n]/n_arr[n]; vroty_arr[n] = vroty_arr[n]/n_arr[n]; vrotz_arr[n] = vrotz_arr[n]/n_arr[n]; //vrad_arr[n] = pow(vradx_arr[n]*vradx_arr[n] + vrady_arr[n]*vrady_arr[n] + vradz_arr[n]*vradz_arr[n], 0.5)/n_arr[n]; vrad_arr[n] = vrad_arr[n]/n_arr[n]; vrot_arr[n] = pow(vrotx_arr[n]*vrotx_arr[n] + vroty_arr[n]*vroty_arr[n] + vrotz_arr[n]*vrotz_arr[n], 0.5)/n_arr[n]; c_s_arr[n] = c_s_arr[n]/n_arr[n]; temp_arr[n] = temp_arr[n]/n_arr[n]; mbe_arr[n] = mbe_arr[n]/n_arr[n]; surf_dens_arr[n] = surf_dens_arr[n]/3.14159/(pow(1.4958e13*d_arr[n+1],2) - pow(1.4958e13*d_arr[n],2)); turb_arr[n] = pow(velx_arr[n] - vradx_arr[n] - vrotx_arr[n],2) + pow(vely_arr[n] - vrady_arr[n] - vroty_arr[n],2) + pow(velz_arr[n] - vradz_arr[n] - vrotz_arr[n],2); turb_arr[n] = pow(turb_arr[n], 0.5); vrot_arr[n] = pow(vrotx_arr[n]*vrotx_arr[n] + vroty_arr[n]*vroty_arr[n] + vrotz_arr[n]*vrotz_arr[n], 0.5); if(n > 0) amom_arr[n] = (m_enc_arr[k] - m_enc_arr[k-1])*vrot_arr[n]*d_arr[n]*1.5e13*1.e5*2.e33; if(n == 0) amom_arr[n] = m_enc_arr[0]*vrot_arr[0]*d_arr[0]*1.5e13*1.e5*2.e33; fprintf(outfile, "%15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g\n", d_arr[n], m_enc_arr[n], mdm_enc_arr[n], dens_arr[n], surf_dens_arr[n], c_s_arr[n], temp_arr[n], mbe_arr[n], omega_arr[n]/m_enc_arr[n], vrad_arr[n], vrot_arr[n], turb_arr[n], amom_arr[n]); } fclose(outfile); free(P); } }
int main(int argc, char **argv) { int port = SERVER_PORT; timeout = 60; static int daemon_mode = 0; int c; while (1) { static struct option long_options[] = { {"daemon", no_argument, &daemon_mode, 1}, {"file", required_argument, 0, 'f'}, {"port", required_argument, 0, 'p'}, {"sync", required_argument, 0, 's'}, {0, 0, 0, 0} }; int option_index = 0; c = getopt_long(argc, argv, "f:p:s:", long_options, &option_index); if (c == -1) { break; } switch (c) { case 0: if (long_options[option_index].flag != 0) { break; } printf ("option %s", long_options[option_index].name); if (optarg) { printf(" with arg %s", optarg); } printf("\n"); break; case 'f': sync_file = optarg; break; case 'p': port = atoi(optarg); break; case 's': timeout = atoi(optarg); break; case '?': /* getopt_long already printed an error message. */ break; default: abort(); } } if (daemon_mode == 1) { daemonize(); } if (sync_file == NULL) { sync_file = "barbershop.snapshot"; } // side snapshot file to hot load a snapshot by sending SIGHUP int n = strlen(sync_file); load_file = malloc(sizeof(char) * (n + 6)); sprintf(load_file, "%s.load", sync_file); initializePriorityQueue(); time(&app_stats.started_at); app_stats.version = "00.02.01"; app_stats.updates = 0; app_stats.items = 0; app_stats.pools = 0; load_snapshot(sync_file); signal(SIGCHLD, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGHUP, signal_handler); /* catch hangup signal */ signal(SIGTERM, signal_handler); /* catch kill signal */ pthread_t garbage_collector; pthread_create(&garbage_collector, NULL, (void *) gc_thread, NULL); int listen_fd; struct sockaddr_in listen_addr; int reuseaddr_on = 1; struct event ev_accept; event_init(); listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd < 0) { err(1, "listen failed"); } if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr_on, sizeof(reuseaddr_on)) == -1) { err(1, "setsockopt failed"); } memset(&listen_addr, 0, sizeof(listen_addr)); listen_addr.sin_family = AF_INET; listen_addr.sin_addr.s_addr = INADDR_ANY; listen_addr.sin_port = htons(port); if (bind(listen_fd, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) < 0) { err(1, "bind failed"); } if (listen(listen_fd, 5) < 0) { err(1, "listen failed"); } if (setnonblock(listen_fd) < 0) { err(1, "failed to set server socket to non-blocking"); } event_set(&ev_accept, listen_fd, EV_READ|EV_PERSIST, on_accept, NULL); event_add(&ev_accept, NULL); event_dispatch(); return 0; }
void snap_thread() { load_snapshot(load_file); respond_empty = 0; pthread_exit(0); }