int main(int argc, char **argv) { int i, j, n_gas, ray_num, N_rays, pid; int RAY_ORIGIN_CELL; int first_bh_ray, first_star_ray, first_disk_ray, first_bulge_ray; char *simfile; char *outfile; float theta, phi; float nh_prefactor; fprintf(stderr, "nh_prefactor = %.3le\n", nh_prefactor); Ray_struct *ray; FILE *op; simfile = (char*) malloc(sizeof(char)*NAMELEN); outfile = (char*) malloc(sizeof(char)*NAMELEN*2); if (argc != 4) { fprintf(stderr, "Usage: %s snapshot theta phi\n", argv[0]); exit(0); } sprintf(simfile,"%s",argv[1]); theta = atof(argv[2]); phi = atof(argv[3]); /* check that we don't go try to integrate exactly along cell boundaries */ if (sin(theta) == 0.) theta += 1.e-30; if (sin(phi) == 0.) theta += 1.e-30; /* setup the output file */ sprintf(outfile,"%s_%.1f_%.1f_nh.bin",argv[1], theta, phi); if (DEBUG) fprintf(stderr, "outfile = %s\n", outfile); if ((op = fopen(outfile, "wb")) == NULL) fprintf(stderr, "Error: Cannot open %s\n", "outfile"); /* read in the snapshot */ fprintf(stdout, "Loading snapshot %s... \n",simfile); readsnap(simfile); fprintf(stdout, "Snapshot %s loaded... \n",simfile); if (All.N_bh < 1) { fprintf(stdout,"Warning: No black holes in %s! \n", simfile); } /* * initialize the tree */ setup_lineofsight_overhead(); initialize_the_tree(); fprintf(stdout, "tree built... \n"); /* * initialize the rays */ NUMBER_OF_RAYS = (All.N_bh + All.N_star + All.N_disk + All.N_bulge); N_rays = NUMBER_OF_RAYS; N_rays = (int)(sqrt(N_rays)+1) * (int)(sqrt(N_rays)+1); /* Convert to a perfect square */ if (DEBUG) fprintf(stderr, "NUMBER_OF_RAYS = %d, N_rays = %d\n", NUMBER_OF_RAYS, N_rays); printf("Initializing (%i) Rays... \n",N_rays); ray = calloc(N_rays,sizeof(Ray_struct)); ALL_CELL_COUNTER = 0; nh_prefactor = (All.UnitMass_in_g/PROTONMASS)/(SQR(All.UnitLength_in_cm)); if (DEBUG) fprintf(stderr, "Done allocating memory for rays\n"); /* * set up the rays */ first_bh_ray = 0; first_star_ray = first_bh_ray + All.N_bh; first_disk_ray = first_star_ray + All.N_star; first_bulge_ray = first_disk_ray + All.N_disk; for (ray_num=0; ray_num<N_rays; ray_num++) { } /* rays from BH particles */ for (ray_num=first_bh_ray,pid=0; ray_num<first_star_ray; ray_num++,pid++) { ray[ray_num].ORIGIN_TYPE = PTYPE_BH; ray[ray_num].ORIGIN_ID = PBH[pid].ID; for (j=0; j<3; j++) ray[ray_num].pos[j] = PBH[pid].pos[j]; } /* rays from star particles */ for (ray_num=first_star_ray,pid=0; ray_num<first_disk_ray; ray_num++,pid++) { ray[ray_num].ORIGIN_TYPE = PTYPE_STAR; ray[ray_num].ORIGIN_ID = PS[pid].ID; for (j=0; j<3; j++) ray[ray_num].pos[j] = PS[pid].pos[j]; } /* rays from disk particles */ for (ray_num=first_disk_ray,pid=0; ray_num<first_bulge_ray; ray_num++,pid++) { ray[ray_num].ORIGIN_TYPE = PTYPE_DISK; ray[ray_num].ORIGIN_ID = PD[pid].ID; for (j=0; j<3; j++) ray[ray_num].pos[j] = PD[pid].pos[j]; } /* rays from bulge particles */ for (ray_num=first_bulge_ray,pid=0; ray_num<NUMBER_OF_RAYS; ray_num++,pid++) { ray[ray_num].ORIGIN_TYPE = PTYPE_BULGE; ray[ray_num].ORIGIN_ID = PB[pid].ID; for (j=0; j<3; j++) ray[ray_num].pos[j] = PB[pid].pos[j]; } /* initialize the remaining rays */ for (ray_num=NUMBER_OF_RAYS; ray_num<N_rays; ray_num++) { ray[ray_num].ORIGIN_TYPE = -1; ray[ray_num].ORIGIN_ID = -1; for (j=0; j<3; j++) ray[ray_num].pos[j] = 0.; ray[ray_num].theta = 0.; ray[ray_num].phi = 0.; } if (DEBUG) fprintf(stderr, "Done setting up the ray IDs and positions\n"); /* * now perform the calculations */ for (ray_num=0; ray_num<NUMBER_OF_RAYS; ray_num++) { ray[ray_num].theta = theta; ray[ray_num].phi = phi; ray[ray_num].n_hat[0] = sin(ray[ray_num].theta) * cos(ray[ray_num].phi); ray[ray_num].n_hat[1] = sin(ray[ray_num].theta) * sin(ray[ray_num].phi); ray[ray_num].n_hat[2] = cos(ray[ray_num].theta); ray[ray_num].nh=1.e-40; ray[ray_num].nh_hot=1.e-40; ray[ray_num].Z=0.; ray[ray_num].neutral_frac=0.; RAY_ORIGIN_CELL = find_cell_from_scratch(ray[ray_num].pos); integrate_ray_to_escape(&ray[ray_num],RAY_ORIGIN_CELL); ray[ray_num].Z /= ray[ray_num].nh; ray[ray_num].neutral_frac /= ray[ray_num].nh; ray[ray_num].nh *= nh_prefactor; ray[ray_num].nh_hot *= nh_prefactor; if (DEBUG) fprintf(stderr, "ray_num %d origin_cell %d origin_type %d origin_id %d theta %.1f phi %.1f nh %.3f Z %f\n",ray_num, RAY_ORIGIN_CELL, ray[ray_num].ORIGIN_TYPE, ray[ray_num].ORIGIN_ID,ray[ray_num].theta,ray[ray_num].phi,log10(ray[ray_num].nh_hot),ray[ray_num].Z); fwrite(&ray[ray_num].ORIGIN_TYPE,sizeof(int),1,op); fwrite(&ray[ray_num].ORIGIN_ID,sizeof(int),1,op); fwrite(&ray[ray_num].nh_hot,sizeof(float),1,op); } fclose(op); printf("\n Done! \n"); return 0; }
void main(int argc, char **argv) { Biobuf *b; Data *d; File *fdir, *f; Proc *p, *plist; Tree *tree; char *mtpt, buf[32]; int i, mflag; mtpt = "/proc"; mflag = MBEFORE; ARGBEGIN{ case 'D': chatty9p++; break; case 'd': debug = 1; break; case 'a': mflag = MAFTER; break; case 'm': mtpt = ARGF(); break; default: usage(); }ARGEND if(argc != 1) usage(); b = Bopen(argv[0], OREAD); if(b == nil) { fprint(2, "cannot open \"%s\": %r\n", argv[0]); exits("Bopen"); } if((plist = readsnap(b)) == nil) { fprint(2, "readsnap fails\n"); exits("readsnap"); } tree = alloctree(nil, nil, DMDIR|0555, nil); fs.tree = tree; for(p=plist; p; p=p->link) { print("process %ld %.*s\n", p->pid, 28, p->d[Pstatus] ? p->d[Pstatus]->data : ""); snprint(buf, sizeof buf, "%ld", p->pid); fdir = ecreatefile(tree->root, buf, nil, DMDIR|0555, nil); ecreatefile(fdir, "ctl", nil, 0777, nil); if(p->text) ecreatefile(fdir, "text", nil, 0777, PDProc(p)); ecreatefile(fdir, "mem", nil, 0666, PDProc(p)); for(i=0; i<Npfile; i++) { if((d = p->d[i])) { f = ecreatefile(fdir, pfile[i], nil, 0666, PDData(d)); f->Dir.length = d->len; } } } postmountsrv(&fs, nil, mtpt, mflag); exits(0); }
int main(int argc, char **argv) { int n_gas, N_particles; /* Load the simulation snapshot and check for black holes */ char sim_file[100]; if(argc==1) { printf("Snapshot filename: "); scanf("%s",sim_file); }else if(argc==2) { sprintf(sim_file,"%s",argv[1]); }else if(argc==3) { sprintf(sim_file,"%s",argv[1]); }else{ printf("wrong number of arguments\n"); printf("./sim [snapshot_filename] \n"); exit(-1); } printf("Loading snapshot %s... \n",sim_file); readsnap(sim_file); printf("Snapshot %s loaded... \n",sim_file); if(MODE == QSOMODE && All.N_bh < 1) { fprintf(stderr,"No black holes! \n"); exit(0); } else if (All.N_bh < 1) { fprintf(stderr,"Warning: No black holes! \n"); } //free(PH); //free(PD); //free(PB); int N_rays; if (MODE == QSOMODE) { NUMBER_OF_RAYS = 1000; } else if (MODE == RTMODE) { NUMBER_OF_RAYS = All.N_star+All.N_bh; } N_rays = NUMBER_OF_RAYS; /* Number of rays to use to trace the structure */ N_rays = (int)(sqrt(N_rays)+1) * (int)(sqrt(N_rays)+1); /* Convert to a perfect square */ if (DEBUG) fprintf(stderr, "NUMBER_OF_RAYS = %d, N_rays = %d\n", NUMBER_OF_RAYS, N_rays); /* * initialize the tree */ setup_lineofsight_overhead(); /* Build the tree-cell system to sort the gas properties */ initialize_the_tree(); printf("tree built... \n",sim_file); /* Get the info for the output files */ int p_file_chk,j; float dummf0 = 0.0; char out_file_2[100]; FILE *output_file; if((argc==2)||(argc==1)) { printf("\nFilename for integrated values (NH, etc): "); scanf("%s",out_file_2); }else{ sprintf(out_file_2,"%s",argv[2]); } if ((output_file = fopen(out_file_2, "wb")) == NULL) fprintf(stderr, "Cannot open %s\n", "output_file_2"); int dumfcount; /* Create & allocate memory for the ray list */ printf("Initializing (%i) Rays... \n",N_rays); int byte, ray_num; Ray_struct *ray; ray = calloc(N_rays,sizeof(Ray_struct)); int rayorigintype; int RAY_ORIGIN_CELL; ALL_CELL_COUNTER = 0; float origin_pos[3]; float nh_prefactor = (All.UnitMass_in_g/PROTONMASS)/(SQR(All.UnitLength_in_cm)); /* * QSOMODE * This is supposed to represent the original purpose of the code, but * hasn't been actually checked. . . */ if (MODE == QSOMODE) { int number_of_ray_origins = 1; rayorigintype = PTYPE_BH; for (j=0;j<3;j++) origin_pos[j]=PBH[0].pos[j]; RAY_ORIGIN_CELL = find_cell_from_scratch(origin_pos); generate_ray_angles(ray, N_rays); for (ray_num=0; ray_num < N_rays; ray_num++) { ray[ray_num].n_hat[0] = sin(ray[ray_num].theta) * cos(ray[ray_num].phi); ray[ray_num].n_hat[1] = sin(ray[ray_num].theta) * sin(ray[ray_num].phi); ray[ray_num].n_hat[2] = cos(ray[ray_num].theta); } for (ray_num=0; ray_num < N_rays; ray_num++) { ray[ray_num].n_hat[0] = sin(ray[ray_num].theta) * cos(ray[ray_num].phi); ray[ray_num].n_hat[1] = sin(ray[ray_num].theta) * sin(ray[ray_num].phi); ray[ray_num].n_hat[2] = cos(ray[ray_num].theta); } /* Print some of the overhead info to the binary NH output file */ fwrite(&rayorigintype,sizeof(int),1,output_file); fwrite(&number_of_ray_origins,sizeof(int),1,output_file); fwrite(&N_rays,sizeof(int),1,output_file); for (ray_num=0; ray_num < N_rays; ray_num++) { fwrite(&ray[ray_num].theta,sizeof(float),1,output_file); fwrite(&ray[ray_num].phi,sizeof(float),1,output_file); } for (ray_num=0; ray_num < N_rays; ray_num++) { for (j=0;j<3;j++) ray[ray_num].pos[j] = PBH[0].pos[j]; integrate_ray_to_escape(&ray[ray_num],RAY_ORIGIN_CELL); ray[ray_num].Z /= ray[ray_num].nh; ray[ray_num].neutral_frac /= ray[ray_num].nh; ray[ray_num].nh *= nh_prefactor; ray[ray_num].nh_hot *= nh_prefactor; } fwrite(&PBH[0].ID,sizeof(int),1,output_file); fwrite(&ray[ray_num].DEST_ID,sizeof(int),1,output_file); fwrite(&ray[ray_num].nh_hot,sizeof(float),1,output_file); fwrite(&ray[ray_num].Z,sizeof(float),1,output_file); fclose(output_file); } /* end of QSOMODE */ /* * RTMODE * Very simple radiative transfer. Calculated the N_H from all star and BH * particles to each gas particle. */ if (MODE == RTMODE) { int number_of_ray_origins = All.N_star + All.N_bh; int number_of_ray_destinations = All.N_gas; printf("In RTMODE\n"); printf("Beginning to process %i ray sources...\n",number_of_ray_origins); allocate_gas_sources(); /* loop over gas particles */ /* N_particles = All.N_gas; */ N_particles = All.N_gas; for (n_gas=0; n_gas<N_particles; n_gas++) { fprintf(stderr, "Processing gas particle %d of %d\n", n_gas, N_particles); /* calculate the angles from the current gas particle to the star and BH particles */ set_ray_angles(ray,N_rays,PG[n_gas].pos, PG[n_gas].ID); /* calculate each of the vectors */ for (ray_num=0; ray_num < N_rays; ray_num++) { ray[ray_num].n_hat[0] = sin(ray[ray_num].theta) * cos(ray[ray_num].phi); ray[ray_num].n_hat[1] = sin(ray[ray_num].theta) * sin(ray[ray_num].phi); ray[ray_num].n_hat[2] = cos(ray[ray_num].theta); } RAY_ORIGIN_CELL = find_cell_from_scratch(PG[n_gas].pos); /* Calculate N_H along the rays */ for (ray_num=0; ray_num < N_rays; ray_num++) { for (j=0;j<3;j++) ray[ray_num].pos[j] = PG[n_gas].pos[j]; /* need to fix this */ /* integrate_ray_to_target(&ray[ray_num],RAY_ORIGIN_CELL); */ ray[ray_num].Z /= ray[ray_num].nh; ray[ray_num].neutral_frac /= ray[ray_num].nh; ray[ray_num].nh *= nh_prefactor; ray[ray_num].nh_hot *= nh_prefactor; PG[n_gas].PTYPE[ray_num] = ray[ray_num].DEST_TYPE; PG[n_gas].PID[ray_num] = ray[ray_num].DEST_ID; PG[n_gas].NH[ray_num] = ray[ray_num].nh_hot; PG[n_gas].D[ray_num] = ray[ray_num].D; if (DEBUG) printf("ray_num %d origin cell %d dest type %d dest id %d theta %f phi %f xmax[0] %.3f xmax[1] %.3f xmax[2] %.3f nh %.3f Z %f D %.3f\n",ray_num, RAY_ORIGIN_CELL,PG[n_gas].PTYPE[ray_num], PG[n_gas].PID[ray_num],ray[ray_num].theta,ray[ray_num].phi,ray[ray_num].xmax[0]-origin_pos[0],ray[ray_num].xmax[1]-origin_pos[1],ray[ray_num].xmax[2]-origin_pos[2],log10(PG[n_gas].NH[ray_num]),ray[ray_num].Z,PG[n_gas].D[ray_num]); } /* end of loop for ray calculations */ } /* end of loop over destination particles */ } /* end of RTMODE */ /* * VMODE: * Calculate the N_H for all star particles along one theta,phi for a * quick & dirty treatment of dust in the output images * will compute an N_H for each star and BH particle * */ if (MODE == VMODE) { int number_of_sources, n_source; number_of_sources = All.N_star + All.N_bh; for(n_source=0; n_source < number_of_sources; n_source++) { } } /* end of VMODE */ printf("\n Done! \n"); return 0; }