source: XIOS/trunk/src/node/generate_rectilinear_domain.cpp @ 732

Last change on this file since 732 was 727, checked in by mhnguyen, 9 years ago

Add more attributes to generate_rectilinear_domain

+) Longitude and latitude of an auto-generated domain can be specified by its boundaries whose values are determined by range

Test
+) On Curie
+) test_remap passes

File size: 7.2 KB
Line 
1#include "generate_rectilinear_domain.hpp"
2#include "type.hpp"
3
4namespace xios {
5
6  /// ////////////////////// Définitions ////////////////////// ///
7
8  CGenerateRectilinearDomain::CGenerateRectilinearDomain(void)
9    : CObjectTemplate<CGenerateRectilinearDomain>(), CGenerateRectilinearDomainAttributes(), CTransformation<CDomain>()
10  { /* Ne rien faire de plus */ }
11
12  CGenerateRectilinearDomain::CGenerateRectilinearDomain(const StdString & id)
13    : CObjectTemplate<CGenerateRectilinearDomain>(id), CGenerateRectilinearDomainAttributes(), CTransformation<CDomain>()
14  { /* Ne rien faire de plus */ }
15
16  CGenerateRectilinearDomain::~CGenerateRectilinearDomain(void)
17  {}
18
19  //----------------------------------------------------------------
20
21  StdString CGenerateRectilinearDomain::GetName(void)    { return StdString("generate_rectilinear_domain"); }
22  StdString CGenerateRectilinearDomain::GetDefName(void) { return StdString("generate_rectilinear_domain"); }
23  ENodeType CGenerateRectilinearDomain::GetType(void)    { return eGenerateRectilinearDomain; }
24
25  void CGenerateRectilinearDomain::checkValid(CDomain* domainDst)
26  {
27    const double defaultBndsLonStart = 0;
28    const double defaultBndsLonEnd = 360;
29
30    const double defaultBndsLatStart = -90;
31    const double defaultBndsLatEnd = 90;
32
33    if ((!lon_start.isEmpty() && lon_end.isEmpty()) ||
34        (lon_start.isEmpty() && !lon_end.isEmpty()))
35         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
36               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
37               << "Only longitude start or longitude end attribute is defined." << std::endl
38               << "Must define both: 'lon_start' and 'lon_end'.");
39
40    if ((!lat_start.isEmpty() && lat_end.isEmpty()) ||
41        (lat_start.isEmpty() && !lat_end.isEmpty()))
42         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
43               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
44               << "Only latitude start or latitude end attribute is defined." << std::endl
45               << "Must define both: 'lat_start' and 'lat_end'.");
46
47    if ((!bounds_lon_start.isEmpty() && bounds_lon_end.isEmpty()) ||
48        (bounds_lon_start.isEmpty() && !bounds_lon_end.isEmpty()))
49         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
50               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
51               << "Only longitude boundary start or longitude boundary end attribute is defined." << std::endl
52               << "Must define both: 'bounds_lon_start' and 'bounds_lon_end'.");
53
54    if ((!bounds_lat_start.isEmpty() && bounds_lat_end.isEmpty()) ||
55        (bounds_lat_start.isEmpty() && !bounds_lat_end.isEmpty()))
56         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
57               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
58               << "Only latitude boundary start or latitude boundary end attribute is defined." << std::endl
59               << "Must define both: 'bounds_lat_start' and 'bounds_lat_end'.");
60
61    if (!bounds_lon_start.isEmpty() && !lon_start.isEmpty())
62         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
63               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
64               << "Only one longitude boundary attribute or longitude can be used but both 'bounds_lon_start' and 'lon_start' are defined." << std::endl
65               << "Define only one attribute: 'bounds_lon_start' or 'lon_start'.");
66
67    if (!bounds_lat_start.isEmpty() && !lat_start.isEmpty())
68         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
69               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
70               << "Only one latitude boundary attribute or latitude can be used but both 'bounds_lat_start' and 'lat_start' are defined." << std::endl
71               << "Define only one attribute: 'bounds_lat_start' or 'lat_start'.");
72
73    if (!bounds_lon_start.isEmpty() && !lat_start.isEmpty())
74         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
75               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
76               << "Only one latitude boundary attribute or latitude can be used but both 'bounds_lon_start' and 'lat_start' are defined." << std::endl
77               << "Define only one pair of attributes: ('bounds_lon_start' and 'bounds_lat_start') or ('lon_start' and 'lat_start').");
78
79    if (!bounds_lat_start.isEmpty() && !lon_start.isEmpty())
80         ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)",
81               << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] "
82               << "Only one latitude boundary attribute or latitude can be used but both 'bounds_lat_start' and 'lon_start' are defined." << std::endl
83               << "Define only one pair of attributes: ('bounds_lon_start' and 'bounds_lat_start') or ('lon_start' and 'lat_start').");
84
85    if (bounds_lon_start.isEmpty() && bounds_lat_start.isEmpty() &&
86        lon_start.isEmpty() && lat_start.isEmpty())
87    {
88      bounds_lon_start.setValue(defaultBndsLonStart);
89      bounds_lon_end.setValue(defaultBndsLonEnd);
90      bounds_lat_start.setValue(defaultBndsLatStart);
91      bounds_lat_end.setValue(defaultBndsLatEnd);
92    }
93
94    if (!bounds_lon_start.isEmpty())
95    {
96      int niGlo = domainDst->ni_glo.getValue();
97
98      double boundsLonRange = bounds_lon_end - bounds_lon_start;
99      double boundsLonStep = boundsLonRange/double(niGlo);
100      domainDst->bounds_lon_start = bounds_lon_start;
101      domainDst->bounds_lon_end   = bounds_lon_end;
102      domainDst->lon_start = bounds_lon_start + boundsLonStep/2;
103      domainDst->lon_end   = bounds_lon_end   - boundsLonStep/2;
104    }
105
106    if (!bounds_lat_start.isEmpty())
107    {
108      int njGlo = domainDst->nj_glo.getValue();
109
110      double boundsLatRange = bounds_lat_end - bounds_lat_start;
111      double boundsLatStep = boundsLatRange/double(njGlo);
112      domainDst->bounds_lat_start = bounds_lat_start;
113      domainDst->bounds_lat_end   = bounds_lat_end;
114      domainDst->lat_start = bounds_lat_start + boundsLatStep/2;
115      domainDst->lat_end   = bounds_lat_end   - boundsLatStep/2;
116    }
117
118    if (lon_start.isEmpty() && lat_start.isEmpty()) return;
119
120    if (!lon_start.isEmpty())
121    {
122      int niGlo = domainDst->ni_glo.getValue();
123
124      double lonRange = lon_end - lon_start;
125      double lonStep = lonRange/double(niGlo);
126      domainDst->lon_start = lon_start;
127      domainDst->lon_end   = lon_end;
128      domainDst->bounds_lon_start = lon_start - lonStep/2;
129      domainDst->bounds_lon_end   = lon_end   + lonStep/2;
130    }
131
132    if (!lat_start.isEmpty())
133    {
134      int njGlo = domainDst->nj_glo.getValue();
135
136      double latRange = lat_end - lat_start;
137      double latStep = latRange/double(njGlo);
138      domainDst->lat_start = lat_start;
139      domainDst->lat_end   = lat_end;
140      domainDst->bounds_lat_start = lat_start - latStep/2;
141      domainDst->bounds_lat_end   = lat_end   + latStep/2;
142    }
143  }
144
145}
Note: See TracBrowser for help on using the repository browser.