source: XIOS/dev/dev_olga/src/interface/c/icduration.cpp @ 1612

Last change on this file since 1612 was 1612, checked in by oabramkina, 21 months ago

Dev: adding exception handling.

To activate it, compilation flag -DXIOS_EXCEPTION should be added.

File size: 3.3 KB
Line 
1#include "xios.hpp"
2
3#include "icutil.hpp"
4#include "icdate.hpp"
5#include "calendar_util.hpp"
6
7extern "C"
8{
9  void cxios_duration_convert_to_string(cxios_duration dur_c, char* str, int str_size)
10  TRY
11  {
12    xios::CDuration dur( dur_c.year, dur_c.month, dur_c.day, dur_c.hour, dur_c.minute, dur_c.second, dur_c.timestep );
13
14    if (!string_copy(dur.toString(), str, str_size))
15      ERROR("void cxios_duration_convert_to_string(cxios_duration dur_c, char* str, int str_size)", << "Input string is too short");
16  }
17  CATCH_DUMP_STACK
18
19  cxios_duration cxios_duration_convert_from_string(const char* str, int str_size)
20  TRY
21  {
22    std::string dur_str;
23    xios::CDuration dur;
24
25    if (cstr2string(str, str_size, dur_str))
26      dur = xios::CDuration::FromString(dur_str);
27
28    return { dur.year, dur.month, dur.day, dur.hour, dur.minute, dur.second, dur.timestep };
29  }
30  CATCH_DUMP_STACK
31
32  cxios_duration cxios_duration_add(cxios_duration dur1_c, cxios_duration dur2_c)
33  TRY
34  {
35    xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep );
36    xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep );
37
38    xios::CDuration res = dur1 + dur2;
39    return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep };
40  }
41  CATCH_DUMP_STACK
42
43  cxios_duration cxios_duration_sub(cxios_duration dur1_c, cxios_duration dur2_c)
44  TRY
45  {
46    xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep );
47    xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep );
48
49    xios::CDuration res = dur1 - dur2;
50    return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep };
51  }
52  CATCH_DUMP_STACK
53
54  cxios_duration cxios_duration_mult(double val, cxios_duration dur_c)
55  TRY
56  {
57    xios::CDuration dur( dur_c.year, dur_c.month, dur_c.day, dur_c.hour, dur_c.minute, dur_c.second, dur_c.timestep );
58    xios::CDuration res = val * dur;
59    return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep };
60  }
61  CATCH_DUMP_STACK
62
63  cxios_duration cxios_duration_neg(cxios_duration dur_c)
64  TRY
65  {
66    xios::CDuration dur( dur_c.year, dur_c.month, dur_c.day, dur_c.hour, dur_c.minute, dur_c.second, dur_c.timestep );
67    xios::CDuration res = -dur;
68    return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep };
69  }
70  CATCH_DUMP_STACK
71
72  bool cxios_duration_eq(cxios_duration dur1_c, cxios_duration dur2_c)
73  TRY
74  {
75    xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep );
76    xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep );
77    return (dur1 == dur2);
78  }
79  CATCH_DUMP_STACK
80
81  bool cxios_duration_neq(cxios_duration dur1_c, cxios_duration dur2_c)
82  TRY
83  {
84    xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep );
85    xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep );
86    return (dur1 != dur2);
87  }
88  CATCH_DUMP_STACK
89}
Note: See TracBrowser for help on using the repository browser.