source: XIOS/trunk/src/node/axis.cpp @ 566

Last change on this file since 566 was 566, checked in by rlacroix, 9 years ago

Improve the error messages when checking the axis attributes.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 5.9 KB
Line 
1#include "axis.hpp"
2
3#include "attribute_template.hpp"
4#include "object_template.hpp"
5#include "group_template.hpp"
6#include "message.hpp"
7#include "type.hpp"
8#include "xmlioserver_spl.hpp"
9
10namespace xios {
11
12   /// ////////////////////// Définitions ////////////////////// ///
13
14   CAxis::CAxis(void)
15      : CObjectTemplate<CAxis>()
16      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject()
17   { /* Ne rien faire de plus */ }
18
19   CAxis::CAxis(const StdString & id)
20      : CObjectTemplate<CAxis>(id)
21      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject()
22   { /* Ne rien faire de plus */ }
23
24   CAxis::~CAxis(void)
25   { /* Ne rien faire de plus */ }
26
27   ///---------------------------------------------------------------
28
29   const std::set<StdString> & CAxis::getRelFiles(void) const
30   {
31      return (this->relFiles);
32   }
33
34   bool CAxis::IsWritten(const StdString & filename) const
35   {
36      return (this->relFiles.find(filename) != this->relFiles.end());
37   }
38
39   void CAxis::addRelFile(const StdString & filename)
40   {
41      this->relFiles.insert(filename);
42   }
43
44   //----------------------------------------------------------------
45
46   StdString CAxis::GetName(void)   { return (StdString("axis")); }
47   StdString CAxis::GetDefName(void){ return (CAxis::GetName()); }
48   ENodeType CAxis::GetType(void)   { return (eAxis); }
49
50   //----------------------------------------------------------------
51
52   void CAxis::checkAttributes(void)
53   {
54      if (this->isChecked) return;
55      if (this->size.isEmpty())
56         ERROR("CAxis::checkAttributes(void)",
57               << "Attribute <size> of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be specified");
58      StdSize size = this->size.getValue();
59
60      if (!this->ibegin.isEmpty())
61      {
62        StdSize ibegin = this->ibegin.getValue();
63        if ((ibegin < 0) || (ibegin > size-1))
64          ERROR("CAxis::checkAttributes(void)",
65                << "Attribute <ibegin> of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be non-negative and smaller than size-1");
66      }
67      else this->ibegin.setValue(0);
68
69      if (!this->ni.isEmpty())
70      {
71        StdSize ni = this->ni.getValue();
72        if ((ni < 0) || (ni > size))
73          ERROR("CAxis::checkAttributes(void)",
74                << "Attribute <ni> of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be non-negative and smaller than size");
75      }
76      else this->ni.setValue(size);
77
78      StdSize zoom_begin,zoom_end, zoom_size;
79
80      // Maybe index begins at 0 (zero)
81      zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue();
82      zoom_end = (this->zoom_end.isEmpty()) ?  size-1 : this->zoom_end.getValue();
83      zoom_size = (this->zoom_size.isEmpty()) ?  size : this->zoom_size.getValue();
84
85      if (this->zoom_begin.isEmpty()) zoom_begin=zoom_end-zoom_size+1;
86      if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1;
87      if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1;
88
89      if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end))
90        ERROR("CAxis::checkAttributes(void)",
91              << "One or more attributes among <zoom_begin>, <zoom_end>, <zoom_size> of axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified");
92
93      this->zoom_begin.setValue(zoom_begin);
94      this->zoom_end.setValue(zoom_end);
95      this->zoom_size.setValue(zoom_size);
96
97      StdSize true_size = value.numElements();
98      if (size != true_size)
99         ERROR("CAxis::checkAttributes(void)",
100               << "The array \'value\' of axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] has a different size that the one defined by the \'size\' attribute");
101
102      this->checkData();
103      this->checkMask();
104      this->isChecked = true;
105   }
106
107   void CAxis::checkData()
108   {
109      if (data_begin.isEmpty()) data_begin.setValue(0);
110      if (!data_n.isEmpty() && data_n.getValue() <= 0)
111      {
112        ERROR("CAxis::checkData(void)",
113              << "Data dimension is negative (data_n).");
114      }
115      else if (data_n.isEmpty())
116        data_n.setValue(ni.getValue());
117
118      if (data_index.isEmpty())
119      {
120        int dn = data_n.getValue();
121        data_index.resize(dn);
122        for (int i = 0; i < dn; ++i) data_index(i) = (i+1);
123      }
124   }
125
126   void CAxis::checkMask()
127   {
128      int begin_mask = 0,
129          end_mask = ni.getValue()-1;
130
131      if (!zoom_begin.isEmpty())
132      {
133         int zoom_end = zoom_begin.getValue() + zoom_size.getValue() - 1;
134
135         begin_mask = std::max(ibegin.getValue(), zoom_begin.getValue());
136         end_mask   = std::min(ibegin.getValue() + ni.getValue()-1, zoom_end);
137
138         begin_mask -= ibegin.getValue();
139         end_mask   -= ibegin.getValue();
140      }
141
142
143      if (!mask.isEmpty())
144      {
145         if (mask.extent(0) != ni)
146            ERROR("CAxis::checkMask(void)",
147                  <<"the mask has not the same size than the local axis"<<endl
148                  <<"Local size is "<<ni<<"x"<<endl
149                  <<"Mask size is "<<mask.extent(0)<<"x");
150         for (int i = 0; i < ni; ++i)
151         {
152           if (i < begin_mask && i > end_mask)  mask(i) = false;
153         }
154      }
155      else // (!mask.hasValue())
156      { // Si aucun masque n'est défini,
157        // on en crée un nouveau qui valide l'intégralité du domaine.
158         mask.resize(ni);
159         for (int i = 0; i < ni.getValue(); ++i)
160         {
161               if (i >= begin_mask && i <= end_mask)
162                 mask(i) = true;
163               else  mask(i) = false;
164         }
165      }
166   }
167
168   DEFINE_REF_FUNC(Axis,axis)
169
170   ///---------------------------------------------------------------
171
172} // namespace xios
Note: See TracBrowser for help on using the repository browser.