source: XIOS/dev/XIOS_DEV_CMIP6/src/io/nc4_data_input.cpp @ 1410

Last change on this file since 1410 was 1410, checked in by oabramkina, 5 years ago

Improving protocol for reading : grid attributes such longitude, latitude, etc are read by clients locally.
It concerns only curvilinear and unstructured domains. Local attributes such as ni/nj, ibegin/jbegin are mandatory as before.

  • 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: 25.7 KB
Line 
1#include "nc4_data_input.hpp"
2
3#include "context.hpp"
4#include "context_server.hpp"
5#include "context_client.hpp"
6#include "domain.hpp"
7#include "axis.hpp"
8#include "scalar.hpp"
9
10namespace xios
11{
12  CNc4DataInput::CNc4DataInput(const StdString& filename, MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/, const StdString& timeCounterName /*= "time_counter"*/)
13    : SuperClass()
14    , SuperClassWriter(filename, &comm_file, multifile, timeCounterName)
15    , comm_file(comm_file)
16    , filename(filename)
17    , isCollective(isCollective)
18    , readMetaDataDomains_(), readValueDomains_()
19    , readMetaDataAxis_(), readValueAxis_()
20    , readMetaDataScalar_(), readValueScalar_()
21  {
22    SuperClass::type = multifile ? MULTI_FILE : ONE_FILE;
23  }
24
25  CNc4DataInput::~CNc4DataInput(void)
26  { /* Nothing more to do */ }
27
28  StdSize CNc4DataInput::getFieldNbRecords_(CField* field)
29  {
30    StdString fieldId = field->getFieldOutputName();
31
32    if (SuperClassWriter::isTemporal(fieldId))
33    {
34//      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()];
35      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()];
36    }
37
38    return 1;
39  }
40
41  void CNc4DataInput::readFieldData_(CField* field)
42  {
43    CContext* context = CContext::getCurrent();
44    CContextServer* server = context->server;
45
46    CGrid* grid = field->grid;
47
48    if (!grid->doGridHaveDataToWrite())
49      if (SuperClass::type==MULTI_FILE || !isCollective) return;
50
51    StdString fieldId = field->getFieldOutputName();
52
53    CArray<double,1> fieldData(grid->getWrittenDataSize());
54    if (!field->default_value.isEmpty()) fieldData = field->default_value;
55
56    switch (SuperClass::type)
57    {
58      case MULTI_FILE:
59        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax );
60        break;
61      case ONE_FILE:
62      {
63/*
64        std::vector<int> nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
65        std::vector<int> nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
66        std::vector<int> nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
67
68        int ssize = nZoomBeginGlobal.size();
69
70        std::vector<StdSize> start(ssize);
71        std::vector<StdSize> count(ssize);
72
73        for (int i = 0; i < ssize; ++i)
74        {
75          start[i] = nZoomBeginServer[ssize - i - 1] - nZoomBeginGlobal[ssize - i - 1];
76          count[i] = nZoomSizeServer[ssize - i - 1];
77        }
78*/
79
80        std::vector<int> nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
81        std::vector<int> nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
82        std::vector<int> nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
83
84        std::vector<StdSize> start, count;
85
86        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
87        std::vector<StdString> domainList = grid->getDomainList();
88        std::vector<StdString> axisList   = grid->getAxisList();
89        int numElement = axisDomainOrder.numElements();
90        int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
91        int idx = nZoomBeginGlobal.size() - 1;
92
93        start.reserve(nZoomBeginGlobal.size());
94        count.reserve(nZoomBeginGlobal.size());
95
96        for (int i = numElement - 1; i >= 0; --i)
97        {
98          if (2 == axisDomainOrder(i))
99          {
100            CDomain* domain = CDomain::get(domainList[idxDomain]);
101            if ((domain->type) != CDomain::type_attr::unstructured)
102            {
103              start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
104              count.push_back(nZoomSizeServer[idx]);
105            }
106            --idx ;
107            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
108            count.push_back(nZoomSizeServer[idx]);
109            --idx ;
110            --idxDomain;
111          }
112          else if (1 == axisDomainOrder(i))
113          {
114            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
115            count.push_back(nZoomSizeServer[idx]);
116            --idx;
117          }
118          else
119          {
120            if (1 == axisDomainOrder.numElements())
121            {
122              start.push_back(0);
123              count.push_back(1);
124            }
125            --idx;
126          }
127        }
128
129        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax, &start, &count);
130        break;
131      }
132    }
133
134    field->inputField(fieldData);
135
136    if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
137    {
138      double scaleFactor = 1.0, addOffset = 0.0;
139      if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor;
140      if (!field->add_offset.isEmpty()) addOffset = field->add_offset;
141      field->invertScaleFactorAddOffset(scaleFactor, addOffset);
142    }
143  }
144
145  void CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)
146  {
147    StdString fieldId = field->getFieldOutputName();
148
149    CGrid* grid = field->grid;
150
151    std::vector<CDomain*> domainP = grid->getDomains();
152    std::vector<CAxis*> axisP = grid->getAxis();
153    std::vector<CScalar*> scalarP = grid->getScalars();
154    int gridDim = domainP.size() * 2 + axisP.size();
155
156    // Nothing to do with scalar without timestep
157    if ((0 == gridDim) && (!SuperClassWriter::isTemporal(fieldId))) 
158      return;
159
160    // Verify the compatibility of dimension of declared grid and real grid in file
161    int realGridDim = 1;
162    bool isUnstructuredGrid = SuperClassWriter::isUnstructured(fieldId);
163    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId);
164    std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId);
165
166    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size();
167    if (isUnstructuredGrid) ++realGridDim;
168
169    if (gridDim != realGridDim)
170       ERROR("CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)",
171        << "Field '" << fieldId << "' has incorrect dimension " << std::endl
172        << "Verify dimension of grid defined by 'grid_ref' or 'domain_ref'/'axis_ref' and dimension of grid in read file.");
173
174    // Remove unlimited dimension from the map, we dont need it anymore
175    if (SuperClassWriter::isTemporal(fieldId))
176    {
177      dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName());
178      dimList.pop_front() ;  // assume time dimension is first
179    }
180
181    std::list<std::pair<StdString, StdSize> > listDimSize;
182/*
183    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap)
184      listDimSize.push_front(*itMap);
185*/
186    for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
187      listDimSize.push_front(*dimSizeMap.find(*it));
188
189    // Now process domain and axis
190    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
191    int numElement = domainP.size() + axisP.size() + scalarP.size();
192    int elementPosition = 0;
193    int idxDomain = 0, idxAxis = 0, idxScalar = 0;
194
195    std::pair<std::set<StdString>::iterator,bool> it;
196    for (int i = 0; i < numElement; ++i)
197    {
198      if(2 == axisDomainOrder(i))
199      {
200        if (readAttributeValues)
201        {
202           it = readValueDomains_.insert(domainP[idxDomain]->getId());
203           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
204        }
205        else
206        {
207          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId());
208          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
209        }
210        ++idxDomain;
211        if (isUnstructuredGrid) ++elementPosition;
212        else elementPosition += 2;
213      }
214      else if (1 == axisDomainOrder(i))
215      {
216        if (readAttributeValues)
217        {
218          it = readValueAxis_.insert(axisP[idxAxis]->getId());
219          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
220        }
221        else
222        {
223          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId());
224          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
225        }
226        ++idxAxis;
227        ++elementPosition;
228      }
229      else
230      {
231        if (readAttributeValues)
232        {
233          it = readValueScalar_.insert(scalarP[idxScalar]->getId());
234          if (it.second) readScalarAttributeValueFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
235        }
236        else
237        {
238          it = readMetaDataScalar_.insert(scalarP[idxScalar]->getId());
239          if (it.second) readScalarAttributesFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
240        }
241        ++idxScalar;
242        ++elementPosition;
243      }
244    }
245  }
246
247  /*!
248    Read attributes of a domain from a file
249    \param [in] domain domain whose attributes are read from the file
250    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
251    \param [in] emelentPosition position of domain in grid
252    \param [in] fieldId id (or name) associated with the grid
253  */
254  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
255                                                       int elementPosition, const StdString& fieldId)
256  {
257    // There are some optional attributes of a domain to retrieve from file    // + lon lat?
258    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
259                                                              iteMap  = dimSizeMap.end();
260
261    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
262    itMapNj = itMapNi; ++itMapNj;
263
264    if ((CDomain::type_attr::rectilinear == domain->type))
265    {
266      // Ok, try to read some attributes such as longitude and latitude
267      bool hasLat = SuperClassWriter::hasVariable(itMapNj->first);
268      if (hasLat)
269      {
270        domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second);
271        std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second);
272        readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true);
273      }
274
275      bool hasLon = SuperClassWriter::hasVariable(itMapNi->first);
276      if (hasLon)
277      {
278        domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second);
279        std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second);
280        readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true);
281      }     
282    }
283    else if ((CDomain::type_attr::curvilinear == domain->type))
284    {
285      int ni, nj;
286      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
287
288      if (domain->ni.isEmpty())
289      {
290        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
291          << " Value of attribute ni should be defined for domain " << domain->getDomainOutputName()
292          << " in file " << this->filename << "."
293          << " The value can be provided by a user or generated automatically by XIOS."
294          << " Functionality generate_rectilinear_domain can also be used for curvilinear domains."
295          << std::endl);
296      }
297
298      if (domain->nj.isEmpty())
299      {
300        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
301          << " Value of attribute nj should be defined for domain " << domain->getDomainOutputName()
302          << " in file " << this->filename << "."
303          << " The value can be provided by a user or generated automatically by XIOS."
304          << " Functionality generate_rectilinear_domain can also be used for curvilinear domains."
305          << std::endl);
306      }
307
308      if (domain->ibegin.isEmpty())
309      {
310        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
311          << " Value of attribute ibegin should be defined for domain " << domain->getDomainOutputName()
312          << " in file " << this->filename << "."
313          << " The value can be provided by a user or generated automatically by XIOS."
314          << " Functionality generate_rectilinear_domain can also be used for curvilinear domains."
315          << std::endl);
316      }
317
318      if (domain->jbegin.isEmpty())
319      {
320        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
321          << " Value of attribute jbegin should be defined for domain " << domain->getDomainOutputName()
322          << " in file " << this->filename << "."
323          << " The value can be provided by a user or generated automatically by XIOS."
324          << " Functionality generate_rectilinear_domain can also be used for curvilinear domains."
325          << std::endl);
326      }
327
328      ni = domain->ni;
329      nj = domain->nj;
330      nBeginLatLon[0] = domain->jbegin; nBeginLatLon[1] = domain->ibegin;
331      nSizeLatLon[0]  = nj; nSizeLatLon[1] = ni;
332//      ni = domain->ni_glo;
333//      nj = domain->nj_glo;
334//      nBeginLatLon[0] = 0; nBeginLatLon[1] = 0;
335//      nSizeLatLon[0]  = domain->nj_glo.getValue(); nSizeLatLon[1] = domain->ni_glo.getValue();
336
337      StdString latName = this->getLatCoordName(fieldId);
338      if (SuperClassWriter::hasVariable(latName))
339      {
340        domain->latvalue_curvilinear_read_from_file.resize(ni,nj);
341        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
342      }
343      StdString lonName = this->getLonCoordName(fieldId);
344      if (SuperClassWriter::hasVariable(lonName))
345      {
346        domain->lonvalue_curvilinear_read_from_file.resize(ni,nj);
347        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
348      }
349
350      StdString boundsLatName = this->getBoundsId(latName);
351      StdString boundsLonName = this->getBoundsId(lonName);
352
353      int nbVertex = this->getNbVertex(fieldId);
354      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
355      {
356        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
357          << "The domain " << domain->getDomainOutputName()
358          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
359          << " are not coherent. They should be the same." << std::endl
360          << " nvertex read from file: "<< nbVertex
361          << " nvertex from model: "<< domain->nvertex << std::endl);
362      } 
363
364      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
365        domain->nvertex.setValue(nbVertex);
366
367      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
368      nBeginBndsLatLon[0] = domain->jbegin; nSizeBndsLatLon[0] = domain->nj.getValue();
369      nBeginBndsLatLon[1] = domain->ibegin; nSizeBndsLatLon[1] = domain->ni.getValue();
370      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
371//      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->nj_glo.getValue();
372//      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = domain->ni_glo.getValue();
373//      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
374
375      if (SuperClassWriter::hasVariable(boundsLatName))
376      {
377        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex,ni,nj);
378        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
379
380      }
381      if (SuperClassWriter::hasVariable(boundsLonName)) 
382      {
383        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex,ni,nj);
384        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
385      }     
386    }
387    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
388    {
389      if (domain->ni.isEmpty())
390      {
391        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
392          << " Value of attribute ni should be defined for domain " << domain->getDomainOutputName()
393          << " in file " << this->filename << "."
394          << std::endl);
395      }
396
397      if (domain->ibegin.isEmpty())
398      {
399        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
400          << " Value of attribute ibegin should be defined for domain " << domain->getDomainOutputName()
401          << " in file " << this->filename << "."
402          << std::endl);
403      }
404
405      int ni;
406      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
407
408      ni = domain->ni;
409      nBeginLatLon[0] = domain->ibegin;
410//      ni = domain->ni_glo;
411//      nBeginLatLon[0] = 0;
412      nSizeLatLon[0] = ni;
413
414      StdString latName = this->getLatCoordName(fieldId);
415      if (SuperClassWriter::hasVariable(latName))
416      {
417        domain->latvalue_unstructured_read_from_file.resize(ni);
418        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); 
419      }
420
421      StdString lonName = this->getLonCoordName(fieldId);
422      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
423      {
424        domain->lonvalue_unstructured_read_from_file.resize(ni);
425        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
426      }
427
428      StdString boundsLatName = this->getBoundsId(latName);
429      StdString boundsLonName = this->getBoundsId(lonName);
430
431      int nbVertex = this->getNbVertex(fieldId);
432      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
433      {
434        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
435          << "The domain " << domain->getDomainOutputName()
436          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
437          << " are not coherent. They should be the same." << std::endl
438          << " nvertex read from file: "<< nbVertex
439          << " nvertex from model: "<< domain->nvertex << std::endl);
440      } 
441     
442      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
443        domain->nvertex.setValue(nbVertex);
444
445      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2);
446
447      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->ni.getValue();
448      nBeginBndsLatLon[1] = domain->ibegin.getValue(); nSizeBndsLatLon[1] = nbVertex;
449//      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->ni_glo.getValue();
450//      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
451
452        if (SuperClassWriter::hasVariable(boundsLatName))
453      {
454        domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
455        readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
456      }
457
458      if (SuperClassWriter::hasVariable(boundsLonName)) 
459      {
460        domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
461        readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
462      }     
463    }
464    domain->fillInLonLat();
465  }
466
467  /*!
468    Read attribute value of a domain from a file
469    \param [in] domain domain whose attributes are read from the file
470    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
471    \param [in] emelentPosition position of domain in grid
472    \param [in] fieldId id (or name) associated with the grid
473  */
474  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
475                                                   int elementPosition, const StdString& fieldId)
476  {
477    // There are some mandatory attributes of a domain to retrieve from file
478    // + ni_glo, nj_glo
479    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
480                                                              iteMap  = dimSizeMap.end();
481    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
482    itMapNj = itMapNi; ++itMapNj;
483
484    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
485    {
486      if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second))
487      {
488        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
489          << "The domain " << domain->getDomainOutputName()
490          << " has nj_glo read from file " << this->filename << " and nj_glo provided from model"
491          << " are not coherent. They should be the same." << std::endl
492          << " nj_glo read from file: "<< itMapNj->second
493          << " nj_glo from model: "<< domain->nj_glo << std::endl);
494      } 
495      domain->nj_glo.setValue(itMapNj->second);
496
497      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
498      {
499        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
500          << "The domain " << domain->getDomainOutputName()
501          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
502          << " are not coherent. They should be the same." << std::endl
503          << " ni_glo read from file: "<< itMapNi->second
504          << " ni_glo from model: "<< domain->ni_glo << std::endl);
505      } 
506      domain->ni_glo.setValue(itMapNi->second);
507    }
508    else if (this->isUnstructured(fieldId))
509    {
510      domain->nj_glo.setValue(1);
511
512      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
513      {
514        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
515          << "The domain " << domain->getDomainOutputName()
516          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
517          << " are not coherent. They should be the same." << std::endl
518          << " ni_glo read from file: "<< itMapNi->second
519          << " ni_glo from model: "<< domain->ni_glo << std::endl);
520      }       
521      domain->ni_glo.setValue(itMapNi->second);
522    }
523  }
524
525  /*!
526    Read attributes of an axis from a file
527    \param [in] axis axis whose attributes are read from the file
528    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
529    \param [in] emelentPosition position of axis in grid
530    \param [in] fieldId id (or name) associated with the grid
531  */
532  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
533                                                 int elementPosition, const StdString& fieldId)
534  {
535    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
536                                                              iteMap = dimSizeMap.end();
537    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
538
539    if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second))
540    {
541      ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)",
542        << "The axis " << axis->getAxisOutputName()
543        << " has n_glo read from file " << this->filename << " and n_glo provided from model"
544        << " are not coherent. They should be the same." << std::endl
545        << " n_glo read from file: "<< itMapN->second
546        << " n_glo from model: "<< axis->n_glo << std::endl);
547    }   
548    axis->n_glo.setValue(itMapN->second);
549  }
550
551  /*!
552    Read attribute value of an axis from a file
553    \param [in] axis axis whose attributes are read from the file
554    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
555    \param [in] emelentPosition position of axis in grid
556    \param [in] fieldId id (or name) associated with the grid
557  */
558  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
559                                                    int elementPosition, const StdString& fieldId)
560  {
561    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
562                                                              iteMap = dimSizeMap.end();
563    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
564
565    { // Read axis value
566      bool hasValue = SuperClassWriter::hasVariable(itMapN->first);
567      if (hasValue)
568      {
569        std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second);
570        CArray<double,1> readAxisValue(itMapN->second);
571        readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true);
572        int begin = 0, n = itMapN->second;
573        if (!axis->begin.isEmpty()) begin = axis->begin.getValue();
574        if (!axis->n.isEmpty()) n = axis->n.getValue();
575        axis->value.resize(n);
576        for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i);
577      }
578    }
579  }
580
581  /*!
582    Read attributes of a scalar from a file
583    \param [in] scalar scalar whose attributes are read from the file
584    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
585    \param [in] emelentPosition position of scalar in grid
586    \param [in] fieldId id (or name) associated with the grid
587  */
588  void CNc4DataInput::readScalarAttributesFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
589                                                  int elementPosition, const StdString& fieldId)
590  {
591    /*Nothing to do */
592  }
593
594  /*!
595    Read attribute value of an axis from a file
596    \param [in] axis axis whose attributes are read from the file
597    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
598    \param [in] emelentPosition position of axis in grid
599    \param [in] fieldId id (or name) associated with the grid
600  */
601  void CNc4DataInput::readScalarAttributeValueFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
602                                                      int elementPosition, const StdString& fieldId)
603  {
604    /*Nothing to do */
605  }
606
607  void CNc4DataInput::closeFile_(void)
608  {
609    SuperClassWriter::close();
610  }
611} // namespace xios
Note: See TracBrowser for help on using the repository browser.