TEMPLATE$ returns TEMPLATE$ returns a string value containing formatted values and lines of text
Syntax
TEMPLATE$(Template$, ReplaceMode%=0,1,2, [InpVar])
...
- Template$ is a string/document containing the textual skeleton of the document to be created, including parameters and format statements
- ReplaceMode% is an option how to replace the parameters in the template when "~" is used:
- ReplaceMode% = 0: first remove "~ParName" and then overwrite the value of ParName over the remaining text starting on position of ~
- ReplaceMode% = 1: first overwrite "~ParName" with spaces (the amount specified as Cell width in the Slots & Properties of the parameter) and then overwrite the value ofParName over the remaining text starting on position of ~
- ReplaceMode% = 2: first remove "~ParName" and then insert the value of ParName
- InpVar is an optional list of parameters present as labels in Template$ to be replaced by their values.
- The TEMPLATE$ function is the core function to create knowledge based scripts for other programs;
- The basic mechanism of the TEMPLATE$ function is a script including parameter names, which will be replaced with actual values during execution;
- Please note that, when no format tags are used (see hereafter), the Cell width specified in the the Slots & Properties will have influence on the placement of the parameter values;
- Furthermore, string values are aligned to the left and numeric values are aligned to the right by default;
- Although you can write the script directly between quote on the place of Template$, the easiest way is to use the TEXTITEM$() function to refer to a script in the data slot of the relation;
- Please make sure that, when you are using TEXTITEM$(), you are using delimiters for the start and finish of the script that are different from other characters in your template!
- There are several ways to define where and how to place a parameter value:
- ~ParameterName, see also syntax;
- ~ObjectName(ParameterName1, ParameterName2, ...) or ~TeLiTabName(ParameterName1, ParameterName2, ...), write the content of an object/TeLiTab (most probably a table) specified by the parameter names in their defined order. Useful for writing tables;
- ~ObjectName(ParameterName1\1) or ~ObjectName.ParameterName.1 or ~TeLiTabName.ParameterName.1, write the content of an object but only case 1 of ParameterName1. Useful for writing multi-case values. these values might have a single value but still are presented in the table of a TeLiTab (being a multi-value parameter...);
- #ParameterName#, this method is useful for producing a flow of text and replacing parts in text. #ParameterName# is replaced without leading and trailing spaces. So please realise that "#Pi|F12.3#" (Pi using fixed format, a cell with of 12 and 3 decimal places) returns " 3.142" and is put in the text without spaces, thus as "3.142";
- #Boolean Expression[Label]#Text to be placed[Label], use an expression and place the text (or parameter) specified between the labels when the expression is true. Will not work with Objects in a Boolean Expression and functions referring to data in an any data slot;
- TEMPLATE$ makes it is also possible to generate FORTRAN-look alike formatted data, e.g. for programs requiring an input file containing a formatted set of values. In this case the parameters and their formats are providedwithout "~" or "#" but simply separated by comma's and/or spaces. This mode can be used in individual lines of Template$ when they ONLY contain these formats, so not mixed with other text. See the example below for more details
- Moreover, it is possible to place values in combination with expression (see an example below);
- Besides the replacement options, there are some options for defining formats. In general the format are defined by ParName|Format$. The formats defined in FORMAT$() can also be used for the TEMPLATE$() function (but with "|" behind the parameter name instead of between quotes).
- Note that using the format statements a picture connected to a parameter value can be shown (see also Image management, Data use and management and Documentation of knowledge ). Use <parametername>|P;
- Moreover, when @EQEXPLAIN is used, without the format statements, the actual value for a parameter is shown in the template. If you want to use the explanation as shown using@EQEXPLAIN use <parametername>|C;
- Please note that you can add a Carriage return Linefeed ( CrLf ) to values by adding "/|" after the format. Example: OWPOL(NT|I18|X2|1)/| will write the first case of NT (indicated by |1) in object OWPOL as integer in a cell of 18 positions followed by two spaces (X2) and than place a Carriage return Linefeed
- Special addition that will only work in the TEMPLATE$ function:
- Adding &Number to the fixed format (F) will round values on multitude of Number. Example: "#Pi|F12.3&0.25#" returns " 3.25" and is put in the text without spaces, thus as "3.25"
- Integer values can also be printed as words using &English, however, only for 0-10 and in English. Example: "#NPROP|I2&English#" returns "One" for NPROP=1
In addtion to &English for returning "Value" you can use either:
...
Assume LPP=33.37 with the cell width in de knowledge base defined as 6
TEMPLATE$("Length between PP: ~LPP [m]", 0, LPP)
...
To obtain a better result, you can used the ReplaceMode%=1:
TEMPLATE$("Length between PP: ~LPP [m]", 1, LPP)
...
The final option is to use ReplaceMode%=2:
TEMPLATE$("Length between PP: ~LPP [m]", 2, LPP)
...
0
3 "RADIUS" "THICKNESS" "CHORD"
"1" 0.250 54.0 495.4
"2" 0.450 40.2 520.4
"3" 0.600 21.0 543.7
"4" 0.800 17.0 390.4
"5" 1.000 Â 9.0 Â 14.5
relation:
TEMPLATE$("Thickness distribution:
Radius Thickness
~GEOM(RADIUS,THICKNESS)", 0, @GEOM)
...
Values of RADIUS and THICKNESS are formatted according to the properties in the knowledge base, so fixed format with two decimals placed right in a cell of 9 spaces.
relation:
TEMPLATE$(
"Blade root radius : ~GEOM(RADIUS\1) r/R
BlBlade root thisckness : ~GEOM(THICKNESS\1) mm
Tip thickness : ~GEOM(THICKNESS\5) mm", 0, @GEOM)
...
Assume LPP=33.37 with the cell width in de knowledge base defined as 6
TEMPLATE$("Length between PP: #LPP# [m]", 0, LPP)
...
Assume LPP=33.37 with the cell width in de knowledge base defined as 6
TEMPLATE$("Length between PP: #LPP|E8.3# [m]", 0, LPP)
...
The writing mechanism with "#Boolean Expression[Label]#Text to be placed[Label]"
TEMPLATE$("The model will be fitted with#NPROP=2[1]# two propellers and[1]#NPROP=1[1]# one propeller and[1] all appendages", 0, NPROP)
...
The writing mechanism with nested "#Boolean Expression[Label]#Text to be placed[Label]"
TEMPLATE$("The model will be fitted with#NPROP>0[1]##NPROP=2[2]# two propellers and[2]#NPROP=1[2]# one propeller and[2][1] all appendages", 0, NPROP)
...
Integer values can also be printed as words, however, only for 0-10:
TEMPLATE$("#NPROP|I2&English# propeller#NPROP><1[1]#s[1] fitted.", 0, NPROP)
...
A counter can be included in Template$ by "#&#", for example
TEMPLATE$("#&#) Wood
#Option1[1]##&#) Polyester
[1]#&#) Foam", 0, Option)
...
Instead of integer counters, you can use english words first-tenth by using "%" instead of "&". For independent counters, the same principle is applied as above.
TEMPLATE$("#%#) Wood, #%%#) Polyester and #%%%#) Foam", 0)
...
0
3 "RADIUS" "THICKNESS" "CHORD"
"1" 0.250 54.0 495.4
"2" 0.450 40.2 520.4
"3" 0.600 21.0 543.7
"4" 0.800 17.0 390.4
"5" 1.000 9.1 14.5
TEMPLATE$(
"2nd thickness THICKNESS.2|F6.2/|
3rd thickness: #THICKNESS.3|F6.2# [mm]
4th thickness: ~THICKNESS.4|F6.1
5th thickness: ~THICKNESS.5", 0, Obj$)
...
1
"DATA"
{
0
2 "A" "B"
"1" 1 2
"2" 2 4
"3" 3 6
"4" 4 8
"5" 5 10
"6" 6 12
"7" 7 14
"8" 8 16
"9" 9 18
"10" 10 20
}
Then relation:
TEMPLATE$("An example:
~DATA(A\3)
~DATA(B)",0,@DATA)
...
You can use format tags in the script:
TEMPLATE$("An example:
~DATA(A\3)
~DATA(B|F12.3/|)",0,@DATA)
...
The third case of A is taken without any format decription (so the format of the Workbase/Slots & Properties is taken). this is followed by the content for B in the object using a Cell width of 12 and 3 decimal places.
Please note, when you use format statement for paramters in the object, you have to close with a CrLf, thus "/|". otherwise all values will be placed behind each other:
TEMPLATE$("An example:
~DATA(A\3)
~DATA(B|F12.3)",0,@DATA)
...
TFOR_INT and TAFT_INT will first be used to calculate the average draught.
or
TEMPLATE$(
"Company : #COMPANY$#
Street & City: #STREET$ + CHR$(13) + CHR$(10) + SPACE$(15) + CITY$|#", 0, DEPT$, COMPANY$,
STREET$, CITY$)
...