void output_ascii(int64_t id_offset, int64_t snap, int64_t chunk, float *bounds) { char buffer[1024]; int64_t i, id=0; FILE *output; struct halo *th; get_output_filename(buffer, 1024, snap, chunk, "ascii"); //if (PARALLEL_IO) output = check_fopen(buffer, "w"); //else output = stdout; fprintf(output, "#id num_p m%s mbound_%s r%s vmax rvmax vrms x y z vx vy vz Jx Jy Jz E Spin PosUncertainty VelUncertainty bulk_vx bulk_vy bulk_vz BulkVelUnc n_core\n", MASS_DEFINITION, MASS_DEFINITION, MASS_DEFINITION); print_ascii_header_info(output, bounds); for (i=0; i<num_halos; i++) { if (!_should_print(halos+i, bounds)) continue; th = halos+i; fprintf(output, "%"PRId64" %"PRId64" %.3e %.3e" " %f %f %f %f %f %f %f %f %f %f %g %g %g %g %g %f %f %f %f %f %f %"PRId64"\n", id+id_offset, th->num_p, th->m, th->mgrav, th->r, th->vmax, th->rvmax, th->vrms, th->pos[0], th->pos[1], th->pos[2], th->pos[3], th->pos[4], th->pos[5], th->J[0], th->J[1], th->J[2], th->energy, th->spin, sqrt(th->min_pos_err), sqrt(th->min_vel_err), th->bulkvel[0], th->bulkvel[1], th->bulkvel[2], sqrt(th->min_bulkvel_err), th->n_core); id++; } //if (PARALLEL_IO) fclose(output); }
int i_buf2file (unsigned int const width, unsigned int const height, int const buf[width][height], char* const path, char* const prefix) { FILE* fd = 0; char outfile[40]; int i, j; //obtain output filename if (get_output_filename (outfile, path, prefix, "txt", 0) != 0) { generate_error ("Unable to process output filename for buffer..."); return 1; } fd = fopen (outfile, "w"); if (fd == NULL) { generate_error ("Unable to open file for printing buffer..."); return 1; } // fprintf (fd, "[INFO] ... .............................................\n"); // fprintf (fd, "[INFO] ... %s\n", prefix); // fprintf (fd, "[INFO] ... .............................................\n\n"); for (j=0; j<height; ++j) { for (i=0; i<width; ++i) { fprintf (fd, "%d ", buf[j][i]); } fprintf (fd, "\n"); } fclose (fd); return 0; }
void output_full_particles(int64_t id_offset, int64_t snap, int64_t chunk, float *bounds) { char buffer[1024]; FILE *output; int64_t i, id=0; struct halo *th; if (chunk>=FULL_PARTICLE_CHUNKS) return; get_output_filename(buffer, 1024, snap, chunk, "particles"); output = check_fopen(buffer, "w"); fprintf(output, "#Halo table:\n"); fprintf(output, "#id internal_id num_p m%s mbound_%s r%s vmax rvmax vrms x y z vx vy vz Jx Jy Jz energy spin\n", MASS_DEFINITION, MASS_DEFINITION, MASS_DEFINITION); fprintf(output, "#Particle table:\n"); fprintf(output, "#x y z vx vy vz particle_id assigned_internal_haloid internal_haloid external_haloid\n"); fprintf(output, "#Notes: As not all halos are printed, some halos may not have external halo ids. (Hence the need to print internal halo ids). Each particle is assigned to a unique halo; however, some properties (such as halo bound mass) are calculated including all substructure. As such, particles belonging to subhalos are included in outputs; to exclude substructure, verify that the internal halo id is the same as the assigned internal halo id.\n"); fprintf(output, "#Note also that halos with centers in particle ghost zones (outside the nominal boundaries) will not be printed, as their particle lists may be incomplete.\n"); print_ascii_header_info(output, bounds); fprintf(output, "#Halo table begins here:\n"); for (i=0; i<num_halos; i++) { th = halos+i; if (_should_print(th, bounds)) { th->id = id+id_offset; id++; } else { th->id = -1; } fprintf(output, "#%"PRId64" %"PRId64" %"PRId64" %.3e %.3e" " %f %f %f %f %f %f %f %f %f %f %g %g %g %g %g\n", th->id, i, th->num_p, th->m, th->mgrav, th->r, th->vmax, th->rvmax, th->vrms, th->pos[0], th->pos[1], th->pos[2], th->pos[3], th->pos[4], th->pos[5], th->J[0], th->J[1], th->J[2], th->energy, th->spin); } fprintf(output, "#Particle table begins here:\n"); for (i=0; i<num_halos; i++) print_child_particles(output, i, i, halos[i].id); fclose(output); get_output_filename(buffer, 1024, snap, chunk, "particles"); //gzip_file(buffer); }
int main (int argc, char *argv[]) { GError *error = NULL; init ("xpstotiff"); GOptionContext *context = g_option_context_new ("- convert a xps document to tiff"); g_option_context_set_description (context, "Report bugs to <" PACKAGE_BUGREPORT ">"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) rerror ("%s", error->message); if (in_filename == NULL) rerror ("no input file specified"); out_filename = get_output_filename (in_filename[0], out_filename, ".tiff"); TIFF *tif = TIFFOpen (out_filename, "w"); if (tif == NULL) rerror ("Unable to open %s", out_filename); foreach_gxps_page (in_filename[0], xps_page_cb, tif); TIFFClose (tif); return EXIT_SUCCESS; }
int img2array (png_img* img, int const channel, char* const path, char* const name) { FILE* fd; char outfile[40]; int i, j; png_byte* row; png_byte* tmp; // obtain entire output filename if (get_output_filename (outfile, path, name, "txt", 0) != 0) { generate_error ("Unable to process output filename for group..."); return 1; } fd = fopen (outfile, "w"); if (fd == NULL) { generate_error ("Unable to open file for printing group..."); return 1; } // write pixel values to the file for (j=0; j<img->height; ++j) { row = img->data[j]; for (i=0; i<img->width; ++i) { tmp = &(row[i*3]); fprintf (fd, "%d ", tmp[channel]); } fprintf (fd, "\n"); } fclose (fd); return 0; }
void delete_binary(int64_t snap, int64_t chunk) { char buffer[1024]; get_output_filename(buffer, 1024, snap, chunk, "bin"); unlink(buffer); }
float find_previous_mass(struct halo *h, struct particle *hp, int64_t *best_num_p) { int64_t i, j, last_chunk = -1, max_particles, best_particles = 0; int64_t cur_part, remaining; char buffer[1024]; struct previous_halo *tph, *best_ph=NULL; struct litehash *lh = NULL; FILE *input = NULL; *best_num_p = 0; if (h->num_p < 100 || !num_prev_halos) return 0; fast3tree_find_sphere(phtree, phtree_results, h->pos, h->r); if (!phtree_results->num_points) return 0; for (i=0; i<phtree_results->num_points; i++) { if (!prev_halo_acceptable(h, phtree_results->points[i])) { phtree_results->num_points--; phtree_results->points[i] = phtree_results->points[phtree_results->num_points]; i--; } } if (!phtree_results->num_points) return 0; qsort(phtree_results->points, phtree_results->num_points, sizeof(struct previous_halo *), sort_previous_halos); max_particles = MAX_CORE_PARTICLES; if (max_particles >= h->num_p) max_particles = h->num_p; else convert_and_sort_core_particles(h, hp); lh = new_litehash(8); for (i=0; i<max_particles; i++) lh_setval(lh, &(p[hp[i].id].id), (void *)1); for (i=0; i<phtree_results->num_points; i++) { tph = phtree_results->points[i]; remaining = tph->num_p; cur_part = 0; if (remaining > MAX_CORE_PARTICLES) remaining = MAX_CORE_PARTICLES; if (tph->file_offset >= 0) { if (tph->chunk != last_chunk) { if (last_chunk > -1) fclose(input); get_output_filename(buffer, 1024, prev_snap, tph->chunk, "bin"); input = check_fopen(buffer, "rb"); last_chunk = tph->chunk; } check_fseeko(input, tph->file_offset, SEEK_SET); check_fread(prev_pids, sizeof(int64_t), remaining, input); } else { memcpy(prev_pids, hid_cache+tph->p_offset, sizeof(int64_t)*remaining); } for (j=0; j<remaining; j++) if (lh_getval(lh, prev_pids + j)) cur_part++; if (cur_part > best_particles) { best_particles = cur_part; best_ph = tph; } } if (last_chunk > -1) fclose(input); free_litehash(lh); if (best_ph && best_ph->m > 1e13 && best_particles > max_particles*0.1) { fprintf(stderr, "Hnow: %f %f %f (%"PRId64"; %e); Phalo: %f %f %f (%e); %"PRId64"\n", h->pos[0], h->pos[1], h->pos[2], h->num_p, h->num_p*PARTICLE_MASS, best_ph->pos[0], best_ph->pos[1], best_ph->pos[2], best_ph->m, best_particles); } *best_num_p = best_particles; if (best_ph && (best_particles > max_particles*0.1)) return best_ph->m; return 0; }
int print_list (list_t const list, char* const path, char* const prefix) { FILE* fd = 0; group_node_t* tmp = list; block_node_t* tmp_block; char groupname[40]; int count = 0; while (tmp != NULL) { //obtain output filename if (get_output_filename (groupname, path, prefix, "txt", ++count) != 0) { generate_error ("Unable to process output filename for group..."); return 1; } fd = fopen (groupname, "w"); if (fd == NULL) { generate_error ("Unable to open file for printing group..."); return 1; } tmp_block = tmp->group; fprintf (fd, "[INFO] ... nr of blocks in group: %d\n", group_length(&tmp_block)); if (strstr(path, "est") != NULL) { fprintf (fd, "[INFO] ... group weight: %f\n", tmp->weight); } fprintf (fd, "\n"); fprintf (fd, "[INFO] ... reference block...\n"); while (tmp_block != NULL) { print_block (fd, tmp_block->block); fprintf (fd, "[INFO] ... block position: (%d/%d)\n", tmp_block->block.x, tmp_block->block.y); fprintf (fd, "[INFO] ... distance to reference block: %f\n", tmp_block->distance); tmp_block = tmp_block->next; } tmp = tmp->next; fclose (fd); } return 0; }
int main(int argc, char **argv) { int c; char *input_file_name = NULL; char *output_file_name = NULL; char *output_basename = NULL; char *error_file_name = NULL; FILE *input_file = NULL; FILE *output_file = NULL; FILE *error_file = NULL; gregorio_file_format input_format = FORMAT_UNSET; gregorio_file_format output_format = FORMAT_UNSET; gregorio_verbosity verb_mode = 0; bool point_and_click = false; char *point_and_click_filename = NULL; bool debug = false; bool must_print_short_usage = false; int option_index = 0; static struct option long_options[] = { {"output-file", 1, 0, 'o'}, {"stdout", 0, 0, 'S'}, {"output-format", 1, 0, 'F'}, {"messages-file", 1, 0, 'l'}, {"input-format", 1, 0, 'f'}, {"stdin", 0, 0, 's'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, {"licence", 0, 0, 'L'}, {"verbose", 0, 0, 'v'}, {"all-warnings", 0, 0, 'W'}, {"point-and-click", 0, 0, 'p'}, {"debug", 0, 0, 'd'}, }; gregorio_score *score = NULL; gregorio_support_init("gregorio", argv[0]); if (argc == 1) { fprintf(stderr, "%s: missing file operand.\n", argv[0]); print_short_usage(argv[0]); gregorio_exit(0); } setlocale(LC_CTYPE, "C"); while (1) { c = getopt_long(argc, argv, "o:SF:l:f:shOLVvWpd", long_options, &option_index); if (c == -1) break; switch (c) { case 'o': if (output_file_name) { fprintf(stderr, "warning: several output files declared, %s taken\n", output_file_name); must_print_short_usage = true; break; } if (output_file) { /* means that stdout is defined */ fprintf(stderr, "warning: can't write to file and stdout, writing on stdout\n"); must_print_short_usage = true; break; } output_file_name = optarg; break; case 'S': if (output_file_name) { fprintf(stderr, "warning: can't write to file and stdout, writing on %s\n", output_file_name); must_print_short_usage = true; break; } if (output_file) { /* means that stdout is defined */ fprintf(stderr, "warning: option used several times: %c\n", c); must_print_short_usage = true; break; } output_file = stdout; break; case 'F': if (output_format) { fprintf(stderr, "warning: several output formats declared, first taken\n"); must_print_short_usage = true; break; } if (!strcmp(optarg, GABC_STR)) { output_format = GABC; break; } if (!strcmp(optarg, GTEX_STR)) { output_format = GTEX; break; } if (!strcmp(optarg, DUMP_STR)) { output_format = DUMP; break; } else { fprintf(stderr, "error: unknown output format: %s\n", optarg); print_short_usage(argv[0]); gregorio_exit(1); } break; case 'l': if (error_file_name) { fprintf(stderr, "warning: several error files declared, %s taken\n", error_file_name); must_print_short_usage = true; break; } error_file_name = optarg; break; case 'f': if (input_format) { gregorio_set_error_out(error_file); fprintf(stderr, "warning: several output formats declared, first taken\n"); must_print_short_usage = true; break; } if (!strcmp(optarg, GABC_STR)) { input_format = GABC; break; } else { fprintf(stderr, "error: unknown input format: %s\n", optarg); print_short_usage(argv[0]); gregorio_exit(1); } break; case 's': /* input_file_name will be null here because of the way * we use getopt_long */ assert(!input_file_name); if (input_file) { /* means that stdin is defined */ fprintf(stderr, "warning: option used several times: %c\n", c); must_print_short_usage = true; break; } input_file = stdin; break; case 'h': print_usage(argv[0]); gregorio_exit(0); break; case 'V': gregorio_print_version(copyright); gregorio_exit(0); break; case 'v': if (verb_mode && verb_mode != VERBOSITY_WARNING) { fprintf(stderr, "warning: verbose option passed several times\n"); must_print_short_usage = true; break; } verb_mode = VERBOSITY_INFO; break; case 'W': if (verb_mode == VERBOSITY_WARNING) { fprintf(stderr, "warning: all-warnings option passed several times\n"); must_print_short_usage = true; break; } if (verb_mode != VERBOSITY_INFO) { verb_mode = VERBOSITY_WARNING; } break; case 'L': print_licence(); gregorio_exit(0); break; case 'p': if (point_and_click) { fprintf(stderr, "warning: point-and-click option passed several times\n"); must_print_short_usage = true; break; } point_and_click = true; break; case 'd': if (debug) { fprintf(stderr, "warning: debug option passed several times\n"); must_print_short_usage = true; break; } debug = true; break; case '?': must_print_short_usage = true; break; default: /* not reachable unless there's a programming error */ /* LCOV_EXCL_START */ gregorio_fail2(main, "unknown option: %c", c); print_short_usage(argv[0]); gregorio_exit(1); break; /* LCOV_EXCL_STOP */ } } /* end of while */ if (optind == argc) { if (!input_file) { /* input not undefined (could be stdin) */ fprintf(stderr, "%s: missing file operand.\n", argv[0]); print_short_usage(argv[0]); gregorio_exit(1); } } else { input_file_name = argv[optind++]; output_basename = get_base_filename(input_file_name); if (input_file) { fprintf(stderr, "warning: can't read from both stdin and a file, reading from %s\n", input_file_name); input_file = NULL; must_print_short_usage = true; } } if (optind < argc) { must_print_short_usage = true; fprintf(stderr, "ignored arguments:"); for (; optind < argc; ++optind) { fprintf(stderr, " %s", argv[optind]); } fprintf(stderr, "\n"); } if (must_print_short_usage) { print_short_usage(argv[0]); fprintf(stderr, "Proceeding anyway...\n"); } gregorio_set_debug_messages(debug); if (!input_format) { input_format = DEFAULT_INPUT_FORMAT; } if (!output_format) { output_format = DEFAULT_OUTPUT_FORMAT; } /* then we act... */ if (!output_file_name && !output_file) { if (!output_basename) { output_file = stdout; } else { switch (output_format) { case GABC: output_file_name = get_output_filename(output_basename, "gabc"); break; case GTEX: output_file_name = get_output_filename(output_basename, "gtex"); break; case DUMP: output_file_name = get_output_filename(output_basename, "dump"); break; default: /* not reachable unless there's a programming error */ /* LCOV_EXCL_START */ fprintf(stderr, "error: unsupported format"); print_short_usage(argv[0]); gregorio_exit(1); /* LCOV_EXCL_STOP */ } } } if (output_basename) { free(output_basename); } if (!output_file) { if (!input_file) { check_input_clobber(input_file_name, output_file_name); } gregorio_check_file_access(write, output_file_name, ERROR, gregorio_exit(1)); output_file = fopen(output_file_name, "wb"); if (!output_file) { fprintf(stderr, "error: can't write in file %s", output_file_name); gregorio_exit(1); } } /* we always have input_file or input_file_name */ if (input_file) { if (point_and_click) { fprintf(stderr, "warning: disabling point-and-click since reading from stdin\n"); } } else { gregorio_check_file_access(read, input_file_name, ERROR, gregorio_exit(1)); input_file = fopen(input_file_name, "r"); if (!input_file) { fprintf(stderr, "error: can't open file %s for reading\n", input_file_name); gregorio_exit(1); } if (point_and_click) { point_and_click_filename = encode_point_and_click_filename( input_file_name); } } if (!error_file_name) { error_file = stderr; gregorio_set_error_out(error_file); } else { gregorio_check_file_access(write, error_file_name, ERROR, gregorio_exit(1)); error_file = fopen(error_file_name, "wb"); if (!error_file) { fprintf(stderr, "error: can't open file %s for writing\n", error_file_name); gregorio_exit(1); } gregorio_set_error_out(error_file); } if (!verb_mode) { verb_mode = VERBOSITY_DEPRECATION; } gregorio_set_verbosity_mode(verb_mode); switch (input_format) { case GABC: score = gabc_read_score(input_file); break; default: /* not reachable unless there's a programming error */ /* LCOV_EXCL_START */ fprintf(stderr, "error : invalid input format\n"); fclose(input_file); fclose(output_file); gregorio_exit(1); break; /* LCOV_EXCL_STOP */ } fclose(input_file); if (score == NULL) { /* score should never be NULL on return from gabc_read_score */ /* LCOV_EXCL_START */ fclose(output_file); fprintf(stderr, "error in file parsing\n"); gregorio_exit(1); /* LCOV_EXCL_STOP */ } switch (output_format) { case GABC: gabc_write_score(output_file, score); break; case GTEX: gregoriotex_write_score(output_file, score, point_and_click_filename); break; case DUMP: dump_write_score(output_file, score); break; default: /* not reachable unless there's a programming error */ /* LCOV_EXCL_START */ fprintf(stderr, "error : invalid output format\n"); gregorio_free_score(score); fclose(output_file); gregorio_exit(1); break; /* LCOV_EXCL_STOP */ } fclose(output_file); if (point_and_click_filename) { free(point_and_click_filename); } gregorio_free_score(score); gregorio_vowel_tables_free(); gabc_score_determination_lex_destroy(); gabc_notes_determination_lex_destroy(); gregorio_vowel_rulefile_lex_destroy(); if (error_file_name) { fclose(error_file); } gregorio_exit(gregorio_get_return_value()); } /* due to exit on prior line, this will never be reached; LCOV_EXCL_LINE */
int shrinkage (char* const kind, list_t* list, int const sigma, double const th_3d, int const channel) { FILE* fd = 0; char outfile[40]; char path[30]; char ch; group_node_t* tmp = *list; block_node_t* group; unsigned int z; int count = 0; // obtain letter for channel ch = (channel==0) ? 'y' : (channel==1) ? 'u' : (channel==2) ? 'v' : 0; // determine path for file-writing sprintf (path, "dns/%s/%c/grp/", kind, ch); while (tmp != NULL) { group = tmp->group; z = group_length (&group); unsigned int len = group->block.block_size; double arr[z][len][len]; //obtain output filename if (get_output_filename (outfile, path, "group", "txt", ++count) != 0) { generate_error ("Unable to process output filename for group..."); return 1; } fd = fopen (outfile, "a"); if (fd == NULL) { generate_error ("Unable to open file for printing group..."); return 1; } // build a 3D-array from the actual group group2array (&group, len, z, arr); // append extracted group to log-file array2file (fd, len, z, arr, "extracted group"); // perform 3D transformation if necessary if (!strcmp(kind, "ht") || !strcmp(kind, "wnr")) { // perform 3D-DCT dct_3d (len, z, arr); // append transformed group to log-file array2file (fd, len, z, arr, "group after 3D-DCT transformation"); } // perform actual shrinkage operation if (!strcmp(kind, "avg")) { average_3d (len, z, arr); } else if (!strcmp(kind, "ht")) { hard_threshold_3d (len, z, arr, th_3d, sigma); } else if (!strcmp(kind, "wnr")) { wiener_3d (len, z, arr, sigma); } else if (!strcmp(kind, "none")) { // do nothing } else { generate_error ("Invalid kind of shrinkage..."); return 1; } // append thresholded group to log-file array2file (fd, len, z, arr, "group after 3D-shrinkage-operation"); // transform back if (!strcmp(kind, "ht") || !strcmp(kind, "wnr")) { // perform 3D-IDCT idct_3d (len, z, arr); // append inverse-transformed group to log-file array2file (fd, len, z, arr, "group after 3D-IDCT transformation"); } // write array data back to a list node array2group (&group, len, z, arr); // calculate the weights for the blocks of the actual group tmp->weight = get_weight (kind, len, z, arr); tmp = tmp->next; fclose (fd); } // probably need more variables in interface return 0; }
// Later we might want to move this to the SgProject or SgFile support class (generated by ROSETTA) void // unparseFile ( SgFile & file, UnparseFormatHelp *unparseHelp, UnparseDelegate* repl ) unparseFile ( SgFile* file, UnparseFormatHelp *unparseHelp, UnparseDelegate* unparseDelegate ) { // Call the unparser mechanism ROSE_ASSERT(file != NULL); // DQ (4/22/2006): This can be true when the "-E" option is used, but then we should not have called unparse()! ROSE_ASSERT(file->get_skip_unparse() == false); // If we did unparse an intermediate file then we want to compile that // file instead of the original source file. if (file->get_unparse_output_filename().empty() == true) { string outputFilename = "rose_" + file->get_sourceFileNameWithoutPath(); file->set_unparse_output_filename(outputFilename); ROSE_ASSERT (file->get_unparse_output_filename().empty() == false); // printf ("Inside of SgFile::unparse(UnparseFormatHelp*,UnparseDelegate*) outputFilename = %s \n",outputFilename.c_str()); } if (file->get_skip_unparse() == true) { // MS: commented out the following output } else { // Open the file where we will put the generated code string outputFilename = get_output_filename(*file); fstream ROSE_OutputFile(outputFilename.c_str(),ios::out); // all options are now defined to be false. When these options can be passed in // from the prompt, these options will be set accordingly. bool _auto = false; bool linefile = false; bool useOverloadedOperators = false; bool num = false; // It is an error to have this always turned off (e.g. pointer = this; will not unparse correctly) bool _this = true; bool caststring = false; bool _debug = false; bool _class = false; bool _forced_transformation_format = false; // control unparsing of include files into the source file (default is false) bool _unparse_includes = file->get_unparse_includes(); Unparser_Opt roseOptions( _auto, linefile, useOverloadedOperators, num, _this, caststring, _debug, _class, _forced_transformation_format, _unparse_includes ); int lineNumber = 0; // Zero indicates that ALL lines should be unparsed Unparser roseUnparser ( &ROSE_OutputFile, file->get_file_info()->get_filenameString(), roseOptions, lineNumber, unparseHelp, unparseDelegate ); // Location to turn on unparser specific debugging data that shows up in the output file // This prevents the unparsed output file from compiling properly! // ROSE_DEBUG = 0; // DQ (12/5/2006): Output information that can be used to colorize properties of generated code (useful for debugging). roseUnparser.set_embedColorCodesInGeneratedCode ( file->get_embedColorCodesInGeneratedCode() ); roseUnparser.set_generateSourcePositionCodes ( file->get_generateSourcePositionCodes() ); // information that is passed down through the tree (inherited attribute) // SgUnparse_Info inheritedAttributeInfo (NO_UNPARSE_INFO); SgUnparse_Info inheritedAttributeInfo; // Call member function to start the unparsing process // roseUnparser.run_unparser(); roseUnparser.unparseFile(file,inheritedAttributeInfo); // And finally we need to close the file (to flush everything out!) ROSE_OutputFile.close(); } }
void load_prev_binary_halos(int64_t snap, int64_t chunk, float *bounds, int64_t our_chunk) { FILE *input; char buffer[1024]; struct binary_output_header bh; struct halo h; int64_t remaining = 0, to_read, i,j, h_start = num_prev_halos; double v_to_dx; get_output_filename(buffer, 1024, snap, chunk, "bin"); input = check_fopen(buffer, "rb"); check_fread(&bh, sizeof(struct binary_output_header), 1, input); assert(bh.magic == ROCKSTAR_MAGIC); assert(bh.num_halos >= 0); assert(bh.num_particles >= 0); //Conversion in Comoving Mpc/h / (km/s) //Note that the time units are in 1/H = 1/(h*100 km/s/Mpc) v_to_dx = 0.01*(scale_to_time(SCALE_NOW) - scale_to_time(bh.scale)) / (0.5*(SCALE_NOW + bh.scale)); remaining = bh.num_halos; while (remaining > 0) { to_read = PREV_HALO_BUFFER_SIZE; if (to_read > remaining) to_read = remaining; check_fread(prev_halo_buffer, sizeof(struct halo), to_read, input); remaining -= to_read; for (i=0; i<to_read; i++) { for (j=0; j<3; j++) prev_halo_buffer[i].pos[j] += v_to_dx*prev_halo_buffer[i].pos[j+3]; h = prev_halo_buffer[i]; if (!bounds || _check_bounds(prev_halo_buffer[i].pos, h.pos, bounds) || our_chunk == chunk) add_to_previous_halos(&h, &bh); } } if (chunk == our_chunk) { hid_cache = check_realloc(hid_cache, sizeof(int64_t)*bh.num_particles, "Allocating halo id cache"); check_fread(hid_cache, sizeof(int64_t), bh.num_particles, input); for (i=h_start; i<num_prev_halos; i++) ph[i].file_offset = -1; } fclose(input); }