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.

tablename.fieldname syntax


54North Nov 5, 2010 08:28 PM

From the 2 levels of averaging thread (see below), what does the (1,1) refer to in the following syntax example?

NewVar = CH01_HF.Spd1(1,1

Record number and position of the field element within the record? I don't belive Spd1 was intended as an array in this example.

I tried implementing this in a CR850 with OS CR800.Std.21 dated 10/09/23 which is newer than what is available on the download site, but it doesn't compile.

Advice?

Thanks,

- Brendan

****** Original Thread *****

http://www.campbellsci.com/forum/messages.cfm?threadid=0E1F7F6D-CBDD-2B4C-AFBD97180D98676C

RE: 2 levels of averaging
04/22/09 11:08 AM


> Can I have a table that reads another table?

The tablename.fieldname syntax will read values from another table. For instance,

NewVar = CH01_HF.Spd1(1,1)

will put the Spd1 sample from table CH01_HF into NewVar.
Refer to the CRBasic help.


This syntax can also be used in an output instruction. For example:

Sample(1,CH01_HF.Spd1(1,1),FP2)

Make sure you have the most recent precompiler and OS (can be downloaded from our web site). If I recall correctly, there was one version of the precompiler that would crash with this syntax in a data table.

Regards,

Dana

Dana Worley
Campbell Scientific, Logan UT
Marketing Software Product Manager/Manager Software Support


Sam Nov 8, 2010 01:36 AM

>> what does the (1,1) refer to in the following syntax example? NewVar = CH01_HF.Spd1(1,1


Just for reference, if you have access to the CRBasic editor, take a look at Help -> Search -> Datatable Access


In the example above, you are using the "TableName.FieldName(FieldNameIndex, RecordsBack)" syntax. So:

* CH01_HF = Table name as define in DataTable declaration
* Spd(1,1) = 1st index of "Spd" variable, 1 record back in time

- If "Spd" is not an array, you still need to reference the FieldNameIndex, and the only valid choice is "1"

- If "Spd" is a one dimensional array, for example Spd(3) = {12,14,16}, the valid choices for FieldNameIndex are 1, 2 or 3. They would reference 12,14, and 16, respectively.

RecordsBack is used to select which record or "row" of data to reference. RecordsBack is in reference to "now". So 1 is one record back, i.e. the last record saved in the datatable. 2 would be two records back, so on and so forth. A NAN will be returned if you try to reference an invalid record/row.

Negating the FieldNameIndex and RecordsBack parameters take on other meanings, which you can read about in CRBasic help.


kirving Nov 8, 2010 01:59 AM

>Just for reference, if you have access to the CRBasic editor, take a look at Help -> Search -> Datatable Access

It would be very helpful if that same information were available as a PDF file. I only use CRBasic to check programs, and the online help is not always available.

Thanks!


Sam Nov 8, 2010 03:04 AM

>>> The online help is not always available.

I'm not sure if I interpreted this correctly, but you do not have to be online to view CRBasic's help.

With that said, I agree that there are times I've wished that I had a PDF of CRBasic help - when editing programs on computers that did not have the CRBasic Editor. The CR1000 manual has a lot of that information, but not all. I wouldn't expect it to either. It would just add more bloat.

One thing you can do is download the latest OS from our website, http://www.campbellsci.com/download. When you double click the executable, it will unpack the latest OS and CRBasic definition and help files. Even on machines without the CRBasic Editor. Navigate to C:\Campbellsci\Lib\CRBasicDefFiles. There you can click on CRbasic1.chm for CR1000 related CRBasic help. The "1" denotes CR1000.

* Last updated by: Sam on 11/7/2010 @ 9:13 PM *


54North Nov 8, 2010 05:28 PM

Thank for the explanation Sam. It is not always easy to know what terms to using when search help ;-> In the interim, as a workaround I think I basically implemented a lower-level version of the tablename.fieldname syntax in the following test example... are there pitfalls to having processing instructions between table calls? I ultimately what to include 1-minute based statistics in a 15-minute output block.

'Test Program for incorporating sub-interval statistics in an output table.

'Data from a "hidden" 1-min scracth table is retrieved, processed and
'stored to a 5-min table. To avoid filling up memory, the sracth table
'is reset every 5 minutes. To confirm logic, a 5 minute average from the
' sracth table is calculated and stored to the 5-minute output table for
' comparison to its 5 minute average.
'
'NOTE: First pass through after compiling will be NAN for sub-interval processing.

SequentialMode

Public PTemp, batt_volt
Public T_1min,T_5min

Dim table_record(2), sum_5min
Dim I

DataTable (Scratch_1min,1,-1)
TableHide
DataInterval (0,1,min,10)
Minimum (1,batt_volt,FP2,0,False)
Average (1,PTemp,IEEE4,False)
EndTable
DataTable (Table2,1,-1)
DataInterval (0,5,min,10)
Sample (1,T_5min,IEEE4)
Average (1,PTemp,IEEE4,False)
EndTable

BeginProg

Scan (1,Sec,0,0)

PanelTemp (PTemp,250)
Battery (Batt_volt)

CallTable Scratch_1min

If TimeIntoInterval(0,5,min) Then
For I= 5 To 1 Step -1
GetRecord (table_record(),Scratch_1min,I)
T_1min=table_record(2)
sum_5min=T_1min+sum_5min
Next I
T_5min=(sum_5min)/5
sum_5min=0
ResetTable (Scratch_1min)
EndIf

CallTable Table2

NextScan

EndProg


Sam Nov 8, 2010 05:51 PM

>> are there pitfalls to having processing instructions between table calls?

No there is not. It is a completely valid thing to do.

>> To avoid filling up memory, the sracth table
'is reset every 5 minutes

Regarding this comment, you are not actually saving memory. The "-1" in the "Scratch" table declaration means "auto-allocate". In your program, you have auto-allocated space for all tables. Final storage memory will be divided so that each table will fill at approximately the same time.

If it were me, I would remove the ResetTable instruction. I would also change the Scratch table declaration to:

DataTable (Scratch_1min,1,6)

The "6" means, allocate only enough final storage memory to hold at least 6 records for this table.


54North Nov 9, 2010 02:37 AM

Sam,

Would you recommend the same general approach (sratch table of fixed length) to construct a hourly data table with multiple wind vector formulations, but no parameter duplication?

Hourly mean scalar horizontal wind speed
Hourly unit vector mean wind direction
Hourly std dev of wind direction (1 hour sub-interval)

Hourly resultant (vector) wind speed
Hourly resultant (vector) wind direction

Pseudo std dev of wind direction (four 15-min sub-intervals)

The latter three elements would sampled from the sratch table.

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