Contents

hide

2008-03-31: up-to-date

4.6. Operations on header information

set headers

Figure 1: Set headers dialog box.

This section explains how to modify header information stored in a database in a very efficient way. Any information about signals can be viewed in a table. Signals can be modified one by one by cell editing. For huge number of signals this is boring and time consuming. Instead, you can create formulas and apply them with one single click. The syntax for these formulas is rather simple.

General presentation

From any active viewer (which is by definition a list of signals), click on menu item "Edit/Set headers". The dialog box shown in figure 1 will appear. You can type any number of equations in the left editor. To assist you, for instance for a correct spelling of signal field names, you can use the combos on the right. All formulas are separated by ";" (link in C). If a line begins with "//", all text is ignored until the end of the line (like C comments). The same way, all text included between "/*" and "*/" is considered as a comment. Commenting parts of an equation may be interesting to solve errors. The general syntax is

SignalData = value;

There are various assignment operators:

Assignment operators
Code Description
SignalData = value Set SignalData to value. This operator works for numbers and character strings.
SignalData += value Set SignalData to the sum of its previous content with value. This operator works for numbers and character strings.
SignalData -= value Set SignalData to the difference between its previous content and value. This operator works only for numbers.
SignalData *= value Set SignalData to the product of its previous content with value. This operator works only for numbers.
SignalData /= value Set SignalData to the ratio between its previous content and value. This operator works only for numbers. A floating point division is performed.

Value can be the result of any kind of operation. Parenthesis can be introduced to force order of operation (classical operator priority is used, e.g. * over +). Values can be number constants or strings of characters. In this last case, characters must be placed between "" (double quotes, not single!). A number between "" can be considered as a number or a string.

Other operators
Code Description
value1 + value2 Sum or concatenation operator. If one of the two value contains characters, the number operand is converted to a string and normal concatenation is performed.
value1 - value2 Difference operator.
value1 * value2 Multiplication operator.
value1 / value2 Floating point division operator.
value1 DIV value2 Integer division operator. E.g. 5 DIV 2 produces 2.
value1 MOD value2 Modulo operator. E.g. 8 MOD 3 produces 2.
value1 == value2 Returns a bool value, true if value1 and value2 are equal.
value1 != value2 Returns a bool value, true if value1 and value2 are not equal.
value1 < value2 Returns a bool value, true if value1 is less than value2.
value1value2 Returns a bool value, true if value1 is less than or equal to value2.
value1 > value2 Returns a bool value, true if value1 is greater than value2.
value1value2 Returns a bool value, true if value1 is greater than or equal to value2.
value1 [ value2 ] If value1 is an array, the value2 th element is returned. If value1 is not an array, value2 is ignored.

Additionally, you have access to some useful functions for text manipulation or for conditional operations.

Functions
Code Description
if(value1, value2, value3) If value1 evaluates to true, value2 is returned else value3.
justify(string, nchar, fillchar) Right justifies string to get a nchar length. Blanks are filled with fillchar. fillchar must be 1 character length. E.g. justify( "45", 5, "0") produces "00045".
left(string, nChars) Returns the first nChars characters of string. E.g. left("45678",2) returns "45".
length(string) Returns length of string. E.g. length("45678") returns 5.
mid(string, pos, nChars) Returns nChars characters of string starting at pos. pos starts counting at 0. E.g. mid("45678", 1, 2) returns "56".
right(string, nChars) Returns the last nChars characters of string. E.g. right("45678",2) returns "78".

Any unrecognized name not starting by a number is considered as a custom variable. Custom variables are initialized by an empty string if there not in the left part of "=" assignment. They can be used in formulas like any constant or signal data.

When you click on "Apply", all equations are executed for all signals in the order the equations appear in the editor and in the order of signals in the viewer. Custom variables are persistent during the global loop. This way values can be "propagated" from the first signals to the next one.

The content of the editor can be saved or restored to a .headequ file (a simple text file in fact).

Examples

Example 1
if(left(ShortFileName,4)=="east",Component="East",
if(left(ShortFileName,5)=="north",Component="North",
if(left(ShortFileName,8)=="vertical",Component="Vertical",
if(left(ShortFileName,6)=="radial",Component="East",
if(left(ShortFileName,10)=="transverse",Component="North","")))));

Use nested if functions to convert a file name structure to signal component. ShortFileName is the original file name without its complete path. We assume that the file name starts with a keyword indicating the component.

Example 2
SampFreq=100;

Set sampling frequency to 100 Hz. Can be useful when loading signal from text files without header information. The sampling frequency is the minimum field required to display signals.

Example 3
c=left(right(ShortFileName,13),9);
Name="S_"+c;
ReceiverX=left(c,4);
ReceiverX-=2000;
ReceiverY=right(c,4);
ReceiverY-=2000;

We assume that file names end with this structure: "2056_2030.txt" which represents the coordinates X and Y of the station. The first line extract "2056_2030". "2056_2030.txt" contains 13 characters and only 9 characters are useful. This is a common trick to extract a pattern at the end of a file name of variable length. The result of this operation is stored in custom variable c to be reused three time to set Name and coordinates. The second line build the name of the station by concatenating "S_" to variable c. The remaining lines extract the correct numbers out of "2056_2030" to set 56 and 30 to X and Y respectively.

An alternative to the first line can use a mixture of mid and length functions:

Example 4
c=mid(ShortFileName, length(ShortFileName)-14, 9);

Keep in mind that positioning with mid starts at 0 for the first character. Hence, the last character is at position length(ShortFileName)-1.

Example 5
iComp=(ViewerIndex-1) DIV 3;
Component=if(iComp==0,"Vertical", if(iComp==1,"North", "East"));

Use of ViewerIndex signal data to set the component. ViewerIndex is not a real signal data. It is just the index of the signal in the current viewer. It starts at 1. iComp is then an integer varying from 0 to 2. We assume that signals are order as Z, N, E, Z, N, E,... but components are not (correctly) assigned.