Skip to content

Commit 3a3a7f9

Browse files
committed
NedfExportMarkers + NedfExportStats -> NedfExport
1 parent f6f22ba commit 3a3a7f9

File tree

6 files changed

+94
-89
lines changed

6 files changed

+94
-89
lines changed

NedfExportMarkers/NedfExportMarkers.csproj renamed to NedfExport/NedfExport.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20303.1" />
8+
</ItemGroup>
69
<ItemGroup>
710
<ProjectReference Include="..\nedfreader\nedfreader.csproj" />
811
</ItemGroup>

NedfExport/main.cs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.CommandLine;
3+
using System.CommandLine.Invocation;
4+
using System.CommandLine.Parsing;
5+
using System.Globalization;
6+
using System.IO;
7+
using System.Linq;
8+
using NedfReader;
9+
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
var filesArg = new Argument<FileInfo[]>("files", "NEDF files to process").ExistingOnly();
15+
filesArg.Arity = ArgumentArity.OneOrMore;
16+
var rootCommand = new RootCommand("Export header / marker data for NEDF files")
17+
{
18+
new Option<StreamWriter>(new string[]{"--statsfile", "-o" }, "File to save stats to instead of stdout"),
19+
new Option<StreamWriter>("--errlog", "File to log errors to instead of stderr"),
20+
new Option<uint>("--maxsamples", ()=>int.MaxValue, "Quit after this many samples, useful for sanity checks"),
21+
new Option<bool>("--markercsv", "Write a CSV file with markers for each supplied nedf file"),
22+
filesArg
23+
};
24+
rootCommand.Handler = CommandHandler.Create((StreamWriter statsfile, StreamWriter errlog, uint maxsamples, bool markercsv, FileInfo[] files) =>
25+
{
26+
var stderr = errlog ?? Console.Error;
27+
var statsout = statsfile ?? Console.Out;
28+
29+
statsout.WriteLine("File;NEDFversion;nchan;nacc;nsample;nstim;StartDate_firstEEGTimestamp");
30+
foreach (var file in files)
31+
try
32+
{
33+
using var r = new NedfFile(file.FullName, (str) => errlog.WriteLine(str));
34+
string basename = Path.GetFileNameWithoutExtension(file.Name);
35+
int markercount = 0;
36+
if (markercsv)
37+
{
38+
var outfile = markercsv ? new StreamWriter(file.DirectoryName + '/' + basename + "_markers.csv") : null;
39+
outfile?.WriteLine("sample;marker");
40+
foreach ((uint pos, uint value) in r.GetMarkerPairs(maxsamples))
41+
{
42+
outfile?.WriteLine($"{pos};{value}");
43+
markercount++;
44+
}
45+
outfile?.Dispose();
46+
}
47+
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
48+
statsout.WriteLine(string.Join(";", new object[]{
49+
Path.GetFileName(file.Name),
50+
r.NEDFversion,
51+
r.NChan,
52+
r.NAcc,
53+
r.NSample,
54+
markercount,
55+
r.hdr.StepDetails.StartDate_firstEEGTimestamp
56+
}.Select(obj=>obj.ToString())));
57+
}
58+
catch (Exception e)
59+
{
60+
Console.Error.WriteLine($"{file}: Error: {e.Message}");
61+
}
62+
});
63+
rootCommand.Invoke(args);
64+
}
65+
}

NedfExportMarkers/NedfExportMarkers.cs

-33
This file was deleted.

NedfExportStats/NedfExportStats.cs

-45
This file was deleted.

NedfExportStats/NedfExportStats.csproj

-9
This file was deleted.

README.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1-
# NEDF reader for Analyzer2
1+
# C# NEDF reader
2+
3+
## NEDF reader for Analyzer2
24

35
This is a reader component to allow
46
[Brainvision Analyzer](https://www.brainproducts.com/productdetails.php?id=17)
57
to read
68
[NEDF](https://www.neuroelectrics.com/wiki/index.php/Files_%26_Formats#The_.nedf_.28binary.29_data_format)
79
files (commonly produced by Enobio / StarStim EEG headsets).
810

9-
## Installation
11+
### Installation
1012

1113
Simply copy the [`dll` files](https://github.com/tstenner/nedfreader/releases/latest)
1214
to your Analyzer directory or add the downloaded folder to the analyzer config:
1315

1416
![Analyzer admin screenshot](analyzeradmin.png)
1517

18+
## NedfExport
19+
20+
```
21+
NedfExport:
22+
Export header / marker data for NEDF files
23+
24+
Usage:
25+
NedfExport [options] <files>...
26+
27+
Arguments:
28+
<files> NEDF files to process
29+
30+
Options:
31+
-o, --statsfile <statsfile> File to save stats to instead of stdout
32+
--errlog <errlog> File to log errors to instead of stderr
33+
--maxsamples <maxsamples> Quit after this many samples, useful for sanity checks [default: 2147483647]
34+
--markercsv Write a CSV file with markers for each supplied nedf file
35+
--version Show version information
36+
-?, -h, --help Show help and usage information
37+
```
38+
39+
For Windows users: drag one or more nedf files onto `NedfExport.exe`.

0 commit comments

Comments
 (0)