source: XIOS/trunk/src/node/interpolate_domain.cpp @ 1004

Last change on this file since 1004 was 1004, checked in by mhnguyen, 8 years ago

Some modifications of reading/writing interpolation weight from/into a file
There are 3 attributes concerning read/write weights from/into a file

  • write_weight: true/false. Default value: false
  • weight_filename.
  • mode: Default value: compute + read: read from file whose name is weight_filename + compute: compute weights + read_or_compute: if weight_filename already exists, the weights will be read from it; otherwise the weights will be computed

In mode compute and read_or_compute, if there is no weight_filename, a filename whose format
xios_interpolation_weight_nameOfContext_nameOfDomainSource_nameOfDomainDestination.nc will be used for read/write.

Test
+) On Curie
+) Work

File size: 3.3 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    if (this->mode.isEmpty()) this->mode.setValue(mode_attr::compute);
51    if (this->write_weight.isEmpty()) this->write_weight.setValue(false);
52
53    StdString weightFile;
54    switch (this->mode)
55    {
56      case mode_attr::read:
57        if (this->file.isEmpty())
58        {
59          if (!this->write_weight)
60            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
61                 << "Read mode is activated but there is no file specified." << std::endl
62                 << "Please define a correct file containing interpolation weights with option 'file'. ");
63        }
64        else
65        {
66          weightFile = this->file;
67          ifstream f(weightFile.c_str());
68          if (!f.good())
69            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
70                  << "Read mode is activated but file "  << weightFile << " doesn't exist." << std::endl
71                  << "Please check this file ");
72        }
73        break;
74      case mode_attr::compute:
75        break;
76      case mode_attr::read_or_compute:
77        if (!this->file.isEmpty() && !this->write_weight)
78        {
79          weightFile = this->file;
80          ifstream f(weightFile.c_str());
81          if (!f.good())
82            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
83                  << "read_or_compute mode is activated but file "  << weightFile << " doesn't exist." << std::endl
84                  << "Please check this file ");
85        }
86        break;
87      default:
88        break;
89    }
90
91  }
92
93}
Note: See TracBrowser for help on using the repository browser.