source: XIOS/branchs/xios-2.0/src/io/nc4_data_input.cpp @ 1627

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

Trunk: minor modifications for reading UGRID.

Using attribute nvertex defined by a user and not deduced from metadata of a file being read.
Taking into account the fact that the bounds attribute is not required by UGRID.

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