source: XIOS/dev/branch_openmp/src/interface/c/icduration.cpp @ 1482

Last change on this file since 1482 was 1482, checked in by yushan, 3 years ago

Branch EP merged with Dev_cmip6 @r1481

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