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

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

Reverting changes made in r1310 for local domain read of curvilinear and unstructured domains.
A possible bug in cases when the number of grid points is smaller than the number of clients. To be corrected.

  • 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: 22.7 KB
RevLine 
[219]1#include "nc4_data_input.hpp"
2
[599]3#include "context.hpp"
4#include "context_server.hpp"
[775]5#include "context_client.hpp"
6#include "domain.hpp"
7#include "axis.hpp"
[967]8#include "scalar.hpp"
[599]9
[335]10namespace xios
[219]11{
[802]12  CNc4DataInput::CNc4DataInput(const StdString& filename, MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/, const StdString& timeCounterName /*= "time_counter"*/)
[599]13    : SuperClass()
[802]14    , SuperClassWriter(filename, &comm_file, multifile, timeCounterName)
[599]15    , comm_file(comm_file)
16    , filename(filename)
17    , isCollective(isCollective)
[775]18    , readMetaDataDomains_(), readValueDomains_()
19    , readMetaDataAxis_(), readValueAxis_()
[967]20    , readMetaDataScalar_(), readValueScalar_()
[599]21  {
22    SuperClass::type = multifile ? MULTI_FILE : ONE_FILE;
23  }
[219]24
[599]25  CNc4DataInput::~CNc4DataInput(void)
26  { /* Nothing more to do */ }
[219]27
[599]28  StdSize CNc4DataInput::getFieldNbRecords_(CField* field)
29  {
[770]30    StdString fieldId = field->getFieldOutputName();
[599]31
32    if (SuperClassWriter::isTemporal(fieldId))
33    {
[811]34//      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()];
35      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()];
[599]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
[770]51    StdString fieldId = field->getFieldOutputName();
[599]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:
[850]59        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax );
[599]60        break;
61      case ONE_FILE:
62      {
[765]63/*
[599]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        }
[765]78*/
[599]79
[765]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
[887]86        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[765]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        {
[887]98          if (2 == axisDomainOrder(i))
[765]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          }
[887]112          else if (1 == axisDomainOrder(i))
[765]113          {
114            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
115            count.push_back(nZoomSizeServer[idx]);
116            --idx;
[967]117          }
118          else
119          {
120            if (1 == axisDomainOrder.numElements())
121            {
122              start.push_back(0);
123              count.push_back(1);
124            }
125            --idx;
126          }
[765]127        }
[777]128
[850]129        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax, &start, &count);
[599]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
[775]145  void CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)
146  {
[777]147    StdString fieldId = field->getFieldOutputName();
[775]148
149    CGrid* grid = field->grid;
150
151    std::vector<CDomain*> domainP = grid->getDomains();
152    std::vector<CAxis*> axisP = grid->getAxis();
[967]153    std::vector<CScalar*> scalarP = grid->getScalars();
[775]154    int gridDim = domainP.size() * 2 + axisP.size();
155
[967]156    // Nothing to do with scalar without timestep
157    if ((0 == gridDim) && (!SuperClassWriter::isTemporal(fieldId))) 
158      return;
159
[775]160    // Verify the compatibility of dimension of declared grid and real grid in file
161    int realGridDim = 1;
[783]162    bool isUnstructuredGrid = SuperClassWriter::isUnstructured(fieldId);
[775]163    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId);
[807]164    std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId);
[825]165
[775]166    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size();
[783]167    if (isUnstructuredGrid) ++realGridDim;
[775]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
[825]175    if (SuperClassWriter::isTemporal(fieldId))
[807]176    {
177      dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName());
178      dimList.pop_front() ;  // assume time dimension is first
179    }
[825]180
[783]181    std::list<std::pair<StdString, StdSize> > listDimSize;
[807]182/*
[783]183    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap)
184      listDimSize.push_front(*itMap);
[807]185*/
186    for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
187      listDimSize.push_front(*dimSizeMap.find(*it));
[775]188
189    // Now process domain and axis
[887]190    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[967]191    int numElement = domainP.size() + axisP.size() + scalarP.size();
[775]192    int elementPosition = 0;
[967]193    int idxDomain = 0, idxAxis = 0, idxScalar = 0;
[775]194
195    std::pair<std::set<StdString>::iterator,bool> it;
196    for (int i = 0; i < numElement; ++i)
197    {
[887]198      if(2 == axisDomainOrder(i))
[775]199      {
200        if (readAttributeValues)
201        {
202           it = readValueDomains_.insert(domainP[idxDomain]->getId());
[783]203           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
[775]204        }
205        else
206        {
207          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId());
[783]208          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
[775]209        }
210        ++idxDomain;
[783]211        if (isUnstructuredGrid) ++elementPosition;
212        else elementPosition += 2;
[775]213      }
[887]214      else if (1 == axisDomainOrder(i))
[775]215      {
216        if (readAttributeValues)
217        {
218          it = readValueAxis_.insert(axisP[idxAxis]->getId());
[783]219          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
[775]220        }
221        else
222        {
223          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId());
[783]224          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
[775]225        }
226        ++idxAxis;
227        ++elementPosition;
228      }
[967]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      }
[775]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
[782]252    \param [in] fieldId id (or name) associated with the grid
[775]253  */
[783]254  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]255                                                       int elementPosition, const StdString& fieldId)
256  {
257    // There are some optional attributes of a domain to retrieve from file    // + lon lat?
[783]258    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
259                                                              iteMap  = dimSizeMap.end();
[775]260
[783]261    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
262    itMapNj = itMapNi; ++itMapNj;
[775]263
[1158]264    if ((CDomain::type_attr::rectilinear == domain->type))
[775]265    {
[1413]266      // Ok, try to read some f.. attributes such as longitude and latitude
[825]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      }
[775]274
[825]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);
[1158]281      }     
[775]282    }
[1158]283    else if ((CDomain::type_attr::curvilinear == domain->type))
[783]284    {
[1413]285      int ni = domain->ni;
286      int nj = domain->nj;
[785]287      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
[1413]288      nBeginLatLon[0] = 0; nBeginLatLon[1] = 0;
289      nSizeLatLon[0]  = domain->nj_glo.getValue(); nSizeLatLon[1] = domain->ni_glo.getValue();
[783]290
291      StdString latName = this->getLatCoordName(fieldId);
[1158]292      if (SuperClassWriter::hasVariable(latName))
[825]293      {
[1413]294        domain->latvalue_curvilinear_read_from_file.resize(domain->ni_glo,domain->nj_glo);
[1158]295        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
[825]296      }
[783]297      StdString lonName = this->getLonCoordName(fieldId);
[1158]298      if (SuperClassWriter::hasVariable(lonName))
[825]299      {
[1413]300        domain->lonvalue_curvilinear_read_from_file.resize(domain->ni_glo,domain->nj_glo);
[1158]301        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
[825]302      }
[783]303
304      StdString boundsLatName = this->getBoundsId(latName);
305      StdString boundsLonName = this->getBoundsId(lonName);
306
307      int nbVertex = this->getNbVertex(fieldId);
[1158]308      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
309      {
310        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
311          << "The domain " << domain->getDomainOutputName()
312          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
313          << " are not coherent. They should be the same." << std::endl
314          << " nvertex read from file: "<< nbVertex
315          << " nvertex from model: "<< domain->nvertex << std::endl);
316      } 
317
318      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
[825]319        domain->nvertex.setValue(nbVertex);
[1201]320
[785]321      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
[1413]322      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->nj_glo.getValue();
323      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = domain->ni_glo.getValue();
[785]324      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
[783]325
[1158]326      if (SuperClassWriter::hasVariable(boundsLatName))
[825]327      {
[1413]328        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex,domain->ni_glo,domain->nj_glo);
[1158]329        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
[825]330
331      }
[1158]332      if (SuperClassWriter::hasVariable(boundsLonName)) 
[825]333      {
[1413]334        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex,domain->ni_glo,domain->nj_glo);
[1158]335        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
336      }     
[783]337    }
[825]338    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
[775]339    {
[785]340      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
[1413]341      nSizeLatLon[0]  = domain->ni_glo.getValue();
342      CArray<double,1> globalLonLat(domain->ni_glo.getValue());
[785]343
[782]344      StdString latName = this->getLatCoordName(fieldId);
[1158]345      if (SuperClassWriter::hasVariable(latName))
[825]346      {
[1413]347        domain->latvalue_unstructured_read_from_file.resize(domain->ni_glo);
[1158]348        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); 
[825]349      }
[785]350
[782]351      StdString lonName = this->getLonCoordName(fieldId);
[825]352      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
353      {
[1413]354        // readFieldVariableValue(globalLonLat, lonName, nBeginLatLon, nSizeLatLon);
355        domain->lonvalue_unstructured_read_from_file.resize(domain->ni_glo);
[1158]356        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
[825]357      }
[782]358
359      StdString boundsLatName = this->getBoundsId(latName);
360      StdString boundsLonName = this->getBoundsId(lonName);
361
[783]362      int nbVertex = this->getNbVertex(fieldId);
[1158]363      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
364      {
365        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
366          << "The domain " << domain->getDomainOutputName()
367          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
368          << " are not coherent. They should be the same." << std::endl
369          << " nvertex read from file: "<< nbVertex
370          << " nvertex from model: "<< domain->nvertex << std::endl);
371      } 
372     
373      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
[825]374        domain->nvertex.setValue(nbVertex);
375
[785]376      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2);
[1413]377      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->ni_glo.getValue();
378      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
[782]379
[1413]380      if (SuperClassWriter::hasVariable(boundsLatName)) 
[825]381      {
[1158]382        domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
383        readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
[825]384      }
[785]385
[1158]386      if (SuperClassWriter::hasVariable(boundsLonName)) 
[825]387      {
[1158]388        domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
389        readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
390      }     
[775]391    }
[1158]392    domain->fillInLonLat();
[775]393  }
394
395  /*!
[782]396    Read attribute value of a domain from a file
[775]397    \param [in] domain domain whose attributes are read from the file
398    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
399    \param [in] emelentPosition position of domain in grid
[782]400    \param [in] fieldId id (or name) associated with the grid
[775]401  */
[783]402  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]403                                                   int elementPosition, const StdString& fieldId)
404  {
405    // There are some mandatory attributes of a domain to retrieve from file
406    // + ni_glo, nj_glo
[783]407    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
408                                                              iteMap  = dimSizeMap.end();
409    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
410    itMapNj = itMapNi; ++itMapNj;
[775]411
[782]412    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
[775]413    {
[1158]414      if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second))
415      {
416        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
417          << "The domain " << domain->getDomainOutputName()
418          << " has nj_glo read from file " << this->filename << " and nj_glo provided from model"
419          << " are not coherent. They should be the same." << std::endl
420          << " nj_glo read from file: "<< itMapNj->second
421          << " nj_glo from model: "<< domain->nj_glo << std::endl);
422      } 
[775]423      domain->nj_glo.setValue(itMapNj->second);
[1158]424
425      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
426      {
427        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
428          << "The domain " << domain->getDomainOutputName()
429          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
430          << " are not coherent. They should be the same." << std::endl
431          << " ni_glo read from file: "<< itMapNi->second
432          << " ni_glo from model: "<< domain->ni_glo << std::endl);
433      } 
[783]434      domain->ni_glo.setValue(itMapNi->second);
[775]435    }
436    else if (this->isUnstructured(fieldId))
437    {
[783]438      domain->nj_glo.setValue(1);
[1158]439
440      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
441      {
442        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
443          << "The domain " << domain->getDomainOutputName()
444          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
445          << " are not coherent. They should be the same." << std::endl
446          << " ni_glo read from file: "<< itMapNi->second
447          << " ni_glo from model: "<< domain->ni_glo << std::endl);
448      }       
[783]449      domain->ni_glo.setValue(itMapNi->second);
[775]450    }
451  }
452
453  /*!
454    Read attributes of an axis from a file
455    \param [in] axis axis whose attributes are read from the file
456    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
457    \param [in] emelentPosition position of axis in grid
[782]458    \param [in] fieldId id (or name) associated with the grid
[775]459  */
[783]460  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]461                                                 int elementPosition, const StdString& fieldId)
462  {
[783]463    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
464                                                              iteMap = dimSizeMap.end();
[775]465    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
[1158]466
467    if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second))
468    {
469      ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)",
470        << "The axis " << axis->getAxisOutputName()
471        << " has n_glo read from file " << this->filename << " and n_glo provided from model"
472        << " are not coherent. They should be the same." << std::endl
473        << " n_glo read from file: "<< itMapN->second
474        << " n_glo from model: "<< axis->n_glo << std::endl);
475    }   
[775]476    axis->n_glo.setValue(itMapN->second);
477  }
478
479  /*!
[782]480    Read attribute value of an axis from a file
[775]481    \param [in] axis axis whose attributes are read from the file
482    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
483    \param [in] emelentPosition position of axis in grid
[782]484    \param [in] fieldId id (or name) associated with the grid
[775]485  */
[783]486  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]487                                                    int elementPosition, const StdString& fieldId)
488  {
[783]489    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
490                                                              iteMap = dimSizeMap.end();
[775]491    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
492
493    { // Read axis value
[1310]494      bool hasValue = SuperClassWriter::hasVariable(itMapN->first);
495      if (hasValue)
496      {
497        std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second);
498        CArray<double,1> readAxisValue(itMapN->second);
499        readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true);
500        int begin = 0, n = itMapN->second;
501        if (!axis->begin.isEmpty()) begin = axis->begin.getValue();
502        if (!axis->n.isEmpty()) n = axis->n.getValue();
503        axis->value.resize(n);
504        for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i);
505      }
[775]506    }
507  }
508
[967]509  /*!
510    Read attributes of a scalar from a file
511    \param [in] scalar scalar whose attributes are read from the file
512    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
513    \param [in] emelentPosition position of scalar in grid
514    \param [in] fieldId id (or name) associated with the grid
515  */
516  void CNc4DataInput::readScalarAttributesFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
517                                                  int elementPosition, const StdString& fieldId)
518  {
[1158]519    /*Nothing to do */
[967]520  }
521
522  /*!
523    Read attribute value of an axis from a file
524    \param [in] axis axis whose attributes are read from the file
525    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
526    \param [in] emelentPosition position of axis in grid
527    \param [in] fieldId id (or name) associated with the grid
528  */
529  void CNc4DataInput::readScalarAttributeValueFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
530                                                      int elementPosition, const StdString& fieldId)
531  {
[1158]532    /*Nothing to do */
[967]533  }
534
[599]535  void CNc4DataInput::closeFile_(void)
536  {
537    SuperClassWriter::close();
538  }
[335]539} // namespace xios
Note: See TracBrowser for help on using the repository browser.