source: XIOS/dev/dev_trunk_omp/src/io/nc4_data_input.cpp @ 1691

Last change on this file since 1691 was 1646, checked in by yushan, 5 years ago

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

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