ADIOSScalar.cxx 3.67 KB
Newer Older
1
/*=========================================================================
2

3 4
  Program:   Visualization Toolkit
  Module:    ADIOSScalar.cxx
5

6 7 8
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11 12
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.
13

14
=========================================================================*/
15

16 17 18 19
#include <complex>
#include <stdexcept>

#include <adios_read.h>
20

21
#include "ADIOSScalar.h"
22

23 24
namespace ADIOS
{
25

26 27 28 29 30
template<typename T>
void LoadScalarsFromStats(void* &ptr, ADIOS_VARINFO *v)
{
  T* &ptrT = reinterpret_cast<T*&>(ptr);
  ptrT = new T[v->sum_nblocks];
31
  for(int i = 0; i < v->sum_nblocks; ++i)
32
  {
33
    ptrT[i] = *reinterpret_cast<const T*>(v->statistics->blocks->mins[i]);
34
  }
35 36
}

37 38
//----------------------------------------------------------------------------
Scalar::Scalar(ADIOS_FILE *f, ADIOS_VARINFO *v)
39
: VarInfo(f, v), Values(nullptr)
40 41
{
  switch(this->Type)
42
  {
43
    case adios_byte:
44
      LoadScalarsFromStats<int8_t>(this->Values, v);
45
      break;
46
    case adios_short:
47
      LoadScalarsFromStats<int16_t>(this->Values, v);
48
      break;
49
    case adios_integer:
50
      LoadScalarsFromStats<int32_t>(this->Values, v);
51
      break;
52
    case adios_long:
53
      LoadScalarsFromStats<int64_t>(this->Values, v);
54
      break;
55
    case adios_unsigned_byte:
56
      LoadScalarsFromStats<uint8_t>(this->Values, v);
57
      break;
58
    case adios_unsigned_short:
59
      LoadScalarsFromStats<uint16_t>(this->Values, v);
60
      break;
61
    case adios_unsigned_integer:
62
      LoadScalarsFromStats<uint32_t>(this->Values, v);
63
      break;
64
    case adios_unsigned_long:
65
      LoadScalarsFromStats<uint64_t>(this->Values, v);
66
      break;
67
    case adios_real:
68
      LoadScalarsFromStats<float>(this->Values, v);
69
      break;
70
    case adios_double:
71
      LoadScalarsFromStats<double>(this->Values, v);
72 73
      break;
    case adios_complex:
74
      LoadScalarsFromStats<std::complex<float> >(this->Values, v);
75 76
      break;
    case adios_double_complex:
77 78 79 80
      LoadScalarsFromStats<std::complex<double> >(this->Values, v);
      break;
    default:
      // Unsupported data type
81
      break;
82
  }
83 84 85
}

//----------------------------------------------------------------------------
86
Scalar::~Scalar()
87
{
88
  if(!this->Values)
89
  {
90
    return;
91
  }
92 93

  switch(this->Type)
94
  {
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    case adios_byte:
      delete[] reinterpret_cast<int8_t*>(this->Values);
      break;
    case adios_short:
      delete[] reinterpret_cast<int16_t*>(this->Values);
      break;
    case adios_integer:
      delete[] reinterpret_cast<int32_t*>(this->Values);
      break;
    case adios_long:
      delete[] reinterpret_cast<int64_t*>(this->Values);
      break;
    case adios_unsigned_byte:
      delete[] reinterpret_cast<uint8_t*>(this->Values);
      break;
    case adios_unsigned_short:
      delete[] reinterpret_cast<uint16_t*>(this->Values);
      break;
    case adios_unsigned_integer:
      delete[] reinterpret_cast<uint32_t*>(this->Values);
      break;
    case adios_unsigned_long:
      delete[] reinterpret_cast<uint64_t*>(this->Values);
      break;
    case adios_real:
      delete[] reinterpret_cast<float*>(this->Values);
      break;
    case adios_double:
      delete[] reinterpret_cast<double*>(this->Values);
      break;
    case adios_complex:
      delete[] reinterpret_cast<std::complex<float>*>(this->Values);
      break;
    case adios_double_complex:
      delete[] reinterpret_cast<std::complex<double>*>(this->Values);
      break;
131
    default: break;
132
  }
133 134
}

135
} // End namespace ADIOS