Ignore:
Timestamp:
12/10/14 14:27:09 (10 years ago)
Author:
rlacroix
Message:

Add a new attribute type for dates and use it for the context's start_date and time_origin.

The "xios_date" type should now be used to get/set date attributes through the Fortran interface. This avoids using strings to manipulate dates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/interface/c_attr/iccontext_attr.cpp

    r526 r532  
    1010#include "group_template.hpp" 
    1111#include "icutil.hpp" 
     12#include "icdate.hpp" 
    1213#include "timer.hpp" 
    1314#include "node_type.hpp" 
     
    6970   
    7071   
    71   void cxios_set_context_start_date(context_Ptr context_hdl, const char * start_date, int start_date_size) 
     72  void cxios_set_context_start_date(context_Ptr context_hdl, cxios_date start_date_c) 
    7273  { 
    73     std::string start_date_str; 
    74     if(!cstr2string(start_date, start_date_size, start_date_str)) return; 
    75      CTimer::get("XIOS").resume(); 
    76     context_hdl->start_date.setValue(start_date_str); 
    77      CTimer::get("XIOS").suspend(); 
     74    CTimer::get("XIOS").resume(); 
     75    context_hdl->start_date.allocate(); 
     76    CDate& start_date = context_hdl->start_date.get(); 
     77    start_date.setDate(start_date_c.year, 
     78                           start_date_c.month, 
     79                           start_date_c.day, 
     80                           start_date_c.hour, 
     81                           start_date_c.minute, 
     82                           start_date_c.second); 
     83    if (start_date.hasRelCalendar()) 
     84      start_date.checkDate(); 
     85    CTimer::get("XIOS").suspend(); 
    7886  } 
    7987   
    80   void cxios_get_context_start_date(context_Ptr context_hdl, char * start_date, int start_date_size) 
     88  void cxios_get_context_start_date(context_Ptr context_hdl, cxios_date* start_date_c) 
    8189  { 
    82      CTimer::get("XIOS").resume(); 
    83     if(!string_copy(context_hdl->start_date.getInheritedValue(),start_date , start_date_size)) 
    84       ERROR("void cxios_get_context_start_date(context_Ptr context_hdl, char * start_date, int start_date_size)", <<"Input string is to short"); 
    85      CTimer::get("XIOS").suspend(); 
     90    CTimer::get("XIOS").resume(); 
     91    CDate start_date = context_hdl->start_date.getInheritedValue(); 
     92    start_date_c->year = start_date.getYear(); 
     93    start_date_c->month = start_date.getMonth(); 
     94    start_date_c->day = start_date.getDay(); 
     95    start_date_c->hour = start_date.getHour(); 
     96    start_date_c->minute = start_date.getMinute(); 
     97    start_date_c->second = start_date.getSecond(); 
     98    CTimer::get("XIOS").suspend(); 
    8699  } 
    87100   
     
    95108   
    96109   
    97   void cxios_set_context_time_origin(context_Ptr context_hdl, const char * time_origin, int time_origin_size) 
     110  void cxios_set_context_time_origin(context_Ptr context_hdl, cxios_date time_origin_c) 
    98111  { 
    99     std::string time_origin_str; 
    100     if(!cstr2string(time_origin, time_origin_size, time_origin_str)) return; 
    101      CTimer::get("XIOS").resume(); 
    102     context_hdl->time_origin.setValue(time_origin_str); 
    103      CTimer::get("XIOS").suspend(); 
     112    CTimer::get("XIOS").resume(); 
     113    context_hdl->time_origin.allocate(); 
     114    CDate& time_origin = context_hdl->time_origin.get(); 
     115    time_origin.setDate(time_origin_c.year, 
     116                           time_origin_c.month, 
     117                           time_origin_c.day, 
     118                           time_origin_c.hour, 
     119                           time_origin_c.minute, 
     120                           time_origin_c.second); 
     121    if (time_origin.hasRelCalendar()) 
     122      time_origin.checkDate(); 
     123    CTimer::get("XIOS").suspend(); 
    104124  } 
    105125   
    106   void cxios_get_context_time_origin(context_Ptr context_hdl, char * time_origin, int time_origin_size) 
     126  void cxios_get_context_time_origin(context_Ptr context_hdl, cxios_date* time_origin_c) 
    107127  { 
    108      CTimer::get("XIOS").resume(); 
    109     if(!string_copy(context_hdl->time_origin.getInheritedValue(),time_origin , time_origin_size)) 
    110       ERROR("void cxios_get_context_time_origin(context_Ptr context_hdl, char * time_origin, int time_origin_size)", <<"Input string is to short"); 
    111      CTimer::get("XIOS").suspend(); 
     128    CTimer::get("XIOS").resume(); 
     129    CDate time_origin = context_hdl->time_origin.getInheritedValue(); 
     130    time_origin_c->year = time_origin.getYear(); 
     131    time_origin_c->month = time_origin.getMonth(); 
     132    time_origin_c->day = time_origin.getDay(); 
     133    time_origin_c->hour = time_origin.getHour(); 
     134    time_origin_c->minute = time_origin.getMinute(); 
     135    time_origin_c->second = time_origin.getSecond(); 
     136    CTimer::get("XIOS").suspend(); 
    112137  } 
    113138   
Note: See TracChangeset for help on using the changeset viewer.