void WriteGroupFile(GroupFile groupFile,BinaryWriter groupwriter,BinaryWriter subhalowriter ) { if (groupFile.wasWritten) { DebugOut.PrintLine("ERROR " + groupFile.ifile + " was alrady written"); return; } // a potential sort would go here, this must be done AFTER the groups's subhaloid-s have been set ! if (writeFOFs) { for (int igroup = 0; igroup < groupFile.numGroups; igroup++) groupFile.groups[igroup].WriteBinary(groupwriter, groupFile.hasVelDisp); } if (writeSubHalos) { for (int isubhalo = 0; isubhalo < groupFile.numSubgroups; isubhalo++) groupFile.subhalos[isubhalo].WriteBinary(subhalowriter); } groupFile.wasWritten = true; }
/// <summary> /// /// </summary> /// <param name="files"></param> /// <param name="previousFile"></param> /// <param name="snap"></param> /// <returns></returns> GroupFile NextGroupFile(List<GroupFile> files, GroupFile previousFile, short snap) { int ifile = (previousFile == null ? 0 : previousFile.ifile + 1); GroupFile groupFile = null; if (ifile < files.Count) { groupFile = files[ifile]; if (groupFile == null) DebugOut.PrintLine("ERROR Group file " + ifile + " was already removed"); } if (groupFile == null) { groupFile = new GroupFile(this, GetSubTab(inPath, snap, ifile), snap, previousFile); files.Add(groupFile); } return groupFile; }
private GroupProcess process; // for accessing useful config data #endregion Fields #region Constructors //string filename, bool _hasVelDisp, short snapnum, float redshift) /// <summary> /// /// </summary> /// <param name="_process"></param> /// <param name="filename"></param> /// <param name="_snapnum"></param> /// <param name="_ifile"></param> public GroupFile(GroupProcess _process, string filename, short _snapnum, GroupFile previous) { this.process = _process; this.snapnum = _snapnum; this.ifile = (previous == null?0:previous.ifile+1); float redshift = process.globals.redshifts[snapnum]; bool hasVelDisp = process.hasVelDisp; // no need for records/bytesRead, not in fortran format using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open))) { numGroups = reader.ReadInt32(); totalGroups = reader.ReadInt32(); numIDs = reader.ReadInt32(); totalIDs = reader.ReadInt64(); numFiles = reader.ReadInt32(); numSubgroups = reader.ReadInt32(); totalSubgroups = reader.ReadInt32(); previousLastGroupIndex = (previous == null ? -1 : previous.lastGroupIndex); previousLastSubhaloIndex = (previous == null ? -1 : previous.lastSubhaloIndex); groups = new GroupInfo[numGroups]; for (int i = 0; i < numGroups; i++) { groups[i] = new GroupInfo(); groups[i].snapnum = snapnum; groups[i].redshift = redshift; } subhalos = new SubhaloInfo[numSubgroups]; for (int i = 0; i < numSubgroups; i++) { subhalos[i] = new SubhaloInfo(); subhalos[i].snapnum = snapnum; subhalos[i].redshift = redshift; } for (int i = 0; i < numGroups; i++) groups[i].Length = reader.ReadInt32(); for (int i = 0; i < numGroups; i++) groups[i].offset = reader.ReadInt32(); for (int i = 0; i < numGroups; i++) groups[i].Mass = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) { groups[i].x = reader.ReadSingle(); groups[i].y = reader.ReadSingle(); groups[i].z = reader.ReadSingle(); groups[i].ix = process.GetZone(groups[i].x); groups[i].iy = process.GetZone(groups[i].y); groups[i].iz = process.GetZone(groups[i].z); groups[i].phkey = process.GetPHKey(groups[i].x, groups[i].y, groups[i].z); } for (int i = 0; i < numGroups; i++) groups[i].M_Mean200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].R_Mean200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].M_Crit200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].R_Crit200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].M_TopHat200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].R_TopHat200 = reader.ReadSingle(); if (hasVelDisp) { for (int i = 0; i < numGroups; i++) groups[i].VelDisp_Mean200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].VelDisp_Crit200 = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].VelDisp_TopHat200 = reader.ReadSingle(); } for (int i = 0; i < numGroups; i++) reader.ReadInt32(); // groups[i].contamCount = reader.ReadInt32(); for (int i = 0; i < numGroups; i++) reader.ReadSingle(); // groups[i].contamMass = reader.ReadSingle(); for (int i = 0; i < numGroups; i++) groups[i].numSubs = reader.ReadInt32(); for (int i = 0; i < numGroups; i++) groups[i].firstSubIndex = reader.ReadInt32(); // ------------------------------------- // now we're at the subhalo table start // ------------------------------------- for (int i = 0; i < numSubgroups; i++) subhalos[i].length = reader.ReadInt32(); for (int i = 0; i < numSubgroups; i++) subhalos[i].offset = reader.ReadInt32(); // skip offsets and parents reader.ReadBytes(4 * numSubgroups); for (int i = 0; i < numSubgroups; i++) subhalos[i].mass = reader.ReadSingle(); for (int i = 0; i < numSubgroups; i++) { subhalos[i].x = reader.ReadSingle(); subhalos[i].y = reader.ReadSingle(); subhalos[i].z = reader.ReadSingle(); subhalos[i].ix = process.GetZone(subhalos[i].x); subhalos[i].iy = process.GetZone(subhalos[i].y); subhalos[i].iz = process.GetZone(subhalos[i].z); subhalos[i].phkey = process.GetPHKey(subhalos[i].x, subhalos[i].y, subhalos[i].z); } for (int i = 0; i < numSubgroups; i++) { subhalos[i].vx = reader.ReadSingle(); subhalos[i].vy = reader.ReadSingle(); subhalos[i].vz = reader.ReadSingle(); } for (int i = 0; i < numSubgroups; i++) { subhalos[i].cmx = reader.ReadSingle(); subhalos[i].cmy = reader.ReadSingle(); subhalos[i].cmz = reader.ReadSingle(); } for (int i = 0; i < numSubgroups; i++) { subhalos[i].sx = reader.ReadSingle(); subhalos[i].sy = reader.ReadSingle(); subhalos[i].sz = reader.ReadSingle(); } for (int i = 0; i < numSubgroups; i++) subhalos[i].veldisp = reader.ReadSingle(); for (int i = 0; i < numSubgroups; i++) subhalos[i].velMax = reader.ReadSingle(); for (int i = 0; i < numSubgroups; i++) subhalos[i].velMaxRad = reader.ReadSingle(); for (int i = 0; i < numSubgroups; i++) subhalos[i].hmradius = reader.ReadSingle(); for (int i = 0; i < numSubgroups; i++) subhalos[i].mostBoundId = reader.ReadInt64(); // skip GrNr reader.ReadBytes(4 * numSubgroups); } }
public void Remove(GroupFile f) { list.Remove(f); }
public void Add(GroupFile f) { list.AddLast(f); }
public Queue(GroupFile first) { list = new LinkedList<GroupFile>(); }