-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonitorGases_4.03.f90
1969 lines (1767 loc) · 84 KB
/
MonitorGases_4.03.f90
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Module CommParameters
! This is version 2, 18 Mar 2010
! 03 Aug 2010 Ver 2.1 Adding ability to control WeederTech DOT board.
! Added some global variables to allow for correcting for sample loop dilution.
Implicit none
!============= Define Which ports go to which equip =================
integer, parameter:: oxigrafPort = 4
integer, parameter:: ch4Port = 5
integer, parameter:: valcoPort = 6
integer, parameter:: mfmPort = 7
integer, parameter:: WTDOTport = 9 ! note port 8 has the MKS 647C controller.
!===================CHARACTER CONSTANTS===================================
CHARACTER(LEN=1), PARAMETER :: SOH = CHAR( 1)
CHARACTER(LEN=1), PARAMETER :: STX = CHAR( 2)
CHARACTER(LEN=1), PARAMETER :: ETX = CHAR( 3)
CHARACTER(LEN=1), PARAMETER :: EOT = CHAR( 4)
CHARACTER(LEN=1), PARAMETER :: ENQ = CHAR( 5)
CHARACTER(LEN=1), PARAMETER :: ACK = CHAR( 6)
CHARACTER(LEN=1), PARAMETER :: NAK = CHAR(15)
CHARACTER(LEN=1), PARAMETER :: DLE = CHAR(16)
CHARACTER(LEN=1), PARAMETER :: ESC = CHAR(27)
CHARACTER(LEN=1), PARAMETER :: CR = CHAR(13)
CHARACTER(LEN=2), PARAMETER :: crlf = CHAR(13)//CHAR(10)
! Some WeederTech WTDOT commands. These are based on which channel the WTDOT board is set to
! and what channels instruments/valves are connected to.
! These commands are for turning on or off the gas pump that circulates gases to the detectors.
character(len=3), parameter:: N2on = 'ALA' ! Set channel A on Board A to low (i.e., turn it on )
character(len=3), parameter:: N2Off = 'AHA' ! Set channel A on Board A to high (i.e., turn it off)
character(len=3), parameter:: gasPumpOn = 'ALB' ! Set channel B on Board A to low (i.e., turn it on )
character(len=3), parameter:: gasPumpOff = 'AHB' ! Set channel B on Board A to high (i.e., turn it off)
character(len=3), parameter:: feed2On = 'ALC' ! Set channel C on Board A to low (i.e., turn it on )
character(len=3), parameter:: feed2Off = 'AHC' ! Set channel C on Board A to high (i.e., turn it off)
character(len=3), parameter:: feed2Stat = 'ARC' ! Read channel C on Board A
character(len=3), parameter:: feed2L = 'ACL' ! On board A, Channel C is Low (response to ARC)
character(len=3), parameter:: feed2H = 'ACH' ! On board A, Channel C is High (response to ARC)
character(len=3), parameter:: f2SmpOn = 'ALD' ! Set channel D on Board A to low (i.e., turn it on )
character(len=3), parameter:: f2SmpOff = 'AHD' ! Set channel D on Board A to high (i.e., turn it off)
!================== Other parameters
real, parameter:: badRead = -9.99 ! values to use for bad port reads.
real sampleTime ! Time to spend sampling one reactor (min). This is needed to purge detectors, etc.
real loopTime ! How often to intitiate a complete sampling (min). This is entered as hours, but converted to nearist min.
! loopTime > sampleTime*(nMCports+2)
integer, parameter:: infoUnit=100, datUnit=101, rcvUnit=102 ! unit numbers for *.info, *.dat and *.rcv files.
integer, parameter:: onOffUnit = 103 ! file that has times of FeedGas On and Off cycling
integer, parameter:: maxNoPorts = 10 !Current number of sample ports on Valco Valve.
character*15, parameter:: okDigits = '+-0123456789. ,'
real co2Feed, o2Feed, ch4Feed ! Concentrations of feed gas
real o2Adj, co2Adj, ch4Adj !
integer noteFlag ! Is set to 1 when new note is entered.
! Version 3.0 additions
logical gasCycleRunning ! If true, then the gasCycling of feed 2 is currently running.
logical Feed2GasOn ! current state of feed 2 gas valve
real co2Feed2, o2Feed2, ch4Feed2 ! Concentrations of feed gas 2
real co2Feed2cur, o2Feed2cur, ch4Feed2cur ! Current concentrations of feed gas 2 depending on valve position
integer noteCnt ! moved to here
real(8) tzero, t0GasCycling
real(8) tCycleOnOff ! Every tCycleOnOff days, Feed gas is switched between feed gas 1 or 2.
integer ncycledPorts, cycledPorts(maxNoPorts) ! Which MCs have the feed gas cycled
character filename*80
real(8) MCheadSpaceVol(maxNoPorts), SLvol
real(8) SL_O2, SL_CO2, SL_CH4, SL_o2_new, SL_co2_new, SL_ch4_new ! concentrations of these gases in the sample loop.
integer mixtankPort ! port that is used to sample mix-tank composition
integer mixtankVentPort ! Port that is connected to the VENT of the mix-tank
integer feed2GasPort ! Port that is used to sample the feed2Gas composition. Note, must open gas value to do so.
real(8) SLpurgeTime ! How long sample loop needs to be purged with the mix-tank vent gas (min).
integer MCports(maxNoPorts), nMCports ! Contains how many MCs to sample (not including mix-tank and
! feed 2 gas port.
character debugStr*1024, tempStr*1024 ! just using for debugging
namelist /recovery/ o2Feed, co2Feed, ch4Feed, sampleTime, loopTime
namelist /recovery/ tcycleOnOff, gasCycleRunning, ncycledPorts, cycledPorts, o2Feed2, co2Feed2, ch4Feed2
namelist /recovery/ tzero, noteCnt, t0GasCycling, MCheadSpaceVol, SLvol, mixtankVentPort, SLpurgeTime
namelist /recovery/ MCports, nMCports, mixtankPort, feed2GasPort
contains
subroutine writeRecovery
! This routine writes recovery info
open(unit=rcvUnit,file=trim(filename)//'.rcv',status='unknown')
write(rcvUnit,nml=recovery)
close(unit=rcvUnit)
return
end subroutine writeRecovery
subroutine readRecovery
! This routine reads the recovery info
open(unit=rcvUnit,file=trim(filename)//'.rcv',status='old')
read(rcvUnit,nml=recovery)
close(unit=rcvUnit)
return
end subroutine readRecovery
End Module CommParameters
Program MonitorGases
! This Program is used to monitor the gass composition for the bioreactor setup.
! Versions
! 15 May 05 1.0 First writing to read multiple ports for actual equipment
! 23 Jun 05 1.01 Fixed serial port problem with sbits
! 18 Aug 05 1.02 Added more purging of serial port data.
! 23 Sep 05 1.03 Just have purge time now. Also look at menu control more often.
! 11 Oct 05 1.04 Problem getting valco port to switch following calibration
! 12 Jan 06 1.05 Modify program so that it also samples feed gas as well as microcosm exit gas
! Also, values are displayed every 10 sec instead of just when storred.
! 3 Jul 08 1.06 Modify time output format so that > 1000 days can be handelled.
! Note, this is being compilter with Intel Fortran...
! 19 Nov 09 1.07 Attempt to sample anayzers repeatively so as to obtain values
! with lower noise.
! 20 Mar 10 1.08 Adding ability to record gas analyzer values in a separate file. This
! will allow easier determination of CH4/Air mix concentration that is now
! being controlled by the MKS mass flow controllers (or will be soon). Also
! will try to improve analyzer readings by averaging reads.
! 25 Jun 10 1.09 Modified readCH4 so that an error returned in a read does not cause the
! data to be lost (i.e., reported as -9.99).
! 03 Aug 10 2.0 Modifying the code to allow a new gas sampling loop that includes a gas
! pump that requires turning on and off. Also, code will also be added
! to allow the switching on and off a secondary feed for the ATB experiment.
! 06 Aug 10 2.01 Added ASCO valve to control N2 on an added code to do so.
! 18 Aug 10 3.0 Adding ability to cycle gasses on user specified reactors, also added recovery file.
! 01 Sep 10 3.01 Added ability to execute batch file to update web page followind data save.
! 10 Sep 10 3.02 Option to turn pump off/on during gas monitoring option 4.
! Set valco value to port that is connected to the exit of the gas-mix tank.
! 11 Sep 10 3.03 Accounting for dilution of MC head space gas by sample loop.
! 12 Sep 10 3.04 More options regarding sample loop purging
! 13 Sep 10 4.0 Moved all routines to one file so that file versions are easier to handle.
! Changed loop and data file to allow for feed gas 2 sampling and saving to dat file
! Microcosm sample order now depends on state of feed gas 2 status.
! Allow feed gas 2 to be sampled with control via ASCO on/off valve.
! 30 Sep 10 4.01 Fixed problem with invalid filename causing program to crash in menu option 4.
! 15 Mar 11 4.02 Changed gas cycling so that feed gas 2 is on for even days and off for odd.
! This way, feed 2 will be turned on as soon as gas cycling is started if no
! delay is given to the start of cycling.
! 15 May 12 4.03 Modified call to "system" for exporting images so that it does not wait for cmd to return
!
! Notes for next version
! 1. Have gas mixture composition print in notes info (done V. 2.0)
use ifport
use ifwin
use ifWINTY
use ifcore
use CommParameters
implicit None
integer iresult, i, j, portNo, byteCnt, ok2read
integer dt(8), ifail, optNo, cntrl
real(8) datavec(maxNoPorts,21), beginT, endT, loopStartT, loopCurT, loopMin
character formStr*80, key*1, lineRead*80, tecStr*1000, longStr*120, version*20, ptN*2
logical keyHit, infoExists, datExists, rcvExists, getOpt, testing
! Declarations with Version 3.0 and above
real(8) eltime, t2cycle
logical saveData, OnOffExists
character outStr*80, onoff*3
integer irow
real(8) purgeTime, purgeTime0
integer iports(maxNoPorts), nports
! Data declarations for console cursor access
integer fhandle
logical logstat
Type(T_CONSOLE_SCREEN_BUFFER_INFO) conbuf
Type (T_COORD) dwCursorPosition
! Program version
version = '4.03 (15 May 2012)'
! Get the handle of the console
fhandle = GetStdHandle(STD_OUTPUT_HANDLE)
! Get name to label data files
write(6,'(a)') 'Program Version: '//version
write(6,'(a,$)') 'Enter file name for data (no extension): '
read(5,'(a)') filename
! Four files are used:
! filename.info contains information (notes) about the run
! filename.dat Contains the collected data.
! If either files already exists, then data is appended (allows for restarts)
! filename.rcv Contains all the user entered data to restart program.
! filename.OnOff Contains the times when feed gas swiching occurs. It may not be used, but will be created.
! See if the files exist
inquire(file=trim(filename)//'.info' ,exist=infoExists)
inquire(file=trim(filename)//'.dat' ,exist=datExists)
inquire(file=trim(filename)//'.rcv' ,exist=rcvExists)
inquire(file=trim(filename)//'.OnOff',exist=OnOffExists)
!open files
if (infoExists) then
write(6,*) ' **Warning**: file: ',trim(filename)//'.info',' exits. Will append data'
open(unit=infoUnit,file=trim(filename)//'.info',status='old',access='append')
else
open(unit=infoUnit,file=trim(filename)//'.info',status='new')
end if
if (datExists) then
write(6,*) ' **Warning**: file: ',trim(filename)//'.dat',' exits. Will append data'
open(unit=datUnit,file=trim(filename)//'.dat',status='old',access='append')
else
open(unit=datUnit,file=trim(filename)//'.dat',status='new')
end if
if (OnOffExists) then
write(6,*) ' **Warning**: file: ',trim(filename)//'.OnOff',' exits. Will append data'
open(unit=onOffUnit,file=trim(filename)//'.OnOff',status='old',access='append')
else
open(unit=onOffUnit,file=trim(filename)//'.OnOff',status='new')
end if
! Setup com ports
call initializePorts()
! Initialize the gas analyzer offsets (only needed if not sampling feed gas)
o2Adj = 0.0; co2Adj = 0.0; ch4Adj = 0.0
feed2GasPort = 0 ! initialze to zero if not using.
! See if a recovery file exists
if (rcvExists) then
write(6,'(a,$)') 'Recovery file found! Do you wish to use it (y/n) ?'
read(5,'(a)') lineRead
if (scan(lineRead,'yY') /= 0) then
call readRecovery
else
call getProgramRunParams
end if
else
call getProgramRunParams
end if
! Regardless of whether gas cycling is on or not, get status of valve
call writeWeederT(feed2Stat)
! get responce, which should equal feed2L
call readWeederT(outStr)
if (outStr == feed2L) then
Feed2GasOn = .true.
else if (outStr == feed2H) then
Feed2GasOn = .false.
else
write(6,'(a)') 'WARNING:: could not obtain status of feed gas 2 valve'
write(6,'(2a)') 'WTDOT Output response was: ',trim(outStr)
write(6,'(a)') 'Setting Feed2GasOn state to false'
Feed2GasOn = .false. ! just set to off then
end if
if (feed2GasOn .and. (.not. gasCycleRunning) ) then
write(6,'(a)') 'WARNING:: Feed 2 gas valve is on, but gasCycleRunning is false'
write(6,'(a)') ' Will attempt to turn feed gas 2 valve off...'
call writeWeederT(feed2Off)
! get responce, which should just be the return of command
call readWeederT(outStr)
if (outStr /= feed2Off) then
write(6,'(a)') 'WARNING:: Failed to turn Feed 2 Gas off!'
write(6,'(2a)') 'WTDOT Output response was: ',trim(outStr)
end if
end if
! Alow users to enter info about run:
call DATE_AND_TIME (values=dt)
write(infoUnit,'(a)') 'Program Version: '//version
write(infoUnit,'(2(a,i2.2),a,i4,3(a,i2.2))') 'Program Started: ',dt(2),'/',dt(3),'/',dt(1),' ',dt(5),':',dt(6),':',dt(7)
write(infoUnit,'(a,i2)') 'Mix-tank sample port: ', mixtankPort
write(infoUnit,'(a,i2)') 'Mix-tank vent port: ', mixtankVentPort
write(infoUnit,'(a,6(x,i1))') 'Microcosm ports: ',(MCports(i),i=1,nMCports)
write(infoUnit,'(a,f5.1)') 'Sample loop purge time (min): ', SLpurgeTime
write(infoUnit,'(a,f5.2)') 'Sample time (min): ', sampleTime
write(infoUnit,'(a,f5.2)') 'Loop time (hr): ', loopTime/60.0
write(infoUnit,'(a,f6.2)') 'O2 feed (%): ', o2Feed
write(infoUnit,'(a,f6.2)') 'CO2 feed (%): ', co2Feed
write(infoUnit,'(a,f6.2)') 'CH4 feed (%): ', ch4Feed
if (gasCycleRunning) then
write(infoUnit,'(a,6(1x,i1))') 'The following MCs have been configured to have feed gas cycling:', (cycledPorts(i),i=1,ncycledPorts)
write(infoUnit,'(a,f5.2,a)') 'Feed gas will be cycled every ', tCycleOnOff,' days.'
write(infoUnit,'(a,i2)') 'Feed gas 2 port: ', feed2GasPort
write(infoUnit,'(a,f6.2)') 'O2 feed 2 (%): ', o2Feed2
write(infoUnit,'(a,f6.2)') 'CO2 feed 2 (%): ', co2Feed2
write(infoUnit,'(a,f6.2)') 'CH4 feed 2 (%): ', ch4Feed2
end if
write(infoUnit,'(a)') '--------------------------- Experiment Description ----------------------------'
write(6,'(a)') 'Enter description of experiment. Blank line terminates entry.'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
! Write tecplot header if this is a new data file
if (.not. datExists) then
tecStr = 'Variables = "M" "D" "Y" "Hr" "Min" "Sec" "O2 Feed" "CO2 Feed" "CH4 Feed" "O2 Feed 2" "CO2 Feed 2" "CH4 Feed 2"'
longStr = ' "Time ## (d)" "Port ##" "Flow ## (sccm)" "O2r ## (%)" "O2 ## (%)" "CO2r ## (%)" "CO2 ## (%)" "CH4r ## (%)" "CH4 ## (%)"'
! Must have space for sampling mix tank and feed gas 2, even if not used.
do i=1,2
ptN = 'F'//char(48+i)
longStr(8:9) = ptN ! Time
longStr(22:23) = ptN ! Port
longStr(32:33) = ptN ! Flow
longStr(48:49) = ptN ! O2r
longStr(60:61) = ptN ! O2
longStr(74:75) = ptN ! CO2r
longStr(87:88) = ptN ! CO2
longStr(101:102) = ptN ! CH4r
longStr(114:115) = ptN ! CH4
tecStr = trim(tecStr)//longStr
end do
do i=1,nMCports
ptN = 'M'//char(48+i)
longStr(8:9) = ptN ! Time
longStr(22:23) = ptN ! Port
longStr(32:33) = ptN ! Flow
longStr(48:49) = ptN ! O2r
longStr(60:61) = ptN ! O2
longStr(74:75) = ptN ! CO2r
longStr(87:88) = ptN ! CO2
longStr(101:102) = ptN ! CH4r
longStr(114:115) = ptN ! CH4
tecStr = trim(tecStr)//longStr
end do
tecStr = trim(tecStr)//' "Notes"'
write(datUnit,'(a)') tecStr
write(datUnit,'(a)') 'Zone'
end if
! Store the input info in a recovery file
call writeRecovery
! ------------------------------------------------------
! -------------- Begin Test loop ---------------------
! ------------------------------------------------------
write(6,'(a,$)') 'Do you want to test gas sampling loop hardware/software? (y/n): '
read(5,'(a)') lineRead
testing = .false.
if (scan(lineRead,'yY') /= 0) testing = .true.
call setIports (iports, nports, Feed2GasOn)
do while (testing)
Write(6,'(a)') 'Running test reads...'
call pumpOn ()
write(6,'(a)') 'Gas pump should be on, check flow'
do i=1,nports
! Set the valve to position 1 to nports
portNo = iports(i)
Call valcoControl(portNo)
call convPort2data (portNo, irow) ! row in datavec that the port correspond to.
datavec(irow,14) = dble(portNo)
call readGasAnalyzers (portNo,datavec(irow,:),tzero,.true.)
longStr = '(2(i2.2,''/''),i4,1x,2(i2.2,'':''),i2.2,1x,i2,##x,f6.2,6x,f6.2,6x,f7.3,6x,f8.4)'
write(longStr(43:44),'(i2)') 2*(i-1)+1
write(6,longStr) (int(datavec(irow,j)),j=1,6), int(datavec(irow,14)), real(datavec(irow,15)), (real(datavec(irow,j)),j=17,21,2)
end do
call pumpOff ()
write(6,'(a)') 'Gas pump should be off, check flow'
write(6,'(a)') 'Done with test reads.'
write(6,'(a$)') 'Run test reads again? (y/n): '
read(5,'(a)') lineRead
testing = .false.
if (scan(lineRead,'yY') /= 0) testing = .true.
end do
Write(6,'(a)') 'Sampling begining...'
write(6,'(a)') 'Hit ESC at anytime to bring up Menu.'
! ------------------------------------------------------
! -------------- Begin Sample loop ---------------------
! ------------------------------------------------------
noteFlag = 0
call pumpOff () ! make sure pump is off
portNo = mixtankVentPort
Call valcoControl(portNo) ! Move to valvo port connected to mix-tank VENT
datavec(portNo,14) = dble(portNo)
purgeTime0 = RTC() ! Start the clock on the purging of the sample loop with vent gas
sampling: do
call f2SampleGasOff ! make sure feed 2 gas sample valve is closed.
! Make sure sample loop has been purged with vent gas for at least SLpurgeTime amount of time.
purgeTime = (RTC() - purgeTime0)/60.0 ! time that sample loop as been purged in min.
do while (purgeTime < SLpurgeTime)
purgeTime = (RTC() - purgeTime0)/60.0
! get the cursor position
logstat = GetConsoleScreenBufferInfo(fhandle, conbuf)
call readGasAnalyzers (portNo,datavec(portNo,:),tzero,.true.)
longStr = '(''At: '',2(i2.2,'':''),i2.2,'' Port: '',i3,'' Flow: '',f6.2,'' O2: '',f6.2,'' CO2: '',f7.3,'' CH4: '',f8.4)'
write(6,longStr) (int(datavec(portNo,j)),j=4,6), int(datavec(portNo,14)), real(datavec(portNo,15)), (real(datavec(portNo,j)),j=17,21,2)
write(6,'(a,f5.1,a)') 'Need to wait ',SLpurgeTime-purgeTime,' min. for sample loop purge. ESC to skip.'
! put the cursor back to where it was
logstat = SetConsoleCursorPosition(fhandle, conbuf.dwCursorPosition)
call SLEEPQQ (10000) ! Sleep for 10 sec.
! See if ESC key was hit
keyHit = PEEKCHARQQ ( )
if (keyHit) then
!See if key hit is ESC, if so exit.
key = GETCHARQQ( )
if (key == ESC) then
write(6,'(//a,$)') 'Do you want to skip sample loop purge? (y/n): '
read(5,'(a)') lineRead
if (scan(lineRead,'yY') /= 0) exit
end if
end if
end do
call cycleFeedGas2 ! set feed 2 gas valve position if using.
! Determine which ports to sample depending state of Feed2Gas valve
call setIports (iports, nports, Feed2GasOn)
portNo = iports(1)
Call valcoControl(portNo) ! Move to mix-tank sample port
! turn gas pump on
call pumpOn ()
saveData = .true.
loopStartT = RTC() ! marks the time, in sec, that a sampling loop started
readPort: do i=1,nports
! Set the valve to position 1 to nports
portNo = iports(i)
Call valcoControl(portNo)
call convPort2data (portNo, irow) ! row in datavec that the port correspond to.
if (portNo == feed2GasPort) call f2SampleGasOn ! open valve to sample feed 2 gas.
datavec(irow,14) = dble(portNo)
datavec(irow,7) = o2Feed
datavec(irow,8) = co2Feed
datavec(irow,9) = ch4Feed
datavec(irow,10) = o2Feed2cur
datavec(irow,11) = co2Feed2cur
datavec(irow,12) = ch4Feed2cur
! Now wait sufficient time for system to be flushed (purgeTime)
! Get time in seconds since 1970
beginT = RTC()
wait: do
! Sleepy sleep for 10 sec.
call SLEEPQQ (10000)
! See if ESC key was hit
keyHit = PEEKCHARQQ ( )
if (keyHit) then
!See if key hit is ESC, if is so exit.
key = GETCHARQQ( )
if (key == ESC) then
call pumpOff () ! turn pump off while in menu.
call shortMenu(noteCnt, cntrl)
select case (cntrl)
case(1) ! just continue sampling port like nothing happened.
call pumpOn () ! turn pump on and return to sampling.
case(2) ! restart readPort sample loop, do not save anything
purgeTime0 = RTC() ! Assume sample loop got contaminated
cycle sampling
case(3) ! exit readPort sample loop, do not save anything
saveData = .false.
exit readPort
case(9) ! exit program
write(6,'(a,$)') 'Exit program? (y/n): '
read(5,'(a)') lineRead
if (scan(lineRead,'yY') /= 0) exit sampling
call pumpOn () ! turn pump on and return to sampling.
end select ! if neither case is selected, just continue sampling port
end if
end if
endT = RTC()
if ( (endT-beginT)/60. >= sampleTime ) exit wait
! ok, just print update, but don't store.
call readGasAnalyzers (portNo,datavec(irow,:),tzero,.false.)
! get the cursor position
logstat = GetConsoleScreenBufferInfo(fhandle, conbuf)
! write current reading out at the same location
longStr = '(''Purge t:'',f4.1,,'' min'','' Port:'',i2,'' Flow: '',f6.2,'' O2:'',f6.2,'' CO2:'',f7.3,'' CH4:'',f8.4)'
write(6,longStr) (endT-beginT)/60., int(datavec(irow,14)), real(datavec(irow,15)), (real(datavec(irow,j)),j=17,21,2)
! put the cursor back to where it was
logstat = SetConsoleCursorPosition(fhandle, conbuf.dwCursorPosition)
end do wait
call readGasAnalyzers (portNo,datavec(irow,:),tzero,.false.)
if (portNo == feed2GasPort) call f2SampleGasOff ! close valve to sample feed 2 gas.
longStr = '(2(i2.2,''/''),i4,1x,2(i2.2,'':''),i2.2,1x,i2,##x,f6.2,6x,f6.2,6x,f7.3,6x,f8.4)'
write(longStr(43:44),'(i2)') 2*(i-1)+1
formStr = ' '
write(formStr,longStr) (int(datavec(irow,j)),j=1,6), int(datavec(irow,14)), real(datavec(irow,15)), (real(datavec(irow,j)),j=17,21,2)
write(6,'(a)') formStr(1:79)
! Set the concentration of the gases in the sample loop to the current measured value
SL_o2 = SL_o2_new; SL_co2 = SL_co2_new; SL_ch4 = SL_ch4_new
end do readPort
! Turn gas pump off
call pumpOff ()
call f2SampleGasOff ! make sure feed 2 sample valve is off
! Store data in *.dat file (designed for Tecplot read)
if (saveData) then
! Feed gas 2 was not sampled, then just copy info from main feed sampling
if (.not. Feed2GasOn) datavec(2,:) = datavec(1,:)
longStr = '(2(f3.0,1x),f5.0,3(1x,f3.0),6(1x,f7.4),#(1x,f10.5,1x,f4.0,3(1x,f6.2),2(1x,f7.3),2(1x,f8.4),1x),i3)'
write(longStr(40:40),'(i1)') nMCports+2
write(datUnit,longStr) (datavec(1,j),j=1,12), ((datavec(i,j),j=13,21),i=1,nMCports+2), noteCnt*noteFlag
noteFlag = 0
! Generate tecplot images for web page by calling dos command batch file.
! iresult = system('exportImages.bat > exportImages.txt')
iresult = system('start "ExportImages" cmd /C exportImages.bat') ! this allows the program to return without waiting.
end if
! Now wait loopTime until time to begin next total sampling
purgeTime0 = RTC() ! Start the clock on the purging of the sample loop with vent gas
loopWait: do
! make sure that the gas-mix tank is purging the sample loop.
portNo = mixtankVentPort ! port connected to exit of gas mix tank
Call valcoControl(portNo)
datavec(portNo,14) = dble(portNo)
call cycleFeedGas2 ! set feed 2 gas valve position if using.
loopCurT = RTC() ! get current time, in sec, and check loop time.
loopMin = (loopCurT-loopStartT)/60.0
if ( loopMin >= loopTime ) exit loopWait
! get the cursor position
logstat = GetConsoleScreenBufferInfo(fhandle, conbuf)
call readGasAnalyzers (portNo,datavec(portNo,:),tzero,.true.)
longStr = '(''At: '',2(i2.2,'':''),i2.2,'' Port: '',i3,'' Flow: '',f6.2,'' O2: '',f6.2,'' CO2: '',f7.3,'' CH4: '',f8.4)'
write(6,longStr) (int(datavec(portNo,j)),j=4,6), int(datavec(portNo,14)), real(datavec(portNo,15)), (real(datavec(portNo,j)),j=17,21,2)
write(6,'(a,f7.2,a)') 'Time to next sampling: ',loopTime-loopMin, &
' (min). Hit ESC for LONG menu'
if (gasCycleRunning) then
if (Feed2GasOn) then
onoff = ' on'
else
onoff = 'off'
end if
call DATE_AND_TIME (values=dt)
call julday(dt(1),dt(2),dt(3),dt(5),dt(6),real(dt(7)),eltime,ifail)
eltime = eltime - t0GasCycling ! elapsed time in days since start of gas cycling
t2cycle = tcycleOnOff - mod(eltime,tcycleOnOff)
write(6,'(3a,f6.3,a)') 'Gas feed 2 valve is ', onoff,'. Valve cycle in ',t2cycle,' days.'
end if
logstat = SetConsoleCursorPosition(fhandle, conbuf.dwCursorPosition)
! Sleepy sleep for 10 sec.
call SLEEPQQ (10000)
! See if ESC key was hit
keyHit = PEEKCHARQQ ( )
if (keyHit) then
!See if key hit is ESC, if is so exit.
key = GETCHARQQ( )
if (key == ESC) then
call longMenu(noteCnt, cntrl)
select case (cntrl)
case(1) ! just continue sampling port like nothing happened.
cycle loopWait
case(2) ! restart sample loop BEFORE loopTime has expired
exit loopWait
case(3) ! Get new feed gas concentrations, but continue to wait
cycle loopWait
case(4) ! Record gas analyzer data, but continue to wait on return.
purgeTime0 = RTC() ! Assume sample loop got contaminated
cycle loopWait
case(5) ! Turn gas cycling on, but continue to wait.
cycle loopWait
case(6) ! Turn gas cycling off, but continue to wait.
cycle loopWait
case(7) ! Test feed gas cycling valve, but continue to wait.
cycle loopWait
case(8) ! Enter note, but continue to wait.
cycle loopWait
case(9) ! Get new headspace gas volumes, but continue to wait.
cycle loopWait
case(10) ! exit program
write(6,'(a,$)') 'Exit program? (y/n): '
read(5,'(a)') lineRead
if (scan(lineRead,'yY') /= 0) exit sampling
cycle loopWait
end select ! if no case is selected, just continue to wait (shouldn't happen)
end if
end if
end do loopWait
end do sampling
! ------------------------------------------------------
! -------------- End Main Sampling Loop -----------------
! ------------------------------------------------------
! make sure pump is off and feed 2 sample valve is closed.
! however, leave the feed gas switcing valve unchanged.
! place valco port onto purging with vent gas
call pumpOff ()
call f2SampleGasOff
portNo = mixtankVentPort
Call valcoControl(portNo) ! Move to valvo port connected to mix-tank VENT
! Let user know status of port before leaving program.
call writeWeederT(feed2Stat)
! get responce, which should just be the return of command
call readWeederT(outStr)
if (outStr == feed2L) then
write(6,'(/a)') 'NOTE: feed gas 2 valve is ON'
else if (outStr == feed2H) then
write(6,'(/a)') 'NOTE: feed gas 2 valve is OFF'
else
write(6,'(/a)') 'WARNING:: could not obtain status of feed gas 2 valve'
write(6,'(2a)') ' WTDOT Output response was: ',trim(outStr)
write(6,'(a)') ' You should check valve status manualy!'
Feed2GasOn = .false. ! just set to off then
end if
! Release all the ports
iresult = SPORT_RELEASE (oxigrafPort)
iresult = SPORT_RELEASE (ch4Port )
iresult = SPORT_RELEASE (valcoPort )
iresult = SPORT_RELEASE (mfmPort )
iresult = SPORT_RELEASE (WTDOTport )
! Although recovery file should be up to date, write anyway
call writeRecovery
close(unit=infoUnit)
close(unit=datUnit )
close(unit=onOffUnit )
stop
end program MonitorGases
subroutine shortMenu(noteCnt, optNo)
use DFLIB
use CommParameters, only: noteFlag, infoUnit, o2Feed, co2Feed, ch4Feed, gasCycleRunning, &
o2Feed2, co2Feed2, ch4Feed2, ncycledPorts, cycledPorts, tCycleOnOff, &
feed2Off, feed2On
implicit none
integer noteCnt, optNo
! Local declarations
integer dt(8), input
logical getOpt
character formStr*80, lineRead*80, outStr*80
CALL BEEPQQ(1000, 2000)
getOpt = .true.
opt: do while (getOpt)
write(6,'(/)')
write(6,'(a)') 'Sampling Paused; Options:'
write(6,'(a)') ' 1. Return to sampling.'
write(6,'(a)') ' 2. Restart sample loop imediately after entering a note.'
write(6,'(a)') ' 3. Exit current sampling w/o saving this data point.'
write(6,'(a)') ' 9. Exit program.'
read(5,*) optNo
select case (optNo)
case(1) ! Just return like nothing happened.
write(6,*) ' Returning to sampling, press ESC for menu'
write(6,*) ' '
getOpt = .false.
case(2) ! Restart sample loop and the entering of a note
noteCnt = noteCnt + 1
noteFlag = 1
call DATE_AND_TIME (values=dt)
write(formStr,'(2(a,i2.2),a,i4,3(a,i2.2),a)') &
' (',int(dt(2)),'/',int(dt(3)),'/',int(dt(1)),' ',int(dt(5)),':',int(dt(6)),':',int(dt(7)),')'
write(infoUnit,'(a,i3,a)') 'Note Number: ',noteCnt,trim(formStr)
write(6,'(a,i3)') 'Enter description for Note: ',noteCnt
write(6,'(a)') 'Enter blank line to return to sampling (calibrate before returning)'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
getOpt = .false.
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(3)
write(6,*) ' Returning to sampling, press ESC for menu'
write(6,*) ' '
getOpt = .false.
case(9)
write(6,*) ' Exiting program.'
getOpt = .false.
case default
write(6,*) ' ** Option not recognized, try again **'
end select
end do opt
return
end subroutine shortMenu
subroutine longMenu(noteCnt, optNo)
use DFLIB
use CommParameters, only: noteFlag, infoUnit, o2Feed, co2Feed, ch4Feed, gasCycleRunning, &
o2Feed2, co2Feed2, ch4Feed2, ncycledPorts, cycledPorts, tCycleOnOff, &
feed2Off, feed2On, writeRecovery, o2Feed2Cur, co2Feed2Cur, ch4Feed2Cur, &
feed2GasPort, MCheadSpaceVol, SLvol, nMCports
implicit none
integer noteCnt, optNo
! Local declarations
integer dt(8), input, i
logical getOpt
character formStr*80, lineRead*80, outStr*80
CALL BEEPQQ(1000, 2000)
getOpt = .true.
opt: do while (getOpt)
write(6,'(//)')
write(6,'(a)') 'Sampling Paused; Options:'
write(6,'(a)') ' 1. Return to sampling.'
write(6,'(a)') ' 2. Restart sample loop IMMEDIATELY after entering a note.'
write(6,'(a)') ' 3. Enter new feed gas conc. and note.'
write(6,'(a)') ' 4. Begin recording gas analyzer readings.'
write(6,'(a)') ' 5. Begin gas cycling with Feed 2.'
write(6,'(a)') ' 6. End gas cycling of Feed 2.'
write(6,'(a)') ' 7. Test feed gas cycling valve.'
write(6,'(a)') ' 8. Enter a note, but continue to wait for next sample event.'
write(6,'(a)') ' 9. Enter new microcosm headspace gas volumes.'
write(6,'(a)') ' 10. Exit program'
read(5,*) optNo
select case (optNo)
case(1)
write(6,*) ' Returning to sampling, press ESC for menu'
write(6,*) ' '
getOpt = .false.
case(2)
! Enter a note and start sampling MCs imediatly on return.
noteCnt = noteCnt + 1
noteFlag = 1
call DATE_AND_TIME (values=dt)
write(formStr,'(2(a,i2.2),a,i4,3(a,i2.2),a)') &
' (',int(dt(2)),'/',int(dt(3)),'/',int(dt(1)),' ',int(dt(5)),':',int(dt(6)),':',int(dt(7)),')'
write(infoUnit,'(a,i3,a)') 'Note Number: ',noteCnt,trim(formStr)
write(6,'(a,i3)') 'Enter description for Note: ',noteCnt
write(6,'(a)') 'Enter blank line to return to sampling (calibrate before returning)'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
getOpt = .false.
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(3)
noteCnt = noteCnt + 1
noteFlag = 1
! Get concentrations of feed gas
write(6,'(a)') 'Enter feed gas concentrations:'
write(6,'(a,$)') 'O2 (%): '
read(5,*) o2Feed
write(6,'(a,$)') 'CO2 (%): '
read(5,*) co2Feed
write(6,'(a,$)') 'CH4 (%): '
read(5,*) ch4Feed
if (gasCycleRunning) then
write(6,'(a)') 'Enter feed 2 gas concentrations:'
write(6,'(a,$)') 'O2 (%): '
read(5,*) o2Feed2
write(6,'(a,$)') 'CO2 (%): '
read(5,*) co2Feed2
write(6,'(a,$)') 'CH4 (%): '
read(5,*) ch4Feed2
end if
call DATE_AND_TIME (values=dt)
write(formStr,'(2(a,i2.2),a,i4,3(a,i2.2),a)') &
' (',int(dt(2)),'/',int(dt(3)),'/',int(dt(1)),' ',int(dt(5)),':',int(dt(6)),':',int(dt(7)),')'
write(infoUnit,'(a,i3,a)') 'Note Number: ',noteCnt,trim(formStr)
write(infoUnit,'(a)' ) 'New feed gas composition entered:'
write(infoUnit,'(a,f6.2)') ' O2 feed (%): ', o2Feed
write(infoUnit,'(a,f6.2)') ' CO2 feed (%): ', co2Feed
write(infoUnit,'(a,f6.2)') ' CH4 feed (%): ', ch4Feed
if (gasCycleRunning) then
write(infoUnit,'(a)') 'New feed 2 gas composition entered:'
write(infoUnit,'(a,f6.2)') ' O2 feed 2 (%): ', o2Feed2
write(infoUnit,'(a,f6.2)') ' CO2 feed 2 (%): ', co2Feed2
write(infoUnit,'(a,f6.2)') ' CH4 feed 2 (%): ', ch4Feed2
end if
write(6,'(a,i3)') 'Enter description for Note: ',noteCnt
write(6,'(a)') 'Enter blank line to return to sampling (calibrate before returning)'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
getOpt = .false.
call writeRecovery ! update recovery file
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(4) ! Save gas anlyzer data to a specified file
call readAndStoreAnalzers (1)
write(6,'(/,a)') ' ** Returing to sampling, press ESC for menu'
getOpt = .false.
case(5) ! Begin cycling of feed gas 2
noteCnt = noteCnt + 1
noteFlag = 1
gasCycleRunning = .true.
call gasCyclingParams
call DATE_AND_TIME (values=dt)
write(formStr,'(2(a,i2.2),a,i4,3(a,i2.2),a)') &
' (',int(dt(2)),'/',int(dt(3)),'/',int(dt(1)),' ',int(dt(5)),':',int(dt(6)),':',int(dt(7)),')'
write(infoUnit,'(a,i3,a)') 'Note Number: ',noteCnt,trim(formStr)
write(infoUnit,'(a,6(1x,i1))') 'The following MCs have been configured to have feed gas cycling:' &
, (cycledPorts(i),i=1,ncycledPorts)
write(infoUnit,'(a,f5.2,a)') 'Feed gas will be cycled every ', tCycleOnOff,' days.'
write(infoUnit,'(a,i2)') 'Feed gas 2 port: ', feed2GasPort
write(infoUnit,'(a,f6.2)') 'O2 feed 2 (%): ', o2Feed2
write(infoUnit,'(a,f6.2)') 'CO2 feed 2 (%): ', co2Feed2
write(infoUnit,'(a,f6.2)') 'CH4 feed 2 (%): ', ch4Feed2
write(6,'(a,i3)') 'Enter description for Note: ',noteCnt
write(6,'(a)') 'Enter blank line to return to sampling (calibrate before returning)'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
getOpt = .false.
call writeRecovery ! update recovery file
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(6) ! Stop gas cycling
noteCnt = noteCnt + 1
noteFlag = 1
gasCycleRunning = .false.
! Make sure valve if off
call forceFeedGas2Valve (0)
! Add a note.
call DATE_AND_TIME (values=dt)
write(formStr,'(2(a,i2.2),a,i4,3(a,i2.2),a)') &
' (',int(dt(2)),'/',int(dt(3)),'/',int(dt(1)),' ',int(dt(5)),':',int(dt(6)),':',int(dt(7)),')'
write(infoUnit,'(a,i3,a)') 'Note Number: ',noteCnt,trim(formStr)
write(infoUnit,'(a)') ' Gas cycling of feed 2 turned off'
write(6,'(a,i3)') 'Enter description for Note: ',noteCnt
write(6,'(a)') 'Enter blank line to return to sampling (calibrate before returning)'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
getOpt = .false.
call writeRecovery ! update recovery file
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(7) ! Test feed cycling valve
write(6,'(a)') 'If gas cycling is ON, the valve status will revert to what it was on return.'
write(6,'(a)') 'But, if gas cycling is OFF, valve retains state on return to sampling!!'
do
write(6,'(a,$)') 'Enter 1 to turn feed gas 2 valve on, 0 for off, or <cr> to exit: '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
read(lineRead,*) input
call forceFeedGas2Valve (input)
end do
getOpt = .false.
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(8)
! Pause to allow entering of a note
! Unlike option 2, this just continues to wait until next sampling event.
noteCnt = noteCnt + 1
noteFlag = 1
call DATE_AND_TIME (values=dt)
write(formStr,'(2(a,i2.2),a,i4,3(a,i2.2),a)') &
' (',int(dt(2)),'/',int(dt(3)),'/',int(dt(1)),' ',int(dt(5)),':',int(dt(6)),':',int(dt(7)),')'
write(infoUnit,'(a,i3,a)') 'Note Number: ',noteCnt,trim(formStr)
write(6,'(a,i3)') 'Enter description for Note: ',noteCnt
write(6,'(a)') 'Enter blank line to return to sampling.'
do
write(6,'(a,$)') '> '
read(5,'(a)') lineRead
if (lineRead == ' ') exit
write(infoUnit,'(a)') lineRead
end do
write(infoUnit,'(a)') '-------------------------------------------------------------------------------'
write(infoUnit,*) ' '
getOpt = .false.
write(6,*) ' ** Returing to sampling, press ESC for menu'
case(9)
! Enter new values for MC headspace gas volume (mL)
write(6,'(a)') 'Enter headspace gas volumes for MCs (mL): '
read(5,*) (MCheadSpaceVol(i),i=1,nMCports)
write(6,'(a,$)') 'Enter gas volume of sample loop (mL): '
read(5,*) SLvol
call writeRecovery ! update recovery file
getOpt = .false.
case(10)
write(6,*) ' Exiting program.'
getOpt = .false.
case default
write(6,*) ' ** Option not recognized, try again **'
end select
end do opt
return
end subroutine longMenu
subroutine convPort2data (iport, idatavec)
! This routine maps the port number to the correct datavec row.
! The datavec rows correspond as follows, regardless of sampling or use of a second feed gas:
! [mixtankPort, feed2gasPort, MCports(1), ..., MCports(nMCports)]
use CommParameters, only: mixtankPort, feed2GasPort, MCports, nMCports
implicit none
integer iport, idatavec
integer i
if (iport == mixtankPort) then
idatavec = 1
return
end if
if (iport == feed2gasPort) then
idatavec = 2
return
end if
do i=1,nMCports
if (iport == MCports(i)) then
idatavec = i+2
return
end if
end do
write(6,'(a)') 'ERROR::convPort2data: port value incorrect, Stopping!'
write(6,'(a,i)') ' iport = ',iport
stop
end subroutine convPort2data
Subroutine readGasAnalyzers (iport,datavec,tzero,NoAdjust)
use CommParameters, only: o2Adj, co2Adj, ch4Adj, o2Feed, co2Feed, ch4Feed, &
SL_O2, SL_CO2, SL_CH4, SLvol, MCheadSpaceVol, &
SL_o2_new, SL_co2_new, SL_ch4_new, mixtankVentPort, &
mixtankPort, feed2GasPort, o2Feed2, co2Feed2, ch4Feed2
implicit none
integer iport ! current valco port selected
logical NoAdjust ! If true, not adjustment is done to the "corrected" gas values
real(8) datavec(*), tzero
!local declarations
integer dt(8), ifail, i
real flow, o2, co2, ch4
! Get time stamp and julian time
call DATE_AND_TIME (values=dt)
datavec(1:6) = (/dble(dt(2)),dble(dt(3)),dble(dt(1)),dble(dt(5)),dble(dt(6)),dble(dt(7))/)
call julday(dt(1),dt(2),dt(3),dt(5),dt(6),real(dt(7)),datavec(13),ifail)
datavec(13) = datavec(13) - tzero
! Sample Mass flow meter
call readMassFlowMeter (flow)
datavec(15) = dble(flow)
! Sample oxigraph
call readOxigraf(o2, co2)
datavec(16) = dble(o2)
datavec(18) = dble(co2)
! Sample CH4
call readCH4 (ch4)
datavec(20) = dble(ch4)
! Copy this data over to the "adjusted" gas values columns
datavec(17) = datavec(16)
datavec(19) = datavec(18)
datavec(21) = datavec(20)
if (NoAdjust) return
if (iport == mixtankPort .or. iport == feed2GasPort) then
! Either mix tank (feed 1) or feed 2 port is being sampled, so generate offsets
if (iport == mixtankPort) then
o2Adj = o2 - o2Feed
co2Adj = co2 - co2Feed
ch4Adj = ch4 - ch4Feed
datavec(17) = dble(o2Adj)
datavec(19) = dble(co2Adj)
datavec(21) = dble(ch4Adj)