Changeset 526 for XIOS/trunk


Ignore:
Timestamp:
12/02/14 15:18:09 (9 years ago)
Author:
rlacroix
Message:

Convert some attributes to enumerations:

  • file: par_access
  • context: calendar_type

Those changes should have no effect on existing XML configuration files and ensure that a proper error message is always displayed during parsing if the value is not supported.

Location:
XIOS/trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/config/calendar_type.conf

    r501 r526  
    11#ifdef __XMLIO_CAllLeapCalendar__ 
    2    DECLARE_CALENDAR(AllLeap  , AllLeap) 
     2   DECLARE_CALENDAR(AllLeap, calendar_type_attr::AllLeap) 
    33#endif //__XMLIO_CAllLeapCalendar__ 
    44 
    55#ifdef __XMLIO_CD360Calendar__ 
    6    DECLARE_CALENDAR(D360  , D360) 
     6   DECLARE_CALENDAR(D360, calendar_type_attr::D360) 
    77#endif //__XMLIO_CD360Calendar__ 
    88 
    99#ifdef __XMLIO_CGregorianCalendar__ 
    10    DECLARE_CALENDAR(Gregorian  , Gregorian) 
     10   DECLARE_CALENDAR(Gregorian, calendar_type_attr::Gregorian) 
    1111#endif //__XMLIO_CGregorianCalendar__ 
    1212 
    1313#ifdef __XMLIO_CJulianCalendar__ 
    14    DECLARE_CALENDAR(Julian  , Julian) 
     14   DECLARE_CALENDAR(Julian, calendar_type_attr::Julian) 
    1515#endif //__XMLIO_CJulianCalendar__ 
    1616 
    1717#ifdef __XMLIO_CNoLeapCalendar__ 
    18    DECLARE_CALENDAR(NoLeap  , NoLeap) 
     18   DECLARE_CALENDAR(NoLeap, calendar_type_attr::NoLeap) 
    1919#endif //__XMLIO_CNoLeapCalendar__ 
    20  
    21 #undef DECLARE_CALENDAR 
  • XIOS/trunk/src/config/context_attribute.conf

    r501 r526  
    1 DECLARE_ATTRIBUTE(StdString, calendar_type) 
     1DECLARE_ENUM5(calendar_type, D360, AllLeap, NoLeap, Julian, Gregorian) 
    22DECLARE_ATTRIBUTE(StdString, start_date) 
    33DECLARE_ATTRIBUTE(StdString, time_origin) 
  • XIOS/trunk/src/config/file_attribute.conf

    r517 r526  
    1313DECLARE_ENUM2(type,one_file,multiple_file) 
    1414DECLARE_ENUM2(format, netcdf4, netcdf4_classic) 
    15 DECLARE_ATTRIBUTE(StdString,      par_access) 
     15DECLARE_ENUM2(par_access, collective, independent) 
    1616 
    1717// DECLARE_ATTRIBUTE_DEF(bool, enabled, true) 
  • XIOS/trunk/src/interface/c_attr/iccontext_attr.cpp

    r509 r526  
    2222    if(!cstr2string(calendar_type, calendar_type_size, calendar_type_str)) return; 
    2323     CTimer::get("XIOS").resume(); 
    24     context_hdl->calendar_type.setValue(calendar_type_str); 
     24    context_hdl->calendar_type.fromString(calendar_type_str); 
    2525     CTimer::get("XIOS").suspend(); 
    2626  } 
     
    2929  { 
    3030     CTimer::get("XIOS").resume(); 
    31     if(!string_copy(context_hdl->calendar_type.getInheritedValue(),calendar_type , calendar_type_size)) 
     31    if(!string_copy(context_hdl->calendar_type.getInheritedStringValue(),calendar_type , calendar_type_size)) 
    3232      ERROR("void cxios_get_context_calendar_type(context_Ptr context_hdl, char * calendar_type, int calendar_type_size)", <<"Input string is to short"); 
    3333     CTimer::get("XIOS").suspend(); 
  • XIOS/trunk/src/interface/c_attr/icfile_attr.cpp

    r517 r526  
    215215    if(!cstr2string(par_access, par_access_size, par_access_str)) return; 
    216216     CTimer::get("XIOS").resume(); 
    217     file_hdl->par_access.setValue(par_access_str); 
     217    file_hdl->par_access.fromString(par_access_str); 
    218218     CTimer::get("XIOS").suspend(); 
    219219  } 
     
    222222  { 
    223223     CTimer::get("XIOS").resume(); 
    224     if(!string_copy(file_hdl->par_access.getInheritedValue(),par_access , par_access_size)) 
     224    if(!string_copy(file_hdl->par_access.getInheritedStringValue(),par_access , par_access_size)) 
    225225      ERROR("void cxios_get_file_par_access(file_Ptr file_hdl, char * par_access, int par_access_size)", <<"Input string is to short"); 
    226226     CTimer::get("XIOS").suspend(); 
  • XIOS/trunk/src/interface/c_attr/icfilegroup_attr.cpp

    r517 r526  
    241241    if(!cstr2string(par_access, par_access_size, par_access_str)) return; 
    242242     CTimer::get("XIOS").resume(); 
    243     filegroup_hdl->par_access.setValue(par_access_str); 
     243    filegroup_hdl->par_access.fromString(par_access_str); 
    244244     CTimer::get("XIOS").suspend(); 
    245245  } 
     
    248248  { 
    249249     CTimer::get("XIOS").resume(); 
    250     if(!string_copy(filegroup_hdl->par_access.getInheritedValue(),par_access , par_access_size)) 
     250    if(!string_copy(filegroup_hdl->par_access.getInheritedStringValue(),par_access , par_access_size)) 
    251251      ERROR("void cxios_get_filegroup_par_access(filegroup_Ptr filegroup_hdl, char * par_access, int par_access_size)", <<"Input string is to short"); 
    252252     CTimer::get("XIOS").suspend(); 
  • XIOS/trunk/src/node/context.cpp

    r511 r526  
    7373   { 
    7474      this->calendar = newCalendar; 
    75       calendar_type.setValue(this->calendar->getId()); 
     75      calendar_type.fromString(this->calendar->getId()); 
    7676      start_date.setValue(this->calendar->getInitDate().toString()); 
    7777   } 
     
    8787               << "Impossible to define a calendar (an attribute is missing)."); 
    8888 
    89 #define DECLARE_CALENDAR(MType  , mtype)                              \ 
    90    if (calendar_type.getValue().compare(#mtype) == 0)                 \ 
    91    {                                                                  \ 
    92       if (time_origin.isEmpty())                                       \ 
    93         this->calendar =  boost::shared_ptr<CCalendar>          \ 
    94            (new C##MType##Calendar(start_date.getValue()));     \ 
    95       else this->calendar =  boost::shared_ptr<CCalendar>       \ 
    96            (new C##MType##Calendar(start_date.getValue(),time_origin.getValue()));    \ 
    97       if (!this->timestep.isEmpty())                                  \ 
    98        this->calendar->setTimeStep                                    \ 
    99           (CDuration::FromString(this->timestep.getValue()));   \ 
    100       return;                                                         \ 
     89#define DECLARE_CALENDAR(MType, eType)                                              \ 
     90   if (calendar_type.getValue() == eType)                                           \ 
     91   {                                                                                \ 
     92      if (time_origin.isEmpty())                                                    \ 
     93        this->calendar = boost::shared_ptr<CCalendar>                               \ 
     94            (new C##MType##Calendar(start_date.getValue()));                        \ 
     95      else this->calendar = boost::shared_ptr<CCalendar>                            \ 
     96            (new C##MType##Calendar(start_date.getValue(),time_origin.getValue())); \ 
     97      if (!this->timestep.isEmpty())                                                \ 
     98        this->calendar->setTimeStep                                                 \ 
     99            (CDuration::FromString(this->timestep.getValue()));                     \ 
     100      return;                                                                       \ 
    101101   } 
    102102#include "calendar_type.conf" 
     103#undef DECLARE_CALENDAR 
    103104 
    104105      ERROR("CContext::solveCalendar(void)", 
    105             << "[ calendar_type = " << calendar_type.getValue() << " ] " 
    106             << "The calendar is not defined !"); 
     106            << "[ calendar_type = " << calendar_type.getStringValue() << " ] " 
     107            << "The calendar is not properly handled!"); 
    107108   } 
    108109 
  • XIOS/trunk/src/node/file.cpp

    r518 r526  
    358358         oss << ".nc"; 
    359359 
    360          if (isOpen) data_out->closeFile() ; 
    361          bool isCollective=true ; 
    362          if (!par_access.isEmpty()) 
    363          { 
    364            if (par_access.getValue()=="independent") isCollective=false ; 
    365            else if (par_access.getValue()=="collective") isCollective=true ; 
    366            else 
    367            { 
    368              ERROR("void Context::createDataOutput(void)", 
    369                         "incorrect file <par_access> attribut : must be <collective> or <indepedent>, " 
    370                         <<"having : <"<<type.getValue()<<">") ; 
    371            } 
    372          } 
     360         bool isCollective = par_access.isEmpty() ||  par_access == par_access_attr::collective; 
     361 
     362         if (isOpen) data_out->closeFile(); 
     363 
    373364         data_out=shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), false, useClassicFormat, 
    374365                                                             fileComm, multifile, isCollective)); 
Note: See TracChangeset for help on using the changeset viewer.