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

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

dev_omp

  • 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{
[1328]12  CNc4DataInput::CNc4DataInput(const StdString& filename, ep_lib::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;
[1338]55    #ifdef _usingEP
56      SuperClass::type = ONE_FILE;
57      printf("SuperClass::type = %d\n", SuperClass::type);
58    #endif
59       
[599]60    switch (SuperClass::type)
61    {
62      case MULTI_FILE:
[850]63        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax );
[599]64        break;
65      case ONE_FILE:
66      {
[765]67/*
[599]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        }
[765]82*/
[599]83
[765]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
[887]90        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[765]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        {
[887]102          if (2 == axisDomainOrder(i))
[765]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          }
[887]116          else if (1 == axisDomainOrder(i))
[765]117          {
118            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
119            count.push_back(nZoomSizeServer[idx]);
120            --idx;
[967]121          }
122          else
123          {
124            if (1 == axisDomainOrder.numElements())
125            {
126              start.push_back(0);
127              count.push_back(1);
128            }
129            --idx;
130          }
[765]131        }
[777]132
[850]133        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax, &start, &count);
[599]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
[775]149  void CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)
150  {
[777]151    StdString fieldId = field->getFieldOutputName();
[775]152
153    CGrid* grid = field->grid;
154
155    std::vector<CDomain*> domainP = grid->getDomains();
156    std::vector<CAxis*> axisP = grid->getAxis();
[967]157    std::vector<CScalar*> scalarP = grid->getScalars();
[775]158    int gridDim = domainP.size() * 2 + axisP.size();
159
[967]160    // Nothing to do with scalar without timestep
161    if ((0 == gridDim) && (!SuperClassWriter::isTemporal(fieldId))) 
162      return;
163
[775]164    // Verify the compatibility of dimension of declared grid and real grid in file
165    int realGridDim = 1;
[783]166    bool isUnstructuredGrid = SuperClassWriter::isUnstructured(fieldId);
[775]167    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId);
[807]168    std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId);
[825]169
[775]170    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size();
[783]171    if (isUnstructuredGrid) ++realGridDim;
[775]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
[825]179    if (SuperClassWriter::isTemporal(fieldId))
[807]180    {
181      dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName());
182      dimList.pop_front() ;  // assume time dimension is first
183    }
[825]184
[783]185    std::list<std::pair<StdString, StdSize> > listDimSize;
[807]186/*
[783]187    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap)
188      listDimSize.push_front(*itMap);
[807]189*/
190    for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
191      listDimSize.push_front(*dimSizeMap.find(*it));
[775]192
193    // Now process domain and axis
[887]194    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[967]195    int numElement = domainP.size() + axisP.size() + scalarP.size();
[775]196    int elementPosition = 0;
[967]197    int idxDomain = 0, idxAxis = 0, idxScalar = 0;
[775]198
199    std::pair<std::set<StdString>::iterator,bool> it;
200    for (int i = 0; i < numElement; ++i)
201    {
[887]202      if(2 == axisDomainOrder(i))
[775]203      {
204        if (readAttributeValues)
205        {
206           it = readValueDomains_.insert(domainP[idxDomain]->getId());
[783]207           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
[775]208        }
209        else
210        {
211          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId());
[783]212          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
[775]213        }
214        ++idxDomain;
[783]215        if (isUnstructuredGrid) ++elementPosition;
216        else elementPosition += 2;
[775]217      }
[887]218      else if (1 == axisDomainOrder(i))
[775]219      {
220        if (readAttributeValues)
221        {
222          it = readValueAxis_.insert(axisP[idxAxis]->getId());
[783]223          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
[775]224        }
225        else
226        {
227          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId());
[783]228          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
[775]229        }
230        ++idxAxis;
231        ++elementPosition;
232      }
[967]233      else
234      {
235        if (readAttributeValues)
236        {
237          it = readValueScalar_.insert(scalarP[idxScalar]->getId());
238          if (it.second) readScalarAttributeValueFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
239        }
240        else
241        {
242          it = readMetaDataScalar_.insert(scalarP[idxScalar]->getId());
243          if (it.second) readScalarAttributesFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
244        }
245        ++idxScalar;
246        ++elementPosition;
247      }
[775]248    }
249  }
250
251  /*!
252    Read attributes of a domain from a file
253    \param [in] domain domain whose attributes are read from the file
254    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
255    \param [in] emelentPosition position of domain in grid
[782]256    \param [in] fieldId id (or name) associated with the grid
[775]257  */
[783]258  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]259                                                       int elementPosition, const StdString& fieldId)
260  {
261    // There are some optional attributes of a domain to retrieve from file    // + lon lat?
[783]262    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
263                                                              iteMap  = dimSizeMap.end();
[775]264
[783]265    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
266    itMapNj = itMapNi; ++itMapNj;
[775]267
[1064]268    if ((CDomain::type_attr::rectilinear == domain->type))
[775]269    {
270      // Ok, try to read some f.. attributes such as longitude and latitude
[825]271      bool hasLat = SuperClassWriter::hasVariable(itMapNj->first);
272      if (hasLat)
273      {
274        domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second);
275        std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second);
276        readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true);
277      }
[775]278
[825]279      bool hasLon = SuperClassWriter::hasVariable(itMapNi->first);
280      if (hasLon)
281      {
282        domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second);
283        std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second);
284        readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true);
[1064]285      }     
[775]286    }
[1064]287    else if ((CDomain::type_attr::curvilinear == domain->type))
[783]288    {
289      int ni = domain->ni;
[785]290      int nj = domain->nj;
291      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
[1064]292      nBeginLatLon[0] = 0; nBeginLatLon[1] = 0;
293      nSizeLatLon[0]  = domain->nj_glo.getValue(); nSizeLatLon[1] = domain->ni_glo.getValue();
[783]294
295      StdString latName = this->getLatCoordName(fieldId);
[1064]296      if (SuperClassWriter::hasVariable(latName))
[825]297      {
[1064]298        domain->latvalue_curvilinear_read_from_file.resize(domain->ni_glo,domain->nj_glo);
299        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
[825]300      }
[783]301      StdString lonName = this->getLonCoordName(fieldId);
[1064]302      if (SuperClassWriter::hasVariable(lonName))
[825]303      {
[1064]304        domain->lonvalue_curvilinear_read_from_file.resize(domain->ni_glo,domain->nj_glo);
305        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
[825]306      }
[783]307
308      StdString boundsLatName = this->getBoundsId(latName);
309      StdString boundsLonName = this->getBoundsId(lonName);
310
311      int nbVertex = this->getNbVertex(fieldId);
[1064]312      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
313      {
314        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
315          << "The domain " << domain->getDomainOutputName()
316          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
317          << " are not coherent. They should be the same." << std::endl
318          << " nvertex read from file: "<< nbVertex
319          << " nvertex from model: "<< domain->nvertex << std::endl);
320      } 
321
322      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
[825]323        domain->nvertex.setValue(nbVertex);
[1064]324
[785]325      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
[1064]326      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->nj_glo.getValue();
[1328]327      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = domain->ni_glo.getValue();
[785]328      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
[783]329
[1064]330      if (SuperClassWriter::hasVariable(boundsLatName))
[825]331      {
[1064]332        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex,domain->ni_glo,domain->nj_glo);
333        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
[825]334
335      }
[1064]336      if (SuperClassWriter::hasVariable(boundsLonName)) 
[825]337      {
[1064]338        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex,domain->ni_glo,domain->nj_glo);
339        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
340      }     
[783]341    }
[825]342    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
[775]343    {
[785]344      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
345      nSizeLatLon[0]  = domain->ni_glo.getValue();
346      CArray<double,1> globalLonLat(domain->ni_glo.getValue());
347
[782]348      StdString latName = this->getLatCoordName(fieldId);
[1064]349      if (SuperClassWriter::hasVariable(latName))
[825]350      {
[1064]351        domain->latvalue_unstructured_read_from_file.resize(domain->ni_glo);
352        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); 
[825]353      }
[785]354
[782]355      StdString lonName = this->getLonCoordName(fieldId);
[825]356      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
357      {
[1064]358        // readFieldVariableValue(globalLonLat, lonName, nBeginLatLon, nSizeLatLon);
359        domain->lonvalue_unstructured_read_from_file.resize(domain->ni_glo);
360        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
[825]361      }
[782]362
363      StdString boundsLatName = this->getBoundsId(latName);
364      StdString boundsLonName = this->getBoundsId(lonName);
365
[783]366      int nbVertex = this->getNbVertex(fieldId);
[1064]367      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
368      {
369        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
370          << "The domain " << domain->getDomainOutputName()
371          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
372          << " are not coherent. They should be the same." << std::endl
373          << " nvertex read from file: "<< nbVertex
374          << " nvertex from model: "<< domain->nvertex << std::endl);
375      } 
376     
377      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
[825]378        domain->nvertex.setValue(nbVertex);
379
[785]380      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2);
381      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->ni_glo.getValue();
382      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
[782]383
[1064]384      if (SuperClassWriter::hasVariable(boundsLatName)) 
[825]385      {
[1064]386        domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
387        readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
[825]388      }
[785]389
[1064]390      if (SuperClassWriter::hasVariable(boundsLonName)) 
[825]391      {
[1064]392        domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
393        readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
394      }     
[775]395    }
[1064]396    domain->fillInLonLat();
[775]397  }
398
399  /*!
[782]400    Read attribute value of a domain from a file
[775]401    \param [in] domain domain whose attributes are read from the file
402    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
403    \param [in] emelentPosition position of domain in grid
[782]404    \param [in] fieldId id (or name) associated with the grid
[775]405  */
[783]406  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]407                                                   int elementPosition, const StdString& fieldId)
408  {
409    // There are some mandatory attributes of a domain to retrieve from file
410    // + ni_glo, nj_glo
[783]411    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
412                                                              iteMap  = dimSizeMap.end();
413    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
414    itMapNj = itMapNi; ++itMapNj;
[775]415
[782]416    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
[775]417    {
[1064]418      if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second))
419      {
420        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
421          << "The domain " << domain->getDomainOutputName()
422          << " has nj_glo read from file " << this->filename << " and nj_glo provided from model"
423          << " are not coherent. They should be the same." << std::endl
424          << " nj_glo read from file: "<< itMapNj->second
425          << " nj_glo from model: "<< domain->nj_glo << std::endl);
426      } 
[775]427      domain->nj_glo.setValue(itMapNj->second);
[1064]428
429      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
430      {
431        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
432          << "The domain " << domain->getDomainOutputName()
433          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
434          << " are not coherent. They should be the same." << std::endl
435          << " ni_glo read from file: "<< itMapNi->second
436          << " ni_glo from model: "<< domain->ni_glo << std::endl);
437      } 
[783]438      domain->ni_glo.setValue(itMapNi->second);
[775]439    }
440    else if (this->isUnstructured(fieldId))
441    {
[783]442      domain->nj_glo.setValue(1);
[1064]443
444      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
445      {
446        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
447          << "The domain " << domain->getDomainOutputName()
448          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
449          << " are not coherent. They should be the same." << std::endl
450          << " ni_glo read from file: "<< itMapNi->second
451          << " ni_glo from model: "<< domain->ni_glo << std::endl);
452      }       
[783]453      domain->ni_glo.setValue(itMapNi->second);
[775]454    }
455  }
456
457  /*!
458    Read attributes of an axis from a file
459    \param [in] axis axis 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 axis in grid
[782]462    \param [in] fieldId id (or name) associated with the grid
[775]463  */
[783]464  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]465                                                 int elementPosition, const StdString& fieldId)
466  {
[783]467    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
468                                                              iteMap = dimSizeMap.end();
[775]469    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
[1064]470
471    if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second))
472    {
473      ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)",
474        << "The axis " << axis->getAxisOutputName()
475        << " has n_glo read from file " << this->filename << " and n_glo provided from model"
476        << " are not coherent. They should be the same." << std::endl
477        << " n_glo read from file: "<< itMapN->second
478        << " n_glo from model: "<< axis->n_glo << std::endl);
479    }   
[775]480    axis->n_glo.setValue(itMapN->second);
481  }
482
483  /*!
[782]484    Read attribute value of an axis from a file
[775]485    \param [in] axis axis whose attributes are read from the file
486    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
487    \param [in] emelentPosition position of axis in grid
[782]488    \param [in] fieldId id (or name) associated with the grid
[775]489  */
[783]490  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]491                                                    int elementPosition, const StdString& fieldId)
492  {
[783]493    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
494                                                              iteMap = dimSizeMap.end();
[775]495    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
496
497    { // Read axis value
498      std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second);
499      CArray<double,1> readAxisValue(itMapN->second);
500      readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true);
501      int begin = 0, n = itMapN->second;
502      if (!axis->begin.isEmpty()) begin = axis->begin.getValue();
503      if (!axis->n.isEmpty()) n = axis->n.getValue();
504      axis->value.resize(n);
505      for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i);
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  {
[1064]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  {
[1064]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.