Exemple #1
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);
        }
Exemple #2
0
        public static MatlabOutputOptions GetMatlabOutputOptions(string prefix)
        {
            bool writeMatFile   = Configuration.CurrentConfiguration.GetParameterWithDefault("output.writematfile", false);
            bool compressOutput = Configuration.CurrentConfiguration.GetParameterWithDefault("output.compress", true);
            bool useNewFormat   = Configuration.CurrentConfiguration.GetParameterWithDefault("output.newmatformat", false);

            var matlabOptions = new MatlabOutputOptions {
                Filename = prefix + ".mat", CompressOutput = compressOutput, WriteMatFile = writeMatFile, UseNewFormat = useNewFormat
            };

            return(matlabOptions);
        }