修复读写bug
This commit is contained in:
@ -39,6 +39,7 @@ namespace mainProgram
|
||||
private void OpenProjectToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenProjectWindow w = new OpenProjectWindow();
|
||||
w.TransferEvent += RecieveProjectManager;
|
||||
|
||||
//w.Show();//不阻塞
|
||||
w.ShowDialog();//阻塞
|
||||
@ -46,55 +47,52 @@ namespace mainProgram
|
||||
|
||||
private void RadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
SpectralDataReaderWriter xx = new SpectralDataReaderWriter(@"D:\Desktop\0easySifProject\1raw\2021_12_16\beijing_17_57_44.csv");
|
||||
//SpectralDataReaderWriter xx = new SpectralDataReaderWriter(@"D:\Desktop\0easySifProject\1raw\2021_12_16\beijing_17_57_44.csv");
|
||||
|
||||
|
||||
string name = xx.mDataTable.Rows[16][0].ToString();
|
||||
|
||||
int i = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//mProjectManager.
|
||||
|
||||
|
||||
|
||||
|
||||
//string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderName);
|
||||
|
||||
//for (int i = 0; i < sourceFilesPath.Length; i++)
|
||||
//SpectralData tmp1 = xx.GetSpectral(1);
|
||||
//for (int ii = 0; ii < tmp1.spectralDataLength; ii++)
|
||||
//{
|
||||
// string sourceFilePath = (sourceFilesPath[i]).Replace("\\", "/");
|
||||
// string[] forlders = sourceFilePath.Split('/');
|
||||
|
||||
// if (File.Exists(sourceFilePath))
|
||||
// {
|
||||
// string dest = destFolderName;
|
||||
// string sourceFileName = Path.GetFileName(sourceFilePath);
|
||||
// File.Copy(sourceFilePath, Path.Combine(dest, sourceFileName), overwrite);
|
||||
// }
|
||||
// else if (Directory.Exists(sourceFilePath))
|
||||
// {
|
||||
// string lastDirectory = forlders[forlders.Length - 1];
|
||||
// string dest = Path.Combine(destFolderName, lastDirectory).Replace("\\", "/");
|
||||
|
||||
// if (!Directory.Exists(dest))
|
||||
// {
|
||||
// Directory.CreateDirectory(dest);
|
||||
// }
|
||||
// CopySubFun(sourceFilePath, dest, overwrite);
|
||||
// }
|
||||
// tmp1.spectral[ii] = 1;
|
||||
//}
|
||||
//xx.UpdateSpectral(1, tmp1);
|
||||
|
||||
//SpectralData tmp3 = xx.GetSpectral(3);
|
||||
//for (int ii = 0; ii < tmp3.spectralDataLength; ii++)
|
||||
//{
|
||||
// tmp3.spectral[ii] = 3;
|
||||
//}
|
||||
//xx.UpdateSpectral(3, tmp3);
|
||||
|
||||
//SpectralData tmp7 = xx.GetSpectral(7);
|
||||
//for (int ii = 0; ii < tmp7.spectralDataLength; ii++)
|
||||
//{
|
||||
// tmp7.spectral[ii] = 7;
|
||||
//}
|
||||
//xx.UpdateSpectral(7, tmp7);
|
||||
|
||||
//SpectralData tmp10 = xx.GetSpectral(10);
|
||||
//for (int ii = 0; ii < tmp10.spectralDataLength; ii++)
|
||||
//{
|
||||
// tmp10.spectral[ii] = 10;
|
||||
//}
|
||||
//xx.UpdateSpectral(10, tmp10);
|
||||
|
||||
//xx.SaveCSV(@"D:\Desktop\0easySifProject\1raw\2021_12_16\beijing_17_57_44__.csv");
|
||||
|
||||
|
||||
|
||||
//SpectralDataReaderWriter xx = new SpectralDataReaderWriter(@"D:\Desktop\0easySifProject\1raw\2021_12_13\beijing_15_53_16.csv");
|
||||
|
||||
//SpectralData tmp1 = xx.GetSpectral(1);
|
||||
//for (int ii = 0; ii < tmp1.spectralDataLength; ii++)
|
||||
//{
|
||||
// tmp1.spectral[ii] = 1;
|
||||
//}
|
||||
//xx.UpdateSpectral(1, tmp1);
|
||||
|
||||
//xx.SaveCSV(@"D:\Desktop\0easySifProject\1raw\2021_12_13\beijing_15_53_16__.csv");
|
||||
|
||||
mProjectManager.Rad();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,23 @@ namespace mainProgram
|
||||
}
|
||||
}
|
||||
|
||||
public event transferProjectManagerDelegate TransferEvent;//申明事件
|
||||
private void OpenProjectPathBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
string projectPath = ProjectPathTextBox.Text;
|
||||
if (projectPath != null && projectPath.Length == 0)
|
||||
{
|
||||
MessageBox.Show(this, "工程路径不能为空", "提示");
|
||||
return;
|
||||
}
|
||||
|
||||
ProjectManager projectManager = new ProjectManager(projectPath);
|
||||
projectManager.OpenProject(projectPath);
|
||||
|
||||
TransferEvent(projectManager);//触发事件
|
||||
|
||||
MessageBox.Show(this, "工程打开成功!", "提示");
|
||||
Close();//打开工程完成后,关闭窗口
|
||||
}
|
||||
|
||||
private void CancelBtn_Click(object sender, EventArgs e)
|
||||
|
@ -5,6 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace mainProgram
|
||||
{
|
||||
@ -60,9 +61,33 @@ namespace mainProgram
|
||||
|
||||
}
|
||||
|
||||
public void OpenProject()
|
||||
public void OpenProject(string projectPath)
|
||||
{
|
||||
mProjectPath = projectPath;
|
||||
|
||||
mMetadataPath = Path.Combine(mProjectPath, ".project");
|
||||
mRawPath = Path.Combine(mProjectPath, "1raw");
|
||||
mRadPath = Path.Combine(mProjectPath, "2rad");
|
||||
mSifPath = Path.Combine(mProjectPath, "3sif");
|
||||
|
||||
//if (false == Directory.Exists(mMetadataPath))
|
||||
//{
|
||||
// Directory.CreateDirectory(mMetadataPath);
|
||||
|
||||
// MessageBox.Show("工程打开成功!", "提示");
|
||||
//}
|
||||
//if (false == Directory.Exists(mRawPath))
|
||||
//{
|
||||
// Directory.CreateDirectory(mRawPath);
|
||||
//}
|
||||
//if (false == Directory.Exists(mRadPath))
|
||||
//{
|
||||
// Directory.CreateDirectory(mRadPath);
|
||||
//}
|
||||
//if (false == Directory.Exists(mSifPath))
|
||||
//{
|
||||
// Directory.CreateDirectory(mSifPath);
|
||||
//}
|
||||
}
|
||||
|
||||
public void SaveProject()
|
||||
@ -354,31 +379,50 @@ namespace mainProgram
|
||||
//处理工程中的数据
|
||||
public void Rad()
|
||||
{
|
||||
//string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderName);
|
||||
Console.WriteLine("工程目录为" + mProjectPath);
|
||||
|
||||
//for (int i = 0; i < sourceFilesPath.Length; i++)
|
||||
//{
|
||||
// string sourceFilePath = sourceFilesPath[i];
|
||||
// string[] forlders = sourceFilePath.Split('\\');
|
||||
DelectDir(mRadPath);
|
||||
|
||||
// if (File.Exists(sourceFilePath))//是文件,直接拷贝
|
||||
// {
|
||||
// string dest = destFolderName;
|
||||
// string sourceFileName = Path.GetFileName(sourceFilePath);//获取文件名
|
||||
// File.Copy(sourceFilePath, Path.Combine(dest, sourceFileName), overwrite);
|
||||
// }
|
||||
// else if (Directory.Exists(sourceFilePath))//是文件夹,拷贝文件夹;并递归
|
||||
// {
|
||||
// string lastDirectory = forlders[forlders.Length - 1];
|
||||
// string dest = Path.Combine(destFolderName, lastDirectory);
|
||||
string[] sourceFilesPath = Directory.GetFileSystemEntries(mRawPath);
|
||||
|
||||
// if (!Directory.Exists(dest))
|
||||
// {
|
||||
// Directory.CreateDirectory(dest);
|
||||
// }
|
||||
// CopySubFun(sourceFilePath, dest, overwrite);
|
||||
// }
|
||||
//}
|
||||
for (int i = 0; i < sourceFilesPath.Length; i++)
|
||||
{
|
||||
string sourceFilePath = sourceFilesPath[i];
|
||||
string[] forlders = sourceFilePath.Split('\\');
|
||||
|
||||
string lastDirectory = forlders[forlders.Length - 1];
|
||||
string dest = Path.Combine(mRadPath, lastDirectory);
|
||||
|
||||
if (!Directory.Exists(dest))
|
||||
{
|
||||
Directory.CreateDirectory(dest);
|
||||
}
|
||||
//福亮度转换
|
||||
string[] rawFiles = Directory.GetFileSystemEntries(Path.Combine(mRawPath, lastDirectory));
|
||||
|
||||
foreach (string rawFileName in rawFiles)//文件夹下的文件
|
||||
{
|
||||
string[] nameTmp = rawFileName.Split('\\');
|
||||
|
||||
string name = nameTmp[nameTmp.Length - 1];
|
||||
SpectralDataReaderWriter SpectralData = new SpectralDataReaderWriter(rawFileName);
|
||||
for (int j = 1; j <= SpectralData.TotalSpectralCount; j++)//处理 csv文件中的每条光谱
|
||||
{
|
||||
SpectralData tmp1 = SpectralData.GetSpectral(j);
|
||||
for (int ii = 0; ii < tmp1.spectralDataLength; ii++)
|
||||
{
|
||||
tmp1.spectral[ii] = j;
|
||||
}
|
||||
SpectralData.UpdateSpectral(j, tmp1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
string destFileName = Path.Combine(dest, name);
|
||||
SpectralData.SaveCSV(destFileName);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,6 @@ namespace mainProgram
|
||||
{
|
||||
class SpectralProcessor
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
public void OpenNolinerData()
|
||||
{
|
||||
|
||||
@ -52,6 +48,18 @@ namespace mainProgram
|
||||
|
||||
}
|
||||
|
||||
public enum DataStatus { NoData, Raw, NonLinearCorrection, Rad, Sif };
|
||||
|
||||
public struct SpectralData
|
||||
{
|
||||
public DataStatus dataStatus;
|
||||
public string SN;
|
||||
public int exposureTime;
|
||||
public int spectralDataLength;
|
||||
public double[] spectral;//long or double ?????????????????????????
|
||||
}
|
||||
|
||||
|
||||
public class SpectralDataReaderWriter
|
||||
{
|
||||
public SpectralDataReaderWriter(string csvPath)
|
||||
@ -66,11 +74,26 @@ namespace mainProgram
|
||||
public DataTable mDataTable = null;
|
||||
|
||||
private int mTotalSpectrometer;
|
||||
private int mSpectralCount;
|
||||
private int mTotalSpectralCount;
|
||||
private int mSpectralCountOfOneSpectrometer;
|
||||
private int[] mWavelengthCountOfSpectrometers;//mWavelengthCountOfSpectrometers
|
||||
private string[] mSN;
|
||||
|
||||
|
||||
public int TotalSpectralCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return mTotalSpectralCount;
|
||||
}
|
||||
set
|
||||
{
|
||||
mTotalSpectralCount = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int findMaxColunmCount(string filePath)
|
||||
{
|
||||
@ -143,11 +166,71 @@ namespace mainProgram
|
||||
public void GetMetaData()
|
||||
{
|
||||
mTotalSpectrometer = int.Parse(mDataTable.Rows[1][1].ToString());
|
||||
mWavelengthCountOfSpectrometers = new int[mTotalSpectrometer];
|
||||
mSN = new string[mTotalSpectrometer];
|
||||
|
||||
for (int i = 0; i < mTotalSpectrometer; i++)
|
||||
{
|
||||
mWavelengthCountOfSpectrometers[i] = int.Parse(mDataTable.Rows[i * 2 + 2][6].ToString());
|
||||
mSN[i] = mDataTable.Rows[i * 2 + 2][4].ToString();
|
||||
}
|
||||
|
||||
mTotalSpectralCount = mDataTable.Rows.Count - 3 - mTotalSpectrometer * 2;
|
||||
mSpectralCountOfOneSpectrometer = mTotalSpectralCount / mTotalSpectrometer;
|
||||
|
||||
mSpectralCount = mDataTable.Rows.Count - 3 - mTotalSpectrometer * 2;
|
||||
}
|
||||
|
||||
public void SaveCSV(DataTable dt, string fullPath)//table数据写入csv
|
||||
public SpectralData GetSpectral(int index)
|
||||
{
|
||||
SpectralData spectralData;
|
||||
|
||||
if (index > mTotalSpectralCount)
|
||||
{
|
||||
//return spectralData;
|
||||
}
|
||||
|
||||
int rowOffset = 3 + mTotalSpectrometer * 2;
|
||||
int wavelengthCountIndex = GetIndex(index);
|
||||
|
||||
|
||||
spectralData.SN = mSN[wavelengthCountIndex];
|
||||
spectralData.spectralDataLength = mWavelengthCountOfSpectrometers[wavelengthCountIndex];
|
||||
spectralData.exposureTime = int.Parse(mDataTable.Rows[index - 1 + rowOffset][2].ToString());
|
||||
|
||||
spectralData.spectral = new double[mWavelengthCountOfSpectrometers[wavelengthCountIndex]];
|
||||
for (int i = 0; i < mWavelengthCountOfSpectrometers[wavelengthCountIndex]; i++)
|
||||
{
|
||||
string tmp = mDataTable.Rows[index - 1 + rowOffset][i + 3].ToString();
|
||||
spectralData.spectral[i] = long.Parse(tmp);
|
||||
}
|
||||
spectralData.dataStatus = DataStatus.Raw;
|
||||
|
||||
return spectralData;
|
||||
}
|
||||
|
||||
public void UpdateSpectral(int index, SpectralData spectralData)
|
||||
{
|
||||
int rowOffset = 3 + mTotalSpectrometer * 2;
|
||||
int wavelengthCountIndex = GetIndex(index);
|
||||
|
||||
|
||||
for (int i = 0; i < spectralData.spectralDataLength; i++)
|
||||
{
|
||||
mDataTable.Rows[index - 1 + rowOffset][i + 3] = spectralData.spectral[i];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int GetIndex(int index)
|
||||
{
|
||||
index -= 1;//因为0基索引,所以减1
|
||||
double wavelengthCountIndexTmp = index / mSpectralCountOfOneSpectrometer;
|
||||
int wavelengthCountIndex = (int)Math.Floor(wavelengthCountIndexTmp);//因为0基索引,所以向下取整,否则向上取整
|
||||
|
||||
return wavelengthCountIndex;
|
||||
}
|
||||
|
||||
public void SaveCSV(string fullPath)//table数据写入csv
|
||||
{
|
||||
FileInfo fi = new FileInfo(fullPath);
|
||||
if (!fi.Directory.Exists)
|
||||
@ -158,22 +241,22 @@ namespace mainProgram
|
||||
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
|
||||
string data = "";
|
||||
|
||||
for (int i = 0; i < dt.Columns.Count; i++)//写入列名
|
||||
{
|
||||
data += dt.Columns[i].ColumnName.ToString();
|
||||
if (i < dt.Columns.Count - 1)
|
||||
{
|
||||
data += ",";
|
||||
}
|
||||
}
|
||||
sw.WriteLine(data);
|
||||
//for (int i = 0; i < mDataTable.Columns.Count; i++)//写入列名
|
||||
//{
|
||||
// data += mDataTable.Columns[i].ColumnName.ToString();
|
||||
// if (i < mDataTable.Columns.Count - 1)
|
||||
// {
|
||||
// data += ",";
|
||||
// }
|
||||
//}
|
||||
//sw.WriteLine(data);
|
||||
|
||||
for (int i = 0; i < dt.Rows.Count; i++) //写入各行数据
|
||||
for (int i = 0; i < mDataTable.Rows.Count; i++) //写入各行数据
|
||||
{
|
||||
data = "";
|
||||
for (int j = 0; j < dt.Columns.Count; j++)
|
||||
for (int j = 0; j < mDataTable.Columns.Count; j++)
|
||||
{
|
||||
string str = dt.Rows[i][j].ToString();
|
||||
string str = mDataTable.Rows[i][j].ToString();
|
||||
str = str.Replace("\"", "\"\"");//替换英文冒号 英文冒号需要换成两个冒号
|
||||
if (str.Contains(',') || str.Contains('"')
|
||||
|| str.Contains('\r') || str.Contains('\n')) //含逗号 冒号 换行符的需要放到引号中
|
||||
@ -182,7 +265,7 @@ namespace mainProgram
|
||||
}
|
||||
|
||||
data += str;
|
||||
if (j < dt.Columns.Count - 1)
|
||||
if (j < mDataTable.Columns.Count - 1)
|
||||
{
|
||||
data += ",";
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user