Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Rating Lookup Table


ZS Mar 21, 2016 08:19 PM

I've been keeping up with reported rating curves at a few sites by updating the programs with new equations.  However, this has reached what I would consider to be critical mass.  Does anyone have a example program/script that can read in a text file residing on the logger and act like a a lookup table?  Thanks. 


JDavis Mar 22, 2016 09:45 PM

There are multiple ways of doing this. A simple method is to put the data in a text file with a pair of values on each line. A loop is needed to read lines from the file at startup. SplitStr will break the line into two numbers and place them in the array. 

Const MaxCount = 20 'Maximum number of lines in your rating table

Public RatingTable(MaxCount,2)
Dim DataLine As String * 48
Dim LineLength As Long, FileHandle As Long
Dim k As Long

'Main Program
BeginProg
FileHandle = FileOpen ("CPU:RatingTable.csv","r",0) 'Open the csv text file
For k = 1 To MaxCount
LineLength = FileReadLine (FileHandle,DataLine,48) 'The Read Length should be the same as the destination string size
If LineLength > 1 Then
SplitStr (RatingTable(k,1),DataLine,"",2,0)
Else
RatingTable(k,1) = NAN 'Fills missing values with NAN
RatingTable(k,2) = NAN
EndIf
Next k

FileClose(FileHandle) 'Closing the file is important


Scan (1,Sec,0,0)
'Measurements etc. go here

NextScan
EndProg


dandersonncwcd Nov 19, 2020 01:14 PM

I am having a hard time understanding how you would match up the sensor measurements to the values in the text file?


nsw Nov 27, 2020 10:58 AM

I would suspect that the "Case" statement should give you what you need.


JDavis Nov 30, 2020 05:51 PM

Run through the lookup table in a loop. The table is value pairs of level and flow.

Search for the level. If the level in Table(23,1) matches, then the flow is in Table(23,2).

Looking for exact matches can be difficult with Float values. Integer values (type Long) can give you exact matches. One way to go about it is to shift decimals places, and put the float value into a long.

For i = 1 to TableLength

  If   CType(Level * 100 , Long) = CType(Table( i , 1) * 100 , Long ) Then   'Match

     Flow = Table( i , 2 )

  EndIf

Next i

Log in or register to post/reply in the forum.