コード例 #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);
        }
コード例 #2
0
ファイル: CsvSupport.cs プロジェクト: JSchripsema-IDM/IDM-CMS
 private static void WriteSampleTimes(SolverBase.Trajectories trajectories, TextWriter output)
 {
     if (GetPrivateStaticField("_writeSampleTimes", typeof(CsvOutputOptions)))
     {
         WriteRowHeader("sampletimes", output);
         WriteRowData(trajectories.SampleTimes, output);
     }
 }
コード例 #3
0
ファイル: JsonSupport.cs プロジェクト: clorton/IDM-CMS
        internal static void WriteJsonFile(SolverBase.Trajectories trajectories, JsonOutputOptions outputOptions)
        {
            var jsonSerializer = new JsonSerializer();

            StreamWriter streamWriter;

            if (outputOptions.CompressOutput)
            {
                var fs = File.Open(outputOptions.Filename + ".gz", FileMode.OpenOrCreate, FileAccess.Write);
                var gz = new GZipStream(fs, CompressionMode.Compress);
                streamWriter = new StreamWriter(gz);
            }
            else
            {
                streamWriter = new StreamWriter(outputOptions.Filename);
            }

            using (streamWriter)
                using (var jsonWriter = new JsonTextWriter(streamWriter))
                {
                    jsonWriter.Formatting  = Formatting.Indented;
                    jsonWriter.Indentation = 1;
                    jsonWriter.IndentChar  = '\t';

                    int runCount    = trajectories.Values.First().Length;
                    int sampleCount = trajectories.Values.First()[0].Length;

                    var realizationData = new RealizationData(VersionInfo.Version,
                                                              VersionInfo.Description,
                                                              runCount,
                                                              sampleCount, trajectories.Keys.Select(o => o.Name).ToArray(),
                                                              trajectories.SampleTimes,
                                                              outputOptions.ChannelTitles);

                    int channelIndex = 0;
                    foreach (Observable o in trajectories.Keys)
                    {
                        for (int runIndex = 0; runIndex < trajectories[o].Length; runIndex++)
                        {
                            realizationData.ChannelData[channelIndex++] = trajectories[o][runIndex];
                        }
                    }

                    jsonSerializer.Serialize(jsonWriter, realizationData);
                }
        }
コード例 #4
0
        private static IEnumerable <int> TrajectoryData(SolverBase.Trajectories trajectories)
        {
            int rows    = trajectories.Values.First().Length;
            int columns = trajectories.Values.First()[0].Length;

            for (int iSample = 0; iSample < columns; iSample++)
            {
                foreach (Observable o in trajectories.Keys)
                {
                    float[][] runs = trajectories[o];
                    for (int iRun = 0; iRun < rows; iRun++)
                    {
                        yield return((int)runs[iRun][iSample]);
                    }
                }
            }
        }
コード例 #5
0
ファイル: CsvSupport.cs プロジェクト: JSchripsema-IDM/IDM-CMS
        private static void WriteTrajectoryData(SolverBase.Trajectories trajectories, CsvOutputOptions outputOptions, TextWriter output)
        {
            bool writeObservableInfo = GetPrivateStaticField("_writeObservableInfo", typeof(CsvOutputOptions));

            foreach (Observable o in trajectories.Keys)
            {
                float[][] observableTrajectories = trajectories[o];
                var       header = new StringBuilder();
                for (int runIndex = 0; runIndex < observableTrajectories.Length; runIndex++)
                {
                    if (writeObservableInfo)
                    {
                        BuildRowHeader(o, runIndex, outputOptions, header);
                        WriteRowHeader(header.ToString(), output);
                    }
                    WriteRowData(observableTrajectories[runIndex], output);
                }
            }
        }
コード例 #6
0
ファイル: CsvSupport.cs プロジェクト: JSchripsema-IDM/IDM-CMS
        internal static void WriteCsvFile(SolverBase.Trajectories trajectories, CsvOutputOptions outputOptions)
        {
            TextWriter output;

            if (outputOptions.CompressOutput)
            {
                var fileStream = File.Open(outputOptions.Filename + ".gz", FileMode.OpenOrCreate, FileAccess.Write);
                var gZipStream = new GZipStream(fileStream, CompressionMode.Compress);
                output = new StreamWriter(gZipStream);
            }
            else
            {
                output = new StreamWriter(outputOptions.Filename);
            }

            using (output)
            {
                WriteVersionInfo(output);
                WriteSampleTimes(trajectories, output);
                WriteTrajectoryData(trajectories, outputOptions, output);
            }
        }