Nearly every program written for a Campbell Scientific data logger will include one or more data tables as a method of storing measurements or variable states for later analysis or diagnostics. In some cases it can be useful to recall previous stored records during run time for a multitude of operations. Once data table records are written it is possible to perform operations on previous data stored to maintain data integrity, trigger events or prevent double handling of data using an array for operations such as running averages or totals. 

Usage

Accessing data table records requires the use of special syntax available in CRBasic, this syntax is used in the form

TableName.FieldName (FieldNameIndex,RecordsBack)     

This syntax will access data from a specific Field of a DataTable Record. The TableName is the name of the table where the value to be accessed is stored. The table can be a user-defined data table or the status table. FieldName is the name of the field in the table, and it is always an array even when it consists of only one variable. FieldNameIndex specifies the array variable from which to retrieve data. RecordsBack specifies the number of records back in the DataTable the desired value resides (1 is the most recent record stored).

 

In the below example the current measured temperature (AirTemp) is stored in a data table named Temperature. These stored records are retrieved to calculate the change in temperature recorded 15 records ago (1 minute storage) compared to the current temperature.

Public AirTemp, Tdiff

 

DataTable(Temperature,True,-1)

  DataInterval(0,1,min,5)

  Sample(1,AirTemp,IEEE4)

EndTable

 

BeginProg

  Scan(1,min,5,0)

    Therm107(AirTemp,1,1,1,0,_50Hz,1,0)  ‘ Measure Air temperature using a 107 thermistor

    ‘ Calculate 15 min temperature difference

    Tdiff = Temperature.AirTemp(1,1) – Temperature.AirTemp(1,15)

 

    CallTable Temperature

  NextScan

EndProg    

 

This ability to access previous records within a data table allows the calculation of running totals, differences or averages to be achieved without maintaining an array. This syntax can also be used with other data table access options to keep track of fill times, new records or event based recording. A list of available syntax commands are below:

TableName.EventCount  Used to access the number of data storage events that have occurred in an event driven DataTable.
TableName.EventEnd Used to determine when the last record of an event is sent to the DataTable.
TableName.FieldName Used to access data from a specific Field of a DataTable Record.
TableName.Output  Used to ascertain whether data was written to the Output DataTable the last time that the DataTable was called.
TableName.Record Returns the record number of the record output n records back.
TableName.Tablefull Returns either 1 or 0 to indicate whether a fill and stop table is full or whether a ring-mode table has begun overwriting its oldest data.
TableName.TableSize  Returns the size allocation, in number of records, of the selected DataTable.
TableName.TimeStamp Returns one time stamp element of the record output n records back.

In the next example the syntax TableName.Output will be used to detect new records and calculate a running total of rainfall in the previous 1, 12, 24, 48 and 72 hour periods.  The rainfall is stored at one hour intervals in the Hourly data table and each record is accessed and added to an accumulator, when the accumulator reaches each multiple of hours the current value is moved to a corresponding variable. 

    If Hourly.output(1,1) = True Then      ‘ If new Hourly table record

      RainTotal = 0                            ‘ Reset the raintotal variable

      For RainDataPos = 1 To 72    ‘ 72 hours at one hour per record

        RainTotal = RainTotal + Hourly.Rain_mm(1,RainDataPos)      ‘ Get Rain record from RainDataPos

        If RainDataPos = 1 Then RainTotal1Hr = RainTotal

        If RainDataPos = 12 Then RainTotal12Hr = RainTotal

        If RainDataPos = 24 Then RainTotal24Hr = RainTotal

        If RainDataPos = 48 Then RainTotal48Hr = RainTotal

        If RainDataPos = 72 Then RainTotal72Hr = RainTotal

      Next RainDataPos

  EndIf

The use of data access syntax within your program can greatly simplify coding during testing data tables and allows operations on your data to be performed without maintaining complicated arrays, time intervals or incrementing variables.