private void WriteData(SparseTwinIndex <float> data, int matrixNumber, string fileName) { var zoneNumbers = data.ValidIndexArray(); var flatData = data.GetFlatData(); var numberOfZones = zoneNumbers.Length; using (StreamWriter writer = new StreamWriter(fileName)) { // We need to know what the head should look like. writer.WriteLine("t matrices\r\nd matrix=mf{0}\r\na matrix=mf{0} name=drvtot default=incr descr=generated", matrixNumber); // Now that the header is in place we can start to generate all of the instructions StringBuilder[] builders = new StringBuilder[numberOfZones]; System.Threading.Tasks.Parallel.For(0, numberOfZones, delegate(int o) { var build = builders[o] = new StringBuilder(); var strBuilder = new StringBuilder(10); var convertedO = zoneNumbers[o]; for (int d = 0; d < numberOfZones; d++) { Controller.ToEmmeFloat(flatData[o][d], strBuilder); build.AppendFormat("{0,7:G}{1,7:G} {2}\r\n", convertedO, zoneNumbers[d], strBuilder); } }); for (int i = 0; i < numberOfZones; i++) { writer.Write(builders[i]); } } }
public static void SaveMatrix(SparseTwinIndex<float> matrix, string fileName) { var zones = matrix.ValidIndexArray(); var data = matrix.GetFlatData(); StringBuilder header = null; StringBuilder[] zoneLines = new StringBuilder[zones.Length]; Parallel.Invoke( () => { var dir = Path.GetDirectoryName(fileName); if (!String.IsNullOrWhiteSpace(dir)) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } }, () => { header = new StringBuilder(); header.Append("Zones O\\D"); for (int i = 0; i < zones.Length; i++) { header.Append(','); header.Append(zones[i]); } }, () => { Parallel.For(0, zones.Length, (int i) => { zoneLines[i] = new StringBuilder(); zoneLines[i].Append(zones[i]); var row = data[i]; if (row == null) { for (int j = 0; j < zones.Length; j++) { zoneLines[i].Append(','); zoneLines[i].Append('0'); } } else { for (int j = 0; j < zones.Length; j++) { zoneLines[i].Append(','); zoneLines[i].Append(row[j]); } } }); }); using (StreamWriter writer = new StreamWriter(fileName)) { writer.WriteLine(header); for (int i = 0; i < zoneLines.Length; i++) { writer.WriteLine(zoneLines[i]); } } }
public static void SaveMatrix(SparseTwinIndex <float> matrix, string fileName) { var zones = matrix.ValidIndexArray(); var data = matrix.GetFlatData(); StringBuilder header = null; StringBuilder[] zoneLines = new StringBuilder[zones.Length]; Parallel.Invoke( () => { var dir = Path.GetDirectoryName(fileName); if (!String.IsNullOrWhiteSpace(dir)) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } }, () => { header = new StringBuilder(); header.Append("Zones O\\D"); for (int i = 0; i < zones.Length; i++) { header.Append(','); header.Append(zones[i]); } }, () => { Parallel.For(0, zones.Length, (int i) => { zoneLines[i] = new StringBuilder(); zoneLines[i].Append(zones[i]); var row = data[i]; if (row == null) { for (int j = 0; j < zones.Length; j++) { zoneLines[i].Append(','); zoneLines[i].Append('0'); } } else { for (int j = 0; j < zones.Length; j++) { zoneLines[i].Append(','); zoneLines[i].Append(row[j]); } } }); }); using (StreamWriter writer = new StreamWriter(fileName)) { writer.WriteLine(header); for (int i = 0; i < zoneLines.Length; i++) { writer.WriteLine(zoneLines[i]); } } }
private void WriteData(SparseTwinIndex<float> data, int matrixNumber, string fileName) { var zoneNumbers = data.ValidIndexArray(); var flatData = data.GetFlatData(); var numberOfZones = zoneNumbers.Length; using ( StreamWriter writer = new StreamWriter( fileName ) ) { // We need to know what the head should look like. writer.WriteLine( "t matrices\r\nd matrix=mf{0}\r\na matrix=mf{0} name=drvtot default=incr descr=generated", matrixNumber ); // Now that the header is in place we can start to generate all of the instructions StringBuilder[] builders = new StringBuilder[numberOfZones]; System.Threading.Tasks.Parallel.For( 0, numberOfZones, delegate(int o) { var build = builders[o] = new StringBuilder(); var strBuilder = new StringBuilder( 10 ); var convertedO = zoneNumbers[o]; for ( int d = 0; d < numberOfZones; d++ ) { this.ToEmmeFloat( flatData[o][d], strBuilder ); build.AppendFormat( "{0,7:G}{1,7:G} {2,9:G}\r\n", convertedO, zoneNumbers[d], strBuilder ); } } ); for ( int i = 0; i < numberOfZones; i++ ) { writer.Write( builders[i] ); } } }