aboutsummaryrefslogtreecommitdiff
path: root/CarpetDev/CarpetIOF5/src/physical_quantity.cc
blob: 0b6720ecef189a60dd2b641da1db80afe71f5cd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <cassert>
#include <cstdlib>

#include "cctk.h"

#include "physical_quantity.hh"



namespace CarpetIOF5 {
  
  namespace F5 {
    
    physical_quantity_t::
    physical_quantity_t (coordinate_system_t & coordinate_system,
                         int const group)
      : m_coordinate_system (coordinate_system),
        m_group (group)
    {
      assert (group >= 0 and group < CCTK_NumGroups());
      
      char * const name = CCTK_GroupName (group);
      assert (name != 0);
      for (char * p = name; * p; ++ p)
      {
        * p = static_cast<char> (tolower (* p));
      }
      m_name = string (name);
      
      m_hdf5_physical_quantity
        = open_or_create_group (m_coordinate_system
                                .get_hdf5_coordinate_system(),
                                name);
      assert (m_hdf5_physical_quantity >= 0);
      
      free (name);
      
      assert (invariant());
    }
    
    
    
    physical_quantity_t::
    ~ physical_quantity_t ()
    {
      herr_t const herr = H5Gclose (m_hdf5_physical_quantity);
      assert (not herr);
    }
    
    
    
    coordinate_system_t & physical_quantity_t::
    get_coordinate_system ()
      const
    {
      return m_coordinate_system;
    }
    
    
    
    int physical_quantity_t::
    get_group ()
      const
    {
      return m_group;
    }
    
    
    
    hid_t physical_quantity_t::
    get_hdf5_physical_quantity ()
      const
    {
      return m_hdf5_physical_quantity;
    }
    
    
    
    void physical_quantity_t::
    get_link_destination (string & filename,
                          string & objectname)
      const
    {
      static bool initialised = false;
      static string l_filename;
      static string l_objectname;
      if (not initialised)
      {
        initialised = true;
        get_coordinate_system().get_link_destination (l_filename, l_objectname);
        l_objectname += string ("/") + m_name;
      }
      filename = l_filename;
      objectname = l_objectname;
    }
    
    
    
    bool physical_quantity_t::
    invariant ()
      const
    {
      return (m_group >= 0 and m_group < CCTK_NumGroups()
              and m_hdf5_physical_quantity >= 0);
    }
    
  } // namespace F5

} // namespace CarpetIOF5