I'm using the tstring for it's storage option. that way I can scan it and fix it without getting to involved with other large arrays of different data types here are a snippet of my code. The TstrFile may hold over 1 million lines at this point.
procedure TFMain.PostProcessCSVfile(var TStrFile:TStringList);
const CountToV_mul = 0.319671630859375;
var i,count: Cardinal;
ch:integer;
offset:array[1..12] of extended; // 10 byte float
TimeOffset, tmp:extended;
str, off_str:string;
Tstr: TStringList;
begin
FillChar(offset,sizeof(offset),0);
count:=0;
// scan the rest to update bias and offset numbers
i := 240*60; // skip frist minite of data
if (i > TStrFile.Count-1) then
i:= 1; // skip the header
Tstr := TStringList.Create;
try
// scan the file and calulate the offsets
while (i < TStrFile.Count) do begin
str:= TstrFile.Strings[i];
tstr.CommaText:= str;
inc(count);
for ch:=1 to 12 do begin
tmp := StrToInt(tstr.Strings[ch+5]); // 6th col = chan1
offset[ch] := offset[ch]+tmp;
end;
inc(i); // next line
end; // end of while
if (count > 1) then begin
for ch:=1 to 12 do begin
offset[ch] := offset[ch]/count;
end;
end;
off_str := format(';,,,,,offset=,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,mul=,%.4f',
[offset[1],offset[2],offset[3],offset[ 4],offset[ 5],offset[ 6],
offset[7],offset[8],offset[9],offset[10],offset[11],offset[12],CountToV_mul]);
TStrFile.Insert(0,off_str);
// update the header
str := TStrFile.Strings[1]; // get the header
str := str+'seconds,uV1,uV2,uV3,uV4,uV5,uV6,uV7,uV8,uV9,uV10,uV11,uV12';
TStrFile.Strings[1] := str; // save new header
// save the time of the frist record so it can be removed later
str:=TstrFile.Strings[2];
tstr.CommaText:= str;
TimeOffset := StrToInt(tstr.Strings[1]); // second col = time
// convert each ADC -> voltage (adc-offset)*mul
for i:=2 to TStrFile.Count-1 do begin
str:= TstrFile.Strings[i];
tstr.CommaText:= str;
// adjust the time
tmp := StrToInt(tstr.Strings[1]); // 2nd = time
tmp := (tmp -TimeOffset) *1.000/1024.0; // ms ->sec
tstr.Add(format('%-.4f',[tmp])); // add to the end of this line
// now for the channel data
for ch:=1 to 12 do begin
str := tstr.Strings[ch+5]; // 7th col = chan1 data
if str <>'' then begin
tmp := StrToInt(str);
tmp := tmp - offset[ch];
tmp := tmp * CountToV_mul;
tstr.Add(format('%.3f',[tmp]));
end;
end;
str := tstr.CommaText;
TstrFile.Strings[i] := str;
end;
// ...
finally
Tstr.Free;
end;
I know things would run faster if I did not do the string conversion but the speed of this software is already 1200% faster than it's original and it did not do the post processing