public static void DumpFormattedColsMetadataToFile(Old.Cols c, string filename) { FileStream l = File.Open(filename, FileMode.Create); using (StreamWriter sw = new StreamWriter(l)) { c.Colis.ForEach(h => { h.ColiObjs.ForEach(j => { sw.Write(j.ColiType.ToString("X2") + " "); if (j.ColiSubType.HasValue) { sw.Write(j.ColiSubType.Value.ToString("X2") + " "); } else { sw.Write("-- "); } sw.Write(j.ColiCount + " "); sw.Write(j.ObjData.Count + "\n"); }); }); } }
public static void DumpFormattedColsToFile(Old.Cols c, string filename) { FileStream l = File.Open(filename, FileMode.Create); using (StreamWriter sw = new StreamWriter(l)) { c.Colis.ForEach(h => { h.ColiObjs.ForEach(j => { sw.Write(j.ColiType.ToString("X2") + " "); if (j.ColiSubType.HasValue) { sw.Write(j.ColiSubType.Value.ToString("X2") + " "); } else { sw.Write("-- "); } sw.Write(j.ColiCount + " "); sw.Write(j.ObjData.Count + "\n"); for (int i = 0; i < j.ObjData.Count; i++) { float bx, by, bz; if (j.ColiType == 0 && j.ColiSubType.HasValue) { switch (j.ColiSubType) { case 0x02: case 0x01: bx = j.ObjData[i]; bz = j.ObjData[++i]; sw.WriteLine($"({bx}, {bz})"); break; case 0x03: by = j.ObjData[i]; bx = j.ObjData[++i]; bz = j.ObjData[++i]; sw.WriteLine($"({bx}, {by}, {bz})"); break; default: sw.WriteLine(j.ObjData[i]); break; } } else { sw.WriteLine(j.ObjData[i]); } } }); }); } }
public static void DumpFormattedTypeCountsToFile(Old.Cols c, string filename) { Dictionary <string, int> typeStats = new Dictionary <string, int>(); c.Colis.ForEach(coli => { coli.ColiObjs.ForEach(coliObj => { string key = coliObj.ColiType.ToString("X2") + " "; if (coliObj.ColiSubType.HasValue) { key += coliObj.ColiSubType.Value.ToString("X2"); } else { key += "--"; } if (coliObj.ColiCount.HasValue) { // key += coliObj.ColiSubType.Value.ToString("X2"); key += " " + coliObj.ColiCount.Value.ToString("X2"); } else { key += " --"; } key += " " + coliObj.ObjData.Count; if (typeStats.ContainsKey(key)) { typeStats[key]++; } else { typeStats[key] = 1; } }); }); List <string> s = typeStats.Select(v => $"{v.Key} {v.Value}").ToList(); s.Sort(); FileStream f = File.Open("D000_COLS_COLI0_ColiObj_Types.txt", FileMode.Create); using (StreamWriter sw = new StreamWriter(f)) { s.ForEach(g => sw.WriteLine(g)); } Console.WriteLine("-----------------------------------"); }
public static void DumpFormattedZeroThreeColsToFile(Old.Cols c, string filename) { FileStream l = File.Open(filename, FileMode.Create); using (StreamWriter sw = new StreamWriter(l)) { var zeroThreeCounts = new Dictionary <string, int>(); c.Colis.ForEach(h => { h.ColiObjs.ForEach(j => { if ((j.ColiType == 0x00) && (j.ColiSubType.HasValue && j.ColiSubType.Value == 0x03)) { var coli = (Old.ColiType0003)j; foreach (var cp in coli.Points) { byte[] vOut = BitConverter.GetBytes(cp.Y); string byteString = vOut[0].ToString("X2") + vOut[1].ToString("X2") + vOut[2].ToString("X2") + vOut[3].ToString("X2"); if (zeroThreeCounts.ContainsKey(byteString)) { zeroThreeCounts[byteString]++; } else { zeroThreeCounts[byteString] = 1; } } } }); }); sw.WriteLine("| Address? | Count |"); sw.WriteLine("|----------|-------|"); var kvl = zeroThreeCounts.ToList(); kvl.Sort((a, b) => b.Value.CompareTo(a.Value)); foreach (var kv in kvl) { sw.WriteLine($"| {kv.Key} | {kv.Value} |"); } } }