Calculate Statistics, Save in Historical Periodic Files and Email

Last updated:  April 10, 2002

Introduction
This document is one of five that describes the basic ICON program (skeleton.icn) which normally provides the framework for all ICON programs. This document describes the fourth module type named "Historical periodic data" which takes imported data, calculates statistics such as average, standard deviation, maximum and minimum over a period of time and records the results to the historical periodic files. Optionally the data can also be emailed. If you wish to perform email functions, refer to the following sections:

  1. Configure email addresses and the IP address of your SMTP mail access point. Refer to the Connection section. Under general parameters, refer to Mail Server IP:, IP Email 1 (return address): and IP Email 2:. Under table parameters, refer to E-mail Address:.
  2. Configure a periodic file. Include an email address range if sending email.
In the following sections the program is listed along with the configuration. The first line is the instruction and caption as would be listed when programming. This is followed by the general and table parameter configuration. Finally, a description of the purpose of the program is included if needed. If the instruction needs a reference on the HMI, the configuration for that HMI object is included.

Module Historical periodic data

Map Import historical data for time file 1
General Parameters
Array: time1
Direction: To array
Table Parameters
Individual
#sensor_avg1
#sensor_avg1[1]
#sensor_avg1[2]
#sensor_avg1[3]
#sensor_avg1[4]
#sensor_avg1[5]
#sensor_avg1[6]
#sensor_avg1[7]
#sensor_avg1[8]
#sensor_avg1[9]
#sensor_avg1[10]
#sensor_avg1[11]
#sensor_avg1[12]
#sensor_avg1[13]
#sensor_avg1[14]
#sensor_avg1[15]

Statistics
General Parameters
Parameter Example Description
Input: time1 The data on which to calculate statistics. This instruction expects the validity status to be at time1[1].
Results: time1_statistics The statistical results are placed in this array. The first statistical result is in time1_statistics and the validity status is in time1_statistics[1]. The second statistical result is in time1_statistics[2] and the validity status is in time1_statistics[3]. This pattern continues for all statistics calculations configured.
Control: time1_control The control value for this variable will be described and created below.
Max valid status: 000000h This indicates that any non-zero value in time1[1] will cause the value in time1 to be rejected and not used in the statistical calculation for that pass. This prevents invalid data from being used in the statistics calculation.
Minimum valid: 1 This indicates that a valid statistics result will be returned in time1_statistics if there are 1 or more valid inputs during the period.
Table Parameters
Parameter Example Description
Calc type: Average You may choose from Average, Standard Deviation, Maximum, Minimum, Difference, Total, Circular average and Circular Standard deviation. You may set your table length to do as many of the above as you desire. The circular functions expect the input data to be in degrees.

Repeat the above instruction for each required input data point for the selected time file. For the second instruction use time1[2] and time1_statistics[2]. Follow this block of instructions with the Map instruction which is used to gather the data together to write data to the periodic file.

Map Remove status
General Parameters
Parameter Example Description
Array: time1_selected The name of the data array to write to the periodic file.
Direction: To array Select this to gather data from a random set of variables to the periodic_data variable
Table Parameters
Individual
time1_statistics
time1_statistics[2]
time1_statistics[4]
time1_statistics[6]
time1_statistics[8]
time1_statistics[10]
time1_statistics[12]
time1_statistics[14]
The above instruction is optional and is only required if you want to store data values only and remove the status values.

Histper Time file 1
General Parameters
Parameter Example Description
Data: time1_selected The name of the data array to write to the periodic file. If you eliminate the Map instruction above, you may set this variable to time1_statistics.
Status: time1_status The value of this variable is set to 1 for the pass that actually writes data to the periodic file. On all other passes the value is set to 0. Therefore, if writing to a periodic file set for a recording interval of 1 hour, this variable is only set to 1 on the pass once per hour when data is written to the file.
Periodic file: 1 Select the time file (1-4).

Expression Create statistics control for file 1
Table Parameters
Result: Expression
time1_control time1_status*2+1
This Expression instruction causes the variable time1_control to have a value of 1 for all passes except the pass where data is written to the periodic file. For this pass the value is 3. This is then used as input to the Statistics instructions above. 1 causes the statistics to be calculated. A value of 3 causes the statistics to reset to start a new sequence. Notice because the Expression is done after writing to the file, the statistics are not reset till the pass after writing to the file.

You may repeat the above block three more times for time files 2, 3 and 4. The statistics instructions can be eliminated if you want to record instantaneous data. Often times time file 1 is used for 1 minute data and only an instantaneous value is recorded.