[549] | 1 | /* ************************************************************************** * |
---|
| 2 | * Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011 * |
---|
| 3 | * ************************************************************************** */ |
---|
| 4 | |
---|
| 5 | #include <boost/multi_array.hpp> |
---|
| 6 | |
---|
[1542] | 7 | #include <memory> |
---|
| 8 | |
---|
[591] | 9 | #include "xios.hpp" |
---|
[549] | 10 | |
---|
| 11 | #include "attribute_template.hpp" |
---|
| 12 | #include "object_template.hpp" |
---|
| 13 | #include "group_template.hpp" |
---|
| 14 | |
---|
| 15 | #include "icutil.hpp" |
---|
| 16 | #include "icdate.hpp" |
---|
| 17 | #include "timer.hpp" |
---|
| 18 | #include "calendar_wrapper.hpp" |
---|
| 19 | |
---|
| 20 | extern "C" |
---|
| 21 | { |
---|
| 22 | // /////////////////////////////// Définitions ////////////////////////////// // |
---|
| 23 | |
---|
| 24 | // ----------------------- Redéfinition de type ---------------------------- |
---|
| 25 | |
---|
| 26 | typedef xios::CCalendarWrapper *XCalendarWrapperPtr; |
---|
| 27 | |
---|
| 28 | // ------------------------ Création des handle ----------------------------- |
---|
| 29 | |
---|
| 30 | void cxios_calendar_wrapper_handle_create(XCalendarWrapperPtr* _ret, const char* _id, int _id_len) |
---|
[1622] | 31 | TRY |
---|
[549] | 32 | { |
---|
| 33 | std::string id; |
---|
| 34 | if (!cstr2string(_id, _id_len, id)) return; |
---|
| 35 | CTimer::get("XIOS").resume(); |
---|
| 36 | *_ret = CCalendarWrapper::get(id); |
---|
| 37 | CTimer::get("XIOS").suspend(); |
---|
| 38 | } |
---|
[1622] | 39 | CATCH_DUMP_STACK |
---|
[549] | 40 | |
---|
| 41 | void cxios_get_current_calendar_wrapper(XCalendarWrapperPtr* _ret) |
---|
[1622] | 42 | TRY |
---|
[549] | 43 | { |
---|
| 44 | CTimer::get("XIOS").resume(); |
---|
| 45 | *_ret = CCalendarWrapper::get(CCalendarWrapper::GetDefName()); |
---|
| 46 | CTimer::get("XIOS").suspend(); |
---|
| 47 | } |
---|
[1622] | 48 | CATCH_DUMP_STACK |
---|
[549] | 49 | |
---|
| 50 | // -------------------- Vérification des identifiants ----------------------- |
---|
| 51 | |
---|
| 52 | void cxios_calendar_wrapper_valid_id(bool* _ret, const char* _id, int _id_len) |
---|
[1622] | 53 | TRY |
---|
[549] | 54 | { |
---|
| 55 | std::string id; |
---|
| 56 | if (!cstr2string(_id, _id_len, id)) return; |
---|
| 57 | CTimer::get("XIOS").resume(); |
---|
| 58 | *_ret = CCalendarWrapper::has(id); |
---|
| 59 | CTimer::get("XIOS").suspend(); |
---|
| 60 | } |
---|
[1622] | 61 | CATCH_DUMP_STACK |
---|
[549] | 62 | |
---|
| 63 | // ----------------------- Custom getters and setters ----------------------- |
---|
| 64 | |
---|
| 65 | void cxios_set_calendar_wrapper_date_start_date(XCalendarWrapperPtr calendarWrapper_hdl, cxios_date start_date_c) |
---|
[1622] | 66 | TRY |
---|
[549] | 67 | { |
---|
| 68 | CTimer::get("XIOS").resume(); |
---|
| 69 | CDate start_date(*calendarWrapper_hdl->getCalendar(true), |
---|
| 70 | start_date_c.year, |
---|
| 71 | start_date_c.month, |
---|
| 72 | start_date_c.day, |
---|
| 73 | start_date_c.hour, |
---|
| 74 | start_date_c.minute, |
---|
| 75 | start_date_c.second); |
---|
| 76 | calendarWrapper_hdl->setInitDate(start_date); |
---|
| 77 | CTimer::get("XIOS").suspend(); |
---|
| 78 | } |
---|
[1622] | 79 | CATCH_DUMP_STACK |
---|
[549] | 80 | |
---|
| 81 | void cxios_get_calendar_wrapper_date_start_date(XCalendarWrapperPtr calendarWrapper_hdl, cxios_date* start_date_c) |
---|
[1622] | 82 | TRY |
---|
[549] | 83 | { |
---|
| 84 | CTimer::get("XIOS").resume(); |
---|
| 85 | const CDate& start_date = calendarWrapper_hdl->getInitDate(); |
---|
| 86 | start_date_c->year = start_date.getYear(); |
---|
| 87 | start_date_c->month = start_date.getMonth(); |
---|
| 88 | start_date_c->day = start_date.getDay(); |
---|
| 89 | start_date_c->hour = start_date.getHour(); |
---|
| 90 | start_date_c->minute = start_date.getMinute(); |
---|
| 91 | start_date_c->second = start_date.getSecond(); |
---|
| 92 | CTimer::get("XIOS").suspend(); |
---|
| 93 | } |
---|
[1622] | 94 | CATCH_DUMP_STACK |
---|
[549] | 95 | |
---|
| 96 | void cxios_set_calendar_wrapper_date_time_origin(XCalendarWrapperPtr calendarWrapper_hdl, cxios_date time_origin_c) |
---|
[1622] | 97 | TRY |
---|
[549] | 98 | { |
---|
| 99 | CTimer::get("XIOS").resume(); |
---|
| 100 | CDate time_origin(*calendarWrapper_hdl->getCalendar(true), |
---|
| 101 | time_origin_c.year, |
---|
| 102 | time_origin_c.month, |
---|
| 103 | time_origin_c.day, |
---|
| 104 | time_origin_c.hour, |
---|
| 105 | time_origin_c.minute, |
---|
| 106 | time_origin_c.second); |
---|
| 107 | calendarWrapper_hdl->setTimeOrigin(time_origin); |
---|
| 108 | CTimer::get("XIOS").suspend(); |
---|
| 109 | } |
---|
[1622] | 110 | CATCH_DUMP_STACK |
---|
[549] | 111 | |
---|
| 112 | void cxios_get_calendar_wrapper_date_time_origin(XCalendarWrapperPtr calendarWrapper_hdl, cxios_date* time_origin_c) |
---|
[1622] | 113 | TRY |
---|
[549] | 114 | { |
---|
| 115 | CTimer::get("XIOS").resume(); |
---|
| 116 | const CDate& time_origin = calendarWrapper_hdl->getTimeOrigin(); |
---|
| 117 | time_origin_c->year = time_origin.getYear(); |
---|
| 118 | time_origin_c->month = time_origin.getMonth(); |
---|
| 119 | time_origin_c->day = time_origin.getDay(); |
---|
| 120 | time_origin_c->hour = time_origin.getHour(); |
---|
| 121 | time_origin_c->minute = time_origin.getMinute(); |
---|
| 122 | time_origin_c->second = time_origin.getSecond(); |
---|
| 123 | CTimer::get("XIOS").suspend(); |
---|
| 124 | } |
---|
[1622] | 125 | CATCH_DUMP_STACK |
---|
[549] | 126 | |
---|
| 127 | // ----------------------- Calendar creation and update ---------------------- |
---|
| 128 | |
---|
| 129 | void cxios_create_calendar(XCalendarWrapperPtr calendarWrapper_hdl) |
---|
[1622] | 130 | TRY |
---|
[549] | 131 | { |
---|
| 132 | CTimer::get("XIOS").resume(); |
---|
| 133 | calendarWrapper_hdl->createCalendar(); |
---|
| 134 | CTimer::get("XIOS").suspend(); |
---|
| 135 | } |
---|
[1622] | 136 | CATCH_DUMP_STACK |
---|
[549] | 137 | |
---|
| 138 | void cxios_update_calendar_timestep(XCalendarWrapperPtr calendarWrapper_hdl) |
---|
[1622] | 139 | TRY |
---|
[549] | 140 | { |
---|
| 141 | CTimer::get("XIOS").resume(); |
---|
| 142 | calendarWrapper_hdl->updateTimestep(); |
---|
| 143 | CTimer::get("XIOS").suspend(); |
---|
| 144 | } |
---|
[1622] | 145 | CATCH_DUMP_STACK |
---|
[549] | 146 | } // extern "C" |
---|