This repository has been archived by the owner on May 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsuWindTower.cr3
695 lines (655 loc) · 25.3 KB
/
wsuWindTower.cr3
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Washington State University '
' Big Southern Butte Turbulence Field Study '
' '
' CR3000 Datalogger - WSU Wind Tower v2 '
' pokeeffe - patrick.okeeffe@email.wsu.edu '
' Last modified 2010.07.17 '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''' PROGRAM DEFAULTS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Define the following values to load upon program reset (or following catastrophe)
' These values can be adjusted during run-time using the program menu
Const DEF_save_data = True
Const DEF_com1_used = True
Const DEF_com2_used = True
Const DEF_com3_used = True
Const DEF_com4_used = False
Const DEF_azimuth_1 = 268
Const DEF_azimuth_2 = 268
Const DEF_azimuth_3 = 268
Const DEF_azimuth_4 = 268 'COM4 not used, just in case
Const DEF_declination = 13 'value for Big Southern Butte, ID early July 2010
'''''' ATI sonic configuration '''''''''''''''''''''''''''''''''''''''''''''''''
' ASCII mode: terse Data quality algorithm: ON
' Baud rate: 9600 Shadow correction: ON
' Parity: even Remove RH from temp calc: OFF
' data bits: 7 Sampling 10Hz (20 samples, 5ms apart per output)
' stop bits: 1 Output: U,V,W,T
' Data lag: 1/10th second
'''''' PS100 charger wiring ''''''''''''''''''''''''''''''''''''''''''''''''''''
'POWER IN (15- vDC)
'one 18vDC dell laptop power supply (+)
'other 18vDC dell laptop power supply (-)
'
'POWER OUT
'12V CR3000 12v
'12V ATI sonics (+)
'G CR3000 ground
'G ATI sonics (-)
'''''' CR3000 Wiring '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'POWER IN (10-16vDC)
'12V PS100 charger (+)
'G PS100 charger (-)
'
'BATTERY BASE POWER IN
'one 18vDC dell laptop power supply (+)
'other 18vDC dell laptop power supply (-)
'
'COM PORTS
'C1 green COM1 Tx
'C2 red COM1 Rx
'C3 brown COM2 Tx
'C4 white COM2 Rx
'G black common ground/shield
'C5 blue COM3 Tx
'C6 orange COM3 Rx
'C7 yellow COM4 Tx
'C8 violet COM4 Rx
'''''' Variables '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim initialized = False 'used as flag to reinit; I don't trust PreserveVariables function yet
Dim j
Const R = 8.314472*10^-5
Const DperR = 180/3.14159
Const Yes = True
Const No = False
' DATALOGGER
Public panel_temp_C
Public batt_V
Public low_12V_cnt
Units panel_temp_C = C
Units batt_V = volts
Units low_12V_cnt = records
' MENU/STATE VARIABLES
Public save_data As Boolean
Public com_states(4) As Boolean
Alias com_states(1) = com1_used
Alias com_states(2) = com2_used
Alias com_states(3) = com3_used
Alias com_states(4) = com4_used
' TIME VARS
Public rTime(9)
Alias rTime(1) = rYear
Alias rTime(2) = rMonth
Alias rTime(3) = rDay
Alias rTime(4) = rHour
Alias rTime(5) = rMinute
Alias rTime(6) = rSecond
Alias rTime(7) = rMicroSec
Alias rTime(8) = rWeekDay
Alias rTime(9) = rDayOfYear
' COM 1 sonic input
Public sonic_1(5) As Float
Alias sonic_1(1) = Ux_1
Alias sonic_1(2) = Uy_1
Alias sonic_1(3) = Uz_1
Alias sonic_1(4) = Ts_1
Alias sonic_1(5) = diag_1
Units sonic_1 = m/s
Units Ts_1 = C
Dim son1_in_str As String * 20
Dim son1_in_parts(4) As String * 5
Dim bytes_back_1
' COM 2 sonic input
Public sonic_2(5) As Float
Alias sonic_2(1) = Ux_2
Alias sonic_2(2) = Uy_2
Alias sonic_2(3) = Uz_2
Alias sonic_2(4) = Ts_2
Alias sonic_2(5) = diag_2
Units sonic_2 = m/s
Units Ts_2 = C
Dim son2_in_str As String * 20
Dim son2_in_parts(4) As String * 5
Dim bytes_back_2
' COM 3 sonic input
Public sonic_3(5) As Float
Alias sonic_3(1) = Ux_3
Alias sonic_3(2) = Uy_3
Alias sonic_3(3) = Uz_3
Alias sonic_3(4) = Ts_3
Alias sonic_3(5) = diag_3
Units sonic_3 = m/s
Units Ts_3 = C
Dim son3_in_str As String * 20
Dim son3_in_parts(4) As String * 5
Dim bytes_back_3
' COM 4 sonic input
Public sonic_4(5) As Float
Alias sonic_4(1) = Ux_4
Alias sonic_4(2) = Uy_4
Alias sonic_4(3) = Uz_4
Alias sonic_4(4) = Ts_4
Alias sonic_4(5) = diag_4
Units sonic_4 = m/s
Units Ts_4 = C
Dim son4_in_str As String * 20
Dim son4_in_parts(4) As String * 5
Dim bytes_back_4
' UNRECORDED INST. WIND SPEEDS & DIRECTIONS
Public instWD(4)
Alias instWD(1) = instWD_1
Alias instWD(2) = instWD_2
Alias instWD(3) = instWD_3
Alias instWD(4) = instWD_4
Units instWD = degrees
Public instWS(4)
Alias instWS(1) = instWS_1
Alias instWS(2) = instWS_2
Alias instWS(3) = instWS_3
Alias instWS(4) = instWS_4
Units instWS = m/s
'Public negUy(4)
'Alias negUy(1) = negUy_1
'Alias negUy(2) = negUy_2
'Alias negUy(3) = negUy_3
'Alias negUy(4) = negUy_4
' SONIC ORIENTATION / WIND VECTOR CALC OFFSETS
Public declination
Public headings(4)
Alias headings(1) = azimuth_1
Alias headings(2) = azimuth_2
Alias headings(3) = azimuth_3
Alias headings(4) = azimuth_4
Units declination = degrees
Units headings = degrees
' RECORDED AVERAGED WIND SPEEDS & DIRECTIONS
'Public avgWind(24)
'Alias avgWind(1) = WSavg_1
'Alias avgWind(2) = WDunitAvg_1
'Alias avgWind(3) = WDepaStdev_1
'Alias avgWind(4) = WSavg_1_dup
'Alias avgWind(5) = WSrsltAvg_1
'Alias avgWind(6) = WDrsltAvg_1
'Alias avgWind(7) = WDcsiStdev_1
'Alias avgWind(8) = WSstdev_1
'Alias avgWind(9) = WSavg_2
'Alias avgWind(10) = WDunitAvg_2
'Alias avgWind(11) = WDepaStdev_2
'Alias avgWind(12) = WSavg_2_dup
'Alias avgWind(13) = WSrsltAvg_2
'Alias avgWind(14) = WDrsltAvg_2
'Alias avgWind(15) = WDcsiStdev_2
'Alias avgWind(16) = WSstdev_2
'Alias avgWind(17) = WSavg_3
'Alias avgWind(18) = WDunitAvg_3
'Alias avgWind(19) = WDepaStdev_3
'Alias avgWind(20) = WSavg_3_dup
'Alias avgWind(21) = WSrsltAvg_3
'Alias avgWind(22) = WDrsltAvg_3
'Alias avgWind(23) = WDcsiStdev_3
'Alias avgWind(24) = WSstdev_3
'Alias avgWind(25) = WSavg_4
'Alias avgWind(26) = WDunitAvg_4
'Alias avgWind(27) = WDepaStdev_4
'Alias avgWind(28) = WSavg_4_dup
'Alias avgWind(29) = WSrsltAvg_4
'Alias avgWind(30) = WDrsltAvg_4
'Alias avgWind(31) = WDcsiStdev_4
'Alias avgWind(32) = WSstdev_4
'''''' Data Tables ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DataTable(wsuWind_10hz,save_data,-1)
DataInterval(0,0,mSec,100) ' set data inteval same as scan interval
CardOut(0,-1) ' store on card: ring fill, allocate all memory
Sample(5,sonic_1,FP2)
Sample(5,sonic_2,FP2)
Sample(5,sonic_3,FP2)
Sample(5,sonic_4,FP2)
EndTable
'DataTable(wsuWind_5min,save_data,-1)
' DataInterval(0,5,Min,10)
' CardOut(0,-1)
' 'Average(3,sonic_1(1),FP2,False)
' Average(1,Ux_1,FP2,(Ux_1=NAN))
' Average(1,Uy_1,FP2,(Uy_1=NAN))
' Average(1,Uz_1,FP2,(Uz_1=NAN))
' Sample(1,WSavg_1,FP2)
' Sample(1,WSrsltAvg_1,FP2)
' Sample(1,WSstdev_1,FP2)
' Sample(1,WDunitAvg_1,FP2)
' Sample(1,WDrsltAvg_1,FP2)
' Sample(1,WDepaStdev_1,FP2)
' Sample(1,WDcsiStdev_1,FP2)
' 'Average(3,sonic_2(1),FP2,False)
' Average(1,Ux_2,FP2,(Ux_2=NAN))
' Average(1,Uy_2,FP2,(Uy_2=NAN))
' Average(1,Uz_2,FP2,(Uz_2=NAN))
' Sample(1,WSavg_2,FP2)
' Sample(1,WSrsltAvg_2,FP2)
' Sample(1,WSstdev_2,FP2)
' Sample(1,WDunitAvg_2,FP2)
' Sample(1,WDrsltAvg_2,FP2)
' Sample(1,WDepaStdev_2,FP2)
' Sample(1,WDcsiStdev_2,FP2)
' 'Average(3,sonic_3(1),FP2,False)
' Average(1,Ux_3,FP2,(Ux_3=NAN))
' Average(1,Uy_3,FP2,(Uy_3=NAN))
' Average(1,Uz_3,FP2,(Uz_3=NAN))
' Sample(1,WSavg_3,FP2)
' Sample(1,WSrsltAvg_3,FP2)
' Sample(1,WSstdev_3,FP2)
' Sample(1,WDunitAvg_3,FP2)
' Sample(1,WDrsltAvg_3,FP2)
' Sample(1,WDepaStdev_3,FP2)
' Sample(1,WDcsiStdev_3,FP2)
' Average(3,sonic_4(1),FP2,False)
' Sample(1,WSavg_4,FP2)
' Sample(1,WSrsltAvg_4,FP2)
' Sample(1,WSstdev_4,FP2)
' Sample(1,WDunitAvg_4,FP2)
' Sample(1,WDrsltAvg_4,FP2)
' Sample(1,WDepaStdev_4,FP2)
' Sample(1,WDcsiStdev_4,FP2)
' Average(1,batt_V,FP2,(batt_V=NAN))
'EndTable
'DataTable(wsuWind_30min,save_data,-1)
' DataInterval(0,30,min,10)
' CardOut(0,-1)
' 'Average(3,sonic_1(1),FP2,False) 'replaced with seperate avg()
' Average(1,Ux_1,FP2,(Ux_1=NAN))
' Average(1,Uy_1,FP2,(Uy_1=NAN))
' Average(1,Uz_1,FP2,(Uz_1=NAN))
' Sample(1,WSavg_1,FP2)
' Sample(1,WSrsltAvg_1,FP2)
' Sample(1,WSstdev_1,FP2)
' Sample(1,WDunitAvg_1,FP2)
' Sample(1,WDrsltAvg_1,FP2)
' Sample(1,WDepaStdev_1,FP2)
' Sample(1,WDcsiStdev_1,FP2)
' 'Average(3,sonic_2(1),FP2,False) 'replaced with seperate avg()
' Average(1,Ux_2,FP2,(Ux_2=NAN))
' Average(1,Uy_2,FP2,(Uy_2=NAN))
' Average(1,Uz_2,FP2,(Uz_2=NAN))
' Sample(1,WSavg_2,FP2)
' Sample(1,WSrsltAvg_2,FP2)
' Sample(1,WSstdev_2,FP2)
' Sample(1,WDunitAvg_2,FP2)
' Sample(1,WDrsltAvg_2,FP2)
' Sample(1,WDepaStdev_2,FP2)
' Sample(1,WDcsiStdev_2,FP2)
' 'Average(3,sonic_3(1),FP2,False) 'replaced with seperate avg()
' Average(1,Ux_3,FP2,(Ux_3=NAN))
' Average(1,Uy_3,FP2,(Uy_3=NAN))
' Average(1,Uz_3,FP2,(Uz_3=NAN))
' Sample(1,WSavg_3,FP2)
' Sample(1,WSrsltAvg_3,FP2)
' Sample(1,WSstdev_3,FP2)
' Sample(1,WDunitAvg_3,FP2)
' Sample(1,WDrsltAvg_3,FP2)
' Sample(1,WDepaStdev_3,FP2)
' Sample(1,WDcsiStdev_3,FP2)
' Average(3,sonic_4(1),FP2,False) 'com4 not used, should be changed tho
' Sample(1,WSavg_4,FP2)
' Sample(1,WSrsltAvg_4,FP2)
' Sample(1,WSstdev_4,FP2)
' Sample(1,WDunitAvg_4,FP2)
' Sample(1,WDrsltAvg_4,FP2)
' Sample(1,WDepaStdev_4,FP2)
' Sample(1,WDcsiStdev_4,FP2)
' Average(1,batt_V,FP2,(batt_V=NAN))
'EndTable
'DataTable(windVec_5min,save_data,1)
' DataInterval(0,5,Min,1)
' WindVector(1,negUy_1,Ux_1,FP2,(NOT(com1_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,0)
' FieldNames("1_avgWS:, 1_unitAvgWD:, 1_epaStdevWD")
' WindVector(1,negUy_1,Ux_1,FP2,(NOT(com1_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,2)
' FieldNames("1_dup:, 1_rsltAvgWS:, 1_rsltAvgWD:, 1_csiStdevWD")
' StdDev(1,instWS_1,FP2,(NOT(com1_used) OR (instWS_1=NAN)))
' WindVector(1,negUy_2,Ux_2,FP2,(NOT(com2_used) OR (negUy_2=NAN) OR (Ux_2=NAN)),0,1,0)
' FieldNames("2_avgWS:, 2_unitAvgWD:, 2_epaStdevWD")
' WindVector(1,negUy_2,Ux_2,FP2,(NOT(com2_used) OR (negUy_2=NAN) OR (Ux_2=NAN)),0,1,2)
' FieldNames("2_dup:, 2_rsltAvgWS:, 2_rsltAvgWD:, 2_csiStdevWD")
' StdDev(1,instWS_2,FP2,(NOT(com2_used) OR (instWS_2=NAN)))
' WindVector(1,negUy_3,Ux_3,FP2,(NOT(com3_used) OR (negUy_3=NAN) OR (Ux_3=NAN)),0,1,0)
' FieldNames("3_avgWS:, 3_unitAvgWD:, 3_epaStdevWD")
' WindVector(1,negUy_3,Ux_3,FP2,(NOT(com3_used) OR (negUy_3=NAN) OR (Ux_3=NAN)),0,1,2)
' FieldNames("3_dup:, 3_rsltAvgWS:, 3_rsltAvgWD:, 3_csiStdevWD")
' StdDev(1,instWS_3,FP2,(NOT(com3_used) OR (instWS_3=NAN)))
' WindVector(1,negUy_4,Ux_4,FP2,NOT(com4_used),0,1,0)
' FieldNames("4_avgWS:, 4_unitAvgWD:, 4_epaStdevWD")
' WindVector(1,negUy_4,Ux_4,FP2,NOT(com4_used),0,1,2)
' FieldNames("4_dup:, 4_rsltAvgWS:, 4_rsltAvgWD:, 4_csiStdevWD")
' StdDev(1,instWS_4,FP2,NOT(com4_used))
'EndTable
'DataTable(windVec_30min,save_data,1)
' DataInterval(0,30,Min,1)
' WindVector(1,negUy_1,Ux_1,FP2,(NOT(com1_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,0)
' FieldNames("1_avgWS:, 1_unitAvgWD:, 1_epaStdevWD")
' WindVector(1,negUy_1,Ux_1,FP2,(NOT(com1_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,2)
' FieldNames("1_dup:, 1_rsltAvgWS:, 1_rsltAvgWD:, 1_csiStdevWD")
' StdDev(1,instWS_1,FP2,(NOT(com1_used) OR (instWS_1=NAN)))
' WindVector(1,negUy_2,Ux_2,FP2,(NOT(com2_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,0)
' FieldNames("2_avgWS:, 2_unitAvgWD:, 2_epaStdevWD")
' WindVector(1,negUy_2,Ux_2,FP2,(NOT(com2_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,2)
' FieldNames("2_dup:, 2_rsltAvgWS:, 2_rsltAvgWD:, 2_csiStdevWD")
' StdDev(1,instWS_2,FP2,(NOT(com2_used) OR (instWS_2=NAN)))
' WindVector(1,negUy_3,Ux_3,FP2,(NOT(com3_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,0)
' FieldNames("3_avgWS:, 3_unitAvgWD:, 3_epaStdevWD")
' WindVector(1,negUy_3,Ux_3,FP2,(NOT(com3_used) OR (negUy_1=NAN) OR (Ux_1=NAN)),0,1,2)
' FieldNames("3_dup:, 3_rsltAvgWS:, 3_rsltAvgWD:, 3_csiStdevWD")
' StdDev(1,instWS_3,FP2,(NOT(com3_used) OR (instWS_3=NAN)))
' WindVector(1,negUy_4,Ux_4,FP2,NOT(com4_used),0,1,0)
' FieldNames("4_avgWS:, 4_unitAvgWD:, 4_epaStdevWD")
' WindVector(1,negUy_4,Ux_4,FP2,NOT(com4_used),0,1,2)
' FieldNames("4_dup:, 4_rsltAvgWS:, 4_rsltAvgWD:, 4_csiStdevWD")
' StdDev(1,instWS_4,FP2,NOT(com4_used))
'EndTable
'''''' Datalogger Menu ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DisplayMenu("WSU Wind Tower",-2) 'show menu upon startup; display system as submenu
MenuItem("Save data?",save_data)
MenuPick(Yes,No)
DisplayValue("Battery",Public.batt_V)
SubMenu("Watch 10hz data")
SubMenu("COM1")
DisplayValue("Ux",Public.Ux_1)
DisplayValue("Uy",Public.Uy_1)
DisplayValue("Uz",Public.Uz_1)
DisplayValue("Ts",Public.Ts_1)
DisplayValue("WS",Public.instWS_1)
DisplayValue("WD",Public.instWD_1)
DisplayValue("diag",Public.diag_1)
EndSubMenu
SubMenu("COM2")
DisplayValue("Ux",Public.Ux_2)
DisplayValue("Uy",Public.Uy_2)
DisplayValue("Uz",Public.Uz_2)
DisplayValue("Ts",Public.Ts_2)
DisplayValue("WS",Public.instWS_2)
DisplayValue("WD",Public.instWD_2)
DisplayValue("diag",Public.diag_2)
EndSubMenu
SubMenu("COM3")
DisplayValue("Ux",Public.Ux_3)
DisplayValue("Uy",Public.Uy_3)
DisplayValue("Uz",Public.Uz_3)
DisplayValue("Ts",Public.Ts_3)
DisplayValue("WS",Public.instWS_3)
DisplayValue("WD",Public.instWD_3)
DisplayValue("diag",Public.diag_3)
EndSubMenu
SubMenu("COM4")
DisplayValue("Ux",Public.Ux_4)
DisplayValue("Uy",Public.Uy_4)
DisplayValue("Uz",Public.Uz_4)
DisplayValue("Ts",Public.Ts_4)
DisplayValue("WS",Public.instWS_4)
DisplayValue("WD",Public.instWD_4)
DisplayValue("diag",Public.diag_4)
EndSubMenu
EndSubMenu
SubMenu("Sonic COM setup")
MenuItem("On COM1?",com1_used)
MenuPick(Yes,No)
MenuItem("On COM2?",com2_used)
MenuPick(Yes,No)
MenuItem("On COM3?",com3_used)
MenuPick(Yes,No)
MenuItem("On COM4?",com4_used)
MenuPick(Yes,No)
EndSubMenu
SubMenu("Sonic orientation")
MenuItem("Azimuth 1",azimuth_1)
MenuItem("Azimuth 2",azimuth_2)
MenuItem("Azimuth 3",azimuth_3)
MenuItem("Azimuth 4",azimuth_4)
MenuItem("Declination",declination)
EndSubMenu
EndMenu
'''''' SUBROUTINES ''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub setDefaults
save_data = DEF_save_data
com1_used = DEF_com1_used
com2_used = DEF_com2_used
com3_used = DEF_com3_used
com4_used = DEF_com4_used
azimuth_1 = DEF_azimuth_1
azimuth_2 = DEF_azimuth_2
azimuth_3 = DEF_azimuth_3
azimuth_4 = DEF_azimuth_4
declination = DEF_declination
initialized = True
EndSub
Sub resetVars
Ux_1 = NAN
Uy_1 = NAN
Uz_1 = NAN
Ts_1 = NAN
diag_1 = 0 'need to be added to - must be number; could be set to NAN later
Ux_2 = NAN
Uy_2 = NAN
Uz_2 = NAN
Ts_2 = NAN
diag_2 = 0 'ditto...
Ux_3 = NAN
Uy_3 = NAN
Uz_3 = NAN
Ts_3 = NAN
diag_3 = 0
Ux_4 = NAN
Uy_4 = NAN
Uz_4 = NAN
Ts_4 = NAN
diag_4 = 0
'negUy_1 = NAN
'negUy_2 = NAN
'negUy_3 = NAN
'negUy_4 = NAN
' Move(sonic_1(1),4,NaN,1) 'IDK if Move() can be trusted to affect all four
' Move(sonic_2(1),4,NaN,1) 'so modified program to use brute force
' Move(sonic_3(1),4,NaN,1)
' Move(sonic_4(1),4,NaN,1)
' Move(instWS(1),4,NaN,1)
' Move(instWD(1),4,NaN,1)
' Move(negUy(1),4,NaN,1)
EndSub
'''''' PROGRAM '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PreserveVariables 'tests suggest this instruction is a massive failure. can't hurt though
BeginProg
If (NOT initialized) 'if not initialized yet
Call setDefaults 'place call to set vars to defaults
EndIf
'Attempt to open all serial ports
' Baud=9600; 10=even/7bits/1stop; 0ms Tx delay; 40byte buffer
SerialOpen(Com1,9600,10,0,40)
SerialOpen(Com2,9600,10,0,40)
SerialOpen(Com3,9600,10,0,40)
SerialOpen(Com4,9600,10,0,40)
Scan (100,mSec,5,0) 'start scans @ 10Hz, 5-scan (1/2 sec) buffer, loop forever
Call resetVars 'empty out data variables
RealTime(rTime) 'retrieve time this scan
If ( (rMinute=29 OR rMinute=59) AND rSecond=59 AND rMicroSec=900000 ) ' prior to each new half hour
FileMark(wsuWind_10hz) ' store next record in new file
EndIf
PanelTemp(panel_temp_C,250) ' measure datalogger temperature
'If ( panel_temp_C >= 30 ) ' if data logger temp exceeds 30 deg C / 85 deg F
'SW12(2,-1) ' turn on fan: set SW12 power #2 high (-1)
'EndIf
Battery(batt_V) ' measure input voltage
'Get serial data from ATI-Sx sonic
'SerialInRecord (COMPort,Dest,SyncChar,NumBytes,EndWord,NumberBytesReturned,Option)
' ComPort: Datalogger communications port
' Dest: Destination variable
' SyncChar: Synchronization character at the beginning of the record
' NumBytes: Fixed number of bytes in the record, if the number of bytes varies, use the SyncChar and EndWord to define the record
' EndWord: Record termination word
' NumberbytesReturned: Variable to hold the number of bytes in the record
' Options: 00 most recent record, do not store NAN if no record
' 01 most recent record, store NAN if no record
' 10 oldest record, do not store NAN if no record
' 11 oldest record, store NAN if no record
' SONIC COM PORT 1
SerialInRecord (Com1,son1_in_str,0,20,&H0D0A,bytes_back_1,00) 'get serial data
If (com1_used) 'if sonic is attached
MoveBytes (son1_in_parts(1),0,son1_in_str,0,5) 'parse individual values from data string
MoveBytes (son1_in_parts(2),0,son1_in_str,5,5)
MoveBytes (son1_in_parts(3),0,son1_in_str,10,5)
MoveBytes (son1_in_parts(4),0,son1_in_str,15,5)
For j = 1 To 4 'for each data byte
sonic_1(j) = son1_in_parts(j) 'Convert from a string to float
If (sonic_1(j) = -9999) 'if reported -99.99 -> axis blockage / transducer failure
sonic_1(j) = NAN
diag_1 = diag_1 + 1*10^(j-1) 'place a 1 in ones/tens/hundreds/thousands place
ElseIf ( sonic_1(j)=9999 ) 'if reported +99.99 -> data quality algorithm on; ATI threw out data
sonic_1(j) = NAN
diag_1 = diag_1 + 2*10^(j-1) 'place a 2 in ones/... place
Else 'otherwise
sonic_1(j) = sonic_1(j)/100 'Scale the ATI data.
diag_1 = NAN
EndIf
Next j
'calc horizontal WD, correct for sonic orientation, mag declination & adjust 0-360
instWD_1 = (ATN2(-1*Ux_1,-1*Uy_1)*DperR + azimuth_1 + declination) MOD 360
instWS_1 = SQR(Ux_1^2+Uy_1^2) 'calc WS
'negUy_1 = -1*Uy_1 'calc east component (-Uy)
EndIf
'SerialFlush(Com1)
' SONIC COM PORT 2
SerialInRecord (Com2,son2_in_str,0,20,&H0D0A,bytes_back_2,00) 'get serial data
If (com2_used) 'if sonic attached
MoveBytes (son2_in_parts(1),0,son2_in_str,0,5) 'parse individual values from data string
MoveBytes (son2_in_parts(2),0,son2_in_str,5,5)
MoveBytes (son2_in_parts(3),0,son2_in_str,10,5)
MoveBytes (son2_in_parts(4),0,son2_in_str,15,5)
For j = 1 To 4 'for each data byte
sonic_2(j) = son2_in_parts(j) 'Convert from a string to float
If (sonic_2(j) = -9999)
sonic_2(j) = NAN
diag_2 = diag_2 + 1*10^(j-1)
ElseIf (sonic_2(j) = 9999)
sonic_2(j) = NAN
diag_2 = diag_2 + 2*10^(j-1)
Else
sonic_2(j) = sonic_2(j)/100 'Scale the ATI data.
EndIf
Next j
'calc horizontal WD, correct for sonic orientation, mag declination & adjust 0-360
instWD_2 = (ATN2(-1*Ux_2,-1*Uy_2)*DperR + azimuth_2 + declination) MOD 360
instWS_2 = SQR(Ux_2^2+Uy_2^2) 'calc WS
'negUy_2 = -1*Uy_2 'calc east component (-Uy)
EndIf
'SerialFlush(Com2)
' SONIC COM PORT 3
SerialInRecord (Com3,son3_in_str,0,20,&H0D0A,bytes_back_3,01) 'get serial data
If (com3_used) 'if sonic attached
MoveBytes (son3_in_parts(1),0,son3_in_str,0,5) 'parse individual values from data string
MoveBytes (son3_in_parts(2),0,son3_in_str,5,5)
MoveBytes (son3_in_parts(3),0,son3_in_str,10,5)
MoveBytes (son3_in_parts(4),0,son3_in_str,15,5)
For j = 1 To 4 'for each data byte
sonic_3(j) = son3_in_parts(j) 'Convert from a string to float
If (sonic_3(j) = -9999)
sonic_3(j) = NAN
diag_3 = diag_3 + 1*10^(j-1)
ElseIf (sonic_3(j) = 9999)
sonic_3(j) = NAN
diag_3 = diag_3 + 2*10^(j-1)
Else
sonic_3(j) = sonic_3(j)/100 'Scale the ATI data.
EndIf
Next j
'calc horizontal WD, correct for sonic orientation, mag declination & adjust 0-360
instWD_3 = (ATN2(-1*Ux_3,-1*Uy_3)*DperR + azimuth_3 + declination) MOD 360
instWS_3 = SQR(Ux_3^2+Uy_3^2) 'calc WS
'negUy_3 = -1*Uy_3 'calc east component (-Uy)
EndIf
'SerialFlush(Com3)
' SONIC COM PORT 4
SerialInRecord (Com4,son4_in_str,0,20,&H0D0A,bytes_back_4,01) 'get serial data
If (com4_used) 'if sonic attached
MoveBytes (son4_in_parts(1),0,son4_in_str,0,5) 'parse individual values from data string
MoveBytes (son4_in_parts(2),0,son4_in_str,5,5)
MoveBytes (son4_in_parts(3),0,son4_in_str,10,5)
MoveBytes (son4_in_parts(4),0,son4_in_str,15,5)
For j = 1 To 4 'for each data byte
sonic_4(j) = son4_in_parts(j) 'Convert from a string to float
If (sonic_4(j) = -9999)
sonic_4(j) = NAN
diag_4 = diag_4 + 1*10^(j-1)
ElseIf (sonic_4(j) = 9999)
sonic_4(j) = NAN
diag_4 = diag_4 + 2*10^(j-1)
Else
sonic_4(j) = sonic_4(j)/100 'Scale the ATI data.
EndIf
Next j
'calc horizontal WD, correct for sonic orientation, mag declination & adjust 0-360
instWD_4 = (ATN2(-1*Ux_4,-1*Uy_4)*DperR + azimuth_4 + declination) MOD 360
instWS_4 = SQR(Ux_4^2+Uy_4^2) 'calc WS
'negUy_4 = -1*Uy_4 'calc east component (-Uy)
EndIf
'SerialFlush(Com4)
CallTable(wsuWind_10hz) 'save 10Hz data to final storage table
NextScan
EndProg
' CallTable(windVec_5min) 'perform wind direction computations
' If( windVec_5min.Output(1,1) ) Then 'if record was output
' Move(avgWind(1),24,NaN,1) 'clear array
' GetRecord(avgWind(1),windVec_5min,1) 'retrieve results into avgWind array
' 'for each attached sonic, convert from sonic coordinate system to meteorological coords
' If(com1_used)
' WDunitAvg_1 = (WDunitAvg_1 + azimuth_1 + declination + 360) MOD 360
' WDrsltAvg_1 = (WDrsltAvg_1 + azimuth_1 + declination + 360) MOD 360
' Else
' Move(avgWind(1),7,NaN,1) 'if Com1 not used, reset vars to NaN
' EndIf
' If(com2_used)
' WDunitAvg_2 = (WDunitAvg_2 + azimuth_2 + declination + 360) MOD 360
' WDrsltAvg_2 = (WDrsltAvg_2 + azimuth_2 + declination + 360) MOD 360
' Else
' Move(avgWind(8),7,NaN,1) 'if Com2 not used, fill vars with NaN
' EndIf
' If(com3_used)
' WDunitAvg_3 = (WDunitAvg_3 + azimuth_3 + declination + 360) MOD 360
' WDrsltAvg_3 = (WDrsltAvg_3 + azimuth_3 + declination + 360) MOD 360
' Else
' Move(avgWind(15),7,NaN,1) 'if Com3 not used, fill with NaN
' EndIf
' 'If(com4_used)
' ' WDunitAvg_4 = (WDunitAvg_4 + azimuth_4 + declination + 360) MOD 360
' ' WDrsltAvg_4 = (WDrsltAvg_4 + azimuth_4 + declination + 360) MOD 360
' 'Else
' ' Move(avgWind(22),7,NaN,1) 'if Com4 not used, fill with NaN
' 'EndIf
' EndIf
' CallTable(wsuWind_5min) 'save WS & adjusted WD to final storage table
' CallTable(windVec_30min) 'perform wind direction computations
' If( windVec_30min.Output(1,1) ) Then 'if record was output
' Move(avgWind(1),24,NaN,1) 'clear array again
' GetRecord(avgWind(1),windVec_30min,1) 'retrieve results into avgWind array
' 'for each attached sonic, convert from sonic coordinate system to meteorological coords
' If(com1_used)
' WDunitAvg_1 = (WDunitAvg_1 + azimuth_1 + declination + 360) MOD 360
' WDrsltAvg_1 = (WDrsltAvg_1 + azimuth_1 + declination + 360) MOD 360
' Else
' Move(avgWind(1),7,NaN,1) 'if com1 not used, fill vars with NaN
' EndIf
' If(com2_used)
' WDunitAvg_2 = (WDunitAvg_2 + azimuth_2 + declination + 360) MOD 360
' WDrsltAvg_2 = (WDrsltAvg_2 + azimuth_2 + declination + 360) MOD 360
' Else
' Move(avgWind(8),7,NaN,1) 'if com2 not used, fill with NaN
' EndIf
' If(com3_used)
' WDunitAvg_3 = (WDunitAvg_3 + azimuth_3 + declination + 360) MOD 360
' WDrsltAvg_3 = (WDrsltAvg_3 + azimuth_3 + declination + 360) MOD 360
' Else
' Move(avgWind(15),7,NaN,1) 'if com3 not used, fill with NaN
' EndIf
' 'If(com4_used)
' ' WDunitAvg_4 = (WDunitAvg_4 + azimuth_4 + declination + 360) MOD 360
' ' WDrsltAvg_4 = (WDrsltAvg_4 + azimuth_4 + declination + 360) MOD 360
' 'Else
' ' Move(avgWind(22),7,NaN,1) 'if com4 not used, fill with NaN
' 'EndIf
' EndIf
' CallTable(wsuWind_30min)