added tecio to wmake rules
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / pltview.cpp
blobfd9dd63976dd0bef2a6e6845f8e33c3657c83633
1 /*
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.
17 * Tecplot, Inc.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
25 *****************************************************************
26 *****************************************************************
27 ******* ********
28 ****** (C) Copyright 2004-2006 by Tecplot, Inc. ********
29 ****** (C) Copyright 1989-2003 by AMTEC ENGINEERING INC.********
30 ******* All Rights Reserved. ********
31 ******* ********
32 *****************************************************************
33 *****************************************************************
38 ****************************************************************
39 ****************** BEGIN DEVELOPMENT NOTES *********************
40 ****************************************************************
42 BEGIN CODELOG PLTVIEW
43 V 09/04/98
44 V ****************************************************************
45 V * Build 1.0 9-04-98 *
46 V ****************************************************************
47 END CODELOG
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 ****************************************************************
66 #if defined ADDON
67 #include "TECADDON.h"
68 #include "GUIDEFS.h"
69 #include "GUI.h"
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)
78 #else
79 #include "MASTER.h"
80 #include "GLOBAL.h"
81 #include "TASSERT.h"
82 #define ALLOC_ARRAY(N,Type,S) (Type *)TecAlloc((N)*sizeof(Type))
83 #define FREE_ARRAY(N,S) TecFree((void *)N)
84 #include "ARRLIST.h"
85 #include "STRLIST.h"
86 #include "DATAUTIL.h"
89 #include "TECADDON.h"
90 #include "TECXXX.h"
91 #include "DATAUTIL.h"
92 #include "STRLIST.h"
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
102 #endif
105 static int GetNumPtsPerCell(ZoneType_e ZoneType)
107 int NumPts = 0;
108 switch (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;
116 return (NumPts);
119 static int GetNumPts(ZoneType_e ZoneType,
120 LgIndex_t NumPtsI,
121 LgIndex_t NumPtsJ,
122 LgIndex_t NumPtsK)
124 int NumPts = 0;
125 switch (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;
135 return (NumPts);
140 static void DeallocHeaderInfo(char **DataSetTitle,
141 StringList_pa *VarNames,
142 StringList_pa *ZoneNames,
143 LgIndex_t **NumPtsI,
144 LgIndex_t **NumPtsJ,
145 LgIndex_t **NumPtsK,
146 ZoneType_e **ZoneType,
147 StringList_pa *UserRec)
149 if (*DataSetTitle)
150 FREE_ARRAY(*DataSetTitle, "data set title");
151 if (*VarNames)
152 STRINGLISTDEALLOC(VarNames);
153 if (*ZoneNames)
154 STRINGLISTDEALLOC(ZoneNames);
155 if (*NumPtsI)
156 FREE_ARRAY(*NumPtsI, "NumPtsI Array");
157 if (*NumPtsJ)
158 FREE_ARRAY(*NumPtsJ, "NumPtsJ Array");
159 if (*NumPtsK)
160 FREE_ARRAY(*NumPtsK, "NumPtsK Array");
161 if (*ZoneType)
162 FREE_ARRAY(*ZoneType, "ZoneType Array");
163 if (*UserRec)
164 STRINGLISTDEALLOC(UserRec);
166 *DataSetTitle = NULL;
167 *VarNames = NULL;
168 *ZoneNames = NULL;
169 *NumPtsI = NULL;
170 *NumPtsJ = NULL;
171 *NumPtsK = NULL;
172 *ZoneType = NULL;
173 *UserRec = NULL;
178 #define MAXCHARSINFOLINE 5000
181 void ReportFileInfo(char *FName,
182 Boolean_t LoadRawData,
183 Boolean_t AllocateRawDataSpaceLocally)
185 short IVersion;
186 EntIndex_t NumZones;
187 EntIndex_t NumVars;
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;
196 int CZ, CV;
197 char InfoLine[MAXCHARSINFOLINE+1];
198 double **VDataBase = NULL;
199 NodeMap_t **NodeMap = NULL;
202 * Load in the header information only.
205 if (!READTEC(TRUE,
206 FName,
207 &IVersion,
208 &DataSetTitle,
209 &NumZones,
210 &NumVars,
211 &VarNames,
212 &ZoneNames,
213 &NumPtsI,
214 &NumPtsJ,
215 &NumPtsK,
216 &ZoneType,
217 &UserRec,
218 FALSE,
219 (NodeMap_t ***)NULL,
220 (double ***)NULL))
222 sprintf(InfoLine, "Cannot read file \"%s\"\nor file is not a Tecplot binary data file.\n", FName);
223 ERRMSG(InfoLine);
225 else
227 Boolean_t IsOk = TRUE;
228 if (LoadRawData)
230 if (AllocateRawDataSpaceLocally)
232 int NumPts;
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]);
238 if (NumPts >= 1)
239 VDataBase[CZ*NumVars+CV] = ALLOC_ARRAY(NumPts, double, "vdatabase array");
240 else
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)
248 NodeMap[CZ] = NULL;
249 else
251 int PtsPerCell = GetNumPtsPerCell(ZoneType[CZ]);
252 NodeMap[CZ] = ALLOC_ARRAY(PtsPerCell * NumPtsJ[CZ],
253 NodeMap_t, "zone nodemap");
257 else
259 VDataBase = NULL;
260 NodeMap = NULL;
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,
269 &VarNames,
270 &ZoneNames,
271 &NumPtsI,
272 &NumPtsJ,
273 &NumPtsK,
274 &ZoneType,
275 &UserRec);
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).
282 if (!READTEC(FALSE,
283 FName,
284 &IVersion,
285 &DataSetTitle,
286 &NumZones,
287 &NumVars,
288 &VarNames,
289 &ZoneNames,
290 &NumPtsI,
291 &NumPtsJ,
292 &NumPtsK,
293 &ZoneType,
294 &UserRec,
295 AllocateRawDataSpaceLocally,
296 &NodeMap,
297 &VDataBase))
299 if (IVersion > 99)
301 sprintf(InfoLine,
302 "Error: ***\n"
303 " This add-on can only display raw nodal data\n"
304 " and it appears to contain cell centered data.\n");
305 SHOWINFO(InfoLine);
307 else
309 sprintf(InfoLine,
310 "Cannot Read File, %s.\n"
311 "File may not be a tecplot binary data file.",
312 FName);
313 ERRMSG(InfoLine);
315 IsOk = FALSE;
319 SHOWINFO("\n");
320 sprintf(InfoLine, "FileName : %s\n", FName);
321 SHOWINFO(InfoLine);
322 sprintf(InfoLine, "File Version: %3.1f\n", IVersion / 10.0);
323 SHOWINFO(InfoLine);
325 /* if the file contains filetype, then retrieve that separately since ReadTec should not be changed */
326 if (IVersion >= 109)
328 DataFileType_e FileType = DataFileType_Full;
329 char FileTypeStr[32];
330 FILE *F = NULL;
332 /* open the file and get the filetype */
333 F = fopen(FName, "rb");
334 if (F)
336 char Buffer[8];
337 Int32_t One;
338 Int32_t FileTypeInt;
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;
345 fclose(F);
346 F = NULL;
348 /* map the filetype */
349 switch (FileType)
351 case DataFileType_Full:
352 strcpy(FileTypeStr, "Full");
353 break;
354 case DataFileType_Grid:
355 strcpy(FileTypeStr, "Grid");
356 break;
357 case DataFileType_Solution:
358 strcpy(FileTypeStr, "Solution");
359 break;
360 default:
361 IsOk = FALSE;
362 CHECK(FALSE);
363 break;
365 sprintf(InfoLine, "File Type : %s\n", FileTypeStr);
366 SHOWINFO(InfoLine);
369 sprintf(InfoLine, "DataSetTitle: %s\n", DataSetTitle ? DataSetTitle : " ");
370 SHOWINFO(InfoLine);
371 sprintf(InfoLine, "NumZones : %d\n", (int)NumZones);
372 SHOWINFO(InfoLine);
373 sprintf(InfoLine, "NumVars : %d\n", (int)NumVars);
374 SHOWINFO(InfoLine);
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, ",");
384 else
385 strcat(InfoLine, "\n\n");
386 SHOWINFO(InfoLine);
387 if (VarName)
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"),
402 (long)NumPtsI[CZ],
403 (long)NumPtsK[CZ],
404 (long)NumPtsJ[CZ]);
405 else
406 sprintf(InfoLine, "%-20s --- --- --- %-8ld --- %-8ld ",
407 (ZoneName ? ZoneName : "NULL"),
408 (long)NumPtsI[CZ],
409 (long)NumPtsJ[CZ]);
410 SHOWINFO(InfoLine);
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;
423 else
425 sprintf(InfoLine, "%-20s %-7ld %-7ld %-7ld --- --- --- ---\n",
426 (ZoneName ? ZoneName : "NULL"),
427 (long)NumPtsI[CZ],
428 (long)NumPtsJ[CZ],
429 (long)NumPtsK[CZ]);
430 SHOWINFO(InfoLine);
432 if (ZoneName)
433 FREE_ARRAY(ZoneName, "ZoneName Array");
437 if (IsOk)
439 for (CZ = 1; CZ <= STRINGLISTGETCOUNT(UserRec); CZ++)
441 char *S = STRINGLISTGETSTRING(UserRec, CZ);
442 if (S)
444 int L;
445 strcpy(InfoLine, "UserRec: ");
446 L = (int)strlen(InfoLine);
447 strncat(&InfoLine[L], S, MAXCHARSINFOLINE - L - 2);
448 strcat(&InfoLine[strlen(InfoLine)], "\n");
449 SHOWINFO(InfoLine);
450 FREE_ARRAY(S, "temp string");
455 if (LoadRawData)
457 for (CZ = 0; CZ < NumZones; CZ++)
459 int CV;
460 for (CV = 0; CV < NumVars; CV++)
461 if (VDataBase[CZ*NumVars+CV])
463 int I;
464 int NumPts = GetNumPts(ZoneType[CZ], NumPtsI[CZ], NumPtsJ[CZ], NumPtsK[CZ]);
465 int SLen = 0;
466 sprintf(InfoLine, "\n\nVariable data for zone %d, Var %d\n", CZ + 1, CV + 1);
467 SHOWINFO(InfoLine);
468 InfoLine[0] = '\0';
469 for (I = 0; I < NumPts; I++)
471 char PString[50];
472 if (SLen + 50 > MAXCHARSINFOLINE)
474 SHOWINFO(InfoLine);
475 InfoLine[0] = '\0';
476 SLen = 0;
479 sprintf(PString, "%lG ", VDataBase[CZ*NumVars+CV][I]);
480 strcat(InfoLine, PString);
481 SLen += (int)strlen(PString);
483 if ((I % 5) == 4)
485 strcat(InfoLine, "\n");
486 SLen++;
489 if (*InfoLine)
490 SHOWINFO(InfoLine);
491 FREE_ARRAY(VDataBase[CZ*NumVars+CV], "vdatabase double");
493 if (NodeMap[CZ])
495 int I, J;
496 int PtsPerCell = GetNumPtsPerCell(ZoneType[CZ]);
497 int SLen = 0;
498 SHOWINFO("\nConnectivity list:\n");
499 InfoLine[0] = '\0';
500 for (J = 0; J < NumPtsJ[CZ]; J++)
502 if (SLen + 200 > MAXCHARSINFOLINE)
504 SHOWINFO(InfoLine);
505 InfoLine[0] = '\0';
506 SLen = 0;
508 for (I = 0; I < PtsPerCell; I++)
510 char NString[20];
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");
516 SLen++;
518 if (*InfoLine)
519 SHOWINFO(InfoLine);
520 FREE_ARRAY(NodeMap[CZ], "nodemap");
523 FREE_ARRAY(NodeMap, "Nodemap base array");
524 FREE_ARRAY(VDataBase, "vdatabase base array");
528 SHOWINFO("\n\n");
530 DeallocHeaderInfo(&DataSetTitle,
531 &VarNames,
532 &ZoneNames,
533 &NumPtsI,
534 &NumPtsJ,
535 &NumPtsK,
536 &ZoneType,
537 &UserRec);
543 #if !defined ADDON
544 int main(int argc, char *(argv[]))
546 short CurFile;
548 if (argc == 1)
550 printf("Err: Need: pltview file1 [file2] ...\n");
551 exit(-1);
554 for (CurFile = 1; CurFile < argc; CurFile++)
555 ReportFileInfo(argv[CurFile], FALSE, FALSE);
557 return 0;
559 #endif