Skip to content

Commit bf7cd2d

Browse files
author
Elliott Leonard
committed
Small UI and other bug fixes. Updated the Manual
1 parent 1ab8401 commit bf7cd2d

File tree

12 files changed

+151
-59
lines changed

12 files changed

+151
-59
lines changed

CAMDataReader/CAMIO.cs

+53-15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ authority from the Government may result in criminal liability under U.S. laws.
2424
using System.IO;
2525
using System.Diagnostics;
2626
using System.Data;
27+
using System.Collections;
28+
using System.ComponentModel;
2729

2830
namespace CAMInputOutput
2931
{
@@ -213,8 +215,8 @@ protected enum EfficiencyPointParameterLocation
213215
private const UInt16 headerSize = 0x800;
214216
private const UInt16 blockHeaderSize = 0x30;
215217

216-
IList<byte[]> lines;
217-
IList<byte[]> nucs;
218+
List<byte[]> lines;
219+
List<byte[]> nucs;
218220

219221
IList<Line> fileLines;
220222
IList<Nuclide> fileNuclides;
@@ -1282,7 +1284,7 @@ public void CreateFile(string filePath)
12821284
//numRecords = numRecords + startRecord > lines.Count ? lines.Count - startRecord : (int)numLineRecords;
12831285
blockNo = startRecord + numRecords > lines.Count ? (UInt16)0U: (UInt16)(blockNo + 1U);
12841286
//blockList[fileIndex] = GenerateBlock(CAMBlock.NLINES, loc, ((List<byte[]>)lines).GetRange(startRecord, numRecords), blockNo, i == 1);
1285-
byte[] block = GenerateBlock(CAMBlock.NLINES, loc, ((List<byte[]>)lines).GetRange(startRecord, lines.Count-startRecord), blockNo, startRecord == 0);
1287+
byte[] block = GenerateBlock(CAMBlock.NLINES, loc, (lines.ToList<byte[]>()).GetRange(startRecord, lines.Count-startRecord), blockNo, startRecord == 0);
12861288
numRecords = (int)BitConverter.ToUInt16(block, 0x1E);
12871289
startRecord += numRecords;
12881290
blockList.Add(block);
@@ -1346,7 +1348,7 @@ public void AddNuclide(string name, double halfLife, double halfLifeUnc, string
13461348
}
13471349

13481350
/// <summary>
1349-
/// Add a nuclide to the file
1351+
/// Add a nuclide to the file after all the lines have been added
13501352
/// </summary>
13511353
/// <param name="nuc">Nuclide to add</param>
13521354
/// <param name="nucNo">The nuclide record number</param>
@@ -1386,6 +1388,8 @@ public void AddNuclide(Nuclide nuc)
13861388
lines.Where(line => line[0x1B] == BitConverter.GetBytes(nucNo)[0]).Select(l => (UInt16)(lines.IndexOf(l) + 1U)).ToArray() :
13871389
new UInt16[0];
13881390

1391+
//IComparer lnNumComparer = new LineNumberComparer();
1392+
Array.Sort(lineNums);
13891393
nucs.Add(GenerateNuclide(nuc.Name, nuc.HalfLife, nuc.HalfLifeUncertainty, nuc.HalfLifeUnit.ToUpper(), lineNums));
13901394
}
13911395

@@ -1414,14 +1418,21 @@ public void AddLine(Line line)
14141418
if (nucNo > 255)
14151419
throw new ArgumentException("Cannot have more than 255 nuclides");
14161420

1417-
//if the nuclide alredy exists add lines to it
1418-
if (nucs != null && nucs.Count > nucNo)
1419-
AddLinesToNuclide(nucs.ElementAt(nucNo), new byte[] { BitConverter.GetBytes(lines.Count)[0] });
14201421
//initilize the lines
14211422
if (lines == null || lines.Count < 1)
14221423
lines = new List<byte[]>();
1424+
//insert in the correct position
1425+
byte[] lineBytes = GenerateLine(line.Energy, line.EnergyUncertainty, line.Abundance, line.AbundanceUncertainty, line.IsKeyLine, BitConverter.GetBytes(nucNo)[0]);
1426+
int lnIndex = ~lines.BinarySearch(lineBytes, new LineComparer());
1427+
if (lnIndex < 0)
1428+
lines.Insert(~lnIndex,lineBytes);
1429+
else
1430+
lines.Insert(lnIndex, lineBytes);
14231431

