foam to Tecplot360 converter
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / tecsrc / datautil.cpp
blob783abec0c404116d4c98ccb122d20f3746769306
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/
24 #include "stdafx.h"
25 #include "MASTER.h"
26 #define TECPLOTENGINEMODULE
28 ******************************************************************
29 ******************************************************************
30 ******* ********
31 ****** (C) 1988-2008 Tecplot, Inc. *******
32 ******* ********
33 ******************************************************************
34 ******************************************************************
38 * datautil.c:
40 * version 1.00 : 12/10/91 (cm) changes made for manual
41 * version 1.01 : 12/30/91 Get and ReturnHugeBlock are now ptr to function
42 * version 6.00 : 04/21/92 updated to match version 6 of tecplot.
43 * version 6.30 : 10/15/92 updated to match binary file version 6.3
44 * version 6.30a: 05/04/93 (cm) minor changes to prototypes
45 * version : 11/01/93 (cm) put in D4GW stuff
46 * version 6.30b: 12/27/93 (cm) fixed missing NumKPts in DumpZone
47 * version 6.30c: 12/27/93 (cm) put back in D4GW stuff
48 BEGIN CODELOG TECXXX
49 C 03/06/96 (BDP)
50 C Update to V7
52 C 03/14/97 (BDP)
53 C Added code to main tecplot source. Now can
54 C be built stand alone or added so TecUtil_ functions
55 C can access.
56 C 06/02/98 (bdp)
57 C v75 coding. Also removed Array of ZoneSpec_s
58 C structs in favor of zonenames, i,j,and k dimensions
59 C and zonetype array.
60 END CODELOG
65 #include "GLOBAL.h"
66 #include "TASSERT.h"
67 #include "Q_UNICODE.h"
68 #include "SYSTEM.h"
69 #include "ALLOC.h"
70 #include "TECXXX.h"
71 #include "ARRLIST.h"
72 #include "SET.h"
73 #include "DATASET.h"
74 #include "FILESTREAM.h"
75 #if defined TECPLOTKERNEL
76 /* CORE SOURCE CODE REMOVED */
77 #endif
78 #include "DATAIO.h"
79 #include "DATAIO4.h"
80 #include "DATAUTIL.h"
81 #include "STRLIST.h"
82 #include "Q_MSG.h"
83 #if defined MAKEARCHIVE
84 #define INITMODULE
85 #endif
86 #include "INPUT.h"
88 using namespace tecplot::strutil;
90 #if defined MAKEARCHIVE
91 #define ANGLEEPSILON 1.0e-10
93 void InitInputSpecs(void)
95 LineThicknessInputSpec.Type = Input_Double;
96 LineThicknessInputSpec.Min = 0.000001;
97 LineThicknessInputSpec.Max = 1.0;
98 LineThicknessInputSpec.InterfaceAdjust.ScaleFact = 100.0;
99 LineThicknessInputSpec.SuffixModifier = NULL;
101 PatternLengthInputSpec.Type = Input_Double;
102 PatternLengthInputSpec.Min = 0.0001;
103 PatternLengthInputSpec.Max = 1.0;
104 PatternLengthInputSpec.InterfaceAdjust.ScaleFact = 100.0;
105 PatternLengthInputSpec.SuffixModifier = NULL;
107 TextBoxMarginInputSpec.Type = Input_Double;
108 TextBoxMarginInputSpec.Min = 0.0;
109 TextBoxMarginInputSpec.Max = 20.0;
110 TextBoxMarginInputSpec.InterfaceAdjust.ScaleFact = 100.0;
111 TextBoxMarginInputSpec.SuffixModifier = NULL;
113 TextLineSpacingInputSpec.Type = Input_Double;
114 TextLineSpacingInputSpec.Min = 0.0;
115 TextLineSpacingInputSpec.Max = 5.0;
116 TextLineSpacingInputSpec.InterfaceAdjust.ScaleFact = 1.0;
117 TextLineSpacingInputSpec.SuffixModifier = NULL;
120 ArrowheadSizeInputSpec.Type = Input_Double;
121 ArrowheadSizeInputSpec.Min = 0.0;
122 ArrowheadSizeInputSpec.Max = 0.5;
123 ArrowheadSizeInputSpec.InterfaceAdjust.ScaleFact = 100.0;
124 ArrowheadSizeInputSpec.SuffixModifier = NULL;
126 TextAngleInputSpec.Type = Input_Double;
127 TextAngleInputSpec.Min = -PI - ANGLEEPSILON;
128 TextAngleInputSpec.Max = PI + ANGLEEPSILON;
129 TextAngleInputSpec.InterfaceAdjust.ScaleFact = DEGPERRADIANS;
130 TextAngleInputSpec.SuffixModifier = NULL;
132 ArrowheadAngleInputSpec.Type = Input_Double;
133 ArrowheadAngleInputSpec.Min = 1.0 / DEGPERRADIANS - ANGLEEPSILON;
134 ArrowheadAngleInputSpec.Max = PIOVER2 + ANGLEEPSILON;
135 ArrowheadAngleInputSpec.InterfaceAdjust.ScaleFact = DEGPERRADIANS;
136 ArrowheadAngleInputSpec.SuffixModifier = NULL;
138 #endif
143 void LocalReadBlock(FileStream_s *FileStream,
144 double *CurVPtr,
145 FieldDataType_e FieldDataTypeInFile,
146 HgIndex_t NumValues,
147 Boolean_t *IsOk)
149 REQUIRE(VALID_REF(IsOk) && VALID_BOOLEAN(*IsOk));
150 REQUIRE(!(*IsOk) || VALID_REF(FileStream));
151 REQUIRE(!(*IsOk) || VALID_FIELD_DATA_TYPE(FieldDataTypeInFile));
153 if (*IsOk)
155 Boolean_t DoRead = (CurVPtr != NULL);
156 Boolean_t ReadByBlock = (FieldDataType_Double == FieldDataTypeInFile) || !DoRead;
157 if (ReadByBlock)
159 ReadPureBlock(FileStream,
160 DoRead,
161 (void *)CurVPtr,
162 FieldDataTypeInFile,
164 NumValues,
165 IsOk);
167 else
169 LgIndex_t N;
170 for (N = 0; *IsOk && (N < NumValues); N++)
172 double D = GetNextValue(FileStream, FieldDataTypeInFile, -LARGEDOUBLE, LARGEDOUBLE, IsOk);
173 if (DoRead)
174 CurVPtr[N] = D;
185 * NOTE: ReadTec only allocates space for NodeMap and VDataBase
186 * if RawDataSpaceAllocated == FALSE and GetHeaderInfoOnly
187 * is FALSE.
189 * Also note that all data read in by ReadTec is currently
190 * limited to be in double precision.
195 Boolean_t STDCALL ReadTec(Boolean_t GetHeaderInfoOnly,
196 char *FName,
197 short *IVersion,
198 char **DataSetTitle,
199 EntIndex_t *NumZones,
200 EntIndex_t *NumVars,
201 StringList_pa *VarNames,
202 StringList_pa *ZoneNames,
203 LgIndex_t **NumPtsI,
204 LgIndex_t **NumPtsJ,
205 LgIndex_t **NumPtsK,
206 ZoneType_e **ZoneType,
207 StringList_pa *UserRec,
208 Boolean_t RawDataSpaceAllocated,
209 NodeMap_t ***NodeMap,
210 double ***VDataBase)
212 Boolean_t InputIsOk = FALSE;
213 ArrayList_pa ZoneSpecList = NULL;
214 LgIndex_t *FNNumBndryConns = NULL; /* [NumZones] */
215 FileStream_s *ReadTecFileStream = NULL;
216 Set_pa *IsVarCellCentered = NULL; /* [NumZones] */
218 REQUIRE(VALID_BOOLEAN(GetHeaderInfoOnly));
219 REQUIRE(VALID_NON_ZERO_LEN_STR(FName));
220 REQUIRE(VALID_REF(IVersion));
221 REQUIRE(VALID_REF(DataSetTitle) || DataSetTitle == NULL);
222 REQUIRE(VALID_REF(NumZones));
223 REQUIRE(VALID_REF(NumVars));
224 REQUIRE(VarNames == NULL || VALID_REF(VarNames));
225 REQUIRE(ZoneNames == NULL || VALID_REF(ZoneNames));
226 REQUIRE(NumPtsI == NULL || VALID_REF(NumPtsI));
227 REQUIRE(NumPtsJ == NULL || VALID_REF(NumPtsJ));
228 REQUIRE(NumPtsK == NULL || VALID_REF(NumPtsK));
229 REQUIRE(ZoneType == NULL || VALID_REF(ZoneType));
230 REQUIRE(UserRec == NULL || VALID_REF(UserRec));
231 REQUIRE(VALID_BOOLEAN(RawDataSpaceAllocated));
232 REQUIRE(IMPLICATION(!GetHeaderInfoOnly && RawDataSpaceAllocated,
233 VALID_REF(NodeMap) && VALID_REF(VDataBase)));
235 #if defined MAKEARCHIVE
236 InitInputSpecs();
237 #endif
239 InputIsOk = OpenBinaryFileAndCheckMagicNumber(&ReadTecFileStream,
240 FName,
242 IVersion);
244 if (InputIsOk)
245 InputIsOk = ReadDataFileHeader(ReadTecFileStream,
246 *IVersion,
247 FALSE,
248 NumZones,
249 NumVars,
250 (SmInteger_t *)NULL,
251 DataSetTitle,
252 (Text_s **)NULL,
253 (Geom_s **)NULL,
254 (StringList_pa **)NULL,
255 UserRec,
256 (AuxData_pa *)NULL,
257 &IsVarCellCentered,
258 (Boolean_t *)NULL,
259 (Boolean_t *)NULL,
260 &ZoneSpecList,
261 VarNames,
262 (ArrayList_pa *)NULL,
263 (Set_pa *)NULL,
264 &FNNumBndryConns,
265 (DataFileType_e *)NULL);
269 if (InputIsOk)
271 if (*NumZones == 0)
272 *NumVars = 0;
273 else if (*IVersion > 112)
276 * This may not be true but we put it hear to remind us to make
277 * updates to this code when we change the version number.
279 ErrMsg(translate("ReadTec does not yet support version %d "
280 "Tecplot binary data files."), *IVersion);
281 InputIsOk = FALSE;
283 else if (!GetHeaderInfoOnly)
285 EntIndex_t Z;
286 for (Z = 0; Z < *NumZones && InputIsOk; Z++)
288 InputIsOk = (MemberCount(IsVarCellCentered[Z]) == 0);
289 if (!InputIsOk)
290 ErrMsg(translate("Cell centered data not supported by ReadTec."));
295 if (IsVarCellCentered != NULL)
297 EntIndex_t Z;
298 for (Z = 0; Z < *NumZones; Z++)
299 DeallocSet(&IsVarCellCentered[Z]);
300 FREE_ARRAY(IsVarCellCentered, "Array of IsVarCellCentered sets");
303 if (InputIsOk)
305 EntIndex_t Z;
307 * Allocate space for the zone info pieces.
309 if (ZoneNames)
310 *ZoneNames = StringListAlloc();
311 if (NumPtsI)
312 *NumPtsI = ALLOC_ARRAY(*NumZones, LgIndex_t, "numptsi");
313 if (NumPtsJ)
314 *NumPtsJ = ALLOC_ARRAY(*NumZones, LgIndex_t, "numptsj");
315 if (NumPtsK)
316 *NumPtsK = ALLOC_ARRAY(*NumZones, LgIndex_t, "numptsk");
317 if (ZoneType)
318 *ZoneType = ALLOC_ARRAY(*NumZones, ZoneType_e, "zonetype");
319 for (Z = 0; Z < *NumZones; Z++)
321 ZoneSpec_s *ZoneSpec = GetZoneSpec(ZoneSpecList, Z);
322 if (ZoneSpec != NULL)
324 if (ZoneNames && *ZoneNames)
325 StringListAppendString(*ZoneNames, ZoneSpec->Name);
327 if (NumPtsI && *NumPtsI)
328 (*NumPtsI)[Z] = ZoneSpec->NumPtsI;
330 if (NumPtsJ && *NumPtsJ)
331 (*NumPtsJ)[Z] = ZoneSpec->NumPtsJ;
333 if (NumPtsK && *NumPtsK)
334 (*NumPtsK)[Z] = ZoneSpec->NumPtsK;
336 if (ZoneType && *ZoneType)
337 (*ZoneType)[Z] = ZoneSpec->Type;
339 else
341 if (ZoneNames && *ZoneNames)
342 StringListAppendString(*ZoneNames, NULL);
344 if (NumPtsI && *NumPtsI)
345 (*NumPtsI)[Z] = 0;
347 if (NumPtsJ && *NumPtsJ)
348 (*NumPtsJ)[Z] = 0;
350 if (NumPtsK && *NumPtsK)
351 (*NumPtsK)[Z] = 0;
353 if (ZoneType && *ZoneType)
354 (*ZoneType)[Z] = ZoneType_Invalid;
358 if (!GetHeaderInfoOnly && InputIsOk && (*NumZones > 0))
360 EntIndex_t *VarSharesFromZone = NULL; /* [NumVars] */
361 Boolean_t *IsVarPassive = NULL; /* [NumVars] */
362 EntIndex_t *ConnectivitySharesFromZone = NULL; /* [NumZones] */
363 FieldDataType_e *VarType = NULL;
364 int CurZone;
365 int CurVar;
366 LgIndex_t NumIPts = 0;
367 LgIndex_t NumJPts = 0;
368 LgIndex_t NumKPts = 0;
369 LgIndex_t TotalNumPts;
370 LgIndex_t I, J;
372 if ((*NumZones > 0) && !RawDataSpaceAllocated)
374 *VDataBase = ALLOC_ARRAY(*NumZones * (*NumVars), double *, "vdatabase array");
375 if (*VDataBase == NULL)
377 ErrMsg(translate("Cannot allocate space for field data"));
378 InputIsOk = FALSE;
380 else
382 int I;
383 for (I = 0; I < *NumZones*(*NumVars); I++)
384 (*VDataBase)[I] = NULL;
387 if (InputIsOk)
389 *NodeMap = ALLOC_ARRAY(*NumZones, NodeMap_t *, "nodemap array");
390 if (*NodeMap == NULL)
392 ErrMsg(translate("Cannot allocate space for nodemap"));
393 InputIsOk = FALSE;
395 else
397 int I;
398 for (I = 0; I < *NumZones; I++)
399 (*NodeMap)[I] = NULL;
404 if (InputIsOk)
406 VarType = ALLOC_ARRAY(*NumVars + 1, FieldDataType_e, "Var Type");
407 VarSharesFromZone = ALLOC_ARRAY(*NumVars + 1, EntIndex_t, "VarSharesFromZone");
408 IsVarPassive = ALLOC_ARRAY(*NumVars + 1, Boolean_t, "IsVarPassive");
410 ConnectivitySharesFromZone = ALLOC_ARRAY(*NumZones, EntIndex_t, "ConnectivitySharesFromZone");
411 InputIsOk = (VarType != NULL &&
412 VarSharesFromZone != NULL &&
413 IsVarPassive != NULL &&
414 ConnectivitySharesFromZone != NULL);
417 /* for each zone */
418 for (CurZone = 0; CurZone < *NumZones && InputIsOk; CurZone++)
420 double X1 = GetNextValue(ReadTecFileStream, FieldDataType_Float, 0.0, 1000.0, &InputIsOk);
421 if (InputIsOk && (X1 == ZoneMarker))
423 ZoneSpec_s *CurZoneSpec = GetZoneSpec(ZoneSpecList, CurZone);
424 Boolean_t ZoneIsFinite = (CurZoneSpec->Type != ZoneType_Ordered);
425 Boolean_t ZoneIsFEPoly = (CurZoneSpec->Type == ZoneType_FEPolygon ||
426 CurZoneSpec->Type == ZoneType_FEPolyhedron);
427 Boolean_t InBlockFormat = CurZoneSpec->ZoneLoadInfo.IsInBlockFormat;
428 for (J = 0; J < *NumVars; J++)
430 VarSharesFromZone[J] = -1; /* eumulate DupVar: no DupVar */
431 VarType[J] = FieldDataType_Float;
432 IsVarPassive[J] = FALSE;
435 /* dupvars */
436 if (*IVersion > 45 && *IVersion < 101 && InputIsOk)
438 EntIndex_t NumDupVars, ZZ;
440 NumDupVars = (EntIndex_t)GetIoFileInt(ReadTecFileStream, *IVersion, 0, (LgIndex_t) * NumVars, &InputIsOk);
441 for (J = 0; J < NumDupVars; J++)
443 ZZ = (EntIndex_t)GetIoFileInt(ReadTecFileStream, *IVersion, 0, *NumVars, &InputIsOk) - 1;
444 VarSharesFromZone[ZZ] = CurZone - 1; /* emulate DupVar: share from previous zone */
446 /* Can't duplicate from the first zone */
447 if ((NumDupVars > 0) && (CurZone == 0))
449 ErrMsg(translate("Cannot duplicate variables from the first zone since there are "
450 "no previous zones to duplicate from."));
451 InputIsOk = FALSE;
455 /* get the data type for each variable */
456 if (*IVersion >= 70 && InputIsOk)
458 for (J = 0; J < *NumVars; J++)
460 VarType[J] = (FieldDataType_e)GetIoFileInt(ReadTecFileStream, *IVersion,
462 (LgIndex_t)FieldDataType_Bit,
463 &InputIsOk);
464 if (!InputIsOk)
466 ErrMsg(translate("Invalid data type - binary input file corrupted"));
467 InputIsOk = FALSE;
472 if (InputIsOk)
474 NumIPts = CurZoneSpec->NumPtsI;
475 NumJPts = CurZoneSpec->NumPtsJ;
476 NumKPts = CurZoneSpec->NumPtsK;
479 if (ZoneIsFinite)
480 TotalNumPts = NumIPts;
481 else
482 TotalNumPts = (NumIPts * NumJPts * NumKPts);
484 for (CurVar = 0; CurVar < *NumVars && InputIsOk; CurVar++)
486 if (!RawDataSpaceAllocated && TotalNumPts >= 1)
489 * The calling program did not allocate space for the
490 * data so do it here.
492 (*VDataBase)[CurVar+CurZone*(*NumVars)] =
493 ALLOC_ARRAY(TotalNumPts, double, "raw data");
497 if (*IVersion >= 105 && InputIsOk)
499 /* passive variables */
500 if ((Boolean_t)GetIoFileInt(ReadTecFileStream, *IVersion, 0, 1, &InputIsOk) && InputIsOk)
502 for (CurVar = 0; CurVar < *NumVars && InputIsOk; CurVar++)
504 IsVarPassive[CurVar] = (Boolean_t)GetIoFileInt(ReadTecFileStream,
505 *IVersion,
506 0, 1, &InputIsOk);
511 if (*IVersion >= 101 && InputIsOk)
513 /* variable sharing: equivalent to DupVar for ReadTec */
514 if ((Boolean_t)GetIoFileInt(ReadTecFileStream, *IVersion, 0, 1, &InputIsOk) && InputIsOk)
516 for (CurVar = 0; CurVar < *NumVars && InputIsOk; CurVar++)
518 EntIndex_t SharedZone = GetIoFileInt(ReadTecFileStream, *IVersion,
519 -1, MaxNumZonesOrVars - 1,
520 &InputIsOk);
521 if (SharedZone != -1 && InputIsOk)
522 VarSharesFromZone[CurVar] = SharedZone;
526 /* face neighbor or FE node connectivity sharing */
527 if (InputIsOk)
529 EntIndex_t SharedZone = GetIoFileInt(ReadTecFileStream, *IVersion,
530 -1, MaxNumZonesOrVars - 1,
531 &InputIsOk);
532 if (InputIsOk)
533 ConnectivitySharesFromZone[CurZone] = SharedZone;
538 * Non-shared variable min/max (but not for Zombie zones).
540 if (*IVersion >= 103 && InputIsOk)
542 for (CurVar = 0; CurVar < *NumVars && InputIsOk; CurVar++)
544 if (VarSharesFromZone[CurVar] == -1 && !IsVarPassive[CurVar])
547 * Currently ReadTec doesn't do anything with the
548 * min/max values.
550 GetNextValue(ReadTecFileStream, FieldDataType_Double,
551 -LARGEDOUBLE, LARGEDOUBLE,
552 &InputIsOk);
553 GetNextValue(ReadTecFileStream, FieldDataType_Double,
554 -LARGEDOUBLE, LARGEDOUBLE,
555 &InputIsOk);
560 if (InBlockFormat)
562 CurVar = -1;
563 while (InputIsOk && ((CurVar + 1) < *NumVars))
565 CurVar++;
566 if ((CurVar < *NumVars) && (TotalNumPts > 0))
568 double *CurVPtr = (*VDataBase)[CurVar+CurZone*(*NumVars)];
569 J = 0;
570 if (VarSharesFromZone[CurVar] != -1)
572 LgIndex_t M;
573 EntIndex_t SourceZone = VarSharesFromZone[CurVar];
574 double *SourceVPtr = (*VDataBase)[CurVar+SourceZone*(*NumVars)];
575 for (M = 0; M < TotalNumPts; M++)
576 CurVPtr[M] = SourceVPtr[M];
578 else if (!IsVarPassive[CurVar])
580 LocalReadBlock(ReadTecFileStream,
581 CurVPtr,
582 VarType[CurVar],
583 TotalNumPts,
584 &InputIsOk);
588 if (!InputIsOk)
589 ErrMsg(translate("Invalid raw data section of binary file"));
591 else if (TotalNumPts > 0)
594 * Zone is not empty and is in POINT format
596 J = -1;
597 if (InputIsOk)
599 LgIndex_t N;
600 N = 0;
601 while (InputIsOk && (N < TotalNumPts))
603 EntIndex_t CurVar;
604 for (CurVar = 0; InputIsOk && (CurVar < *NumVars); CurVar++)
606 double *CurVPtr = (*VDataBase)[CurVar+CurZone*(*NumVars)];
607 if (VarSharesFromZone[CurVar] != -1)
609 EntIndex_t SourceZone = VarSharesFromZone[CurVar];
610 double *SourceVPtr = (*VDataBase)[CurVar+SourceZone*(*NumVars)];
611 CurVPtr[N] = SourceVPtr[N];
613 else if (!IsVarPassive[CurVar])
615 double D = GetNextValue(ReadTecFileStream,
616 VarType[CurVar],
617 -LARGEDOUBLE,
618 LARGEDOUBLE,
619 &InputIsOk);
621 if (InputIsOk && CurVPtr)
622 CurVPtr[N] = D;
626 if (!InputIsOk)
627 ErrMsg(translate("Binary datafile corrupted!"));
628 N++;
633 if (InputIsOk && *IVersion < 101)
635 if (ZoneIsFinite)
638 * Pre-version 101 had FE connectivity sharing,
639 * FECONNECT, information here.
641 Boolean_t DupConnectivity;
642 if (*IVersion > 61)
643 DupConnectivity = GetIoFileInt(ReadTecFileStream, *IVersion, 0, 1, &InputIsOk);
644 else
645 DupConnectivity = FALSE;
647 if (DupConnectivity)
648 ConnectivitySharesFromZone[CurZone] = CurZone - 1; /* previous zone */
649 else
650 ConnectivitySharesFromZone[CurZone] = -1;
652 else
653 ConnectivitySharesFromZone[CurZone] = -1;
656 if (InputIsOk && ZoneIsFinite && !ZoneIsFEPoly)
658 Boolean_t SkipNodemap;
659 NodeMap_t *NM = NULL;
660 NodeMap_t *ONM = NULL;
662 * Allocate the nodemap ptr if necessary Note that if
663 * RawDataSpaceAllocated is TRUE then (*NodeMap)[CurZone]
664 * can either contain a valid address (read the connectivity
665 * list) or be NULL (skip the list).
667 if (!RawDataSpaceAllocated && NumKPts*NumJPts >= 1)
669 (*NodeMap)[CurZone] = ALLOC_ARRAY(NumKPts * NumJPts, NodeMap_t, "node map");
670 if ((*NodeMap)[CurZone] == NULL)
671 ErrMsg(translate("Cannot allocate space for connectivity list",
672 "See the Tecplot User's Manual for a definition of 'connectivity list'"));
675 if (InputIsOk)
676 NM = (*NodeMap)[CurZone];
678 SkipNodemap = (NM == NULL);
680 if (InputIsOk && ConnectivitySharesFromZone[CurZone] != -1)
682 EntIndex_t SourceZone = ConnectivitySharesFromZone[CurZone];
683 if (SourceZone >= CurZone)
685 ErrMsg(translate("Zone %d is attempting to share connectivity "
686 "with a zone that has not yet been loaded."),
687 CurZone + 1);
688 InputIsOk = FALSE;
690 else
692 ONM = (*NodeMap)[SourceZone];
693 if (ONM == NULL)
695 ErrMsg(translate("Zone %d is attempting to share connectivity "
696 "with a zone that is not finite element."),
697 CurZone + 1);
698 InputIsOk = FALSE;
703 if (InputIsOk)
705 /* load the FE node connectivity */
706 for (J = 0; J < NumJPts; J++)
707 for (I = 0; I < NumKPts; I++)
709 LgIndex_t M;
710 LgIndex_t L = J * NumKPts + I;
711 if (ConnectivitySharesFromZone[CurZone] != -1)
712 M = ONM[L];
713 else
714 M = GetNextI(ReadTecFileStream, &InputIsOk) - 1;
715 if (!SkipNodemap)
716 NM[L] = M;
721 /* skip over the face neighbor connectivity */
722 if (*IVersion >= 101 && InputIsOk)
724 EntIndex_t SharedZone = ConnectivitySharesFromZone[CurZone];
725 if (SharedZone == -1 && FNNumBndryConns[CurZone] != 0)
727 LgIndex_t Connection = 0;
728 while (Connection < FNNumBndryConns[CurZone] && InputIsOk)
731 * Face neighbor connection have the following format for both
732 * ASCII and binary:
734 * FaceNeighborMode_LocalOneToOne 3 cz,fz,cz
735 * FaceNeighborMode_LocalOneToMany nz+4 cz,fz,oz,nz,cz1,cz2,...,czn
736 * FaceNeighborMode_GlobalOneToOne 4 cz,fz,ZZ,CZ
737 * FaceNeighborMode_GlobalOneToMany 2*nz+4 cz,fz,oz,nz,ZZ1,CZ1,ZZ2,CZ2,...,ZZn,CZn
739 * Where:
740 * cz = cell in current zone
741 * fz = face of cell in current zone
742 * oz = face obsuration flag (only applies to one-to-many):
743 * 0 = face partially obscured
744 * 1 = face entirely obscured
745 * nz = number of cell or zone/cell associations (only applies to one-to-many)
746 * ZZ = remote Zone
747 * CZ = cell in remote zone
749 (void)GetNextI(ReadTecFileStream, &InputIsOk); /* read cz */
750 if (!InputIsOk)
751 ErrMsg(translate("Unexpected end-of-file while reading face neighbor data."));
753 (void)GetNextI(ReadTecFileStream, &InputIsOk); /* read fz */
755 if (InputIsOk)
758 * read FaceNeighborMode_LocalOneToOne: cz ||
759 * FaceNeighborMode_LocalOneToMany: oz ||
760 * FaceNeighborMode_GlobalOneToOne: ZZ ||
761 * FaceNeighborMode_GlobalOneToMany: oz
763 if (CurZoneSpec->FNMode == FaceNeighborMode_LocalOneToOne)
764 (void)GetNextI(ReadTecFileStream, &InputIsOk);
765 else if (CurZoneSpec->FNMode == FaceNeighborMode_LocalOneToMany)
766 (void)GetNextI(ReadTecFileStream, &InputIsOk);
767 else if (CurZoneSpec->FNMode == FaceNeighborMode_GlobalOneToOne)
768 (void)GetNextI(ReadTecFileStream, &InputIsOk);
769 else if (CurZoneSpec->FNMode == FaceNeighborMode_GlobalOneToMany)
770 (void)GetNextI(ReadTecFileStream, &InputIsOk);
771 else
772 CHECK(FALSE);
774 if (CurZoneSpec->FNMode != FaceNeighborMode_LocalOneToOne && InputIsOk)
776 LgIndex_t NumAssociations = 0;
778 * read FaceNeighborMode_LocalOneToMany: nz ||
779 * FaceNeighborMode_GlobalOneToOne: CZ ||
780 * FaceNeighborMode_GlobalOneToMany: nz
782 if (CurZoneSpec->FNMode == FaceNeighborMode_LocalOneToMany)
783 NumAssociations = GetNextI(ReadTecFileStream, &InputIsOk);
784 else if (CurZoneSpec->FNMode == FaceNeighborMode_GlobalOneToOne)
785 (void)GetNextI(ReadTecFileStream, &InputIsOk);
786 else if (CurZoneSpec->FNMode == FaceNeighborMode_GlobalOneToMany)
787 NumAssociations = GetNextI(ReadTecFileStream, &InputIsOk);
788 else
789 CHECK(FALSE);
791 if (CurZoneSpec->FNMode != FaceNeighborMode_GlobalOneToOne && InputIsOk)
793 LgIndex_t Assoc;
794 if (CurZoneSpec->FNMode == FaceNeighborMode_LocalOneToMany)
795 for (Assoc = 0; Assoc < NumAssociations && InputIsOk; Assoc++)
796 (void)GetNextI(ReadTecFileStream, &InputIsOk); /* read czn */
797 else if (CurZoneSpec->FNMode == FaceNeighborMode_GlobalOneToMany)
798 for (Assoc = 0; Assoc < NumAssociations && InputIsOk; Assoc++)
800 (void)GetNextI(ReadTecFileStream, &InputIsOk); /* read ZZn */
801 (void)GetNextI(ReadTecFileStream, &InputIsOk); /* read CZn */
803 else
804 CHECK(FALSE);
806 if (InputIsOk)
807 Connection += NumAssociations;
809 else if (InputIsOk) /* CurZoneSpec->FNMode == FaceNeighborMode_GlobalOneToOne */
810 Connection += 1;
812 else if (InputIsOk) /* CurZoneSpec->FNMode == FaceNeighborMode_LocalOneToOne */
813 Connection += 1;
815 if (!InputIsOk)
816 ErrMsg(translate("Corrupt input file: invalid face neighbors."));
820 }/* face neighbor connectivity */
821 /* skip over face map section */
822 if (ZoneIsFEPoly &&
823 *IVersion >= 110 &&
824 ConnectivitySharesFromZone[CurZone] != -1 &&
825 InputIsOk)
827 if (!InBlockFormat)
829 ErrMsg(translate("Poly zones must be in block format"));
830 InputIsOk = FALSE;
832 if (InputIsOk)
834 HgIndex_t NumFaces = CurZoneSpec->NumPtsK;
835 if (*IVersion == 110) // ...version 111 moved these to the zone header
837 CurZoneSpec->NumFaceNodes = GetNextI(ReadTecFileStream, &InputIsOk);
838 CurZoneSpec->NumFaceBndryFaces = GetNextI(ReadTecFileStream, &InputIsOk);
839 CurZoneSpec->NumFaceBndryItems = GetNextI(ReadTecFileStream, &InputIsOk);
841 HgIndex_t TotalNumFaceNodes = CurZoneSpec->NumFaceNodes;
842 HgIndex_t TotalNumBndryFaces = CurZoneSpec->NumFaceBndryFaces;
843 HgIndex_t TotalNumBndryItems = CurZoneSpec->NumFaceBndryItems;
844 if (CurZoneSpec->Type == ZoneType_FEPolyhedron)
845 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, NumFaces + 1, &InputIsOk);
846 if (InputIsOk)
847 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, TotalNumFaceNodes, &InputIsOk);
848 if (InputIsOk)
849 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, NumFaces, &InputIsOk);
850 if (InputIsOk)
851 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, NumFaces, &InputIsOk);
852 if (TotalNumBndryFaces > 0)
854 if (InputIsOk)
855 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, TotalNumBndryFaces + 1, &InputIsOk);
856 if (InputIsOk)
857 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, TotalNumBndryItems, &InputIsOk);
858 if (InputIsOk)
860 if (*IVersion >= 112)
861 ReadInt32Block(ReadTecFileStream, FALSE, NULL, 0, TotalNumBndryItems, &InputIsOk);
862 else
863 ReadInt16Block(ReadTecFileStream, FALSE, NULL, 0, TotalNumBndryItems, &InputIsOk);
867 }/* face map section */
869 else
871 ErrMsg(translate("Corrupt input file"));
872 InputIsOk = FALSE;
876 if (VarSharesFromZone)
877 FREE_ARRAY(VarSharesFromZone, "VarSharesFromZone");
878 if (IsVarPassive)
879 FREE_ARRAY(IsVarPassive, "IsVarPassive");
880 if (ConnectivitySharesFromZone)
881 FREE_ARRAY(ConnectivitySharesFromZone, "ConnectivitySharesFromZone");
882 if (VarType)
883 FREE_ARRAY(VarType, "VarType");
885 if (!InputIsOk && !RawDataSpaceAllocated)
887 int I;
888 if (*VDataBase)
890 for (I = 0; I < *NumZones*(*NumVars); I++)
892 if ((*VDataBase)[I])
893 FREE_ARRAY((*VDataBase)[I], "vdatabase array");
895 FREE_ARRAY(*VDataBase, "vdatabase pointer array");
899 if (*NodeMap)
901 for (I = 0; I < *NumZones; I++)
903 if ((*NodeMap)[I])
904 FREE_ARRAY((*NodeMap)[I], "connectivity list");
906 FREE_ARRAY(*NodeMap, "connectivity pointer array");
909 } /*Reading Raw Data*/
911 if (FNNumBndryConns != NULL)
912 FREE_ARRAY(FNNumBndryConns, "FNNumBndryConns");
913 if (ZoneSpecList)
914 ArrayListDealloc(&ZoneSpecList, ZoneSpecItemDestructor, 0);
916 if (ReadTecFileStream)
918 #if defined TECPLOTKERNEL
919 /* CORE SOURCE CODE REMOVED */
920 #else
921 TP_FCLOSE(ReadTecFileStream->File);
922 free(ReadTecFileStream);
923 #endif
925 return (InputIsOk);
929 void * STDCALL TecAlloc(size_t size)
931 return (void *)ALLOC_ARRAY(size, char, "TecAlloc");
934 void STDCALL TecFree(void *ptr)
936 /* Hack to remove delete warning... */
937 char *Tmp = (char *)ptr;
938 FREE_ARRAY(Tmp, "TecAlloc");