From cd05d0ee034dd0d078a4649c1d5ceb572c66d0e0 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Fri, 28 Aug 2020 16:33:33 -0400 Subject: [PATCH] initial commit --- .../DataSetCollection/SDFDataFormat.uexml | 20 +++ .../Scientific/DataSet/DataSetEditor.glade | 39 ++++++ ...iversalEditor.Extensions.Scientific.csproj | 54 ++++++++ .../DataSetCollectionEditor.cs | 131 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 46 ++++++ ...or.Plugins.Scientific.UserInterface.csproj | 68 +++++++++ .../DataFormats/NASA/CDF/CDFDataFormat.cs | 106 ++++++++++++++ .../DataFormats/NASA/CDF/CDFFileFlags.cs | 39 ++++++ .../DataFormats/NASA/CDF/CDFRecordType.cs | 83 +++++++++++ .../DataFormats/SDF/SDFDataFormat.cs | 126 +++++++++++++++++ .../DataFormats/SDF/SDFDataSetDataType.cs | 31 +++++ .../ObjectModels/DataSetCollection/DataSet.cs | 73 ++++++++++ .../DataSetCollectionObjectModel.cs | 52 +++++++ .../Properties/AssemblyInfo.cs | 46 ++++++ .../UniversalEditor.Plugins.Scientific.csproj | 62 +++++++++ UniversalEditor.sln | 21 +++ 16 files changed, 997 insertions(+) create mode 100644 Extensions/UniversalEditor.Extensions.Scientific/Associations/DataSetCollection/SDFDataFormat.uexml create mode 100644 Extensions/UniversalEditor.Extensions.Scientific/Editors/Scientific/DataSet/DataSetEditor.glade create mode 100644 Extensions/UniversalEditor.Extensions.Scientific/UniversalEditor.Extensions.Scientific.csproj create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Editors/DataSetCollection/DataSetCollectionEditor.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Properties/AssemblyInfo.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface.csproj create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFDataFormat.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFFileFlags.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFRecordType.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataFormat.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataSetDataType.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSet.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSetCollectionObjectModel.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/Properties/AssemblyInfo.cs create mode 100644 Plugins/UniversalEditor.Plugins.Scientific/UniversalEditor.Plugins.Scientific.csproj diff --git a/Extensions/UniversalEditor.Extensions.Scientific/Associations/DataSetCollection/SDFDataFormat.uexml b/Extensions/UniversalEditor.Extensions.Scientific/Associations/DataSetCollection/SDFDataFormat.uexml new file mode 100644 index 00000000..9b40ad91 --- /dev/null +++ b/Extensions/UniversalEditor.Extensions.Scientific/Associations/DataSetCollection/SDFDataFormat.uexml @@ -0,0 +1,20 @@ + + + + + + + + *.sdf + + + + + + + + + + + + diff --git a/Extensions/UniversalEditor.Extensions.Scientific/Editors/Scientific/DataSet/DataSetEditor.glade b/Extensions/UniversalEditor.Extensions.Scientific/Editors/Scientific/DataSet/DataSetEditor.glade new file mode 100644 index 00000000..3a1110d2 --- /dev/null +++ b/Extensions/UniversalEditor.Extensions.Scientific/Editors/Scientific/DataSet/DataSetEditor.glade @@ -0,0 +1,39 @@ + + + + + + False + + + + + + True + False + vertical + + + True + True + in + + + True + True + + + + + + + + True + True + 0 + + + + + + diff --git a/Extensions/UniversalEditor.Extensions.Scientific/UniversalEditor.Extensions.Scientific.csproj b/Extensions/UniversalEditor.Extensions.Scientific/UniversalEditor.Extensions.Scientific.csproj new file mode 100644 index 00000000..670178ad --- /dev/null +++ b/Extensions/UniversalEditor.Extensions.Scientific/UniversalEditor.Extensions.Scientific.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {D46D9232-F585-4552-B3CA-6B0F284B746A} + Library + Properties + UniversalEditor.Extensions.Scientific + UniversalEditor.Extensions.Scientific + v4.0 + 512 + + true + ..\..\..\Production.snk + 4.0.2019.12 + + + true + full + false + ..\..\Output\Debug\Extensions + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Extensions + TRACE + prompt + 4 + + + + + + + + + + + + + diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Editors/DataSetCollection/DataSetCollectionEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Editors/DataSetCollection/DataSetCollectionEditor.cs new file mode 100644 index 00000000..9f389931 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Editors/DataSetCollection/DataSetCollectionEditor.cs @@ -0,0 +1,131 @@ +// +// DataSetEditor.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls.ListView; +using UniversalEditor.Plugins.Scientific.ObjectModels.DataSetCollection; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Plugins.Scientific.UserInterface.Editors.DataSetCollection +{ + [ContainerLayout("~/Editors/Scientific/DataSet/DataSetEditor.glade")] + public class DataSetCollectionEditor : Editor + { + private ListViewControl tv = null; + + private static EditorReference _er = null; + public override EditorReference MakeReference() + { + if (_er == null) + { + _er = base.MakeReference(); + _er.SupportedObjectModels.Add(typeof(DataSetCollectionObjectModel)); + } + return _er; + } + + public override void UpdateSelections() + { + } + + protected override Selection CreateSelectionInternal(object content) + { + return null; + } + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + + OnObjectModelChanged(e); + } + + private void tm_RowCompare(object sender, TreeModelRowCompareEventArgs e) + { + float? _Value = e.Left.RowColumns[e.ColumnIndex].GetExtraData("value"); + if (_Value == null) _Value = 0.0f; + + float? value = e.Right.RowColumns[e.ColumnIndex].GetExtraData("value"); + if (value == null) value = 0.0f; + + e.Value = _Value.Value.CompareTo(value.Value); + e.Handled = true; + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + + if (!IsCreated) return; + + tv.Columns.Clear(); + tv.Model = null; + + DataSetCollectionObjectModel dsc = (ObjectModel as DataSetCollectionObjectModel); + if (dsc == null) return; + + DataSet ds = null; + if (dsc.DataSets.Count > 0) + ds = dsc.DataSets[0]; + + if (ds != null) + { + List list = new List(); + for (int i = 0; i < ds.Dimensions; i++) + { + list.Add(typeof(string)); + } + DefaultTreeModel tm = new DefaultTreeModel(list.ToArray()); + tm.RowCompare += tm_RowCompare; + + for (int i = 0; i < ds.Dimensions; i++) + { + tv.Columns.Add(new ListViewColumnText(tm.Columns[i], i.ToString())); + + for (int j = 0; j < ds.Sizes[i]; j++) + { + float? val = ds.GetValue(i, j); + + TreeModelRow row = null; + if (j >= tm.Rows.Count) + { + row = new TreeModelRow(); + for (int i1 = 0; i1 < ds.Dimensions; i1++) + { + row.RowColumns.Add(new TreeModelRowColumn(tm.Columns[i], String.Empty)); + } + tm.Rows.Add(row); + } + else + { + row = tm.Rows[j]; + } + row.RowColumns[i].Value = (val == null ? String.Empty : val.ToString()); + row.RowColumns[i].SetExtraData("value", val); + } + } + + tv.Model = tm; + } + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Properties/AssemblyInfo.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b6585638 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("UniversalEditor.Plugins.Scientific.UserInterface")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Mike Becker's Software")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker's Software")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface.csproj new file mode 100644 index 00000000..3a32b6bf --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface/UniversalEditor.Plugins.Scientific.UserInterface.csproj @@ -0,0 +1,68 @@ + + + + Debug + AnyCPU + {5F7935DF-55DF-44AC-8B0F-A395658AD7E0} + Library + UniversalEditor.Plugins.Scientific.UserInterface + UniversalEditor.Plugins.Scientific.UserInterface + v4.7 + 4.0.2019.12 + + + true + full + false + ..\..\Output\Debug\Plugins + DEBUG; + prompt + 4 + false + + + true + ..\..\Output\Release\Plugins + prompt + 4 + false + + + + + + + + + + + + + + + {2D4737E6-6D95-408A-90DB-8DFF38147E85} + UniversalEditor.Core + + + {30467E5C-05BC-4856-AADC-13906EF4CADD} + UniversalEditor.Essential + + + {B9E4DD2F-A059-476F-823A-1AA8C1970663} + UniversalEditor.Plugins.Scientific + + + {8622EBC4-8E20-476E-B284-33D472081F5C} + UniversalEditor.UserInterface + + + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + MBS.Framework + + + {29E1C1BB-3EA5-4062-B62F-85EEC703FE07} + MBS.Framework.UserInterface + + + + \ No newline at end of file diff --git a/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFDataFormat.cs b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFDataFormat.cs new file mode 100644 index 00000000..d3e303a4 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFDataFormat.cs @@ -0,0 +1,106 @@ +// +// CDFDataFormat.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.IO; + +namespace UniversalEditor.Plugins.Scientific.DataFormats.NASA.CDF +{ + public class CDFDataFormat : DataFormat + { + private const int COPYRIGHT_FIELD_LENGTH_BEFORE_2_5 = 1945; + private const int COPYRIGHT_FIELD_LENGTH_AFTER_2_5 = 256; + private readonly Version VERSION_2_5 = new Version(2, 5); + + public Version FormatVersion { get; set; } = new Version(2, 5); + + protected override void LoadInternal(ref ObjectModel objectModel) + { + Reader reader = Accessor.Reader; + reader.Endianness = Endianness.BigEndian; + + uint magic = reader.ReadUInt32(); // 0xCDF26002, 0xCDF30000 + uint compressionFlag = reader.ReadUInt32(); // 0x0000FFFF uncompressed, 0xCCCC0001 compressed + uint dummy = reader.ReadUInt32(); // 0x00000000 + + while (reader.EndOfStream) + { + long pos = reader.Accessor.Position; + uint recordSize = reader.ReadUInt32(); // 318 + CDFRecordType recordType = (CDFRecordType)reader.ReadUInt32(); // 1 - CDR + + switch (recordType) + { + case CDFRecordType.CDR: + { + int GDRoffset = reader.ReadInt32(); + + // The version of the CDF distribution (library) that created this CDF. CDF + // distributions are identi ed with four values: version, release, increment, + // and sub-increment.For example, CDF V2.5.8a is CDF version 2, release 5, + // increment 8, sub - increment `a'. Note that the sub-increment is not stored in a CDF. + int version = reader.ReadInt32(); + + // The release of the CDF distribution that created this CDF. See the Version field above. + int release = reader.ReadInt32(); + + // The data encoding for attribute entry and variable values. + int encoding = reader.ReadInt32(); + + CDFFileFlags flags = (CDFFileFlags)reader.ReadInt32(); + + int rfuA = reader.ReadInt32(); // reserved + int rfuB = reader.ReadInt32(); // reserved + + // The increment of the CDF distribution that created this CDF. See the Version field above. Prior to CDF V2.1 this field was always set to zero. + int increment = reader.ReadInt32(); + + int rfuD = reader.ReadInt32(); // reserved + int rfuE = reader.ReadInt32(); // reserved + + FormatVersion = new Version(version, release, increment); + + string copyright = null; + if (FormatVersion < VERSION_2_5) + { + copyright = reader.ReadFixedLengthString(COPYRIGHT_FIELD_LENGTH_BEFORE_2_5); + } + else + { + copyright = reader.ReadFixedLengthString(COPYRIGHT_FIELD_LENGTH_AFTER_2_5); + } + + break; + } + } + + if (reader.Accessor.Position < pos + recordSize) + { + reader.Accessor.Seek((pos + recordSize) - reader.Accessor.Position, SeekOrigin.Current); + } + } + } + + protected override void SaveInternal(ObjectModel objectModel) + { + throw new NotImplementedException(); + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFFileFlags.cs b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFFileFlags.cs new file mode 100644 index 00000000..5cf47919 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFFileFlags.cs @@ -0,0 +1,39 @@ +// +// CDFFileFlags.cs - flags describing the various aspects of a CDF file +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.Scientific.DataFormats.NASA.CDF +{ + /// + /// Flags describing the various aspects of a CDF file. + /// + [Flags()] + public enum CDFFileFlags + { + /// + /// The majority of variable values within a variable record. Set indicates row - majority. Clear indicates column-majority. + /// + RowMajority = 0x00000001, + /// + /// The file format of the CDF. Set indicates single-file. Clear indicates multi-file. + /// + SingleFile = 0x00000002 + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFRecordType.cs b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFRecordType.cs new file mode 100644 index 00000000..513ac1db --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/NASA/CDF/CDFRecordType.cs @@ -0,0 +1,83 @@ +// +// CDFRecordType.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.Scientific.DataFormats.NASA.CDF +{ + public enum CDFRecordType : uint + { + /// + /// CDF Descriptor Record. General information about the CDF. + /// + CDR = 0x00000001, + /// + /// Global Descriptor Record. Additional general information about the CDF. + /// + GDR = 0x00000002, + /// + /// rVariable Descriptor Record. Information about an rVariable. + /// + rVDR = 0x00000003, + /// + /// Attribute Descriptor Record. Information about an attribute. + /// + ADR = 0x00000004, + /// + /// Attribute g/rEntry Descriptor Record. Information about a gEntry or rEntry of an attribute. + /// + AgrEDR = 0x00000005, + /// + /// Variable Index Record. Indexing information for a variable. + /// + VXR = 0x00000006, + /// + /// Variable Values Record. One or more variable records. + /// + VVR = 0x00000007, + /// + /// zVariable Descriptor Record. Information about a zVariable. + /// + zVDR = 0x00000008, + /// + /// Attribute zEntry Descriptor Record. Information about a zEntry of an attribute. + /// + AzEDR = 0x00000009, + /// + /// Compressed CDF Record. Information about a compressed CDF/variable. + /// + CCR = 0x0000000A, + /// + /// Compression Parameters Record. Information about the compression used for a CDF/variable. + /// + CPR = 0x0000000B, + /// + /// Sparseness Parameters Record. Information about the speci ed sparseness array. + /// + SPR = 0x0000000C, + /// + /// Compressed Variable Values Record. Information for the compressed CDF/variable. + /// + CVVR = 0x0000000D, + /// + /// Unused Internal Record. An internal record not currently being used. + /// + UIR = 0xFFFFFFFF + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataFormat.cs b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataFormat.cs new file mode 100644 index 00000000..cb040e63 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataFormat.cs @@ -0,0 +1,126 @@ +// +// SDFDataFormat.cs - a platform-independent data format that works in Fortran, C, and IDL +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.IO; +using UniversalEditor.Plugins.Scientific.ObjectModels.DataSetCollection; + +namespace UniversalEditor.Plugins.Scientific.DataFormats.SDF +{ + /// + /// A platform-independent data format that works in Fortran, C, and IDL. + /// + public class SDFDataFormat : DataFormat + { + private static DataFormatReference _dfr = null; + protected override DataFormatReference MakeReferenceInternal() + { + if (_dfr == null) + { + _dfr = base.MakeReferenceInternal(); + _dfr.Capabilities.Add(typeof(DataSetCollectionObjectModel), DataFormatCapabilities.All); + } + return _dfr; + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + DataSetCollectionObjectModel dsc = (objectModel as DataSetCollectionObjectModel); + if (dsc == null) + throw new ObjectModelNotSupportedException(); + + Reader reader = Accessor.Reader; + string signature = reader.ReadFixedLengthString(11); + + if (signature != "SDF format\0") + throw new InvalidDataFormatException("File does not begin with 'SDF format', 0x00"); + + reader.Endianness = Endianness.BigEndian; + + // location of next available byte in header + ulong hdrlen = reader.ReadUInt64(); + // location of next available byte in data area. This is also equal to the file size. + ulong datalen = reader.ReadUInt64(); + // number of datasets currently in file + uint ndatasets = reader.ReadUInt32(); + + // The current size of the header (initially set to HINITSZ, and incremented in blocks of HINITSZ as + // necessary.Default value of HINITSZ is 2000, but can be set by user. + ulong hdr_alloc_size = reader.ReadUInt64(); + + for (uint i = 0; i < ndatasets; i++) + { + string dataset_desc = reader.ReadLine(); + string[] tokenized = dataset_desc.Split(new char[] { ' ' }); + + if (tokenized.Length < 6) throw new InvalidDataFormatException("dataset description (tokenized) does not contain at least 6 elements"); + + DataSet ds = new DataSet(); + + int iorder = Int32.Parse(tokenized[0]); // the order of this dataset in the file + ds.Order = iorder; + + string label = tokenized[1]; + ds.Name = label; + + SDFDataSetDataType dataType = (SDFDataSetDataType)(byte)Char.Parse(tokenized[2]); // a single character denoting the type of data; i.e., 'f', 'i', 'c', or 'b' + switch (dataType) + { + case SDFDataSetDataType.Byte: ds.DataType = typeof(byte); break; + case SDFDataSetDataType.Complex: ds.DataType = typeof(long); break; + case SDFDataSetDataType.Float: ds.DataType = typeof(float); break; + case SDFDataSetDataType.Integer: ds.DataType = typeof(long); break; + } + + int nbpw = Int32.Parse(tokenized[3]); // the number of bytes per word + int ndim = Int32.Parse(tokenized[4]); // the number of dimensions of the dataset or array + ds.Dimensions = ndim; + ds.Sizes = new int[ndim]; + for (int j = 5; j < 5 + ndim; j++) + { + int dim = Int32.Parse(tokenized[j]); // the ndim values of the array dimensions + ds.Sizes[j - 5] = dim; + } + + dsc.DataSets.Add(ds); + } + + reader.Seek((long)hdr_alloc_size, SeekOrigin.Begin); + reader.Seek(19, SeekOrigin.Current); // idk??? + + for (int i = 0; i < dsc.DataSets.Count; i++) + { + for (int j = 0; j < dsc.DataSets[i].Dimensions; j++) + { + for (int k = 0; k < dsc.DataSets[i].Sizes[j]; k++) + { + float w = reader.ReadSingle(); + dsc.DataSets[i].SetValue(j, k, w); + } + } + } + } + + protected override void SaveInternal(ObjectModel objectModel) + { + throw new NotImplementedException(); + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataSetDataType.cs b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataSetDataType.cs new file mode 100644 index 00000000..93c75848 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/DataFormats/SDF/SDFDataSetDataType.cs @@ -0,0 +1,31 @@ +// +// SDFDataSetDataType.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.Scientific.DataFormats.SDF +{ + public enum SDFDataSetDataType : byte + { + Float = (byte)'f', + Integer = (byte)'i', + Complex = (byte)'c', + Byte = (byte)'b' + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSet.cs b/Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSet.cs new file mode 100644 index 00000000..683be269 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSet.cs @@ -0,0 +1,73 @@ +// +// DataSet.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.Scientific.ObjectModels.DataSetCollection +{ + public class DataSet : ICloneable + { + + public class DataSetCollection + : System.Collections.ObjectModel.Collection + { + + } + + public string Name { get; set; } = String.Empty; + public int Order { get; set; } = 0; + public Type DataType { get; set; } = null; + public int Dimensions { get; set; } + public int[] Sizes { get; set; } = null; + + public object Clone() + { + DataSet clone = new DataSet(); + clone.Name = Name.Clone() as string; + clone.Order = Order; + clone.DataType = DataType; + clone.Dimensions = Dimensions; + return clone; + } + + private float?[][] fs = null; + + private void Init() + { + if (fs == null) + { + fs = new float?[Dimensions][]; + for (int i = 0; i < Dimensions; i++) + { + fs[i] = new float?[Sizes[i]]; + } + } + } + public float? GetValue(int nDimension, int nIndex, float? defaultValue = null) + { + Init(); + return fs[nDimension][nIndex].GetValueOrDefault(defaultValue.GetValueOrDefault()); + } + public void SetValue(int nDimension, int nIndex, float? value) + { + Init(); + fs[nDimension][nIndex] = value; + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSetCollectionObjectModel.cs b/Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSetCollectionObjectModel.cs new file mode 100644 index 00000000..f930c188 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/ObjectModels/DataSetCollection/DataSetCollectionObjectModel.cs @@ -0,0 +1,52 @@ +// +// DataSetObjectModel.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.Scientific.ObjectModels.DataSetCollection +{ + public class DataSetCollectionObjectModel : ObjectModel + { + private static ObjectModelReference _omr = null; + protected override ObjectModelReference MakeReferenceInternal() + { + if (_omr == null) + { + _omr = base.MakeReferenceInternal(); + _omr.Title = "Data set collection"; + } + return _omr; + } + + public DataSet.DataSetCollection DataSets { get; } = new DataSet.DataSetCollection(); + + public override void Clear() + { + DataSets.Clear(); + } + + public override void CopyTo(ObjectModel where) + { + for (int i = 0; i < DataSets.Count; i++) + { + DataSets.Add(DataSets[i].Clone() as DataSet); + } + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Scientific/Properties/AssemblyInfo.cs b/Plugins/UniversalEditor.Plugins.Scientific/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..587943c0 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("UniversalEditor.Plugins.Scientific")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Mike Becker's Software")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker's Software")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Plugins/UniversalEditor.Plugins.Scientific/UniversalEditor.Plugins.Scientific.csproj b/Plugins/UniversalEditor.Plugins.Scientific/UniversalEditor.Plugins.Scientific.csproj new file mode 100644 index 00000000..3e70c520 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Scientific/UniversalEditor.Plugins.Scientific.csproj @@ -0,0 +1,62 @@ + + + + Debug + AnyCPU + {B9E4DD2F-A059-476F-823A-1AA8C1970663} + Library + UniversalEditor.Plugins.Scientific + UniversalEditor.Plugins.Scientific + v4.7 + 4.0.2019.12 + + + true + full + false + ..\..\Output\Debug\Plugins + DEBUG; + prompt + 4 + false + + + true + ..\..\Output\Release\Plugins + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + + + + + + {2D4737E6-6D95-408A-90DB-8DFF38147E85} + UniversalEditor.Core + + + {30467E5C-05BC-4856-AADC-13906EF4CADD} + UniversalEditor.Essential + + + + \ No newline at end of file diff --git a/UniversalEditor.sln b/UniversalEditor.sln index e2e08d16..cdaf48ad 100644 --- a/UniversalEditor.sln +++ b/UniversalEditor.sln @@ -189,6 +189,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.MSBuild.Tas EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Compiler", "Applications\UniversalEditor.Compiler\UniversalEditor.Compiler.csproj", "{5E639F63-97B0-4B34-8928-29A5A3C661F4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Scientific.UserInterface", "Plugins.UserInterface\UniversalEditor.Plugins.Scientific.UserInterface\UniversalEditor.Plugins.Scientific.UserInterface.csproj", "{5F7935DF-55DF-44AC-8B0F-A395658AD7E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Scientific", "Plugins\UniversalEditor.Plugins.Scientific\UniversalEditor.Plugins.Scientific.csproj", "{B9E4DD2F-A059-476F-823A-1AA8C1970663}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Extensions.Scientific", "Extensions\UniversalEditor.Extensions.Scientific\UniversalEditor.Extensions.Scientific.csproj", "{D46D9232-F585-4552-B3CA-6B0F284B746A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -545,6 +551,18 @@ Global {5E639F63-97B0-4B34-8928-29A5A3C661F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {5E639F63-97B0-4B34-8928-29A5A3C661F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {5E639F63-97B0-4B34-8928-29A5A3C661F4}.Release|Any CPU.Build.0 = Release|Any CPU + {5F7935DF-55DF-44AC-8B0F-A395658AD7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F7935DF-55DF-44AC-8B0F-A395658AD7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F7935DF-55DF-44AC-8B0F-A395658AD7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F7935DF-55DF-44AC-8B0F-A395658AD7E0}.Release|Any CPU.Build.0 = Release|Any CPU + {B9E4DD2F-A059-476F-823A-1AA8C1970663}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9E4DD2F-A059-476F-823A-1AA8C1970663}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9E4DD2F-A059-476F-823A-1AA8C1970663}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9E4DD2F-A059-476F-823A-1AA8C1970663}.Release|Any CPU.Build.0 = Release|Any CPU + {D46D9232-F585-4552-B3CA-6B0F284B746A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D46D9232-F585-4552-B3CA-6B0F284B746A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D46D9232-F585-4552-B3CA-6B0F284B746A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D46D9232-F585-4552-B3CA-6B0F284B746A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {6F0AB1AF-E1A1-4D19-B19C-05BBB15C94B2} = {05D15661-E684-4EC9-8FBD-C014BA433CC5} @@ -633,6 +651,9 @@ Global {8A0618F6-4FE6-4BA2-81DE-87C222235FBE} = {5E4765D1-3959-4433-8E9C-992E26D7BE62} {676D52A3-F285-4F58-B7A8-7BF415E3F733} = {0399182F-AF56-4E86-B229-EAB38C2EE6AF} {5E639F63-97B0-4B34-8928-29A5A3C661F4} = {05D15661-E684-4EC9-8FBD-C014BA433CC5} + {5F7935DF-55DF-44AC-8B0F-A395658AD7E0} = {7B535D74-5496-4802-B809-89ED88274A91} + {B9E4DD2F-A059-476F-823A-1AA8C1970663} = {2ED32D16-6C06-4450-909A-40D32DA67FB4} + {D46D9232-F585-4552-B3CA-6B0F284B746A} = {5E4765D1-3959-4433-8E9C-992E26D7BE62} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0