public void CellWithMixedContents() { var matfile = new DotMatFile(); var cell = new MatlabCell(new[] { 4, 1 }); var innerCell = new MatlabCell(); innerCell.Contents.Add(new MatlabString("output files are up-to-date")); cell.Contents.Add(innerCell); cell.Contents.Add(new MatlabMatrix(new[] { 2.8284271247461900976, 3.14159265 })); cell.Contents.Add(new MatlabString("5 succeeded, 0 failed, 1 up-to-date, 0 skipped")); var mapping = new Dictionary <string, MatrixElement>(); mapping.Add("bits", new MatlabMatrix(new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 })); var names = new MatlabCell(new[] { 8, 1 }); names.Contents.Add(new MatlabString("one")); names.Contents.Add(new MatlabString("two")); names.Contents.Add(new MatlabString("four")); names.Contents.Add(new MatlabString("eight")); names.Contents.Add(new MatlabString("sixteen")); names.Contents.Add(new MatlabString("thirty-two")); names.Contents.Add(new MatlabString("sixty-four")); names.Contents.Add(new MatlabString("one twenty-eight")); mapping.Add("names", names); var structure = new MatlabStructure(mapping); cell.Contents.Add(structure); matfile["cellMixed"] = cell; matfile.WriteToDisk("cellMixed.mat"); }
public void MatlabStructureTest() { var matfile = new DotMatFile(); var mapping = new Dictionary <string, MatrixElement>(); var cell = new MatlabCell(); cell.Contents.Add(new MatlabString("cell contents")); mapping.Add("cell", cell); mapping.Add("matrix", new MatlabMatrix(new [] { 1.1, 2.1, 1.2, 2.2 }, new [] { 2, 2 })); mapping.Add("string", new MatlabString("11 dimensional")); var innerMapping = new Dictionary <string, MatrixElement>(); innerMapping.Add("bits", new MatlabMatrix(new [] { 1, 2, 4, 8, 16, 32, 64, 128 })); var names = new MatlabCell(new [] { 8, 1 }); names.Contents.Add(new MatlabString("zero")); names.Contents.Add(new MatlabString("one")); names.Contents.Add(new MatlabString("two")); names.Contents.Add(new MatlabString("three")); names.Contents.Add(new MatlabString("four")); names.Contents.Add(new MatlabString("five")); names.Contents.Add(new MatlabString("size")); names.Contents.Add(new MatlabString("seven")); innerMapping.Add("names", names); var innerStruct = new MatlabStructure(innerMapping); mapping.Add("structure", innerStruct); var structure = new MatlabStructure(mapping); matfile["structure"] = structure; matfile.WriteToDisk("structure.mat"); }
internal static void WriteMatFile(SolverBase.Trajectories trajectories, MatlabOutputOptions outputOptions) { var dotMatFile = new DotMatFile(); int observableCount = trajectories.Keys.Count; int traceCount = trajectories.Values.First().Length; int sampleCount = trajectories.Values.First()[0].Length; Dictionary <string, MatrixElement> structure; if (!outputOptions.UseNewFormat) { /* * version = string * observables = #observables rows x 1 column cell matrix * sampletimes = 1 row x #samples columns matrix * data = (#observables x #realizations) rows x #samples columns matrix */ var cellMatrix = new MatlabCell(new[] { observableCount, 1 }); foreach (var observable in trajectories.Keys) { cellMatrix.Contents.Add(new MatlabString(observable.Name)); } structure = new Dictionary <string, MatrixElement>(4) { { "version", new MatlabString(VersionString) }, { "observables", cellMatrix }, { "sampletimes", new MatlabMatrix(trajectories.SampleTimes, new[] { 1, sampleCount }) }, { "data", new MatlabMatrix(TrajectoryData(trajectories), new[] { observableCount *traceCount, sampleCount }) } }; } else { /* * version = string * sampletimes = 1 row x #samples columns matrix * observable1 = #realizations rows x #samples columns matrix * ... * observable2 = #realizations rows x #samples columns matrix * observableN = #realizations rows x #samples columns matrix */ int elementCount = 2 + observableCount; structure = new Dictionary <string, MatrixElement>(elementCount) { { "version", new MatlabString(VersionString) }, { "sampletimes", new MatlabMatrix(trajectories.SampleTimes, new[] { 1, sampleCount }) } }; foreach (var key in trajectories.Keys) { structure.Add(key.Name, MatrixForObservable(trajectories[key])); } } var structMatrix = new MatlabStructure(structure); dotMatFile["data"] = structMatrix; dotMatFile.WriteToDisk(outputOptions.Filename, outputOptions.CompressOutput); }
public void NullDictionaryTest() { var matfile = new DotMatFile(); var structure = new MatlabStructure(null); matfile["structNull"] = structure; matfile.WriteToDisk("structNull.mat"); }
public void EmptyDictionaryTest() { var matfile = new DotMatFile(); var empty = new Dictionary <string, MatrixElement>(); var structure = new MatlabStructure(empty); matfile["structEmpty"] = structure; matfile.WriteToDisk("structEmpty.mat"); }
public void EmptyKeyDictionaryTest() { var matfile = new DotMatFile(); var emptyKey = new Dictionary <string, MatrixElement> { { string.Empty, new MatlabString("empty key") } }; var structure = new MatlabStructure(emptyKey); matfile["structEmptyKey"] = structure; matfile.WriteToDisk("structEmptyKey.mat"); }
public void CellWithStructure() { var matfile = new DotMatFile(); var cell = new MatlabCell(); var mapping = new Dictionary <string, MatrixElement>(); mapping.Add("bits", new MatlabMatrix(new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 })); var names = new MatlabCell(new[] { 8, 1 }); names.Contents.Add(new MatlabString("one")); names.Contents.Add(new MatlabString("two")); names.Contents.Add(new MatlabString("four")); names.Contents.Add(new MatlabString("eight")); names.Contents.Add(new MatlabString("sixteen")); names.Contents.Add(new MatlabString("thirty-two")); names.Contents.Add(new MatlabString("sixty-four")); names.Contents.Add(new MatlabString("one twenty-eight")); mapping.Add("names", names); var structure = new MatlabStructure(mapping); cell.Contents.Add(structure); matfile["cellStructure"] = cell; matfile.WriteToDisk("cellStructure.mat"); }