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

Last change on this file since 2280 was 2280, checked in by ymipsl, 2 years ago

Improve file reading reading

  • add_offset and scaling_factor attributes are set when present in reading file
  • Add new attribute for axis to scale axis_value when read from file : convert_from_factor
  • fix bugs when time dimension in reading file is not unlimited

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