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

Last change on this file since 1485 was 1485, checked in by oabramkina, 6 years ago

Enforcing sequential I/O on the client side during reading of metadata by client processes. Parallel I/O can still be used in this case via setting file attribute "read_metadata_par" to true.

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