Contents

2008-03-31: up-to-date
4.6. Operations on header information

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 | ||||||||||||
|
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 | ||||||||||||||||||||||||||||
|
Additionally, you have access to some useful functions for text manipulation or for conditional operations.
Functions | ||||||||||||||
|
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.