The Templex
read statement is used to access a vector of data from a results
file. The read statement automatically recognizes all result file
types supported by import templates or external readers registered with your
MotionView or HyperGraph
installation. Import templates and external readers describe the file format,
allowing Templex direct access to specific results
vectors.
Tip: To use the two columns of data shown below, copy and paste them
into a new file.
X |
Y |
0.0000000000e+00
1.0000000000e+00
2.0000000000e+00
3.0000000000e+00
4.0000000000e+00
5.0000000000e+00
6.0000000000e+00
7.0000000000e+00
8.0000000000e+00
9.0000000000e+00
1.0000000000e+01
|
0.0000000000e+00
-2.0452000000e-01
-2.0996000000e+02
1.3688000000e+02
-2.0412000000e+03
-4.5116000000e+03
-7.5309000000e+03
-9.4560000000e+03
-7.0598000000e+03
-4.3536000000e+03
-5.6833000000e+01
|
The following template reads the first column into a vector named "x" and the second
column into a vector named "y." This template then uses the statement
{
max} to find the maximum negative value of the
y-vector.
{x = read("curve.dat", 0, 0, 0) 'Read column 0 into }
{y = read("curve.dat", 0, 0, 1) 'Read column 1 into y vector}
{ny = -y}
{ymax = max(ny)}
The maximum negative value of {-ymax} occurs at x = {x[indexofmax(ny)]}
Any text outside the braces is treated as plain text. Plain text is copied to the
output stream exactly as it appears in the template. Templex statements, expressions and variables are located
within braces, {}. If the Templex statement generates
output, the resulting value is sent to the output stream.
The above template yields the following
output:
The maximum negative value of -9456 occurs at x = 7
In the following template, the same two vectors are read from one file. This template
uses the math statement
Polyfit to calculate the coefficients
from a sixth-order least squares polynomial curve fit of the
data.
{x = read("curve.dat", 0, 0, 0) 'Read column 0 into x vector}
{y = read("curve.dat", 0, 0, 1) 'Read column 1 into y vector}
{result = polyfit(x,y,6)}
{open "curvefit.out"}
"X" "Y" Polyfit "Y"
----------- ----------- -----------
{table(x, y, result, "%12.6f %12.6f %12.6f", 0, numpts(x)-1)}
{close}
There are two outputs from this template. First, the calculated coefficients are
reported to the standard output stream, as
shown:
Polynomial coefficients:
+4.61436e+01 * X^0
-1.23808e+03 * X^1
+1.30333e+03 * X^2
-3.38257e+02 * X^3
-3.88651e+00 * X^4
+6.09099e+00 * X^5
-3.50098e-01 * X^6
Mean deviation: 3.33713e+02
Correlation coefficient: 9.91274e-01
Second,
a new dependent vector representing the polyfit data is assigned to the vector
result, which is then written to the file along with the independent vector x. This
is shown below:
X |
Y |
Polyfit"Y" |
0.000000
1.000000
2.000000
3.000000
4.000000
5.000000
6.000000
7.000000
8.000000
9.000000
10.000000
|
0.000000
-0.204520
-209.960000
136.880000
-2041.200000
-4511.600000
-7530.900000
-9456.000000
-7059.800000
-4353.600000
-56.833000
|
46.143579
-225.009132
187.561497
-161.006006
-1893.164101
-4708.213938
-7533.633874
-8928.478798
-7738.850272
-4005.437480
-123.128993
|
In the next example, the template reads in a file containing wheel center
displacements and spindle alignment point displacements which result from stroking a
suspension from jounce to rebound. This information is used to calculate camber and
toe for each output position. The result is formatted and sent to the standard
output stream.
The following input file is used:
Inc |
Whl_cntr_xdsp |
Whl_cntr_ydsp |
Whl_cntr_zdsp |
Spdl_aln_xdsp |
Spdl_aln_ydsp |
Spdl_aln_zdsp |
1 |
1005.338500 |
-819.560700 |
420.000000 |
1004.721800 |
-769.611100 |
417.840800 |
2 |
1004.335100 |
-823.669400 |
400.000000 |
1003.815700 |
-773.695100 |
398.482200 |
3 |
1003.305400 |
-826.754700 |
380.000000 |
1002.889200 |
-776.766100 |
379.015600 |
4 |
1002.243700 |
-828.834400 |
360.000000 |
1001.943800 |
-778.838400 |
359.445100 |
5 |
1001.144100 |
-829.916700 |
340.000000 |
1000.980400 |
-779.917500 |
339.773200 |
6 |
1000.000000 |
-830.000000 |
320.000000 |
1000.000000 |
-780.000000 |
320.000000 |
7 |
998.804400 |
-829.072700 |
300.000000 |
999.002900 |
-779.073200 |
300.123900 |
8 |
997.548600 |
-827.111900 |
280.000000 |
997.989100 |
-777.114000 |
280.140400 |
9 |
996.222100 |
-824.081600 |
260.000000 |
996.958400 |
-774.087100 |
260.041900 |
10 |
994.811200 |
-819.929100 |
240.000000 |
995.910100 |
-769.941500 |
239.816500 |
11 |
993.296900 |
-814.579100 |
220.000000 |
994.842900 |
-764.606100 |
219.445900 |
The following template is
created:
{increment = read("sdf.dat", 0, 0, 0)}
{wcx = read("sdf.dat", 0, 0, 1)}
{wcy = read("sdf.dat", 0, 0, 2)}
{wcz = read("sdf.dat", 0, 0, 3)}
{spax = read("sdf.dat", 0, 0, 4)}
{spay = read("sdf.dat", 0, 0, 5)}
{spaz = read("sdf.dat", 0, 0, 6)}
{n = numpts(increment)}
{camber = array(n)}
{toe = array(n)}
Inc wcx wcy wcz
--- ------------ ------------ ------------
{table(increment, wcx, wcy, wcz,"%2d %12.6f %12.6f %12.6f", 0, n-1)}
Inc spax spay spaz
--- ------------ ------------ ------------
{table(increment, spax, spay, spaz, "%2d %12.6f %12.6f %12.6f", 0, n-1)}
{for(i=0; i<=10; i++)}
{temp1 = spaz[i] - wcz[i]}
{temp2 = sqrt((wcy[i]-spay[i])^2+(wcz[i]-spaz[i])^2)}
{temp3 = wcx[i] - spax[i]}
{temp4 = sqrt((wcx[i]-spax[i])^2+(wcy[i]-spay[i])^2)}
{camber[i] = rtod(asin(temp1/temp2))}
{toe[i] = rtod(asin(temp3/temp4))}
{endloop}
Inc camber toe
--- ------------ ------------
{table(increment, camber, toe, "%2d %12.6f %12.6f", 0, n-1)}
The
template output is shown below:
Inc |
wcx |
wcy |
wcz |
1 |
1005.338500 |
-819.560700 |
420.000000 |
2 |
1004.335100 |
-823.669400 |
400.000000 |
3 |
1003.305400 |
-826.754700 |
380.000000 |
4 |
1002.243700 |
-828.834400 |
360.000000 |
5 |
1001.144100 |
-829.916700 |
340.000000 |
6 |
1000.000000 |
-830.000000 |
320.000000 |
7 |
998.804400 |
-829.072700 |
300.000000 |
8 |
997.548600 |
-827.111900 |
280.000000 |
9 |
996.222100 |
-824.081600 |
260.000000 |
10 |
994.811200 |
-819.929100 |
240.000000 |
11 |
993.296900 |
-814.579100 |
220.000000 |
Inc |
spax |
spay |
spaz |
1 |
1004.721800 |
-769.611100 |
417.840800 |
2 |
1003.815700 |
-773.695100 |
398.482200 |
3 |
1002.889200 |
-776.766100 |
379.015600 |
4 |
1001.943800 |
-778.838400 |
359.445100 |
5 |
1000.980400 |
-779.917500 |
339.773200 |
6 |
1000.000000 |
-780.000000 |
320.000000 |
7 |
999.002900 |
-779.073200 |
300.123900 |
8 |
997.989100 |
-777.114000 |
280.140400 |
9 |
996.958400 |
-774.087100 |
260.041900 |
10 |
995.910100 |
-769.941500 |
239.816500 |
11 |
994.842900 |
-764.606100 |
219.445900 |
Inc |
camber |
toe |
1 |
-2.475217 |
0.707363 |
2 |
-1.739630 |
0.595473 |
3 |
-1.128151 |
0.477028 |
4 |
-0.635893 |
0.343683 |
5 |
-0.259896 |
0.187589 |
6 |
0.000000 |
0.000000 |
7 |
0.141980 |
-0.227465 |
8 |
0.160893 |
-0.504784 |
9 |
0.048019 |
-0.843769 |
10 |
-0.210327 |
-1.259356 |
11 |
-0.635269 |
-1.771978 |
Templex templates can also be incorporated into
report definitions in
MotionView and
HyperGraph to produce text summaries as part of a standard
report.