private long GetFOFIdPrefix(LittleFOF fof) { if (fof == null) return 0; else return fof.fofId * multiplier; }
/// <summary> /// /// </summary> /// <param name="file"></param> /// <returns></returns> void ReadLittleSubHalos(String file, LittleFOF[] fofs) { if (fofs.Length == 0) return; List<String[]> rows = ReadGAVO_CSV(file + "\\subhalo.csv"); LittleFOF currentFOF = fofs[0]; int subhaloCount = 0; int ifof = 0; for (int i = 1; i < rows.Count; i++) { String[] words = rows[i]; LittleSubHalo sh = new LittleSubHalo(); sh.subhaloId = long.Parse(words[0]); sh.np = Int32.Parse(words[1]); if (sh.fofId != currentFOF.fofId) { while (true) { ifof++; currentFOF = fofs[ifof]; if (currentFOF.fofId == sh.fofId) break; if (ifof >= fofs.Length) { throw new Exception("ReadLittleSubHalos: Invalid state, found subhalo without fof group"); } } subhaloCount = 0; } try { currentFOF.subhalos[subhaloCount++] = sh; } catch (IndexOutOfRangeException ioe) { DebugOut.PrintLine("Help"); throw ioe; } } // set first particle ids foreach (LittleFOF fof in fofs) { if (fof.numSubs == 0) continue; long particleId = GetFOFIdPrefix(fof); foreach (LittleSubHalo subhalo in fof.subhalos) { subhalo.firstParticleFofId = particleId; particleId += subhalo.np; } } }
/// <summary> /// Read and write snapshot files as ordered by Mik Boylan-Kolchin. /// Write IDs /// </summary> /// <param name="snap"></param> /// <summary> /// /// </summary> /// <param name="file"></param> /// <returns></returns> LittleFOF[] ReadLittleFOFs(String file) { List<String[]> rows = ReadGAVO_CSV(file+"\\fof.csv"); LittleFOF[] fofs = new LittleFOF[rows.Count - 1]; for (int i = 1; i < rows.Count; i++) { String[] words = rows[i]; LittleFOF fof = new LittleFOF(); fof.fofId = long.Parse(words[0]); fof.np = Int32.Parse(words[1]); fof.numSubs = Int32.Parse(words[2]); if(fof.numSubs > 0) fof.subhalos = new LittleSubHalo[fof.numSubs]; fofs[i - 1] = fof; } return fofs; }