source: XIOS/dev/dev_ym/XIOS_COUPLING/src/io/nc4_data_input.cpp @ 1853

Last change on this file since 1853 was 1853, checked in by ymipsl, 4 years ago

Coupling branch : replace hasServer and hasClient combination by the name of correct service : CLIENT, GATHERER or OUT_SERVER.

YM

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