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

Last change on this file since 1482 was 1482, checked in by yushan, 3 years ago

Branch EP merged with Dev_cmip6 @r1481

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