让我的代码工作,但我需要使用的double和字符串的混合推动我在我的代码中使用Struct,但是我不断得到一个空的结果文件,我不明白为什么......毫无疑问对其他人都很明显:/任何帮助都非常感谢,,,,,
SB
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Program
{
public struct RArray
{
public string ChNum;
public string StartDate;
public double IQuies;
public double ISample;
public double IWriteTX;
public double IDepass;
public double IDischarge;
public string DischargeDateCompleted;
}
static void Main(string[] args)
{
string[,] TestLoads = new string[16, 8]
//Enable, RQuies, RSample, RWriteTx, RDepass, RDischarge, DischargeDate, Discharge Time
{{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2008-12-23", "12:00:00" },//0 3
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//1 3
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//2 6
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//3 6
{ "1", "475000", "7560", "100000000" , "383" , "1180" , "2009-04-03", "16:32:00" },//4 csc93 12
{ "1", "475000", "7560", "100000000" , "383" , "1180" , "2009-04-03", "16:32:00" },//5 csc93 12
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//6 12
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//7 12
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//8 12
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//9 12
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//10 continuing
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//11 na
{ "1", "475000", "7560", "100000000" , "383" , "1180" , "2009-04-03", "16:32:00" },//12 csc93 24
{ "1", "475000", "7560", "100000000" , "383" , "1180" , "2009-04-03", "16:32:00" },//13 csc93 24
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" },//14 24
{ "1", "232000", "3770", "100000000" , "191" , "1180" , "2009-04-03", "16:32:00" }};//15 24
int[,] FileMap = new int[16, 5]
//Vtop index, Results Row, Sample index, WriteTX index, Depass Index, ]
{{9 , 0, 41, 42, 73},
{10, 1, 43, 44, 74},
{11, 2, 45, 46, 75},
{12, 3, 47, 48, 76},
{13, 4, 49, 50, 77,},
{14, 5, 51, 52, 78,},
{15, 6, 53, 54, 79,},
{16, 7, 55, 56, 80,},
{25, 8, 57, 58, 81,},
{26, 9, 59, 60, 82,},
{27,10, 61, 62, 83,},
{28,11, 63, 64, 84,},
{29,12, 65, 66, 85,},
{30,13, 67, 68, 86,},
{31,14, 69, 70, 87,},
{32,15, 71, 72, 88,}};
double Vtop;
//double IQuies;
double RQuies;
//double ISample;
double RSample;
//double IWriteTX;
double RWriteTx;
//double IDepass;
double RDepass;
//double IDischarge;
double RDischarge;
double WriteTXIndicator;
double SampleIndicator;
double DepassIndicator;
int[] DischargeStatusFlag = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
string DischargeDateTime;
//string DischargeDateCompleted;
RArray[] ScratchResults = new RArray[16];
var reader = new StreamReader(File.OpenRead(@"C:\Users\SBoyle\Documents\Visual Studio 2010\Projects\1Day Test File\00 Dev1 2008-12-23 08-47-48.csv")); // Static for testing only, to be replaced by file filter code
Console.WriteLine();
Console.WriteLine("Test started on {0}", (DateTime.Now));
Console.WriteLine();
Console.WriteLine();
reader.ReadLine(); // skip headers, read and do nothing
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
for (int Row = 0; Row < 16; Row++)
{
SampleIndicator = Convert.ToSingle(values[FileMap[Row, 2]]); // Mapping for Sample indicator
DepassIndicator = Convert.ToSingle(values[FileMap[Row, 4]]);
WriteTXIndicator = Convert.ToSingle(values[FileMap[Row, 3]]);
RQuies = Convert.ToDouble(TestLoads[Row, 1]);
RSample = Convert.ToDouble(TestLoads[Row, 2]);
RWriteTx = Convert.ToDouble(TestLoads[Row, 3]);
RDepass = Convert.ToDouble(TestLoads[Row, 4]);
RDischarge = Convert.ToDouble(TestLoads[Row, 5]);
DischargeDateTime = (values[0]);
Vtop = Convert.ToSingle(values[FileMap[Row, 0]]);
//if (DischargeStatusFlag[(Row)] == 0)
//{
// if (Vtop < 5.4)
// {
// DischargeStatusFlag[Row] = 1;
// Console.WriteLine("Channel Number {0} was less than 5.4v on {1},", (Row), DischargeDateTime);
// }
//
//IQuies = (Vtop / RQuies); //Quiesecent load is in ohms, but summing V0,[09] x 32000 at this point for debugging
ScratchResults[Row]. += (Vtop / RQuies); //Add IQuiescent to ScratchResults Quiescent location containing previous IQuies value artefact
if (SampleIndicator == 1)
{
//Add ISample to ScratchResults Sample location containing previous ISample value artefact
ScratchResults[Row].ISample += (Vtop / RSample);
}
if (DepassIndicator == 1)
{
//Add IDepass to ScratchResults Depass location containing previous IDepass value artefact
ScratchResults[Row].IDepass += (Vtop / RDepass);
}
if (WriteTXIndicator == 1)
{
//Add IWriteTX to ScratchResults WriteTX location containing previous IWriteTX value artefact
ScratchResults[Row].IWriteTX += (Vtop / RWriteTx);
}
//}
}
}
Console.WriteLine(ScratchResults[0].IQuies);
using (StreamWriter outfile = new StreamWriter(@"C:\\ScratchResultsContent.txt"))
{
outfile.WriteLine("BatteryCell nnDevn Channel# ,nnDevn Start Date ,nnDevn Quiescent Total Coulombs ,nnDevn Sample Total Coulombs, nnDevn WriteTX Total Coulombs ,nnDevn Depass Total Coulombs ,nnDevn Discharge date start , nnDevn Discharge Date Completed (VTop<5.4volts), nnDevn Discharge Total Coulombs, nnDevn Cell/Battery delivered Total Coloumbs");
for (int x = 0; x < 16; x++)
{
string content = "";
for (int y = 0; y < 1; y++)
{
content = ScratchResults[x].ChNum ;
content = ScratchResults[x].StartDate ;
content += ScratchResults[x].IQuies.ToString();
content += ScratchResults[x].ISample.ToString();
content += ScratchResults[x].IWriteTX.ToString();
content += ScratchResults[x].IDepass.ToString();
content = ScratchResults[x].DischargeDateCompleted;
content += ScratchResults[x].IDischarge.ToString();
}
}
}
Console.WriteLine("Test ended on {0}", (DateTime.Now));
Console.ReadLine();
}
}