diff --git a/.appveyor.yml b/.appveyor.yml
index 4221aa0..512908a 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -1,5 +1,5 @@
-image: Visual Studio 2017
-version: 1.0.20-{build}
+image: Visual Studio 2022
+version: 1.0.21-{build}
environment:
global:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
diff --git a/.gitignore b/.gitignore
index 1746e32..9a202af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
bin
obj
+/.vs
+/*.user
diff --git a/BuildAllReleaseVersions.bat b/BuildAllReleaseVersions.bat
index 87cdf68..68932dd 100644
--- a/BuildAllReleaseVersions.bat
+++ b/BuildAllReleaseVersions.bat
@@ -1,3 +1,16 @@
-SET BUILDTOOL=c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
-%BUILDTOOL% CSMatIO.sln /p:Configuration=Release /p:TargetFrameworkVersion=v2.0
-%BUILDTOOL% CSMatIO.sln /p:Configuration=Release /p:TargetFrameworkVersion=v4.0
+SET BUILDTOOL="C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
+
+REM Restore NuGet packages first
+dotnet restore src\csmatio.csproj
+
+REM Build for specific framework targets
+dotnet build src\csmatio.csproj -c Release -f netstandard2.0
+dotnet build src\csmatio.csproj -c Release -f netstandard2.1
+dotnet build src\csmatio.csproj -c Release -f net6.0
+dotnet build src\csmatio.csproj -c Release -f net8.0
+
+REM Create NuGet package with all frameworks
+dotnet pack src\csmatio.csproj -c Release --no-build
+
+echo Press any key to continue...
+pause > nul
diff --git a/CSMatIO.sln b/CSMatIO.sln
index 5f29178..f9c6d0c 100644
--- a/CSMatIO.sln
+++ b/CSMatIO.sln
@@ -1,13 +1,18 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.21005.1
+# Visual Studio Version 17
+VisualStudioVersion = 17.12.35728.132
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csmatio", "src\csmatio.csproj", "{D6EB17BF-9074-484F-9950-E06169A3C39D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSMatIOTest", "demo\CSMatIOTest.csproj", "{C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csmatio.test", "test\csmatio.test.csproj", "{1425535D-7FE0-417E-8B2A-837F498B4792}"
+ ProjectSection(ProjectDependencies) = postProject
+ {D6EB17BF-9074-484F-9950-E06169A3C39D} = {D6EB17BF-9074-484F-9950-E06169A3C39D}
+ EndProjectSection
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{30C632C4-5F79-4893-84E9-CA4CE498846C}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsMatIoTestExampleWpf", "demo-wpf\CsMatIoTestExampleWpf.csproj", "{A5A2B6A5-2F80-44BA-8852-562D5048C019}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsMatIoTestExampleForms", "demo-forms\CsMatIoTestExampleForms.csproj", "{C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,14 +24,18 @@ Global
{D6EB17BF-9074-484F-9950-E06169A3C39D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6EB17BF-9074-484F-9950-E06169A3C39D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6EB17BF-9074-484F-9950-E06169A3C39D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1425535D-7FE0-417E-8B2A-837F498B4792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1425535D-7FE0-417E-8B2A-837F498B4792}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1425535D-7FE0-417E-8B2A-837F498B4792}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1425535D-7FE0-417E-8B2A-837F498B4792}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A5A2B6A5-2F80-44BA-8852-562D5048C019}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A5A2B6A5-2F80-44BA-8852-562D5048C019}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A5A2B6A5-2F80-44BA-8852-562D5048C019}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A5A2B6A5-2F80-44BA-8852-562D5048C019}.Release|Any CPU.Build.0 = Release|Any CPU
{C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}.Release|Any CPU.Build.0 = Release|Any CPU
- {30C632C4-5F79-4893-84E9-CA4CE498846C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {30C632C4-5F79-4893-84E9-CA4CE498846C}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {30C632C4-5F79-4893-84E9-CA4CE498846C}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {30C632C4-5F79-4893-84E9-CA4CE498846C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/demo/CSMatIOTest.csproj b/demo-forms/CsMatIoTestExampleForms.csproj
similarity index 97%
rename from demo/CSMatIOTest.csproj
rename to demo-forms/CsMatIoTestExampleForms.csproj
index faad076..b8f9005 100644
--- a/demo/CSMatIOTest.csproj
+++ b/demo-forms/CsMatIoTestExampleForms.csproj
@@ -1,81 +1,82 @@
-
-
-
- Debug
- AnyCPU
- {C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}
- WinExe
- bin\
- Properties
- CSMatIOTest
- CSMatIOTest
- v4.7.1
- true
- prompt
- 4
-
-
- NET40
- true
- true
- full
- false
- false
-
-
- NET40
- false
- pdbonly
- true
- false
-
-
-
-
-
-
-
-
-
-
-
- Form
-
-
- Main.cs
-
-
-
-
- Designer
- Main.cs
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
- True
- Resources.resx
- True
-
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
- True
- Settings.settings
- True
-
-
-
-
- {D6EB17BF-9074-484F-9950-E06169A3C39D}
- csmatio
-
-
-
-
+
+
+
+ Debug
+ AnyCPU
+ {C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}
+ WinExe
+ bin\
+ Properties
+ CSMatIOTest
+ CSMatIOTest
+ v4.7.1
+ true
+ prompt
+ 4
+ true
+
+
+ NET40
+ true
+ true
+ full
+ false
+ false
+
+
+ NET40
+ false
+ pdbonly
+ true
+ false
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ Main.cs
+
+
+
+
+ Designer
+ Main.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+ True
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+ {D6EB17BF-9074-484F-9950-E06169A3C39D}
+ csmatio
+
+
+
+
diff --git a/demo/Main.Designer.cs b/demo-forms/Main.Designer.cs
similarity index 100%
rename from demo/Main.Designer.cs
rename to demo-forms/Main.Designer.cs
diff --git a/demo/Main.cs b/demo-forms/Main.cs
similarity index 100%
rename from demo/Main.cs
rename to demo-forms/Main.cs
diff --git a/demo/Main.resx b/demo-forms/Main.resx
similarity index 100%
rename from demo/Main.resx
rename to demo-forms/Main.resx
diff --git a/demo/Program.cs b/demo-forms/Program.cs
similarity index 100%
rename from demo/Program.cs
rename to demo-forms/Program.cs
diff --git a/demo/Properties/AssemblyInfo.cs b/demo-forms/Properties/AssemblyInfo.cs
similarity index 100%
rename from demo/Properties/AssemblyInfo.cs
rename to demo-forms/Properties/AssemblyInfo.cs
diff --git a/demo/Properties/Resources.Designer.cs b/demo-forms/Properties/Resources.Designer.cs
similarity index 100%
rename from demo/Properties/Resources.Designer.cs
rename to demo-forms/Properties/Resources.Designer.cs
diff --git a/demo/Properties/Resources.resx b/demo-forms/Properties/Resources.resx
similarity index 100%
rename from demo/Properties/Resources.resx
rename to demo-forms/Properties/Resources.resx
diff --git a/demo/Properties/Settings.Designer.cs b/demo-forms/Properties/Settings.Designer.cs
similarity index 100%
rename from demo/Properties/Settings.Designer.cs
rename to demo-forms/Properties/Settings.Designer.cs
diff --git a/demo/Properties/Settings.settings b/demo-forms/Properties/Settings.settings
similarity index 100%
rename from demo/Properties/Settings.settings
rename to demo-forms/Properties/Settings.settings
diff --git a/demo-forms/README.md b/demo-forms/README.md
new file mode 100644
index 0000000..0768887
--- /dev/null
+++ b/demo-forms/README.md
@@ -0,0 +1,35 @@
+# CSMatIO WPF Demo Application
+
+This is a .NET 8.0 WPF demo application for the CSMatIO library, which provides functionality for reading and writing MATLAB MAT-files in C#.
+
+## Features
+
+- Read MAT-files and display their contents
+- Create MAT-files with various data types:
+ - Cell arrays
+ - Structures
+ - Character arrays
+ - Sparse arrays
+ - Numeric arrays (Double, Single, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64)
+ - Imaginary matrices
+
+## Requirements
+
+- .NET 8.0 SDK or later
+- Windows operating system
+
+## Building and Running
+
+1. Open the solution in Visual Studio 2022 or later
+2. Build the solution
+3. Run the CSMatIOTestWPF project
+
+## Usage
+
+1. To read a MAT-file, click the "Read MAT-File" button and select a file
+2. To create a MAT-file:
+ - Select the data types you want to include
+ - Click the "Create MAT-File" button
+ - Choose a location to save the file
+
+The output window will display information about the operations performed.
\ No newline at end of file
diff --git a/demo/app.config b/demo-forms/app.config
similarity index 100%
rename from demo/app.config
rename to demo-forms/app.config
diff --git a/demo-froms/CsMatIoTestExampleForms.csproj b/demo-froms/CsMatIoTestExampleForms.csproj
new file mode 100644
index 0000000..b8f9005
--- /dev/null
+++ b/demo-froms/CsMatIoTestExampleForms.csproj
@@ -0,0 +1,82 @@
+
+
+
+ Debug
+ AnyCPU
+ {C5C58FCB-2DDA-4472-ACED-0C97FE09F7C1}
+ WinExe
+ bin\
+ Properties
+ CSMatIOTest
+ CSMatIOTest
+ v4.7.1
+ true
+ prompt
+ 4
+ true
+
+
+ NET40
+ true
+ true
+ full
+ false
+ false
+
+
+ NET40
+ false
+ pdbonly
+ true
+ false
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ Main.cs
+
+
+
+
+ Designer
+ Main.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+ True
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+ {D6EB17BF-9074-484F-9950-E06169A3C39D}
+ csmatio
+
+
+
+
diff --git a/demo-wpf/App.xaml b/demo-wpf/App.xaml
new file mode 100644
index 0000000..d156734
--- /dev/null
+++ b/demo-wpf/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/demo-wpf/App.xaml.cs b/demo-wpf/App.xaml.cs
new file mode 100644
index 0000000..79c12f9
--- /dev/null
+++ b/demo-wpf/App.xaml.cs
@@ -0,0 +1,11 @@
+using System.Windows;
+
+namespace CSMatIOTest
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
\ No newline at end of file
diff --git a/demo-wpf/CsMatIoTestExampleWpf.csproj b/demo-wpf/CsMatIoTestExampleWpf.csproj
new file mode 100644
index 0000000..ae20d38
--- /dev/null
+++ b/demo-wpf/CsMatIoTestExampleWpf.csproj
@@ -0,0 +1,15 @@
+
+
+
+ WinExe
+ net8.0-windows
+ true
+ CSMatIOTest
+ CSMatIOTest
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo-wpf/MainWindow.xaml b/demo-wpf/MainWindow.xaml
new file mode 100644
index 0000000..2f2ec6e
--- /dev/null
+++ b/demo-wpf/MainWindow.xaml
@@ -0,0 +1,116 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo-wpf/MainWindow.xaml.cs b/demo-wpf/MainWindow.xaml.cs
new file mode 100644
index 0000000..e4c8ab7
--- /dev/null
+++ b/demo-wpf/MainWindow.xaml.cs
@@ -0,0 +1,268 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Windows;
+using Microsoft.Win32;
+using csmatio.io;
+using csmatio.types;
+
+namespace CSMatIOTest
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ private bool toggleCheck;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+
+ private void btnRead_Click(object sender, RoutedEventArgs e)
+ {
+ var openFileDialog = new OpenFileDialog
+ {
+ Filter = "MAT-files|*.mat|All files|*.*",
+ Title = "Select a MAT-file"
+ };
+
+ if (openFileDialog.ShowDialog() == true)
+ {
+ var fileName = openFileDialog.FileName;
+
+ txtOutput.Text = txtOutput.Text + "Attempting to read the file '" + fileName + "'...";
+ try
+ {
+ var mfr = new MatFileReader(fileName);
+ txtOutput.Text += "Done!\nMAT-file contains the following:\n";
+ txtOutput.Text += mfr.MatFileHeader + "\n";
+ foreach (var mla in mfr.Data)
+ {
+ txtOutput.Text = txtOutput.Text + mla.ContentToString() + "\n";
+ }
+ }
+ catch (IOException)
+ {
+ txtOutput.Text = txtOutput.Text + "Invalid MAT-file!\n";
+ MessageBox.Show("Invalid binary MAT-file! Please select a valid binary MAT-file.",
+ "Invalid MAT-file", MessageBoxButton.OK, MessageBoxImage.Exclamation);
+ }
+ }
+ }
+
+ private void btnCreate_Click(object sender, RoutedEventArgs e)
+ {
+ var mlList = new List();
+ // Go through each of the options to add in the file
+ if (chkCell.IsChecked == true)
+ {
+ mlList.Add(CreateCellArray());
+ }
+ if (chkStruct.IsChecked == true)
+ {
+ mlList.Add(CreateStructArray());
+ }
+ if (chkChar.IsChecked == true)
+ {
+ mlList.Add(CreateCharArray());
+ }
+ if (chkSparse.IsChecked == true)
+ {
+ mlList.Add(CreateSparseArray());
+ }
+ if (chkDouble.IsChecked == true)
+ {
+ mlList.Add(CreateDoubleArray());
+ }
+ if (chkSingle.IsChecked == true)
+ {
+ mlList.Add(CreateSingleArray());
+ }
+ if (chkInt8.IsChecked == true)
+ {
+ mlList.Add(CreateInt8Array());
+ }
+ if (chkUInt8.IsChecked == true)
+ {
+ mlList.Add(CreateUInt8Array());
+ }
+ if (chkInt16.IsChecked == true)
+ {
+ mlList.Add(CreateInt16Array());
+ }
+ if (chkUInt16.IsChecked == true)
+ {
+ mlList.Add(CreateUInt16Array());
+ }
+ if (chkInt32.IsChecked == true)
+ {
+ mlList.Add(CreateInt32Array());
+ }
+ if (chkUInt32.IsChecked == true)
+ {
+ mlList.Add(CreateUIn32Array());
+ }
+ if (chkInt64.IsChecked == true)
+ {
+ mlList.Add(CreateInt64Array());
+ }
+ if (chkUInt64.IsChecked == true)
+ {
+ mlList.Add(CreateUInt64Array());
+ }
+ if (chkImagMatrix.IsChecked == true)
+ {
+ mlList.Add(CreateImaginaryArray());
+ }
+
+ if (mlList.Count <= 0)
+ {
+ MessageBox.Show("You must select at least one MAT-file Creation Element in order to" +
+ " create a MAT-file.", "No MAT-file elements selected", MessageBoxButton.OK,
+ MessageBoxImage.Exclamation);
+ return;
+ }
+
+ // Get a filename name to write the file out to
+ var saveFileDialog = new SaveFileDialog
+ {
+ Filter = "MAT-Files|*.mat|All files|*.*"
+ };
+
+ if (saveFileDialog.ShowDialog() != true)
+ {
+ return;
+ }
+
+ var filename = saveFileDialog.FileName;
+
+ txtOutput.Text += "Creating the MAT-file '" + filename + "'...";
+
+ try
+ {
+ var mfw = new MatFileWriter(filename, mlList, chkCompress.IsChecked == true);
+ }
+ catch (Exception err)
+ {
+ MessageBox.Show("There was an error when creating the MAT-file: \n" + err,
+ "MAT-File Creation Error!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
+ txtOutput.Text += "Failed!\n";
+ return;
+ }
+
+ txtOutput.Text += "Done!\nMAT-File created with the following data: \n";
+ foreach (var mla in mlList)
+ txtOutput.Text += mla.ContentToString() + "\n";
+ }
+
+ private void btnCheckEmAll_Click(object sender, RoutedEventArgs e)
+ {
+ toggleCheck = !toggleCheck;
+
+ chkCell.IsChecked =
+ chkStruct.IsChecked =
+ chkChar.IsChecked =
+ chkSparse.IsChecked =
+ chkDouble.IsChecked =
+ chkSingle.IsChecked =
+ chkInt8.IsChecked =
+ chkUInt8.IsChecked =
+ chkInt16.IsChecked =
+ chkUInt16.IsChecked =
+ chkInt32.IsChecked =
+ chkUInt32.IsChecked =
+ chkInt64.IsChecked =
+ chkUInt64.IsChecked =
+ chkImagMatrix.IsChecked =
+ toggleCheck;
+ }
+
+ private static MLArray CreateCellArray()
+ {
+ var names = new[] { "Hello", "World", "I am", "a", "MAT-file" };
+ var cell = new MLCell("Names", new[] { names.Length, 1 });
+ for (var i = 0; i < names.Length; i++)
+ cell[i] = new MLChar(null, names[i]);
+ return cell;
+ }
+
+ private static MLArray CreateStructArray()
+ {
+ var structure = new MLStructure("X", new[] { 1, 1 });
+ structure["w", 0] = new MLUInt8("", new byte[] { 1 }, 1);
+ structure["y", 0] = new MLUInt8("", new byte[] { 2 }, 1);
+ structure["z", 0] = new MLUInt8("", new byte[] { 3 }, 1);
+ return structure;
+ }
+
+ private static MLArray CreateCharArray()
+ {
+ return new MLChar("AName", "Hello from .NET 8.0 WPF!");
+ }
+
+ private static MLArray CreateSparseArray()
+ {
+ var sparse = new MLSparse("S", new[] { 3, 3 }, 0, 3);
+ sparse.SetReal(1.5, 0, 0);
+ sparse.SetReal(2.5, 1, 1);
+ sparse.SetReal(3.5, 2, 2);
+ return sparse;
+ }
+
+ private static MLArray CreateDoubleArray() => new MLDouble("Double", new[] { double.MaxValue, double.MinValue }, 1);
+
+ private static MLArray CreateSingleArray() => new MLSingle("Single", new[] { float.MinValue, float.MaxValue }, 1);
+
+ private static MLArray CreateInt8Array() => new MLInt8("Int8", new[] { sbyte.MinValue, sbyte.MaxValue }, 1);
+
+ private static MLArray CreateUInt8Array() => new MLUInt8("UInt8", new[] { byte.MinValue, byte.MaxValue }, 1);
+
+ private static MLArray CreateInt16Array()
+ {
+ return new MLInt16("Int16", new[] { short.MinValue, short.MaxValue }, 1);
+ }
+
+ private static MLArray CreateUInt16Array()
+ {
+ return new MLUInt16("UInt16", new[] { ushort.MinValue, ushort.MaxValue }, 1);
+ }
+
+ private static MLArray CreateInt32Array()
+ {
+ return new MLInt32("Int32", new[] { int.MinValue, int.MaxValue }, 1);
+ }
+
+ private static MLArray CreateUIn32Array()
+ {
+ return new MLUInt32("UInt32", new[] { uint.MinValue, uint.MaxValue }, 1);
+ }
+
+ private static MLArray CreateInt64Array()
+ {
+ return new MLInt64("Int64", new[] { long.MinValue, long.MaxValue }, 1);
+ }
+
+ private static MLArray CreateUInt64Array()
+ {
+ return new MLUInt64("UInt64", new[] { ulong.MinValue, ulong.MaxValue }, 1);
+ }
+
+ private static MLArray CreateImaginaryArray()
+ {
+ // Create a large, randomly generated imaginary array
+ var myRealNums = new long[2000];
+ var myImagNums = new long[2000];
+ var numGen = new Random();
+ for (var i = 0; i < myRealNums.Length; i++)
+ {
+ myRealNums[i] = numGen.Next(int.MinValue, int.MaxValue);
+ myImagNums[i] = numGen.Next(int.MinValue, int.MaxValue);
+ }
+ var myImagArray =
+ new MLInt64("IA", myRealNums, myImagNums, myRealNums.Length / 5);
+ return myImagArray;
+ }
+ }
+}
\ No newline at end of file
diff --git a/demo-wpf/README.md b/demo-wpf/README.md
new file mode 100644
index 0000000..0768887
--- /dev/null
+++ b/demo-wpf/README.md
@@ -0,0 +1,35 @@
+# CSMatIO WPF Demo Application
+
+This is a .NET 8.0 WPF demo application for the CSMatIO library, which provides functionality for reading and writing MATLAB MAT-files in C#.
+
+## Features
+
+- Read MAT-files and display their contents
+- Create MAT-files with various data types:
+ - Cell arrays
+ - Structures
+ - Character arrays
+ - Sparse arrays
+ - Numeric arrays (Double, Single, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64)
+ - Imaginary matrices
+
+## Requirements
+
+- .NET 8.0 SDK or later
+- Windows operating system
+
+## Building and Running
+
+1. Open the solution in Visual Studio 2022 or later
+2. Build the solution
+3. Run the CSMatIOTestWPF project
+
+## Usage
+
+1. To read a MAT-file, click the "Read MAT-File" button and select a file
+2. To create a MAT-file:
+ - Select the data types you want to include
+ - Click the "Create MAT-File" button
+ - Choose a location to save the file
+
+The output window will display information about the operations performed.
\ No newline at end of file
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.Main.resources b/demo/obj-v4.7.1/Debug/CSMatIOTest.Main.resources
deleted file mode 100644
index 6c05a97..0000000
Binary files a/demo/obj-v4.7.1/Debug/CSMatIOTest.Main.resources and /dev/null differ
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.Properties.Resources.resources b/demo/obj-v4.7.1/Debug/CSMatIOTest.Properties.Resources.resources
deleted file mode 100644
index 6c05a97..0000000
Binary files a/demo/obj-v4.7.1/Debug/CSMatIOTest.Properties.Resources.resources and /dev/null differ
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.CopyComplete b/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.CopyComplete
deleted file mode 100644
index e69de29..0000000
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.CoreCompileInputs.cache b/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.CoreCompileInputs.cache
deleted file mode 100644
index 8426ae5..0000000
--- a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.CoreCompileInputs.cache
+++ /dev/null
@@ -1 +0,0 @@
-c5643dbf8820cdbee19bcf7122df367c1521a64c
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.FileListAbsolute.txt b/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.FileListAbsolute.txt
deleted file mode 100644
index 84ef384..0000000
--- a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.FileListAbsolute.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\CSMatIOTest.exe.config
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\CSMatIOTest.exe
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\CSMatIOTest.pdb
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Data.Common.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Diagnostics.StackTrace.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Diagnostics.Tracing.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Globalization.Extensions.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.IO.Compression.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Net.Http.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Net.Sockets.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Runtime.Serialization.Primitives.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Security.Cryptography.Algorithms.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Security.SecureString.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Threading.Overlapped.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\System.Xml.XPath.XDocument.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\csmatio.dll
-C:\projects\private\csmatio.git\demo\bin\Debug-v4.7.1\csmatio.pdb
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.csprojResolveAssemblyReference.cache
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.Main.resources
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.Properties.Resources.resources
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.csproj.GenerateResource.cache
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.csproj.CoreCompileInputs.cache
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.csproj.CopyComplete
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.exe
-C:\projects\private\csmatio.git\demo\obj-v4.7.1\Debug\CSMatIOTest.pdb
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.GenerateResource.cache b/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.GenerateResource.cache
deleted file mode 100644
index dda5c67..0000000
Binary files a/demo/obj-v4.7.1/Debug/CSMatIOTest.csproj.GenerateResource.cache and /dev/null differ
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.csprojResolveAssemblyReference.cache b/demo/obj-v4.7.1/Debug/CSMatIOTest.csprojResolveAssemblyReference.cache
deleted file mode 100644
index 15abc3a..0000000
Binary files a/demo/obj-v4.7.1/Debug/CSMatIOTest.csprojResolveAssemblyReference.cache and /dev/null differ
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.exe b/demo/obj-v4.7.1/Debug/CSMatIOTest.exe
deleted file mode 100644
index 594b9a2..0000000
Binary files a/demo/obj-v4.7.1/Debug/CSMatIOTest.exe and /dev/null differ
diff --git a/demo/obj-v4.7.1/Debug/CSMatIOTest.pdb b/demo/obj-v4.7.1/Debug/CSMatIOTest.pdb
deleted file mode 100644
index e438887..0000000
Binary files a/demo/obj-v4.7.1/Debug/CSMatIOTest.pdb and /dev/null differ
diff --git a/demo/obj-v4.7.1/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/demo/obj-v4.7.1/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
deleted file mode 100644
index e69de29..0000000
diff --git a/demo/obj-v4.7.1/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs b/demo/obj-v4.7.1/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
deleted file mode 100644
index e69de29..0000000
diff --git a/demo/obj-v4.7.1/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/demo/obj-v4.7.1/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
deleted file mode 100644
index e69de29..0000000
diff --git a/readme.md b/readme.md
index 6c642db..1160402 100644
--- a/readme.md
+++ b/readme.md
@@ -43,6 +43,12 @@ David A. Zier
# CHANGE LOG #
+## r21, 2025-05-22 ##
+- update to visualstudio 2022
+- support for netstandard2.0, netstandard2.1, net6.0, net8.0
+- update tests to net 8.0
+- Optimize .mat file loading performance
+
## r20, 2018-04-22 ##
- support netstandard (net471 + netcoreapp2.0)
diff --git a/src/csmatio.csproj b/src/csmatio.csproj
index 2b1cdc7..38e853a 100644
--- a/src/csmatio.csproj
+++ b/src/csmatio.csproj
@@ -1,8 +1,8 @@
- netstandard2.0
- 1.0.20
+ netstandard2.0;netstandard2.1;net6.0;net8.0
+ 1.0.21
Matlab I/O API Library for .NET
Copyright © 2007, David A. Zier
true
diff --git a/src/io/MatFileReader.cs b/src/io/MatFileReader.cs
index 875c7cf..cbe9b0e 100644
--- a/src/io/MatFileReader.cs
+++ b/src/io/MatFileReader.cs
@@ -165,40 +165,34 @@ Stream Inflate(Stream buf, int numOfBytes)
try
{
- // skip CRC (at end) and zip format (0x789C at begin)
+ // Skip zip format header (2 bytes)
buf.Position += 2;
- numOfBytes -= 6;
+ numOfBytes -= 6; // Account for header (2) and CRC (4)
- var compressedStream = new MemoryStream();
- int data;
- do
- {
- data = buf.ReadByte();
- if (data != -1)
- {
- compressedStream.WriteByte((byte)(data & 0x000000FF));
- }
- }
- while (data != -1 && compressedStream.Length < numOfBytes);
-
- // skip CRC
+ // Read compressed data in one operation instead of byte by byte
+ byte[] compressedData = new byte[numOfBytes];
+ buf.Read(compressedData, 0, numOfBytes);
+
+ // Skip CRC (4 bytes)
buf.Position += 4;
- compressedStream.Position = 0;
- var decompressedStream = new MemoryStream();
- using (var df = new DeflateStream(compressedStream, CompressionMode.Decompress))
+
+ // Create memory streams with adequate capacity to avoid reallocations
+ using (var compressedStream = new MemoryStream(compressedData))
{
- do
+ // Estimate decompressed size (usually compressed data is ~40-60% of original)
+ // A reasonable estimate helps avoid memory reallocations
+ var decompressedStream = new MemoryStream(numOfBytes * 3);
+
+ // Use buffer for bulk copying instead of byte-by-byte
+ using (var df = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
- data = df.ReadByte();
- if (data != -1)
- {
- decompressedStream.WriteByte((byte)(data & 0x000000FF));
- }
+ // Copy in bulk using a buffer instead of byte-by-byte
+ df.CopyTo(decompressedStream, 81920); // Use 80KB buffer (optimal for most .NET I/O)
}
- while (data != -1);
+
+ decompressedStream.Position = 0;
+ return decompressedStream;
}
- decompressedStream.Position = 0;
- return decompressedStream;
}
catch (IOException e)
{
diff --git a/test/ReaderWriterTests.cs b/test/ReaderWriterTests.cs
index 498b15b..816a57e 100644
--- a/test/ReaderWriterTests.cs
+++ b/test/ReaderWriterTests.cs
@@ -1,11 +1,5 @@
-using System;
-using System.CodeDom;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using csmatio.io;
+using csmatio.io;
using csmatio.types;
-using NUnit.Framework;
namespace test
{
@@ -13,6 +7,17 @@ public class ReaderWriterTests
{
string _tempFileName;
+ // Add a parameterless constructor for NUnit
+ public ReaderWriterTests()
+ {
+ _tempFileName = Path.GetTempFileName();
+ }
+
+ public ReaderWriterTests(string tempFileName)
+ {
+ _tempFileName = tempFileName;
+ }
+
[TearDown]
public void TearDown()
{
@@ -167,7 +172,7 @@ public static IEnumerable ReadDataFolder()
{
#if NET471
var baseDir = TestContext.CurrentContext.TestDirectory;
-#elif NETCOREAPP2_0
+#elif NETCOREAPP2_0_OR_GREATER
var baseDir = TestContext.CurrentContext.WorkDirectory;
#endif
var dir = Path.Combine(baseDir, "..", "..", "..", "..", "data");
diff --git a/test/csmatio.test.csproj b/test/csmatio.test.csproj
new file mode 100644
index 0000000..7c7b371
--- /dev/null
+++ b/test/csmatio.test.csproj
@@ -0,0 +1,28 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/test.csproj b/test/test.csproj
deleted file mode 100644
index 8591077..0000000
--- a/test/test.csproj
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
- netcoreapp2.0;net471
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file