int load_snapshot(char* fname, int num) { int i,j,k,l; char outfilename[256]; printf("reading file: %s\n", fname); numpart = readgadget_part(fname, &head, &part); if (numpart==0) { extern int libgaderr; fprintf(stderr,"LibGad Error Code: %d\n", libgaderr); exit(1); } if (!use_ind) qsort(part, numpart, sizeof(gadpart), cmp_id ); i=0; char buf[256]; sprintf(buf, "subhalos_%03d", num); mkdir(buf, 02755); for (j=0; j<TotNsubgroups; j++) { if ((sfid >= 0) && (j != sfid)) continue; if ((StarMassThreshold) && (SubhaloStarsMass[j] < StarMassThreshold )) continue; if ((TotalMassThreshold) && (SubhaloMass[j] < TotalMassThreshold )) continue; gadpart *wpart=(gadpart*) malloc (sizeof(gadpart) * SubhaloLen[j]); struct header outhead = head; for (i=0; i<6; i++) { outhead.nall[i] = 0; outhead.npart[i]= 0; } l=0; for (k=SubhaloOffset[j];k<SubhaloOffset[j]+SubhaloLen[j];k++) { gadpart dumpart; dumpart.id = IDs[k]; gadpart *fnd; if (!use_ind) { fnd = bsearch (&dumpart, &part[0], numpart, sizeof(gadpart), cmp_id ); } else { fnd = &part[IDs[k]-1]; } if (fnd != NULL) { wpart[l] = *fnd; outhead.nall[ wpart[l].type ]++; outhead.npart[ wpart[l].type ]++; l++; } } findcenter(wpart, SubhaloLen[j], -1, use_cm); sprintf(outfilename, "subhalos_%03d/subhalo.%05d.p%05d.g%05d.gad", num, j, SubhaloParent[j],SubhaloGrNr[j]); writegadget_part(outfilename, outhead, wpart); free (wpart); } }
void findFWHM (gsl_matrix * m, unsigned int *FWHM_i, unsigned int *FWHM_j) { unsigned int s1 = m->size1; unsigned int s2 = m->size2; double max = 0.; unsigned int i_max = 0; unsigned int j_max = 0; //findpeak (m, &i_max, &j_max, &max); findcenter (m, &i_max, &j_max, &max); double elem; unsigned int i_FWHM_plus = i_max; while (i_FWHM_plus < s1) { elem = gsl_matrix_get (m, i_FWHM_plus, j_max); if (elem < max / 2.) break; i_FWHM_plus++; } unsigned int i_FWHM_minus = i_max; while (i_FWHM_minus > 0) { elem = gsl_matrix_get (m, i_FWHM_minus, j_max); if (elem < max / 2.) break; i_FWHM_minus--; } unsigned int j_FWHM_plus = j_max; while (j_FWHM_plus < s2) { elem = gsl_matrix_get (m, i_max, j_FWHM_plus); if (elem < max / 2.) break; j_FWHM_plus++; } unsigned int j_FWHM_minus = j_max; while (j_FWHM_minus > 0) { elem = gsl_matrix_get (m, i_max, j_FWHM_minus); if (elem < max / 2.) break; j_FWHM_minus--; } *FWHM_i = i_FWHM_plus - i_FWHM_minus; *FWHM_j = j_FWHM_plus - j_FWHM_minus; if (*FWHM_i == 0) { if (VERBOSE) cout << "Warning: FWHM_i overridden to be > 0" << endl; *FWHM_i = 10; } if (*FWHM_j == 0) { if (VERBOSE) cout << "Warning: FWHM_i overridden to be > 0" << endl; *FWHM_j = 10; } if (VERBOSE) { cout << endl << "\tFWHM_i = " << *FWHM_i << ", FWHM_j = " << *FWHM_j << endl; } return; }
void findmoments (gsl_matrix * m, unsigned int *ci, unsigned int *cj, double *peak, unsigned int *wi1e, unsigned int *wj1e) { findcenter (m, ci, cj, peak); //sometimes a negative atom number shows up in the column density //this affects the center of mass calculation, so whenever a pixel //with a negative number of atoms is found it is taken as zero //for the center of mass estimate double i0 = (double) *ci; double j0 = (double) *cj; double masstotal = 0., mass = 0.; double wi1e_ = 0., wj1e_ = 0.; for (unsigned int i = 0; i < m->size1; i++) for (unsigned int j = 0; j < m->size2; j++) { mass = gsl_matrix_get (m, i, j); mass = mass > 0 ? mass : 0.; masstotal += mass; wi1e_ += mass * (i - i0) * (i - i0); wj1e_ += mass * (j - j0) * (j - j0); } wi1e_ = sqrt (2. * wi1e_ / masstotal); wj1e_ = sqrt (2. * wj1e_ / masstotal); /* //// SUM ALONG I AND J FIRST gsl_vector *isum = gsl_vector_alloc (m->size1); gsl_vector *jsum = gsl_vector_alloc (m->size1); double sum; for (unsigned int i = 0; i < m->size1; i++) { sum = 0.; for (unsigned int j = 0; j < m->size2; j++) { sum = sum + gsl_matrix_get (m, i, j); } gsl_vector_set (isum, i, sum); } for (unsigned int j = 0; j < m->size2; j++) { sum = 0.; for (unsigned int i = 0; i < m->size1; i++) { sum = sum + gsl_matrix_get (m, i, j); } gsl_vector_set (jsum, j, sum); } double masstotal = 0., mass = 0.; double wi1e_ = 0., wj1e_ = 0.; for (unsigned int i = 0; i < m->size1; i++) { mass = gsl_vector_get (isum, i); mass = mass > 0 ? mass : 0.; masstotal += mass; wi1e_ += mass * (i - i0) * (i - i0); } wi1e_ = sqrt (2. * wi1e_ / masstotal); masstotal = 0.; mass = 0.; for (unsigned int j = 0; j < m->size2; j++) { mass = gsl_vector_get (jsum, j); mass = mass > 0 ? mass : 0.; masstotal += mass; wj1e_ += mass * (j - j0) * (j - j0); } wj1e_ = sqrt (2. * wj1e_ / masstotal); //// */ if (VERBOSE && false) { printf ("Center is at (%.1f,%.1f)\n", i0, j0); cout << "Moments results: ci = " << i0 << ", cj = " << j0 << ", wi1e = " << wi1e_ << ", wj1e = " << wj1e_ << endl << endl;; } *wi1e = (unsigned int) floor (wi1e_); *wj1e = (unsigned int) floor (wj1e_); return; }