source: XIOS/dev/XIOS_DEV_CMIP6/src/node/interpolate_domain.cpp @ 1264

Last change on this file since 1264 was 1264, checked in by ymipsl, 7 years ago
  • Add new attribute : detect_missing_value on "interpolate_domain" element. It will replace the standard detect_missing_value set on the field. It will be added progressively to all spatial transformation.
  • Now, when detecting missing value, horizontal interpolation do a correct renormalization.

YM

File size: 3.9 KB
Line 
1#include "interpolate_domain.hpp"
2#include "type.hpp"
3
4namespace xios {
5
6  /// ////////////////////// Définitions ////////////////////// ///
7
8  CInterpolateDomain::CInterpolateDomain(void)
9    : CObjectTemplate<CInterpolateDomain>(), CInterpolateDomainAttributes(), CTransformation<CDomain>()
10  { /* Ne rien faire de plus */ }
11
12  CInterpolateDomain::CInterpolateDomain(const StdString & id)
13    : CObjectTemplate<CInterpolateDomain>(id), CInterpolateDomainAttributes(), CTransformation<CDomain>()
14  { /* Ne rien faire de plus */ }
15
16  CInterpolateDomain::~CInterpolateDomain(void)
17  {}
18
19  CTransformation<CDomain>* CInterpolateDomain::create(const StdString& id, xml::CXMLNode* node)
20  {
21    CInterpolateDomain* interpDomain = CInterpolateDomainGroup::get("interpolate_domain_definition")->createChild(id);
22    if (node) interpDomain->parse(*node);
23    return static_cast<CTransformation<CDomain>*>(interpDomain);
24  }
25
26  bool CInterpolateDomain::_dummyRegistered = CInterpolateDomain::registerTrans();
27  bool CInterpolateDomain::registerTrans()
28  {
29    registerTransformation(TRANS_INTERPOLATE_DOMAIN, create);
30  }
31
32  //----------------------------------------------------------------
33
34  StdString CInterpolateDomain::GetName(void)    { return StdString("interpolate_domain"); }
35  StdString CInterpolateDomain::GetDefName(void) { return StdString("interpolate_domain"); }
36  ENodeType CInterpolateDomain::GetType(void)    { return eInterpolateDomain; }
37
38  void CInterpolateDomain::checkValid(CDomain* domainSrc)
39  {
40    int order = 2;
41    if (!this->order.isEmpty()) order = this->order.getValue();
42    else this->order.setValue(order);
43    if (order < 1)
44    {
45       ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
46             << "Interpolation order is less than 1, it should be greater than 0."
47             << "Please define a correct one") ;
48    }
49
50    bool detect_missing_value=false ;
51    if (!this->detect_missing_value.isEmpty()) detect_missing_value = this->detect_missing_value.getValue();
52    else this->detect_missing_value.setValue(detect_missing_value);
53
54    bool renormalize=false ;
55    if (!this->renormalize.isEmpty()) renormalize = this->renormalize.getValue();
56    else this->renormalize.setValue(renormalize);
57
58    bool quantity=false ;
59    if (!this->quantity.isEmpty()) quantity = this->quantity.getValue();
60    else this->quantity.setValue(quantity);
61
62    if (this->mode.isEmpty()) this->mode.setValue(mode_attr::compute);
63    if (this->write_weight.isEmpty()) this->write_weight.setValue(false);
64
65    StdString weightFile;
66    switch (this->mode)
67    {
68      case mode_attr::read:
69        if (this->weight_filename.isEmpty())
70        {
71          if (!this->write_weight)
72            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
73                 << "Read mode is activated but there is no file specified." << std::endl
74                 << "Please define a correct file containing interpolation weights with option 'file'. ");
75        }
76        else
77        {
78          weightFile = this->weight_filename;
79          ifstream f(weightFile.c_str());
80          if (!f.good())
81            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
82                  << "Read mode is activated but file "  << weightFile << " doesn't exist." << std::endl
83                  << "Please check this file ");
84        }
85        break;
86      case mode_attr::compute:
87        break;
88      case mode_attr::read_or_compute:
89        if (!this->weight_filename.isEmpty() && !this->write_weight)
90        {
91          weightFile = this->weight_filename;
92          ifstream f(weightFile.c_str());
93          if (!f.good())
94            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
95                  << "read_or_compute mode is activated but file "  << weightFile << " doesn't exist." << std::endl
96                  << "Please check this file ");
97        }
98        break;
99      default:
100        break;
101    }
102
103  }
104
105}
Note: See TracBrowser for help on using the repository browser.