Hi. I am running a M903 nephelometer on a CR1000. We use weighed filters to compare to the neph for linear regression and have found that in the summer, if there is a wildfire, the slope and intercept change. I am trying to apply an If/Then statement to make this happen. Basically, if the month is July-Sept and the reading is > 0.0020, a new slope is applied. Otherwise, it is the normal slope we use for this particular airshed for the rest of the year.
Below is the code I came up with, but my programming skill are rusty to say the least.
A sample of the output from the neph string is
opening 1
4.452e-05 8.018e-04 1013 293 00 00
4.454e-05 8.018e-04 1013 293 00 00
4.457e-05 8.018e-04 1013 293 00 00
4.457e-05 8.018e-04 1013 293 00 00
Exiting talk thru
where 4.457e-05 is the BScat, 8.018e-04 is the BSCal (not used here) and the rest are various settings on the neph.
I have tested this by changing the date on the computer and on the CR1000 (using the DevConfig) and blowing some smoke into the neph until the BScat (or "Scat" in this case) is above 0.002, but it is still only using 14.9x - 2.1 for the slope. It isn't taking the month and/or the Scat into account. I'm unsure if the TimeIntoInterval function is correct to use here.
Any help is appreciated.
Code:
'Radiance Research RNeph Variables Public RNeph(2) As String Alias RNeph(1) = BScat Alias RNeph(2) = BSCal Public Scat As Float Public PMEst DataTable(OneMin,true,-1) DataInterval(0,1,min,10) Average(1,BScat,IEEE4,False) Average(1, PMEst, FP2, False) EndTable SequentialMode BeginProg 'Begin main scan Scan(1,Sec,3,0) SerialOpen(ComRS232,9600,3,0,219) SerialInRecord(ComRS232,inString,13,109,0,numBytesRet,00) 'Get data from RNeph SplitStr(RNeph,inString," ",2,6) 'Begin slope selection for wildfire Scat = RNeph(1) If TimeIntoInterval (7,12,Mon) AND Scat > 0.0020 Then PMEst = (10000 * Scat) * 13.31 + 2.96 ElseIf TimeIntoInterval (8,12,Mon) AND Scat > 0.0020 Then PMEst = (10000 * Scat) * 13.31 + 2.96 ElseIf TimeIntoInterval (9,12,Mon) AND Scat > 0.0020 Then PMEst = (10000 * Scat) * 13.31 + 2.96 Else PMEst = (10000 * Scat) * 14.9 - 2.1 EndIf EndProg
TimeIntoInterval() is only going to be true for the first second of the month.
I would suggest using the RealTime() instruction to get the month number into a variable. Then check against that variable.
That worked great. Thank you! The new code is:
'Radiance Research RNeph Variables Public RNeph(2) As String Alias RNeph(1) = BScat Alias RNeph(2) = BSCal Public Scat As Float Public PMEst Public rTime(9) 'Pulled from help example Alias rTime(2) = Month DataTable(OneMin,true,-1) DataInterval(0,1,min,10) Average(1,BScat,IEEE4,False) Average(1, PMEst, FP2, False) Sample( 9, rTime( ), IEEE4 ) EndTable SequentialMode BeginProg 'Begin main scan Scan(1,Sec,3,0) SerialOpen(ComRS232,9600,3,0,219) SerialInRecord(ComRS232,inString,13,109,0,numBytesRet,00) 'Get data from RNeph SplitStr(RNeph,inString," ",2,6) 'Begin slope selection for wildfire Scat = RNeph(1) RealTime( rTime ) If Month = 7 AND Scat > 0.0020 Then PMEst = (10000 * Scat) * 13.31 + 2.96 ElseIf Month = 8 AND Scat > 0.0020 Then PMEst = (10000 * Scat) * 13.31 + 2.96 ElseIf Month = 9 AND Scat > 0.0020 Then PMEst = (10000 * Scat) * 13.31 + 2.96 Else PMEst = (10000 * Scat) * 14.9 - 2.1 EndIf EndProg