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

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

Big update on on going work related to data distribution and transfer between clients and servers.
Revisite of the source and store filter using "connectors".

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