1424-
lines.Add(GenerateLine(line.Energy, line.EnergyUncertainty, line.Abundance, line.AbundanceUncertainty, line.IsKeyLine, BitConverter.GetBytes(nucNo)[0]));
1432+
//if the nuclide alredy exists add lines to it
1433+
if (nucs != null && nucs.Count > nucNo)
1434+
AddLinesToNuclide(nucs.ElementAt(nucNo), new byte[] { BitConverter.GetBytes(lnIndex)[0] });
1435+
//lines.Add(GenerateLine(line.Energy, line.EnergyUncertainty, line.Abundance, line.AbundanceUncertainty, line.IsKeyLine, BitConverter.GetBytes(nucNo)[0]));
14251436
}
14261437
/// <summary>
14271438
/// Generate the contents of a CAM file file
@@ -1704,7 +1715,7 @@ protected byte[] GenerateNuclide(string name, double halfLife, double halfLifeUn
17041715
/// Add lines to an existing nuclide
17051716
/// </summary>
17061717
/// <param name="nuc">The nuclide</param>
1707-
/// <param name="lineNums">he record number of the lines to be associated with the nuclide</param>
1718+
/// <param name="lineNums">the record number of the lines to be associated with the nuclide</param>
17081719
/// <returns></returns>
17091720
protected byte[] AddLinesToNuclide(byte[] nuc, byte[] lineNums)
17101721
{
@@ -1716,6 +1727,8 @@ protected byte[] AddLinesToNuclide(byte[] nuc, byte[] lineNums)
17161727
//Create a byte array and fill it
17171728
byte[] linesList = new byte[numLines * 0x3U];
17181729

1730+
Array.Sort(lineNums);
1731+
17191732
for (UInt16 i = 0; i < numLines; i++)
17201733
{
17211734
UInt32 offset = i * 0x3U;
@@ -1759,7 +1772,7 @@ public byte[] GenerateLine(double energy, double enUnc, double yield, double yie
17591772
/// <param name="pos">The position of the value to covert</param>
17601773
/// <param name="data">The array of bytes to be converted</param>
17611774
/// <returns>A date time</returns>
1762-
private DateTime ConvertDateTime(byte[] data, UInt32 pos)
1775+
public static DateTime ConvertDateTime(byte[] data, UInt32 pos)
17631776
{
17641777
if (data.Length < 0x08)
17651778
throw new ArgumentException("The data input array is not long enough");
@@ -1777,7 +1790,7 @@ private DateTime ConvertDateTime(byte[] data, UInt32 pos)
17771790
/// </summary>
17781791
/// <param name="input">DateTime to convert</param>
17791792
/// <returns>byte repesetnation of hte DateTime in CAM format</returns>
1780-
private byte[] DateTimeToCAM(DateTime input)
1793+
public static byte[] DateTimeToCAM(DateTime input)
17811794
{
17821795
//get the unix epoch
17831796
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
@@ -1796,7 +1809,7 @@ private byte[] DateTimeToCAM(DateTime input)
17961809
/// <param name="pos">The position of the value to covert</param>
17971810
/// <param name="data">The array of bytes to be converted</param>
17981811
/// <returns>The number of seconds</returns>
1799-
private double ConvertTimeSpan(byte[] data, UInt32 pos)
1812+
public static double ConvertTimeSpan(byte[] data, UInt32 pos)
18001813
{
18011814
//check the inputs
18021815
if (data.Length < 0x08)
@@ -1820,7 +1833,7 @@ private double ConvertTimeSpan(byte[] data, UInt32 pos)
18201833
/// </summary>
18211834
/// <param name="input">Time span in seconds to convert</param>
18221835
/// <returns>byte represnentaion of the timespan in CAM format</returns>
1823-
private byte[] TimeSpanToCAM(double input)
1836+
public static byte[] TimeSpanToCAM(double input)
18241837
{
18251838
Int64 tspan;
18261839
byte[] span;
@@ -1856,7 +1869,7 @@ private byte[] TimeSpanToCAM(double input)
18561869
/// <param name="pos">The start index of the value to covert</param>
18571870
/// <param name="data">The array of bytes to be converted</param>
18581871
/// <returns>The floating point value </returns>
1859-
private double ConvertFloat(byte[] data, UInt32 pos)
1872+
public static double ConvertFloat(byte[] data, UInt32 pos)
18601873
{
18611874
if (data.Length < 0x04)
18621875
throw new ArgumentException("The data input array is not long enough");
@@ -1879,7 +1892,7 @@ private double ConvertFloat(byte[] data, UInt32 pos)
18791892
/// </summary>
18801893
/// <param name="input">number to be converted</param>
18811894
/// <returns>byte representation in PDP-11 format</returns>
1882-
private byte[] FloatToCAM(double input)
1895+
public static byte[] FloatToCAM(double input)
18831896
{
18841897
byte[] word1 = new byte[0x2], word2 = new byte[0x2];
18851898
byte[] inpByte = BitConverter.GetBytes(Convert.ToSingle(input * 4));
@@ -1892,6 +1905,31 @@ private byte[] FloatToCAM(double input)
18921905
#endregion
18931906

18941907
}
1908+
class LineComparer : IComparer<byte[]>
1909+
{
1910+
public int Compare(byte[] x, byte[] y)
1911+
{
1912+
return Comparer<double>.Default.Compare(CAMIO.ConvertFloat(x, 0x01), CAMIO.ConvertFloat(y, 0x01));
1913+
}
1914+
}
18951915

1916+
//class LineNumberComparer : IComparer<byte>
1917+
//{
1918+
// public int Compare(byte x, byte y)
1919+
// {
1920+
// return Comparer<int>.Default.Compare(BitConverter.ToUInt16(x,0), BitConverter.ToUInt16(y, 0));
1921+
// }
1922+
//}
1923+
//class SortedList : List<byte[]>
1924+
//{
1925+
// IComparer comparer;
1926+
// public SortedList(IComparer comparer)
1927+
// {
1928+
// this.comparer = comparer;
1929+
// }
1930+
1931+
// public override void Add(object obj)
1932+
1933+
//}
18961934

18971935
}

CAMDataReader/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ authority from the Government may result in criminal liability under U.S. laws.
5050
// You can specify all the values or you can default the Build and Revision Numbers
5151
// by using the '*' as shown below:
5252
// [assembly: AssemblyVersion("1.0.*")]
53-
[assembly: AssemblyVersion("1.0.1.0")]
54-
[assembly: AssemblyFileVersion("1.0.1.0")]
53+
[assembly: AssemblyVersion("1.0.3.0")]
54+
[assembly: AssemblyFileVersion("1.0.3.0")]

Manual/UsersManual.pdf

-71.3 KB
Binary file not shown.

PeakMap/CAMLibrary.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ protected override void WriteDataToFile()
9595
File.Delete(file);
9696
}
9797
int nucID = 1;
98+
//always do the lines first
9899
foreach (DataRow nuclide in lib.Tables["MATCHEDNUCLIDES"].Rows)
99100
{
100101
DataRow[] nucLines = lib.Tables["MATCHEDLINES"].Select("NAME = '" + nuclide["NAME"] + "'", "ENERGY ASC");
101-
//always do the lines first
102-
103102
foreach (DataRow nucLine in nucLines)
104103
{
105104
Line line = new Line
@@ -114,6 +113,18 @@ protected override void WriteDataToFile()
114113
//add the line
115114
camfile.AddLine(line);
116115
}
116+
nucID++;
117+
}
118+
nucID = 1;
119+
foreach (DataRow nuclide in lib.Tables["MATCHEDNUCLIDES"].Rows)
120+
{
121+
//DataRow[] nucLines = lib.Tables["MATCHEDLINES"].Select("NAME = '" + nuclide["NAME"] + "'", "ENERGY ASC");
122+
//
123+
124+
//foreach (DataRow nucLine in nucLines)
125+
//{
126+
127+
//}
117128
//now do the nuclide
118129
Nuclide nuc = new Nuclide
119130
{
@@ -179,6 +190,7 @@ public override async Task LoadLibraryAsync(string file)
179190
nucRow["ENERGYUNC"] = line.Energy;
180191
nucRow["YIELD"] = line.Abundance;
181192
nucRow["YIELDUNC"] = line.AbundanceUncertainty;
193+
nucRow["ISKEY"] = line.IsKeyLine;
182194
lib.Tables["MATCHEDLINES"].Rows.Add(nucRow);
183195
ln++;
184196
}
@@ -190,7 +202,7 @@ public override async Task LoadLibraryAsync(string file)
190202
/// <returns>percision</returns>
191203
protected override double GetPrecision(double num)
192204
{
193-
return 1e-5;
205+
return 1e-4;
194206
}
195207

196208
}

PeakMap/CAMSpecData.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ authority from the Government may result in criminal liability under U.S. laws.
2525
using System.ComponentModel;
2626

2727
using CAMInputOutput;
28+
using System.IO;
2829

2930
namespace PeakMap
3031
{
@@ -184,12 +185,24 @@ public override async Task LoadDataAsync(DataTable peaks)
184185
//assign the calibration info
185186
energyCoeff = await ecalTask;
186187
shapeCoeff = await shapeCalTask;
187-
EfficiencyPoint[] effpts = await effCalTask;
188+
//efficiency is not necessary, if there isn't efficiency calibration add some defaults
189+
try
190+
{
191+
effMeas = new ObservableEntityCollection<EfficiencyMeasurement>();
192+
EfficiencyPoint[] effpts = await effCalTask;
193+
for (int i = 0; i < effpts.Length; i++)
194+
effMeas.Add(new EfficiencyMeasurement(effpts[i].Energy, effpts[i].Efficiency, effpts[i].EfficiencyUncertainty));
195+
}
196+
catch (FileFormatException)
197+
{
198+
double eff = 0.9999999999999;
199+
double effunc = 0.000000000005;
200+
effMeas.Add(new EfficiencyMeasurement(Properties.Settings.Default.LOWERELIMT, eff, effunc));
201+
effMeas.Add(new EfficiencyMeasurement((Properties.Settings.Default.LOWERELIMT + Properties.Settings.Default.UPPERELIMIT) / 2, eff, effunc));
202+
effMeas.Add(new EfficiencyMeasurement(Properties.Settings.Default.UPPERELIMIT, eff, effunc));
203+
order = 2;
204+
}
188205

189-
//assign the efficiency points
190-
effMeas = new ObservableEntityCollection<EfficiencyMeasurement>();
191-
for (int i =0; i< effpts.Length;i++ )
192-
effMeas.Add( new EfficiencyMeasurement(effpts[i].Energy, effpts[i].Efficiency, effpts[i].EfficiencyUncertainty));
193206
effMeas.CollectionChanged += EffMeas_CollectionChanged;
194207
//assign the peaks
195208
Peak[] filePeaks = await peakTask;

PeakMap/PeakMap.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<Reference Include="System.Deployment" />
106106
<Reference Include="System.Drawing" />
107107
<Reference Include="System.Xml" />
108+
<Reference Include="WindowsBase" />
108109
</ItemGroup>
109110
<ItemGroup>
110111
<Compile Include="CAMLibrary.cs" />

PeakMap/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ authority from the Government may result in criminal liability under U.S. laws.
5454
// You can specify all the values or you can default the Build and Revision Numbers
5555
// by using the '*' as shown below:
5656
// [assembly: AssemblyVersion("1.0.*")]
57-
[assembly: AssemblyVersion("1.3.5.0")]
58-
[assembly: AssemblyFileVersion("1.3.5.0")]
57+
[assembly: AssemblyVersion("1.3.6.1")]
58+
[assembly: AssemblyFileVersion("1.3.6.1")]
5959
[assembly: NeutralResourcesLanguage("en-US")]

PeakMapWPF/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ authority from the Government may result in criminal liability under U.S. laws.
6868
// You can specify all the values or you can default the Build and Revision Numbers
6969
// by using the '*' as shown below:
7070
// [assembly: AssemblyVersion("1.0.*")]
71-
[assembly: AssemblyVersion("1.3.5.0")]
72-
[assembly: AssemblyFileVersion("1.3.5.0")]
71+
[assembly: AssemblyVersion("1.3.5.3")]
72+
[assembly: AssemblyFileVersion("1.3.5.3")]
7373
[assembly: NeutralResourcesLanguage("en-US")]

PeakMapWPF/ViewModels/MainWindowMatchingViewModel.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ public async Task GetSpecDataAsync(string file)
185185
DialogViewModel dialogViewModel = new DialogViewModel("File: " + file + " is in use by another program", "Exeption: File in Use", true, false);
186186
dialogService.ShowDialog(dialogViewModel);
187187
}
188+
catch (System.IO.FileFormatException ex)
189+
{
190+
DialogViewModel dialogViewModel = new DialogViewModel($"File: {file} \n\n{ex.Message}", "Exeption: File Format", true, false);
191+
dialogService.ShowDialog(dialogViewModel);
192+
}
188193
catch (Exception ex)
189194
{
190195
DialogViewModel dialogViewModel = new DialogViewModel(ex.Message + ":\n" + ex.StackTrace, "General Exception", true, false);
@@ -457,7 +462,7 @@ protected override void LinesMenuCommand_Executed(object context)
457462
protected override bool CanLinesMenuExecute(object context)
458463
{
459464
string menuName = context.ToString().ToLowerInvariant();
460-
if (menuName.Contains("write") && menuName.Contains("matched"))
465+
if (menuName.Contains("write") && menuName.Contains("selected"))
461466
{
462467
return SelectedNuclide != null && LibraryFile != null;
463468
}

PeakMapWPF/ViewModels/MainWindowViewModel.cs

+21-4
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,21 @@ protected void WriteLines(WriteType type)
485485

486486
}
487487

488+
private void SaveLibrary()
489+
{
490+
try
491+
{
492+
libGen.SaveFile();
493+
this.LibraryFile = libGen.FileName;
494+
}
495+
catch (Exception ex)
496+
{
497+
DialogViewModel dialogViewModel = new DialogViewModel($"There was an exeption while writing to the library:\n {ex.Message}", "Library Exception", true);
498+
dialogService.ShowDialog(dialogViewModel);
499+
}
500+
}
501+
502+
488503
#region Commands
489504

490505

@@ -516,11 +531,13 @@ protected virtual async void FileMenuCommand_Executed(object context)
516531
else if (menuName.Contains("as") && menuName.Contains("library"))
517532
{
518533
libGen.FileName = GetLibraryFilename(FileOperation.New);
519-
libGen.SaveFile();
534+
535+
if(libGen != null)
536+
SaveLibrary();
520537
}
521538
else if (menuName.Contains("save") && menuName.Contains("library"))
522539
{
523-
libGen.SaveFile();
540+
SaveLibrary();
524541
}
525542

526543

@@ -544,7 +561,7 @@ protected virtual void LinesMenuCommand_Executed(object context)
544561
WriteLines(WriteType.All);
545562
IsWriteAllChecked = true;
546563
}
547-
else if (menuName.Contains("write") && menuName.Contains("selected"))
564+
else if (menuName.Contains("write") && menuName.Contains("highlighted"))
548565
{
549566
WriteLines(WriteType.Selected);
550567
IsWriteSelChecked = true;
@@ -559,7 +576,7 @@ protected virtual bool CanLinesMenuExecute(object context)
559576

560577
if (menuName.Contains("all"))
561578
return SelectedNuclide != null && LibraryFile != null;
562-
else if (menuName.Contains("selected"))
579+
else if (menuName.Contains("highlighted"))
563580
return SelectedLines != null && LibraryFile != null;
564581
else if (menuName.Contains("write"))
565582
return SelectedNuclide != null && LibraryFile != null &&

0 commit comments

Comments
 (0)