Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / examples / comtest / comtest.c
blobc290dcef40e3a73694bb3c2c15d0b8616274b275
1 /*
2 * Complex example C program to write a
3 * binary data file for Tecplot. This example
4 * does the following:
6 * 1. Open a data file called "field.plt."
7 * 2. Open a data file called "line.plt."
8 * 3. Assign values for X, Y and P. These will be used
9 * in both the ordered and finite-element data files.
10 * 4. Write out an ordered zone dimensioned 4 x 5 to "field.plt."
11 * 5. Assign values for XL and YL arrays.
12 * 6. Write out data for line plot to "line.plt." Make the data
13 * use double precision.
14 * 7. Write out a finite-element zone to "field.plt."
15 * 8. Write out a text record to "field.plt."
16 * 9. Write out a geometry (circle) record to "field.plt."
17 * 10. Close file 1.
18 * 11. Close file 2.
21 #include <stdio.h>
22 #include <math.h>
23 #include "TECIO.h"
25 int main(void)
27 float X[5][4], Y[5][4], P[5][4];
28 double XL[50], YL[50];
29 double SolTime;
30 INTEGER4 Debug, I, J, K, L, III, NPts, NElm, DIsDouble, VIsDouble, IMax, JMax, KMax;
31 INTEGER4 ICellMax, JCellMax, KCellMax, ZoneType, Clipping;
32 INTEGER4 StrandID, ParentZn, FieldFileType, LineFileType;
33 INTEGER4 SharingZone[3] = {0, 0, 0};
34 INTEGER4 IsBlock, NumFaceConnections, FaceNeighborMode, ShareConnectivityFromZone;
35 INTEGER4 NM[12][4];
36 double XP, YP, ZP, FH, LineSpacing, PatternLength;
37 double BoxMargin, BoxLineThickness, TextAngle;
38 INTEGER4 AttachToZone, Zone, Scope, PositionCoordSys, FontType, HeightUnits;
39 INTEGER4 IsFilled, GeomType, LinePattern, NumEllipsePts;
40 INTEGER4 Anchor, BoxType, BoxColor, BoxFillColor, TextColor, Color, FillColor;
41 INTEGER4 ArrowheadStyle, ArrowheadAttachment, NumSegments, NumSegPts[1];
42 double LineThickness, ArrowheadSize, ArrowheadAngle;
43 float XGeomData[1], YGeomData[1], ZGeomData[1];
44 enum FileType { FULL = 0, GRID = 1, SOLUTION = 2 };
46 Debug = 2;
47 VIsDouble = 0;
48 DIsDouble = 0;
49 FieldFileType = FULL;
50 LineFileType = FULL;
52 * Open order.plt and write the header information.
54 I = TECINI112((char*)"DATASET WITH ONE ORDERED ZONE AND ONE FE-QUAD ZONE OVER 2 TIME STEPS",
55 (char*)"X Y P",
56 (char*)"field.plt",
57 (char*)".",
58 &FieldFileType,
59 &Debug,
60 &VIsDouble);
62 * Open line.plt and write the header information.
64 VIsDouble = 1;
65 I = TECINI112((char*)"DATASET WITH ONE I-ORDERED ZONE",
66 (char*)"X Y",
67 (char*)"line.plt",
68 (char*)".",
69 &LineFileType,
70 &Debug,
71 &VIsDouble);
74 * Calculate values for the field variables.
76 for (J = 0; J < 5; J++)
77 for (I = 0; I < 4; I++)
79 X[J][I] = (float)(I + 1);
80 Y[J][I] = (float)(J + 1);
81 P[J][I] = (float)((I + 1) * (J + 1));
85 * Make sure writing to file #1.
87 III = 1;
88 I = TECFIL112(&III);
91 * Write the zone header information for the ordered zone.
93 IMax = 4;
94 JMax = 5;
95 KMax = 1;
96 ICellMax = 0;
97 JCellMax = 0;
98 KCellMax = 0;
99 ZoneType = 0;
100 SolTime = 10.0;
101 StrandID = 1;
102 ParentZn = 0;
103 IsBlock = 1;
104 NumFaceConnections = 0;
105 FaceNeighborMode = 0;
106 ShareConnectivityFromZone = 0;
107 I = TECZNE112((char*)"Ordered Zone 1",
108 &ZoneType,
109 &IMax,
110 &JMax,
111 &KMax,
112 &ICellMax,
113 &JCellMax,
114 &KCellMax,
115 &SolTime,
116 &StrandID,
117 &ParentZn,
118 &IsBlock,
119 &NumFaceConnections,
120 &FaceNeighborMode,
121 NULL, /* PassiveVarList */
122 NULL, /* ValueLocation */
123 NULL, /* ShareVarFromZone */
124 0, /* TotalNumFaceNodes */
125 0, /* NumConnectedBoundaryFaces */
126 0, /* TotalNumBoundaryConnections */
127 &ShareConnectivityFromZone);
129 * Write out the field data for the ordered zone.
131 III = IMax * JMax;
132 I = TECDAT112(&III, &X[0][0], &DIsDouble);
133 I = TECDAT112(&III, &Y[0][0], &DIsDouble);
134 I = TECDAT112(&III, &P[0][0], &DIsDouble);
137 * Calculate values for the I-ordered zone.
140 for (I = 0; I < 50; I++)
142 XL[I] = I + 1;
143 YL[I] = sin((double)(I + 1) / 20.0);
146 * Switch to the "line.plt" file (file number 2)
147 * and write out the line plot data.
150 III = 2;
151 I = TECFIL112(&III);
154 * Write the zone header information for the XY-data.
156 IMax = 50;
157 JMax = 1;
158 KMax = 1;
159 SolTime = 0.0;
160 StrandID = 0; /* StaticZone */
161 I = TECZNE112((char*)"XY Line plot",
162 &ZoneType,
163 &IMax,
164 &JMax,
165 &KMax,
166 &ICellMax,
167 &JCellMax,
168 &KCellMax,
169 &SolTime,
170 &StrandID,
171 &ParentZn,
172 &IsBlock,
173 &NumFaceConnections,
174 &FaceNeighborMode,
175 0, /* TotalNumFaceNodes */
176 0, /* NumConnectedBoundaryFaces */
177 0, /* TotalNumBoundaryConnections */
178 NULL, /* PassiveVarList */
179 NULL, /* ValueLocation */
180 NULL, /* ShareVarFromZone */
181 &ShareConnectivityFromZone);
183 * Write out the line plot.
185 DIsDouble = 1;
186 III = IMax;
187 I = TECDAT112(&III, (float *) & XL[0], &DIsDouble);
188 I = TECDAT112(&III, (float *) & YL[0], &DIsDouble);
191 * Switch back to the field plot file and write out
192 * the finite-element zone.
194 III = 1;
195 I = TECFIL112(&III);
198 * Move the coordinates so this zone's not on top of the other
200 for (J = 0; J < 5; J++)
201 for (I = 0; I < 4; I++)
203 X[J][I] = (float)(I + 6);
204 Y[J][I] = (float)(J + 1);
205 P[J][I] = (float)((I + 1) * (J + 1));
209 * Write the zone header information for the finite-element zone.
211 ZoneType = 3; /* FEQuad */
212 NPts = 20; /* Number of points */
213 NElm = 12; /* Number of elements */
214 KMax = 0; /* Unused */
215 SolTime = 10.0;
216 StrandID = 2;
217 I = TECZNE112((char*)"Finite Zone 1",
218 &ZoneType,
219 &NPts,
220 &NElm,
221 &KMax,
222 &ICellMax,
223 &JCellMax,
224 &KCellMax,
225 &SolTime,
226 &StrandID,
227 &ParentZn,
228 &IsBlock,
229 &NumFaceConnections,
230 &FaceNeighborMode,
231 0, /* TotalNumFaceNodes */
232 0, /* NumConnectedBoundaryFaces */
233 0, /* TotalNumBoundaryConnections */
234 NULL, /* PassiveVarList */
235 NULL, /* ValueLocation */
236 NULL, /* ShareVarFromZone */
237 &ShareConnectivityFromZone);
239 * Write out the field data for the finite-element zone.
241 IMax = 4;
242 JMax = 5;
243 III = IMax * JMax;
244 DIsDouble = 0;
245 I = TECDAT112(&III, &X[0][0], &DIsDouble);
246 I = TECDAT112(&III, &Y[0][0], &DIsDouble);
247 I = TECDAT112(&III, &P[0][0], &DIsDouble);
250 * Calculate and then write out the connectivity list.
251 * Note: The NM array references cells starting with
252 * offset of 1.
255 for (I = 1; I < IMax; I++)
256 for (J = 1; J < JMax; J++)
258 K = I + (J - 1) * (IMax - 1);
259 L = I + (J - 1) * IMax;
260 NM[K-1][0] = L;
261 NM[K-1][1] = L + 1;
262 NM[K-1][2] = L + IMax + 1;
263 NM[K-1][3] = L + IMax;
266 I = TECNOD112((INTEGER4 *)NM);
269 * Calculate values for the new solution variable.
271 for (J = 0; J < 5; J++)
272 for (I = 0; I < 4; I++)
274 P[J][I] = (float)(2.0 * (I + 1) * (J + 1));
278 * Write the zone header information for time step 2
280 ZoneType = 0;
281 IMax = 4;
282 JMax = 5;
283 KMax = 1;
284 SolTime = 20.0;
285 StrandID = 1;
286 SharingZone[0] = 1;
287 SharingZone[1] = 1;
288 SharingZone[2] = 0; /* solution variable is not shared */
289 ShareConnectivityFromZone = 0;
291 I = TECZNE112((char*)"Ordered Zone 2",
292 &ZoneType,
293 &IMax,
294 &JMax,
295 &KMax,
296 &ICellMax,
297 &JCellMax,
298 &KCellMax,
299 &SolTime,
300 &StrandID,
301 &ParentZn,
302 &IsBlock,
303 &NumFaceConnections,
304 &FaceNeighborMode,
305 0, /* TotalNumFaceNodes */
306 0, /* NumConnectedBoundaryFaces */
307 0, /* TotalNumBoundaryConnections */
308 NULL,
309 NULL,
310 SharingZone,
311 &ShareConnectivityFromZone);
314 * Write out the solution variable the grid variables are shared.
316 IMax = 4;
317 JMax = 5;
318 III = IMax * JMax;
319 DIsDouble = 0;
320 I = TECDAT112(&III, &P[0][0], &DIsDouble);
323 * Calculate values for the new solution variable.
325 for (J = 0; J < 5; J++)
326 for (I = 0; I < 4; I++)
328 P[J][I] = (float)(3.0 * (I + 1) * (J + 1));
332 * Write another time step for the FEZone and share from the first
334 ZoneType = 3;
335 SolTime = 20.0;
336 StrandID = 2;
337 KMax = 0;
338 SharingZone[0] = 2;
339 SharingZone[1] = 2;
340 SharingZone[2] = 0; /* solution variable is not shared */
341 ShareConnectivityFromZone = 2;
342 I = TECZNE112((char*)"Finite Zone 2",
343 &ZoneType,
344 &NPts,
345 &NElm,
346 &KMax,
347 &ICellMax,
348 &JCellMax,
349 &KCellMax,
350 &SolTime,
351 &StrandID,
352 &ParentZn,
353 &IsBlock,
354 &NumFaceConnections,
355 &FaceNeighborMode,
356 0, /* TotalNumFaceNodes */
357 0, /* NumConnectedBoundaryFaces */
358 0, /* TotalNumBoundaryConnections */
359 NULL, /* PassiveVarList */
360 NULL, /* ValueLocation */
361 SharingZone,
362 &ShareConnectivityFromZone);
365 * Write out the solution variable the grid variables are shared.
367 IMax = 4;
368 JMax = 5;
369 III = IMax * JMax;
370 DIsDouble = 0;
371 I = TECDAT112(&III, &P[0][0], &DIsDouble);
374 * Prepare to write out text record. Text is positioned
375 * at 0.5, 0.5 in frame units and has a height
376 * of 0.05 frame units.
378 XP = 50.0;
379 YP = 50.0;
380 ZP = 0.0;
381 FH = 5.0;
382 Scope = 1; /* Local */
383 Clipping = 1; /* Clip to frame */
384 PositionCoordSys = 1; /* Frame */
385 FontType = 1; /* Helv Bold */
386 HeightUnits = 1; /* Frame */
387 AttachToZone = 0;
388 Zone = 0;
389 BoxType = 0; /* None */
390 BoxMargin = 5.0;
391 BoxLineThickness = 0.5;
392 BoxColor = 3;
393 BoxFillColor = 7;
394 TextAngle = 0.0;
395 Anchor = 0; /* Left */
396 LineSpacing = 1.0;
397 TextColor = 0; /* Black */
399 III = TECTXT112(&XP,
400 &YP,
401 &ZP,
402 &PositionCoordSys,
403 &AttachToZone,
404 &Zone,
405 &FontType,
406 &HeightUnits,
407 &FH,
408 &BoxType,
409 &BoxMargin,
410 &BoxLineThickness,
411 &BoxColor,
412 &BoxFillColor,
413 &TextAngle,
414 &Anchor,
415 &LineSpacing,
416 &TextColor,
417 &Scope,
418 &Clipping,
419 (char*)"Hi Mom",
420 (char*)"");
423 * Prepare to write out geometry record (circle). Circle is
424 * positioned at 25, 25 (in frame units) and has a radius of
425 * 20 percent. Circle is drawn using a dashed line.
429 XP = 25.0;
430 YP = 25.0;
431 ZP = 0.0;
432 IsFilled = 0;
433 Color = 0;
434 FillColor = 7;
435 GeomType = 3; /* Circle */
436 LinePattern = 1; /* Dashed */
437 LineThickness = 0.3;
438 PatternLength = 1.5;
439 NumEllipsePts = 72;
440 ArrowheadStyle = 0;
441 ArrowheadAttachment = 0;
442 ArrowheadSize = 0.1;
443 ArrowheadAngle = 15.0;
444 NumSegments = 1;
445 NumSegPts[0] = 1;
447 XGeomData[0] = 20.0;
448 YGeomData[0] = 0.0;
449 ZGeomData[0] = 0.0;
452 III = TECGEO112(&XP,
453 &YP,
454 &ZP,
455 &PositionCoordSys,
456 &AttachToZone,
457 &Zone,
458 &Color,
459 &FillColor,
460 &IsFilled,
461 &GeomType,
462 &LinePattern,
463 &PatternLength,
464 &LineThickness,
465 &NumEllipsePts,
466 &ArrowheadStyle,
467 &ArrowheadAttachment,
468 &ArrowheadSize,
469 &ArrowheadAngle,
470 &Scope,
471 &Clipping,
472 &NumSegments,
473 NumSegPts,
474 &XGeomData[0],
475 &YGeomData[0],
476 &ZGeomData[0],
477 (char*)"");
480 * Close out file 1.
482 I = TECEND112();
485 * Close out file 2.
487 III = 2;
488 I = TECFIL112(&III);
489 I = TECEND112();
491 return 0;