source: XIOS/trunk/src/io/nc4_data_input.cpp @ 1553

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

The zoom is dead, long live the zoom.

Replacing domain_zoom transformation by copying it from domain_extract. From now on, only the zoomed part of a domain is sent to servers. On the user's side all definitions stay the same.

To do soon: axis_zoom.

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