Example #1
0
        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");
        }
Example #2
0
        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");
        }
Example #3
0
        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);
        }
Example #4
0
        public void LongStringTest()
        {
            var matfile = new DotMatFile();
            var str     = new MatlabString("Now is the time for all good men to come to the aid of the party.");

            matfile["stringLong"] = str;
            matfile.WriteToDisk("stringLong.mat");
        }
Example #5
0
        public void ShortStringTest()
        {
            var matfile = new DotMatFile();
            var str     = new MatlabString("foo");

            matfile["stringFoo"] = str;
            matfile.WriteToDisk("stringFoo.mat");
        }
Example #6
0
        public void EmptyStringTest()
        {
            var matfile = new DotMatFile();
            var str     = new MatlabString(string.Empty);

            matfile["stringEmpty"] = str;
            matfile.WriteToDisk("stringEmpty.mat");
        }
Example #7
0
        public void NullStringTest()
        {
            var matfile = new DotMatFile();
            var str     = new MatlabString(null);

            matfile["stringNull"] = str;
            matfile.WriteToDisk("stringNull.mat");
        }
        public void UintDataTest()
        {
            var matfile = new DotMatFile();
            var matrix  = new MatlabMatrix(new uint[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            matfile["uintData"] = matrix;
            matfile.WriteToDisk("uintData.mat");
        }
        public void IntDataTest()
        {
            var matfile = new DotMatFile();
            var matrix  = new MatlabMatrix(new [] { 1, -2, 3, -4, 5, -6, 7, -8, 9, -10 });

            matfile["intData"] = matrix;
            matfile.WriteToDisk("intData.mat");
        }
        public void FloatDataTest()
        {
            var matfile = new DotMatFile();
            var matrix  = new MatlabMatrix(new[] { 1.2f, -2.3f, 3.4f, -4.5f, 5.6f, -6.7f, 7.8f, -8.9f, 9.10f, -10.11f });

            matfile["floatData"] = matrix;
            matfile.WriteToDisk("floatData.mat");
        }
Example #11
0
        public void EmptyTest()
        {
            var matFile  = new DotMatFile();
            var filename = Path.GetRandomFileName() + ".empty.mat";

            matFile.WriteToDisk(filename);
            // File.Delete(filename);
        }
Example #12
0
        public void NullDictionaryTest()
        {
            var matfile   = new DotMatFile();
            var structure = new MatlabStructure(null);

            matfile["structNull"] = structure;
            matfile.WriteToDisk("structNull.mat");
        }
        public void DoubleDataTest()
        {
            var matfile = new DotMatFile();
            var matrix  = new MatlabMatrix(new[] { 1.2, -2.3, 3.4, -4.5, 5.6, -6.7, 7.8, -8.9, 9.10, -10.11 });

            matfile["doubleData"] = matrix;
            matfile.WriteToDisk("doubleData.mat");
        }
Example #14
0
        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");
        }
Example #15
0
        public void ThreeDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new[] { 1000000, 1000001, 1000002, 1000004, 1000006, 1000005, 1000003, 1000007 };
            var matrix  = new MatlabMatrix(data, new[] { 2, 2, 2 });

            matfile["threedIntegers"] = matrix;
            matfile.WriteToDisk("threedIntegers.mat");
        }
Example #16
0
        public void SimpleBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new[] { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097151 };
            var matrix  = new MatlabMatrix(data);

            matfile["simpleIntegers"] = matrix;
            matfile.WriteToDisk("simpleIntegers.mat");
        }
        public void TwoDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new ushort[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var matrix  = new MatlabMatrix(data, new[] { 2, 4 });

            matfile["twodUshorts"] = matrix;
            matfile.WriteToDisk("twodUshorts.mat");
        }
Example #18
0
        public void CellWithString()
        {
            var matfile = new DotMatFile();
            var cell    = new MatlabCell();

            cell.Contents.Add(new MatlabString("She sells seashells by the seashore."));
            matfile["cellString"] = cell;
            matfile.WriteToDisk("cellString.mat");
        }
Example #19
0
        public void TwoDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new uint[] { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152 };
            var matrix  = new MatlabMatrix(data, new[] { 2, 11 });

            matfile["twodUints"] = matrix;
            matfile.WriteToDisk("twodUints.mat");
        }
        public void ThreeDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new [] { 0.1, 1.2, 2.3, 4.5, 6.7, 5.6, 3.4, 7.8 };
            var matrix  = new MatlabMatrix(data, new [] { 2, 2, 2 });

            matfile["threedDoubles"] = matrix;
            matfile.WriteToDisk("threedDoubles.mat");
        }
        public void SimpleBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new [] { 0.1, 1.2, 2.3, 4.5, 8.9, 16.17, 32.33, 64.65, 128.129, 255.256 };
            var matrix  = new MatlabMatrix(data);

            matfile["simpleDoubles"] = matrix;
            matfile.WriteToDisk("simpleDoubles.mat");
        }
        public void ThreeDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new ushort[] { 0, 1, 2, 4, 6, 5, 3, 7 };
            var matrix  = new MatlabMatrix(data, new[] { 2, 2, 2 });

            matfile["threedUshorts"] = matrix;
            matfile.WriteToDisk("threedUshorts.mat");
        }
Example #23
0
        public void SimpleBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new byte[] { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
            var matrix  = new MatlabMatrix(data);

            matfile["simpleBytes"] = matrix;
            matfile.WriteToDisk("simpleBytes.mat");
        }
Example #24
0
        public void SimpleBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new[] { 0.1f, 1.2f, 2.3f, 4.5f, 8.9f, 16.17f, 32.33f, 64.65f, 128.129f, 255.256f };
            var matrix  = new MatlabMatrix(data);

            matfile["simpleFloats"] = matrix;
            matfile.WriteToDisk("simpleFloats.mat");
        }
        public void TwoDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new [] { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 };
            var matrix  = new MatlabMatrix(data, new [] { 2, 4 });

            matfile["twodDoubles"] = matrix;
            matfile.WriteToDisk("twodDoubles.mat");
        }
Example #26
0
        public void TwoDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new[] { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f };
            var matrix  = new MatlabMatrix(data, new[] { 2, 4 });

            matfile["twodFloats"] = matrix;
            matfile.WriteToDisk("twodFloats.mat");
        }
Example #27
0
        public void EmptyBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new uint[0];
            var matrix  = new MatlabMatrix(data);

            matfile["emptyUints"] = matrix;
            matfile.WriteToDisk("emptyUints.mat");
        }
Example #28
0
        public void ThreeDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new[] { 0.1f, 1.2f, 2.3f, 4.5f, 6.7f, 5.6f, 3.4f, 7.8f };
            var matrix  = new MatlabMatrix(data, new[] { 2, 2, 2 });

            matfile["threedFloats"] = matrix;
            matfile.WriteToDisk("threedFloats.mat");
        }
Example #29
0
        public void ThreeDeeBufferTest()
        {
            var matfile = new DotMatFile();
            var data    = new uint[] { 4000000, 4000001, 4000002, 4000004, 4000006, 4000005, 4000003, 4000007 };
            var matrix  = new MatlabMatrix(data, new[] { 2, 2, 2 });

            matfile["threedUints"] = matrix;
            matfile.WriteToDisk("threedUints.mat");
        }
Example #30
0
        public void CellWithMatrixTest()
        {
            var matfile = new DotMatFile();
            var cell    = new MatlabCell();

            cell.Contents.Add(new MatlabMatrix(new [] { 2.8284271247461900976, 3.14159265 }));
            matfile["cellMatrix"] = cell;
            matfile.WriteToDisk("cellMatrix.mat");
        }