averagelap.pro
3.72 KB
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
; $Id: $
;====================================================================
;---------- Special LAP averaging 2D array
;====================================================================
pro AVERAGELAP, AverStructure, T, Val
common GraphC, Graph, GraphN, Item
Yinfo = SIZE(Val)
RetSize = Yinfo[2];
Val = reform(Val, Yinfo[1]*RetSize);
if (Graph[GraphN].Step GT AverStructure.Sampling*2.0) then begin
MF = AverStructure.Nres eq -1L ? Val : [*(AverStructure.LastVal),VAL]
Time = AverStructure.Nres eq -1L ? T : [*(AverStructure.LastTime),T]
N_Time = N_elements(Time)
NAve = long(((Time[N_Time-1] < Graph[GraphN].TotalTime) - Time[0]) / Graph[GraphN].Step + 1)> 1L
MF = REFORM(MF, Yinfo[1], N_Time)
numStart = where(abs((*AverStructure.Time)-Time[0]) LE Graph[GraphN].Step/2.0, IndexStart)
if (IndexStart le 0) then begin
AverStructure.Nres = -1L
return
endif
NStart = numStart[0]
for i = NStart, NStart+NAve-1L do begin
num = where(abs((*AverStructure.Time)[i]-Time) LE Graph[GraphN].Step/2.0, Index)
if (Index LE 0) AND (Graph[GraphN].Sampling[Item] LT Graph[GraphN].MaxSampling[Item]) then $
num = where(abs((*AverStructure.Time)[i]-Time) LE Graph[GraphN].MaxSampling[Item]/2.0, Index)
if (Index GT 0) then begin
for k = 0, Yinfo[1]-2 do begin
if (Index GT 1) then begin
temp = 0.0;
numK = 0;
for kk = 0, Index-1 do begin
if (finite(MF[k,num[kk]])) then begin
temp += MF[k,num[kk]];
numK++;
endif ; if (finite
endfor ; for kk
(*AverStructure.Val)[i*Yinfo[1]+k] = temp/ numK;
endif else (*AverStructure.Val)[i*Yinfo[1]+k] = MF[k,num[0]] ; if (Index GT 1)
endfor ; for k = 0,
(*AverStructure.Val)[i*Yinfo[1]+Yinfo[1]-1] = MF[Yinfo[1]-1,num[0]]
endif ; if (Index GT 0)
endfor ; for i = NStart
AverStructure.Nres = Index GT 0 ? (num[Index-1]+1) < (N_Time-1) : -1L
if (Graph[GraphN].CurrentSec LT (Graph[GraphN].Sections-1)) AND (AverStructure.Nres ne -1) then begin
*(AverStructure.LastTime) = Time[AverStructure.NRes:*]
*(AverStructure.LastVal) = REFORM(MF[*,AverStructure.NRes:N_Time-1], Yinfo[1]*(N_Time-AverStructure.Nres))
endif
if (Graph[GraphN].CurrentSec eq (Graph[GraphN].Sections-1)) then begin
if ptr_valid(AverStructure.LastTime) then ptr_free, AverStructure.LastTime
if ptr_valid(AverStructure.LastVal) then ptr_free, AverStructure.LastVal
endif
endif else begin ;if (Step GT Sampling*2.0)
records = N_elements(*AverStructure.Time);
if (records eq 0) then begin
(*AverStructure.Time) = T; : [*AverStructure.Time,T]
(*AverStructure.Val) = Val;
endif else begin
numBefore = where((*AverStructure.Time)[records-1] GT T, IndexBefore);
if (IndexBefore eq 0) then begin
(*AverStructure.Time) = [*AverStructure.Time,T];
(*AverStructure.Val) = [*AverStructure.Val,Val];
endif else begin
(*AverStructure.Time) = [*AverStructure.Time,T[IndexBefore-1:RetSize-1]];
(*AverStructure.Val) = [*AverStructure.Val,Val[Yinfo[1]*(IndexBefore-1):Yinfo[1]*RetSize-1]]
endelse
endelse
endelse
return
end