-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcond2conditionorder.bas
484 lines (364 loc) · 13.8 KB
/
cond2conditionorder.bas
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
Attribute VB_Name = "CodeCOND2ConditionOrder"
' (c) Copyright 1995-2025 by John J. Donovan
Option Explicit
' Column condition arrays for ordering
Dim ConditionsNumberOf As Integer
Dim Condition_Takeoffs() As Single
Dim Condition_Kilovolts() As Single
Dim Condition_BeamCurrents() As Single
Dim Condition_BeamSizes() As Single
Dim Condition_ColMethods() As Integer
Dim Condition_ColStrings() As String
Sub Cond2ConditionDefaultOrder(sample() As TypeSample)
' Load default combined condition orders for new or modified sample
ierror = False
On Error GoTo Cond2ConditionDefaultOrderError
Dim n As Integer, nn As Integer
Dim chan As Integer, tchan As Integer
Dim bMatched As Boolean, tAddCond As Boolean
' Check for at least one element
If sample(1).LastElm% <= 0 Then Exit Sub
' Re-set check for matched conditions (load channel 1 as default)
bMatched = Cond2ConditionMatched(Int(0), Int(1), nn%, sample())
' Loop on sample until all conditions loaded
bMatched = False
Do Until bMatched
tAddCond = False
' Check for this condition in existing conditions
For chan% = 1 To sample(1).LastElm%
bMatched = Cond2ConditionMatched(Int(1), chan%, nn%, sample())
If Not bMatched Then
tAddCond = True
tchan% = chan%
Exit For
End If
Next chan%
' Found new condition for this sample, so load new condition
If tAddCond Then
n% = ConditionsNumberOf% + 1
' Increase array
If n% > ConditionsNumberOf% Then
ReDim Preserve Condition_Takeoffs(1 To n%) As Single
ReDim Preserve Condition_Kilovolts(1 To n%) As Single
ReDim Preserve Condition_BeamCurrents(1 To n%) As Single
ReDim Preserve Condition_BeamSizes(1 To n%) As Single
ReDim Preserve Condition_ColMethods(1 To n%) As Integer
ReDim Preserve Condition_ColStrings(1 To n%) As String
End If
' Save condition to module level variables
Condition_Takeoffs!(n%) = sample(1).TakeoffArray!(tchan%)
Condition_Kilovolts!(n%) = sample(1).KilovoltsArray!(tchan%)
Condition_BeamCurrents!(n%) = sample(1).BeamCurrentArray!(tchan%)
Condition_BeamSizes!(n%) = sample(1).BeamSizeArray!(tchan%)
Condition_ColMethods%(n%) = sample(1).ColumnConditionMethodArray%(tchan%)
Condition_ColStrings$(n%) = sample(1).ColumnConditionStringArray$(tchan%)
ConditionsNumberOf% = n%
End If
Loop
' Now reload all condition orders based on new conditions
For chan% = 1 To sample(1).LastElm%
bMatched = Cond2ConditionMatched(Int(1), chan%, nn%, sample())
If Not bMatched Then GoTo Cond2ConditionDefaultOrderNotFound
sample(1).ConditionNumbers%(chan%) = nn%
Next chan%
' Load (for now) sample combined condition acquisition order as condition step
For n% = 1 To Cond2ConditionGetMaxCondition%(sample())
sample(1).ConditionOrders%(n%) = n%
Next n%
Exit Sub
' Errors
Cond2ConditionDefaultOrderError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionDefaultOrder"
ierror = True
Exit Sub
Cond2ConditionDefaultOrderNotFound:
msg$ = "Channel " & Format$(chan%) & "(" & sample(1).Elsyms$(chan%) & " " & sample(1).Xrsyms$(chan%) & ") could not be matched to an existing condition. This error should not occur, please contact Probe Software technical support."
MsgBox msg$, vbOKOnly + vbExclamation, "Cond2ConditionDefaultOrder"
ierror = True
Exit Sub
End Sub
Function Cond2ConditionMatched(mode As Integer, chan As Integer, nn As Integer, sample() As TypeSample) As Integer
' Checks to see if the sample conditions that are different from the parameters since the last time called.
' mode = 0 reset condition
' mode = 1 check for changed condition
' chan is the element channel to check the conditions for
' nn is the column condition number that was matched (0 = no match)
ierror = False
On Error GoTo Cond2ConditionMatchedError
Dim n As Integer
' Set default as changed
Cond2ConditionMatched = False
' Check for just a re-set
If mode% = 0 Then
ConditionsNumberOf% = 1
ReDim Condition_Takeoffs(1 To ConditionsNumberOf%) As Single
ReDim Condition_Kilovolts(1 To ConditionsNumberOf%) As Single
ReDim Condition_BeamCurrents(1 To ConditionsNumberOf%) As Single
ReDim Condition_BeamSizes(1 To ConditionsNumberOf%) As Single
ReDim Condition_ColMethods(1 To ConditionsNumberOf%) As Integer
ReDim Condition_ColStrings(1 To ConditionsNumberOf%) As String
Condition_Takeoffs!(ConditionsNumberOf%) = sample(1).TakeoffArray!(chan%) ' load passed element as default
Condition_Kilovolts!(ConditionsNumberOf%) = sample(1).KilovoltsArray!(chan%)
Condition_BeamCurrents!(ConditionsNumberOf%) = sample(1).BeamCurrentArray!(chan%)
Condition_BeamSizes!(ConditionsNumberOf%) = sample(1).BeamSizeArray!(chan%)
Condition_ColMethods%(ConditionsNumberOf%) = sample(1).ColumnConditionMethodArray%(chan%)
Condition_ColStrings$(ConditionsNumberOf%) = sample(1).ColumnConditionStringArray$(chan%)
nn% = 0
Exit Function
End If
' Using analytical conditions (analytical *and* column condition strings must match!)
For n% = 1 To ConditionsNumberOf%
' Using analytical conditions
If sample(1).ColumnConditionMethodArray%(chan%) = 0 Then
If sample(1).TakeoffArray!(chan%) = Condition_Takeoffs!(n%) And _
sample(1).KilovoltsArray!(chan%) = Condition_Kilovolts!(n%) And _
sample(1).BeamCurrentArray!(chan%) = Condition_BeamCurrents!(n%) And _
sample(1).BeamSizeArray!(chan%) = Condition_BeamSizes!(n%) And _
sample(1).ColumnConditionStringArray$(chan%) = Condition_ColStrings$(n%) Then
Cond2ConditionMatched = True
nn% = n%
End If
' Using column conditions
Else
If sample(1).ColumnConditionStringArray$(chan%) = Condition_ColStrings$(n%) Then
Cond2ConditionMatched = True
nn% = n%
End If
End If
Next n%
Exit Function
' Errors
Cond2ConditionMatchedError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionMatched"
ierror = True
Exit Function
End Function
Sub Cond2ConditionDisplayGrid(tForm As Form)
' Load combined condition to the display grid
ierror = False
On Error GoTo Cond2ConditionDisplayGridError
Dim i As Integer
' Load size
tForm.GridConditions.cols = 7
tForm.GridConditions.rows = ConditionsNumberOf% + 1
' Blank grid
tForm.GridConditions.Clear
' Resize and label fixed row
For i% = 0 To tForm.GridConditions.cols - 1
tForm.GridConditions.ColWidth(i%) = 400
Next i%
' Make last column very long for filename
tForm.GridConditions.ColWidth(tForm.GridConditions.cols - 1) = 4000
' Load fixed column labels
tForm.GridConditions.row = 0
tForm.GridConditions.col = 0
tForm.GridConditions.Text = "Num"
tForm.GridConditions.col = 1
tForm.GridConditions.Text = "TO"
tForm.GridConditions.col = 2
tForm.GridConditions.Text = "keV"
tForm.GridConditions.col = 3
tForm.GridConditions.Text = "nA"
tForm.GridConditions.col = 4
tForm.GridConditions.Text = "um"
tForm.GridConditions.col = 5
tForm.GridConditions.Text = "Col"
tForm.GridConditions.col = 6
tForm.GridConditions.Text = "File"
' Load the conditions to the grid
For i% = 1 To ConditionsNumberOf%
tForm.GridConditions.row = i%
tForm.GridConditions.col = 0
tForm.GridConditions.Text = Format$(i%)
tForm.GridConditions.col = 1
tForm.GridConditions.Text = Format$(Condition_Takeoffs!(i%))
tForm.GridConditions.col = 2
tForm.GridConditions.Text = Format$(Condition_Kilovolts!(i%))
tForm.GridConditions.col = 3
tForm.GridConditions.Text = Format$(Condition_BeamCurrents!(i%))
tForm.GridConditions.col = 4
tForm.GridConditions.Text = Format$(Condition_BeamSizes!(i%))
tForm.GridConditions.col = 5
tForm.GridConditions.Text = Format$(Condition_ColMethods%(i%))
tForm.GridConditions.col = 6
tForm.GridConditions.Text = MiscGetFileNameOnly$(Condition_ColStrings$(i%))
Next i%
Exit Sub
' Errors
Cond2ConditionDisplayGridError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionDisplayGrid"
ierror = True
Exit Sub
End Sub
Function Cond2ConditionGetNextChannel(motor As Integer, tOrder As Integer, tCond As Integer, sample() As TypeSample) As Integer
' Returns the next channel for this spectrometer number, spectrometer order and condition order
ierror = False
On Error GoTo Cond2ConditionGetNextChannelError
Dim chan As Integer, nextchan As Integer
' Find next spectro and element for this condition order
nextchan% = 0
For chan% = 1 To sample(1).LastElm%
If sample(1).ConditionNumbers%(chan%) = tCond% Then
If sample(1).MotorNumbers%(chan%) = motor% Then
If sample(1).OrderNumbers%(chan%) = tOrder% Then
nextchan% = chan%
Exit For
End If
End If
End If
Next chan%
Cond2ConditionGetNextChannel% = nextchan%
Exit Function
' Errors
Cond2ConditionGetNextChannelError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionGetNextChannel"
ierror = True
Exit Function
End Function
Function Cond2ConditionGetMaxCondition(sample() As TypeSample) As Integer
' Returns the maximum condition order for the sample
ierror = False
On Error GoTo Cond2ConditionGetMaxConditionError
Dim chan As Integer, max_order As Integer
' Search element for max condition number
max_order% = MININTEGER%
For chan% = 1 To sample(1).LastElm%
If sample(1).ConditionNumbers%(chan%) > max_order% Then max_order% = sample(1).ConditionNumbers%(chan%)
Next chan%
Cond2ConditionGetMaxCondition% = max_order%
Exit Function
' Errors
Cond2ConditionGetMaxConditionError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionGetMaxCondition"
ierror = True
Exit Function
End Function
Function Cond2ConditionGetMaxCondition2(motor As Integer, sample() As TypeSample) As Integer
' Returns the maximum condition order for the specified spectrometer for the sample
ierror = False
On Error GoTo Cond2ConditionGetMaxCondition2Error
Dim chan As Integer, max_order As Integer
' Search element for max condition number
max_order% = 0
For chan% = 1 To sample(1).LastElm%
If sample(1).MotorNumbers%(chan%) = motor% Then
If sample(1).ConditionNumbers%(chan%) > max_order% Then max_order% = sample(1).ConditionNumbers%(chan%)
End If
Next chan%
Cond2ConditionGetMaxCondition2% = max_order%
Exit Function
' Errors
Cond2ConditionGetMaxCondition2Error:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionGetMaxCondition2"
ierror = True
Exit Function
End Function
Function Cond2ConditionGetChannel(tCond As Integer, sample() As TypeSample) As Integer
' Returns first channel for the specified condition number (skips disable acquisition elements)
ierror = False
On Error GoTo Cond2ConditionGetChannelError
Dim chan As Integer, nchan As Integer
' Search element for specified condition number
nchan% = 0
For chan% = 1 To sample(1).LastElm%
If sample(1).DisableAcqFlag%(chan%) = 0 Then
If sample(1).ConditionNumbers%(chan%) = tCond% Then
nchan% = chan%
Exit For
End If
End If
Next chan%
Cond2ConditionGetChannel% = nchan%
Exit Function
' Errors
Cond2ConditionGetChannelError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionGetChannel"
ierror = True
Exit Function
End Function
Function Cond2ConditionCheckCondition(condition As Integer, wdsdone() As Boolean, sample() As TypeSample) As Boolean
' Returns true if all elements using the specified condition are complete
ierror = False
On Error GoTo Cond2ConditionCheckConditionError
Dim chan As Integer
Cond2ConditionCheckCondition = True
' Loop on channels
For chan% = 1 To sample(1).LastElm%
If sample(1).ConditionNumbers%(chan%) = condition% And Not wdsdone(chan%) Then
Cond2ConditionCheckCondition = False
Exit For
End If
Next chan%
Exit Function
' Errors
Cond2ConditionCheckConditionError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionCheckCondition"
ierror = True
Exit Function
End Function
Function CondConditionGetAcquisitionOrder(conditionorder As Integer, sample() As TypeSample) As Integer
' Return the condition number for the specified acquisition condition order
ierror = False
On Error GoTo CondConditionGetAcquisitionOrderError
Dim n As Integer
CondConditionGetAcquisitionOrder% = 1
' Loop on conditions
For n% = 1 To MAXCOND%
If sample(1).ConditionOrders%(n%) = conditionorder% Then
CondConditionGetAcquisitionOrder% = n%
Exit For
End If
Next n%
Exit Function
' Errors
CondConditionGetAcquisitionOrderError:
MsgBox Error$, vbOKOnly + vbCritical, "CondConditionGetAcquisitionOrder"
ierror = True
Exit Function
End Function
Function Cond2ConditionCheckConditionPeaking(tPeakStandardNumber As Integer, condition As Integer, peakingdone() As Boolean, sample() As TypeSample) As Boolean
' Returns true if all peaking elements are peaked for the specified standard (Automate! window)
ierror = False
On Error GoTo Cond2ConditionCheckConditionPeakingError
Dim chan As Integer
Cond2ConditionCheckConditionPeaking = True
' Loop on channels
For chan% = 1 To sample(1).LastElm%
If sample(1).ConditionNumbers%(chan%) = condition% Then
If Not AcquisitionOnAutomate Or (AcquisitionOnAutomate And Not PeakOnAssignedStandardsFlag) Or (AcquisitionOnAutomate And tPeakStandardNumber% = sample(1).StdAssigns%(chan%)) Then
If WavePeakCenterFlags(chan%) And Not peakingdone(chan%) Then
Cond2ConditionCheckConditionPeaking = False
Exit For
End If
End If
End If
Next chan%
Exit Function
' Errors
Cond2ConditionCheckConditionPeakingError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionCheckConditionPeaking"
ierror = True
Exit Function
End Function
Function Cond2ConditionIsMotorUsed(condition As Integer, motor As Integer, sample() As TypeSample) As Boolean
' Returns true if this spectrometer is used in the specified condition
ierror = False
On Error GoTo Cond2ConditionIsMotorUsedError
Dim chan As Integer
Cond2ConditionIsMotorUsed = False
' Loop on channels
For chan% = 1 To sample(1).LastElm%
If sample(1).ConditionNumbers%(chan%) = condition% Then
If sample(1).MotorNumbers%(chan%) = motor% Then
Cond2ConditionIsMotorUsed = True
Exit For
End If
End If
Next chan%
Exit Function
' Errors
Cond2ConditionIsMotorUsedError:
MsgBox Error$, vbOKOnly + vbCritical, "Cond2ConditionIsMotorUsed"
ierror = True
Exit Function
End Function