8 #include "ioda/core/obsspace_f.h"
15 #include "eckit/exception/Exceptions.h"
17 #include "oops/util/DateTime.h"
25 const util::DateTime * begin,
26 const util::DateTime * end) {
28 params.validateAndDeserialize(*conf);
29 return new ObsSpace(
params, oops::mpi::world(), *begin, *end, oops::mpi::myself());
34 ASSERT(obss !=
nullptr);
40 std::string obsname = obss.obsname();
41 lcname = obsname.size();
43 strncpy(cname, obsname.c_str(), lcname);
48 return &obss.obsvariables();
53 return obss.globalNumLocs();
74 std::size_t & len_dim_name,
char * dim_name) {
76 len_dim_name = dimName.size();
77 ASSERT(len_dim_name < 100);
78 strncpy(dim_name, dimName.c_str(), len_dim_name);
86 return static_cast<int>(obss.get_dim_id(std::string(dim_name)));
91 lcname = obss.comm().
name().size();
93 strncpy(cname, obss.comm().
name().c_str(), lcname);
97 const std::size_t & length, std::size_t * recnum) {
98 ASSERT(length >= obss.
nlocs());
99 for (std::size_t i = 0; i < length; i++) {
100 recnum[i] = obss.recnum()[i];
105 const std::size_t & length, std::size_t * index) {
106 ASSERT(length >= obss.
nlocs());
107 for (std::size_t i = 0; i < length; i++) {
110 index[i] = obss.index()[i] + 1;
115 return obss.has(std::string(group), std::string(vname));
119 const std::size_t & length, int32_t* vec,
120 const std::size_t & len_cs,
int* chan_select) {
121 ASSERT(len_cs <= obss.nchans());
122 std::vector<int> chanSelect(len_cs);
123 chanSelect.assign(chan_select, chan_select + len_cs);
124 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
126 ASSERT(length >= obss.
nlocs());
127 std::vector<int32_t> vdata(length);
128 obss.get_db(std::string(group), std::string(vname), vdata, chanSelect);
129 std::copy(vdata.begin(), vdata.end(), vec);
133 const std::size_t & length, int64_t* vec,
134 const std::size_t & len_cs,
int* chan_select) {
135 ASSERT(len_cs <= obss.nchans());
136 std::vector<int> chanSelect(len_cs);
137 chanSelect.assign(chan_select, chan_select + len_cs);
138 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
140 ASSERT(length >= obss.
nlocs());
145 const std::size_t & length,
float* vec,
146 const std::size_t & len_cs,
int* chan_select) {
147 ASSERT(len_cs <= obss.nchans());
148 std::vector<int> chanSelect(len_cs);
149 chanSelect.assign(chan_select, chan_select + len_cs);
150 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
152 ASSERT(length >= obss.
nlocs());
157 const std::size_t & length,
double* vec,
158 const std::size_t & len_cs,
int* chan_select) {
159 ASSERT(len_cs <= obss.nchans());
160 std::vector<int> chanSelect(len_cs);
161 chanSelect.assign(chan_select, chan_select + len_cs);
162 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
164 ASSERT(length >= obss.
nlocs());
165 std::vector<double> vdata(length);
166 obss.get_db(std::string(group), std::string(vname), vdata, chanSelect);
167 std::copy(vdata.begin(), vdata.end(), vec);
171 const std::size_t & length, int32_t* date, int32_t* time,
172 const std::size_t & len_cs,
int* chan_select) {
173 ASSERT(len_cs <= obss.nchans());
174 std::vector<int> chanSelect(len_cs);
175 chanSelect.assign(chan_select, chan_select + len_cs);
176 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
178 ASSERT(length >= obss.
nlocs());
182 util::DateTime temp_dt(
"0000-01-01T00:00:00Z");
183 std::vector<util::DateTime> dt_vect(length, temp_dt);
184 obss.get_db(std::string(group), std::string(vname), dt_vect, chanSelect);
194 for (std::size_t i = 0; i < length; i++) {
195 dt_vect[i].toYYYYMMDDhhmmss(year, month, day, hour, minute, second);
196 date[i] = (year * 10000) + (month * 100) + day;
197 time[i] = (hour * 10000) + (minute * 100) + second;
202 const std::size_t & length, int32_t* vec,
203 const std::size_t & ndims,
int* dim_ids) {
207 std::vector<std::string> dimList;
208 int numElements = (ndims > 0) ? 1 : 0;
209 for (std::size_t i = 0; i < ndims; ++i) {
211 dimList.push_back(obss.get_dim_name(dimId));
212 numElements *= obss.get_dim_size(dimId);
215 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
217 ASSERT(length >= numElements);
218 std::vector<int32_t> vdata;
219 vdata.assign(vec, vec + length);
221 obss.put_db(std::string(group), std::string(vname), vdata, dimList);
225 const std::size_t & length, int64_t* vec,
226 const std::size_t & ndims,
int* dim_ids) {
230 std::vector<std::string> dimList;
231 int numElements = (ndims > 0) ? 1 : 0;
232 for (std::size_t i = 0; i < ndims; ++i) {
234 dimList.push_back(obss.get_dim_name(dimId));
235 numElements *= obss.get_dim_size(dimId);
238 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
240 ASSERT(length >= numElements);
245 const std::size_t & length,
float* vec,
246 const std::size_t & ndims,
int* dim_ids) {
250 std::vector<std::string> dimList;
251 int numElements = (ndims > 0) ? 1 : 0;
252 for (std::size_t i = 0; i < ndims; ++i) {
254 dimList.push_back(obss.get_dim_name(dimId));
255 numElements *= obss.get_dim_size(dimId);
258 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
260 ASSERT(length >= numElements);
265 const std::size_t & length,
double* vec,
266 const std::size_t & ndims,
int* dim_ids) {
270 std::vector<std::string> dimList;
271 int numElements = (ndims > 0) ? 1 : 0;
272 for (std::size_t i = 0; i < ndims; ++i) {
274 dimList.push_back(obss.get_dim_name(dimId));
275 numElements *= obss.get_dim_size(dimId);
278 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
280 ASSERT(length >= numElements);
281 std::vector<double> vdata;
282 vdata.assign(vec, vec + length);
284 obss.put_db(std::string(group), std::string(vname), vdata, dimList);
std::size_t obsspace_get_nvars_f(const ObsSpace &obss)
void obsspace_get_comm_f(const ObsSpace &obss, int &lcname, char *cname)
const ObsSpace * obsspace_construct_f(const eckit::Configuration *conf, const util::DateTime *begin, const util::DateTime *end)
void obsspace_get_int32_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int32_t *vec, const std::size_t &len_cs, int *chan_select)
void obsspace_put_real32_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, float *vec, const std::size_t &ndims, int *dim_ids)
void obsspace_put_int32_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int32_t *vec, const std::size_t &ndims, int *dim_ids)
void obsspace_get_real32_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, float *vec, const std::size_t &len_cs, int *chan_select)
void obsspace_destruct_f(ObsSpace *obss)
std::size_t obsspace_get_nlocs_f(const ObsSpace &obss)
const oops::Variables * obsspace_obsvariables_f(const ObsSpace &obss)
IODA_DL void copy(const ObjectSelection &from, ObjectSelection &to, const ScaleMapping &scale_map)
Generic data copying function.
void obsspace_get_recnum_f(const ObsSpace &obss, const std::size_t &length, std::size_t *recnum)
int obsspace_get_dim_id_f(const ObsSpace &obss, const char *dim_name)
void obsspace_obsname_f(const ObsSpace &obss, size_t &lcname, char *cname)
void obsspace_get_real64_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, double *vec, const std::size_t &len_cs, int *chan_select)
void obsspace_get_datetime_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int32_t *date, int32_t *time, const std::size_t &len_cs, int *chan_select)
void obsspace_get_index_f(const ObsSpace &obss, const std::size_t &length, std::size_t *index)
void obsspace_put_real64_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, double *vec, const std::size_t &ndims, int *dim_ids)
bool obsspace_has_f(const ObsSpace &obss, const char *group, const char *vname)
void obsspace_get_int64_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int64_t *vec, const std::size_t &len_cs, int *chan_select)
std::size_t obsspace_get_nchans_f(const ObsSpace &obss)
int obsspace_get_nchans_dim_id_f()
int obsspace_get_nlocs_dim_id_f()
void obsspace_put_int64_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int64_t *vec, const std::size_t &ndims, int *dim_ids)
std::size_t obsspace_get_dim_size_f(const ObsSpace &obss, const int &dim_id)
std::size_t obsspace_get_gnlocs_f(const ObsSpace &obss)
void obsspace_get_dim_name_f(const ObsSpace &obss, const int &dim_id, std::size_t &len_dim_name, char *dim_name)
std::size_t obsspace_get_nrecs_f(const ObsSpace &obss)