-
Notifications
You must be signed in to change notification settings - Fork 0
/
FreqMatrix.pas
300 lines (255 loc) · 6.9 KB
/
FreqMatrix.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
unit FreqMatrix;
{$DebugInfo OFF}
{$LocalSymbols OFF}
{$ReferenceInfo OFF}
{$RangeChecks OFF}
{$OverflowChecks OFF}
{$Optimization ON}
interface
uses Classes, MultiDimMatrix,
ThreeDimTypes, ThreeDimMatrix, FreqMatrixIF;
type
TFreqMeasCell = class(T3DimCell, IFreqMeasCell)
private
fErrCode : SmallInt;
fIzmNum : LongWord;
fFreq, fDisp : double;
fVar : byte;
fMemory : TMemoryStream;
protected
function GetErrCode: SmallInt; stdcall;
function GetIzmNum: LongWord; stdcall;
function GetMemory: TMemoryStream; stdcall;
function GetFreq: double; stdcall;
function GetDisp: double; stdcall;
procedure SetErrCode(const Value: SmallInt);stdcall;
procedure SetIzmNum(const Value: LongWord); stdcall;
procedure SetFreq(const Value: double); stdcall;
procedure SetDisp(const Value: double); stdcall;
function GetVar: byte; stdcall;
procedure SetVar(const Value: byte); stdcall;
public
constructor Create(AOwner: TComponent; const ADimCell : IDepthCell);override;
destructor Destroy; override;
property ErrCode : SmallInt read GetErrCode write SetErrCode;
property IzmNum : LongWord read GetIzmNum write SetIzmNum;
property Freq : double read GetFreq write SetFreq;
property Disp : double read GetDisp write SetDisp;
property mVar : byte read GetVar write SetVar;
property Memory : TMemoryStream read GetMemory;
end;
TFreqDepthCell = class(TDepthCell)
protected
function DefaultCellClass: T3DimCellClass; override;
end;
{Ñòðóêòóðà òàáëèöû TFreqMatrix
3DimCell = ýòî ÿ÷åéêà òðåòüåãî èçìåðåíèÿ ñ êîíòåéíåðîì äëÿ ïðîèçâîëüíûõ äàííûõ
Col->°Ñ | -60 |..| 85 | <-Header
\/Row
Tag 1 |3DimCell |..| 3DimCell |
Tag 2 |3DimCell |..| 3DimCell |
Tag 3 |3DimCell |..| 3DimCell |
............
Tag 6 |3DimCell |..| 3DimCell |
}
TFreqMatrix = class(TMultiDimMatrix, IFreqMatrix)
protected
function DefaultCellClass : TCellClass; override;
public
function ByVar(ACol : byte; ATag : SmallInt; AVar: byte; const IID: TGUID; out Obj):boolean; stdcall;
function TotalCount : word; stdcall;
function ErrorCount : word; stdcall;
end;
TFreqMatrixClass = class of TFreqMatrix;
{Ñòðóêòóðà òàáëèöû TFreqTable
Col->°Ñ -60 |..| 85 | <-Header
\/Row
Tag 1 |Freq |..| Freq |
Tag 2 |Freq |..| Freq |
Tag 3 |Freq |..| Freq |
............
Tag 6 |Freq |..| Freq |
}
TValueCell = class(TCell, IValueCell)
private
fValue : double;
protected
function GetValue: double; stdcall;
procedure SetValue(AValue : double); stdcall;
public
property Value: double read GetValue write SetValue;
end;
TFreqTable = class(TMultiDimMatrix, IFreqTable)
private
fNominal : Double;
protected
function GetFreq(ACol, ARow : byte): double; stdcall;
procedure SetFreq(ACol, ARow : byte; AValue : double); stdcall;
function GetNominal: double;stdcall;
procedure SetNominal(AValue : double); stdcall;
function GetDeviation(ACol, ARow : byte): double;stdcall;
function DefaultCellClass : TCellClass; override;
public
property Freq[ACol, ARow : byte]: double read GetFreq write SetFreq;
property Nominal: double read GetNominal write SetNominal;
property Deviation[ACol, ARow : byte]: double read GetDeviation;
end;
TFreqTableClass = class of TFreqTable;
implementation
uses SysUtils, vdMath;
{ TFreqMeasCell }
constructor TFreqMeasCell.Create(AOwner: TComponent; const ADimCell: IDepthCell);
begin
inherited Create(AOwner, ADimCell);
fMemory := TMemoryStream.Create;
end;
destructor TFreqMeasCell.Destroy;
begin
FreeAndNil(fMemory);
inherited;
end;
function TFreqMeasCell.GetErrCode: SmallInt;
begin
result := fErrCode;
end;
function TFreqMeasCell.GetIzmNum: LongWord;
begin
result := fIzmNum;
end;
function TFreqMeasCell.GetMemory: TMemoryStream;
begin
fMemory.Position := 0;
result := fMemory;
end;
function TFreqMeasCell.GetDisp: double;
begin
Result := fDisp;
end;
function TFreqMeasCell.GetFreq: double;
begin
result := fFreq;
end;
function TFreqMeasCell.GetVar: byte;
begin
result := fVar;
end;
procedure TFreqMeasCell.SetErrCode(const Value: SmallInt);
begin
fErrCode := Value;
end;
procedure TFreqMeasCell.SetIzmNum(const Value: LongWord);
begin
fIzmNum := Value;
end;
procedure TFreqMeasCell.SetDisp(const Value: double);
begin
fDisp := Value;
end;
procedure TFreqMeasCell.SetFreq(const Value: double);
begin
fFreq := Value;
end;
procedure TFreqMeasCell.SetVar(const Value: byte);
begin
fVar := Value;
end;
{ VvarDepthCell }
function TFreqDepthCell.DefaultCellClass: T3DimCellClass;
begin
result := TFreqMeasCell;
end;
{ TVvarMeasTable }
function TFreqMatrix.ByVar(ACol : byte; ATag : SmallInt; AVar: byte; const IID: TGUID; out Obj): boolean;
var
vDepthCell : IDepthCell;
begin
result := ByParams(ACol, ATag, IDepthCell, vDepthCell)
and (vDepthCell.QueryItem(AVar, IID, Obj));
vDepthCell := nil;
end;
function TFreqMatrix.DefaultCellClass: TCellClass;
begin
result := TFreqDepthCell;
end;
function TFreqMatrix.TotalCount: word;
var
vIdx : word;
vCell : IDepthCell;
begin
result := 0;
vIdx := 0;
while vIdx < Cells.Count do
begin
if Cells.QueryItem(vIdx, IDepthCell, vCell) then
inc(result, vCell.Depth);
vCell := nil;
inc(vIdx);
end;
end;
function TFreqMatrix.ErrorCount: word;
var
vCellIdx, VvarIdx : word;
vCell : IDepthCell;
vVvarCell : IFreqMeasCell;
begin
result := 0;
vCellIdx := 0;
while vCellIdx < Cells.Count do
begin
if Cells.QueryItem(vCellIdx, IDepthCell, vCell) then
begin
VvarIdx := 0;
while VvarIdx < vCell.Depth do
begin
if vCell.QueryItem(VvarIdx, IFreqMeasCell, vVvarCell)
and (vVvarCell.ErrCode <> 0) then
inc(result);
vVvarCell := nil;
inc(VvarIdx);
end;
end;
vCell := nil;
inc(vCellIdx);
end;
end;
{ TVoltageCell }
function TValueCell.GetValue: double;
begin
result := fValue;
end;
procedure TValueCell.SetValue(AValue: double);
begin
fValue := AValue;
end;
{ TVoltageTable }
function TFreqTable.DefaultCellClass: TCellClass;
begin
result := TValueCell;
end;
function TFreqTable.GetFreq(ACol, ARow: byte): double;
var vValueCell : IValueCell;
begin
if ByIndex(ACol, ARow, IValueCell, vValueCell) then
result := vValueCell.Value;
end;
procedure TFreqTable.SetFreq(ACol, ARow: byte; AValue: double);
var vBoostCell : IValueCell;
begin
if ByIndex(ACol, ARow, IValueCell, vBoostCell) then
vBoostCell.Value := AValue;
end;
function TFreqTable.GetNominal: double;
begin
Result := fNominal;
end;
procedure TFreqTable.SetNominal(AValue: double);
begin
fNominal := AValue;
end;
function TFreqTable.GetDeviation(ACol, ARow: byte): double;
var vValueCell : IValueCell;
begin
if ByIndex(ACol, ARow, IValueCell, vValueCell) then
result := ppm(fNominal, vValueCell.Value);
end;
end.