1 #if defined TECPLOTKERNEL
2 /* CORE SOURCE CODE REMOVED */
3 #endif
4 #include "stdafx.h"
5 #include "MASTER.h"
6 
7 #define TECPLOTENGINEMODULE
8 
9 /*
10 ******************************************************************
11 ******************************************************************
12 *******                                                   ********
13 ******  (C) 1988-2010 Tecplot, Inc.                        *******
14 *******                                                   ********
15 ******************************************************************
16 ******************************************************************
17 */
18 
19 #define DATASET0MODULE
20 #include "GLOBAL.h"
21 #include "TASSERT.h"
22 #include "Q_UNICODE.h"
23 #include "ALLOC.h"
24 #include "ARRLIST.h"
25 #include "DATASET.h"
26 #include "SET.h"
27 #include "FILESTREAM.h"
28 #include "Q_MSG.h"
29 #if defined TECPLOTKERNEL
30 /* CORE SOURCE CODE REMOVED */
31 #endif
32 #include "DATASET0.h"
33 
34 using namespace tecplot::strutil;
35 #if defined TECPLOTKERNEL
36 /* CORE SOURCE CODE REMOVED */
37 #endif
38 
39 /*
40  * Low level dataset functions.  No references to zones, vars or
41  * the DataSet_s master structure here.
42  */
43 
44 
45 /*
46  */
OutOfMemoryMsg(void)47 void OutOfMemoryMsg(void)
48 {
49     ErrMsg(translate("Cannot allocate enough memory for this operation."));
50 } /* OutOfMemoryMsg() */
51 
52 
53 /**
54  */
FieldDataAlloc(Boolean_t doTrackVarSharing)55 FieldData_pa FieldDataAlloc(Boolean_t doTrackVarSharing)
56 {
57     FieldData_pa Result;
58 
59     Result = (FieldData_pa)ALLOC_ITEM(struct _FieldData_a, "FieldDataPtr");
60     if (Result != NULL)
61     {
62         Result->Data = NULL;
63 
64         #if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
65 /* CORE SOURCE CODE REMOVED */
66         #else /* ...for TecIO only */
67         Result->GetValueCallback[0] = NULL;
68         Result->SetValueCallback[0] = NULL;
69         #endif
70 
71         #if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
72 /* CORE SOURCE CODE REMOVED */
73         #endif
74 
75         Result->Type             = FieldDataType_Invalid;
76         Result->ValueLocation    = ValueLocation_Invalid;
77         #if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
78 /* CORE SOURCE CODE REMOVED */
79         #endif
80         Result->NumValues        = 0;
81         #if defined TECPLOTKERNEL /* TecIO doesn't require these features yet */
82 /* CORE SOURCE CODE REMOVED */
83         #endif
84     }
85 
86     ENSURE(VALID_REF(Result) || Result == NULL);
87     return Result;
88 }
89 
90 /**
91  * Most clients should not call this function but FieldDataCleanup() instead.
92  * An exception to this would be Tecplot's own storable load-on-demand
93  * functions.
94  */
FieldDataDeallocData(FieldData_pa FieldData)95 void FieldDataDeallocData(FieldData_pa FieldData)
96 {
97     REQUIRE(VALID_REF(FieldData));
98 
99 #if defined TECPLOTKERNEL
100 /* CORE SOURCE CODE REMOVED */
101 #endif
102         if (FieldData->Data != NULL)
103         {
104             /* Hack to remove 'deleting void* is undefined' warning... */
105             char *Tmp = (char *)FieldData->Data;
106             FREE_ARRAY(Tmp, "FieldData _Data");
107             FieldData->Data = NULL;
108         }
109 
110 #if defined TECPLOTKERNEL
111 /* CORE SOURCE CODE REMOVED */
112 #endif
113 
114     ENSURE(FieldData->Data == NULL);
115 }
116 
117 #if defined TECPLOTKERNEL
118 /* CORE SOURCE CODE REMOVED */
119 #endif
120 
121 #if defined TECPLOTKERNEL
122 /* CORE SOURCE CODE REMOVED */
123 #endif
124 
125 #if defined TECPLOTKERNEL
126 /* CORE SOURCE CODE REMOVED */
127 #endif
128 
129 #if defined TECPLOTKERNEL
130 /* CORE SOURCE CODE REMOVED */
131 #endif
132 
133 #if defined TECPLOTKERNEL
134 /* CORE SOURCE CODE REMOVED */
135 #endif
136 
137 #if defined TECPLOTKERNEL
138 /* CORE SOURCE CODE REMOVED */
139 #endif
140 
141 #if defined TECPLOTKERNEL
142 /* CORE SOURCE CODE REMOVED */
143 #endif
144 
145 #if defined TECPLOTKERNEL
146 /* CORE SOURCE CODE REMOVED */
147 #endif
148 
149 #if defined TECPLOTKERNEL
150 /* CORE SOURCE CODE REMOVED */
151 #endif
152 
153 #if defined TECPLOTKERNEL
154 /* CORE SOURCE CODE REMOVED */
155 #endif
156 
157 #if defined TECPLOTKERNEL
158 /* CORE SOURCE CODE REMOVED */
159 #endif
160 
161 #if defined TECPLOTKERNEL
162 /* CORE SOURCE CODE REMOVED */
163 #endif
164 
165 #if defined TECPLOTKERNEL
166 /* CORE SOURCE CODE REMOVED */
167 #endif
168 
169 /**
170  */
FieldDataCleanup(FieldData_pa FieldData)171 void FieldDataCleanup(FieldData_pa FieldData)
172 {
173     REQUIRE(VALID_REF(FieldData));
174 
175 # if defined TECPLOTKERNEL
176 /* CORE SOURCE CODE REMOVED */
177 # else
178     FieldDataDeallocData(FieldData);
179 # endif
180 }
181 
182 /**
183  */
FieldDataDealloc(FieldData_pa * FieldData,Boolean_t DoTrackVarSharing)184 void FieldDataDealloc(FieldData_pa *FieldData,
185                       Boolean_t     DoTrackVarSharing)
186 {
187     REQUIRE(VALID_REF(FieldData));
188     REQUIRE(VALID_REF(*FieldData) || *FieldData == NULL);
189     #if defined TECPLOTKERNEL
190 /* CORE SOURCE CODE REMOVED */
191     #endif
192 
193     if (*FieldData != NULL)
194     {
195         #if defined TECPLOTKERNEL
196 /* CORE SOURCE CODE REMOVED */
197         #endif
198         {
199             FieldDataCleanup(*FieldData);
200 
201             #if defined TECPLOTKERNEL
202 /* CORE SOURCE CODE REMOVED */
203             #endif
204 
205             FREE_ITEM(*FieldData, "field data");
206         }
207         *FieldData = NULL;
208     }
209 
210     ENSURE(*FieldData == NULL);
211 }
212 
213 #if defined TECPLOTKERNEL
214 /* CORE SOURCE CODE REMOVED */
215 #endif
216 
217 #if defined TECPLOTKERNEL
218 /* CORE SOURCE CODE REMOVED */
219 #endif
220 
221 template <typename T>
copyTypedValueArray(void * DstArray,LgIndex_t DstStart,void * SrcArray,LgIndex_t SrcStart,LgIndex_t SrcEnd)222 static void copyTypedValueArray(void*     DstArray,
223                                 LgIndex_t DstStart,
224                                 void*     SrcArray,
225                                 LgIndex_t SrcStart,
226                                 LgIndex_t SrcEnd)
227 {
228     REQUIRE(VALID_REF(DstArray));
229     REQUIRE(DstStart >= 0);
230     REQUIRE(VALID_REF(SrcArray));
231     REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd+1);
232     REQUIRE(DstArray != SrcArray);
233 
234     size_t const numBytes = sizeof(T) * (SrcEnd - SrcStart + 1);
235     if (numBytes != 0)
236     {
237         T const* SrcPtr = ((T const*)SrcArray) + SrcStart;
238         T* DstPtr       = ((T*)DstArray) + DstStart;
239         memcpy(DstPtr, SrcPtr, numBytes);
240     }
241 }
242 
243 /**
244  * DstArray and SrcArray are aligned on proper word boundaries.
245  */
CopyTypedValueArray(FieldDataType_e ValueType,void * DstArray,LgIndex_t DstStart,void * SrcArray,LgIndex_t SrcStart,LgIndex_t SrcEnd)246 void CopyTypedValueArray(FieldDataType_e  ValueType,
247                          void            *DstArray,
248                          LgIndex_t        DstStart,
249                          void            *SrcArray,
250                          LgIndex_t        SrcStart,
251                          LgIndex_t        SrcEnd)
252 {
253     REQUIRE(VALID_FIELD_DATA_TYPE(ValueType) &&
254             ValueType != FieldDataType_Bit);
255     REQUIRE(VALID_REF(DstArray));
256     REQUIRE(DstStart >= 0);
257     REQUIRE(VALID_REF(SrcArray));
258     REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd+1);
259     REQUIRE(DstArray != SrcArray);
260 
261     switch (ValueType)
262     {
263         case FieldDataType_Int64 : CHECK(FALSE); /* Future work: remove check */
264         case FieldDataType_Double :
265         {
266             CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
267             copyTypedValueArray<UInt64_t>(DstArray,
268                                           DstStart,
269                                           SrcArray,
270                                           SrcStart,
271                                           SrcEnd);
272         } break;
273         case FieldDataType_Float :
274         case FieldDataType_Int32 :
275         {
276             CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
277             copyTypedValueArray<UInt32_t>(DstArray,
278                                           DstStart,
279                                           SrcArray,
280                                           SrcStart,
281                                           SrcEnd);
282         } break;
283         case FieldDataType_Int16 :
284         {
285             CHECK(sizeof(UInt16_t) == 2);
286             copyTypedValueArray<UInt16_t>(DstArray,
287                                           DstStart,
288                                           SrcArray,
289                                           SrcStart,
290                                           SrcEnd);
291         } break;
292         case FieldDataType_Byte :
293         {
294             copyTypedValueArray<Byte_t>(DstArray,
295                                         DstStart,
296                                         SrcArray,
297                                         SrcStart,
298                                         SrcEnd);
299         } break;
300         default : CHECK(FALSE);
301     }
302 }
303 
304 /**
305  * SrcArray is aligned on proper word boundaries.
306  */
SwapBytesInTypedValueArray(FieldDataType_e ValueType,void * SrcArray,LgIndex_t SrcStart,LgIndex_t SrcEnd,LgIndex_t SrcSkip)307 void SwapBytesInTypedValueArray(FieldDataType_e  ValueType,
308                                 void            *SrcArray,
309                                 LgIndex_t        SrcStart,
310                                 LgIndex_t        SrcEnd,
311                                 LgIndex_t        SrcSkip)
312 {
313     REQUIRE(VALID_FIELD_DATA_TYPE(ValueType) &&
314             ValueType != FieldDataType_Bit);
315     REQUIRE(VALID_REF(SrcArray));
316     REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd);
317     REQUIRE(SrcSkip > 0);
318 
319     switch (ValueType)
320     {
321         case FieldDataType_Int64: CHECK(FALSE); /* Future work: remove CHECK */
322         case FieldDataType_Double:
323         {
324             /* swap 8 bytes blocks */
325             UInt64_t *SrcPtr = ((UInt64_t *)SrcArray) + SrcStart;
326             UInt64_t *SrcPtrEnd = ((UInt64_t *)SrcArray) + SrcEnd;
327             CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
328             while (SrcPtr <= SrcPtrEnd)
329             {
330                 REVERSE_8_BYTES(SrcPtr);
331                 SrcPtr += SrcSkip;
332             }
333         } break;
334         case FieldDataType_Float:
335         case FieldDataType_Int32:
336         {
337             /* swap 4 bytes blocks */
338             UInt32_t *SrcPtr = ((UInt32_t *)SrcArray) + SrcStart;
339             UInt32_t *SrcPtrEnd = ((UInt32_t *)SrcArray) + SrcEnd;
340             CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
341             while (SrcPtr <= SrcPtrEnd)
342             {
343                 REVERSE_4_BYTES(SrcPtr);
344                 SrcPtr += SrcSkip;
345             }
346         } break;
347         case FieldDataType_Int16:
348         {
349             /* swap 4 bytes blocks */
350             UInt16_t *SrcPtr = ((UInt16_t *)SrcArray) + SrcStart;
351             UInt16_t *SrcPtrEnd = ((UInt16_t *)SrcArray) + SrcEnd;
352             CHECK(sizeof(UInt16_t) == 2);
353             while (SrcPtr <= SrcPtrEnd)
354             {
355                 REVERSE_2_BYTES(SrcPtr);
356                 SrcPtr += SrcSkip;
357             }
358         } break;
359         case FieldDataType_Byte:
360         case FieldDataType_Bit:
361         {
362             /* nothing to do */
363         } break;
364         default: CHECK(FALSE);
365     }
366 }
367 
368 /**
369  * Same as SwapBytesInTypedValueArray, but does extra work.  Doesn't assume
370  * DstArray and SrcArray are aligned on proper word boundaries.
371  */
SwapBytesInUnalignedTypedValueArray(FieldDataType_e ValueType,void * SrcArray,LgIndex_t SrcStart,LgIndex_t SrcEnd,LgIndex_t SrcSkip)372 void SwapBytesInUnalignedTypedValueArray(FieldDataType_e  ValueType,
373                                          void            *SrcArray,
374                                          LgIndex_t        SrcStart,
375                                          LgIndex_t        SrcEnd,
376                                          LgIndex_t        SrcSkip)
377 {
378     REQUIRE(VALID_FIELD_DATA_TYPE(ValueType) &&
379             ValueType != FieldDataType_Bit);
380     REQUIRE(VALID_REF(SrcArray));
381     REQUIRE(0 <= SrcStart && SrcStart <= SrcEnd);
382     REQUIRE(SrcSkip > 0);
383 
384     switch (ValueType)
385     {
386         case FieldDataType_Int64: CHECK(FALSE); /* Future work: remove CHECK */
387         case FieldDataType_Double:
388         {
389             /* swap 8-byte blocks */
390             Byte_t *SrcPtr = ((Byte_t *)SrcArray) + SrcStart * sizeof(UInt64_t);
391             Byte_t *SrcPtrEnd = ((Byte_t *)SrcArray) + SrcEnd * sizeof(UInt64_t);
392             size_t byte_skip = SrcSkip * sizeof(UInt64_t);
393             CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
394             while (SrcPtr <= SrcPtrEnd)
395             {
396                 REVERSE_8_BYTES_1_AT_A_TIME(SrcPtr);
397                 SrcPtr += byte_skip;
398             }
399         } break;
400         case FieldDataType_Float:
401         case FieldDataType_Int32:
402         {
403             /* swap 4-byte blocks */
404             Byte_t *SrcPtr = ((Byte_t *)SrcArray) + SrcStart * sizeof(UInt32_t);
405             Byte_t *SrcPtrEnd = ((Byte_t *)SrcArray) + SrcEnd * sizeof(UInt32_t);
406             size_t byte_skip = SrcSkip * sizeof(UInt32_t);
407             CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
408             while (SrcPtr <= SrcPtrEnd)
409             {
410                 REVERSE_4_BYTES_1_AT_A_TIME(SrcPtr);
411                 SrcPtr += byte_skip;
412             }
413         } break;
414         case FieldDataType_Int16:
415         {
416             /* swap 2-byte blocks */
417             Byte_t *SrcPtr = ((Byte_t *)SrcArray) + SrcStart * sizeof(UInt16_t);
418             Byte_t *SrcPtrEnd = ((Byte_t *)SrcArray) + SrcEnd * sizeof(UInt16_t);
419             size_t byte_skip = SrcSkip * sizeof(UInt16_t);
420             CHECK(sizeof(UInt16_t) == 2);
421             while (SrcPtr <= SrcPtrEnd)
422             {
423                 REVERSE_2_BYTES_1_AT_A_TIME(SrcPtr);
424                 SrcPtr += byte_skip;
425             }
426         } break;
427         case FieldDataType_Byte:
428         case FieldDataType_Bit:
429         {
430             /* No swapping required. */
431         } break;
432         default: CHECK(FALSE);
433     }
434 }
435 
436 
437 #if defined TECPLOTKERNEL
438 /* CORE SOURCE CODE REMOVED */
439 #endif
440 
441 #if defined TECPLOTKERNEL
442 /* CORE SOURCE CODE REMOVED */
443 #endif
444 
445 #if defined TECPLOTKERNEL
446 /* CORE SOURCE CODE REMOVED */
447 #endif
448 
449 #if defined TECPLOTKERNEL
450 /* CORE SOURCE CODE REMOVED */
451 #endif
452 
453 #if defined TECPLOTKERNEL
454 /* CORE SOURCE CODE REMOVED */
455 #endif
456 
457 #if defined TECPLOTKERNEL
458 /* CORE SOURCE CODE REMOVED */
459 #endif
460 
461 #if defined TECPLOTKERNEL
462 /* CORE SOURCE CODE REMOVED */
463 #endif
464 
465 
466 #if defined TECPLOTKERNEL
467 /* CORE SOURCE CODE REMOVED */
468 #endif
469 
470 #if defined TECPLOTKERNEL
471 /* CORE SOURCE CODE REMOVED */
472 #endif
473 
474 #if defined TECPLOTKERNEL
475 /* CORE SOURCE CODE REMOVED */
476 #endif
477 
478 #if defined TECPLOTKERNEL
479 /* CORE SOURCE CODE REMOVED */
480 #endif
481 
482 #if defined TECPLOTKERNEL
483 /* CORE SOURCE CODE REMOVED */
484 #endif
485 
486 #if defined DEBUG_FIELDVALUES
487 # define DEBUG_FIELDVALUES_BAD_VALUE 0x11
488 static unsigned char BadValueStr[] =
489 {
490     DEBUG_FIELDVALUES_BAD_VALUE,
491     DEBUG_FIELDVALUES_BAD_VALUE,
492     DEBUG_FIELDVALUES_BAD_VALUE,
493     DEBUG_FIELDVALUES_BAD_VALUE,
494     DEBUG_FIELDVALUES_BAD_VALUE,
495     DEBUG_FIELDVALUES_BAD_VALUE,
496     DEBUG_FIELDVALUES_BAD_VALUE,
497     DEBUG_FIELDVALUES_BAD_VALUE
498 };
499 /**
500  * If Tecplot is responsible for managing (allocating and deallocating) the
501  * raw data then
502  */
503 # if defined TECPLOTKERNEL
504 /* CORE SOURCE CODE REMOVED */
505 # else
506 #   define FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, type) \
507                    ((sizeof(type) < 4) /* cannot make reliably test with less than four bytes */ || \
508                     memcmp(BadValueStr,((char *)((fd)->Data))+sizeof(type)*(pt), sizeof(type)) != 0)
509 # endif
510 #else
511 # define FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, type) TRUE
512 #endif
513 
514 
515 
516 /**
517  * Used in macros, thus not static
518  */
GetFieldValueForFloat(const FieldData_pa fd,LgIndex_t pt)519 double STDCALL GetFieldValueForFloat(const FieldData_pa fd,
520                                      LgIndex_t          pt)
521 {
522     REQUIRE(VALID_REF(fd));
523 # if defined TECPLOTKERNEL
524 /* CORE SOURCE CODE REMOVED */
525 # endif
526     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
527     REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, float));
528 
529     double Result = (double)GetFieldDataFloatPtr(fd)[pt];
530 
531     return Result;
532 }
533 
534 
535 #if defined TECPLOTKERNEL
536 /* CORE SOURCE CODE REMOVED */
537 #endif
538 
539 
540 /**
541  * Used in macros, thus not static
542  */
GetFieldValueForDouble(const FieldData_pa fd,LgIndex_t pt)543 double STDCALL GetFieldValueForDouble(const FieldData_pa fd,
544                                       LgIndex_t          pt)
545 {
546     REQUIRE(VALID_REF(fd));
547 # if defined TECPLOTKERNEL
548 /* CORE SOURCE CODE REMOVED */
549 # endif
550     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
551     REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, double));
552 
553     double Result = GetFieldDataDoublePtr(fd)[pt];
554 
555     return Result;
556 }
557 
558 
559 #if defined TECPLOTKERNEL
560 /* CORE SOURCE CODE REMOVED */
561 #endif
562 
563 
564 /**
565  */
GetFieldValueForInt32(const FieldData_pa fd,LgIndex_t pt)566 double STDCALL GetFieldValueForInt32(const FieldData_pa fd,
567                                      LgIndex_t          pt)
568 {
569     REQUIRE(VALID_REF(fd));
570 # if defined TECPLOTKERNEL
571 /* CORE SOURCE CODE REMOVED */
572 # endif
573     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
574     REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int32_t));
575 
576     double Result = (double)GetFieldDataInt32Ptr(fd)[pt];
577 
578     return Result;
579 }
580 
581 
582 #if defined TECPLOTKERNEL
583 /* CORE SOURCE CODE REMOVED */
584 #endif
585 
586 
587 /**
588  */
GetFieldValueForInt16(const FieldData_pa fd,LgIndex_t pt)589 double STDCALL GetFieldValueForInt16(const FieldData_pa fd,
590                                      LgIndex_t          pt)
591 {
592     REQUIRE(VALID_REF(fd));
593 # if defined TECPLOTKERNEL
594 /* CORE SOURCE CODE REMOVED */
595 # endif
596     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
597     REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int16_t));
598 
599     double Result = (double)GetFieldDataInt16Ptr(fd)[pt];
600 
601     return Result;
602 }
603 
604 
605 #if defined TECPLOTKERNEL
606 /* CORE SOURCE CODE REMOVED */
607 #endif
608 
609 
610 /**
611  */
GetFieldValueForByte(const FieldData_pa fd,LgIndex_t pt)612 double STDCALL GetFieldValueForByte(const FieldData_pa fd,
613                                     LgIndex_t          pt)
614 {
615     REQUIRE(VALID_REF(fd));
616 # if defined TECPLOTKERNEL
617 /* CORE SOURCE CODE REMOVED */
618 # endif
619     REQUIRE(fd->Type == FieldDataType_Byte);
620     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
621     REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Byte_t));
622 
623     double Result = (double)GetFieldDataBytePtr(fd)[pt];
624 
625     return Result;
626 }
627 
628 
629 #if defined TECPLOTKERNEL
630 /* CORE SOURCE CODE REMOVED */
631 #endif
632 
633 
634 /**
635  */
GetFieldValueForBit(const FieldData_pa fd,LgIndex_t pt)636 double STDCALL GetFieldValueForBit(const FieldData_pa fd,
637                                    LgIndex_t          pt)
638 {
639     REQUIRE(VALID_REF(fd));
640 # if defined TECPLOTKERNEL
641 /* CORE SOURCE CODE REMOVED */
642 # endif
643     REQUIRE(fd->Type == FieldDataType_Bit);
644     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
645     REQUIRE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt / 8, Byte_t));
646 
647     LgIndex_t ByteOffset = pt / 8;
648     Byte_t    BitMask    = (01 << (pt % 8));
649 
650     Byte_t *byte_array = GetFieldDataBytePtr(fd);
651     double Result = (byte_array[ByteOffset] & BitMask) ? 1.0 : 0.0;
652 
653     return Result;
654 }
655 
656 
657 #if defined TECPLOTKERNEL
658 /* CORE SOURCE CODE REMOVED */
659 #endif
660 
661 
662 /**
663  */
DetermineFieldDataGetFunction(FieldDataType_e DataType,Boolean_t IsFragmented)664 FieldValueGetFunction_pf DetermineFieldDataGetFunction(FieldDataType_e DataType,
665                                                        Boolean_t       IsFragmented)
666 {
667     FieldValueGetFunction_pf Result;
668 
669     REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
670     REQUIRE(VALID_BOOLEAN(IsFragmented));
671 
672 #if defined TECPLOTKERNEL
673 /* CORE SOURCE CODE REMOVED */
674 #endif
675     {
676         switch (DataType)
677         {
678             case FieldDataType_Float :
679             {
680                 Result = GetFieldValueForFloat;
681             } break;
682             case FieldDataType_Double :
683             {
684                 Result = GetFieldValueForDouble;
685             } break;
686             case FieldDataType_Int32 :
687             {
688                 Result = GetFieldValueForInt32;
689             } break;
690             case FieldDataType_Int16 :
691             {
692                 Result = GetFieldValueForInt16;
693             } break;
694             case FieldDataType_Byte :
695             {
696                 Result = GetFieldValueForByte;
697             } break;
698             case FieldDataType_Bit :
699             {
700                 Result = GetFieldValueForBit;
701             } break;
702             default :
703             {
704                 CHECK(FALSE);
705                 Result = NULL; /* satisfy compiler */
706             } break;
707         }
708     }
709     return (Result);
710 }
711 
712 /**
713  */
SetFieldValueForFloat(FieldData_pa fd,LgIndex_t pt,double val)714 static void STDCALL SetFieldValueForFloat(FieldData_pa fd,
715                                           LgIndex_t    pt,
716                                           double       val)
717 {
718     REQUIRE(VALID_REF(fd));
719 # if defined TECPLOTKERNEL
720 /* CORE SOURCE CODE REMOVED */
721 # endif
722     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
723     REQUIRE("val can have any value");
724 
725     GetFieldDataFloatPtr(fd)[pt] = CONVERT_DOUBLE_TO_FLOAT(val);
726 
727     ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, float));
728 }
729 
730 
731 #if defined TECPLOTKERNEL
732 /* CORE SOURCE CODE REMOVED */
733 #endif
734 
735 
736 /**
737  */
SetFieldValueForDouble(FieldData_pa fd,LgIndex_t pt,double val)738 static void STDCALL SetFieldValueForDouble(FieldData_pa fd,
739                                            LgIndex_t    pt,
740                                            double       val)
741 {
742     REQUIRE(VALID_REF(fd));
743 # if defined TECPLOTKERNEL
744 /* CORE SOURCE CODE REMOVED */
745 # endif
746     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
747     REQUIRE("val can have any value");
748 
749     GetFieldDataDoublePtr(fd)[pt] = CLAMP_DOUBLE(val);
750 
751     ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, double));
752 }
753 
754 
755 #if defined TECPLOTKERNEL
756 /* CORE SOURCE CODE REMOVED */
757 #endif
758 
759 
760 /**
761  */
SetFieldValueForInt32(FieldData_pa fd,LgIndex_t pt,double val)762 static void STDCALL SetFieldValueForInt32(FieldData_pa fd,
763                                           LgIndex_t    pt,
764                                           double       val)
765 {
766     REQUIRE(VALID_REF(fd));
767 # if defined TECPLOTKERNEL
768 /* CORE SOURCE CODE REMOVED */
769 # endif
770     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
771     REQUIRE("val can have any value");
772 
773     GetFieldDataInt32Ptr(fd)[pt] = CONVERT_DOUBLE_TO_INT32(val);
774 
775     ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int32_t));
776 }
777 
778 
779 #if defined TECPLOTKERNEL
780 /* CORE SOURCE CODE REMOVED */
781 #endif
782 
783 
784 /**
785  */
SetFieldValueForInt16(FieldData_pa fd,LgIndex_t pt,double val)786 static void STDCALL SetFieldValueForInt16(FieldData_pa fd,
787                                           LgIndex_t    pt,
788                                           double       val)
789 {
790     REQUIRE(VALID_REF(fd));
791 # if defined TECPLOTKERNEL
792 /* CORE SOURCE CODE REMOVED */
793 # endif
794     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
795     REQUIRE("val can have any value");
796 
797     GetFieldDataInt16Ptr(fd)[pt] = CONVERT_DOUBLE_TO_INT16(val);
798 
799     ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Int16_t));
800 }
801 
802 
803 #if defined TECPLOTKERNEL
804 /* CORE SOURCE CODE REMOVED */
805 #endif
806 
807 
808 /**
809  */
SetFieldValueForByte(FieldData_pa fd,LgIndex_t pt,double val)810 static void STDCALL SetFieldValueForByte(FieldData_pa fd,
811                                          LgIndex_t    pt,
812                                          double       val)
813 {
814     REQUIRE(VALID_REF(fd));
815 # if defined TECPLOTKERNEL
816 /* CORE SOURCE CODE REMOVED */
817 # endif
818     REQUIRE(fd->Type == FieldDataType_Byte);
819     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
820     REQUIRE("val can have any value");
821 
822     if (val < 1.0)
823         GetFieldDataBytePtr(fd)[pt] = 0;
824     else if (val > 255.0)
825         GetFieldDataBytePtr(fd)[pt] = 255;
826     else
827         GetFieldDataBytePtr(fd)[pt] = (Byte_t)val;
828 
829     ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt, Byte_t));
830 }
831 
832 
833 #if defined TECPLOTKERNEL
834 /* CORE SOURCE CODE REMOVED */
835 #endif
836 
837 
838 /**
839  */
SetFieldValueForBit(FieldData_pa fd,LgIndex_t pt,double val)840 static void STDCALL SetFieldValueForBit(FieldData_pa fd,
841                                         LgIndex_t    pt,
842                                         double       val)
843 {
844     REQUIRE(VALID_REF(fd));
845 # if defined TECPLOTKERNEL
846 /* CORE SOURCE CODE REMOVED */
847 # endif
848     REQUIRE(fd->Type == FieldDataType_Bit);
849     REQUIRE(0 <= pt && pt < GetFieldDataNumValues(fd));
850     REQUIRE("val can have any value");
851 
852     LgIndex_t ByteOffset = pt / 8;
853     Byte_t    BitMask    = (01 << (pt % 8));
854 
855     if (val < 1.0)
856         GetFieldDataBytePtr(fd)[ByteOffset] &= ~BitMask;
857     else
858         GetFieldDataBytePtr(fd)[ByteOffset] |= BitMask;
859 
860     ENSURE(FIELD_DATA_VALUE_IS_INITIALIZED(fd, pt / 8, Byte_t));
861 }
862 
863 
864 #if defined TECPLOTKERNEL
865 /* CORE SOURCE CODE REMOVED */
866 #endif
867 
868 
869 /**
870  */
DetermineFieldDataSetFunction(FieldDataType_e DataType,Boolean_t IsFragmented)871 FieldValueSetFunction_pf DetermineFieldDataSetFunction(FieldDataType_e DataType,
872                                                        Boolean_t       IsFragmented)
873 {
874     FieldValueSetFunction_pf Result;
875 
876     REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
877     REQUIRE(VALID_BOOLEAN(IsFragmented));
878 
879 #if defined TECPLOTKERNEL
880 /* CORE SOURCE CODE REMOVED */
881 #endif
882     {
883         switch (DataType)
884         {
885             case FieldDataType_Float :
886             {
887                 Result = SetFieldValueForFloat;
888             } break;
889             case FieldDataType_Double :
890             {
891                 Result = SetFieldValueForDouble;
892             } break;
893             case FieldDataType_Int32 :
894             {
895                 Result = SetFieldValueForInt32;
896             } break;
897             case FieldDataType_Int16 :
898             {
899                 Result = SetFieldValueForInt16;
900             } break;
901             case FieldDataType_Byte :
902             {
903                 Result = SetFieldValueForByte;
904             } break;
905             case FieldDataType_Bit :
906             {
907                 Result = SetFieldValueForBit;
908             } break;
909             default :
910             {
911                 CHECK(FALSE);
912                 Result = NULL; /* satisfy compiler */
913             } break;
914         }
915     }
916     return (Result);
917 }
918 
919 
920 /**
921  */
FieldDataGetBytesNeeded(LgIndex_t NumValues,FieldDataType_e DataType)922 Int64_t FieldDataGetBytesNeeded(LgIndex_t       NumValues,
923                                 FieldDataType_e DataType)
924 {
925     Int64_t Result = 0; /* ...quite compiler */
926 
927     REQUIRE(NumValues >= 0);
928     REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
929 
930     switch (DataType)
931     {
932         case FieldDataType_Float:  Result = ((Int64_t)NumValues)*sizeof(float);        break;
933         case FieldDataType_Double: Result = ((Int64_t)NumValues)*sizeof(double);       break;
934         case FieldDataType_Int32:  Result = ((Int64_t)NumValues)*sizeof(LgIndex_t);    break;
935         case FieldDataType_Int16:  Result = ((Int64_t)NumValues)*sizeof(SmInteger_t);  break;
936         case FieldDataType_Byte:   Result = ((Int64_t)NumValues)*sizeof(Byte_t);       break;
937         case FieldDataType_Bit:    Result = ((Int64_t)(NumValues+7)/8)*sizeof(Byte_t); break;
938         default: CHECK(FALSE); break;
939     }
940 
941     ENSURE(Result >= 0);
942     return Result;
943 }
944 
945 /**
946  * On the SGI, HP, Sun and Itanium Linux machines 64 bit objects such as
947  * doubles must be 8 byte aligned while on all other machines 32 bit alignment
948  * suffices. Some allow 1 byte alignment but we won't bother with that.
949  */
950 #if defined IRISX || defined HPUX || defined SUNX
951 # define SIZEOF_LARGEST_OBJECT_TO_ALIGN sizeof(Int64_t)
952 #else
953 # define SIZEOF_LARGEST_OBJECT_TO_ALIGN sizeof(Int32_t)
954 #endif
955 
956 /**
957  */
IsOffsetAlignedForFieldDataType(FieldDataType_e FieldDataType,Int64_t Offset)958 Boolean_t IsOffsetAlignedForFieldDataType(FieldDataType_e FieldDataType,
959                                           Int64_t         Offset)
960 {
961     REQUIRE(VALID_FIELD_DATA_TYPE(FieldDataType));
962     REQUIRE(Offset >= 0);
963 
964     Int64_t SizeOfType = FieldDataGetBytesNeeded(1, FieldDataType);
965     if (SizeOfType > (Int64_t)SIZEOF_LARGEST_OBJECT_TO_ALIGN)
966         SizeOfType = SIZEOF_LARGEST_OBJECT_TO_ALIGN;
967 
968     Boolean_t HasValidAlignment = (Offset % SizeOfType == 0);
969 
970     ENSURE(VALID_BOOLEAN(HasValidAlignment));
971     return HasValidAlignment;
972 }
973 
974 /**
975  */
GetAlignedOffsetForFieldDataType(FieldDataType_e FieldDataType,Int64_t Offset)976 Int64_t GetAlignedOffsetForFieldDataType(FieldDataType_e FieldDataType,
977                                          Int64_t         Offset)
978 {
979     REQUIRE(VALID_FIELD_DATA_TYPE(FieldDataType));
980     REQUIRE(Offset >= 0);
981 
982     Int64_t SizeOfType = FieldDataGetBytesNeeded(1, FieldDataType);
983     if (SizeOfType > (Int64_t)SIZEOF_LARGEST_OBJECT_TO_ALIGN)
984         SizeOfType = SIZEOF_LARGEST_OBJECT_TO_ALIGN;
985 
986     Int64_t NumBytesPastAlignment = (Offset % SizeOfType);
987     Int64_t Result = Offset - NumBytesPastAlignment;
988 
989     ENSURE(0 <= Result && Result <= Offset);
990     ENSURE(IsOffsetAlignedForFieldDataType(FieldDataType, Result));
991     return Result;
992 }
993 
994 /**
995  */
FieldDataDefineData(FieldData_pa FieldData,LgIndex_t NumValues,FieldDataType_e DataType,ValueLocation_e ValueLocation)996 void FieldDataDefineData(FieldData_pa    FieldData,
997                          LgIndex_t       NumValues,
998                          FieldDataType_e DataType,
999                          ValueLocation_e ValueLocation)
1000 {
1001     REQUIRE(VALID_REF(FieldData));
1002     REQUIRE(NumValues >= 0);
1003     REQUIRE(VALID_FIELD_DATA_TYPE(DataType));
1004     REQUIRE(VALID_ENUM(ValueLocation, ValueLocation_e));
1005 
1006     /*
1007      * Remove any old data (transformed UVW is one example that calls this
1008      * function with a non-null data pointer when switching the value location
1009      * when style changes the value location and therefore the amount of data
1010      * allocated.)
1011      */
1012     FieldDataCleanup(FieldData);
1013 
1014     /*
1015      * The reference count is not modified here. This function only allocates the
1016      * structure and makes adjustments to the some of the members. The reference
1017      * count was initialized when the structure was initially created and the
1018      * structure may be shared before the data portion is even allocated.
1019      */
1020     FieldData->NumValues                = NumValues;
1021     FieldData->Type                     = DataType;
1022     FieldData->ValueLocation            = ValueLocation;
1023 # if defined TECPLOTKERNEL
1024 /* CORE SOURCE CODE REMOVED */
1025 # else /* ...for TecIO only */
1026     FieldData->GetValueCallback[0] = (void *)DetermineFieldDataGetFunction(DataType, FALSE);
1027     FieldData->SetValueCallback[0] = (void *)DetermineFieldDataSetFunction(DataType, FALSE);
1028 #endif
1029 
1030     ENSURE(FieldData->Data == NULL);
1031 }
1032 
1033 #if defined TECPLOTKERNEL
1034 /* CORE SOURCE CODE REMOVED */
1035 #endif
1036 
1037 /**
1038  */
FieldDataAllocData(FieldData_pa FieldData,Boolean_t ShowErrMsg)1039 Boolean_t FieldDataAllocData(FieldData_pa FieldData,
1040                              Boolean_t    ShowErrMsg)
1041 {
1042     REQUIRE(VALID_REF(FieldData));
1043     REQUIRE(FieldData->Type != FieldDataType_Invalid); /* ...must call FieldDataDefineData first */
1044     REQUIRE(FieldData->Data == NULL);
1045     REQUIRE(VALID_BOOLEAN(ShowErrMsg));
1046 
1047     /*
1048      * The size of size_t may be smaller than our unsigned 64 bit integer value
1049      * so we might have to squeeze it down possibly loosing precision.
1050      */
1051     Int64_t ActualBytesNeeded = FieldDataGetBytesNeeded(FieldData->NumValues, FieldData->Type);
1052     size_t  BytesToAllocate   = (size_t)ActualBytesNeeded;
1053 
1054     /*
1055      * 64 bit architectures are effectively unlimited in their allocation size
1056      * while 32 architectures are limited to 4GB (some may limit further to 2GB
1057      * which will be borne out by the call to malloc).
1058      */
1059     CHECK(sizeof(size_t) == 4 || sizeof(size_t) == 8);
1060     Boolean_t IsOk = (FieldData->NumValues <= MAXINDEX &&
1061                       IMPLICATION(sizeof(size_t) == 4,
1062                                   ActualBytesNeeded <= (Int64_t)0xffffffff));
1063     if (IsOk)
1064     {
1065         if (FieldData->NumValues > 0)
1066         {
1067             FieldData->Data = (void *)ALLOC_ARRAY(BytesToAllocate, char, "FieldData's Data");
1068             #if defined DEBUG_FIELDVALUES
1069             {
1070                 if (FieldData->Data != NULL)
1071                     memset(FieldData->Data, DEBUG_FIELDVALUES_BAD_VALUE, BytesToAllocate);
1072             }
1073             #endif
1074             /*
1075              * For bit type data zero the last byte in the data array. We do
1076              * this because NumValues is probably not a multiple of 8 bits and
1077              * thus the valid bit values will not occupy all bits of the last
1078              * byte. By zeroing the unused bits at the end of the array we
1079              * produce consistent data files when written to disk.
1080              */
1081             if (FieldData->Type == FieldDataType_Bit && FieldData->Data != NULL)
1082                 ((char*)FieldData->Data)[BytesToAllocate-1] = '\0';
1083         }
1084         IsOk = (FieldData->NumValues == 0 ||
1085                 FieldData->Data != NULL);
1086         if (!IsOk && ShowErrMsg)
1087             OutOfMemoryMsg();
1088     }
1089     else if (ShowErrMsg)
1090         ErrMsg(translate("Storage limit (%ld) exceeded for a single variable."), (long)MAXINDEX);
1091 
1092 # if defined TECPLOTKERNEL
1093 /* CORE SOURCE CODE REMOVED */
1094 # endif
1095 
1096     ENSURE(VALID_REF(FieldData->Data) || FieldData->Data == NULL);
1097     ENSURE(VALID_BOOLEAN(IsOk));
1098     return IsOk;
1099 }
1100 
1101 #if defined TECPLOTKERNEL
1102 /* CORE SOURCE CODE REMOVED */
1103 #endif
1104 
1105 #if defined TECPLOTKERNEL
1106 /* CORE SOURCE CODE REMOVED */
1107 #endif
1108 
1109 #if defined TECPLOTKERNEL
1110 /* CORE SOURCE CODE REMOVED */
1111 #endif
1112 
1113 #if defined TECPLOTKERNEL
1114 /* CORE SOURCE CODE REMOVED */
1115 #endif
1116 
1117 #if defined TECPLOTKERNEL
1118 /* CORE SOURCE CODE REMOVED */
1119 #endif
1120 
1121 #if defined TECPLOTKERNEL
1122 /* CORE SOURCE CODE REMOVED */
1123 #endif
1124 
1125 #if defined TECPLOTKERNEL
1126 /* CORE SOURCE CODE REMOVED */
1127 #endif
1128 
1129 #if !defined NO_ASSERTS
1130 #if defined TECPLOTKERNEL
1131 /* CORE SOURCE CODE REMOVED */
1132 #endif
1133 #endif
1134 
1135 #if defined TECPLOTKERNEL
1136 /* CORE SOURCE CODE REMOVED */
1137 #endif
1138 
1139 #if defined TECPLOTKERNEL
1140 /* CORE SOURCE CODE REMOVED */
1141 #endif
1142 
1143 /**
1144  * Allocates a field data pointer with space for "num_pts" of field data type
1145  * "field_data_type" nodal values.
1146  *
1147  * IMPORTANT:
1148  *   This field data may NOT be used for zones but only for things like
1149  *   geometries or other temporary field data that will never be placed
1150  *   into a COB or zone.
1151  */
AllocScratchNodalFieldDataPtr(LgIndex_t NumValues,FieldDataType_e Type,Boolean_t ShowErrMsg)1152 FieldData_pa AllocScratchNodalFieldDataPtr(LgIndex_t       NumValues,
1153                                            FieldDataType_e Type,
1154                                            Boolean_t       ShowErrMsg)
1155 {
1156     REQUIRE(NumValues >= 0);
1157     REQUIRE(VALID_FIELD_DATA_TYPE(Type));
1158     REQUIRE(VALID_BOOLEAN(ShowErrMsg));
1159 
1160     FieldData_pa Result = FieldDataAlloc(FALSE);
1161     if (Result != NULL)
1162     {
1163         FieldDataDefineData(Result, NumValues, Type, ValueLocation_Nodal);
1164         if (!FieldDataAllocData(Result, ShowErrMsg))
1165             FieldDataDealloc(&Result, FALSE);
1166     }
1167     else if (ShowErrMsg)
1168         OutOfMemoryMsg();
1169 
1170     ENSURE(VALID_REF(Result) || Result == NULL);
1171 # if defined TECPLOTKERNEL
1172 /* CORE SOURCE CODE REMOVED */
1173 # endif
1174     ENSURE(IMPLICATION(Result != NULL,
1175                        (Result->NumValues >= 0                &&
1176                         IMPLICATION(Result->NumValues != 0,
1177                                     VALID_REF(Result->Data))  &&
1178                         VALID_FIELD_DATA_TYPE(Result->Type))));
1179 
1180     return Result;
1181 }
1182 
1183 
1184 /**
1185  * Frees memory allocated with AllocScratchNodalFieldDataPtr().
1186  *
1187  * @param ScratchFieldData
1188  *   Scratch field data pointer to deallocate. This should NEVER be a field
1189  *   data from a zone or COB. See note in AllocScratchNodalFieldDataPtr().
1190  */
DeallocScratchNodalFieldDataPtr(FieldData_pa * FieldDataRef)1191 void DeallocScratchNodalFieldDataPtr(FieldData_pa *FieldDataRef)
1192 {
1193     FieldDataDealloc(FieldDataRef,
1194                      FALSE); /* DoTrackVarSharing */
1195 }
1196 
1197 
1198 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1199 /**
1200  */
GetFieldDataType_FUNC(FieldData_pa FieldData)1201 FieldDataType_e GetFieldDataType_FUNC(FieldData_pa FieldData)
1202 {
1203     REQUIRE(VALID_REF(FieldData));
1204 
1205     FieldDataType_e Result = GetFieldDataType_MACRO(FieldData);
1206 
1207     ENSURE(VALID_FIELD_DATA_TYPE(Result));
1208     return Result;
1209 }
1210 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1211 
1212 
1213 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1214 /**
1215  */
GetFieldDataGetFunction_FUNC(FieldData_pa FieldData)1216 FieldValueGetFunction_pf GetFieldDataGetFunction_FUNC(FieldData_pa FieldData)
1217 {
1218     REQUIRE(VALID_REF(FieldData));
1219 
1220     FieldValueGetFunction_pf Result = GetFieldDataGetFunction_MACRO(FieldData);
1221 
1222     ENSURE(VALID_FN_REF(Result));
1223     return Result;
1224 }
1225 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1226 
1227 
1228 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1229 /**
1230  */
GetFieldDataSetFunction_FUNC(FieldData_pa FieldData)1231 FieldValueSetFunction_pf GetFieldDataSetFunction_FUNC(FieldData_pa FieldData)
1232 {
1233     REQUIRE(VALID_REF(FieldData));
1234 
1235     FieldValueSetFunction_pf Result = GetFieldDataSetFunction_MACRO(FieldData);
1236 
1237     ENSURE(VALID_FN_REF(Result));
1238     return Result;
1239 }
1240 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1241 
1242 
1243 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1244 /**
1245  */
GetFieldDataNumValues_FUNC(FieldData_pa FieldData)1246 LgIndex_t GetFieldDataNumValues_FUNC(FieldData_pa FieldData)
1247 {
1248     REQUIRE(VALID_REF(FieldData));
1249 
1250     LgIndex_t Result = GetFieldDataNumValues_MACRO(FieldData);
1251 
1252     ENSURE(Result >= 0);
1253     return Result;
1254 }
1255 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1256 
1257 
1258 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1259 /**
1260  */
GetFieldDataValueLocation_FUNC(FieldData_pa FieldData)1261 ValueLocation_e GetFieldDataValueLocation_FUNC(FieldData_pa FieldData)
1262 {
1263     REQUIRE(VALID_REF(FieldData));
1264 
1265     ValueLocation_e Result = GetFieldDataValueLocation_MACRO(FieldData);
1266 
1267     ENSURE(Result == ValueLocation_Invalid || /* i.e. pending assignment */
1268            VALID_ENUM(Result, ValueLocation_e));
1269     return Result;
1270 }
1271 #endif /* !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS */
1272 
1273 
1274 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1275 /**
1276  */
IsFieldDataDirectAccessAllowed_FUNC(FieldData_pa FieldData)1277 Boolean_t IsFieldDataDirectAccessAllowed_FUNC(FieldData_pa FieldData)
1278 {
1279     REQUIRE(VALID_REF(FieldData));
1280 
1281     Boolean_t Result = IsFieldDataDirectAccessAllowed_MACRO(FieldData);
1282 
1283     ENSURE(VALID_BOOLEAN(Result));
1284     return Result;
1285 }
1286 #endif
1287 
1288 
1289 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1290 /**
1291  */
GetFieldDataFloatPtr_FUNC(FieldData_pa fd)1292 float *GetFieldDataFloatPtr_FUNC(FieldData_pa fd)
1293 {
1294     REQUIRE(VALID_REF(fd));
1295 
1296     float *Result = GetFieldDataFloatPtr_MACRO(fd);
1297 
1298     ENSURE(VALID_REF(Result));
1299     return Result;
1300 }
1301 #endif
1302 
1303 
1304 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1305 /**
1306  */
GetFieldDataDoublePtr_FUNC(FieldData_pa fd)1307 double *GetFieldDataDoublePtr_FUNC(FieldData_pa fd)
1308 {
1309     REQUIRE(VALID_REF(fd));
1310 
1311     double *Result = GetFieldDataDoublePtr_MACRO(fd);
1312 
1313     ENSURE(VALID_REF(Result));
1314     return Result;
1315 }
1316 #endif
1317 
1318 
1319 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1320 /**
1321  */
GetFieldDataInt64Ptr_FUNC(FieldData_pa fd)1322 Int64_t *GetFieldDataInt64Ptr_FUNC(FieldData_pa fd)
1323 {
1324     REQUIRE(VALID_REF(fd));
1325 
1326     Int64_t *Result = GetFieldDataInt64Ptr_MACRO(fd);
1327 
1328     ENSURE(VALID_REF(Result));
1329     return Result;
1330 }
1331 #endif
1332 
1333 
1334 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1335 /**
1336  */
GetFieldDataInt32Ptr_FUNC(FieldData_pa fd)1337 Int32_t *GetFieldDataInt32Ptr_FUNC(FieldData_pa fd)
1338 {
1339     REQUIRE(VALID_REF(fd));
1340 
1341     Int32_t *Result = GetFieldDataInt32Ptr_MACRO(fd);
1342 
1343     ENSURE(VALID_REF(Result));
1344     return Result;
1345 }
1346 #endif
1347 
1348 
1349 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1350 /**
1351  */
GetFieldDataInt16Ptr_FUNC(FieldData_pa fd)1352 Int16_t *GetFieldDataInt16Ptr_FUNC(FieldData_pa fd)
1353 {
1354     REQUIRE(VALID_REF(fd));
1355 
1356     Int16_t *Result = GetFieldDataInt16Ptr_MACRO(fd);
1357 
1358     ENSURE(VALID_REF(Result));
1359     return Result;
1360 }
1361 #endif
1362 
1363 
1364 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1365 /*
1366  * No byte ordering or alignment issues with single bytes (which are also used with the "Bit" type)
1367  */
GetFieldDataBytePtr_FUNC(FieldData_pa fd)1368 Byte_t *GetFieldDataBytePtr_FUNC(FieldData_pa fd)
1369 {
1370     /*
1371      * This function gets called for Byte and Bit types, but we cannot REQUIRE
1372      * those types because it is also used for non-aligned values.  We can't
1373      * check for non-aligned because we might be copying aligned bytes to a
1374      * non-aligned location.
1375      */
1376     REQUIRE(VALID_REF(fd));
1377 
1378     Byte_t *Result = GetFieldDataBytePtr_MACRO(fd);
1379 
1380     ENSURE(VALID_REF(Result));
1381     return Result;
1382 }
1383 #endif
1384 
1385 
1386 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1387 /**
1388  * Gets a ptr to 2-byte blocks regardless of byte ordering, but still has to
1389  * worry about byte alignment
1390  */
GetFieldData2BytePtr_FUNC(FieldData_pa fd)1391 UInt16_t *GetFieldData2BytePtr_FUNC(FieldData_pa fd)
1392 {
1393     REQUIRE(VALID_REF(fd));
1394     REQUIRE(fd->Type == FieldDataType_Int16);
1395 
1396     UInt16_t *Result = GetFieldData2BytePtr_MACRO(fd);
1397 
1398     ENSURE(VALID_REF(Result));
1399     return Result;
1400 }
1401 #endif
1402 
1403 
1404 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1405 /*
1406  * Gets a ptr to 4-byte blocks regardless of byte ordering, but still has to
1407  * worry about byte alignment
1408  */
GetFieldData4BytePtr_FUNC(FieldData_pa fd)1409 UInt32_t *GetFieldData4BytePtr_FUNC(FieldData_pa fd)
1410 {
1411     REQUIRE(VALID_REF(fd));
1412     REQUIRE(fd->Type == FieldDataType_Int32 || fd->Type == FieldDataType_Float);
1413 
1414     UInt32_t *Result = GetFieldData4BytePtr_MACRO(fd);
1415 
1416     ENSURE(VALID_REF(Result));
1417     return Result;
1418 }
1419 #endif
1420 
1421 
1422 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1423 /*
1424  * Gets a ptr to 8-byte blocks regardless of byte ordering, but still has to
1425  * worry about byte alignment
1426  */
GetFieldData8BytePtr_FUNC(FieldData_pa fd)1427 UInt64_t *GetFieldData8BytePtr_FUNC(FieldData_pa fd)
1428 {
1429     REQUIRE(VALID_REF(fd));
1430     REQUIRE(fd->Type == FieldDataType_Int64 || fd->Type == FieldDataType_Double);
1431 
1432     UInt64_t *Result = GetFieldData8BytePtr_MACRO(fd);
1433 
1434     ENSURE(VALID_REF(Result));
1435     return Result;
1436 }
1437 #endif
1438 
1439 
1440 #if !defined USE_MACROS_FOR_FIELD_DATA_FUNCTIONS
1441 /*
1442  * WARNING: GetFieldDataVoidPtr checks nothing, and thus should only be
1443  * used with extreme caution (that is, checking the alignment
1444  * and byte order by hand).
1445  */
GetFieldDataVoidPtr_FUNC(FieldData_pa fd)1446 void *GetFieldDataVoidPtr_FUNC(FieldData_pa fd)
1447 {
1448     REQUIRE(VALID_REF(fd));
1449 
1450     void *Result = GetFieldDataVoidPtr_MACRO(fd);
1451 
1452     ENSURE(VALID_REF(Result));
1453     return Result;
1454 }
1455 #endif
1456 
1457 #if defined TECPLOTKERNEL
1458 /* CORE SOURCE CODE REMOVED */
1459 #endif
1460 
1461 #if defined TECPLOTKERNEL
1462 /* CORE SOURCE CODE REMOVED */
1463 #endif
1464 
1465 #if defined TECPLOTKERNEL
1466 /* CORE SOURCE CODE REMOVED */
1467 #endif
1468 
1469 #if defined TECPLOTKERNEL
1470 /* CORE SOURCE CODE REMOVED */
1471 #endif
1472 
1473 #if defined TECPLOTKERNEL
1474 /* CORE SOURCE CODE REMOVED */
1475 #endif
1476 
1477 #if defined TECPLOTKERNEL
1478 /* CORE SOURCE CODE REMOVED */
1479 #endif /* TECPLOTKERNEL */
1480 
1481 #if defined TECPLOTKERNEL
1482 /* CORE SOURCE CODE REMOVED */
1483 #endif
1484 
1485 #if defined TECPLOTKERNEL
1486 /* CORE SOURCE CODE REMOVED */
1487 #endif
1488 
1489 #if defined TECPLOTKERNEL
1490 /* CORE SOURCE CODE REMOVED */
1491 #endif
1492 
1493 #if defined TECPLOTKERNEL
1494 /* CORE SOURCE CODE REMOVED */
1495 #endif
1496 
1497 #if defined TECPLOTKERNEL
1498 /* CORE SOURCE CODE REMOVED */
1499 #endif
1500 
1501 #if defined TECPLOTKERNEL
1502 /* CORE SOURCE CODE REMOVED */
1503 #endif
1504 
1505 #if defined TECPLOTKERNEL
1506 /* CORE SOURCE CODE REMOVED */
1507 #endif
1508 
1509 #if defined TECPLOTKERNEL
1510 /* CORE SOURCE CODE REMOVED */
1511 #endif
1512 
1513 #if defined TECPLOTKERNEL
1514 /* CORE SOURCE CODE REMOVED */
1515 #endif
1516 
1517 #if defined TECPLOTKERNEL
1518 /* CORE SOURCE CODE REMOVED */
1519 #endif /* TECPLOTKERNEL */
1520 
1521 #if defined TECPLOTKERNEL
1522 /* CORE SOURCE CODE REMOVED */
1523 #endif
1524 
1525 
1526 /*
1527  */
CopyFieldValue(FieldData_pa dst,LgIndex_t dstindex,FieldData_pa src,LgIndex_t srcindex)1528 void CopyFieldValue(FieldData_pa  dst,
1529                     LgIndex_t     dstindex,
1530                     FieldData_pa  src,
1531                     LgIndex_t     srcindex)
1532 {
1533     REQUIRE(VALID_REF(dst));
1534     REQUIRE(VALID_REF(src));
1535 #if defined TECPLOTKERNEL
1536 /* CORE SOURCE CODE REMOVED */
1537 #endif /* TECPLOTKERNEL */
1538     REQUIRE(dstindex >= 0 && dstindex < GetFieldDataNumValues(dst) &&
1539             srcindex >= 0 && srcindex < GetFieldDataNumValues(src));
1540 
1541     Boolean_t DoBruteForceCopy = TRUE;
1542 
1543     if (IsFieldDataDirectAccessAllowed(src) &&
1544         IsFieldDataDirectAccessAllowed(dst) &&
1545         GetFieldDataType(src) == GetFieldDataType(dst))
1546     {
1547         switch (GetFieldDataType(src))
1548         {
1549             case FieldDataType_Int64 : CHECK(FALSE); /* Future work: remove and let fall through */
1550             case FieldDataType_Double :
1551             {
1552                 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
1553                 UInt64_t *dst_ptr = GetFieldData8BytePtr(dst) + dstindex;
1554                 UInt64_t *src_ptr = GetFieldData8BytePtr(src) + srcindex;
1555                 *dst_ptr = *src_ptr;
1556                 DoBruteForceCopy = FALSE;
1557             } break;
1558             case FieldDataType_Float :
1559             case FieldDataType_Int32 :
1560             {
1561                 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
1562                 UInt32_t *dst_ptr = GetFieldData4BytePtr(dst) + dstindex;
1563                 UInt32_t *src_ptr = GetFieldData4BytePtr(src) + srcindex;
1564                 *dst_ptr = *src_ptr;
1565                 DoBruteForceCopy = FALSE;
1566             } break;
1567             case FieldDataType_Int16 :
1568             {
1569                 CHECK(sizeof(UInt16_t) == 2);
1570                 UInt16_t *dst_ptr = GetFieldData2BytePtr(dst) + dstindex;
1571                 UInt16_t *src_ptr = GetFieldData2BytePtr(src) + srcindex;
1572                 *dst_ptr = *src_ptr;
1573             } break;
1574             case FieldDataType_Byte :
1575             {
1576                 GetFieldDataBytePtr(dst)[dstindex] = GetFieldDataBytePtr(src)[srcindex];
1577                 DoBruteForceCopy = FALSE;
1578             } break;
1579             case FieldDataType_Bit : break; /* handle below */
1580             default : CHECK(FALSE); /* Future work: when more complex types are added, remove this CHECK */
1581         }
1582     }
1583 
1584     if (DoBruteForceCopy)
1585     {
1586         double val = GetFieldValue(src, srcindex);
1587         SetFieldValue(dst, dstindex, val);
1588     }
1589 } /* CopyFieldValue() */
1590 
1591 
1592 #if defined TECPLOTKERNEL
1593 /* CORE SOURCE CODE REMOVED */
1594 #if defined TECPLOTKERNEL
1595 #endif /* TECPLOTKERNEL */
1596 #endif
1597 
1598 #if defined TECPLOTKERNEL
1599 /* CORE SOURCE CODE REMOVED */
1600 #endif
1601 
1602 #if defined TECPLOTKERNEL
1603 /* CORE SOURCE CODE REMOVED */
1604 #endif
1605 
1606 #if defined TECPLOTKERNEL
1607 /* CORE SOURCE CODE REMOVED */
1608 #endif
1609 
1610 #if defined TECPLOTKERNEL
1611 /* CORE SOURCE CODE REMOVED */
1612 #endif
1613 
1614 
1615 #if defined TECPLOTKERNEL
1616 /* CORE SOURCE CODE REMOVED */
1617 #endif /* TECPLOTKERNEL */
1618 
1619 
1620 /*
1621  */
SetFieldDataPtrToAllZeros(FieldData_pa fd)1622 void SetFieldDataPtrToAllZeros(FieldData_pa fd)
1623 {
1624     REQUIRE(VALID_REF(fd));
1625 #if defined TECPLOTKERNEL
1626 /* CORE SOURCE CODE REMOVED */
1627 #endif /* TECPLOTKERNEL */
1628 
1629     LgIndex_t NumValues = GetFieldDataNumValues(fd);
1630 
1631     /*
1632      * memset each byte to 0 works for floats and doubles and works regardless
1633      * of byte ordering or alignment.
1634      */
1635     size_t NumBytesToMemSet = 0;
1636     if (IsFieldDataDirectAccessAllowed(fd))
1637     {
1638         switch (GetFieldDataType(fd))
1639         {
1640             case FieldDataType_Int64 : CHECK(FALSE); /* Future work: remove CHECK */
1641             case FieldDataType_Double :
1642             {
1643                 CHECK(sizeof(UInt64_t) == 8 && sizeof(double) == 8);
1644                 NumBytesToMemSet = NumValues * sizeof(Int64_t);
1645             } break;
1646             case FieldDataType_Int32 :
1647             case FieldDataType_Float :
1648             {
1649                 CHECK(sizeof(UInt32_t) == 4 && sizeof(float) == 4);
1650                 NumBytesToMemSet = NumValues * sizeof(Int32_t);
1651             } break;
1652             case FieldDataType_Int16 :
1653             {
1654                 CHECK(sizeof(UInt16_t) == 2);
1655                 NumBytesToMemSet = NumValues * sizeof(Int16_t);
1656             } break;
1657             case FieldDataType_Byte :
1658             {
1659                 NumBytesToMemSet = NumValues * sizeof(Byte_t);
1660             } break;
1661             case FieldDataType_Bit :
1662             {
1663                 NumBytesToMemSet = ((NumValues + 7) / 8) * sizeof(Byte_t);
1664             } break;
1665             default :
1666             {
1667                 CHECK(FALSE);
1668             } break;
1669         }
1670     }
1671 
1672     if (NumBytesToMemSet > 0)
1673     {
1674         char* fd_data = (char*)GetFieldDataVoidPtr(fd);
1675         #if defined TECPLOTKERNEL
1676 /* CORE SOURCE CODE REMOVED */
1677         #else
1678             memset(fd_data, 0, NumBytesToMemSet);
1679         #endif
1680     }
1681     else
1682     {
1683         int ii;
1684         for (ii = 0; ii < NumValues; ii++)
1685             SetFieldValue(fd, ii, 0.0);
1686     }
1687 
1688 } /* SetFieldDataPtrToAllZeros() */
1689 
1690 #if defined TECPLOTKERNEL
1691 /* CORE SOURCE CODE REMOVED */
1692 #endif /* TECPLOTKERNEL */
1693