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

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

Fixing a bug in reading of rectilinear domains introduced in r1430.

  • 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.0 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*/
[1434]186
187    if (!SuperClassWriter::isRectilinear(fieldId))
[1430]188    {
[1434]189      for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
[1430]190        listDimSize.push_front(*dimSizeMap.find(*it));
191    }
[1434]192    else
193    {
194       std::list<StdString> coords = SuperClassWriter::getCoordinatesIdList(fieldId);
195       std::list<StdString>::const_iterator itCoord = coords.begin();
196       for (; itCoord != coords.end(); itCoord++)
197       {
198         const StdString& coord = *itCoord;
199         if (SuperClassWriter::hasVariable(coord) && !SuperClassWriter::isTemporal(coord))
200         {
201           std::map<StdString, StdSize> dimsTmp = SuperClassWriter::getDimensions(&coord);
202           StdString dimNameTmp = dimsTmp.begin()->first;
203           StdSize dimSizeTmp = dimsTmp.begin()->second;
204           listDimSize.push_front(make_pair(coord, dimSizeTmp));
205           dimSizeMap.erase(dimNameTmp);
206           dimList.remove(dimNameTmp);
207         }
208       }
209       for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
210        listDimSize.push_front(*dimSizeMap.find(*it));
211    }
[1430]212
[775]213    // Now process domain and axis
[887]214    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[967]215    int numElement = domainP.size() + axisP.size() + scalarP.size();
[775]216    int elementPosition = 0;
[967]217    int idxDomain = 0, idxAxis = 0, idxScalar = 0;
[775]218
219    std::pair<std::set<StdString>::iterator,bool> it;
220    for (int i = 0; i < numElement; ++i)
221    {
[887]222      if(2 == axisDomainOrder(i))
[775]223      {
224        if (readAttributeValues)
225        {
226           it = readValueDomains_.insert(domainP[idxDomain]->getId());
[783]227           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
[775]228        }
229        else
230        {
231          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId());
[783]232          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
[775]233        }
234        ++idxDomain;
[783]235        if (isUnstructuredGrid) ++elementPosition;
236        else elementPosition += 2;
[775]237      }
[887]238      else if (1 == axisDomainOrder(i))
[775]239      {
240        if (readAttributeValues)
241        {
242          it = readValueAxis_.insert(axisP[idxAxis]->getId());
[783]243          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
[775]244        }
245        else
246        {
247          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId());
[783]248          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
[775]249        }
250        ++idxAxis;
251        ++elementPosition;
252      }
[967]253      else
254      {
255        if (readAttributeValues)
256        {
257          it = readValueScalar_.insert(scalarP[idxScalar]->getId());
258          if (it.second) readScalarAttributeValueFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
259        }
260        else
261        {
262          it = readMetaDataScalar_.insert(scalarP[idxScalar]->getId());
263          if (it.second) readScalarAttributesFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
264        }
265        ++idxScalar;
266        ++elementPosition;
267      }
[775]268    }
269  }
270
271  /*!
272    Read attributes of a domain from a file
273    \param [in] domain domain whose attributes are read from the file
274    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
275    \param [in] emelentPosition position of domain in grid
[782]276    \param [in] fieldId id (or name) associated with the grid
[775]277  */
[783]278  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]279                                                       int elementPosition, const StdString& fieldId)
280  {
281    // There are some optional attributes of a domain to retrieve from file    // + lon lat?
[783]282    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
283                                                              iteMap  = dimSizeMap.end();
[775]284
[783]285    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
286    itMapNj = itMapNi; ++itMapNj;
[775]287
[1158]288    if ((CDomain::type_attr::rectilinear == domain->type))
[775]289    {
[1419]290      // Ok, try to read some attributes such as longitude and latitude
[825]291      bool hasLat = SuperClassWriter::hasVariable(itMapNj->first);
292      if (hasLat)
293      {
294        domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second);
295        std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second);
296        readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true);
297      }
[775]298
[825]299      bool hasLon = SuperClassWriter::hasVariable(itMapNi->first);
300      if (hasLon)
301      {
302        domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second);
303        std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second);
304        readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true);
[1158]305      }     
[775]306    }
[1158]307    else if ((CDomain::type_attr::curvilinear == domain->type))
[783]308    {
[1428]309      // Make sure that if there is no local domain defined on a process, the process still reads just one value.
310      int ni, nj, ibegin, jbegin;
311      if (domain->ni == 0)
312      {
313        ni = 1;
314        ibegin = 0;
315      }
316      else
317      {
318        ni = domain->ni;
319        ibegin = domain->ibegin;
320      }
321      if (domain->nj == 0)
322      {
323        nj = 1;
324        jbegin = 0;
325      }
326      else
327      {
328        nj = domain->nj;
329        jbegin = domain->jbegin;
330      }
331
[785]332      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
[1428]333      nBeginLatLon[0] = jbegin; nBeginLatLon[1] = ibegin;
334      nSizeLatLon[0]  = nj; nSizeLatLon[1] = ni;
[783]335
336      StdString latName = this->getLatCoordName(fieldId);
[1158]337      if (SuperClassWriter::hasVariable(latName))
[825]338      {
[1428]339        domain->latvalue_curvilinear_read_from_file.resize(ni, nj);
[1158]340        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
[825]341      }
[783]342      StdString lonName = this->getLonCoordName(fieldId);
[1158]343      if (SuperClassWriter::hasVariable(lonName))
[825]344      {
[1428]345        domain->lonvalue_curvilinear_read_from_file.resize(ni, nj);
[1158]346        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
[825]347      }
[783]348
349      StdString boundsLatName = this->getBoundsId(latName);
350      StdString boundsLonName = this->getBoundsId(lonName);
351
352      int nbVertex = this->getNbVertex(fieldId);
[1158]353      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
354      {
355        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
356          << "The domain " << domain->getDomainOutputName()
357          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
358          << " are not coherent. They should be the same." << std::endl
359          << " nvertex read from file: "<< nbVertex
360          << " nvertex from model: "<< domain->nvertex << std::endl);
361      } 
362
363      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
[825]364        domain->nvertex.setValue(nbVertex);
[1201]365
[785]366      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
[1428]367      nBeginBndsLatLon[0] = jbegin; nSizeBndsLatLon[0] = nj;
368      nBeginBndsLatLon[1] = ibegin; nSizeBndsLatLon[1] = ni;
[785]369      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
[783]370
[1158]371      if (SuperClassWriter::hasVariable(boundsLatName))
[825]372      {
[1428]373        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj);
[1158]374        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
[825]375
376      }
[1158]377      if (SuperClassWriter::hasVariable(boundsLonName)) 
[825]378      {
[1428]379        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj);
[1158]380        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
381      }     
[783]382    }
[825]383    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
[775]384    {
[1428]385      // Make sure that if there is no local domain defined on a process, the process still reads just one value.
386      int ni, ibegin;
387      if (domain->ni == 0)
388      {
389        ni = 1;
390        ibegin = 0;
391      }
392      else
393      {
394        ni = domain->ni;
395        ibegin = domain->ibegin;
396      }
397
[785]398      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
[1428]399      nBeginLatLon[0] = ibegin;
400      nSizeLatLon[0]  = ni;
[785]401
[782]402      StdString latName = this->getLatCoordName(fieldId);
[1158]403      if (SuperClassWriter::hasVariable(latName))
[825]404      {
[1428]405        domain->latvalue_unstructured_read_from_file.resize(ni);
[1158]406        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); 
[825]407      }
[785]408
[782]409      StdString lonName = this->getLonCoordName(fieldId);
[825]410      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
411      {
[1428]412        domain->lonvalue_unstructured_read_from_file.resize(ni);
[1158]413        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
[825]414      }
[782]415
416      StdString boundsLatName = this->getBoundsId(latName);
417      StdString boundsLonName = this->getBoundsId(lonName);
418
[783]419      int nbVertex = this->getNbVertex(fieldId);
[1158]420      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
421      {
422        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
423          << "The domain " << domain->getDomainOutputName()
424          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
425          << " are not coherent. They should be the same." << std::endl
426          << " nvertex read from file: "<< nbVertex
427          << " nvertex from model: "<< domain->nvertex << std::endl);
428      } 
429     
430      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
[825]431        domain->nvertex.setValue(nbVertex);
432
[785]433      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2);
[1428]434      nBeginBndsLatLon[0] = ibegin; nSizeBndsLatLon[0] = ni;
[1413]435      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
[782]436
[1413]437      if (SuperClassWriter::hasVariable(boundsLatName)) 
[825]438      {
[1158]439        domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
440        readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
[825]441      }
[785]442
[1158]443      if (SuperClassWriter::hasVariable(boundsLonName)) 
[825]444      {
[1158]445        domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
446        readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
447      }     
[775]448    }
[1158]449    domain->fillInLonLat();
[775]450  }
451
452  /*!
[782]453    Read attribute value of a domain from a file
[775]454    \param [in] domain domain whose attributes are read from the file
455    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
456    \param [in] emelentPosition position of domain in grid
[782]457    \param [in] fieldId id (or name) associated with the grid
[775]458  */
[783]459  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]460                                                   int elementPosition, const StdString& fieldId)
461  {
462    // There are some mandatory attributes of a domain to retrieve from file
463    // + ni_glo, nj_glo
[783]464    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
465                                                              iteMap  = dimSizeMap.end();
466    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
467    itMapNj = itMapNi; ++itMapNj;
[775]468
[782]469    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
[775]470    {
[1158]471      if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second))
472      {
473        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
474          << "The domain " << domain->getDomainOutputName()
475          << " has nj_glo read from file " << this->filename << " and nj_glo provided from model"
476          << " are not coherent. They should be the same." << std::endl
477          << " nj_glo read from file: "<< itMapNj->second
478          << " nj_glo from model: "<< domain->nj_glo << std::endl);
479      } 
[775]480      domain->nj_glo.setValue(itMapNj->second);
[1158]481
482      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
483      {
484        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
485          << "The domain " << domain->getDomainOutputName()
486          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
487          << " are not coherent. They should be the same." << std::endl
488          << " ni_glo read from file: "<< itMapNi->second
489          << " ni_glo from model: "<< domain->ni_glo << std::endl);
490      } 
[783]491      domain->ni_glo.setValue(itMapNi->second);
[775]492    }
493    else if (this->isUnstructured(fieldId))
494    {
[783]495      domain->nj_glo.setValue(1);
[1158]496
497      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
498      {
499        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
500          << "The domain " << domain->getDomainOutputName()
501          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
502          << " are not coherent. They should be the same." << std::endl
503          << " ni_glo read from file: "<< itMapNi->second
504          << " ni_glo from model: "<< domain->ni_glo << std::endl);
505      }       
[783]506      domain->ni_glo.setValue(itMapNi->second);
[775]507    }
508  }
509
510  /*!
511    Read attributes of an axis from a file
512    \param [in] axis axis whose attributes are read from the file
513    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
514    \param [in] emelentPosition position of axis in grid
[782]515    \param [in] fieldId id (or name) associated with the grid
[775]516  */
[783]517  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]518                                                 int elementPosition, const StdString& fieldId)
519  {
[783]520    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
521                                                              iteMap = dimSizeMap.end();
[775]522    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
[1158]523
524    if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second))
525    {
526      ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)",
527        << "The axis " << axis->getAxisOutputName()
528        << " has n_glo read from file " << this->filename << " and n_glo provided from model"
529        << " are not coherent. They should be the same." << std::endl
530        << " n_glo read from file: "<< itMapN->second
531        << " n_glo from model: "<< axis->n_glo << std::endl);
532    }   
[775]533    axis->n_glo.setValue(itMapN->second);
534  }
535
536  /*!
[782]537    Read attribute value of an axis from a file
[775]538    \param [in] axis axis whose attributes are read from the file
539    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
540    \param [in] emelentPosition position of axis in grid
[782]541    \param [in] fieldId id (or name) associated with the grid
[775]542  */
[783]543  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
[775]544                                                    int elementPosition, const StdString& fieldId)
545  {
[783]546    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
547                                                              iteMap = dimSizeMap.end();
[775]548    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
549
550    { // Read axis value
[1310]551      bool hasValue = SuperClassWriter::hasVariable(itMapN->first);
552      if (hasValue)
553      {
554        std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second);
555        CArray<double,1> readAxisValue(itMapN->second);
556        readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true);
557        int begin = 0, n = itMapN->second;
558        if (!axis->begin.isEmpty()) begin = axis->begin.getValue();
559        if (!axis->n.isEmpty()) n = axis->n.getValue();
560        axis->value.resize(n);
561        for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i);
562      }
[775]563    }
564  }
565
[967]566  /*!
567    Read attributes of a scalar from a file
568    \param [in] scalar scalar whose attributes are read from the file
569    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
570    \param [in] emelentPosition position of scalar in grid
571    \param [in] fieldId id (or name) associated with the grid
572  */
573  void CNc4DataInput::readScalarAttributesFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
574                                                  int elementPosition, const StdString& fieldId)
575  {
[1158]576    /*Nothing to do */
[967]577  }
578
579  /*!
580    Read attribute value of an axis from a file
581    \param [in] axis axis whose attributes are read from the file
582    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
583    \param [in] emelentPosition position of axis in grid
584    \param [in] fieldId id (or name) associated with the grid
585  */
586  void CNc4DataInput::readScalarAttributeValueFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
587                                                      int elementPosition, const StdString& fieldId)
588  {
[1158]589    /*Nothing to do */
[967]590  }
591
[599]592  void CNc4DataInput::closeFile_(void)
593  {
594    SuperClassWriter::close();
595  }
[335]596} // namespace xios
Note: See TracBrowser for help on using the repository browser.