source: XIOS/dev/branch_openmp/src/io/nc4_data_input.cpp @ 1642

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

dev on ADA. add flag switch _usingEP/_usingMPI

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