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

Last change on this file since 2010 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
Line 
1#include "nc4_data_input.hpp"
2
3#include "context.hpp"
4#include "context_server.hpp"
5#include "context_client.hpp"
6#include "domain.hpp"
7#include "axis.hpp"
8#include "scalar.hpp"
9
10namespace xios
11{
12  CNc4DataInput::CNc4DataInput(const StdString& filename, MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/,
13                               bool readMetaDataPar /*= false*/, bool ugridConvention /*= false*/, const StdString& timeCounterName /*= "time_counter"*/)
14    : SuperClass()
15    , SuperClassWriter(filename, &comm_file, multifile, readMetaDataPar, timeCounterName)
16    , comm_file(comm_file)
17    , filename(filename)
18    , isCollective(isCollective)
19    , ugridConvention(ugridConvention)
20    , readMetaDataDomains_(), readValueDomains_()
21    , readMetaDataAxis_(), readValueAxis_()
22    , readMetaDataScalar_(), readValueScalar_()
23  {
24    SuperClass::type = multifile ? MULTI_FILE : ONE_FILE;
25  }
26
27  CNc4DataInput::~CNc4DataInput(void)
28  { /* Nothing more to do */ }
29
30  StdSize CNc4DataInput::getFieldNbRecords_(CField* field)
31  TRY
32  {
33    StdString fieldId = field->getFieldOutputName();
34
35    if (SuperClassWriter::isTemporal(fieldId))
36    {
37//      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()];
38      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()];
39    }
40
41    return 1;
42  }
43  CATCH
44
45  void CNc4DataInput::readFieldData_(CField* field, int record, CArray<double,1>& dataOut)
46  TRY
47  {
48    CContext* context = CContext::getCurrent();
49
50    CGrid* grid = field->getGrid();
51
52    if (!grid->doGridHaveDataToWrite())  if (SuperClass::type==MULTI_FILE || !isCollective) return;
53
54    StdString fieldId = field->getFieldOutputName();
55
56    switch (SuperClass::type)
57    {
58      case MULTI_FILE:
59        SuperClassWriter::getData(dataOut, fieldId, isCollective, record );
60        break;
61      case ONE_FILE:
62      {
63        std::vector<StdSize> start, count;
64
65        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
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;
70        int idx = domainList.size() * 2 + axisList.size() - 1;
71
72        start.reserve(idx+1);
73        count.reserve(idx+1);
74
75        for (int i = numElement - 1; i >= 0; --i)
76        {
77          if (2 == axisDomainOrder(i))
78          {
79            CDomain* domain = CDomain::get(domainList[idxDomain]);
80            if ((domain->type) != CDomain::type_attr::unstructured)
81            {
82              start.push_back(domain->jbegin);
83              count.push_back(domain->nj);
84            }
85            start.push_back(domain->ibegin);
86            count.push_back(domain->ni);
87            --idxDomain;
88          }
89          else if (1 == axisDomainOrder(i))
90          {
91            CAxis* axis = CAxis::get(axisList[idxAxis]);
92            start.push_back(axis->begin);
93            count.push_back(axis->n);
94            --idxAxis ;
95          }
96          else
97          {
98            if (1 == axisDomainOrder.numElements())
99            {
100              start.push_back(0);
101              count.push_back(1);
102            }
103          }
104        }
105
106        SuperClassWriter::getData(dataOut, fieldId, isCollective, record, &start, &count);
107        break;
108      }
109    }
110  }
111  CATCH
112
113  void CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)
114  TRY
115  {
116    StdString fieldId = field->getFieldOutputName();
117
118    CGrid* grid = field->getGrid();
119
120    std::vector<CDomain*> domainP = grid->getDomains();
121    std::vector<CAxis*> axisP = grid->getAxis();
122    std::vector<CScalar*> scalarP = grid->getScalars();
123    int gridDim = domainP.size() * 2 + axisP.size();
124
125    // Nothing to do with scalar without timestep
126    if ((0 == gridDim) && (!SuperClassWriter::isTemporal(fieldId))) 
127      return;
128
129    // Verify the compatibility of dimension of declared grid and real grid in file
130    int realGridDim = 1;
131    bool isUnstructuredGrid = ((gridDim < 2) ? false :  SuperClassWriter::isUnstructured(fieldId));
132    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId);
133    std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId);
134
135    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size();
136    if (isUnstructuredGrid) ++realGridDim;
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
144    if (SuperClassWriter::isTemporal(fieldId))
145    {
146      dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName());
147      dimList.pop_front() ;  // assume time dimension is first
148    }
149
150    std::list<std::pair<StdString, StdSize> > listDimSize;
151/*
152    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap)
153      listDimSize.push_front(*itMap);
154*/
155
156//    if (!SuperClassWriter::isRectilinear(fieldId))
157    if (true)
158    {
159      for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
160        listDimSize.push_front(*dimSizeMap.find(*it));
161    }
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    }
182
183    // Now process domain and axis
184    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
185    int numElement = domainP.size() + axisP.size() + scalarP.size();
186    int elementPosition = 0;
187    int idxDomain = 0, idxAxis = 0, idxScalar = 0;
188
189    std::pair<std::set<StdString>::iterator,bool> it;
190    for (int i = 0; i < numElement; ++i)
191    {
192      if(2 == axisDomainOrder(i))
193      {
194        if (readAttributeValues)
195        {
196           it = readValueDomains_.insert(domainP[idxDomain]->getId());
197           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
198        }
199        else
200        {
201          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId());
202          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
203        }
204        ++idxDomain;
205        if (isUnstructuredGrid) ++elementPosition;
206        else elementPosition += 2;
207      }
208      else if (1 == axisDomainOrder(i))
209      {
210        if (readAttributeValues)
211        {
212          it = readValueAxis_.insert(axisP[idxAxis]->getId());
213          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
214        }
215        else
216        {
217          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId());
218          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
219        }
220        ++idxAxis;
221        ++elementPosition;
222      }
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      }
238    }
239  }
240  CATCH
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
247    \param [in] fieldId id (or name) associated with the grid
248  */
249  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
250                                                       int elementPosition, const StdString& fieldId)
251  TRY
252  {
253    // There are some optional attributes of a domain to retrieve from file    // + lon lat?
254    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
255                                                              iteMap  = dimSizeMap.end();
256
257    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
258    itMapNj = itMapNi; ++itMapNj;
259
260    if ((CDomain::type_attr::rectilinear == domain->type))
261    {
262      // Ok, try to read some attributes such as longitude and latitude
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      }
270
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);
277      }     
278    }
279    else if ((CDomain::type_attr::curvilinear == domain->type))
280    {
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
304      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
305      nBeginLatLon[0] = jbegin; nBeginLatLon[1] = ibegin;
306      nSizeLatLon[0]  = nj; nSizeLatLon[1] = ni;
307
308      StdString latName = this->getLatCoordName(fieldId);
309      if (SuperClassWriter::hasVariable(latName))
310      {
311        domain->latvalue_curvilinear_read_from_file.resize(ni, nj);
312        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
313      }
314      StdString lonName = this->getLonCoordName(fieldId);
315      if (SuperClassWriter::hasVariable(lonName))
316      {
317        domain->lonvalue_curvilinear_read_from_file.resize(ni, nj);
318        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
319      }
320
321      StdString boundsLatName = this->getBoundsId(latName);
322      StdString boundsLonName = this->getBoundsId(lonName);
323
324      int nbVertex = 4; //this->getNbVertex(fieldId);
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)) 
336        domain->nvertex.setValue(nbVertex);
337
338      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
339      nBeginBndsLatLon[0] = jbegin; nSizeBndsLatLon[0] = nj;
340      nBeginBndsLatLon[1] = ibegin; nSizeBndsLatLon[1] = ni;
341      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
342
343      if (SuperClassWriter::hasVariable(boundsLatName))
344      {
345        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj);
346        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
347
348      }
349      if (SuperClassWriter::hasVariable(boundsLonName)) 
350      {
351        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj);
352        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
353      }     
354    }
355    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
356    {
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
370      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
371      nBeginLatLon[0] = ibegin;
372      nSizeLatLon[0]  = ni;
373
374      StdString latName = this->getLatCoordName(fieldId);
375      if (SuperClassWriter::hasVariable(latName))
376      {
377        domain->latvalue_unstructured_read_from_file.resize(ni);
378        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); 
379      }
380
381      StdString lonName = this->getLonCoordName(fieldId);
382      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
383      {
384        domain->lonvalue_unstructured_read_from_file.resize(ni);
385        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
386      }
387
388      StdString boundsLatName = this->getBoundsId(latName);
389      StdString boundsLonName = this->getBoundsId(lonName);
390
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);
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)) 
410        domain->nvertex.setValue(nbVertex);
411
412      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2);
413      nBeginBndsLatLon[0] = ibegin; nSizeBndsLatLon[0] = ni;
414      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
415
416      if (SuperClassWriter::hasVariable(boundsLatName)) 
417      {
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);
420      }
421
422      if (SuperClassWriter::hasVariable(boundsLonName)) 
423      {
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      }     
427    }
428    domain->fillInLonLat();
429  }
430  CATCH
431
432  /*!
433    Read attribute value of a domain from a file
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
437    \param [in] fieldId id (or name) associated with the grid
438  */
439  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
440                                                   int elementPosition, const StdString& fieldId)
441  TRY
442  {
443    // There are some mandatory attributes of a domain to retrieve from file
444    // + ni_glo, nj_glo
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;
449
450    if (CDomain::type_attr::rectilinear == domain->type || CDomain::type_attr::curvilinear == domain->type ||
451        this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
452    {
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      } 
462      domain->nj_glo.setValue(itMapNj->second);
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      } 
473      domain->ni_glo.setValue(itMapNi->second);
474    }
475    else if (CDomain::type_attr::unstructured == domain->type|| this->isUnstructured(fieldId))
476    {
477      domain->nj_glo.setValue(1);
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      }       
488      domain->ni_glo.setValue(itMapNi->second);
489    }
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    }
509  }
510  CATCH
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
517    \param [in] fieldId id (or name) associated with the grid
518  */
519  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
520                                                 int elementPosition, const StdString& fieldId)
521  TRY
522  {
523    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
524                                                              iteMap = dimSizeMap.end();
525    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
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    }   
536    axis->n_glo.setValue(itMapN->second);
537  }
538  CATCH
539
540  /*!
541    Read attribute value of an axis from a file
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
545    \param [in] fieldId id (or name) associated with the grid
546  */
547  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
548                                                    int elementPosition, const StdString& fieldId)
549  TRY
550  {
551    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
552                                                              iteMap = dimSizeMap.end();
553    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
554
555    { // Read axis value
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      }
568    }
569  }
570  CATCH
571
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  {
582    /*Nothing to do */
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  {
595    /*Nothing to do */
596  }
597
598  void CNc4DataInput::closeFile_(void)
599  TRY
600  {
601    SuperClassWriter::close();
602  }
603  CATCH
604} // namespace xios
Note: See TracBrowser for help on using the repository browser.