source: XIOS/dev/branch_openmp/src/io/nc4_data_input.cpp @ 1544

Last change on this file since 1544 was 1544, checked in by yushan, 6 years ago

bug fix for tests in prod mode

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