int main(int ac, char *av[]) { int i, j, k=-1, c, err=0, oclose=0; char *ifile=NULL, rdtok[MAXLABLEN], rdfile[MAXLABLEN]; FILE *fp, *ofp=stdout; TreePtr gtree=NULL, ttree=NULL; AlPtr align=NULL, zalign; SPConf peval=init_peval(); extern char *optarg; extern int optind; while ((c = getopt(ac, av, "p:a:F:v?")) != -1) switch (c) { case 'v': peval->verbose = 1; break; case 'p': peval->params=optarg; break; case 'F': ofp=myfopen(optarg,"w"); oclose=1; break; case '?': default: err++; } if (err || ac != optind+3) { fprintf(stderr, USAGE, av[0]); exit(1); } if (peval->params != NULL) config_peval(peval,&rdfile[0],&rdtok[0]); strcpy(peval->gfile,av[optind]); strcpy(peval->tfile,av[optind+1]); fp=myfopen(av[optind],"r"); while (fgets(rdfile,MAXLABLEN,fp) != NULL) { i=0; while (ws(rdfile[i])) i++; if (rdfile[i]=='\n') continue; gtree=load_tree(&rdfile[0],&rdtok[0],&i,NULL,NULL,peval,1,gtree,0,'g'); } fclose(fp); i=0; fp=myfopen(av[optind+1],"r"); while (fgets(rdfile,MAXLABLEN,fp) != NULL) { i=0; while (ws(rdfile[i])) i++; if (rdfile[i]=='\n') continue; ttree=load_tree(&rdfile[0],&rdtok[0],&i,NULL,NULL,peval,0,ttree,0,'t'); } fclose(fp); fp=myfopen(av[optind+2],"r"); align=get_rawalign(fp,&rdfile[0],&rdtok[0]); fclose(fp); get_strings(gtree,ttree,align, &rdtok[0],0); show_align(ofp,align,peval); if (oclose) fclose(ofp); }
void balanced_whole_shared_q(int method, int shuffle, int burnin, int samples, int lag, int treecount, char *outdir, int logging) { FILE *logfp; int treeindex, i; char methods[][16] = {"geographic", "genetic", "feature", "combination" }; char filename[1024]; node_t **trees = calloc(6, sizeof(node_t*)); node_t **subtrees = calloc(6, sizeof(node_t*)); mcmc_t mcmc; gslws_t *wses = calloc(6, sizeof(gslws_t)); sampman_t *sms = calloc(6, sizeof(sampman_t)); ubertree_t ut; // Open log file if(logging) { logfp = fopen("logfile", "w"); } else { logfp = fopen("/dev/null", "w"); } initialise_mcmc(&mcmc); initialise_ubertree(&ut); for(i=0; i<6; i++) { alloc_gslws(&wses[i]); initialise_sampman(&sms[i], outdir); sms[i].stability_sampling_rate = (treecount*samples) / 500; } // Loop over trees... for(treeindex=0; treeindex<treecount; treeindex++) { mcmc.dummy_tree_age = (55000+gsl_ran_gaussian(mcmc.r, 2500)) / 10000.0; /* Build tree(s) */ for(i=0; i<6; i++) load_tree(&trees[i], "../TreeBuilder/generated_trees/whole/", method, i, treeindex, shuffle); for(i=0; i<6; i++) load_tree(&subtrees[i], "../TreeBuilder/generated_trees/whole/", method, i, treeindex, shuffle); /* Draw samples for this tree (set) */ compute_balanced_multi_tree_probabilities(&mcmc, subtrees, wses); do_balanced_multi_tree_inference(logfp, &mcmc, subtrees, trees, wses, sms, &ut, burnin, samples, lag); /* Free up tree memory */ for(i=0; i<6; i++) free(trees[i]); } // Finish up for(i=0; i<6; i++) compute_means(&sms[i]); sprintf(filename, "%s/%s/", outdir, methods[method]); save_common_q(filename, sms); save_ubertree(&ut, filename); fclose(logfp); }
BOOL CMissionGoalsDlg::OnInitDialog() { int i, adjust = 0; CDialog::OnInitDialog(); // let the base class do the default work if (!Show_sexp_help) adjust = -SEXP_HELP_BOX_SIZE; theApp.init_window(&Mission_goals_wnd_data, this, adjust); m_goals_tree.setup((CEdit *) GetDlgItem(IDC_HELP_BOX)); load_tree(); create_tree(); if (m_num_goals >= MAX_GOALS) GetDlgItem(IDC_BUTTON_NEW_GOAL)->EnableWindow(FALSE); Goal_editor_dlg = this; i = m_goals_tree.select_sexp_node; if (i != -1) { GetDlgItem(IDC_GOALS_TREE) -> SetFocus(); m_goals_tree.hilite_item(i); return FALSE; } return TRUE; }
int main(int argc, char** argv) { srand(time(NULL)); if(argc != 4 || !argv || !argv[1] || !argv[2] || !argv[3]) { printf("usage: makenoncolliding <input> <output> <number of addresses>\n"); return 1; } output_fd = open(argv[2], O_TRUNC | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); uint32_t tree1_size; uint32_t tree2_size = atoi(argv[3]); uint32_t* addrs = malloc(tree2_size * sizeof(uint32_t)); ip_tree_t* tree1 = load_tree(argv[1],&tree1_size); ip_tree_t* tree2 = make_nonintersecting_tree(tree1,tree1_size,&tree2_size); uint32_t real_size = iptree_get_sorted(tree2,addrs); write(output_fd,&real_size,sizeof(uint32_t)); for(uint32_t i = 0; i < real_size; i++) { buffered_writer(addrs[i],0); } buffered_writer(0,1); close(output_fd); return 0; }
int main(int argc, char* argv[]){ Tree mt1,mt2,mt3; mt1 = mkEmptyTree(); mt2 = mkEmptyTree(); if (isEmpty(mt1)) printf("mt1 empty\n"); mt3 = cons(42,mt1,mt2); print_lvr(mt3); printf("\n -- \n"); FILE* fp = fopen(argv[1],"r"); Tree abr1= mkEmptyTree(); load_tree(fp, &abr1); //Only values print_lvr(abr1); printf("\n -- \n"); //father->son print_couple(abr1); //print_rec_edges(abr1); printf("\n -- \n"); return 0; }
WTree * tree_new (int y, int x, int lines, int cols, gboolean is_panel) { WTree *tree; Widget *w; tree = g_new (WTree, 1); w = WIDGET (tree); widget_init (w, y, x, lines, cols, tree_callback, tree_event); tree->is_panel = is_panel; tree->selected_ptr = 0; tree->store = tree_store_get (); tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; tree->search_buffer[0] = 0; tree->topdiff = w->lines / 2; tree->searching = 0; tree->active = 0; /* We do not want to keep the cursor */ widget_want_cursor (w, FALSE); load_tree (tree); return tree; }
void load(std::string url, ForestParam tp, int max_trees = -1) { param = tp; if (max_trees == -1) max_trees = tp.nTrees; std::cout << tp.nTrees << " to load." << std::endl; for (int i = 0; i < tp.nTrees; i++) { if (static_cast<int>(trees.size()) > max_trees) continue; char buffer[200]; sprintf(buffer, "%s%03d.txt", url.c_str(), i); std::string tree_path = buffer; load_tree(tree_path, trees); } std::cout << trees.size() << " trees loaded" << std::endl; }
void draw_histogram(TH1F * const h, const particle_type p, const int energy_level_gev, const detector d) { h->SetName(generate_histogram_name(p, energy_level_gev, d)); TTree *const t = load_tree(generate_file_path(p, energy_level_gev, d), "ntp_cluster"); fill_histogram(h, t, 0.3); h->Scale(1 / h->GetEntries()); h->GetYaxis()->SetRangeUser(0.0001, 10); h->SetXTitle("E_{cluster} (GeV)"); h->SetYTitle("entries / #scale[0.5]{#sum} entries "); h->Draw("SAME"); }
void whole_indiv_q(int method, int shuffle, int burnin, int samples, int lag, int treecount, char *outdir, int logging) { FILE *logfp; uint8_t family; int treeindex; char filename[1024]; char families[][16] = {"afro", "austro", "indo", "niger", "nilo", "sino", "tng", "amer"}; char types[][16] = {"geographic", "genetic", "feature", "combination" }; node_t *tree; mcmc_t mcmc; gslws_t ws; sampman_t sm; // Open log file if(logging) { logfp = fopen("logfile", "w"); } else { logfp = fopen("/dev/null", "w"); } initialise_mcmc(&mcmc); initialise_sampman(&sm, outdir); alloc_gslws(&ws); // Compute stability sampling rate sm.stability_sampling_rate = (treecount*samples) / 500; // Loop over families for(family=0; family<NUM_TREES; family++) { reset_sampman(&sm); // Loop over trees for(treeindex=0; treeindex<treecount; treeindex++) { /* Build tree */ load_tree(&tree, "../TreeBuilder/generated_trees/whole/", method, family, treeindex, shuffle); /* Draw samples for this tree (set) */ compute_single_tree_probabilities(&mcmc, tree, &ws); do_single_tree_inference(logfp, &mcmc, tree, &ws, &sm, burnin, samples, lag); /* Free up tree memory */ free(tree); } // Finish up compute_means(&sm); sprintf(filename, "%s/%s/%s/", outdir, types[method], families[family]); save_indiv_q(filename, &sm); } fclose(logfp); }
void campaign_editor::load_campaign() { Cur_campaign_mission = Cur_campaign_link = -1; load_tree(0); if (!strlen(Campaign.filename)) strcpy(Campaign.filename, BUILTIN_CAMPAIGN); if (mission_campaign_load(Campaign.filename, 0)) { MessageBox("Couldn't open Campaign file!", "Error"); Campaign_wnd->OnCpgnFileNew(); return; } Campaign_modified = 0; Campaign_tree_viewp->construct_tree(); initialize(); }
void campaign_editor::initialize( int init_files ) { Cur_campaign_mission = Cur_campaign_link = -1; m_tree.setup((CEdit *) GetDlgItem(IDC_HELP_BOX)); load_tree(0); Campaign_tree_viewp->initialize(); // only initialize the file dialog box when the parameter says to. This should // only happen when a campaign type changes if ( init_files ){ m_filelist.initialize(); } m_name = Campaign.name; m_type = Campaign.type; m_num_players.Format("%d", Campaign.num_players); if (Campaign.desc) { convert_multiline_string(m_desc, Campaign.desc); } else { m_desc = _T(""); } m_branch_desc = _T(""); m_branch_brief_anim = _T(""); m_branch_brief_sound = _T(""); // single player should hide the two dialog items about number of players allowed if ( m_type == CAMPAIGN_TYPE_SINGLE ) { GetDlgItem(IDC_NUM_PLAYERS)->ShowWindow( SW_HIDE ); GetDlgItem(IDC_PLAYERS_LABEL)->ShowWindow( SW_HIDE ); } else { GetDlgItem(IDC_NUM_PLAYERS)->ShowWindow( SW_SHOW ); GetDlgItem(IDC_PLAYERS_LABEL)->ShowWindow( SW_SHOW ); } // set up the tech db checkbox m_custom_tech_db = (BOOL)(Campaign.flags & CF_CUSTOM_TECH_DATABASE); UpdateData(FALSE); }
SEXP vlmc_sim(SEXP vlmc_R, SEXP nsim_) { /* Given a fitted VLMC (with |alphabet| = m), simulate a new series y[1..N], where N = data_len */ int N = asInteger(nsim_), next_ind = 0, nprot = 1; if (!isInteger(vlmc_R)) { vlmc_R = PROTECT(coerceVector(vlmc_R, INTSXP)); nprot++; } SEXP res = PROTECT(allocVector(INTSXP, N)); // the result int *y = INTEGER(res), m = INTEGER(vlmc_R)[0]; // = |alphabet| node_t *top = load_tree(INTEGER(vlmc_R), &next_ind, LENGTH(vlmc_R), /*level*/ 0, /*Debug*/ 0); GetRNGstate(); for (int i = 0; i < N; i++) { /* Find the context, descending the tree, given y[i-1], y[i-2],... : */ node_t *this, *temp; int j; for (j = 1, this = top; j <= i && (temp = this->child[y[i - j]]) != NULL; j++, this = temp) ; int count = 0; double r = (double) this->total * unif_rand(); for (j = 0; j < m; j++) { count += this->count[j]; if (r <= count) { y[i] = j; break; } } } PutRNGstate(); free_node(top);/* do not leak ! */ UNPROTECT(nprot); return res; }
WTree * tree_new (int is_panel, int y, int x, int lines, int cols) { WTree *tree = g_new (WTree, 1); init_widget (&tree->widget, y, x, lines, cols, tree_callback, event_callback); tree->is_panel = is_panel; tree->selected_ptr = 0; tree->store = tree_store_get (); tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; tree->search_buffer[0] = 0; tree->topdiff = tree->widget.lines / 2; tree->searching = 0; tree->active = 0; /* We do not want to keep the cursor */ widget_want_cursor (tree->widget, 0); load_tree (tree); return tree; }
WTree * tree_new (int y, int x, int lines, int cols, gboolean is_panel) { WTree *tree; Widget *w; tree = g_new (WTree, 1); w = WIDGET (tree); widget_init (w, y, x, lines, cols, tree_callback, tree_mouse_callback); w->options |= WOP_SELECTABLE | WOP_TOP_SELECT; tree->is_panel = is_panel; tree->selected_ptr = 0; tree->store = tree_store_get (); tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; tree->search_buffer[0] = 0; tree->topdiff = w->lines / 2; tree->searching = 0; load_tree (tree); return tree; }
/**@brief Main routine of L-Galaxies*/ int main(int argc, char **argv) { int filenr, *FileToProcess, *TaskToProcess, nfiles; char buf[1000]; time_t start, current; //Catch floating point exceptions #ifdef DEBUG #endif #ifdef PARALLEL MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask); MPI_Comm_size(MPI_COMM_WORLD, &NTask); #else NTask = 1; ThisTask = 0; #endif //PARALLEL #ifdef MCMC time(&global_starting_time); #endif if(argc > 3) { printf("\n usage: L-Galaxies <parameterfile>\n\n"); endrun(0); } if (ThisTask == 0) printf("%s\n",COMPILETIMESETTINGS); /*Reads the parameter file, given as an argument at run time. */ read_parameter_file(argv[1]); #ifdef MR_PLUS_MRII //Start with MR files and later change to MRII LastDarkMatterSnapShot=LastDarkMatterSnapShot_MR; sprintf(FileWithZList, "%s", FileWithZList_MR); sprintf(FileWithZList_OriginalCosm, "%s", FileWithZList_OriginalCosm_MR); #endif mymalloc_init(); sprintf(FinalOutputDir, "%s", OutputDir); if(argc == 3) sprintf(OutputDir, "%s", argv[2]); //time(&start); /* check compatibility of some Makefile Options*/ check_options(); #ifdef COMPUTE_SPECPHOT_PROPERTIES //for dust_model mu_seed = -150; #endif init(); #ifdef STAR_FORMATION_HISTORY #ifdef PARALLEL if(ThisTask == 0) #endif write_sfh_bins(); #endif #ifdef MCMC #ifdef PARALLEL /* a small delay to avoid all processors reading trees at the same time*/ time(&start); do time(¤t); while(difftime(current, start) < 10.0 * ThisTask); #endif #endif #ifndef MCMC nfiles=get_nr_files_to_process(ThisTask); FileToProcess=mymalloc("FileToProcess", sizeof(int) * nfiles); TaskToProcess=mymalloc("TaskToProcess", sizeof(int) * nfiles); assign_files_to_tasks(FileToProcess, TaskToProcess, ThisTask, NTask, nfiles); int file; for(file = 0; file < nfiles; file++) { if(ThisTask==TaskToProcess[file]) filenr=FileToProcess[file]; else continue; #else //MCMC /* In MCMC mode only one file is loaded into memory * and the sampling for all the steps is done on it */ sprintf(SimulationDir, "%s/MergerTrees_%d/", SimulationDir, ThisTask); for(filenr = MCMCTreeSampleFile; filenr <= MCMCTreeSampleFile; filenr++) { #endif //MCMC time(&start); #ifdef READXFRAC get_xfrac_mesh(); #endif load_tree_table(filenr); /* Read in mesh dimensions */ #ifdef MCMC #ifdef PARALLEL time_t start, start2; /* a small delay to reset processors to the same time*/ time(&start2); do time(¤t); while(difftime(current, start2) < 10.0 * (NTask-ThisTask)); #endif Senna(); // run the model in MCMC MODE #else SAM(filenr); // run the model in NORMAL MODE #endif #ifdef MCMC break; //break loop on files since the MCMC is done on a single file #else time(¤t); printf("\ndone tree file %d in %ldmin and %lds\n\n", filenr, (current - start)/60, (current - start)%60); #endif //MCMC free_tree_table(); //if temporary directory given as argument if(argc == 3) { #ifdef GALAXYTREE sprintf(buf, "mv %s/%s_galtree_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir); #else sprintf(buf, "mv %s/%s_z*_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir); #endif system(buf); } } #ifndef MCMC myfree(TaskToProcess); myfree(FileToProcess); #endif #ifdef PARALLEL MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); #endif return 0; } /**@brief SAM() loops on trees and calls construct_galaxies.*/ #ifdef MCMC double SAM(int filenr) #else void SAM(int filenr) #endif { int treenr, halonr; time_t t_mark_a, t_mark_b; #ifdef MCMC int ii; MCMC_GAL = mymalloc("MCMC_Gal", sizeof(struct MCMC_GALAXY) * MCMCAllocFactor); for(ii=0;ii<NOUT;ii++) TotMCMCGals[ii] = 0; if(Sample_Cosmological_Parameters==1) { reset_cosmology (); #ifdef HALOMODEL initialize_halomodel(); #endif } #ifdef MR_PLUS_MRII change_dark_matter_sim("MR"); #else if(Sample_Cosmological_Parameters==1 || CurrentMCMCStep==1) read_sample_info(); else { int snap, ii; for(snap=0;snap<NOUT;snap++) for(ii=0;ii<NFofsInSample[snap];ii++) MCMC_FOF[ii].NGalsInFoF[snap]=0; } #endif #endif //to be used when we have tables for the scaling in any cosmology //read_scaling_parameters(); #ifndef MCMC #ifdef GALAXYTREE create_galaxy_tree_file(filenr); #else create_galaxy_files(filenr); #endif #ifdef ALL_SKY_LIGHTCONE int nr; for ( nr = 0; nr < NCONES; nr++) create_galaxy_lightcone_files(filenr, nr); #endif #endif #ifdef GALAXYTREE FILE *fdg = fopen("treengal.dat", "w"); #endif //*************************************************************************************** //*************************************************************************************** //for(treenr = 0; treenr < NTrees_Switch_MR_MRII; treenr++) //for(treenr = NTrees_Switch_MR_MRII; treenr < Ntrees; treenr++) /* Scan through all trees snapshot by snapshot */ int snapnum; //for(treenr = 0; treenr < NTrees_Switch_MR_MRII; treenr++) //for(treenr = NTrees_Switch_MR_MRII; treenr < Ntrees; treenr++) for(treenr = 0; treenr < Ntrees; treenr++) //for(treenr = 0; treenr < 1;treenr++) { //printf("doing tree %d of %d\n", treenr, Ntrees); #ifdef MR_PLUS_MRII if(treenr == NTrees_Switch_MR_MRII) change_dark_matter_sim("MRII"); #endif load_tree(treenr); #ifdef MCMC #ifdef PRELOAD_TREES if(Sample_Cosmological_Parameters==1 || CurrentMCMCStep==0) #endif #endif scale_cosmology(TreeNHalos[treenr]); gsl_rng_set(random_generator, filenr * 100000 + treenr); NumMergers = 0; NHaloGal = 0; #ifdef GALAXYTREE NGalTree = 0; IndexStored = 0; #endif //LastSnapShotNr is the highest output snapshot /* we process the snapshots now in temporal order * (as a means to reduce peak memory usage) */ for(snapnum = 0; snapnum <= LastSnapShotNr; snapnum++) //for(snapnum = 0; snapnum <= 30; snapnum++) { #ifdef MCMC /* read the appropriate parameter list for current snapnum * into the parameter variables to be used in construct_galaxies */ read_mcmc_par(snapnum); #else //used to allow parameter values to vary with redshift //re_set_parameters(snapnum); #endif //printf("doing snap=%d\n",snapnum); for(halonr = 0; halonr < TreeNHalos[treenr]; halonr++) if(HaloAux[halonr].DoneFlag == 0 && Halo[halonr].SnapNum == snapnum) construct_galaxies(filenr, treenr, halonr); } /* output remaining galaxies as needed */ while(NHaloGal) output_galaxy(treenr, 0); #ifndef MCMC #ifdef GALAXYTREE save_galaxy_tree_finalize(filenr, treenr); #ifndef PARALLEL if((treenr/100)*100==treenr) printf("treenr=%d TotGalCount=%d\n", treenr, TotGalCount); #endif fflush(stdout); fprintf(fdg, "%d\n", NGalTree); #endif #else//ifdef MCMC #ifdef PRELOAD_TREES if(Sample_Cosmological_Parameters==1) un_scale_cosmology(TreeNHalos[treenr]); #endif #endif free_galaxies_and_tree(); } #ifdef MCMC double lhood = get_likelihood(); #ifdef MR_PLUS_MRII free(MCMC_FOF); #else if(Sample_Cosmological_Parameters==1 || CurrentMCMCStep==ChainLength) free(MCMC_FOF); #endif #ifdef HALOMODEL if (Sample_Cosmological_Parameters==1) { gsl_spline_free(FofSpline); gsl_interp_accel_free(FofAcc); gsl_spline_free(SigmaSpline); gsl_interp_accel_free(SigmaAcc); gsl_spline_free(ellipSpline); gsl_interp_accel_free(ellipAcc); gsl_spline_free(PowSpline); } //if #endif myfree(MCMC_GAL); return lhood; #else //MCMC #ifdef GALAXYTREE close_galaxy_tree_file(); #else close_galaxy_files(); #endif #ifdef ALL_SKY_LIGHTCONE for (nr = 0; nr < NCONES; nr++) close_galaxy_lightcone_files(nr); #endif return; #endif }
/**@brief Main routine of L-Galaxies*/ int main(int argc, char **argv) { int filenr, *FileToProcess, *TaskToProcess, nfiles; char buf[1000]; time_t start, current; #ifdef PARALLEL MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask); MPI_Comm_size(MPI_COMM_WORLD, &NTask); #else NTask = 1; ThisTask = 0; #endif //PARALLEL #ifdef MCMC time(&global_starting_time); #endif if(ThisTask==0) { printf("\n\n\n"); printf("**************************************************************************\n"); printf("* *\n"); printf("* Copyright (C) <2016> <L-Galaxies> *\n"); printf("* *\n"); printf("* This program is free software: you can redistribute it and/or modify *\n"); printf("* it under the terms of the GNU General Public License as published by *\n"); printf("* the Free Software Foundation, either version 3 of the License, or *\n"); printf("* (at your option) any later version. *\n"); printf("* *\n"); printf("* This program is distributed in the hope that it will be useful, *\n"); printf("* but WITHOUT ANY WARRANTY; without even the implied warranty of *\n"); printf("* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *\n"); printf("* GNU General Public License for more details. *\n"); printf("* *\n"); printf("* You should have received a copy of the GNU General Public License *\n"); printf("* along with this program. If not, see <http://www.gnu.org/licenses/> *\n"); printf("* *\n"); printf("**************************************************************************\n\n\n"); } if(argc > 3 || argc<2) { printf("\n Wrong number of runtime arguments\n\n"); printf("\n usage: ./L-Galaxies <parameterfile>\n\n"); endrun(0); } if (ThisTask == 0) printf("%s\n",COMPILETIMESETTINGS); /* check compatibility of some Makefile Options*/ check_options(); /*Reads the parameter file, given as an argument at run time. */ read_parameter_file(argv[1]); #ifdef MR_PLUS_MRII //Start with MR files and later change to MRII LastDarkMatterSnapShot=LastDarkMatterSnapShot_MR; sprintf(FileWithZList, "%s", FileWithZList_MR); sprintf(FileWithZList_OriginalCosm, "%s", FileWithZList_OriginalCosm_MR); #endif mymalloc_init(); sprintf(FinalOutputDir, "%s", OutputDir); #ifndef MCMC if(argc == 3) sprintf(OutputDir, "%s", argv[2]); #else FirstChainNumber=0; if(argc == 3) FirstChainNumber=atoi(argv[2]); #endif //time(&start); #ifdef COMPUTE_SPECPHOT_PROPERTIES //for dust_model mu_seed = -150; #endif init(); #ifdef STAR_FORMATION_HISTORY #ifdef PARALLEL if(ThisTask == 0) #endif write_sfh_bins(); #endif #ifndef MCMC nfiles=get_nr_files_to_process(ThisTask); FileToProcess=mymalloc("FileToProcess", sizeof(int) * nfiles); TaskToProcess=mymalloc("TaskToProcess", sizeof(int) * nfiles); assign_files_to_tasks(FileToProcess, TaskToProcess, ThisTask, NTask, nfiles); int file; for(file = 0; file < nfiles; file++) { if(ThisTask==TaskToProcess[file]) filenr=FileToProcess[file]; else continue; #else //MCMC /* In MCMC mode only one file is loaded into memory * and the sampling for all the steps is done on it */ sprintf(SimulationDir, "%s/", SimulationDir); for(filenr = MCMCTreeSampleFile; filenr <= MCMCTreeSampleFile; filenr++) { #endif //MCMC time(&start); #ifdef PARALLEL #ifndef MCMC time_t current; do time(¤t); //while(difftime(current, start) < 5.0 * ThisTask); while(difftime(current, start) < 1.0 * ThisTask); #endif #endif load_tree_table(filenr); #ifdef MCMC Senna(); // run the model in MCMC MODE #else SAM(filenr); // run the model in NORMAL MODE #endif #ifdef MCMC break; //break loop on files since the MCMC is done on a single file #else time(¤t); printf("\ndone tree file %d in %ldmin and %lds\n\n", filenr, (current - start)/60, (current - start)%60); #endif //MCMC free_tree_table(); //if temporary directory given as argument if(argc == 3) { #ifdef GALAXYTREE sprintf(buf, "mv %s/%s_galtree_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir); #else sprintf(buf, "mv %s/%s_z*_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir); #endif system(buf); } } #ifndef MCMC myfree(TaskToProcess); myfree(FileToProcess); #endif #ifdef PARALLEL MPI_Finalize(); #endif return 0; } /**@brief SAM() loops on trees and calls construct_galaxies.*/ #ifdef MCMC double SAM(int filenr) #else void SAM(int filenr) #endif { int treenr, halonr; #ifdef MCMC int ii; MCMC_GAL = mymalloc("MCMC_Gal", sizeof(struct MCMC_GALAXY) * MCMCAllocFactor); for(ii=0;ii<NOUT;ii++) TotMCMCGals[ii] = 0; #ifdef MR_PLUS_MRII change_dark_matter_sim("MR"); #else if(CurrentMCMCStep==1) read_sample_info(); #ifdef HALOMODEL else { int snap, ii; for(snap=0;snap<NOUT;snap++) for(ii=0;ii<NFofsInSample[snap];ii++) MCMC_FOF[ii].NGalsInFoF[snap]=0; } #endif //HALOMODEL #endif //MR_PLUS_MRII #endif //MCMC //to be used when we have tables for the scaling in any cosmology //read_scaling_parameters(); #ifndef MCMC #ifdef GALAXYTREE create_galaxy_tree_file(filenr); #else create_galaxy_files(filenr); #endif #endif #ifdef GALAXYTREE FILE *fdg = fopen("treengal.dat", "w"); #endif //*************************************************************************************** //*************************************************************************************** //for(treenr = 0; treenr < NTrees_Switch_MR_MRII; treenr++) for(treenr = 0; treenr < Ntrees; treenr++) { //printf("doing tree %d of %d\n", treenr, Ntrees); #ifdef MR_PLUS_MRII if(treenr == NTrees_Switch_MR_MRII) change_dark_matter_sim("MRII"); #endif load_tree(treenr); #ifdef MCMC #ifdef PRELOAD_TREES if(CurrentMCMCStep==1) #endif #endif scale_cosmology(TreeNHalos[treenr]); gsl_rng_set(random_generator, filenr * 100000 + treenr); NumMergers = 0; NHaloGal = 0; #ifdef GALAXYTREE NGalTree = 0; IndexStored = 0; #endif int snapnum; //LastSnapShotNr is the highest output snapshot /* we process the snapshots now in temporal order * (as a means to reduce peak memory usage) */ for(snapnum = 0; snapnum <= LastSnapShotNr; snapnum++) { #ifdef MCMC /* read the appropriate parameter list for current snapnum * into the parameter variables to be used in construct_galaxies */ read_mcmc_par(snapnum); #ifdef HALOMODEL //because we need halo masses even for FOFs //with no galaxies it needs to be done here assign_FOF_masses(snapnum, treenr); #endif #endif for(halonr = 0; halonr < TreeNHalos[treenr]; halonr++) if(HaloAux[halonr].DoneFlag == 0 && Halo[halonr].SnapNum == snapnum) construct_galaxies(filenr, treenr, halonr); } /* output remaining galaxies as needed */ while(NHaloGal) output_galaxy(treenr, 0); #ifndef MCMC #ifdef GALAXYTREE save_galaxy_tree_finalize(filenr, treenr); #ifndef PARALLEL if((treenr/100)*100==treenr) printf("treenr=%d TotGalCount=%d\n", treenr, TotGalCount); #endif fflush(stdout); fprintf(fdg, "%d\n", NGalTree); #endif #else//ifdef MCMC #endif free_galaxies_and_tree(); }//loop on trees #ifdef MCMC double lhood = get_likelihood(); #ifdef MR_PLUS_MRII free(MCMC_FOF); #else if(CurrentMCMCStep==ChainLength) free(MCMC_FOF); #endif myfree(MCMC_GAL); return lhood; #else //MCMC #ifdef GALAXYTREE close_galaxy_tree_file(); #else close_galaxy_files(); #endif return; #endif }
void split_shared_q(int method, int shuffle, int burnin, int samples, int lag, int treecount, char *outdir, int logging) { FILE *logfp; FILE *correlfp; int treeindex, i, j, k; char filename[1024]; char methods[][16] = {"geographic", "genetic", "feature", "combination" }; node_t **trees1 = calloc(NUM_TREES, sizeof(node_t*)); node_t **subtrees1 = calloc(NUM_TREES, sizeof(node_t*)); node_t **trees2 = calloc(NUM_TREES, sizeof(node_t*)); node_t **subtrees2 = calloc(NUM_TREES, sizeof(node_t*)); mcmc_t mcmc1, mcmc2; gslws_t *wses1 = calloc(NUM_TREES, sizeof(gslws_t)); gslws_t *wses2 = calloc(NUM_TREES, sizeof(gslws_t)); sampman_t *sms1 = calloc(NUM_TREES, sizeof(sampman_t)); sampman_t *sms2 = calloc(NUM_TREES, sizeof(sampman_t)); gsl_matrix *q1 = gsl_matrix_alloc(6, 6); gsl_matrix *q2 = gsl_matrix_alloc(6, 6); double qcorrel1[6*NUM_TREES], qcorrel2[6*NUM_TREES]; double anccorrel1[6*NUM_TREES], anccorrel2[6*NUM_TREES]; double qcorrelation = 0; double anccorrelation = 0; // Open log file if(logging) { logfp = fopen("logfile", "w"); } else { logfp = fopen("/dev/null", "w"); } initialise_mcmc(&mcmc1); initialise_mcmc(&mcmc2); for(i=0; i<NUM_TREES; i++) { alloc_gslws(&wses1[i]); alloc_gslws(&wses2[i]); initialise_sampman(&sms1[i], outdir); initialise_sampman(&sms2[i], outdir); // Compute stability sampling rate sms1[i].stability_sampling_rate = (treecount*samples) / 500.0; sms2[i].stability_sampling_rate = (treecount*samples) / 500.0; } // Loop over trees... for(treeindex=0; treeindex<treecount; treeindex++) { /* Build tree(s) */ for(i=0; i<NUM_TREES; i++) { load_tree(&trees1[i], "../TreeBuilder/generated_trees/split/1/", method, i, treeindex, shuffle); load_tree(&subtrees1[i], "../TreeBuilder/generated_trees/split/1/", method, i, treeindex, shuffle); load_tree(&trees2[i], "../TreeBuilder/generated_trees/split/2/", method, i, treeindex, shuffle); load_tree(&subtrees2[i], "../TreeBuilder/generated_trees/split/2/", method, i, treeindex, shuffle); } /* Draw samples for this tree (set) */ compute_multi_tree_probabilities(&mcmc1, subtrees1, wses1); compute_multi_tree_probabilities(&mcmc2, subtrees2, wses2); /* Burn in */ for(i=0; i<burnin; i++) { multi_tree_mcmc_iteration(logfp, &mcmc1, subtrees1, wses1); multi_tree_mcmc_iteration(logfp, &mcmc2, subtrees2, wses2); } gsl_matrix_set_zero(q1); gsl_matrix_set_zero(q2); memset(anccorrel1, 0, 6*NUM_TREES*sizeof(double)); memset(anccorrel2, 0, 6*NUM_TREES*sizeof(double)); /* Take samples */ for(i=0; i<samples; i++) { if(gsl_rng_uniform_int(mcmc1.r, 10000) >= 9999) { /* Random restart! */ random_restart(&mcmc1); random_restart(&mcmc2); compute_multi_tree_probabilities(&mcmc1, subtrees1, wses1); compute_multi_tree_probabilities(&mcmc2, subtrees2, wses2); for(j=0; j<burnin; j++) { multi_tree_mcmc_iteration(logfp, &mcmc1, subtrees1, wses1); multi_tree_mcmc_iteration(logfp, &mcmc2, subtrees2, wses2); } } for(j=0; j<lag; j++) { multi_tree_mcmc_iteration(logfp, &mcmc1, subtrees1, wses1); multi_tree_mcmc_iteration(logfp, &mcmc2, subtrees2, wses2); } build_q(&mcmc1); build_q(&mcmc2); for(j=0; j<NUM_TREES; j++) { upwards_belprop(logfp, trees1[j], mcmc1.Q, &wses1[j]); upwards_belprop(logfp, trees2[j], mcmc2.Q, &wses2[j]); process_sample(&sms1[j], &mcmc1, &wses1[j], trees1[j]); process_sample(&sms2[j], &mcmc2, &wses2[j], trees2[j]); } /* Combine Q samples for this tree pair */ gsl_matrix_add(q1, mcmc1.Q); gsl_matrix_add(q2, mcmc2.Q); for(j=0; j<NUM_TREES; j++) { for(k=0; k<6; k++) { anccorrel1[j*6+k] += trees1[j]->dist[k]; anccorrel2[j*6+k] += trees2[j]->dist[k]; } } } gsl_matrix_scale(q1, 1.0 / samples); gsl_matrix_scale(q2, 1.0 / samples); for(i=0; i<NUM_TREES; i++) { for(j=0; j<6; j++) { qcorrel1[i*6+j] = gsl_matrix_get(q1, i, j); qcorrel2[i*6+j] = gsl_matrix_get(q2, i, j); anccorrel1[i*6+j] /= (1.0*samples); anccorrel2[i*6+j] /= (1.0*samples); } } qcorrelation += gsl_stats_correlation(qcorrel1, 1, qcorrel2, 1, 36); anccorrelation += gsl_stats_correlation(anccorrel1, 1, anccorrel2, 1, 36); /***************************************************/ /* Free up tree memory */ for(i=0; i<NUM_TREES; i++) { free(trees1[i]); free(subtrees1[i]); free(trees2[i]); free(subtrees2[i]); } } qcorrelation /= treecount; anccorrelation /= treecount; // Finish up for(i=0; i<NUM_TREES; i++) { compute_means(&sms1[i]); compute_means(&sms2[i]); } sprintf(filename, "%s/%s/", outdir, methods[method]); strcat(filename, "/left-half/"); save_common_q(filename, sms1); sprintf(filename, "%s/%s/", outdir, methods[method]); strcat(filename, "/right-half/"); save_common_q(filename, sms2); sprintf(filename, "%s/%s/correlations", outdir, methods[method]); correlfp = fopen(filename, "w"); fprintf(correlfp, "Q: %f\n", qcorrelation); fprintf(correlfp, "Anc: %f\n", anccorrelation); fclose(correlfp); fclose(logfp); }
/* This is the C-like version : */ void predict_vlmc(int vlmc_vec[], int size_vlmc, int m, /* = alpha_len */ int data[], int data_len, vlmc_pred_type pred_kind, /* Output : prb_mat[] only if pred_kind has "probs" */ int result[], int flags[], double prb_mat[]) { /* ================================================================= Given a fitted VLMC (with |alphabet| = m) and new data Y[1..N], / pred_kind & PROBS (= ..0001 ) return the prediction probabilities of Y[2]..Y[N] xor (based on past = relevant context) as (N-1) x m matrix \ pred_kind & CLASS (= ..0010 ) return the most probably class (i.e. "fitted response") and/or / pred_kind & ID (= ..0100 ) xor return the "ID" of the node / context / MC state at that observation. \ pred_kind & LEVEL (= ..1000 ) return the level / depth of the MC state, i.e., the context length at that observation * ================================================================= TODO : - Allow "marginal" prediction [only for "probs" and "response"] for initial values, instead of NAs */ int i, j, k, level, ct, ctotal, n = data_len; int next_ind = 0; node_t *top, *q1, *q2, *current; #define Pmat(i,k) prb_mat[i + k * n] /* FIXME: Use functions instead of MACROs (?!) ----- Would need to access prb_mat[] / result[] and pass (i,m) additionally */ #define COMP_Pmat(qnode) \ ctotal = 0; \ for (k = 0; k < m; k++) \ ctotal += qnode->count[k]; \ if(ctotal > 0) \ for (k = 0; k < m; k++) \ Pmat(i,k) = (double) (qnode->count[k])/ctotal #define COMP_Max(qnode) \ j = 0; \ ct = qnode->count[0]; \ for (k = 1; k < m; k++) \ if(ct < qnode->count[k]) { \ j = k ; ct = qnode->count[j]; \ } \ if(ct > 0) \ result[i] = j /* in 0..(m-1) */ /* FIXME : Much Smarter and more efficient : * ----- Each node should have a "cumulated-counts" slot * which would be NULL initially and only filled * (using a version of cumulate()) when needed !! */ #define COMP_00(COMP_MACRO_CALL) \ flags[i] += 10; \ if(0) \ Rprintf2("pred(type=P./C.), data[i=%d] = %d\n", \ i, data[i]); \ current = copy_tree(q1, /*fill = */ 1); \ cumulate(current); \ /*----- --> ../../util.c */ \ COMP_MACRO_CALL; \ else { /* never seen till now */ \ flags[i] += 1; \ } \ free_node(current); /* effectively, the first row, prb_mat[0,] should remain untouched */ top = load_tree(vlmc_vec, &next_ind, size_vlmc, /*level*/0, /*Debug*/0); /* --------- -> ./saveload.c */ q2 = current = NULL;/* for -Wall */ /* i=1.. : don't touch result[0] & Pmat(0,*) */ for (i = 1; i < n; i++) { /* Find the context, descending the tree, given y[i-1], y[i-2],... :*/ int di; for (q1 = top, level = 1; level <= i && // ensure that child[.] indexing is kosher : 0 <= (di = data[i - level]) && di < m && // 'di < m' was 'di < q1->count' nonsensical (q2 = q1->child[di]) != NULL; q1 = q2, level++); /* Usually, now level <= i and found terminal node (q2 = NULL) */ if(pred_kind & PROBS) { /* prediction probabilities: */ COMP_Pmat(q1); else { /* (0 .. 0 | 0) ==> use CUMULATED counts -- here only : */ COMP_00(COMP_Pmat(current)); } }
BOOL event_editor::OnInitDialog() { int i, adjust = 0; BOOL r = TRUE; CListBox *list; CComboBox *box; MMessage msg; CDialog::OnInitDialog(); // let the base class do the default work m_play_bm.LoadBitmap(IDB_PLAY); ((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm); if (!Show_sexp_help) adjust = -SEXP_HELP_BOX_SIZE; theApp.init_window(&Events_wnd_data, this, adjust); m_event_tree.setup((CEdit *) GetDlgItem(IDC_HELP_BOX)); load_tree(); create_tree(); if (m_num_events >= MAX_MISSION_EVENTS){ GetDlgItem(IDC_BUTTON_NEW_EVENT)->EnableWindow(FALSE); } update_cur_event(); i = m_event_tree.select_sexp_node; if (i != -1) { GetDlgItem(IDC_EVENT_TREE) -> SetFocus(); m_event_tree.hilite_item(i); r = FALSE; } m_num_messages = Num_messages - Num_builtin_messages; for (i=0; i<m_num_messages; i++) { msg = Messages[i + Num_builtin_messages]; m_messages.push_back(msg); if (m_messages[i].avi_info.name){ m_messages[i].avi_info.name = strdup(m_messages[i].avi_info.name); } if (m_messages[i].wave_info.name){ m_messages[i].wave_info.name = strdup(m_messages[i].wave_info.name); } } ((CEdit *) GetDlgItem(IDC_MESSAGE_NAME))->LimitText(NAME_LENGTH - 1); ((CEdit *) GetDlgItem(IDC_MESSAGE_TEXT))->LimitText(MESSAGE_LENGTH - 1); ((CComboBox *) GetDlgItem(IDC_AVI_FILENAME))->LimitText(MAX_FILENAME_LEN - 1); ((CComboBox *) GetDlgItem(IDC_WAVE_FILENAME))->LimitText(MAX_FILENAME_LEN - 1); list = (CListBox *) GetDlgItem(IDC_MESSAGE_LIST); list->ResetContent(); for (i=0; i<m_num_messages; i++) { list->AddString(m_messages[i].name); } box = (CComboBox *) GetDlgItem(IDC_AVI_FILENAME); box->ResetContent(); box->AddString("<None>"); for (i=0; i<Num_messages; i++) { if (Messages[i].avi_info.name) { maybe_add_head(box, Messages[i].avi_info.name); } } // add new heads, if not already in maybe_add_head(box, "Head-TP2"); maybe_add_head(box, "Head-VC2"); maybe_add_head(box, "Head-TP4"); maybe_add_head(box, "Head-TP5"); maybe_add_head(box, "Head-TP6"); maybe_add_head(box, "Head-TP7"); maybe_add_head(box, "Head-TP8"); maybe_add_head(box, "Head-VP2"); maybe_add_head(box, "Head-VP2"); maybe_add_head(box, "Head-CM2"); maybe_add_head(box, "Head-CM3"); maybe_add_head(box, "Head-CM4"); maybe_add_head(box, "Head-CM5"); maybe_add_head(box, "Head-BSH"); /* box->AddString("Head-VC"); // force it in, since Sandeep wants it and it's not used in built-in messages box->AddString("Head-VC2"); // add terran pilot heads box->AddString("Head-TP4"); box->AddString("Head-TP5"); box->AddString("Head-TP6"); box->AddString("Head-TP7"); box->AddString("Head-TP8"); // add vasudan pilot heads box->AddString("Head-VP2"); // BSH and CM2 box->AddString("Head-CM2"); box->AddString("Head-BSH"); */ box = (CComboBox *) GetDlgItem(IDC_WAVE_FILENAME); box->ResetContent(); box->AddString("<None>"); for (i=0; i<Num_messages; i++){ if (Messages[i].wave_info.name){ if (box->FindStringExact(i, Messages[i].wave_info.name) == CB_ERR){ box->AddString(Messages[i].wave_info.name); } } } // add the persona names into the combo box box = (CComboBox *) GetDlgItem(IDC_PERSONA_NAME); box->ResetContent(); box->AddString("<None>"); for (i = 0; i < Num_personas; i++ ){ box->AddString( Personas[i].name ); } // set the first message to be the first non-builtin message (if it exists) if ( Num_messages > Num_builtin_messages ){ m_cur_msg = 0; } else { m_cur_msg = -1; } update_cur_message(); return r; }
int main() { stringstream ss; clock_t begin, end, training_time; string is_save; srand(time(NULL)); cout << "Human pose estimation CVPR2016 based on SMMC DB" << endl; cout << "Developed by Gyeongsik Moon" << endl << endl; cout << "SAVE or LOAD: "; cin >> is_save; cout << endl; vector<node*> tree_head; point *point_train; joint **joint_train; point *point_matching; joint **joint_matching; point *point_test; joint **joint_test; if (!is_save.compare("SAVE")) { point_train = new point[TRAIN_FRAME_NUM * Q_HEIGHT * Q_WIDTH]; joint_train = new joint *[TRAIN_FRAME_NUM]; for (int f = 0; f < TRAIN_FRAME_NUM; f++) joint_train[f] = new joint[JOINT_NUMBER]; //Load training data cout << "Loading training data..." << endl; load_data(point_train, joint_train, TRAINING); cout << endl; //Train a tree cout << "Training start!" << endl; begin = clock(); tree_train(point_train, joint_train, tree_head); end = clock(); training_time = end - begin; cout << endl << "Training complete!" << endl; cout << (float)(end - begin) / CLOCKS_PER_SEC << "seconds for training" << endl << endl; cout << "Saving tree..." << endl; save_tree(tree_head); for (long long int pid = 0; pid < TRAIN_FRAME_NUM * Q_HEIGHT * Q_WIDTH; pid++) { if (point_train[pid].depth != BACKGROUND_DEPTH) { for (int nid = 0; nid < NEAREST_NUM; nid++) delete[] point_train[pid].offset[nid]; delete[] point_train[pid].offset; } } delete[] point_train; for (int f = 0; f < TRAIN_FRAME_NUM; f++) delete[] joint_train[f]; delete[] joint_train; } else if (!is_save.compare("LOAD")) { cout << "Loading tree..." << endl; training_time = 0; load_tree(&tree_head); } else { cout << "Not a proper input..." << endl; return 0; } point_matching = new point[POINT_MATCHING_FRAME_NUM * Q_HEIGHT * Q_WIDTH]; joint_matching = new joint *[POINT_MATCHING_FRAME_NUM]; for (int f = 0; f < POINT_MATCHING_FRAME_NUM; f++) joint_matching[f] = new joint[JOINT_NUMBER]; cout << "Loading DB for point matching..." << endl; load_data(point_matching, joint_matching, POINT_MATCHING); float** center_matching; center_matching = new float*[POINT_MATCHING_FRAME_NUM]; for (int matching_f = 0; matching_f < POINT_MATCHING_FRAME_NUM; matching_f++) { center_matching[matching_f] = new float[COORDINATE_DIM]; center_matching[matching_f][0] = 0; center_matching[matching_f][1] = 0; center_matching[matching_f][2] = 0; float pixel_num = 0; for (int matching_i = 0; matching_i < Q_WIDTH * Q_HEIGHT; matching_i++) { if (point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].depth != BACKGROUND_DEPTH) { center_matching[matching_f][0] += point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].x_world; center_matching[matching_f][1] += point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].y_world; center_matching[matching_f][2] += point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].depth; pixel_num++; } } center_matching[matching_f][0] /= pixel_num; center_matching[matching_f][1] /= pixel_num; center_matching[matching_f][2] /= pixel_num; } delete[] point_matching; point_test = new point[TEST_FRAME_NUM * Q_HEIGHT * Q_WIDTH]; joint_test = new joint *[TEST_FRAME_NUM]; for (int f = 0; f < TEST_FRAME_NUM; f++) joint_test[f] = new joint[JOINT_NUMBER]; //load test dataset cout << "Loading test dataset..." << endl; load_data(point_test, joint_test, TEST); //Test cout << "Testing start!" << endl; begin = clock(); //tree traversal tree_traversal(point_test, joint_test, center_matching, joint_matching, tree_head); end = clock(); cout << "Testing complete!" << endl << endl; cout << (float)training_time / CLOCKS_PER_SEC << "seoncds for training" << endl; cout << (float)(end - begin) / CLOCKS_PER_SEC << "seoncds for testing" << endl; for (int matching_f = 0; matching_f < POINT_MATCHING_FRAME_NUM; matching_f++) delete[] center_matching[matching_f]; delete[] center_matching; for (int f = 0; f < POINT_MATCHING_FRAME_NUM; f++) delete[] joint_matching[f]; delete[] joint_matching; for (int f = 0; f < TEST_FRAME_NUM; f++) delete[] joint_test[f]; delete[] joint_test; delete[] point_test; return 0; }
/**@file main.c * @brief Controlling function of L-Galaxies plus Construct Galaxies, * Join Galaxies of progenitors, Evolve Galaxies and check * Makefile options. * */ int main(int argc, char **argv) { int filenr, tree, halonr,filenrid,i,j; struct stat filestatus; FILE *fd, *fa; char buf[1000]; time_t initial, final, previous; //int NFOFs=767; int *FileList, *TreeList; int MyNtrees, MytotNHalos, *MyTreeNHalos, NFOFs; float weight; long long haloid; int FileNumber=409024; /*Reads the parameter file, given as an argument at run time.*/ read_parameter_file(argv[1]); sprintf(buf, "./sample_nh_%d.dat",FileNumber); if(!(fd = fopen(buf, "r"))) { printf("can't open file place 1 `%s'\n", buf); exit(1); } fscanf(fd, "%d \n", &MyNtrees); printf("NTrees=%d\n", MyNtrees); FileList = malloc(sizeof(int) * MyNtrees); TreeList = malloc(sizeof(int) * MyNtrees); for(i=0;i<MyNtrees;i++) { fscanf(fd, "%lld %d %d %f\n", &haloid, &TreeList[i], &FileList[i], &weight); //printf("i=%d list=%d \n",i,FileList[i]); } fclose(fd); MyTreeNHalos = malloc(sizeof(int) * MyNtrees); MytotNHalos=0; //MyNtrees=0; printf("\n\nReading Started... -> output file %d\n\n\n",FileNumber); //tree number 3 numbers for the redshift + Nsampling sprintf(buf, "/afs/mpa/data/bmh20/workspace/performance_MCMC_Scaling_backup/MergerTrees/MergerTrees_1/treedata/trees_063.%d",FileNumber); if(!(fd = fopen(buf, "wb"))) { printf("can't open file %d\n", __LINE__); exit(1); } sprintf(buf, "/afs/mpa/data/bmh20/workspace/performance_MCMC_Scaling_backup/MergerTrees/MergerTrees_1/treedata/tree_dbids_063.%d", FileNumber); if(!(fa = fopen(buf, "wb"))) { printf("can't open file %d\n", __LINE__); exit(1); } //jump header in output file /*for (filenr = 0; filenr < NFOFs; filenr++) if(filenr < 0 || ((FileList[filenr]+TreeList[filenr])!= (FileList[filenr-1]+TreeList[filenr-1]))) ++MyNtrees;*/ fseek(fd, sizeof(int) * (2 + MyNtrees),0); for (filenr = 0; filenr < MyNtrees; filenr++) { load_tree_table(FileList[filenr]); load_tree(FileList[filenr], TreeList[filenr]); MytotNHalos+=TreeNHalos[TreeList[filenr]]; MyTreeNHalos[filenr]=TreeNHalos[TreeList[filenr]]; printf("Treenr=%d (of %d), Tree Number of Halos=%d\n",filenr, MyNtrees, TreeNHalos[TreeList[filenr]]); if(fwrite(HaloIDs, sizeof(struct halo_ids_data), MyTreeNHalos[filenr], fa) != MyTreeNHalos[filenr]) printf("error in fwrite\n"); if(fwrite(Halo, sizeof(struct halo_data), MyTreeNHalos[filenr], fd) != MyTreeNHalos[filenr]) printf("error in fwrite\n"); free(HaloAux); free(Halo); free(HaloIDs); for(i = NOUT - 1; i >= 0; i--) free(TreeNgals[i]); free(TreeFirstHalo); free(TreeNHalos); //printf("done file %d\n", filenr); // } } fclose(fa); //write header printf("\n\nRewinding...please wait...\n\n"); rewind(fd); fwrite(&MyNtrees, sizeof(int), 1, fd); fwrite(&MytotNHalos, sizeof(int), 1, fd); fwrite(MyTreeNHalos, sizeof(int), MyNtrees, fd); free(MyTreeNHalos); free(FileList); free(TreeList); fclose(fd); printf("\n\ndone"); }
/*--------------------------------------------------------------- Routine : load_tree_cb Purpose : Callback to load new tree ---------------------------------------------------------------*/ int load_tree_cb( TREE_PIC_FOREST *tree_pic_forest, char *fname ) { TREE *tree = tree_pic_forest->tree_pic->tree; int load_err = 0; ASSERT( ( tree_pic_forest != NULL ) && ( tree != NULL ) && ( fname != NULL ) ); /* load tree from file */ load_err = load_tree(tree, fname); TreePicSetSelectedItem(tree_pic_forest->tree_pic, NULL); if ( load_err == TREE_FILE_ERROR) { FTAFramePostWarning(FILE_OPEN_ERROR, FTA_OPEN_TITLE); create_new_tree_cb(tree_pic_forest); update_tree(tree_pic_forest->tree_pic); return FILE_ERROR; } if ( load_err == TREE_ERROR) { FTAFramePostWarning(TREE_FORMAT_ERROR, FTA_OPEN_TITLE "Tree"); create_new_tree_cb(tree_pic_forest); update_tree(tree_pic_forest->tree_pic); return FILE_ERROR; } /* set new file name in tree */ if(tree->name) { strfree( tree->name ); } if(tree->path) { strfree( tree->path ); } tree_pic_forest->tree_pic->tree->name = filename_from_pathname(fname); tree_pic_forest->tree_pic->tree->path = path_from_pathname(fname); update_tree(tree_pic_forest->tree_pic); ASSERT( tree_pic_forest != NULL ); if ( !ped_shell_exists( tree->database ) ) { if ( !ped_shell_any_exist() ) { ped_shell_create( ); if(tree->database) { /* only load database if one is specified */ FTAFrameLoadPEDFile(tree->database); } /* ped_shell_open( tree->database ); */ } else { FTAFrameNewPEDFile(); if(tree->database) { /* only load database if one is specified */ FTAFrameLoadPEDFile(tree->database); } /* ped_shell_open( tree->database ); */ } /* no shells exist */ } /* no shell exists for database */ ped_shell_add_modify_callback(tree->database, database_modified_callback, (void *)tree_pic_forest ); FTAFrameSetWindowTitle( tree_pic_forest->tree_pic ); update_prim_events_tree( tree_pic_forest->tree_pic->tree ); make_all_levels(tree_pic_forest->tree_pic->tree); return FILE_OK; } /* load_tree_cb */