2 * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM
4 * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide.
6 * Tecplot hereby grants OpenCFD limited authority to distribute without
7 * alteration the source code to the Tecplot Input/Output library, known
8 * as TecIO, as part of its distribution of OpenFOAM and the
9 * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby
10 * granted access to the TecIO source code, and may redistribute it for the
11 * purpose of maintaining the converter. However, no authority is granted
12 * to alter the TecIO source code in any form or manner.
14 * This limited grant of distribution does not supersede Tecplot, Inc.'s
15 * copyright in TecIO. Contact Tecplot, Inc. for further information.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
25 *****************************************************************
26 *****************************************************************
28 ****** (C) Copyright 2004-2006 by Tecplot, Inc. ********
29 ****** (C) Copyright 1989-2003 by AMTEC ENGINEERING INC.********
30 ******* All Rights Reserved. ********
32 *****************************************************************
33 *****************************************************************
38 ****************************************************************
39 ****************** BEGIN DEVELOPMENT NOTES *********************
40 ****************************************************************
44 V ****************************************************************
45 V * Build 1.0 9-04-98 *
46 V ****************************************************************
49 *********************************************************************
50 * IMPORTANT NOTE: Only development notes for "pltview" stand-alone *
51 * belong in this file. See "ADDONVER.h" for changes *
52 * related to the add-on. *
53 *********************************************************************
55 ****************************************************************
56 * V in column 1 marks date information. *
57 * C in column 1 marks notes on new changes. *
58 * B in column 1 marks notes on bug fixes. *
59 ****************************************************************
61 ****************************************************************
62 ****************** END DEVELOPMENT NOTES ***********************
63 ****************************************************************
70 #define READTEC TecUtilReadBinaryData
71 #define SHOWINFO(S) TecGUITextAppendString(Output_T_D1,S);
72 #define ERRMSG(S) TecUtilDialogErrMsg(S)
73 #define ALLOC_ARRAY(N,Type,S) (Type *)TecUtilStringAlloc((N)*sizeof(Type),"debug info")
74 #define FREE_ARRAY(N,S) TecUtilStringDealloc((char **)&N)
75 #define STRINGLISTGETSTRING(S,N) TecUtilStringListGetString(S,N)
76 #define STRINGLISTGETCOUNT(S) TecUtilStringListGetCount(S)
77 #define STRINGLISTDEALLOC(S) TecUtilStringListDealloc(S)
82 #define ALLOC_ARRAY(N,Type,S) (Type *)TecAlloc((N)*sizeof(Type))
83 #define FREE_ARRAY(N,S) TecFree((void *)N)
95 #define READTEC ReadTec
96 #define SHOWINFO(S) printf("%s",S);
97 #define ERRMSG(S) printf("Err: %s\n",S);
98 #define STRINGLISTGETSTRING(S,N) StringListGetString(S,(N)-1)
99 #define STRINGLISTGETCOUNT(S) StringListCount(S)
100 #define STRINGLISTDEALLOC(S) StringListDealloc(S)
101 #define MaxCharsUserRec 500
105 static int GetNumPtsPerCell(ZoneType_e ZoneType
)
110 case ZoneType_FETriangle
: NumPts
= 3; break;
111 case ZoneType_FEQuad
: NumPts
= 4; break;
112 case ZoneType_FETetra
: NumPts
= 4; break;
113 case ZoneType_FEBrick
: NumPts
= 8; break;
114 default : NumPts
= 0;
119 static int GetNumPts(ZoneType_e ZoneType
,
127 case ZoneType_FETriangle
:
128 case ZoneType_FEQuad
:
129 case ZoneType_FETetra
:
130 case ZoneType_FEBrick
:
131 case ZoneType_FEPolygon
:
132 case ZoneType_FEPolyhedron
: NumPts
= NumPtsI
; break;
133 default : NumPts
= NumPtsI
*NumPtsJ
*NumPtsK
;
140 static void DeallocHeaderInfo(char **DataSetTitle
,
141 StringList_pa
*VarNames
,
142 StringList_pa
*ZoneNames
,
146 ZoneType_e
**ZoneType
,
147 StringList_pa
*UserRec
)
150 FREE_ARRAY(*DataSetTitle
, "data set title");
152 STRINGLISTDEALLOC(VarNames
);
154 STRINGLISTDEALLOC(ZoneNames
);
156 FREE_ARRAY(*NumPtsI
, "NumPtsI Array");
158 FREE_ARRAY(*NumPtsJ
, "NumPtsJ Array");
160 FREE_ARRAY(*NumPtsK
, "NumPtsK Array");
162 FREE_ARRAY(*ZoneType
, "ZoneType Array");
164 STRINGLISTDEALLOC(UserRec
);
166 *DataSetTitle
= NULL
;
178 #define MAXCHARSINFOLINE 5000
181 void ReportFileInfo(char *FName
,
182 Boolean_t LoadRawData
,
183 Boolean_t AllocateRawDataSpaceLocally
)
188 char *DataSetTitle
= NULL
;
189 StringList_pa VarNames
= NULL
;
190 StringList_pa ZoneNames
= NULL
;
191 LgIndex_t
*NumPtsI
= NULL
;
192 LgIndex_t
*NumPtsJ
= NULL
;
193 LgIndex_t
*NumPtsK
= NULL
;
194 ZoneType_e
*ZoneType
= NULL
;
195 StringList_pa UserRec
= NULL
;
197 char InfoLine
[MAXCHARSINFOLINE
+1];
198 double **VDataBase
= NULL
;
199 NodeMap_t
**NodeMap
= NULL
;
202 * Load in the header information only.
222 sprintf(InfoLine
, "Cannot read file \"%s\"\nor file is not a Tecplot binary data file.\n", FName
);
227 Boolean_t IsOk
= TRUE
;
230 if (AllocateRawDataSpaceLocally
)
233 VDataBase
= ALLOC_ARRAY(NumZones
* NumVars
, double *, "vdatabase array");
234 for (CZ
= 0; CZ
< NumZones
; CZ
++)
235 for (CV
= 0; CV
< NumVars
; CV
++)
237 NumPts
= GetNumPts(ZoneType
[CZ
], NumPtsI
[CZ
], NumPtsJ
[CZ
], NumPtsK
[CZ
]);
239 VDataBase
[CZ
*NumVars
+CV
] = ALLOC_ARRAY(NumPts
, double, "vdatabase array");
241 VDataBase
[CZ
*NumVars
+CV
] = NULL
;
244 NodeMap
= ALLOC_ARRAY(NumZones
, NodeMap_t
*, "nodemap array");
245 for (CZ
= 0; CZ
< NumZones
; CZ
++)
247 if (ZoneType
[CZ
] == ZoneType_Ordered
)
251 int PtsPerCell
= GetNumPtsPerCell(ZoneType
[CZ
]);
252 NodeMap
[CZ
] = ALLOC_ARRAY(PtsPerCell
* NumPtsJ
[CZ
],
253 NodeMap_t
, "zone nodemap");
264 * NOTE: If any of the above alloc's failed then no big deal. ReadTec
265 * itself "skips" vars if memory was not allocated for it.
268 DeallocHeaderInfo(&DataSetTitle
,
278 * Reread the datafile. This time load in the header AND the raw data
279 * Note that VDataBase may be preallocated or may be left up to ReadTec
280 * to allocate (See AllocateRawDataSpaceLocally above).
295 AllocateRawDataSpaceLocally
,
303 " This add-on can only display raw nodal data\n"
304 " and it appears to contain cell centered data.\n");
310 "Cannot Read File, %s.\n"
311 "File may not be a tecplot binary data file.",
320 sprintf(InfoLine
, "FileName : %s\n", FName
);
322 sprintf(InfoLine
, "File Version: %3.1f\n", IVersion
/ 10.0);
325 /* if the file contains filetype, then retrieve that separately since ReadTec should not be changed */
328 DataFileType_e FileType
= DataFileType_Full
;
329 char FileTypeStr
[32];
332 /* open the file and get the filetype */
333 F
= fopen(FName
, "rb");
340 /* 8 bytes for magic# and version and 4 bytes for Int32 */
341 fread(Buffer
, sizeof(Buffer
[0]), 8, F
);
342 fread(&One
, sizeof(One
), 1, F
);
343 fread(&FileTypeInt
, sizeof(FileTypeInt
), 1, F
);
344 FileType
= (DataFileType_e
)FileTypeInt
;
348 /* map the filetype */
351 case DataFileType_Full
:
352 strcpy(FileTypeStr
, "Full");
354 case DataFileType_Grid
:
355 strcpy(FileTypeStr
, "Grid");
357 case DataFileType_Solution
:
358 strcpy(FileTypeStr
, "Solution");
365 sprintf(InfoLine
, "File Type : %s\n", FileTypeStr
);
369 sprintf(InfoLine
, "DataSetTitle: %s\n", DataSetTitle
? DataSetTitle
: " ");
371 sprintf(InfoLine
, "NumZones : %d\n", (int)NumZones
);
373 sprintf(InfoLine
, "NumVars : %d\n", (int)NumVars
);
375 if (IsOk
&& (NumZones
> 0))
377 SHOWINFO("Var Names : ");
378 for (CZ
= 0; CZ
< NumVars
; CZ
++)
380 char *VarName
= STRINGLISTGETSTRING(VarNames
, CZ
+ 1);
381 sprintf(InfoLine
, "%s", VarName
? VarName
: "NULL");
382 if (CZ
< NumVars
- 1)
383 strcat(InfoLine
, ",");
385 strcat(InfoLine
, "\n\n");
388 FREE_ARRAY(VarName
, "VarName array");
390 SHOWINFO("ZoneName IMax JMax KMax Node Face Elmt EType\n");
391 SHOWINFO("-------------------------------------------------------------------------------\n");
393 for (CZ
= 0; CZ
< NumZones
; CZ
++)
395 char *ZoneName
= STRINGLISTGETSTRING(ZoneNames
, CZ
+ 1);
396 if (ZoneType
[CZ
] != ZoneType_Ordered
)
398 if (ZoneType
[CZ
] == ZoneType_FEPolygon
||
399 ZoneType
[CZ
] == ZoneType_FEPolyhedron
)
400 sprintf(InfoLine
, "%-20s --- --- --- %-8ld %-8ld %-8ld ",
401 (ZoneName
? ZoneName
: "NULL"),
406 sprintf(InfoLine
, "%-20s --- --- --- %-8ld --- %-8ld ",
407 (ZoneName
? ZoneName
: "NULL"),
411 switch (ZoneType
[CZ
])
413 case ZoneType_FETriangle
: SHOWINFO("Tri\n"); break;
414 case ZoneType_FEQuad
: SHOWINFO("Quad\n"); break;
415 case ZoneType_FETetra
: SHOWINFO("Tetra\n"); break;
416 case ZoneType_FEBrick
: SHOWINFO("Brick\n"); break;
417 case ZoneType_FELineSeg
: SHOWINFO("LineSeg\n"); break;
418 case ZoneType_FEPolygon
: SHOWINFO("Polygon\n"); break;
419 case ZoneType_FEPolyhedron
: SHOWINFO("Polyhed\n"); break;
420 default: CHECK(FALSE
); break;
425 sprintf(InfoLine
, "%-20s %-7ld %-7ld %-7ld --- --- --- ---\n",
426 (ZoneName
? ZoneName
: "NULL"),
433 FREE_ARRAY(ZoneName
, "ZoneName Array");
439 for (CZ
= 1; CZ
<= STRINGLISTGETCOUNT(UserRec
); CZ
++)
441 char *S
= STRINGLISTGETSTRING(UserRec
, CZ
);
445 strcpy(InfoLine
, "UserRec: ");
446 L
= (int)strlen(InfoLine
);
447 strncat(&InfoLine
[L
], S
, MAXCHARSINFOLINE
- L
- 2);
448 strcat(&InfoLine
[strlen(InfoLine
)], "\n");
450 FREE_ARRAY(S
, "temp string");
457 for (CZ
= 0; CZ
< NumZones
; CZ
++)
460 for (CV
= 0; CV
< NumVars
; CV
++)
461 if (VDataBase
[CZ
*NumVars
+CV
])
464 int NumPts
= GetNumPts(ZoneType
[CZ
], NumPtsI
[CZ
], NumPtsJ
[CZ
], NumPtsK
[CZ
]);
466 sprintf(InfoLine
, "\n\nVariable data for zone %d, Var %d\n", CZ
+ 1, CV
+ 1);
469 for (I
= 0; I
< NumPts
; I
++)
472 if (SLen
+ 50 > MAXCHARSINFOLINE
)
479 sprintf(PString
, "%lG ", VDataBase
[CZ
*NumVars
+CV
][I
]);
480 strcat(InfoLine
, PString
);
481 SLen
+= (int)strlen(PString
);
485 strcat(InfoLine
, "\n");
491 FREE_ARRAY(VDataBase
[CZ
*NumVars
+CV
], "vdatabase double");
496 int PtsPerCell
= GetNumPtsPerCell(ZoneType
[CZ
]);
498 SHOWINFO("\nConnectivity list:\n");
500 for (J
= 0; J
< NumPtsJ
[CZ
]; J
++)
502 if (SLen
+ 200 > MAXCHARSINFOLINE
)
508 for (I
= 0; I
< PtsPerCell
; I
++)
511 sprintf(NString
, "%u ", (unsigned int)NodeMap
[CZ
][J
*PtsPerCell
+I
] + 1);
512 strcat(InfoLine
, NString
);
513 SLen
+= (int)strlen(NString
);
515 strcat(InfoLine
, "\n");
520 FREE_ARRAY(NodeMap
[CZ
], "nodemap");
523 FREE_ARRAY(NodeMap
, "Nodemap base array");
524 FREE_ARRAY(VDataBase
, "vdatabase base array");
530 DeallocHeaderInfo(&DataSetTitle
,
544 int main(int argc
, char *(argv
[]))
550 printf("Err: Need: pltview file1 [file2] ...\n");
554 for (CurFile
= 1; CurFile
< argc
; CurFile
++)
555 ReportFileInfo(argv
[CurFile
], FALSE
, FALSE
);