[325] | 1 | /* ************************************************************************** * |
---|
[335] | 2 | * Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011 * |
---|
[325] | 3 | * ************************************************************************** */ |
---|
| 4 | |
---|
| 5 | #include <boost/multi_array.hpp> |
---|
| 6 | #include <boost/shared_ptr.hpp> |
---|
| 7 | |
---|
[591] | 8 | #include "xios.hpp" |
---|
[325] | 9 | |
---|
[352] | 10 | #include "attribute_template.hpp" |
---|
| 11 | #include "object_template.hpp" |
---|
| 12 | #include "group_template.hpp" |
---|
[325] | 13 | |
---|
| 14 | #include "icutil.hpp" |
---|
[347] | 15 | #include "timer.hpp" |
---|
[352] | 16 | #include "context.hpp" |
---|
| 17 | #include "grid.hpp" |
---|
| 18 | #include "file.hpp" |
---|
| 19 | #include "field.hpp" |
---|
| 20 | #include "axis.hpp" |
---|
| 21 | #include "domain.hpp" |
---|
[472] | 22 | #include "variable.hpp" |
---|
[325] | 23 | |
---|
| 24 | extern "C" |
---|
| 25 | { |
---|
| 26 | // /////////////////////////////// Définitions ////////////////////////////// // |
---|
| 27 | |
---|
| 28 | // ----------------------- Redéfinition de types ---------------------------- |
---|
| 29 | |
---|
[345] | 30 | typedef xios::CContext * XContextPtr; |
---|
[325] | 31 | |
---|
[345] | 32 | typedef xios::CGrid * XGridPtr; |
---|
| 33 | typedef xios::CGridGroup * XGridGroupPtr; |
---|
[325] | 34 | |
---|
[345] | 35 | typedef xios::CFile * XFilePtr; |
---|
| 36 | typedef xios::CFileGroup * XFileGroupPtr; |
---|
[325] | 37 | |
---|
[345] | 38 | typedef xios::CField * XFieldPtr; |
---|
| 39 | typedef xios::CFieldGroup * XFieldGroupPtr; |
---|
[325] | 40 | |
---|
[345] | 41 | typedef xios::CDomain * XDomainPtr; |
---|
| 42 | typedef xios::CDomainGroup * XDomainGroupPtr; |
---|
[325] | 43 | |
---|
[345] | 44 | typedef xios::CAxis * XAxisPtr; |
---|
| 45 | typedef xios::CAxisGroup * XAxisGroupPtr; |
---|
[509] | 46 | |
---|
[472] | 47 | typedef xios::CVariable * XVariablePtr; |
---|
| 48 | typedef xios::CVariableGroup * XVariableGroupPtr; |
---|
[509] | 49 | |
---|
[325] | 50 | // ----------------------- Ajout d'enfant à un parent ----------------------- |
---|
[509] | 51 | |
---|
[325] | 52 | void cxios_xml_tree_add_field |
---|
| 53 | (XFieldGroupPtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size) |
---|
| 54 | { |
---|
[509] | 55 | std::string child_id_str; |
---|
[347] | 56 | CTimer::get("XIOS").resume() ; |
---|
[325] | 57 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 58 | { |
---|
[347] | 59 | *child_ = parent_->createChild(child_id_str) ; |
---|
[325] | 60 | } |
---|
| 61 | else |
---|
| 62 | { |
---|
[347] | 63 | *child_ = parent_->createChild() ; |
---|
[325] | 64 | } |
---|
[347] | 65 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 66 | } |
---|
[509] | 67 | |
---|
[325] | 68 | void cxios_xml_tree_add_grid |
---|
| 69 | (XGridGroupPtr parent_, XGridPtr * child_, const char * child_id, int child_id_size) |
---|
| 70 | { |
---|
[509] | 71 | std::string child_id_str; |
---|
[347] | 72 | CTimer::get("XIOS").resume() ; |
---|
[325] | 73 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 74 | { |
---|
[347] | 75 | *child_ = parent_->createChild(child_id_str) ; |
---|
[325] | 76 | } |
---|
| 77 | else |
---|
| 78 | { |
---|
[347] | 79 | *child_ = parent_->createChild() ; |
---|
[325] | 80 | } |
---|
[347] | 81 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 82 | } |
---|
[509] | 83 | |
---|
[325] | 84 | void cxios_xml_tree_add_file |
---|
| 85 | (XFileGroupPtr parent_, XFilePtr * child_, const char * child_id, int child_id_size) |
---|
| 86 | { |
---|
[509] | 87 | std::string child_id_str; |
---|
[347] | 88 | CTimer::get("XIOS").resume() ; |
---|
[325] | 89 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 90 | { |
---|
[347] | 91 | *child_ = parent_->createChild(child_id_str) ; |
---|
[325] | 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
[347] | 95 | *child_ = parent_->createChild() ; |
---|
[325] | 96 | } |
---|
[347] | 97 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 98 | } |
---|
[509] | 99 | |
---|
[325] | 100 | void cxios_xml_tree_add_axis |
---|
| 101 | (XAxisGroupPtr parent_, XAxisPtr * child_, const char * child_id, int child_id_size) |
---|
| 102 | { |
---|
[509] | 103 | std::string child_id_str; |
---|
[347] | 104 | CTimer::get("XIOS").resume() ; |
---|
[325] | 105 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 106 | { |
---|
[347] | 107 | *child_ = parent_->createChild(child_id_str) ; |
---|
[325] | 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
[347] | 111 | *child_ = parent_->createChild() ; |
---|
[325] | 112 | } |
---|
[347] | 113 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 114 | } |
---|
[509] | 115 | |
---|
[325] | 116 | void cxios_xml_tree_add_domain |
---|
| 117 | (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size) |
---|
| 118 | { |
---|
[347] | 119 | std::string child_id_str; |
---|
| 120 | CTimer::get("XIOS").resume() ; |
---|
[325] | 121 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 122 | { |
---|
[347] | 123 | *child_ = parent_->createChild(child_id_str) ; |
---|
[325] | 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
[347] | 127 | *child_ = parent_->createChild() ; |
---|
[325] | 128 | } |
---|
[347] | 129 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 130 | } |
---|
[509] | 131 | |
---|
[325] | 132 | void cxios_xml_tree_add_fieldtofile |
---|
| 133 | (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size) |
---|
| 134 | { |
---|
[347] | 135 | std::string child_id_str; |
---|
| 136 | CTimer::get("XIOS").resume() ; |
---|
[509] | 137 | |
---|
[325] | 138 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 139 | { |
---|
[347] | 140 | *child_ = parent_->addField(child_id_str); |
---|
[325] | 141 | } |
---|
| 142 | else |
---|
| 143 | { |
---|
[347] | 144 | *child_ = parent_->addField(); |
---|
[325] | 145 | } |
---|
[347] | 146 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 147 | } |
---|
| 148 | |
---|
[472] | 149 | void cxios_xml_tree_add_variabletofile |
---|
| 150 | (XFilePtr parent_, XVariablePtr * child_, const char * child_id, int child_id_size) |
---|
| 151 | { |
---|
| 152 | std::string child_id_str; |
---|
| 153 | CTimer::get("XIOS").resume() ; |
---|
[509] | 154 | |
---|
[472] | 155 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 156 | { |
---|
| 157 | *child_ = parent_->addVariable(child_id_str); |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | *child_ = parent_->addVariable(); |
---|
| 162 | } |
---|
| 163 | CTimer::get("XIOS").suspend() ; |
---|
| 164 | } |
---|
[509] | 165 | |
---|
[472] | 166 | void cxios_xml_tree_add_variabletofield |
---|
| 167 | (XFieldPtr parent_, XVariablePtr * child_, const char * child_id, int child_id_size) |
---|
| 168 | { |
---|
| 169 | std::string child_id_str; |
---|
| 170 | CTimer::get("XIOS").resume() ; |
---|
[509] | 171 | |
---|
[472] | 172 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 173 | { |
---|
| 174 | *child_ = parent_->addVariable(child_id_str); |
---|
| 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | *child_ = parent_->addVariable(); |
---|
| 179 | } |
---|
| 180 | CTimer::get("XIOS").suspend() ; |
---|
[509] | 181 | } |
---|
[325] | 182 | // ----------------------- Ajout de groupe à un parent ---------------------- |
---|
| 183 | |
---|
| 184 | void cxios_xml_tree_add_fieldgroup |
---|
| 185 | (XFieldGroupPtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 186 | { |
---|
[509] | 187 | std::string child_id_str; |
---|
[347] | 188 | CTimer::get("XIOS").resume() ; |
---|
[325] | 189 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 190 | { |
---|
[347] | 191 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
[325] | 192 | } |
---|
| 193 | else |
---|
| 194 | { |
---|
[347] | 195 | *child_ = parent_->createChildGroup() ; |
---|
[325] | 196 | } |
---|
[347] | 197 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 198 | } |
---|
| 199 | |
---|
| 200 | void cxios_xml_tree_add_gridgroup |
---|
| 201 | (XGridGroupPtr parent_, XGridGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 202 | { |
---|
| 203 | std::string child_id_str; |
---|
[347] | 204 | CTimer::get("XIOS").resume() ; |
---|
[325] | 205 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 206 | { |
---|
[347] | 207 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
[325] | 208 | } |
---|
| 209 | else |
---|
| 210 | { |
---|
[347] | 211 | *child_ = parent_->createChildGroup() ; |
---|
[325] | 212 | } |
---|
[347] | 213 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 214 | } |
---|
| 215 | |
---|
| 216 | void cxios_xml_tree_add_filegroup |
---|
| 217 | (XFileGroupPtr parent_, XFileGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 218 | { |
---|
| 219 | std::string child_id_str; |
---|
[347] | 220 | CTimer::get("XIOS").resume() ; |
---|
[325] | 221 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 222 | { |
---|
[347] | 223 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
[325] | 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
[347] | 227 | *child_ = parent_->createChildGroup() ; |
---|
[325] | 228 | } |
---|
[347] | 229 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 230 | } |
---|
| 231 | |
---|
| 232 | void cxios_xml_tree_add_axisgroup |
---|
| 233 | (XAxisGroupPtr parent_, XAxisGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 234 | { |
---|
| 235 | std::string child_id_str; |
---|
[347] | 236 | CTimer::get("XIOS").resume() ; |
---|
[325] | 237 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 238 | { |
---|
[347] | 239 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
[325] | 240 | } |
---|
| 241 | else |
---|
| 242 | { |
---|
[347] | 243 | *child_ = parent_->createChildGroup() ; |
---|
[325] | 244 | } |
---|
[347] | 245 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 246 | } |
---|
| 247 | |
---|
| 248 | void cxios_xml_tree_add_domaingroup |
---|
| 249 | (XDomainGroupPtr parent_, XDomainGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 250 | { |
---|
| 251 | std::string child_id_str; |
---|
[347] | 252 | CTimer::get("XIOS").resume() ; |
---|
[325] | 253 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 254 | { |
---|
[347] | 255 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
[325] | 256 | } |
---|
| 257 | else |
---|
| 258 | { |
---|
[347] | 259 | *child_ = parent_->createChildGroup() ; |
---|
[325] | 260 | } |
---|
[347] | 261 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 262 | } |
---|
| 263 | |
---|
| 264 | void cxios_xml_tree_add_fieldgrouptofile |
---|
| 265 | (XFilePtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 266 | { |
---|
[509] | 267 | std::string child_id_str; |
---|
[347] | 268 | CTimer::get("XIOS").resume() ; |
---|
[325] | 269 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 270 | { |
---|
[347] | 271 | *child_ = parent_->addFieldGroup(child_id_str); |
---|
[325] | 272 | } |
---|
| 273 | else |
---|
| 274 | { |
---|
[347] | 275 | *child_ = parent_->addFieldGroup(); |
---|
[325] | 276 | } |
---|
[347] | 277 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 278 | } |
---|
[509] | 279 | |
---|
[472] | 280 | void cxios_xml_tree_add_variablegrouptofile |
---|
| 281 | (XFilePtr parent_, XVariableGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 282 | { |
---|
[509] | 283 | std::string child_id_str; |
---|
[472] | 284 | CTimer::get("XIOS").resume() ; |
---|
| 285 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 286 | { |
---|
| 287 | *child_ = parent_->addVariableGroup(child_id_str); |
---|
| 288 | } |
---|
| 289 | else |
---|
| 290 | { |
---|
| 291 | *child_ = parent_->addVariableGroup(); |
---|
| 292 | } |
---|
| 293 | CTimer::get("XIOS").suspend() ; |
---|
| 294 | } |
---|
[509] | 295 | |
---|
[472] | 296 | void cxios_xml_tree_add_variablegrouptofield |
---|
| 297 | (XFieldPtr parent_, XVariableGroupPtr * child_, const char * child_id, int child_id_size) |
---|
| 298 | { |
---|
[509] | 299 | std::string child_id_str; |
---|
[472] | 300 | CTimer::get("XIOS").resume() ; |
---|
| 301 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
| 302 | { |
---|
| 303 | *child_ = parent_->addVariableGroup(child_id_str); |
---|
| 304 | } |
---|
| 305 | else |
---|
| 306 | { |
---|
| 307 | *child_ = parent_->addVariableGroup(); |
---|
| 308 | } |
---|
| 309 | CTimer::get("XIOS").suspend() ; |
---|
[509] | 310 | } |
---|
| 311 | |
---|
| 312 | |
---|
[325] | 313 | // ----------------------- Affichage de l'arborescence ---------------------- |
---|
[509] | 314 | |
---|
| 315 | // void cxios_xml_tree_show (const char * filename, int filename_size) |
---|
[346] | 316 | // { |
---|
| 317 | // std::string filename_str; |
---|
| 318 | // try |
---|
| 319 | // { |
---|
| 320 | // if (cstr2string(filename, filename_size, filename_str)) |
---|
| 321 | // xios::CTreeManager::PrintTreeToFile(filename_str); |
---|
| 322 | // else |
---|
| 323 | // xios::CTreeManager::PrintTreeToStream(std::clog); |
---|
| 324 | // } |
---|
| 325 | // catch (xios::CException & exc) |
---|
| 326 | // { |
---|
| 327 | // std::cerr << exc.getMessage() << std::endl; |
---|
| 328 | // exit (EXIT_FAILURE); |
---|
| 329 | // } |
---|
| 330 | // } |
---|
[509] | 331 | |
---|
| 332 | |
---|
[325] | 333 | // ----------------------- Parsing de document xml -------------------------- |
---|
[509] | 334 | |
---|
[346] | 335 | // void cxios_xml_parse_file (const char * filename , int filename_size)// |
---|
| 336 | // { |
---|
[509] | 337 | // std::string filename_str; |
---|
[346] | 338 | // if (!cstr2string(filename, filename_size, filename_str)) return; |
---|
| 339 | // |
---|
| 340 | // try |
---|
| 341 | // { |
---|
| 342 | // xios::CTreeManager::ParseFile(filename_str); |
---|
| 343 | // } |
---|
| 344 | // catch (xios::CException & exc) |
---|
| 345 | // { |
---|
| 346 | // std::cerr << exc.getMessage() << std::endl; |
---|
| 347 | // exit (EXIT_FAILURE); |
---|
| 348 | // } |
---|
| 349 | // } |
---|
[509] | 350 | |
---|
[346] | 351 | // void cxios_xml_parse_string(const char * xmlcontent, int xmlcontent_size) |
---|
| 352 | // { |
---|
[509] | 353 | // std::string xmlcontent_str; |
---|
[346] | 354 | // if (!cstr2string(xmlcontent, xmlcontent_size, xmlcontent_str)) return; |
---|
| 355 | // |
---|
| 356 | // try |
---|
| 357 | // { |
---|
| 358 | // xios::CTreeManager::ParseString(xmlcontent_str); |
---|
| 359 | // } |
---|
| 360 | // catch (xios::CException & exc) |
---|
| 361 | // { |
---|
| 362 | // std::cerr << exc.getMessage() << std::endl; |
---|
| 363 | // exit (EXIT_FAILURE); |
---|
| 364 | // } |
---|
| 365 | // } |
---|
[325] | 366 | |
---|
| 367 | |
---|
[509] | 368 | |
---|
[325] | 369 | } // extern "C" |
---|