Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / tecsrc / dataset0.cpp
blob138e064bb1387d2aba08b346720c8d4788c3cc53
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
29 ******************************************************************
30 ******************************************************************
31 ******* ********
32 ****** (C) 1988-2008 Tecplot, Inc. *******
33 ******* ********
34 ******************************************************************
35 ******************************************************************
38 #define DATASET0MODULE
39 #include "GLOBAL.h"
40 #include "TASSERT.h"
41 #include "Q_UNICODE.h"
42 #include "ALLOC.h"
43 #include "ARRLIST.h"
44 #include "DATASET.h"
45 #include "SET.h"
46 #include "DATASHR.h"
47 #include "FILESTREAM.h"
48 #if defined TECPLOTKERNEL
49 /* CORE SOURCE CODE REMOVED */
50 #endif
51 #include "Q_MSG.h"
52 #include "DATASET0.h"
54 using namespace tecplot::strutil;
55 #if defined TECPLOTKERNEL
56 /* CORE SOURCE CODE REMOVED */
57 #endif
60 * Low level dataset functions. No references to zones, vars or
61 * the DataSet_s master structure here.
67 void OutOfMemoryMsg(void)
69 ErrMsg(translate("Cannot allocate enough memory for this operation."));
70 } /* OutOfMemoryMsg() */
73 /**
75 FieldData_pa FieldDataAlloc(void)
77 FieldData_pa Result;
79 Result = (FieldData_pa)ALLOC_ITEM(struct _FieldData_a, "FieldDataPtr");
80 if (Result != NULL)
82 Result->Data = NULL;
84 # if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
85 /* CORE SOURCE CODE REMOVED */
86 # else /* ...for TecIO only */
87 Result->GetValueCallback[0] = NULL;
88 Result->SetValueCallback[0] = NULL;
89 # endif
91 # if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
92 /* CORE SOURCE CODE REMOVED */
93 # endif
95 Result->Type = FieldDataType_Invalid;
96 Result->ValueLocation = ValueLocation_Invalid;
97 Result->RefCount = 1; /* self */
98 Result->VarShareRefCount = 1; /* self */
99 Result->NumValues = 0;
100 # if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
101 /* CORE SOURCE CODE REMOVED */
102 # endif
105 ENSURE(VALID_REF(Result) || Result == NULL);
106 return Result;
110 * Most clients should not call this function but FieldDataCleanup() instead.
111 * An exception to this would be Tecplot's own storable load-on-demand
112 * functions.
114 void FieldDataDeallocData(FieldData_pa FieldData)
116 REQUIRE(VALID_REF(FieldData));
118 #if defined TECPLOTKERNEL
119 /* CORE SOURCE CODE REMOVED */
120 #endif
121 if (FieldData->Data != NULL)
123 /* Hack to remove 'deleting void* is undefined' warning... */
124 char *Tmp = (char *)FieldData->Data;
125 FREE_ARRAY(Tmp, "FieldData _Data");
126 FieldData->Data = NULL;
129 #if defined TECPLOTKERNEL
130 /* CORE SOURCE CODE REMOVED */
131 #endif
133 ENSURE(FieldData->Data == NULL);
136 #if defined TECPLOTKERNEL
137 /* CORE SOURCE CODE REMOVED */
138 #endif
140 #if defined TECPLOTKERNEL
141 /* CORE SOURCE CODE REMOVED */
142 #endif
144 #if defined TECPLOTKERNEL
145 /* CORE SOURCE CODE REMOVED */
146 #endif
148 #if defined TECPLOTKERNEL
149 /* CORE SOURCE CODE REMOVED */
150 #endif
152 #if defined TECPLOTKERNEL
153 /* CORE SOURCE CODE REMOVED */
154 #endif
156 #if defined TECPLOTKERNEL
157 /* CORE SOURCE CODE REMOVED */
158 #endif
160 #if defined TECPLOTKERNEL
161 /* CORE SOURCE CODE REMOVED */
162 #endif
164 #if defined TECPLOTKERNEL
165 /* CORE SOURCE CODE REMOVED */
166 #endif
168 #if defined TECPLOTKERNEL
169 /* CORE SOURCE CODE REMOVED */
170 #endif
172 #if defined TECPLOTKERNEL
173 /* CORE SOURCE CODE REMOVED */
174 #endif
176 #if defined TECPLOTKERNEL
177 /* CORE SOURCE CODE REMOVED */
178 #endif
180 #if defined TECPLOTKERNEL
181 /* CORE SOURCE CODE REMOVED */
182 #endif
184 #if defined TECPLOTKERNEL
185 /* CORE SOURCE CODE REMOVED */
186 #endif
188 #if defined TECPLOTKERNEL
189 /* CORE SOURCE CODE REMOVED */
190 #endif
192 #if defined TECPLOTKERNEL
193 /* CORE SOURCE CODE REMOVED */
194 #endif
196 #if defined TECPLOTKERNEL
197 /* CORE SOURCE CODE REMOVED */
198 #endif
202 void FieldDataCleanup(FieldData_pa FieldData)
204 REQUIRE(VALID_REF(FieldData));
206 # if defined TECPLOTKERNEL
207 /* CORE SOURCE CODE REMOVED */
208 # else
209 FieldDataDeallocData(FieldData);
210 # endif
215 void FieldDataDealloc(FieldData_pa *FieldData,
216 Boolean_t DoTrackVarSharing)
218 REQUIRE(VALID_REF(FieldData));
219 REQUIRE(VALID_REF(*FieldData) || *FieldData == NULL);
220 REQUIRE(IMPLICATION(*FieldData != NULL,
221 IsStructureReferenced(*FieldData)));
222 REQUIRE(IMPLICATION(*FieldData != NULL && DoTrackVarSharing,
223 IsVarStructureReferenced(*FieldData)));
224 REQUIRE(VALID_BOOLEAN(DoTrackVarSharing));
225 REQUIRE(IMPLICATION(*FieldData != NULL,
226 (*FieldData)->RefCount >= (*FieldData)->VarShareRefCount));
228 if (*FieldData != NULL)
230 if (DoTrackVarSharing)
231 DecVarStructureReference(*FieldData);
232 DecStructureReference(*FieldData);
233 if (!IsStructureReferenced(*FieldData))
235 FieldDataCleanup(*FieldData);
237 #if defined TECPLOTKERNEL
238 /* CORE SOURCE CODE REMOVED */
239 #endif
241 FREE_ITEM(*FieldData, "field data");
243 *FieldData = NULL;
246 ENSURE(*FieldData == NULL);
249 #if defined TECPLOTKERNEL
250 /* CORE SOURCE CODE REMOVED */
251 #if !defined NDEBUG || defined CHECKED_BUILD
252 #endif
253 #endif
255 #if defined TECPLOTKERNEL
256 /* CORE SOURCE CODE REMOVED */
257 #if !defined NDEBUG || defined CHECKED_BUILD
258 #endif
259 #endif
261 #if defined TECPLOTKERNEL
262 /* CORE SOURCE CODE REMOVED */
263 #endif
265 template <typename T>
266 static void copyTypedValueArray(void* DstArray,
267 LgIndex_t DstStart,
268 void* SrcArray,
269 LgIndex_t SrcStart,
270 LgIndex_t SrcEnd)
272 T* SrcPtr = ((T*)SrcArray) + SrcStart;
273 T* DstPtr = ((T*)DstArray) + DstStart;
274 size_t numBytes = sizeof(T) * (SrcEnd - SrcStart + 1);
275 memcpy(DstPtr, SrcPtr, numBytes);
278 * DstArray and SrcArray are aligned on proper word boundaries.
280 void CopyTypedValueArray(FieldDataType_e ValueType,
281 void *DstArray,
282 LgIndex_t DstStart,
283 void *SrcArray,
284 LgIndex_t SrcStart,
285 LgIndex_t SrcEnd)
287 REQUIRE(VALID_FIELD_DATA_TYPE(ValueType) &&
288 ValueType != FieldDataType_Bit);
289 REQUIRE(VALID_REF(DstArray));
290 REQUIRE(DstStart >= 0);
291 REQUIRE(VALID_REF(SrcArray));
292 REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd);
293 REQUIRE(DstArray != SrcArray);
295 switch (ValueType)
297 case FieldDataType_Int64 : CHECK(FALSE); /* Future work: remove check */
298 case FieldDataType_Double :
300 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
301 copyTypedValueArray<UInt64_t>(DstArray,
302 DstStart,
303 SrcArray,
304 SrcStart,
305 SrcEnd);
306 } break;
307 case FieldDataType_Float :
308 case FieldDataType_Int32 :
310 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
311 copyTypedValueArray<UInt32_t>(DstArray,
312 DstStart,
313 SrcArray,
314 SrcStart,
315 SrcEnd);
316 } break;
317 case FieldDataType_Int16 :
319 CHECK(sizeof(UInt16_t) == 2);
320 copyTypedValueArray<UInt16_t>(DstArray,
321 DstStart,
322 SrcArray,
323 SrcStart,
324 SrcEnd);
325 } break;
326 case FieldDataType_Byte :
328 copyTypedValueArray<Byte_t>(DstArray,
329 DstStart,
330 SrcArray,
331 SrcStart,
332 SrcEnd);
333 } break;
334 default : CHECK(FALSE);
339 * SrcArray is aligned on proper word boundaries.
341 void SwapBytesInTypedValueArray(FieldDataType_e ValueType,
342 void *SrcArray,
343 LgIndex_t SrcStart,
344 LgIndex_t SrcEnd,
345 LgIndex_t SrcSkip)
347 REQUIRE(VALID_FIELD_DATA_TYPE(ValueType) &&
348 ValueType != FieldDataType_Bit);
349 REQUIRE(VALID_REF(SrcArray));
350 REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd);
351 REQUIRE(SrcSkip > 0);
353 switch (ValueType)
355 case FieldDataType_Int64: CHECK(FALSE); /* Future work: remove CHECK */
356 case FieldDataType_Double:
358 /* swap 8 bytes blocks */
359 UInt64_t *SrcPtr = ((UInt64_t *)SrcArray) + SrcStart;
360 UInt64_t *SrcPtrEnd = ((UInt64_t *)SrcArray) + SrcEnd;
361 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
362 while (SrcPtr <= SrcPtrEnd)
364 REVERSE_8_BYTES(SrcPtr);
365 SrcPtr += SrcSkip;
367 } break;
368 case FieldDataType_Float:
369 case FieldDataType_Int32:
371 /* swap 4 bytes blocks */
372 UInt32_t *SrcPtr = ((UInt32_t *)SrcArray) + SrcStart;
373 UInt32_t *SrcPtrEnd = ((UInt32_t *)SrcArray) + SrcEnd;
374 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
375 while (SrcPtr <= SrcPtrEnd)
377 REVERSE_4_BYTES(SrcPtr);
378 SrcPtr += SrcSkip;
380 } break;
381 case FieldDataType_Int16:
383 /* swap 4 bytes blocks */
384 UInt16_t *SrcPtr = ((UInt16_t *)SrcArray) + SrcStart;
385 UInt16_t *SrcPtrEnd = ((UInt16_t *)SrcArray) + SrcEnd;
386 CHECK(sizeof(UInt16_t) == 2);
387 while (SrcPtr <= SrcPtrEnd)
389 REVERSE_2_BYTES(SrcPtr);
390 SrcPtr += SrcSkip;
392 } break;
393 case FieldDataType_Byte:
394 case FieldDataType_Bit:
396 /* nothing to do */
397 } break;
398 default: CHECK(FALSE);
403 * Same as SwapBytesInTypedValueArray, but does extra work. Doesn't assume
404 * DstArray and SrcArray are aligned on proper word boundaries.
406 void SwapBytesInUnalignedTypedValueArray(FieldDataType_e ValueType,
407 void *SrcArray,
408 LgIndex_t SrcStart,
409 LgIndex_t SrcEnd,
410 LgIndex_t SrcSkip)
412 REQUIRE(VALID_FIELD_DATA_TYPE(ValueType) &&
413 ValueType != FieldDataType_Bit);
414 REQUIRE(VALID_REF(SrcArray));
415 REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd);
416 REQUIRE(SrcSkip > 0);
418 switch (ValueType)
420 case FieldDataType_Int64: CHECK(FALSE); /* Future work: remove CHECK */
421 case FieldDataType_Double:
423 /* swap 8-byte blocks */
424 Byte_t *SrcPtr = ((Byte_t *)SrcArray) + SrcStart * sizeof(UInt64_t);
425 Byte_t *SrcPtrEnd = ((Byte_t *)SrcArray) + SrcEnd * sizeof(UInt64_t);
426 size_t byte_skip = SrcSkip * sizeof(UInt64_t);
427 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
428 while (SrcPtr <= SrcPtrEnd)
430 REVERSE_8_BYTES_1_AT_A_TIME(SrcPtr);
431 SrcPtr += byte_skip;
433 } break;
434 case FieldDataType_Float:
435 case FieldDataType_Int32:
437 /* swap 4-byte blocks */
438 Byte_t *SrcPtr = ((Byte_t *)SrcArray) + SrcStart * sizeof(UInt32_t);
439 Byte_t *SrcPtrEnd = ((Byte_t *)SrcArray) + SrcEnd * sizeof(UInt32_t);
440 size_t byte_skip = SrcSkip * sizeof(UInt32_t);
441 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
442 while (SrcPtr <= SrcPtrEnd)
444 REVERSE_4_BYTES_1_AT_A_TIME(SrcPtr);
445 SrcPtr += byte_skip;
447 } break;
448 case FieldDataType_Int16:
450 /* swap 2-byte blocks */
451 Byte_t *SrcPtr = ((Byte_t *)SrcArray) + SrcStart * sizeof(UInt16_t);
452 Byte_t *SrcPtrEnd = ((Byte_t *)SrcArray) + SrcEnd * sizeof(UInt16_t);
453 size_t byte_skip = SrcSkip * sizeof(UInt16_t);
454 CHECK(sizeof(UInt16_t) == 2);
455 while (SrcPtr <= SrcPtrEnd)
457 REVERSE_2_BYTES_1_AT_A_TIME(SrcPtr);
458 SrcPtr += byte_skip;
460 } break;
461 case FieldDataType_Byte:
462 case FieldDataType_Bit:
464 /* No swapping required. */
465 } break;
466 default: CHECK(FALSE);
471 #if defined TECPLOTKERNEL
472 /* CORE SOURCE CODE REMOVED */
473 #endif
475 #if defined TECPLOTKERNEL
476 /* CORE SOURCE CODE REMOVED */
477 #endif
479 #if defined TECPLOTKERNEL
480 /* CORE SOURCE CODE REMOVED */
481 #endif
483 #if defined TECPLOTKERNEL
484 /* CORE SOURCE CODE REMOVED */
485 #endif
487 #if defined TECPLOTKERNEL
488 /* CORE SOURCE CODE REMOVED */
489 #endif
491 #if defined TECPLOTKERNEL
492 /* CORE SOURCE CODE REMOVED */
493 #endif
495 #if defined TECPLOTKERNEL
496 /* CORE SOURCE CODE REMOVED */
497 #endif
500 #if defined TECPLOTKERNEL
501 /* CORE SOURCE CODE REMOVED */
502 #endif
504 #if defined TECPLOTKERNEL
505 /* CORE SOURCE CODE REMOVED */
506 #endif
508 #if defined TECPLOTKERNEL
509 /* CORE SOURCE CODE REMOVED */
510 #endif
512 #if defined DEBUG_FIELDVALUES
513 # define DEBUG_FIELDVALUES_BAD_VALUE 0x11
514 static unsigned char BadValueStr[] =
516 DEBUG_FIELDVALUES_BAD_VALUE,
517 DEBUG_FIELDVALUES_BAD_VALUE,
518 DEBUG_FIELDVALUES_BAD_VALUE,
519 DEBUG_FIELDVALUES_BAD_VALUE,
520 DEBUG_FIELDVALUES_BAD_VALUE,
521 DEBUG_FIELDVALUES_BAD_VALUE,
522 DEBUG_FIELDVALUES_BAD_VALUE,
523 DEBUG_FIELDVALUES_BAD_VALUE
526 * If Tecplot is responsible for managing (allocating and deallocating) the
527 * raw data then
529 # if defined TECPLOTKERNEL
530 /* CORE SOURCE CODE REMOVED */
531 # else
532 # define FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, type) \
533 ((sizeof(type) < 4) /* cannot make reliably test with less than four bytes */ || \
534 memcmp(BadValueStr,((char *)((fd)->Data))+sizeof(type)*(pt), sizeof(type)) != 0)
535 # endif
536 #else
537 # define FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, type) TRUE
538 #endif
543 * Used in macros, thus not static
545 double STDCALL GetFieldValueForFloat(const FieldData_pa fd,
546 LgIndex_t pt)
548 REQUIRE(VALID_REF(fd));
549 # if defined TECPLOTKERNEL
550 /* CORE SOURCE CODE REMOVED */
551 # endif
552 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
553 REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, float));
555 double Result = (double)GetFieldDataFloatPtr(fd)[pt];
557 return Result;
561 #if defined TECPLOTKERNEL
562 /* CORE SOURCE CODE REMOVED */
563 #endif
567 * Used in macros, thus not static
569 double STDCALL GetFieldValueForDouble(const FieldData_pa fd,
570 LgIndex_t pt)
572 REQUIRE(VALID_REF(fd));
573 # if defined TECPLOTKERNEL
574 /* CORE SOURCE CODE REMOVED */
575 # endif
576 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
577 REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, double));
579 double Result = GetFieldDataDoublePtr(fd)[pt];
581 return Result;
585 #if defined TECPLOTKERNEL
586 /* CORE SOURCE CODE REMOVED */
587 #endif
592 double STDCALL GetFieldValueForInt32(const FieldData_pa fd,
593 LgIndex_t pt)
595 REQUIRE(VALID_REF(fd));
596 # if defined TECPLOTKERNEL
597 /* CORE SOURCE CODE REMOVED */
598 # endif
599 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
600 REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int32_t));
602 double Result = (double)GetFieldDataInt32Ptr(fd)[pt];
604 return Result;
608 #if defined TECPLOTKERNEL
609 /* CORE SOURCE CODE REMOVED */
610 #endif
615 double STDCALL GetFieldValueForInt16(const FieldData_pa fd,
616 LgIndex_t pt)
618 REQUIRE(VALID_REF(fd));
619 # if defined TECPLOTKERNEL
620 /* CORE SOURCE CODE REMOVED */
621 # endif
622 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
623 REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int16_t));
625 double Result = (double)GetFieldDataInt16Ptr(fd)[pt];
627 return Result;
631 #if defined TECPLOTKERNEL
632 /* CORE SOURCE CODE REMOVED */
633 #endif
638 double STDCALL GetFieldValueForByte(const FieldData_pa fd,
639 LgIndex_t pt)
641 REQUIRE(VALID_REF(fd));
642 # if defined TECPLOTKERNEL
643 /* CORE SOURCE CODE REMOVED */
644 # endif
645 REQUIRE(fd->Type == FieldDataType_Byte);
646 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
647 REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Byte_t));
649 double Result = (double)GetFieldDataBytePtr(fd)[pt];
651 return Result;
655 #if defined TECPLOTKERNEL
656 /* CORE SOURCE CODE REMOVED */
657 #endif
662 double STDCALL GetFieldValueForBit(const FieldData_pa fd,
663 LgIndex_t pt)
665 REQUIRE(VALID_REF(fd));
666 # if defined TECPLOTKERNEL
667 /* CORE SOURCE CODE REMOVED */
668 # endif
669 REQUIRE(fd->Type == FieldDataType_Bit);
670 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
671 REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt / 8, Byte_t));
673 LgIndex_t ByteOffset = pt / 8;
674 Byte_t BitMask = (01 << (pt % 8));
676 Byte_t *byte_array = GetFieldDataBytePtr(fd);
677 double Result = (byte_array[ByteOffset] & BitMask) ? 1.0 : 0.0;
679 return Result;
683 #if defined TECPLOTKERNEL
684 /* CORE SOURCE CODE REMOVED */
685 #endif
690 FieldValueGetFunction_pf DetermineFieldDataGetFunction(FieldDataType_e DataType,
691 Boolean_t IsFragmented)
693 FieldValueGetFunction_pf Result;
695 REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
696 REQUIRE(VALID_BOOLEAN(IsFragmented));
698 #if defined TECPLOTKERNEL
699 /* CORE SOURCE CODE REMOVED */
700 #endif
702 switch (DataType)
704 case FieldDataType_Float :
706 Result = GetFieldValueForFloat;
707 } break;
708 case FieldDataType_Double :
710 Result = GetFieldValueForDouble;
711 } break;
712 case FieldDataType_Int32 :
714 Result = GetFieldValueForInt32;
715 } break;
716 case FieldDataType_Int16 :
718 Result = GetFieldValueForInt16;
719 } break;
720 case FieldDataType_Byte :
722 Result = GetFieldValueForByte;
723 } break;
724 case FieldDataType_Bit :
726 Result = GetFieldValueForBit;
727 } break;
728 default :
730 CHECK(FALSE);
731 Result = NULL; /* satisfy compiler */
732 } break;
735 return (Result);
740 static void STDCALL SetFieldValueForFloat(FieldData_pa fd,
741 LgIndex_t pt,
742 double val)
744 REQUIRE(VALID_REF(fd));
745 # if defined TECPLOTKERNEL
746 /* CORE SOURCE CODE REMOVED */
747 # endif
748 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
749 REQUIRE("val can have any value");
751 GetFieldDataFloatPtr(fd)[pt] = CONVERT_DOUBLE_TO_FLOAT(val);
753 ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, float));
757 #if defined TECPLOTKERNEL
758 /* CORE SOURCE CODE REMOVED */
759 #endif
764 static void STDCALL SetFieldValueForDouble(FieldData_pa fd,
765 LgIndex_t pt,
766 double val)
768 REQUIRE(VALID_REF(fd));
769 # if defined TECPLOTKERNEL
770 /* CORE SOURCE CODE REMOVED */
771 # endif
772 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
773 REQUIRE("val can have any value");
775 GetFieldDataDoublePtr(fd)[pt] = CLAMP_DOUBLE(val);
777 ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, double));
781 #if defined TECPLOTKERNEL
782 /* CORE SOURCE CODE REMOVED */
783 #endif
788 static void STDCALL SetFieldValueForInt32(FieldData_pa fd,
789 LgIndex_t pt,
790 double val)
792 REQUIRE(VALID_REF(fd));
793 # if defined TECPLOTKERNEL
794 /* CORE SOURCE CODE REMOVED */
795 # endif
796 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
797 REQUIRE("val can have any value");
799 GetFieldDataInt32Ptr(fd)[pt] = CONVERT_DOUBLE_TO_INT32(val);
801 ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int32_t));
805 #if defined TECPLOTKERNEL
806 /* CORE SOURCE CODE REMOVED */
807 #endif
812 static void STDCALL SetFieldValueForInt16(FieldData_pa fd,
813 LgIndex_t pt,
814 double val)
816 REQUIRE(VALID_REF(fd));
817 # if defined TECPLOTKERNEL
818 /* CORE SOURCE CODE REMOVED */
819 # endif
820 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
821 REQUIRE("val can have any value");
823 GetFieldDataInt16Ptr(fd)[pt] = CONVERT_DOUBLE_TO_INT16(val);
825 ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int16_t));
829 #if defined TECPLOTKERNEL
830 /* CORE SOURCE CODE REMOVED */
831 #endif
836 static void STDCALL SetFieldValueForByte(FieldData_pa fd,
837 LgIndex_t pt,
838 double val)
840 REQUIRE(VALID_REF(fd));
841 # if defined TECPLOTKERNEL
842 /* CORE SOURCE CODE REMOVED */
843 # endif
844 REQUIRE(fd->Type == FieldDataType_Byte);
845 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
846 REQUIRE("val can have any value");
848 if (val < 1.0)
849 GetFieldDataBytePtr(fd)[pt] = 0;
850 else if (val > 255.0)
851 GetFieldDataBytePtr(fd)[pt] = 255;
852 else
853 GetFieldDataBytePtr(fd)[pt] = (Byte_t)val;
855 ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Byte_t));
859 #if defined TECPLOTKERNEL
860 /* CORE SOURCE CODE REMOVED */
861 #endif
866 static void STDCALL SetFieldValueForBit(FieldData_pa fd,
867 LgIndex_t pt,
868 double val)
870 REQUIRE(VALID_REF(fd));
871 # if defined TECPLOTKERNEL
872 /* CORE SOURCE CODE REMOVED */
873 # endif
874 REQUIRE(fd->Type == FieldDataType_Bit);
875 REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
876 REQUIRE("val can have any value");
878 LgIndex_t ByteOffset = pt / 8;
879 Byte_t BitMask = (01 << (pt % 8));
881 if (val < 1.0)
882 GetFieldDataBytePtr(fd)[ByteOffset] &= ~BitMask;
883 else
884 GetFieldDataBytePtr(fd)[ByteOffset] |= BitMask;
886 ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt / 8, Byte_t));
890 #if defined TECPLOTKERNEL
891 /* CORE SOURCE CODE REMOVED */
892 #endif
897 FieldValueSetFunction_pf DetermineFieldDataSetFunction(FieldDataType_e DataType,
898 Boolean_t IsFragmented)
900 FieldValueSetFunction_pf Result;
902 REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
903 REQUIRE(VALID_BOOLEAN(IsFragmented));
905 #if defined TECPLOTKERNEL
906 /* CORE SOURCE CODE REMOVED */
907 #endif
909 switch (DataType)
911 case FieldDataType_Float :
913 Result = SetFieldValueForFloat;
914 } break;
915 case FieldDataType_Double :
917 Result = SetFieldValueForDouble;
918 } break;
919 case FieldDataType_Int32 :
921 Result = SetFieldValueForInt32;
922 } break;
923 case FieldDataType_Int16 :
925 Result = SetFieldValueForInt16;
926 } break;
927 case FieldDataType_Byte :
929 Result = SetFieldValueForByte;
930 } break;
931 case FieldDataType_Bit :
933 Result = SetFieldValueForBit;
934 } break;
935 default :
937 CHECK(FALSE);
938 Result = NULL; /* satisfy compiler */
939 } break;
942 return (Result);
948 Int64_t FieldDataGetBytesNeeded(LgIndex_t NumValues,
949 FieldDataType_e DataType)
951 Int64_t Result = 0; /* ...quite compiler */
953 REQUIRE(NumValues >= 0);
954 REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
956 switch (DataType)
958 case FieldDataType_Float: Result = ((Int64_t)NumValues)*sizeof(float); break;
959 case FieldDataType_Double: Result = ((Int64_t)NumValues)*sizeof(double); break;
960 case FieldDataType_Int32: Result = ((Int64_t)NumValues)*sizeof(LgIndex_t); break;
961 case FieldDataType_Int16: Result = ((Int64_t)NumValues)*sizeof(SmInteger_t); break;
962 case FieldDataType_Byte: Result = ((Int64_t)NumValues)*sizeof(Byte_t); break;
963 case FieldDataType_Bit: Result = ((Int64_t)(NumValues+7)/8)*sizeof(Byte_t); break;
964 default: CHECK(FALSE); break;
967 ENSURE(Result >= 0);
968 return Result;
972 * On the SGI, HP, and Sun machines 64 bit objects such as doubles must be 8
973 * byte aligned while on all other machines 32 bit alignment suffices. Some
974 * allow 1 byte alignment but we won't bother with that.
976 #if defined IRISX || defined HPUX || defined SUNX
977 # define SIZEOF_LARGEST_OBJECT_TO_ALIGN sizeof(Int64_t)
978 #else
979 # define SIZEOF_LARGEST_OBJECT_TO_ALIGN sizeof(Int32_t)
980 #endif
984 Boolean_t IsOffsetAlignedForFieldDataType(FieldDataType_e FieldDataType,
985 Int64_t Offset)
987 REQUIRE(VALID_FIELD_DATA_TYPE(FieldDataType));
988 REQUIRE(Offset >= 0);
990 Int64_t SizeOfType = FieldDataGetBytesNeeded(1, FieldDataType);
991 if (SizeOfType > (Int64_t)SIZEOF_LARGEST_OBJECT_TO_ALIGN)
992 SizeOfType = SIZEOF_LARGEST_OBJECT_TO_ALIGN;
994 Boolean_t HasValidAlignment = (Offset % SizeOfType == 0);
996 ENSURE(VALID_BOOLEAN(HasValidAlignment));
997 return HasValidAlignment;
1002 Int64_t GetAlignedOffsetForFieldDataType(FieldDataType_e FieldDataType,
1003 Int64_t Offset)
1005 REQUIRE(VALID_FIELD_DATA_TYPE(FieldDataType));
1006 REQUIRE(Offset >= 0);
1008 Int64_t SizeOfType = FieldDataGetBytesNeeded(1, FieldDataType);
1009 if (SizeOfType > (Int64_t)SIZEOF_LARGEST_OBJECT_TO_ALIGN)
1010 SizeOfType = SIZEOF_LARGEST_OBJECT_TO_ALIGN;
1012 Int64_t NumBytesPastAlignment = (Offset % SizeOfType);
1013 Int64_t Result = Offset - NumBytesPastAlignment;
1015 ENSURE(0 <= Result && Result <= Offset);
1016 ENSURE(IsOffsetAlignedForFieldDataType(FieldDataType, Result));
1017 return Result;
1022 void FieldDataDefineData(FieldData_pa FieldData,
1023 LgIndex_t NumValues,
1024 FieldDataType_e DataType,
1025 ValueLocation_e ValueLocation)
1027 REQUIRE(VALID_REF(FieldData));
1028 REQUIRE(NumValues >= 0);
1029 REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
1030 REQUIRE(VALID_ENUM(ValueLocation, ValueLocation_e));
1033 * Remove any old data (transformed UVW is one example that calls this
1034 * function with a non-null data pointer when switching the value location
1035 * when style changes the value location and therefore the amount of data
1036 * allocated.)
1038 FieldDataCleanup(FieldData);
1041 * The reference count is not modified here. This function only allocates the
1042 * structure and makes adjustments to the some of the members. The reference
1043 * count was initialized when the structure was initially created and the
1044 * structure may be shared before the data portion is even allocated.
1046 FieldData->NumValues = NumValues;
1047 FieldData->Type = DataType;
1048 FieldData->ValueLocation = ValueLocation;
1049 # if defined TECPLOTKERNEL
1050 /* CORE SOURCE CODE REMOVED */
1051 # else /* ...for TecIO only */
1052 FieldData->GetValueCallback[0] = (void *)DetermineFieldDataGetFunction(DataType, FALSE);
1053 FieldData->SetValueCallback[0] = (void *)DetermineFieldDataSetFunction(DataType, FALSE);
1054 #endif
1056 ENSURE(FieldData->Data == NULL);
1061 Boolean_t FieldDataAllocData(FieldData_pa FieldData,
1062 Boolean_t ShowErrMsg)
1064 REQUIRE(VALID_REF(FieldData));
1065 REQUIRE(FieldData->Type != FieldDataType_Invalid); /* ...must call FieldDataDefineData first */
1066 REQUIRE(FieldData->Data == NULL);
1067 REQUIRE(VALID_BOOLEAN(ShowErrMsg));
1070 * The size of size_t may be smaller than our unsigned 64 bit integer value
1071 * so we might have to squeeze it down possibly loosing precision.
1073 Int64_t ActualBytesNeeded = FieldDataGetBytesNeeded(FieldData->NumValues, FieldData->Type);
1074 size_t BytesToAllocate = (size_t)ActualBytesNeeded;
1077 * 64 bit architectures are effectively unlimited in their allocation size
1078 * while 32 architectures are limited to 4GB (some may limit further to 2GB
1079 * which will be borne out by the call to malloc).
1081 CHECK(sizeof(size_t) == 4 || sizeof(size_t) == 8);
1082 Boolean_t IsOk = (FieldData->NumValues <= MAXINDEX &&
1083 IMPLICATION(sizeof(size_t) == 4,
1084 ActualBytesNeeded <= (Int64_t)0xffffffff));
1085 if (IsOk)
1087 if (FieldData->NumValues > 0)
1089 FieldData->Data = (void *)ALLOC_ARRAY(BytesToAllocate, char, "FieldData's Data");
1090 #if defined DEBUG_FIELDVALUES
1092 if (FieldData->Data != NULL)
1093 memset(FieldData->Data, DEBUG_FIELDVALUES_BAD_VALUE, BytesToAllocate);
1095 #endif
1097 * For bit type data zero the last byte in the data array. We do
1098 * this because NumValues is probably not a multiple of 8 bits and
1099 * thus the valid bit values will not occupy all bits of the last
1100 * byte. By zeroing the unused bits at the end of the array we
1101 * produce consistent data files when written to disk.
1103 if (FieldData->Type == FieldDataType_Bit)
1104 ((char*)FieldData->Data)[BytesToAllocate-1] = '\0';
1106 IsOk = (FieldData->NumValues == 0 ||
1107 FieldData->Data != NULL);
1108 if (!IsOk && ShowErrMsg)
1109 OutOfMemoryMsg();
1111 else if (ShowErrMsg)
1112 ErrMsg(translate("Storage limit (%ld) exceeded for a single variable."), (long)MAXINDEX);
1114 # if defined TECPLOTKERNEL
1115 /* CORE SOURCE CODE REMOVED */
1116 # endif
1118 ENSURE(VALID_REF(FieldData->Data) || FieldData->Data == NULL);
1119 ENSURE(VALID_BOOLEAN(IsOk));
1120 return IsOk;
1123 #if defined TECPLOTKERNEL
1124 /* CORE SOURCE CODE REMOVED */
1125 #endif
1127 #if defined TECPLOTKERNEL
1128 /* CORE SOURCE CODE REMOVED */
1129 #endif
1131 #if defined TECPLOTKERNEL
1132 /* CORE SOURCE CODE REMOVED */
1133 #endif
1135 #if defined TECPLOTKERNEL
1136 /* CORE SOURCE CODE REMOVED */
1137 #endif
1139 #if defined TECPLOTKERNEL
1140 /* CORE SOURCE CODE REMOVED */
1141 #endif
1143 #if defined TECPLOTKERNEL
1144 /* CORE SOURCE CODE REMOVED */
1145 #endif
1147 #if defined TECPLOTKERNEL
1148 /* CORE SOURCE CODE REMOVED */
1149 #endif
1151 #if !defined NO_ASSERTS
1152 #if defined TECPLOTKERNEL
1153 /* CORE SOURCE CODE REMOVED */
1154 #endif
1155 #endif
1157 #if defined TECPLOTKERNEL
1158 /* CORE SOURCE CODE REMOVED */
1159 #endif
1161 #if defined TECPLOTKERNEL
1162 /* CORE SOURCE CODE REMOVED */
1163 #endif
1166 * Allocates a field data pointer with space for "num_pts" of field data type
1167 * "field_data_type" nodal values.
1169 * IMPORTANT:
1170 * This field data may NOT be used for zones but only for things like
1171 * geometries or other temporary field data that will never be placed
1172 * into a COB or zone.
1174 FieldData_pa AllocScratchNodalFieldDataPtr(LgIndex_t NumValues,
1175 FieldDataType_e Type,
1176 Boolean_t ShowErrMsg)
1178 REQUIRE(NumValues >= 0);
1179 REQUIRE(VALID_FIELD_DATA_TYPE(Type));
1180 REQUIRE(VALID_BOOLEAN(ShowErrMsg));
1182 FieldData_pa Result = FieldDataAlloc();
1183 if (Result != NULL)
1185 FieldDataDefineData(Result, NumValues, Type, ValueLocation_Nodal);
1186 if (!FieldDataAllocData(Result, ShowErrMsg))
1187 FieldDataDealloc(&Result, FALSE);
1189 else if (ShowErrMsg)
1190 OutOfMemoryMsg();
1192 ENSURE(VALID_REF(Result) || Result == NULL);
1193 # if defined TECPLOTKERNEL
1194 /* CORE SOURCE CODE REMOVED */
1195 # endif
1196 ENSURE(IMPLICATION(Result != NULL,
1197 (Result->NumValues >= 0 &&
1198 IMPLICATION(Result->NumValues != 0,
1199 VALID_REF(Result->Data)) &&
1200 VALID_FIELD_DATA_TYPE(Result->Type))));
1202 return Result;
1207 * Frees memory allocated with AllocScratchNodalFieldDataPtr().
1209 * @param ScratchFieldData
1210 * Scratch field data pointer to deallocate. This should NEVER be a field
1211 * data from a zone or COB. See note in AllocScratchNodalFieldDataPtr().
1213 void DeallocScratchNodalFieldDataPtr(FieldData_pa *FieldDataRef)
1215 FieldDataDealloc(FieldDataRef,
1216 FALSE); /* DoTrackVarSharing */
1220 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1223 FieldDataType_e GetFieldDataType_FUNC(FieldData_pa FieldData)
1225 REQUIRE(VALID_REF(FieldData));
1227 FieldDataType_e Result = GetFieldDataType_MACRO(FieldData);
1229 ENSURE(VALID_FIELD_DATA_TYPE(Result));
1230 return Result;
1232 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1235 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1238 FieldValueGetFunction_pf GetFieldDataGetFunction_FUNC(FieldData_pa FieldData)
1240 REQUIRE(VALID_REF(FieldData));
1242 FieldValueGetFunction_pf Result = GetFieldDataGetFunction_MACRO(FieldData);
1244 ENSURE(VALID_FN_REF(Result));
1245 return Result;
1247 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1250 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1253 FieldValueSetFunction_pf GetFieldDataSetFunction_FUNC(FieldData_pa FieldData)
1255 REQUIRE(VALID_REF(FieldData));
1257 FieldValueSetFunction_pf Result = GetFieldDataSetFunction_MACRO(FieldData);
1259 ENSURE(VALID_FN_REF(Result));
1260 return Result;
1262 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1265 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1268 LgIndex_t GetFieldDataNumValues_FUNC(FieldData_pa FieldData)
1270 REQUIRE(VALID_REF(FieldData));
1272 LgIndex_t Result = GetFieldDataNumValues_MACRO(FieldData);
1274 ENSURE(Result >= 0);
1275 return Result;
1277 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1280 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1283 ValueLocation_e GetFieldDataValueLocation_FUNC(FieldData_pa FieldData)
1285 REQUIRE(VALID_REF(FieldData));
1287 ValueLocation_e Result = GetFieldDataValueLocation_MACRO(FieldData);
1289 ENSURE(Result == ValueLocation_Invalid || /* i.e. pending assignment */
1290 VALID_ENUM(Result, ValueLocation_e));
1291 return Result;
1293 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1296 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1299 Boolean_t IsFieldDataDirectAccessAllowed_FUNC(FieldData_pa FieldData)
1301 REQUIRE(VALID_REF(FieldData));
1303 Boolean_t Result = IsFieldDataDirectAccessAllowed_MACRO(FieldData);
1305 ENSURE(VALID_BOOLEAN(Result));
1306 return Result;
1308 #endif
1311 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1314 float *GetFieldDataFloatPtr_FUNC(FieldData_pa fd)
1316 REQUIRE(VALID_REF(fd));
1318 float *Result = GetFieldDataFloatPtr_MACRO(fd);
1320 ENSURE(VALID_REF(Result));
1321 return Result;
1323 #endif
1326 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1329 double *GetFieldDataDoublePtr_FUNC(FieldData_pa fd)
1331 REQUIRE(VALID_REF(fd));
1333 double *Result = GetFieldDataDoublePtr_MACRO(fd);
1335 ENSURE(VALID_REF(Result));
1336 return Result;
1338 #endif
1341 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1344 Int64_t *GetFieldDataInt64Ptr_FUNC(FieldData_pa fd)
1346 REQUIRE(VALID_REF(fd));
1348 Int64_t *Result = GetFieldDataInt64Ptr_MACRO(fd);
1350 ENSURE(VALID_REF(Result));
1351 return Result;
1353 #endif
1356 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1359 Int32_t *GetFieldDataInt32Ptr_FUNC(FieldData_pa fd)
1361 REQUIRE(VALID_REF(fd));
1363 Int32_t *Result = GetFieldDataInt32Ptr_MACRO(fd);
1365 ENSURE(VALID_REF(Result));
1366 return Result;
1368 #endif
1371 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1374 Int16_t *GetFieldDataInt16Ptr_FUNC(FieldData_pa fd)
1376 REQUIRE(VALID_REF(fd));
1378 Int16_t *Result = GetFieldDataInt16Ptr_MACRO(fd);
1380 ENSURE(VALID_REF(Result));
1381 return Result;
1383 #endif
1386 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1388 * No byte ordering or alignment issues with single bytes (which are also used with the "Bit" type)
1390 Byte_t *GetFieldDataBytePtr_FUNC(FieldData_pa fd)
1393 * This function gets called for Byte and Bit types, but we cannot REQUIRE
1394 * those types because it is also used for non-aligned values. We can't
1395 * check for non-aligned because we might be copying aligned bytes to a
1396 * non-aligned location.
1398 REQUIRE(VALID_REF(fd));
1400 Byte_t *Result = GetFieldDataBytePtr_MACRO(fd);
1402 ENSURE(VALID_REF(Result));
1403 return Result;
1405 #endif
1408 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1410 * Gets a ptr to 2-byte blocks regardless of byte ordering, but still has to
1411 * worry about byte alignment
1413 UInt16_t *GetFieldData2BytePtr_FUNC(FieldData_pa fd)
1415 REQUIRE(VALID_REF(fd));
1416 REQUIRE(fd->Type == FieldDataType_Int16);
1418 UInt16_t *Result = GetFieldData2BytePtr_MACRO(fd);
1420 ENSURE(VALID_REF(Result));
1421 return Result;
1423 #endif
1426 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1428 * Gets a ptr to 4-byte blocks regardless of byte ordering, but still has to
1429 * worry about byte alignment
1431 UInt32_t *GetFieldData4BytePtr_FUNC(FieldData_pa fd)
1433 REQUIRE(VALID_REF(fd));
1434 REQUIRE(fd->Type == FieldDataType_Int32 || fd->Type == FieldDataType_Float);
1436 UInt32_t *Result = GetFieldData4BytePtr_MACRO(fd);
1438 ENSURE(VALID_REF(Result));
1439 return Result;
1441 #endif
1444 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1446 * Gets a ptr to 8-byte blocks regardless of byte ordering, but still has to
1447 * worry about byte alignment
1449 UInt64_t *GetFieldData8BytePtr_FUNC(FieldData_pa fd)
1451 REQUIRE(VALID_REF(fd));
1452 REQUIRE(fd->Type == FieldDataType_Int64 || fd->Type == FieldDataType_Double);
1454 UInt64_t *Result = GetFieldData8BytePtr_MACRO(fd);
1456 ENSURE(VALID_REF(Result));
1457 return Result;
1459 #endif
1462 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1464 * WARNING: GetFieldDataVoidPtr checks nothing, and thus should only be
1465 * used with extreme caution (that is, checking the alignment
1466 * and byte order by hand).
1468 void *GetFieldDataVoidPtr_FUNC(FieldData_pa fd)
1470 REQUIRE(VALID_REF(fd));
1472 void *Result = GetFieldDataVoidPtr_MACRO(fd);
1474 ENSURE(VALID_REF(Result));
1475 return Result;
1477 #endif
1479 #if defined TECPLOTKERNEL
1480 /* CORE SOURCE CODE REMOVED */
1481 #endif /* TECPLOTKERNEL */
1483 #if defined TECPLOTKERNEL
1484 /* CORE SOURCE CODE REMOVED */
1485 #endif
1487 #if defined TECPLOTKERNEL
1488 /* CORE SOURCE CODE REMOVED */
1489 #endif
1491 #if defined TECPLOTKERNEL
1492 /* CORE SOURCE CODE REMOVED */
1493 #endif
1495 #if defined TECPLOTKERNEL
1496 /* CORE SOURCE CODE REMOVED */
1497 #endif
1499 #if defined TECPLOTKERNEL
1500 /* CORE SOURCE CODE REMOVED */
1501 #endif
1503 #if defined TECPLOTKERNEL
1504 /* CORE SOURCE CODE REMOVED */
1505 #endif /* TECPLOTKERNEL */
1507 #if defined TECPLOTKERNEL
1508 /* CORE SOURCE CODE REMOVED */
1509 #endif
1514 void CopyFieldValue(FieldData_pa dst,
1515 LgIndex_t dstindex,
1516 FieldData_pa src,
1517 LgIndex_t srcindex)
1519 REQUIRE(VALID_REF(dst));
1520 REQUIRE(VALID_REF(src));
1521 #if defined TECPLOTKERNEL
1522 /* CORE SOURCE CODE REMOVED */
1523 #endif /* TECPLOTKERNEL */
1524 REQUIRE(dstindex >= 0 && dstindex < GetFieldDataNumValues(dst) &&
1525 srcindex >= 0 && srcindex < GetFieldDataNumValues(src));
1527 Boolean_t DoBruteForceCopy = TRUE;
1529 if (IsFieldDataDirectAccessAllowed(src) &&
1530 IsFieldDataDirectAccessAllowed(dst) &&
1531 GetFieldDataType(src) == GetFieldDataType(dst))
1533 switch (GetFieldDataType(src))
1535 case FieldDataType_Int64 : CHECK(FALSE); /* Future work: remove and let fall through */
1536 case FieldDataType_Double :
1538 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
1539 UInt64_t *dst_ptr = GetFieldData8BytePtr(dst) + dstindex;
1540 UInt64_t *src_ptr = GetFieldData8BytePtr(src) + srcindex;
1541 *dst_ptr = *src_ptr;
1542 DoBruteForceCopy = FALSE;
1543 } break;
1544 case FieldDataType_Float :
1545 case FieldDataType_Int32 :
1547 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
1548 UInt32_t *dst_ptr = GetFieldData4BytePtr(dst) + dstindex;
1549 UInt32_t *src_ptr = GetFieldData4BytePtr(src) + srcindex;
1550 *dst_ptr = *src_ptr;
1551 DoBruteForceCopy = FALSE;
1552 } break;
1553 case FieldDataType_Int16 :
1555 CHECK(sizeof(UInt16_t) == 2);
1556 UInt16_t *dst_ptr = GetFieldData2BytePtr(dst) + dstindex;
1557 UInt16_t *src_ptr = GetFieldData2BytePtr(src) + srcindex;
1558 *dst_ptr = *src_ptr;
1559 } break;
1560 case FieldDataType_Byte :
1562 GetFieldDataBytePtr(dst)[dstindex] = GetFieldDataBytePtr(src)[srcindex];
1563 DoBruteForceCopy = FALSE;
1564 } break;
1565 case FieldDataType_Bit : break; /* handle below */
1566 default : CHECK(FALSE); /* Future work: when more complex types are added, remove this CHECK */
1570 if (DoBruteForceCopy)
1572 double val = GetFieldValue(src, srcindex);
1573 SetFieldValue(dst, dstindex, val);
1575 } /* CopyFieldValue() */
1578 #if defined TECPLOTKERNEL
1579 /* CORE SOURCE CODE REMOVED */
1580 #endif
1582 #if defined TECPLOTKERNEL
1583 /* CORE SOURCE CODE REMOVED */
1584 #endif
1586 #if defined TECPLOTKERNEL
1587 /* CORE SOURCE CODE REMOVED */
1588 #endif
1590 #if defined TECPLOTKERNEL
1591 /* CORE SOURCE CODE REMOVED */
1592 #endif
1595 #if defined TECPLOTKERNEL
1596 /* CORE SOURCE CODE REMOVED */
1597 #endif /* TECPLOTKERNEL */
1602 void SetFieldDataPtrToAllZeros(FieldData_pa fd)
1604 REQUIRE(VALID_REF(fd));
1605 #if defined TECPLOTKERNEL
1606 /* CORE SOURCE CODE REMOVED */
1607 #endif /* TECPLOTKERNEL */
1609 LgIndex_t NumValues = GetFieldDataNumValues(fd);
1612 * memset each byte to 0 works for floats and doubles and works regardless
1613 * of byte ordering or alignment.
1615 size_t NumBytesToMemSet = 0;
1616 if (IsFieldDataDirectAccessAllowed(fd))
1618 switch (GetFieldDataType(fd))
1620 case FieldDataType_Int64 : CHECK(FALSE); /* Future work: remove CHECK */
1621 case FieldDataType_Double :
1623 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
1624 NumBytesToMemSet = NumValues * sizeof(Int64_t);
1625 } break;
1626 case FieldDataType_Int32 :
1627 case FieldDataType_Float :
1629 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
1630 NumBytesToMemSet = NumValues * sizeof(Int32_t);
1631 } break;
1632 case FieldDataType_Int16 :
1634 CHECK(sizeof(UInt16_t) == 2);
1635 NumBytesToMemSet = NumValues * sizeof(Int16_t);
1636 } break;
1637 case FieldDataType_Byte :
1639 NumBytesToMemSet = NumValues * sizeof(Byte_t);
1640 } break;
1641 case FieldDataType_Bit :
1643 NumBytesToMemSet = ((NumValues + 7) / 8) * sizeof(Byte_t);
1644 } break;
1645 default :
1647 CHECK(FALSE);
1648 } break;
1652 if (NumBytesToMemSet > 0)
1654 void *fd_data = GetFieldDataVoidPtr(fd);
1655 memset(fd_data, 0, NumBytesToMemSet);
1657 else
1659 int ii;
1660 for (ii = 0; ii < NumValues; ii++)
1661 SetFieldValue(fd, ii, 0.0);
1664 } /* SetFieldDataPtrToAllZeros() */
1666 #if defined TECPLOTKERNEL
1667 /* CORE SOURCE CODE REMOVED */
1668 #endif /* TECPLOTKERNEL */