source: XIOS/dev/XIOS_DEV_CMIP6/src/interface/c/icduration.cpp @ 1472

Last change on this file since 1472 was 1472, checked in by oabramkina, 2 years ago

Implementing a patch suggested by Rupert Nash in order to bring temporal_filter.cpp in compliance with c++98 norms.

For this, a constructor of CDuration has been added.

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