[219] | 1 | #include "nc4_data_output.hpp" |
---|
| 2 | |
---|
| 3 | #include <boost/lexical_cast.hpp> |
---|
[352] | 4 | #include "attribute_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[219] | 6 | |
---|
| 7 | #include "file.hpp" |
---|
| 8 | #include "calendar.hpp" |
---|
[278] | 9 | #include "context.hpp" |
---|
[300] | 10 | #include "context_server.hpp" |
---|
[498] | 11 | #include "netCdfException.hpp" |
---|
| 12 | #include "exception.hpp" |
---|
[219] | 13 | |
---|
[335] | 14 | namespace xios |
---|
[219] | 15 | { |
---|
[878] | 16 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
[219] | 17 | CNc4DataOutput::CNc4DataOutput |
---|
| 18 | (const StdString & filename, bool exist) |
---|
| 19 | : SuperClass() |
---|
| 20 | , SuperClassWriter(filename, exist) |
---|
| 21 | , filename(filename) |
---|
| 22 | { |
---|
[879] | 23 | SuperClass::type = MULTI_FILE; |
---|
[219] | 24 | } |
---|
| 25 | |
---|
| 26 | CNc4DataOutput::CNc4DataOutput |
---|
[878] | 27 | (const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, |
---|
[924] | 28 | MPI_Comm comm_file, bool multifile, bool isCollective, const StdString& timeCounterName) |
---|
[219] | 29 | : SuperClass() |
---|
[878] | 30 | , SuperClassWriter(filename, exist, useClassicFormat, useCFConvention, &comm_file, multifile, timeCounterName) |
---|
[379] | 31 | , comm_file(comm_file) |
---|
[219] | 32 | , filename(filename) |
---|
[335] | 33 | , isCollective(isCollective) |
---|
[219] | 34 | { |
---|
[879] | 35 | SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; |
---|
[219] | 36 | } |
---|
| 37 | |
---|
| 38 | CNc4DataOutput::~CNc4DataOutput(void) |
---|
[879] | 39 | { /* Ne rien faire de plus */ } |
---|
[219] | 40 | |
---|
| 41 | ///-------------------------------------------------------------- |
---|
| 42 | |
---|
| 43 | const StdString & CNc4DataOutput::getFileName(void) const |
---|
| 44 | { |
---|
| 45 | return (this->filename); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | //--------------------------------------------------------------- |
---|
| 49 | |
---|
[347] | 50 | void CNc4DataOutput::writeDomain_(CDomain* domain) |
---|
[219] | 51 | { |
---|
[881] | 52 | if (domain->type == CDomain::type_attr::unstructured) |
---|
| 53 | { |
---|
| 54 | if (SuperClassWriter::useCFConvention) |
---|
| 55 | writeUnstructuredDomain(domain) ; |
---|
| 56 | else |
---|
| 57 | writeUnstructuredDomainUgrid(domain) ; |
---|
| 58 | return ; |
---|
| 59 | } |
---|
[488] | 60 | |
---|
[347] | 61 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 62 | CContextServer* server=context->server ; |
---|
[488] | 63 | |
---|
[219] | 64 | if (domain->IsWritten(this->filename)) return; |
---|
| 65 | domain->checkAttributes(); |
---|
[488] | 66 | |
---|
| 67 | if (domain->isEmpty()) |
---|
[881] | 68 | if (SuperClass::type==MULTI_FILE) return; |
---|
[219] | 69 | |
---|
| 70 | std::vector<StdString> dim0, dim1; |
---|
[772] | 71 | StdString domid = domain->getDomainOutputName(); |
---|
[318] | 72 | StdString appendDomid = (singleDomain) ? "" : "_"+domid ; |
---|
[706] | 73 | if (isWrittenDomain(domid)) return ; |
---|
[774] | 74 | else setWrittenDomain(domid); |
---|
[449] | 75 | |
---|
| 76 | |
---|
| 77 | StdString dimXid, dimYid ; |
---|
[488] | 78 | |
---|
[664] | 79 | bool isRegularDomain = (domain->type == CDomain::type_attr::rectilinear); |
---|
[449] | 80 | switch (domain->type) |
---|
[433] | 81 | { |
---|
[449] | 82 | case CDomain::type_attr::curvilinear : |
---|
| 83 | dimXid = StdString("x").append(appendDomid); |
---|
| 84 | dimYid = StdString("y").append(appendDomid); |
---|
| 85 | break ; |
---|
[664] | 86 | case CDomain::type_attr::rectilinear : |
---|
[449] | 87 | dimXid = StdString("lon").append(appendDomid); |
---|
| 88 | dimYid = StdString("lat").append(appendDomid); |
---|
| 89 | break; |
---|
[488] | 90 | } |
---|
| 91 | |
---|
[617] | 92 | StdString dimVertId = StdString("nvertex").append(appendDomid); |
---|
| 93 | |
---|
[449] | 94 | string lonid,latid,bounds_lonid,bounds_latid ; |
---|
[611] | 95 | string areaId = "area" + appendDomid; |
---|
[391] | 96 | /* |
---|
[300] | 97 | StdString lonid_loc = (server->intraCommSize > 1) |
---|
[318] | 98 | ? StdString("lon").append(appendDomid).append("_local") |
---|
[278] | 99 | : lonid; |
---|
[300] | 100 | StdString latid_loc = (server->intraCommSize > 1) |
---|
[318] | 101 | ? StdString("lat").append(appendDomid).append("_local") |
---|
[278] | 102 | : latid; |
---|
[391] | 103 | */ |
---|
[219] | 104 | |
---|
[498] | 105 | try |
---|
[219] | 106 | { |
---|
[498] | 107 | switch (SuperClass::type) |
---|
| 108 | { |
---|
| 109 | case (MULTI_FILE) : |
---|
| 110 | { |
---|
| 111 | // if (domain->isEmpty()) return; |
---|
[488] | 112 | |
---|
[498] | 113 | if (server->intraCommSize > 1) |
---|
| 114 | { |
---|
| 115 | // SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue()); |
---|
| 116 | // SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue()); |
---|
| 117 | } |
---|
[286] | 118 | |
---|
[498] | 119 | switch (domain->type) |
---|
| 120 | { |
---|
| 121 | case CDomain::type_attr::curvilinear : |
---|
| 122 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
| 123 | lonid = StdString("nav_lon").append(appendDomid); |
---|
| 124 | latid = StdString("nav_lat").append(appendDomid); |
---|
| 125 | break ; |
---|
[664] | 126 | case CDomain::type_attr::rectilinear : |
---|
[498] | 127 | lonid = StdString("lon").append(appendDomid); |
---|
| 128 | latid = StdString("lat").append(appendDomid); |
---|
| 129 | dim0.push_back(dimYid); |
---|
| 130 | dim1.push_back(dimXid); |
---|
| 131 | break; |
---|
| 132 | } |
---|
[488] | 133 | |
---|
[617] | 134 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
| 135 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
| 136 | |
---|
[616] | 137 | SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv); |
---|
| 138 | SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv); |
---|
[488] | 139 | |
---|
[617] | 140 | if (domain->hasBounds) |
---|
| 141 | SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 142 | |
---|
[498] | 143 | if (server->intraCommSize > 1) |
---|
| 144 | { |
---|
[616] | 145 | this->writeLocalAttributes(domain->zoom_ibegin_srv, |
---|
| 146 | domain->zoom_ni_srv, |
---|
| 147 | domain->zoom_jbegin_srv, |
---|
| 148 | domain->zoom_nj_srv, |
---|
| 149 | appendDomid); |
---|
[488] | 150 | |
---|
[628] | 151 | if (singleDomain) |
---|
| 152 | this->writeLocalAttributes_IOIPSL(dimXid, dimYid, |
---|
| 153 | domain->zoom_ibegin_srv, |
---|
| 154 | domain->zoom_ni_srv, |
---|
| 155 | domain->zoom_jbegin_srv, |
---|
| 156 | domain->zoom_nj_srv, |
---|
| 157 | domain->ni_glo,domain->nj_glo, |
---|
| 158 | server->intraCommRank,server->intraCommSize); |
---|
[449] | 159 | } |
---|
[488] | 160 | |
---|
[665] | 161 | if (domain->hasLonLat) |
---|
[498] | 162 | { |
---|
[665] | 163 | switch (domain->type) |
---|
| 164 | { |
---|
| 165 | case CDomain::type_attr::curvilinear : |
---|
| 166 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
| 167 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
| 168 | break ; |
---|
| 169 | case CDomain::type_attr::rectilinear : |
---|
| 170 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
| 171 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); |
---|
| 172 | break ; |
---|
| 173 | } |
---|
[488] | 174 | |
---|
[665] | 175 | this->writeAxisAttributes(lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 176 | this->writeAxisAttributes(latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid); |
---|
[219] | 177 | |
---|
[665] | 178 | if (domain->hasBounds) |
---|
| 179 | { |
---|
| 180 | SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid); |
---|
| 181 | SuperClassWriter::addAttribute("bounds", bounds_latid, &latid); |
---|
[617] | 182 | |
---|
[665] | 183 | dim0.clear(); |
---|
| 184 | dim0.push_back(dimYid); |
---|
| 185 | dim0.push_back(dimXid); |
---|
| 186 | dim0.push_back(dimVertId); |
---|
| 187 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
| 188 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
| 189 | } |
---|
[617] | 190 | } |
---|
| 191 | |
---|
[498] | 192 | dim0.clear(); |
---|
[616] | 193 | dim0.push_back(dimYid); |
---|
[498] | 194 | dim0.push_back(dimXid); |
---|
[219] | 195 | |
---|
| 196 | |
---|
[498] | 197 | // supress mask if (server->intraCommSize > 1) |
---|
| 198 | // supress mask { |
---|
| 199 | // supress mask SuperClassWriter::addVariable(maskid, NC_INT, dim0); |
---|
| 200 | // supress mask |
---|
| 201 | // supress mask this->writeMaskAttributes(maskid, |
---|
| 202 | // supress mask domain->data_dim.getValue()/*, |
---|
| 203 | // supress mask domain->data_ni.getValue(), |
---|
| 204 | // supress mask domain->data_nj.getValue(), |
---|
| 205 | // supress mask domain->data_ibegin.getValue(), |
---|
| 206 | // supress mask domain->data_jbegin.getValue()*/); |
---|
| 207 | // supress mask } |
---|
[488] | 208 | |
---|
[498] | 209 | //SuperClassWriter::setDefaultValue(maskid, &dvm); |
---|
[219] | 210 | |
---|
[611] | 211 | if (domain->hasArea) |
---|
| 212 | { |
---|
| 213 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
[614] | 214 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 215 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 216 | } |
---|
| 217 | |
---|
[498] | 218 | SuperClassWriter::definition_end(); |
---|
[449] | 219 | |
---|
[665] | 220 | if (domain->hasLonLat) |
---|
[498] | 221 | { |
---|
[665] | 222 | switch (domain->type) |
---|
| 223 | { |
---|
| 224 | case CDomain::type_attr::curvilinear : |
---|
| 225 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); |
---|
| 226 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); |
---|
| 227 | break; |
---|
| 228 | case CDomain::type_attr::rectilinear : |
---|
| 229 | CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; |
---|
| 230 | SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0); |
---|
| 231 | CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; |
---|
| 232 | SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0); |
---|
| 233 | break; |
---|
| 234 | } |
---|
[611] | 235 | |
---|
[665] | 236 | if (domain->hasBounds) |
---|
| 237 | { |
---|
| 238 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0); |
---|
| 239 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0); |
---|
| 240 | } |
---|
[617] | 241 | } |
---|
| 242 | |
---|
[611] | 243 | if (domain->hasArea) |
---|
| 244 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0); |
---|
| 245 | |
---|
[498] | 246 | SuperClassWriter::definition_start(); |
---|
[219] | 247 | |
---|
[498] | 248 | break; |
---|
| 249 | } |
---|
| 250 | case (ONE_FILE) : |
---|
| 251 | { |
---|
[631] | 252 | SuperClassWriter::addDimension(dimXid, domain->global_zoom_ni); |
---|
| 253 | SuperClassWriter::addDimension(dimYid, domain->global_zoom_nj); |
---|
[286] | 254 | |
---|
[617] | 255 | if (domain->hasBounds) |
---|
| 256 | SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 257 | |
---|
[665] | 258 | if (domain->hasLonLat) |
---|
[498] | 259 | { |
---|
[665] | 260 | switch (domain->type) |
---|
| 261 | { |
---|
| 262 | case CDomain::type_attr::curvilinear : |
---|
| 263 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
| 264 | lonid = StdString("nav_lon").append(appendDomid); |
---|
| 265 | latid = StdString("nav_lat").append(appendDomid); |
---|
| 266 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
| 267 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
| 268 | break; |
---|
[449] | 269 | |
---|
[665] | 270 | case CDomain::type_attr::rectilinear : |
---|
| 271 | dim0.push_back(dimYid); |
---|
| 272 | dim1.push_back(dimXid); |
---|
| 273 | lonid = StdString("lon").append(appendDomid); |
---|
| 274 | latid = StdString("lat").append(appendDomid); |
---|
| 275 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
| 276 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); |
---|
| 277 | break; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
| 281 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
| 282 | |
---|
| 283 | this->writeAxisAttributes |
---|
| 284 | (lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 285 | this->writeAxisAttributes |
---|
| 286 | (latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid); |
---|
| 287 | |
---|
| 288 | if (domain->hasBounds) |
---|
| 289 | { |
---|
| 290 | SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid); |
---|
| 291 | SuperClassWriter::addAttribute("bounds", bounds_latid, &latid); |
---|
| 292 | |
---|
| 293 | dim0.clear(); |
---|
[498] | 294 | dim0.push_back(dimYid); |
---|
[665] | 295 | dim0.push_back(dimXid); |
---|
| 296 | dim0.push_back(dimVertId); |
---|
| 297 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
| 298 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
| 299 | } |
---|
[498] | 300 | } |
---|
[611] | 301 | |
---|
| 302 | if (domain->hasArea) |
---|
| 303 | { |
---|
| 304 | dim0.clear(); |
---|
| 305 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
| 306 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
[614] | 307 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 308 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 309 | dim0.clear(); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | SuperClassWriter::definition_end(); |
---|
[286] | 313 | |
---|
[498] | 314 | switch (domain->type) |
---|
[384] | 315 | { |
---|
[498] | 316 | case CDomain::type_attr::curvilinear : |
---|
[449] | 317 | { |
---|
[498] | 318 | std::vector<StdSize> start(2) ; |
---|
| 319 | std::vector<StdSize> count(2) ; |
---|
| 320 | if (domain->isEmpty()) |
---|
| 321 | { |
---|
[611] | 322 | start[0]=0 ; start[1]=0 ; |
---|
[498] | 323 | count[0]=0 ; count[1]=0 ; |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | { |
---|
[631] | 327 | start[1]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 328 | start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin; |
---|
[498] | 329 | count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; |
---|
| 330 | } |
---|
[488] | 331 | |
---|
[665] | 332 | if (domain->hasLonLat) |
---|
| 333 | { |
---|
| 334 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); |
---|
| 335 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); |
---|
| 336 | } |
---|
[498] | 337 | break; |
---|
| 338 | } |
---|
[664] | 339 | case CDomain::type_attr::rectilinear : |
---|
[449] | 340 | { |
---|
[665] | 341 | if (domain->hasLonLat) |
---|
[498] | 342 | { |
---|
[665] | 343 | std::vector<StdSize> start(1) ; |
---|
| 344 | std::vector<StdSize> count(1) ; |
---|
| 345 | if (domain->isEmpty()) |
---|
| 346 | { |
---|
| 347 | start[0]=0 ; |
---|
| 348 | count[0]=0 ; |
---|
| 349 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); |
---|
| 350 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); |
---|
[449] | 351 | |
---|
[665] | 352 | } |
---|
| 353 | else |
---|
| 354 | { |
---|
| 355 | start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin; |
---|
| 356 | count[0]=domain->zoom_nj_srv ; |
---|
| 357 | CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; |
---|
| 358 | SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); |
---|
| 359 | |
---|
| 360 | start[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 361 | count[0]=domain->zoom_ni_srv ; |
---|
| 362 | CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; |
---|
| 363 | SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); |
---|
| 364 | } |
---|
[498] | 365 | } |
---|
| 366 | break; |
---|
[449] | 367 | } |
---|
[384] | 368 | } |
---|
[611] | 369 | |
---|
[617] | 370 | if (domain->hasBounds) |
---|
| 371 | { |
---|
| 372 | std::vector<StdSize> start(3); |
---|
| 373 | std::vector<StdSize> count(3); |
---|
| 374 | if (domain->isEmpty()) |
---|
| 375 | { |
---|
| 376 | start[2] = start[1] = start[0] = 0; |
---|
| 377 | count[2] = count[1] = count[0] = 0; |
---|
| 378 | } |
---|
| 379 | else |
---|
| 380 | { |
---|
| 381 | start[2] = 0; |
---|
[631] | 382 | start[1] = domain->zoom_ibegin_srv - domain->global_zoom_ibegin; |
---|
| 383 | start[0] = domain->zoom_jbegin_srv - domain->global_zoom_jbegin; |
---|
[617] | 384 | count[2] = domain->nvertex; |
---|
| 385 | count[1] = domain->zoom_ni_srv; |
---|
| 386 | count[0] = domain->zoom_nj_srv; |
---|
| 387 | } |
---|
[625] | 388 | |
---|
[878] | 389 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0, &start, &count); |
---|
| 390 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0, &start, &count); |
---|
[617] | 391 | } |
---|
| 392 | |
---|
[611] | 393 | if (domain->hasArea) |
---|
| 394 | { |
---|
| 395 | std::vector<StdSize> start(2); |
---|
| 396 | std::vector<StdSize> count(2); |
---|
| 397 | |
---|
| 398 | if (domain->isEmpty()) |
---|
| 399 | { |
---|
| 400 | start[0] = 0; start[1] = 0; |
---|
| 401 | count[0] = 0; count[1] = 0; |
---|
| 402 | } |
---|
| 403 | else |
---|
| 404 | { |
---|
[631] | 405 | start[1] = domain->zoom_ibegin_srv - domain->global_zoom_ibegin; |
---|
| 406 | start[0] = domain->zoom_jbegin_srv - domain->global_zoom_jbegin; |
---|
[611] | 407 | count[1] = domain->zoom_ni_srv; |
---|
| 408 | count[0] = domain->zoom_nj_srv; |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0, &start, &count); |
---|
| 412 | } |
---|
| 413 | |
---|
[498] | 414 | SuperClassWriter::definition_start(); |
---|
| 415 | break; |
---|
| 416 | } |
---|
| 417 | default : |
---|
| 418 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 419 | << "[ type = " << SuperClass::type << "]" |
---|
| 420 | << " not implemented yet !"); |
---|
| 421 | } |
---|
[449] | 422 | } |
---|
[498] | 423 | catch (CNetCdfException& e) |
---|
| 424 | { |
---|
| 425 | StdString msg("On writing the domain : "); |
---|
| 426 | msg.append(domid); msg.append("\n"); |
---|
| 427 | msg.append("In the context : "); |
---|
| 428 | msg.append(context->getId()); msg.append("\n"); |
---|
| 429 | msg.append(e.what()); |
---|
| 430 | ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg); |
---|
| 431 | } |
---|
| 432 | |
---|
[449] | 433 | domain->addRelFile(this->filename); |
---|
| 434 | } |
---|
| 435 | |
---|
[879] | 436 | //-------------------------------------------------------------- |
---|
[878] | 437 | |
---|
[879] | 438 | void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain) |
---|
| 439 | { |
---|
| 440 | CContext* context = CContext::getCurrent() ; |
---|
| 441 | CContextServer* server=context->server ; |
---|
[878] | 442 | |
---|
[879] | 443 | if (domain->IsWritten(this->filename)) return; |
---|
| 444 | domain->checkAttributes(); |
---|
| 445 | if (domain->isEmpty()) |
---|
| 446 | if (SuperClass::type==MULTI_FILE) return ; |
---|
[878] | 447 | |
---|
[879] | 448 | std::vector<StdString> dim0; |
---|
| 449 | StdString domid = domain->getDomainOutputName(); |
---|
| 450 | StdString domainName = domain->name; |
---|
[924] | 451 | domain->assignMesh(domainName, domain->nvertex); |
---|
| 452 | domain->mesh->createMeshEpsilon(server->intraComm, domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv); |
---|
[878] | 453 | |
---|
[879] | 454 | StdString node_x = domainName + "_node_x"; |
---|
| 455 | StdString node_y = domainName + "_node_y"; |
---|
[878] | 456 | |
---|
[879] | 457 | StdString edge_x = domainName + "_edge_x"; |
---|
| 458 | StdString edge_y = domainName + "_edge_y"; |
---|
| 459 | StdString edge_nodes = domainName + "_edge_nodes"; |
---|
[878] | 460 | |
---|
[879] | 461 | StdString face_x = domainName + "_face_x"; |
---|
| 462 | StdString face_y = domainName + "_face_y"; |
---|
| 463 | StdString face_nodes = domainName + "_face_nodes"; |
---|
[902] | 464 | StdString face_edges = domainName + "_face_edges"; |
---|
| 465 | StdString edge_faces = domainName + "_edge_face_links"; |
---|
| 466 | StdString face_faces = domainName + "_face_links"; |
---|
[878] | 467 | |
---|
[879] | 468 | StdString dimNode = "n" + domainName + "_node"; |
---|
| 469 | StdString dimEdge = "n" + domainName + "_edge"; |
---|
| 470 | StdString dimFace = "n" + domainName + "_face"; |
---|
| 471 | StdString dimVertex = "n" + domainName + "_vertex"; |
---|
| 472 | StdString dimTwo = "Two"; |
---|
[878] | 473 | |
---|
[879] | 474 | if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2); |
---|
| 475 | if (!isWrittenDomain(domid)) |
---|
| 476 | { |
---|
| 477 | dim0.clear(); |
---|
| 478 | SuperClassWriter::addVariable(domainName, NC_INT, dim0); |
---|
| 479 | SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName); |
---|
[924] | 480 | SuperClassWriter::addAttribute("long_name", StdString("Topology data of 2D unstructured mesh"), &domainName); |
---|
| 481 | SuperClassWriter::addAttribute("topology_dimension", 2, &domainName); |
---|
[879] | 482 | SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName); |
---|
| 483 | } |
---|
[878] | 484 | |
---|
[879] | 485 | try |
---|
| 486 | { |
---|
| 487 | switch (SuperClass::type) |
---|
| 488 | { |
---|
| 489 | case (ONE_FILE) : |
---|
| 490 | { |
---|
| 491 | // Adding nodes |
---|
| 492 | if (domain->nvertex == 1) |
---|
| 493 | { |
---|
| 494 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
| 495 | { |
---|
[902] | 496 | SuperClassWriter::addDimension(dimNode, domain->ni_glo); |
---|
[879] | 497 | dim0.clear(); |
---|
| 498 | dim0.push_back(dimNode); |
---|
| 499 | SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); |
---|
| 500 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
[924] | 501 | SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
[879] | 502 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
| 503 | SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); |
---|
| 504 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
[924] | 505 | SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
[879] | 506 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
| 507 | } |
---|
| 508 | } // domain->nvertex == 1 |
---|
[878] | 509 | |
---|
[879] | 510 | // Adding edges and nodes, if nodes have not been defined previously |
---|
| 511 | if (domain->nvertex == 2) |
---|
| 512 | { |
---|
| 513 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
| 514 | { |
---|
[924] | 515 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodesGlo); |
---|
[879] | 516 | dim0.clear(); |
---|
| 517 | dim0.push_back(dimNode); |
---|
| 518 | SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); |
---|
| 519 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
[924] | 520 | SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
[879] | 521 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
| 522 | SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); |
---|
| 523 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
[924] | 524 | SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
[879] | 525 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
| 526 | } |
---|
[924] | 527 | SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); |
---|
| 528 | SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); |
---|
| 529 | SuperClassWriter::addDimension(dimEdge, domain->ni_glo); |
---|
| 530 | dim0.clear(); |
---|
| 531 | dim0.push_back(dimEdge); |
---|
| 532 | SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); |
---|
| 533 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); |
---|
| 534 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x); |
---|
| 535 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); |
---|
| 536 | SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); |
---|
| 537 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); |
---|
| 538 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y); |
---|
| 539 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); |
---|
| 540 | dim0.clear(); |
---|
| 541 | dim0.push_back(dimEdge); |
---|
| 542 | dim0.push_back(dimTwo); |
---|
| 543 | SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0); |
---|
| 544 | SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); |
---|
| 545 | SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); |
---|
| 546 | SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); |
---|
[879] | 547 | } // domain->nvertex == 2 |
---|
[878] | 548 | |
---|
[879] | 549 | // Adding faces, edges, and nodes, if edges and nodes have not been defined previously |
---|
| 550 | if (domain->nvertex > 2) |
---|
| 551 | { |
---|
| 552 | // Nodes |
---|
| 553 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
| 554 | { |
---|
[924] | 555 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodesGlo); |
---|
[879] | 556 | dim0.clear(); |
---|
| 557 | dim0.push_back(dimNode); |
---|
| 558 | SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); |
---|
| 559 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
[924] | 560 | SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
[879] | 561 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
| 562 | SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); |
---|
| 563 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
[924] | 564 | SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
[879] | 565 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
| 566 | } |
---|
| 567 | if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y)) |
---|
| 568 | { |
---|
| 569 | SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); |
---|
| 570 | SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); |
---|
[924] | 571 | SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdgesGlo); |
---|
[879] | 572 | dim0.clear(); |
---|
| 573 | dim0.push_back(dimEdge); |
---|
| 574 | SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); |
---|
| 575 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); |
---|
[924] | 576 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x); |
---|
[879] | 577 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); |
---|
| 578 | SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); |
---|
| 579 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); |
---|
[924] | 580 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y); |
---|
[879] | 581 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); |
---|
| 582 | dim0.clear(); |
---|
| 583 | dim0.push_back(dimEdge); |
---|
| 584 | dim0.push_back(dimTwo); |
---|
| 585 | SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0); |
---|
| 586 | SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); |
---|
| 587 | SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); |
---|
| 588 | SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); |
---|
| 589 | } |
---|
[924] | 590 | SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName); |
---|
| 591 | SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName); |
---|
| 592 | SuperClassWriter::addDimension(dimFace, domain->ni_glo); |
---|
| 593 | SuperClassWriter::addDimension(dimVertex, domain->nvertex); |
---|
| 594 | dim0.clear(); |
---|
| 595 | dim0.push_back(dimFace); |
---|
| 596 | SuperClassWriter::addVariable(face_x, NC_FLOAT, dim0); |
---|
| 597 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x); |
---|
| 598 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh faces."), &face_x); |
---|
| 599 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x); |
---|
| 600 | SuperClassWriter::addVariable(face_y, NC_FLOAT, dim0); |
---|
| 601 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y); |
---|
| 602 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh faces."), &face_y); |
---|
| 603 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y); |
---|
| 604 | dim0.clear(); |
---|
| 605 | dim0.push_back(dimFace); |
---|
| 606 | dim0.push_back(dimVertex); |
---|
| 607 | SuperClassWriter::addVariable(face_nodes, NC_INT, dim0); |
---|
| 608 | SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes); |
---|
| 609 | SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes); |
---|
| 610 | SuperClassWriter::addAttribute("start_index", 0, &face_nodes); |
---|
| 611 | dim0.clear(); |
---|
| 612 | dim0.push_back(dimFace); |
---|
| 613 | dim0.push_back(dimVertex); |
---|
| 614 | SuperClassWriter::addVariable(face_edges, NC_INT, dim0); |
---|
| 615 | SuperClassWriter::addAttribute("cf_role", StdString("face_edge_connectivity"), &face_edges); |
---|
| 616 | SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its edges."), &face_edges); |
---|
| 617 | SuperClassWriter::addAttribute("start_index", 0, &face_edges); |
---|
[929] | 618 | SuperClassWriter::addAttribute("_FillValue", 999999, &face_edges); |
---|
[924] | 619 | dim0.clear(); |
---|
| 620 | dim0.push_back(dimEdge); |
---|
| 621 | dim0.push_back(dimTwo); |
---|
| 622 | SuperClassWriter::addVariable(edge_faces, NC_INT, dim0); |
---|
| 623 | SuperClassWriter::addAttribute("cf_role", StdString("edge_face connectivity"), &edge_faces); |
---|
| 624 | SuperClassWriter::addAttribute("long_name", StdString("neighbor faces for edges"), &edge_faces); |
---|
| 625 | SuperClassWriter::addAttribute("start_index", 0, &edge_faces); |
---|
| 626 | SuperClassWriter::addAttribute("_FillValue", -999, &edge_faces); |
---|
| 627 | SuperClassWriter::addAttribute("comment", StdString("missing neighbor faces are indicated using _FillValue"), &edge_faces); |
---|
| 628 | dim0.clear(); |
---|
| 629 | dim0.push_back(dimFace); |
---|
| 630 | dim0.push_back(dimVertex); |
---|
| 631 | SuperClassWriter::addVariable(face_faces, NC_INT, dim0); |
---|
| 632 | SuperClassWriter::addAttribute("cf_role", StdString("face_face connectivity"), &face_faces); |
---|
| 633 | SuperClassWriter::addAttribute("long_name", StdString("Indicates which other faces neighbor each face"), &face_faces); |
---|
| 634 | SuperClassWriter::addAttribute("start_index", 0, &face_faces); |
---|
[929] | 635 | SuperClassWriter::addAttribute("_FillValue", 999999, &face_faces); |
---|
[924] | 636 | SuperClassWriter::addAttribute("flag_values", -1, &face_faces); |
---|
| 637 | SuperClassWriter::addAttribute("flag_meanings", StdString("out_of_mesh"), &face_faces); |
---|
[879] | 638 | } // domain->nvertex > 2 |
---|
[878] | 639 | |
---|
[879] | 640 | SuperClassWriter::definition_end(); |
---|
[878] | 641 | |
---|
[924] | 642 | std::vector<StdSize> startEdges(1) ; |
---|
| 643 | std::vector<StdSize> countEdges(1) ; |
---|
| 644 | std::vector<StdSize> startNodes(1) ; |
---|
| 645 | std::vector<StdSize> countNodes(1) ; |
---|
| 646 | std::vector<StdSize> startFaces(1) ; |
---|
| 647 | std::vector<StdSize> countFaces(1) ; |
---|
| 648 | std::vector<StdSize> startEdgeNodes(2) ; |
---|
| 649 | std::vector<StdSize> countEdgeNodes(2) ; |
---|
| 650 | std::vector<StdSize> startEdgeFaces(2) ; |
---|
| 651 | std::vector<StdSize> countEdgeFaces(2) ; |
---|
| 652 | std::vector<StdSize> startFaceConctv(2) ; |
---|
| 653 | std::vector<StdSize> countFaceConctv(2) ; |
---|
[902] | 654 | |
---|
[879] | 655 | if (!isWrittenDomain(domid)) |
---|
| 656 | { |
---|
| 657 | if (domain->nvertex == 1) |
---|
| 658 | { |
---|
[924] | 659 | if (domain->isEmpty()) |
---|
| 660 | { |
---|
| 661 | startNodes[0]=0 ; |
---|
| 662 | countNodes[0]=0 ; |
---|
| 663 | } |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | startNodes[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 667 | countNodes[0] = domain->zoom_ni_srv ; |
---|
| 668 | } |
---|
| 669 | |
---|
| 670 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes); |
---|
| 671 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes); |
---|
[879] | 672 | } |
---|
| 673 | else if (domain->nvertex == 2) |
---|
[924] | 674 | { |
---|
| 675 | if (domain->isEmpty()) |
---|
| 676 | { |
---|
| 677 | startEdges[0]=0 ; |
---|
| 678 | countEdges[0]=0 ; |
---|
| 679 | startNodes[0]=0 ; |
---|
| 680 | countNodes[0]=0 ; |
---|
| 681 | startEdgeNodes[0]=0; |
---|
| 682 | startEdgeNodes[1]=0; |
---|
| 683 | countEdgeNodes[0]=0; |
---|
| 684 | countEdgeNodes[1]=0; |
---|
| 685 | |
---|
| 686 | } |
---|
| 687 | else |
---|
| 688 | { |
---|
| 689 | startEdges[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 690 | countEdges[0] = domain->zoom_ni_srv ; |
---|
| 691 | startNodes[0] = domain->mesh->node_start; |
---|
| 692 | countNodes[0] = domain->mesh->node_count; |
---|
| 693 | startEdgeNodes[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 694 | startEdgeNodes[1] = 0; |
---|
| 695 | countEdgeNodes[0] = domain->zoom_ni_srv; |
---|
| 696 | countEdgeNodes[1]= 2; |
---|
| 697 | } |
---|
| 698 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes); |
---|
| 699 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes); |
---|
| 700 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges); |
---|
| 701 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges); |
---|
| 702 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes); |
---|
| 703 | } |
---|
[879] | 704 | else |
---|
| 705 | { |
---|
[924] | 706 | if (domain->isEmpty()) |
---|
| 707 | { |
---|
| 708 | startFaces[0] = 0 ; |
---|
| 709 | countFaces[0] = 0 ; |
---|
| 710 | startNodes[0] = 0; |
---|
| 711 | countNodes[0] = 0; |
---|
| 712 | startEdges[0] = 0; |
---|
| 713 | countEdges[0] = 0; |
---|
| 714 | startEdgeFaces[0] = 0; |
---|
| 715 | startEdgeFaces[1] = 0; |
---|
| 716 | countEdgeFaces[0] = 0; |
---|
| 717 | countEdgeFaces[1] = 0; |
---|
| 718 | startFaceConctv[0] = 0; |
---|
| 719 | startFaceConctv[1] = 0; |
---|
| 720 | countFaceConctv[0] = 0; |
---|
| 721 | countFaceConctv[1] = 0; |
---|
| 722 | } |
---|
| 723 | else |
---|
| 724 | { |
---|
| 725 | startFaces[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 726 | countFaces[0] = domain->zoom_ni_srv ; |
---|
| 727 | startNodes[0] = domain->mesh->node_start; |
---|
| 728 | countNodes[0] = domain->mesh->node_count; |
---|
| 729 | startEdges[0] = domain->mesh->edge_start; |
---|
| 730 | countEdges[0] = domain->mesh->edge_count; |
---|
| 731 | startEdgeNodes[0] = domain->mesh->edge_start; |
---|
| 732 | startEdgeNodes[1] = 0; |
---|
| 733 | countEdgeNodes[0] = domain->mesh->edge_count; |
---|
| 734 | countEdgeNodes[1]= 2; |
---|
| 735 | startEdgeFaces[0] = domain->mesh->edge_start; |
---|
| 736 | startEdgeFaces[1]= 0; |
---|
| 737 | countEdgeFaces[0] = domain->mesh->edge_count; |
---|
| 738 | countEdgeFaces[1]= 2; |
---|
| 739 | startFaceConctv[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 740 | startFaceConctv[1] = 0; |
---|
| 741 | countFaceConctv[0] = domain->zoom_ni_srv; |
---|
| 742 | countFaceConctv[1] = domain->nvertex; |
---|
| 743 | } |
---|
| 744 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes); |
---|
| 745 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes); |
---|
| 746 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges); |
---|
| 747 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges); |
---|
| 748 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes); |
---|
| 749 | SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0, &startFaces, &countFaces); |
---|
| 750 | SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0, &startFaces, &countFaces); |
---|
| 751 | SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 752 | SuperClassWriter::writeData(domain->mesh->face_edges, face_edges, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 753 | SuperClassWriter::writeData(domain->mesh->edge_faces, edge_faces, isCollective, 0, &startEdgeFaces, &countEdgeFaces); |
---|
| 754 | SuperClassWriter::writeData(domain->mesh->face_faces, face_faces, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
[879] | 755 | } |
---|
| 756 | setWrittenDomain(domid); |
---|
| 757 | } // !isWrittenDomain |
---|
| 758 | else |
---|
| 759 | { |
---|
| 760 | if (domain->nvertex == 2) |
---|
| 761 | { |
---|
[924] | 762 | startEdges[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 763 | countEdges[0] = domain->zoom_ni_srv ; |
---|
| 764 | startEdgeNodes[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 765 | startEdgeNodes[1] = 0; |
---|
| 766 | countEdgeNodes[0] = domain->zoom_ni_srv; |
---|
| 767 | countEdgeNodes[1]= 2; |
---|
| 768 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges); |
---|
| 769 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges); |
---|
| 770 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes); |
---|
[879] | 771 | } |
---|
| 772 | if (domain->nvertex > 2) |
---|
| 773 | { |
---|
[924] | 774 | |
---|
[879] | 775 | if (!domain->mesh->edgesAreWritten) |
---|
| 776 | { |
---|
[924] | 777 | startEdges[0] = domain->mesh->edge_start; |
---|
| 778 | countEdges[0] = domain->mesh->edge_count; |
---|
| 779 | startEdgeNodes[0] = domain->mesh->edge_start; |
---|
| 780 | startEdgeNodes[1] = 0; |
---|
| 781 | countEdgeNodes[0] = domain->mesh->edge_count; |
---|
| 782 | countEdgeNodes[1]= 2; |
---|
| 783 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges); |
---|
| 784 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges); |
---|
| 785 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes); |
---|
[879] | 786 | } |
---|
[924] | 787 | startFaces[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 788 | countFaces[0] = domain->zoom_ni_srv; |
---|
| 789 | startEdgeFaces[0] = domain->mesh->edge_start; |
---|
| 790 | startEdgeFaces[1]= 0; |
---|
| 791 | countEdgeFaces[0] = domain->mesh->edge_count; |
---|
| 792 | countEdgeFaces[1]= 2; |
---|
| 793 | startFaceConctv[0] = domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 794 | startFaceConctv[1] = 0; |
---|
| 795 | countFaceConctv[0] = domain->zoom_ni_srv; |
---|
| 796 | countFaceConctv[1]= domain->nvertex; |
---|
| 797 | SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0, &startFaces, &countFaces); |
---|
| 798 | SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0, &startFaces, &countFaces); |
---|
| 799 | SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 800 | SuperClassWriter::writeData(domain->mesh->face_edges, face_edges, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 801 | SuperClassWriter::writeData(domain->mesh->edge_faces, edge_faces, isCollective, 0, &startEdgeFaces, &countEdgeFaces); |
---|
| 802 | SuperClassWriter::writeData(domain->mesh->face_faces, face_faces, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
[879] | 803 | } |
---|
| 804 | }// isWrittenDomain |
---|
[878] | 805 | |
---|
[879] | 806 | SuperClassWriter::definition_start(); |
---|
[878] | 807 | |
---|
[879] | 808 | break; |
---|
| 809 | } // ONE_FILE |
---|
[878] | 810 | |
---|
[879] | 811 | case (MULTI_FILE) : |
---|
| 812 | { |
---|
| 813 | break; |
---|
| 814 | } |
---|
[878] | 815 | |
---|
[879] | 816 | default : |
---|
| 817 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 818 | << "[ type = " << SuperClass::type << "]" |
---|
| 819 | << " not implemented yet !"); |
---|
| 820 | } // switch |
---|
| 821 | } // try |
---|
[878] | 822 | |
---|
[879] | 823 | catch (CNetCdfException& e) |
---|
| 824 | { |
---|
| 825 | StdString msg("On writing the domain : "); |
---|
| 826 | msg.append(domid); msg.append("\n"); |
---|
| 827 | msg.append("In the context : "); |
---|
| 828 | msg.append(context->getId()); msg.append("\n"); |
---|
| 829 | msg.append(e.what()); |
---|
[924] | 830 | ERROR("CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain)", << msg); |
---|
[879] | 831 | } |
---|
[878] | 832 | |
---|
[879] | 833 | domain->addRelFile(this->filename); |
---|
| 834 | } |
---|
[878] | 835 | |
---|
[879] | 836 | //-------------------------------------------------------------- |
---|
[878] | 837 | |
---|
[879] | 838 | void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain) |
---|
[449] | 839 | { |
---|
| 840 | CContext* context = CContext::getCurrent() ; |
---|
| 841 | CContextServer* server=context->server ; |
---|
[488] | 842 | |
---|
[449] | 843 | if (domain->IsWritten(this->filename)) return; |
---|
| 844 | domain->checkAttributes(); |
---|
[488] | 845 | |
---|
| 846 | if (domain->isEmpty()) |
---|
[449] | 847 | if (SuperClass::type==MULTI_FILE) return ; |
---|
| 848 | |
---|
| 849 | std::vector<StdString> dim0, dim1; |
---|
[772] | 850 | StdString domid = domain->getDomainOutputName(); |
---|
[705] | 851 | if (isWrittenDomain(domid)) return ; |
---|
[774] | 852 | else setWrittenDomain(domid); |
---|
[705] | 853 | |
---|
[449] | 854 | StdString appendDomid = (singleDomain) ? "" : "_"+domid ; |
---|
| 855 | |
---|
| 856 | StdString dimXid = StdString("cell").append(appendDomid); |
---|
| 857 | StdString dimVertId = StdString("nvertex").append(appendDomid); |
---|
[488] | 858 | |
---|
[449] | 859 | string lonid,latid,bounds_lonid,bounds_latid ; |
---|
[611] | 860 | string areaId = "area" + appendDomid; |
---|
[449] | 861 | |
---|
[498] | 862 | try |
---|
[449] | 863 | { |
---|
[498] | 864 | switch (SuperClass::type) |
---|
| 865 | { |
---|
| 866 | case (MULTI_FILE) : |
---|
| 867 | { |
---|
| 868 | dim0.push_back(dimXid); |
---|
[657] | 869 | SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv); |
---|
[488] | 870 | |
---|
[665] | 871 | lonid = StdString("lon").append(appendDomid); |
---|
| 872 | latid = StdString("lat").append(appendDomid); |
---|
[498] | 873 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
| 874 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
[665] | 875 | if (domain->hasLonLat) |
---|
| 876 | { |
---|
| 877 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
| 878 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
| 879 | this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 880 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); |
---|
| 881 | this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid); |
---|
| 882 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); |
---|
| 883 | if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 884 | } |
---|
[498] | 885 | dim0.clear(); |
---|
| 886 | if (domain->hasBounds) |
---|
| 887 | { |
---|
| 888 | dim0.push_back(dimXid); |
---|
| 889 | dim0.push_back(dimVertId); |
---|
| 890 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
| 891 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | dim0.clear(); |
---|
[449] | 895 | dim0.push_back(dimXid); |
---|
[611] | 896 | if (domain->hasArea) |
---|
| 897 | { |
---|
| 898 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
[614] | 899 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 900 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 901 | } |
---|
| 902 | |
---|
[498] | 903 | SuperClassWriter::definition_end(); |
---|
[449] | 904 | |
---|
[665] | 905 | if (domain->hasLonLat) |
---|
[498] | 906 | { |
---|
[665] | 907 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); |
---|
| 908 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); |
---|
| 909 | if (domain->hasBounds) |
---|
| 910 | { |
---|
| 911 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0); |
---|
| 912 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0); |
---|
| 913 | } |
---|
[498] | 914 | } |
---|
[611] | 915 | |
---|
| 916 | if (domain->hasArea) |
---|
| 917 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0); |
---|
| 918 | |
---|
[498] | 919 | SuperClassWriter::definition_start(); |
---|
| 920 | break ; |
---|
| 921 | } |
---|
[488] | 922 | |
---|
[498] | 923 | case (ONE_FILE) : |
---|
| 924 | { |
---|
| 925 | lonid = StdString("lon").append(appendDomid); |
---|
| 926 | latid = StdString("lat").append(appendDomid); |
---|
| 927 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
| 928 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
| 929 | dim0.push_back(dimXid); |
---|
[705] | 930 | SuperClassWriter::addDimension(dimXid, domain->ni_glo); |
---|
[665] | 931 | if (domain->hasLonLat) |
---|
| 932 | { |
---|
| 933 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
| 934 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
| 935 | |
---|
| 936 | this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 937 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); |
---|
| 938 | this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid); |
---|
| 939 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); |
---|
| 940 | if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 941 | } |
---|
[498] | 942 | dim0.clear(); |
---|
[449] | 943 | |
---|
[498] | 944 | if (domain->hasBounds) |
---|
| 945 | { |
---|
| 946 | dim0.push_back(dimXid); |
---|
| 947 | dim0.push_back(dimVertId); |
---|
| 948 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
| 949 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
| 950 | } |
---|
[488] | 951 | |
---|
[611] | 952 | if (domain->hasArea) |
---|
| 953 | { |
---|
| 954 | dim0.clear(); |
---|
| 955 | dim0.push_back(dimXid); |
---|
| 956 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
[614] | 957 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 958 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 959 | } |
---|
| 960 | |
---|
[498] | 961 | SuperClassWriter::definition_end(); |
---|
[488] | 962 | |
---|
[498] | 963 | std::vector<StdSize> start(1), startBounds(2) ; |
---|
| 964 | std::vector<StdSize> count(1), countBounds(2) ; |
---|
| 965 | if (domain->isEmpty()) |
---|
| 966 | { |
---|
| 967 | start[0]=0 ; |
---|
| 968 | count[0]=0 ; |
---|
| 969 | startBounds[1]=0 ; |
---|
| 970 | countBounds[1]=domain->nvertex ; |
---|
| 971 | startBounds[0]=0 ; |
---|
| 972 | countBounds[0]=0 ; |
---|
| 973 | } |
---|
| 974 | else |
---|
| 975 | { |
---|
[705] | 976 | start[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
| 977 | count[0]=domain->zoom_ni_srv ; |
---|
| 978 | startBounds[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
[498] | 979 | startBounds[1]=0 ; |
---|
[705] | 980 | countBounds[0]=domain->zoom_ni_srv ; |
---|
[498] | 981 | countBounds[1]=domain->nvertex ; |
---|
| 982 | } |
---|
[665] | 983 | |
---|
| 984 | if (domain->hasLonLat) |
---|
[498] | 985 | { |
---|
[665] | 986 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); |
---|
| 987 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); |
---|
| 988 | if (domain->hasBounds) |
---|
| 989 | { |
---|
| 990 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0,&startBounds,&countBounds); |
---|
| 991 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0,&startBounds,&countBounds); |
---|
| 992 | } |
---|
[498] | 993 | } |
---|
[488] | 994 | |
---|
[611] | 995 | if (domain->hasArea) |
---|
| 996 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0, &start, &count); |
---|
[488] | 997 | |
---|
[498] | 998 | SuperClassWriter::definition_start(); |
---|
[488] | 999 | |
---|
[498] | 1000 | break; |
---|
| 1001 | } |
---|
| 1002 | default : |
---|
| 1003 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 1004 | << "[ type = " << SuperClass::type << "]" |
---|
| 1005 | << " not implemented yet !"); |
---|
| 1006 | } |
---|
[219] | 1007 | } |
---|
[498] | 1008 | catch (CNetCdfException& e) |
---|
| 1009 | { |
---|
| 1010 | StdString msg("On writing the domain : "); |
---|
| 1011 | msg.append(domid); msg.append("\n"); |
---|
| 1012 | msg.append("In the context : "); |
---|
| 1013 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1014 | msg.append(e.what()); |
---|
| 1015 | ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg); |
---|
| 1016 | } |
---|
[219] | 1017 | domain->addRelFile(this->filename); |
---|
| 1018 | } |
---|
| 1019 | //-------------------------------------------------------------- |
---|
| 1020 | |
---|
[347] | 1021 | void CNc4DataOutput::writeAxis_(CAxis* axis) |
---|
[219] | 1022 | { |
---|
[609] | 1023 | if (axis->IsWritten(this->filename)) return; |
---|
| 1024 | axis->checkAttributes(); |
---|
| 1025 | int zoom_size_srv = axis->zoom_size_srv; |
---|
| 1026 | int zoom_begin_srv = axis->zoom_begin_srv; |
---|
[633] | 1027 | int zoom_size = (MULTI_FILE == SuperClass::type) ? zoom_size_srv |
---|
[821] | 1028 | : axis->global_zoom_n; |
---|
[633] | 1029 | int zoom_begin = (MULTI_FILE == SuperClass::type) ? zoom_begin_srv |
---|
[623] | 1030 | : axis->global_zoom_begin; |
---|
[488] | 1031 | |
---|
[633] | 1032 | if ((0 == zoom_size_srv) && (MULTI_FILE == SuperClass::type)) return; |
---|
[498] | 1033 | |
---|
[609] | 1034 | std::vector<StdString> dims; |
---|
[772] | 1035 | StdString axisid = axis->getAxisOutputName(); |
---|
[705] | 1036 | if (isWrittenAxis(axisid)) return ; |
---|
[774] | 1037 | else setWrittenAxis(axisid); |
---|
[705] | 1038 | |
---|
[609] | 1039 | try |
---|
| 1040 | { |
---|
| 1041 | SuperClassWriter::addDimension(axisid, zoom_size); |
---|
[816] | 1042 | if (axis->hasValue) |
---|
| 1043 | { |
---|
| 1044 | dims.push_back(axisid); |
---|
| 1045 | SuperClassWriter::addVariable(axisid, NC_FLOAT, dims); |
---|
[219] | 1046 | |
---|
[816] | 1047 | if (!axis->name.isEmpty()) |
---|
| 1048 | SuperClassWriter::addAttribute("name", axis->name.getValue(), &axisid); |
---|
[219] | 1049 | |
---|
[816] | 1050 | if (!axis->standard_name.isEmpty()) |
---|
| 1051 | SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisid); |
---|
[540] | 1052 | |
---|
[816] | 1053 | if (!axis->long_name.isEmpty()) |
---|
| 1054 | SuperClassWriter::addAttribute("long_name", axis->long_name.getValue(), &axisid); |
---|
[219] | 1055 | |
---|
[816] | 1056 | if (!axis->unit.isEmpty()) |
---|
| 1057 | SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisid); |
---|
[219] | 1058 | |
---|
[816] | 1059 | if (!axis->positive.isEmpty()) |
---|
| 1060 | { |
---|
| 1061 | SuperClassWriter::addAttribute("axis", string("Z"), &axisid); |
---|
| 1062 | SuperClassWriter::addAttribute("positive", |
---|
| 1063 | (axis->positive == CAxis::positive_attr::up) ? string("up") : string("down"), |
---|
| 1064 | &axisid); |
---|
| 1065 | } |
---|
[399] | 1066 | |
---|
[816] | 1067 | StdString axisBoundsId = axisid + "_bounds"; |
---|
| 1068 | if (!axis->bounds.isEmpty()) |
---|
| 1069 | { |
---|
| 1070 | dims.push_back("axis_nbounds"); |
---|
| 1071 | SuperClassWriter::addVariable(axisBoundsId, NC_FLOAT, dims); |
---|
| 1072 | SuperClassWriter::addAttribute("bounds", axisBoundsId, &axisid); |
---|
| 1073 | } |
---|
[488] | 1074 | |
---|
[816] | 1075 | SuperClassWriter::definition_end(); |
---|
| 1076 | |
---|
| 1077 | switch (SuperClass::type) |
---|
[633] | 1078 | { |
---|
[816] | 1079 | case MULTI_FILE: |
---|
| 1080 | { |
---|
| 1081 | CArray<double,1> axis_value(zoom_size_srv); |
---|
| 1082 | for (int i = 0; i < zoom_size_srv; i++) axis_value(i) = axis->value_srv(i); |
---|
| 1083 | SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); |
---|
[633] | 1084 | |
---|
[816] | 1085 | if (!axis->bounds.isEmpty()) |
---|
| 1086 | SuperClassWriter::writeData(axis->bound_srv, axisBoundsId, isCollective, 0); |
---|
[488] | 1087 | |
---|
[816] | 1088 | SuperClassWriter::definition_start(); |
---|
[219] | 1089 | |
---|
[816] | 1090 | break; |
---|
| 1091 | } |
---|
| 1092 | case ONE_FILE: |
---|
| 1093 | { |
---|
| 1094 | CArray<double,1> axis_value(zoom_size_srv); |
---|
| 1095 | axis_value = axis->value_srv; |
---|
[498] | 1096 | |
---|
[816] | 1097 | std::vector<StdSize> start(1), startBounds(2) ; |
---|
| 1098 | std::vector<StdSize> count(1), countBounds(2) ; |
---|
| 1099 | start[0] = startBounds[0] = zoom_begin_srv-axis->global_zoom_begin; |
---|
| 1100 | count[0] = countBounds[0] = zoom_size_srv; |
---|
| 1101 | startBounds[1] = 0; |
---|
| 1102 | countBounds[1] = 2; |
---|
| 1103 | SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count); |
---|
[633] | 1104 | |
---|
[816] | 1105 | if (!axis->bounds.isEmpty()) |
---|
| 1106 | SuperClassWriter::writeData(axis->bound_srv, axisBoundsId, isCollective, 0, &startBounds, &countBounds); |
---|
[609] | 1107 | |
---|
[816] | 1108 | SuperClassWriter::definition_start(); |
---|
[609] | 1109 | |
---|
[816] | 1110 | break; |
---|
| 1111 | } |
---|
| 1112 | default : |
---|
| 1113 | ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", |
---|
| 1114 | << "[ type = " << SuperClass::type << "]" |
---|
| 1115 | << " not implemented yet !"); |
---|
[609] | 1116 | } |
---|
| 1117 | } |
---|
| 1118 | } |
---|
| 1119 | catch (CNetCdfException& e) |
---|
| 1120 | { |
---|
| 1121 | StdString msg("On writing the axis : "); |
---|
| 1122 | msg.append(axisid); msg.append("\n"); |
---|
| 1123 | msg.append("In the context : "); |
---|
| 1124 | CContext* context = CContext::getCurrent() ; |
---|
| 1125 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1126 | msg.append(e.what()); |
---|
| 1127 | ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg); |
---|
| 1128 | } |
---|
| 1129 | axis->addRelFile(this->filename); |
---|
[391] | 1130 | } |
---|
[488] | 1131 | |
---|
[887] | 1132 | void CNc4DataOutput::writeScalar_(CScalar* scalar) |
---|
| 1133 | { |
---|
| 1134 | if (scalar->IsWritten(this->filename)) return; |
---|
| 1135 | scalar->checkAttributes(); |
---|
| 1136 | int scalarSize = 1; |
---|
| 1137 | |
---|
| 1138 | StdString scalaId = scalar->getScalarOutputName(); |
---|
| 1139 | if (isWrittenAxis(scalaId)) return ; |
---|
| 1140 | else setWrittenAxis(scalaId); |
---|
| 1141 | |
---|
| 1142 | try |
---|
| 1143 | { |
---|
| 1144 | if (!scalar->value.isEmpty()) |
---|
| 1145 | { |
---|
| 1146 | // dims.push_back(scalaId); |
---|
| 1147 | std::vector<StdString> dims; |
---|
| 1148 | SuperClassWriter::addVariable(scalaId, NC_FLOAT, dims); |
---|
| 1149 | |
---|
| 1150 | if (!scalar->name.isEmpty()) |
---|
| 1151 | SuperClassWriter::addAttribute("name", scalar->name.getValue(), &scalaId); |
---|
| 1152 | |
---|
| 1153 | if (!scalar->standard_name.isEmpty()) |
---|
| 1154 | SuperClassWriter::addAttribute("standard_name", scalar->standard_name.getValue(), &scalaId); |
---|
| 1155 | |
---|
| 1156 | if (!scalar->long_name.isEmpty()) |
---|
| 1157 | SuperClassWriter::addAttribute("long_name", scalar->long_name.getValue(), &scalaId); |
---|
| 1158 | |
---|
| 1159 | if (!scalar->unit.isEmpty()) |
---|
| 1160 | SuperClassWriter::addAttribute("units", scalar->unit.getValue(), &scalaId); |
---|
| 1161 | |
---|
| 1162 | SuperClassWriter::definition_end(); |
---|
| 1163 | |
---|
| 1164 | switch (SuperClass::type) |
---|
| 1165 | { |
---|
| 1166 | case MULTI_FILE: |
---|
| 1167 | { |
---|
| 1168 | CArray<double,1> scalarValue(scalarSize); |
---|
| 1169 | scalarValue(0) = scalar->value; |
---|
| 1170 | SuperClassWriter::writeData(scalarValue, scalaId, isCollective, 0); |
---|
| 1171 | SuperClassWriter::definition_start(); |
---|
| 1172 | |
---|
| 1173 | break; |
---|
| 1174 | } |
---|
| 1175 | case ONE_FILE: |
---|
| 1176 | { |
---|
| 1177 | CArray<double,1> scalarValue(scalarSize); |
---|
| 1178 | scalarValue(0) = scalar->value; |
---|
| 1179 | |
---|
| 1180 | std::vector<StdSize> start(1); |
---|
| 1181 | std::vector<StdSize> count(1); |
---|
| 1182 | start[0] = 0; |
---|
| 1183 | count[0] = 1; |
---|
| 1184 | SuperClassWriter::writeData(scalarValue, scalaId, isCollective, 0, &start, &count); |
---|
| 1185 | SuperClassWriter::definition_start(); |
---|
| 1186 | |
---|
| 1187 | break; |
---|
| 1188 | } |
---|
| 1189 | default : |
---|
| 1190 | ERROR("CNc4DataOutput::writeAxis_(CAxis* scalar)", |
---|
| 1191 | << "[ type = " << SuperClass::type << "]" |
---|
| 1192 | << " not implemented yet !"); |
---|
| 1193 | } |
---|
| 1194 | } |
---|
| 1195 | } |
---|
| 1196 | catch (CNetCdfException& e) |
---|
| 1197 | { |
---|
| 1198 | StdString msg("On writing the scalar : "); |
---|
| 1199 | msg.append(scalaId); msg.append("\n"); |
---|
| 1200 | msg.append("In the context : "); |
---|
| 1201 | CContext* context = CContext::getCurrent() ; |
---|
| 1202 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1203 | msg.append(e.what()); |
---|
| 1204 | ERROR("CNc4DataOutput::writeScalar_(CScalar* scalar)", << msg); |
---|
| 1205 | } |
---|
| 1206 | scalar->addRelFile(this->filename); |
---|
| 1207 | } |
---|
| 1208 | |
---|
[676] | 1209 | //-------------------------------------------------------------- |
---|
| 1210 | |
---|
| 1211 | void CNc4DataOutput::writeGridCompressed_(CGrid* grid) |
---|
| 1212 | { |
---|
| 1213 | if (grid->isScalarGrid() || grid->isWrittenCompressed(this->filename)) return; |
---|
| 1214 | |
---|
| 1215 | try |
---|
| 1216 | { |
---|
[887] | 1217 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[676] | 1218 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 1219 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
[887] | 1220 | std::vector<StdString> scalarList = grid->getScalarList(); |
---|
| 1221 | int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[676] | 1222 | |
---|
| 1223 | std::vector<StdString> dims; |
---|
| 1224 | |
---|
| 1225 | if (grid->isCompressible()) |
---|
| 1226 | { |
---|
| 1227 | StdString varId = grid->getId() + "_points"; |
---|
| 1228 | |
---|
| 1229 | int nbIndexes = (SuperClass::type == MULTI_FILE) ? grid->getNumberWrittenIndexes() : grid->getTotalNumberWrittenIndexes(); |
---|
| 1230 | SuperClassWriter::addDimension(varId, nbIndexes); |
---|
| 1231 | |
---|
| 1232 | dims.push_back(varId); |
---|
| 1233 | SuperClassWriter::addVariable(varId, NC_INT, dims); |
---|
| 1234 | |
---|
| 1235 | StdOStringStream compress; |
---|
| 1236 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 1237 | { |
---|
[887] | 1238 | if (2 == axisDomainOrder(i)) |
---|
[676] | 1239 | { |
---|
| 1240 | CDomain* domain = CDomain::get(domainList[domainList.size() - idxDomain - 1]); |
---|
[772] | 1241 | StdString domId = domain->getDomainOutputName(); |
---|
[676] | 1242 | StdString appendDomId = singleDomain ? "" : "_" + domId; |
---|
| 1243 | |
---|
| 1244 | switch (domain->type) |
---|
| 1245 | { |
---|
| 1246 | case CDomain::type_attr::curvilinear: |
---|
| 1247 | compress << "y" << appendDomId << " x" << appendDomId; |
---|
| 1248 | break; |
---|
| 1249 | case CDomain::type_attr::rectilinear: |
---|
| 1250 | compress << "lat" << appendDomId << " lon" << appendDomId; |
---|
| 1251 | break; |
---|
| 1252 | case CDomain::type_attr::unstructured: |
---|
| 1253 | compress << "cell" << appendDomId; |
---|
| 1254 | break; |
---|
| 1255 | } |
---|
| 1256 | ++idxDomain; |
---|
| 1257 | } |
---|
[887] | 1258 | else if (1 == axisDomainOrder(i)) |
---|
[676] | 1259 | { |
---|
| 1260 | CAxis* axis = CAxis::get(axisList[axisList.size() - idxAxis - 1]); |
---|
[772] | 1261 | compress << axis->getAxisOutputName(); |
---|
[676] | 1262 | ++idxAxis; |
---|
| 1263 | } |
---|
[887] | 1264 | else |
---|
| 1265 | { |
---|
| 1266 | CScalar* scalar = CScalar::get(scalarList[scalarList.size() - idxScalar - 1]); |
---|
| 1267 | compress << scalar->getScalarOutputName(); |
---|
| 1268 | ++idxScalar; |
---|
| 1269 | } |
---|
[676] | 1270 | |
---|
| 1271 | if (i != 0) compress << ' '; |
---|
| 1272 | } |
---|
| 1273 | SuperClassWriter::addAttribute("compress", compress.str(), &varId); |
---|
| 1274 | |
---|
| 1275 | grid->computeCompressedIndex(); |
---|
| 1276 | |
---|
| 1277 | CArray<int, 1> indexes(grid->getNumberWrittenIndexes()); |
---|
| 1278 | std::map<int, CArray<size_t, 1> >::const_iterator it; |
---|
| 1279 | for (it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
| 1280 | { |
---|
| 1281 | const CArray<size_t, 1> compressedIndexes = grid->compressedOutIndexFromClient[it->first]; |
---|
| 1282 | for (int i = 0; i < it->second.numElements(); i++) |
---|
| 1283 | indexes(compressedIndexes(i)) = it->second(i); |
---|
| 1284 | } |
---|
| 1285 | |
---|
| 1286 | switch (SuperClass::type) |
---|
| 1287 | { |
---|
| 1288 | case (MULTI_FILE): |
---|
| 1289 | { |
---|
| 1290 | SuperClassWriter::writeData(indexes, varId, isCollective, 0); |
---|
| 1291 | break; |
---|
| 1292 | } |
---|
| 1293 | case (ONE_FILE): |
---|
| 1294 | { |
---|
| 1295 | if (grid->doGridHaveDataDistributed()) |
---|
| 1296 | grid->getDistributionServer()->computeGlobalIndex(indexes); |
---|
| 1297 | |
---|
| 1298 | std::vector<StdSize> start, count; |
---|
| 1299 | start.push_back(grid->getOffsetWrittenIndexes()); |
---|
| 1300 | count.push_back(grid->getNumberWrittenIndexes()); |
---|
| 1301 | |
---|
| 1302 | SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count); |
---|
| 1303 | break; |
---|
| 1304 | } |
---|
| 1305 | } |
---|
| 1306 | } |
---|
| 1307 | else |
---|
| 1308 | { |
---|
| 1309 | for (int i = 0; i < numElement; ++i) |
---|
| 1310 | { |
---|
| 1311 | StdString varId, compress; |
---|
| 1312 | CArray<int, 1> indexes; |
---|
| 1313 | bool isDistributed; |
---|
| 1314 | StdSize nbIndexes, totalNbIndexes, offset; |
---|
| 1315 | int firstGlobalIndex; |
---|
| 1316 | |
---|
[887] | 1317 | if (2 == axisDomainOrder(i)) |
---|
[676] | 1318 | { |
---|
| 1319 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
[774] | 1320 | StdString domId = domain->getDomainOutputName(); |
---|
| 1321 | |
---|
[676] | 1322 | if (!domain->isCompressible() |
---|
| 1323 | || domain->type == CDomain::type_attr::unstructured |
---|
[774] | 1324 | || domain->isWrittenCompressed(this->filename) |
---|
| 1325 | || isWrittenCompressedDomain(domId)) |
---|
[676] | 1326 | continue; |
---|
| 1327 | |
---|
| 1328 | StdString appendDomId = singleDomain ? "" : "_" + domId; |
---|
| 1329 | |
---|
| 1330 | varId = domId + "_points"; |
---|
| 1331 | switch (domain->type) |
---|
| 1332 | { |
---|
| 1333 | case CDomain::type_attr::curvilinear: |
---|
| 1334 | compress = "y" + appendDomId + " x" + appendDomId; |
---|
| 1335 | break; |
---|
| 1336 | case CDomain::type_attr::rectilinear: |
---|
| 1337 | compress = "lat" + appendDomId + " lon" + appendDomId; |
---|
| 1338 | break; |
---|
| 1339 | } |
---|
| 1340 | |
---|
| 1341 | const std::vector<int>& indexesToWrite = domain->getIndexesToWrite(); |
---|
| 1342 | indexes.resize(indexesToWrite.size()); |
---|
| 1343 | for (int n = 0; n < indexes.numElements(); ++n) |
---|
| 1344 | indexes(n) = indexesToWrite[n]; |
---|
| 1345 | |
---|
| 1346 | isDistributed = domain->isDistributed(); |
---|
| 1347 | nbIndexes = domain->getNumberWrittenIndexes(); |
---|
| 1348 | totalNbIndexes = domain->getTotalNumberWrittenIndexes(); |
---|
| 1349 | offset = domain->getOffsetWrittenIndexes(); |
---|
| 1350 | firstGlobalIndex = domain->ibegin + domain->jbegin * domain->ni_glo; |
---|
| 1351 | |
---|
| 1352 | domain->addRelFileCompressed(this->filename); |
---|
[774] | 1353 | setWrittenCompressedDomain(domId); |
---|
[676] | 1354 | ++idxDomain; |
---|
| 1355 | } |
---|
[887] | 1356 | else if (1 == axisDomainOrder(i)) |
---|
[676] | 1357 | { |
---|
| 1358 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
[774] | 1359 | StdString axisId = axis->getAxisOutputName(); |
---|
| 1360 | |
---|
| 1361 | if (!axis->isCompressible() |
---|
| 1362 | || axis->isWrittenCompressed(this->filename) |
---|
| 1363 | || isWrittenCompressedAxis(axisId)) |
---|
[676] | 1364 | continue; |
---|
| 1365 | |
---|
| 1366 | varId = axisId + "_points"; |
---|
| 1367 | compress = axisId; |
---|
| 1368 | |
---|
| 1369 | const std::vector<int>& indexesToWrite = axis->getIndexesToWrite(); |
---|
| 1370 | indexes.resize(indexesToWrite.size()); |
---|
| 1371 | for (int n = 0; n < indexes.numElements(); ++n) |
---|
| 1372 | indexes(n) = indexesToWrite[n]; |
---|
| 1373 | |
---|
| 1374 | isDistributed = axis->isDistributed(); |
---|
| 1375 | nbIndexes = axis->getNumberWrittenIndexes(); |
---|
| 1376 | totalNbIndexes = axis->getTotalNumberWrittenIndexes(); |
---|
| 1377 | offset = axis->getOffsetWrittenIndexes(); |
---|
| 1378 | firstGlobalIndex = axis->begin; |
---|
| 1379 | |
---|
| 1380 | axis->addRelFileCompressed(this->filename); |
---|
[774] | 1381 | setWrittenCompressedAxis(axisId); |
---|
[676] | 1382 | ++idxAxis; |
---|
| 1383 | } |
---|
[887] | 1384 | else |
---|
| 1385 | { |
---|
| 1386 | } |
---|
[676] | 1387 | |
---|
| 1388 | if (!varId.empty()) |
---|
| 1389 | { |
---|
| 1390 | SuperClassWriter::addDimension(varId, (SuperClass::type == MULTI_FILE) ? nbIndexes : totalNbIndexes); |
---|
| 1391 | |
---|
| 1392 | dims.clear(); |
---|
| 1393 | dims.push_back(varId); |
---|
| 1394 | SuperClassWriter::addVariable(varId, NC_INT, dims); |
---|
| 1395 | |
---|
| 1396 | SuperClassWriter::addAttribute("compress", compress, &varId); |
---|
| 1397 | |
---|
| 1398 | switch (SuperClass::type) |
---|
| 1399 | { |
---|
| 1400 | case (MULTI_FILE): |
---|
| 1401 | { |
---|
| 1402 | indexes -= firstGlobalIndex; |
---|
| 1403 | SuperClassWriter::writeData(indexes, varId, isCollective, 0); |
---|
| 1404 | break; |
---|
| 1405 | } |
---|
| 1406 | case (ONE_FILE): |
---|
| 1407 | { |
---|
| 1408 | std::vector<StdSize> start, count; |
---|
| 1409 | start.push_back(offset); |
---|
| 1410 | count.push_back(nbIndexes); |
---|
| 1411 | |
---|
| 1412 | SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count); |
---|
| 1413 | break; |
---|
| 1414 | } |
---|
| 1415 | } |
---|
| 1416 | } |
---|
| 1417 | } |
---|
| 1418 | |
---|
| 1419 | if (!dims.empty()) |
---|
| 1420 | grid->computeCompressedIndex(); |
---|
| 1421 | } |
---|
| 1422 | |
---|
| 1423 | grid->addRelFileCompressed(this->filename); |
---|
| 1424 | } |
---|
| 1425 | catch (CNetCdfException& e) |
---|
| 1426 | { |
---|
| 1427 | StdString msg("On writing compressed grid : "); |
---|
| 1428 | msg.append(grid->getId()); msg.append("\n"); |
---|
| 1429 | msg.append("In the context : "); |
---|
| 1430 | CContext* context = CContext::getCurrent(); |
---|
| 1431 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1432 | msg.append(e.what()); |
---|
| 1433 | ERROR("CNc4DataOutput::writeGridCompressed_(CGrid* grid)", << msg); |
---|
| 1434 | } |
---|
| 1435 | } |
---|
| 1436 | |
---|
| 1437 | //-------------------------------------------------------------- |
---|
| 1438 | |
---|
[391] | 1439 | void CNc4DataOutput::writeTimeDimension_(void) |
---|
| 1440 | { |
---|
[498] | 1441 | try |
---|
| 1442 | { |
---|
[802] | 1443 | SuperClassWriter::addDimension(getTimeCounterName()); |
---|
[498] | 1444 | } |
---|
| 1445 | catch (CNetCdfException& e) |
---|
| 1446 | { |
---|
[614] | 1447 | StdString msg("On writing time dimension : time_couter\n"); |
---|
[498] | 1448 | msg.append("In the context : "); |
---|
| 1449 | CContext* context = CContext::getCurrent() ; |
---|
| 1450 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1451 | msg.append(e.what()); |
---|
| 1452 | ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg); |
---|
| 1453 | } |
---|
[391] | 1454 | } |
---|
[676] | 1455 | |
---|
[219] | 1456 | //-------------------------------------------------------------- |
---|
| 1457 | |
---|
[347] | 1458 | void CNc4DataOutput::writeField_(CField* field) |
---|
[219] | 1459 | { |
---|
[347] | 1460 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 1461 | CContextServer* server=context->server ; |
---|
| 1462 | |
---|
[219] | 1463 | std::vector<StdString> dims, coodinates; |
---|
[347] | 1464 | CGrid* grid = field->grid; |
---|
[567] | 1465 | if (!grid->doGridHaveDataToWrite()) |
---|
| 1466 | if (SuperClass::type==MULTI_FILE) return ; |
---|
[488] | 1467 | |
---|
[887] | 1468 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
| 1469 | int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[567] | 1470 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 1471 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
[887] | 1472 | std::vector<StdString> scalarList = grid->getScalarList(); |
---|
[219] | 1473 | |
---|
[802] | 1474 | StdString timeid = getTimeCounterName(); |
---|
[567] | 1475 | StdString dimXid,dimYid; |
---|
| 1476 | std::deque<StdString> dimIdList, dimCoordList; |
---|
[611] | 1477 | bool hasArea = false; |
---|
| 1478 | StdString cellMeasures = "area:"; |
---|
[676] | 1479 | bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output; |
---|
[488] | 1480 | |
---|
[567] | 1481 | for (int i = 0; i < numElement; ++i) |
---|
[434] | 1482 | { |
---|
[887] | 1483 | if (2 == axisDomainOrder(i)) |
---|
[567] | 1484 | { |
---|
| 1485 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
[772] | 1486 | StdString domId = domain->getDomainOutputName(); |
---|
[676] | 1487 | StdString appendDomId = singleDomain ? "" : "_" + domId ; |
---|
| 1488 | |
---|
| 1489 | if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured) |
---|
| 1490 | { |
---|
| 1491 | dimIdList.push_back(domId + "_points"); |
---|
| 1492 | field->setUseCompressedOutput(); |
---|
| 1493 | } |
---|
| 1494 | |
---|
[567] | 1495 | switch (domain->type) |
---|
| 1496 | { |
---|
[676] | 1497 | case CDomain::type_attr::curvilinear: |
---|
| 1498 | if (!compressedOutput || !domain->isCompressible()) |
---|
| 1499 | { |
---|
| 1500 | dimXid = StdString("x").append(appendDomId); |
---|
| 1501 | dimIdList.push_back(dimXid); |
---|
| 1502 | dimYid = StdString("y").append(appendDomId); |
---|
| 1503 | dimIdList.push_back(dimYid); |
---|
| 1504 | } |
---|
| 1505 | dimCoordList.push_back(StdString("nav_lon").append(appendDomId)); |
---|
| 1506 | dimCoordList.push_back(StdString("nav_lat").append(appendDomId)); |
---|
[567] | 1507 | break ; |
---|
[676] | 1508 | case CDomain::type_attr::rectilinear: |
---|
| 1509 | if (!compressedOutput || !domain->isCompressible()) |
---|
| 1510 | { |
---|
| 1511 | dimXid = StdString("lon").append(appendDomId); |
---|
| 1512 | dimIdList.push_back(dimXid); |
---|
| 1513 | dimYid = StdString("lat").append(appendDomId); |
---|
| 1514 | dimIdList.push_back(dimYid); |
---|
| 1515 | } |
---|
[567] | 1516 | break ; |
---|
[676] | 1517 | case CDomain::type_attr::unstructured: |
---|
[878] | 1518 | { |
---|
[879] | 1519 | if (SuperClassWriter::useCFConvention) |
---|
| 1520 | { |
---|
| 1521 | dimXid = StdString("cell").append(appendDomId); |
---|
| 1522 | dimIdList.push_back(dimXid); |
---|
| 1523 | dimCoordList.push_back(StdString("lon").append(appendDomId)); |
---|
| 1524 | dimCoordList.push_back(StdString("lat").append(appendDomId)); |
---|
| 1525 | } |
---|
| 1526 | else |
---|
| 1527 | { |
---|
| 1528 | StdString domainName = domain->name; |
---|
| 1529 | if (domain->nvertex == 1) |
---|
| 1530 | { |
---|
| 1531 | dimXid = "n" + domainName + "_node"; |
---|
| 1532 | dimIdList.push_back(dimXid); |
---|
| 1533 | dimCoordList.push_back(StdString(domainName + "_node_x")); |
---|
| 1534 | dimCoordList.push_back(StdString(domainName + "_node_y")); |
---|
| 1535 | } |
---|
| 1536 | else if (domain->nvertex == 2) |
---|
| 1537 | { |
---|
| 1538 | dimXid = "n" + domainName + "_edge"; |
---|
| 1539 | dimIdList.push_back(dimXid); |
---|
| 1540 | dimCoordList.push_back(StdString(domainName + "_edge_x")); |
---|
| 1541 | dimCoordList.push_back(StdString(domainName + "_edge_y")); |
---|
| 1542 | } |
---|
| 1543 | else |
---|
| 1544 | { |
---|
| 1545 | dimXid = "n" + domainName + "_face"; |
---|
| 1546 | dimIdList.push_back(dimXid); |
---|
| 1547 | dimCoordList.push_back(StdString(domainName + "_face_x")); |
---|
| 1548 | dimCoordList.push_back(StdString(domainName + "_face_y")); |
---|
| 1549 | } |
---|
| 1550 | } // ugrid convention |
---|
| 1551 | } // case unstructured domain |
---|
[676] | 1552 | } |
---|
[878] | 1553 | |
---|
[676] | 1554 | if (domain->hasArea) |
---|
| 1555 | { |
---|
| 1556 | hasArea = true; |
---|
| 1557 | cellMeasures += " area" + appendDomId; |
---|
| 1558 | } |
---|
| 1559 | ++idxDomain; |
---|
[567] | 1560 | } |
---|
[887] | 1561 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 1562 | { |
---|
| 1563 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
[772] | 1564 | StdString axisId = axis->getAxisOutputName(); |
---|
[676] | 1565 | |
---|
| 1566 | if (compressedOutput && axis->isCompressible()) |
---|
| 1567 | { |
---|
| 1568 | dimIdList.push_back(axisId + "_points"); |
---|
| 1569 | field->setUseCompressedOutput(); |
---|
| 1570 | } |
---|
| 1571 | else |
---|
| 1572 | dimIdList.push_back(axisId); |
---|
| 1573 | |
---|
| 1574 | dimCoordList.push_back(axisId); |
---|
| 1575 | ++idxAxis; |
---|
[567] | 1576 | } |
---|
[887] | 1577 | else // scalar |
---|
| 1578 | { |
---|
| 1579 | /* Do nothing here */ |
---|
| 1580 | } |
---|
[567] | 1581 | } |
---|
[488] | 1582 | |
---|
| 1583 | /* |
---|
[300] | 1584 | StdString lonid_loc = (server->intraCommSize > 1) |
---|
[318] | 1585 | ? StdString("lon").append(appendDomid).append("_local") |
---|
[278] | 1586 | : lonid; |
---|
[300] | 1587 | StdString latid_loc = (server->intraCommSize > 1) |
---|
[318] | 1588 | ? StdString("lat").append(appendDomid).append("_local") |
---|
[278] | 1589 | : latid; |
---|
[391] | 1590 | */ |
---|
[770] | 1591 | StdString fieldid = field->getFieldOutputName(); |
---|
[219] | 1592 | |
---|
[464] | 1593 | nc_type type ; |
---|
| 1594 | if (field->prec.isEmpty()) type = NC_FLOAT ; |
---|
| 1595 | else |
---|
| 1596 | { |
---|
| 1597 | if (field->prec==2) type = NC_SHORT ; |
---|
| 1598 | else if (field->prec==4) type = NC_FLOAT ; |
---|
[488] | 1599 | else if (field->prec==8) type = NC_DOUBLE ; |
---|
[464] | 1600 | } |
---|
[488] | 1601 | |
---|
[645] | 1602 | bool wtime = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once); |
---|
[488] | 1603 | |
---|
[219] | 1604 | if (wtime) |
---|
| 1605 | { |
---|
[488] | 1606 | |
---|
[449] | 1607 | //StdOStringStream oss; |
---|
| 1608 | // oss << "time_" << field->operation.getValue() |
---|
| 1609 | // << "_" << field->getRelFile()->output_freq.getValue(); |
---|
[488] | 1610 | //oss |
---|
[645] | 1611 | if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant")); |
---|
| 1612 | else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered")); |
---|
[219] | 1613 | dims.push_back(timeid); |
---|
| 1614 | } |
---|
| 1615 | |
---|
[676] | 1616 | if (compressedOutput && grid->isCompressible()) |
---|
[219] | 1617 | { |
---|
[676] | 1618 | dims.push_back(grid->getId() + "_points"); |
---|
| 1619 | field->setUseCompressedOutput(); |
---|
[219] | 1620 | } |
---|
[676] | 1621 | else |
---|
| 1622 | { |
---|
| 1623 | while (!dimIdList.empty()) |
---|
| 1624 | { |
---|
| 1625 | dims.push_back(dimIdList.back()); |
---|
| 1626 | dimIdList.pop_back(); |
---|
| 1627 | } |
---|
| 1628 | } |
---|
[219] | 1629 | |
---|
[567] | 1630 | while (!dimCoordList.empty()) |
---|
[219] | 1631 | { |
---|
[567] | 1632 | coodinates.push_back(dimCoordList.back()); |
---|
| 1633 | dimCoordList.pop_back(); |
---|
[219] | 1634 | } |
---|
| 1635 | |
---|
[498] | 1636 | try |
---|
| 1637 | { |
---|
| 1638 | SuperClassWriter::addVariable(fieldid, type, dims); |
---|
[488] | 1639 | |
---|
[498] | 1640 | if (!field->standard_name.isEmpty()) |
---|
| 1641 | SuperClassWriter::addAttribute |
---|
| 1642 | ("standard_name", field->standard_name.getValue(), &fieldid); |
---|
[219] | 1643 | |
---|
[498] | 1644 | if (!field->long_name.isEmpty()) |
---|
| 1645 | SuperClassWriter::addAttribute |
---|
| 1646 | ("long_name", field->long_name.getValue(), &fieldid); |
---|
[219] | 1647 | |
---|
[498] | 1648 | if (!field->unit.isEmpty()) |
---|
| 1649 | SuperClassWriter::addAttribute |
---|
| 1650 | ("units", field->unit.getValue(), &fieldid); |
---|
[463] | 1651 | |
---|
[498] | 1652 | if (!field->valid_min.isEmpty()) |
---|
| 1653 | SuperClassWriter::addAttribute |
---|
| 1654 | ("valid_min", field->valid_min.getValue(), &fieldid); |
---|
[463] | 1655 | |
---|
[498] | 1656 | if (!field->valid_max.isEmpty()) |
---|
| 1657 | SuperClassWriter::addAttribute |
---|
| 1658 | ("valid_max", field->valid_max.getValue(), &fieldid); |
---|
[464] | 1659 | |
---|
[498] | 1660 | if (!field->scale_factor.isEmpty()) |
---|
| 1661 | SuperClassWriter::addAttribute |
---|
| 1662 | ("scale_factor", field->scale_factor.getValue(), &fieldid); |
---|
[464] | 1663 | |
---|
[498] | 1664 | if (!field->add_offset.isEmpty()) |
---|
| 1665 | SuperClassWriter::addAttribute |
---|
| 1666 | ("add_offset", field->add_offset.getValue(), &fieldid); |
---|
[488] | 1667 | |
---|
[498] | 1668 | SuperClassWriter::addAttribute |
---|
| 1669 | ("online_operation", field->operation.getValue(), &fieldid); |
---|
[472] | 1670 | |
---|
[498] | 1671 | // write child variables as attributes |
---|
[488] | 1672 | |
---|
| 1673 | |
---|
[498] | 1674 | vector<CVariable*> listVars = field->getAllVariables() ; |
---|
| 1675 | for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ; |
---|
[472] | 1676 | |
---|
[488] | 1677 | |
---|
[498] | 1678 | if (wtime) |
---|
| 1679 | { |
---|
[614] | 1680 | CDuration freqOp = field->freq_op.getValue(); |
---|
| 1681 | freqOp.solveTimeStep(*context->calendar); |
---|
| 1682 | StdString freqOpStr = freqOp.toStringUDUnits(); |
---|
[612] | 1683 | SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid); |
---|
[437] | 1684 | |
---|
[614] | 1685 | CDuration freqOut = field->getRelFile()->output_freq.getValue(); |
---|
| 1686 | freqOut.solveTimeStep(*context->calendar); |
---|
| 1687 | SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid); |
---|
[612] | 1688 | |
---|
[618] | 1689 | StdString cellMethods = "time: "; |
---|
[612] | 1690 | if (field->operation.getValue() == "instant") cellMethods += "point"; |
---|
| 1691 | else if (field->operation.getValue() == "average") cellMethods += "mean"; |
---|
| 1692 | else if (field->operation.getValue() == "accumulate") cellMethods += "sum"; |
---|
| 1693 | else cellMethods += field->operation; |
---|
[614] | 1694 | if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar)) |
---|
| 1695 | cellMethods += " (interval: " + freqOpStr + ")"; |
---|
[612] | 1696 | SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid); |
---|
[498] | 1697 | } |
---|
[488] | 1698 | |
---|
[611] | 1699 | if (hasArea) |
---|
| 1700 | SuperClassWriter::addAttribute("cell_measures", cellMeasures, &fieldid); |
---|
| 1701 | |
---|
[498] | 1702 | if (!field->default_value.isEmpty()) |
---|
| 1703 | { |
---|
| 1704 | double default_value = field->default_value.getValue(); |
---|
| 1705 | float fdefault_value = (float)default_value; |
---|
| 1706 | if (type == NC_DOUBLE) |
---|
| 1707 | SuperClassWriter::setDefaultValue(fieldid, &default_value); |
---|
| 1708 | else |
---|
| 1709 | SuperClassWriter::setDefaultValue(fieldid, &fdefault_value); |
---|
| 1710 | } |
---|
| 1711 | else |
---|
[517] | 1712 | SuperClassWriter::setDefaultValue(fieldid, (double*)NULL); |
---|
[219] | 1713 | |
---|
[606] | 1714 | if (field->compression_level.isEmpty()) |
---|
| 1715 | field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level; |
---|
| 1716 | SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); |
---|
| 1717 | |
---|
[878] | 1718 | { // Ecriture des coordonnes |
---|
[488] | 1719 | |
---|
[498] | 1720 | StdString coordstr; //boost::algorithm::join(coodinates, " ") |
---|
| 1721 | std::vector<StdString>::iterator |
---|
| 1722 | itc = coodinates.begin(), endc = coodinates.end(); |
---|
[488] | 1723 | |
---|
[498] | 1724 | for (; itc!= endc; itc++) |
---|
| 1725 | { |
---|
| 1726 | StdString & coord = *itc; |
---|
| 1727 | if (itc+1 != endc) |
---|
| 1728 | coordstr.append(coord).append(" "); |
---|
| 1729 | else coordstr.append(coord); |
---|
| 1730 | } |
---|
[219] | 1731 | |
---|
[498] | 1732 | SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid); |
---|
[219] | 1733 | |
---|
[498] | 1734 | } |
---|
[219] | 1735 | } |
---|
[498] | 1736 | catch (CNetCdfException& e) |
---|
| 1737 | { |
---|
| 1738 | StdString msg("On writing field : "); |
---|
| 1739 | msg.append(fieldid); msg.append("\n"); |
---|
| 1740 | msg.append("In the context : "); |
---|
| 1741 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1742 | msg.append(e.what()); |
---|
| 1743 | ERROR("CNc4DataOutput::writeField_(CField* field)", << msg); |
---|
| 1744 | } |
---|
[879] | 1745 | } // writeField_() |
---|
[219] | 1746 | |
---|
| 1747 | //-------------------------------------------------------------- |
---|
| 1748 | |
---|
[347] | 1749 | void CNc4DataOutput::writeFile_ (CFile* file) |
---|
[219] | 1750 | { |
---|
[773] | 1751 | StdString filename = file->getFileOutputName(); |
---|
[219] | 1752 | StdString description = (!file->description.isEmpty()) |
---|
| 1753 | ? file->description.getValue() |
---|
[335] | 1754 | : StdString("Created by xios"); |
---|
[609] | 1755 | |
---|
| 1756 | singleDomain = (file->nbDomains == 1); |
---|
| 1757 | |
---|
[498] | 1758 | try |
---|
| 1759 | { |
---|
[879] | 1760 | if (SuperClassWriter::useCFConvention) |
---|
[878] | 1761 | this->writeFileAttributes(filename, description, |
---|
| 1762 | StdString("CF-1.5"), |
---|
| 1763 | StdString("An IPSL model"), |
---|
| 1764 | this->getTimeStamp()); |
---|
| 1765 | else |
---|
| 1766 | this->writeFileAttributes(filename, description, |
---|
| 1767 | StdString("UGRID"), |
---|
| 1768 | StdString("An IPSL model"), |
---|
| 1769 | this->getTimeStamp()); |
---|
[609] | 1770 | |
---|
[878] | 1771 | |
---|
[701] | 1772 | if (!appendMode) |
---|
| 1773 | SuperClassWriter::addDimension("axis_nbounds", 2); |
---|
[498] | 1774 | } |
---|
| 1775 | catch (CNetCdfException& e) |
---|
| 1776 | { |
---|
| 1777 | StdString msg("On writing file : "); |
---|
| 1778 | msg.append(filename); msg.append("\n"); |
---|
| 1779 | msg.append("In the context : "); |
---|
| 1780 | CContext* context = CContext::getCurrent() ; |
---|
| 1781 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1782 | msg.append(e.what()); |
---|
| 1783 | ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg); |
---|
| 1784 | } |
---|
[219] | 1785 | } |
---|
[488] | 1786 | |
---|
[472] | 1787 | void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId) |
---|
| 1788 | { |
---|
[773] | 1789 | StdString name = var->getVariableOutputName(); |
---|
[488] | 1790 | |
---|
[498] | 1791 | try |
---|
| 1792 | { |
---|
[527] | 1793 | if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32) |
---|
| 1794 | addAttribute(name, var->getData<int>(), &fieldId); |
---|
| 1795 | else if (var->type.getValue() == CVariable::type_attr::t_int16) |
---|
| 1796 | addAttribute(name, var->getData<short int>(), &fieldId); |
---|
| 1797 | else if (var->type.getValue() == CVariable::type_attr::t_float) |
---|
| 1798 | addAttribute(name, var->getData<float>(), &fieldId); |
---|
| 1799 | else if (var->type.getValue() == CVariable::type_attr::t_double) |
---|
| 1800 | addAttribute(name, var->getData<double>(), &fieldId); |
---|
| 1801 | else if (var->type.getValue() == CVariable::type_attr::t_string) |
---|
| 1802 | addAttribute(name, var->getData<string>(), &fieldId); |
---|
| 1803 | else |
---|
| 1804 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", |
---|
| 1805 | << "Unsupported variable of type " << var->type.getStringValue()); |
---|
[498] | 1806 | } |
---|
| 1807 | catch (CNetCdfException& e) |
---|
| 1808 | { |
---|
| 1809 | StdString msg("On writing attributes of variable with name : "); |
---|
| 1810 | msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n"); |
---|
| 1811 | msg.append("In the context : "); |
---|
| 1812 | CContext* context = CContext::getCurrent() ; |
---|
| 1813 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1814 | msg.append(e.what()); |
---|
| 1815 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg); |
---|
| 1816 | } |
---|
[472] | 1817 | } |
---|
[488] | 1818 | |
---|
[472] | 1819 | void CNc4DataOutput::writeAttribute_ (CVariable* var) |
---|
| 1820 | { |
---|
[773] | 1821 | StdString name = var->getVariableOutputName(); |
---|
| 1822 | |
---|
[498] | 1823 | try |
---|
| 1824 | { |
---|
[527] | 1825 | if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32) |
---|
| 1826 | addAttribute(name, var->getData<int>()); |
---|
| 1827 | else if (var->type.getValue() == CVariable::type_attr::t_int16) |
---|
| 1828 | addAttribute(name, var->getData<short int>()); |
---|
| 1829 | else if (var->type.getValue() == CVariable::type_attr::t_float) |
---|
| 1830 | addAttribute(name, var->getData<float>()); |
---|
| 1831 | else if (var->type.getValue() == CVariable::type_attr::t_double) |
---|
| 1832 | addAttribute(name, var->getData<double>()); |
---|
| 1833 | else if (var->type.getValue() == CVariable::type_attr::t_string) |
---|
| 1834 | addAttribute(name, var->getData<string>()); |
---|
| 1835 | else |
---|
| 1836 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", |
---|
| 1837 | << "Unsupported variable of type " << var->type.getStringValue()); |
---|
[498] | 1838 | } |
---|
| 1839 | catch (CNetCdfException& e) |
---|
| 1840 | { |
---|
| 1841 | StdString msg("On writing attributes of variable with name : "); |
---|
| 1842 | msg.append(name); msg.append("\n"); |
---|
| 1843 | msg.append("In the context : "); |
---|
| 1844 | CContext* context = CContext::getCurrent() ; |
---|
| 1845 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1846 | msg.append(e.what()); |
---|
| 1847 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg); |
---|
| 1848 | } |
---|
[488] | 1849 | } |
---|
| 1850 | |
---|
[321] | 1851 | void CNc4DataOutput::syncFile_ (void) |
---|
| 1852 | { |
---|
[498] | 1853 | try |
---|
| 1854 | { |
---|
| 1855 | SuperClassWriter::sync() ; |
---|
| 1856 | } |
---|
| 1857 | catch (CNetCdfException& e) |
---|
| 1858 | { |
---|
| 1859 | StdString msg("On synchronizing the write among processes"); |
---|
| 1860 | msg.append("In the context : "); |
---|
| 1861 | CContext* context = CContext::getCurrent() ; |
---|
| 1862 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1863 | msg.append(e.what()); |
---|
| 1864 | ERROR("CNc4DataOutput::syncFile_ (void)", << msg); |
---|
| 1865 | } |
---|
[321] | 1866 | } |
---|
[219] | 1867 | |
---|
[286] | 1868 | void CNc4DataOutput::closeFile_ (void) |
---|
| 1869 | { |
---|
[498] | 1870 | try |
---|
| 1871 | { |
---|
| 1872 | SuperClassWriter::close() ; |
---|
| 1873 | } |
---|
| 1874 | catch (CNetCdfException& e) |
---|
| 1875 | { |
---|
| 1876 | StdString msg("On closing file"); |
---|
| 1877 | msg.append("In the context : "); |
---|
| 1878 | CContext* context = CContext::getCurrent() ; |
---|
| 1879 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1880 | msg.append(e.what()); |
---|
| 1881 | ERROR("CNc4DataOutput::syncFile_ (void)", << msg); |
---|
| 1882 | } |
---|
| 1883 | |
---|
[286] | 1884 | } |
---|
| 1885 | |
---|
[219] | 1886 | //--------------------------------------------------------------- |
---|
| 1887 | |
---|
| 1888 | StdString CNc4DataOutput::getTimeStamp(void) const |
---|
| 1889 | { |
---|
| 1890 | const int buffer_size = 100; |
---|
| 1891 | time_t rawtime; |
---|
| 1892 | struct tm * timeinfo = NULL; |
---|
| 1893 | char buffer [buffer_size]; |
---|
| 1894 | |
---|
| 1895 | time ( &rawtime ); |
---|
| 1896 | timeinfo = localtime ( &rawtime ); |
---|
| 1897 | strftime (buffer, buffer_size, "%Y-%b-%d %H:%M:%S %Z", timeinfo); |
---|
| 1898 | |
---|
| 1899 | return (StdString(buffer)); |
---|
| 1900 | } |
---|
[488] | 1901 | |
---|
[219] | 1902 | //--------------------------------------------------------------- |
---|
[488] | 1903 | |
---|
[347] | 1904 | void CNc4DataOutput::writeFieldData_ (CField* field) |
---|
[219] | 1905 | { |
---|
[707] | 1906 | CContext* context = CContext::getCurrent(); |
---|
| 1907 | CContextServer* server = context->server; |
---|
| 1908 | CGrid* grid = field->grid; |
---|
[300] | 1909 | |
---|
[707] | 1910 | if (!grid->doGridHaveDataToWrite()) |
---|
| 1911 | if (SuperClass::type == MULTI_FILE || !isCollective) return; |
---|
[488] | 1912 | |
---|
[770] | 1913 | StdString fieldid = field->getFieldOutputName(); |
---|
[286] | 1914 | |
---|
[707] | 1915 | StdOStringStream oss; |
---|
| 1916 | string timeAxisId; |
---|
| 1917 | if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisId = "time_instant"; |
---|
| 1918 | else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisId = "time_centered"; |
---|
[488] | 1919 | |
---|
[802] | 1920 | StdString timeBoundId = getTimeCounterName() + "_bounds"; |
---|
[449] | 1921 | |
---|
[707] | 1922 | StdString timeAxisBoundId; |
---|
| 1923 | if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisBoundId = "time_instant_bounds"; |
---|
| 1924 | else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisBoundId = "time_centered_bounds"; |
---|
[488] | 1925 | |
---|
[707] | 1926 | if (!field->wasWritten()) |
---|
| 1927 | { |
---|
[757] | 1928 | if (appendMode && field->file->record_offset.isEmpty()) |
---|
[707] | 1929 | { |
---|
| 1930 | field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1); |
---|
| 1931 | } |
---|
[488] | 1932 | |
---|
[707] | 1933 | field->setWritten(); |
---|
| 1934 | } |
---|
[488] | 1935 | |
---|
| 1936 | |
---|
[707] | 1937 | CArray<double,1> time_data(1); |
---|
| 1938 | CArray<double,1> time_data_bound(2); |
---|
| 1939 | CArray<double,1> time_counter(1); |
---|
| 1940 | CArray<double,1> time_counter_bound(2); |
---|
| 1941 | |
---|
| 1942 | bool wtime = (field->getOperationTimeType() != func::CFunctor::once); |
---|
| 1943 | |
---|
[444] | 1944 | if (wtime) |
---|
| 1945 | { |
---|
[692] | 1946 | Time lastWrite = field->last_Write_srv; |
---|
| 1947 | Time lastLastWrite = field->lastlast_Write_srv; |
---|
| 1948 | |
---|
[645] | 1949 | if (field->getOperationTimeType() == func::CFunctor::instant) |
---|
[692] | 1950 | time_data(0) = lastWrite; |
---|
| 1951 | else if (field->getOperationTimeType() == func::CFunctor::centered) |
---|
| 1952 | time_data(0) = (lastWrite + lastLastWrite) / 2; |
---|
[488] | 1953 | |
---|
[645] | 1954 | if (field->getOperationTimeType() == func::CFunctor::instant) |
---|
[692] | 1955 | time_data_bound(0) = time_data_bound(1) = lastWrite; |
---|
[645] | 1956 | else if (field->getOperationTimeType() == func::CFunctor::centered) |
---|
[488] | 1957 | { |
---|
[692] | 1958 | time_data_bound(0) = lastLastWrite; |
---|
| 1959 | time_data_bound(1) = lastWrite; |
---|
[488] | 1960 | } |
---|
| 1961 | |
---|
[692] | 1962 | if (field->file->time_counter == CFile::time_counter_attr::instant) |
---|
| 1963 | time_counter(0) = lastWrite; |
---|
| 1964 | else if (field->file->time_counter == CFile::time_counter_attr::centered) |
---|
| 1965 | time_counter(0) = (lastWrite + lastLastWrite) / 2; |
---|
| 1966 | else if (field->file->time_counter == CFile::time_counter_attr::record) |
---|
| 1967 | time_counter(0) = field->getNStep() - 1; |
---|
| 1968 | |
---|
| 1969 | |
---|
| 1970 | if (field->file->time_counter == CFile::time_counter_attr::instant) |
---|
| 1971 | time_counter_bound(0) = time_counter_bound(1) = lastWrite; |
---|
| 1972 | else if (field->file->time_counter == CFile::time_counter_attr::centered) |
---|
| 1973 | { |
---|
| 1974 | time_counter_bound(0) = lastLastWrite; |
---|
| 1975 | time_counter_bound(1) = lastWrite; |
---|
| 1976 | } |
---|
| 1977 | else if (field->file->time_counter == CFile::time_counter_attr::record) |
---|
| 1978 | time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1; |
---|
| 1979 | } |
---|
| 1980 | |
---|
[707] | 1981 | bool isRoot = (server->intraCommRank == 0); |
---|
[488] | 1982 | |
---|
[464] | 1983 | if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) |
---|
| 1984 | { |
---|
[707] | 1985 | double scaleFactor = 1.0; |
---|
| 1986 | double addOffset = 0.0; |
---|
| 1987 | if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor; |
---|
| 1988 | if (!field->add_offset.isEmpty()) addOffset = field->add_offset; |
---|
| 1989 | field->scaleFactorAddOffset(scaleFactor, addOffset); |
---|
[464] | 1990 | } |
---|
[488] | 1991 | |
---|
[498] | 1992 | try |
---|
[219] | 1993 | { |
---|
[676] | 1994 | size_t writtenSize; |
---|
| 1995 | if (field->getUseCompressedOutput()) |
---|
| 1996 | writtenSize = grid->getNumberWrittenIndexes(); |
---|
| 1997 | else |
---|
| 1998 | writtenSize = grid->getWrittenDataSize(); |
---|
| 1999 | |
---|
| 2000 | CArray<double,1> fieldData(writtenSize); |
---|
[567] | 2001 | if (!field->default_value.isEmpty()) fieldData = field->default_value; |
---|
[676] | 2002 | |
---|
| 2003 | if (field->getUseCompressedOutput()) |
---|
| 2004 | field->outputCompressedField(fieldData); |
---|
| 2005 | else |
---|
| 2006 | field->outputField(fieldData); |
---|
| 2007 | |
---|
[707] | 2008 | if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); |
---|
[567] | 2009 | |
---|
| 2010 | switch (SuperClass::type) |
---|
[498] | 2011 | { |
---|
[567] | 2012 | case (MULTI_FILE) : |
---|
| 2013 | { |
---|
[692] | 2014 | SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1); |
---|
[567] | 2015 | if (wtime) |
---|
| 2016 | { |
---|
[692] | 2017 | SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1); |
---|
| 2018 | SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1); |
---|
| 2019 | if (field->file->time_counter != CFile::time_counter_attr::none) |
---|
| 2020 | { |
---|
[802] | 2021 | SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1); |
---|
[692] | 2022 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
| 2023 | SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1); |
---|
| 2024 | } |
---|
[567] | 2025 | } |
---|
[707] | 2026 | break; |
---|
[567] | 2027 | } |
---|
| 2028 | case (ONE_FILE) : |
---|
| 2029 | { |
---|
[676] | 2030 | const std::vector<int>& nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal(); |
---|
| 2031 | const std::vector<int>& nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer(); |
---|
| 2032 | const std::vector<int>& nZoomSizeServer = grid->getDistributionServer()->getZoomSizeServer(); |
---|
[464] | 2033 | |
---|
[676] | 2034 | std::vector<StdSize> start, count; |
---|
[464] | 2035 | |
---|
[676] | 2036 | if (field->getUseCompressedOutput()) |
---|
| 2037 | { |
---|
| 2038 | if (grid->isCompressible()) |
---|
| 2039 | { |
---|
| 2040 | start.push_back(grid->getOffsetWrittenIndexes()); |
---|
| 2041 | count.push_back(grid->getNumberWrittenIndexes()); |
---|
| 2042 | } |
---|
| 2043 | else |
---|
| 2044 | { |
---|
[887] | 2045 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[676] | 2046 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 2047 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
| 2048 | int numElement = axisDomainOrder.numElements(); |
---|
| 2049 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1; |
---|
| 2050 | int idx = nZoomBeginGlobal.size() - 1; |
---|
[464] | 2051 | |
---|
[676] | 2052 | start.reserve(nZoomBeginGlobal.size()); |
---|
| 2053 | count.reserve(nZoomBeginGlobal.size()); |
---|
| 2054 | |
---|
| 2055 | |
---|
| 2056 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 2057 | { |
---|
[887] | 2058 | if (2 == axisDomainOrder(i)) |
---|
[676] | 2059 | { |
---|
| 2060 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
| 2061 | |
---|
| 2062 | if (domain->isCompressible()) |
---|
| 2063 | { |
---|
| 2064 | start.push_back(domain->getOffsetWrittenIndexes()); |
---|
| 2065 | count.push_back(domain->getNumberWrittenIndexes()); |
---|
[710] | 2066 | idx -= 2; |
---|
[676] | 2067 | } |
---|
| 2068 | else |
---|
| 2069 | { |
---|
[710] | 2070 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
| 2071 | { |
---|
| 2072 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
| 2073 | count.push_back(nZoomSizeServer[idx]); |
---|
| 2074 | } |
---|
| 2075 | --idx; |
---|
[676] | 2076 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
| 2077 | count.push_back(nZoomSizeServer[idx]); |
---|
[710] | 2078 | --idx; |
---|
[676] | 2079 | } |
---|
| 2080 | --idxDomain; |
---|
| 2081 | } |
---|
[887] | 2082 | else if (1 == axisDomainOrder(i)) |
---|
[676] | 2083 | { |
---|
| 2084 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
| 2085 | |
---|
| 2086 | if (axis->isCompressible()) |
---|
| 2087 | { |
---|
| 2088 | start.push_back(axis->getOffsetWrittenIndexes()); |
---|
| 2089 | count.push_back(axis->getNumberWrittenIndexes()); |
---|
| 2090 | } |
---|
| 2091 | else |
---|
| 2092 | { |
---|
| 2093 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
| 2094 | count.push_back(nZoomSizeServer[idx]); |
---|
| 2095 | } |
---|
| 2096 | |
---|
| 2097 | --idxAxis; |
---|
| 2098 | --idx; |
---|
| 2099 | } |
---|
| 2100 | } |
---|
| 2101 | } |
---|
| 2102 | } |
---|
| 2103 | else |
---|
[498] | 2104 | { |
---|
[705] | 2105 | |
---|
[887] | 2106 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[705] | 2107 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 2108 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
| 2109 | int numElement = axisDomainOrder.numElements(); |
---|
| 2110 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1; |
---|
| 2111 | int idx = nZoomBeginGlobal.size() - 1; |
---|
| 2112 | |
---|
| 2113 | start.reserve(nZoomBeginGlobal.size()); |
---|
| 2114 | count.reserve(nZoomBeginGlobal.size()); |
---|
| 2115 | |
---|
| 2116 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 2117 | { |
---|
[887] | 2118 | if (2 == axisDomainOrder(i)) |
---|
[705] | 2119 | { |
---|
| 2120 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
[710] | 2121 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
[705] | 2122 | { |
---|
| 2123 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
| 2124 | count.push_back(nZoomSizeServer[idx]); |
---|
| 2125 | } |
---|
| 2126 | --idx ; |
---|
| 2127 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
| 2128 | count.push_back(nZoomSizeServer[idx]); |
---|
| 2129 | --idx ; |
---|
| 2130 | --idxDomain; |
---|
| 2131 | } |
---|
[887] | 2132 | else if (1 == axisDomainOrder(i)) |
---|
[705] | 2133 | { |
---|
| 2134 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
| 2135 | count.push_back(nZoomSizeServer[idx]); |
---|
| 2136 | --idx; |
---|
[887] | 2137 | } |
---|
| 2138 | else |
---|
| 2139 | { |
---|
| 2140 | if (1 == axisDomainOrder.numElements()) |
---|
| 2141 | { |
---|
| 2142 | start.push_back(0); |
---|
| 2143 | count.push_back(1); |
---|
| 2144 | } |
---|
| 2145 | --idx; |
---|
| 2146 | } |
---|
[705] | 2147 | } |
---|
[498] | 2148 | } |
---|
[488] | 2149 | |
---|
[676] | 2150 | SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count); |
---|
[586] | 2151 | if (wtime) |
---|
| 2152 | { |
---|
[692] | 2153 | SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); |
---|
| 2154 | SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
| 2155 | if (field->file->time_counter != CFile::time_counter_attr::none) |
---|
| 2156 | { |
---|
[802] | 2157 | SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1, isRoot); |
---|
[692] | 2158 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
| 2159 | SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
| 2160 | } |
---|
[586] | 2161 | } |
---|
| 2162 | |
---|
| 2163 | break; |
---|
[286] | 2164 | } |
---|
[567] | 2165 | } |
---|
[219] | 2166 | } |
---|
[498] | 2167 | catch (CNetCdfException& e) |
---|
| 2168 | { |
---|
| 2169 | StdString msg("On writing field data: "); |
---|
| 2170 | msg.append(fieldid); msg.append("\n"); |
---|
| 2171 | msg.append("In the context : "); |
---|
| 2172 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2173 | msg.append(e.what()); |
---|
| 2174 | ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); |
---|
| 2175 | } |
---|
[219] | 2176 | } |
---|
| 2177 | |
---|
| 2178 | //--------------------------------------------------------------- |
---|
| 2179 | |
---|
| 2180 | void CNc4DataOutput::writeTimeAxis_ |
---|
[347] | 2181 | (CField* field, |
---|
[343] | 2182 | const boost::shared_ptr<CCalendar> cal) |
---|
[219] | 2183 | { |
---|
| 2184 | StdOStringStream oss; |
---|
[488] | 2185 | |
---|
[645] | 2186 | if (field->getOperationTimeType() == func::CFunctor::once) return ; |
---|
[488] | 2187 | |
---|
[449] | 2188 | // oss << "time_" << field->operation.getValue() |
---|
| 2189 | // << "_" << field->getRelFile()->output_freq.getValue(); |
---|
[488] | 2190 | |
---|
[449] | 2191 | // StdString axisid = oss.str(); |
---|
[645] | 2192 | // if (field->getOperationTimeType() == func::CFunctor::centered) axisid="time_centered" ; |
---|
| 2193 | // else if (field->getOperationTimeType() == func::CFunctor::instant) axisid="time_instant" ; |
---|
[219] | 2194 | |
---|
[488] | 2195 | StdString axisid("time_centered") ; |
---|
| 2196 | StdString axisBoundId("time_centered_bounds"); |
---|
[802] | 2197 | StdString timeid(getTimeCounterName()); |
---|
[614] | 2198 | StdString timeBoundId("axis_nbounds"); |
---|
[488] | 2199 | |
---|
[645] | 2200 | if (field->getOperationTimeType() == func::CFunctor::instant) |
---|
[488] | 2201 | { |
---|
| 2202 | axisid = "time_instant"; |
---|
| 2203 | axisBoundId = "time_instant_bounds"; |
---|
| 2204 | } |
---|
| 2205 | |
---|
[498] | 2206 | try |
---|
[219] | 2207 | { |
---|
[498] | 2208 | // Adding time_instant or time_centered |
---|
| 2209 | std::vector<StdString> dims; |
---|
| 2210 | dims.push_back(timeid); |
---|
| 2211 | if (!SuperClassWriter::varExist(axisid)) |
---|
| 2212 | { |
---|
| 2213 | SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); |
---|
[488] | 2214 | |
---|
[498] | 2215 | CDate timeOrigin=cal->getTimeOrigin() ; |
---|
| 2216 | StdOStringStream oss2; |
---|
| 2217 | // oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " |
---|
| 2218 | // <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; |
---|
| 2219 | StdString strInitdate=oss2.str() ; |
---|
| 2220 | StdString strTimeOrigin=timeOrigin.toString() ; |
---|
| 2221 | this->writeTimeAxisAttributes |
---|
| 2222 | (axisid, cal->getType(), |
---|
| 2223 | StdString("seconds since ").append(strTimeOrigin), |
---|
| 2224 | strTimeOrigin, axisBoundId); |
---|
| 2225 | } |
---|
[219] | 2226 | |
---|
[498] | 2227 | // Adding time_instant_bounds or time_centered_bounds variables |
---|
| 2228 | if (!SuperClassWriter::varExist(axisBoundId)) |
---|
| 2229 | { |
---|
| 2230 | dims.clear() ; |
---|
| 2231 | dims.push_back(timeid); |
---|
| 2232 | dims.push_back(timeBoundId); |
---|
| 2233 | SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); |
---|
| 2234 | } |
---|
[488] | 2235 | |
---|
[692] | 2236 | if (field->file->time_counter != CFile::time_counter_attr::none) |
---|
[498] | 2237 | { |
---|
[692] | 2238 | // Adding time_counter |
---|
[802] | 2239 | axisid = getTimeCounterName(); |
---|
| 2240 | axisBoundId = getTimeCounterName() + "_bounds"; |
---|
[692] | 2241 | dims.clear(); |
---|
| 2242 | dims.push_back(timeid); |
---|
| 2243 | if (!SuperClassWriter::varExist(axisid)) |
---|
| 2244 | { |
---|
| 2245 | SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); |
---|
| 2246 | SuperClassWriter::addAttribute("axis", string("T"), &axisid); |
---|
[488] | 2247 | |
---|
[692] | 2248 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
| 2249 | { |
---|
| 2250 | CDate timeOrigin = cal->getTimeOrigin(); |
---|
| 2251 | StdString strTimeOrigin = timeOrigin.toString(); |
---|
[498] | 2252 | |
---|
[692] | 2253 | this->writeTimeAxisAttributes(axisid, cal->getType(), |
---|
| 2254 | StdString("seconds since ").append(strTimeOrigin), |
---|
| 2255 | strTimeOrigin, axisBoundId); |
---|
| 2256 | } |
---|
| 2257 | } |
---|
| 2258 | |
---|
| 2259 | // Adding time_counter_bound dimension |
---|
| 2260 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
| 2261 | { |
---|
| 2262 | if (!SuperClassWriter::varExist(axisBoundId)) |
---|
| 2263 | { |
---|
| 2264 | dims.clear(); |
---|
| 2265 | dims.push_back(timeid); |
---|
| 2266 | dims.push_back(timeBoundId); |
---|
| 2267 | SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); |
---|
| 2268 | } |
---|
| 2269 | } |
---|
[498] | 2270 | } |
---|
[488] | 2271 | } |
---|
[498] | 2272 | catch (CNetCdfException& e) |
---|
[488] | 2273 | { |
---|
[498] | 2274 | StdString msg("On writing time axis data: "); |
---|
| 2275 | msg.append("In the context : "); |
---|
| 2276 | CContext* context = CContext::getCurrent() ; |
---|
| 2277 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2278 | msg.append(e.what()); |
---|
| 2279 | ERROR("CNc4DataOutput::writeTimeAxis_ (CField* field, \ |
---|
| 2280 | const boost::shared_ptr<CCalendar> cal)", << msg); |
---|
[488] | 2281 | } |
---|
[219] | 2282 | } |
---|
| 2283 | |
---|
| 2284 | //--------------------------------------------------------------- |
---|
[488] | 2285 | |
---|
[219] | 2286 | void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, |
---|
| 2287 | const StdString & calendar, |
---|
| 2288 | const StdString & units, |
---|
| 2289 | const StdString & time_origin, |
---|
[488] | 2290 | const StdString & time_bounds, |
---|
[219] | 2291 | const StdString & standard_name, |
---|
[613] | 2292 | const StdString & long_name) |
---|
[219] | 2293 | { |
---|
[498] | 2294 | try |
---|
| 2295 | { |
---|
| 2296 | SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); |
---|
| 2297 | SuperClassWriter::addAttribute("long_name", long_name , &axis_name); |
---|
| 2298 | SuperClassWriter::addAttribute("calendar", calendar , &axis_name); |
---|
| 2299 | SuperClassWriter::addAttribute("units", units , &axis_name); |
---|
| 2300 | SuperClassWriter::addAttribute("time_origin", time_origin , &axis_name); |
---|
| 2301 | SuperClassWriter::addAttribute("bounds", time_bounds , &axis_name); |
---|
| 2302 | } |
---|
| 2303 | catch (CNetCdfException& e) |
---|
| 2304 | { |
---|
| 2305 | StdString msg("On writing time axis Attribute: "); |
---|
| 2306 | msg.append("In the context : "); |
---|
| 2307 | CContext* context = CContext::getCurrent() ; |
---|
| 2308 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2309 | msg.append(e.what()); |
---|
| 2310 | ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \ |
---|
[613] | 2311 | const StdString & calendar,\ |
---|
| 2312 | const StdString & units, \ |
---|
| 2313 | const StdString & time_origin, \ |
---|
| 2314 | const StdString & time_bounds, \ |
---|
| 2315 | const StdString & standard_name, \ |
---|
| 2316 | const StdString & long_name)", << msg); |
---|
[498] | 2317 | } |
---|
[219] | 2318 | } |
---|
[488] | 2319 | |
---|
[219] | 2320 | //--------------------------------------------------------------- |
---|
| 2321 | |
---|
| 2322 | void CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, |
---|
| 2323 | const StdString & axis, |
---|
| 2324 | const StdString & standard_name, |
---|
| 2325 | const StdString & long_name, |
---|
| 2326 | const StdString & units, |
---|
| 2327 | const StdString & nav_model) |
---|
| 2328 | { |
---|
[498] | 2329 | try |
---|
| 2330 | { |
---|
[613] | 2331 | if (!axis.empty()) |
---|
| 2332 | SuperClassWriter::addAttribute("axis" , axis , &axis_name); |
---|
| 2333 | |
---|
[498] | 2334 | SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); |
---|
| 2335 | SuperClassWriter::addAttribute("long_name" , long_name , &axis_name); |
---|
| 2336 | SuperClassWriter::addAttribute("units" , units , &axis_name); |
---|
| 2337 | SuperClassWriter::addAttribute("nav_model" , nav_model , &axis_name); |
---|
| 2338 | } |
---|
| 2339 | catch (CNetCdfException& e) |
---|
| 2340 | { |
---|
| 2341 | StdString msg("On writing Axis Attribute: "); |
---|
| 2342 | msg.append("In the context : "); |
---|
| 2343 | CContext* context = CContext::getCurrent() ; |
---|
| 2344 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2345 | msg.append(e.what()); |
---|
| 2346 | ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \ |
---|
[613] | 2347 | const StdString & axis, \ |
---|
| 2348 | const StdString & standard_name, \ |
---|
| 2349 | const StdString & long_name, \ |
---|
| 2350 | const StdString & units, \ |
---|
| 2351 | const StdString & nav_model)", << msg); |
---|
[498] | 2352 | } |
---|
[219] | 2353 | } |
---|
| 2354 | |
---|
| 2355 | //--------------------------------------------------------------- |
---|
[488] | 2356 | |
---|
[219] | 2357 | void CNc4DataOutput::writeLocalAttributes |
---|
| 2358 | (int ibegin, int ni, int jbegin, int nj, StdString domid) |
---|
| 2359 | { |
---|
[498] | 2360 | try |
---|
| 2361 | { |
---|
[318] | 2362 | SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin); |
---|
| 2363 | SuperClassWriter::addAttribute(StdString("ni" ).append(domid), ni); |
---|
| 2364 | SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin); |
---|
| 2365 | SuperClassWriter::addAttribute(StdString("nj" ).append(domid), nj); |
---|
[498] | 2366 | } |
---|
| 2367 | catch (CNetCdfException& e) |
---|
| 2368 | { |
---|
| 2369 | StdString msg("On writing Local Attributes: "); |
---|
| 2370 | msg.append("In the context : "); |
---|
| 2371 | CContext* context = CContext::getCurrent() ; |
---|
| 2372 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2373 | msg.append(e.what()); |
---|
| 2374 | ERROR("CNc4DataOutput::writeLocalAttributes \ |
---|
| 2375 | (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg); |
---|
| 2376 | } |
---|
| 2377 | |
---|
[219] | 2378 | } |
---|
| 2379 | |
---|
[628] | 2380 | void CNc4DataOutput::writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid, |
---|
| 2381 | int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size) |
---|
[391] | 2382 | { |
---|
| 2383 | CArray<int,1> array(2) ; |
---|
| 2384 | |
---|
[498] | 2385 | try |
---|
| 2386 | { |
---|
| 2387 | SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ; |
---|
| 2388 | SuperClassWriter::addAttribute("DOMAIN_number", rank) ; |
---|
[629] | 2389 | array = SuperClassWriter::getDimension(dimXid) + 1, SuperClassWriter::getDimension(dimYid) + 1; |
---|
[498] | 2390 | SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ; |
---|
| 2391 | array=ni_glo,nj_glo ; |
---|
| 2392 | SuperClassWriter::addAttribute("DOMAIN_size_global", array) ; |
---|
| 2393 | array=ni,nj ; |
---|
| 2394 | SuperClassWriter::addAttribute("DOMAIN_size_local", array) ; |
---|
[819] | 2395 | array=ibegin+1,jbegin+1 ; |
---|
[498] | 2396 | SuperClassWriter::addAttribute("DOMAIN_position_first", array) ; |
---|
[819] | 2397 | array=ibegin+ni-1+1,jbegin+nj-1+1 ; |
---|
[498] | 2398 | SuperClassWriter::addAttribute("DOMAIN_position_last",array) ; |
---|
| 2399 | array=0,0 ; |
---|
| 2400 | SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ; |
---|
| 2401 | SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array); |
---|
| 2402 | SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ; |
---|
| 2403 | /* |
---|
| 2404 | SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ; |
---|
| 2405 | SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ; |
---|
| 2406 | SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ; |
---|
| 2407 | SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ; |
---|
| 2408 | */ |
---|
| 2409 | } |
---|
| 2410 | catch (CNetCdfException& e) |
---|
| 2411 | { |
---|
[628] | 2412 | StdString msg("On writing Local Attributes IOIPSL \n"); |
---|
[498] | 2413 | msg.append("In the context : "); |
---|
| 2414 | CContext* context = CContext::getCurrent() ; |
---|
| 2415 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2416 | msg.append(e.what()); |
---|
| 2417 | ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \ |
---|
| 2418 | (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg); |
---|
| 2419 | } |
---|
[391] | 2420 | } |
---|
[219] | 2421 | //--------------------------------------------------------------- |
---|
| 2422 | |
---|
| 2423 | void CNc4DataOutput:: writeFileAttributes(const StdString & name, |
---|
| 2424 | const StdString & description, |
---|
| 2425 | const StdString & conventions, |
---|
| 2426 | const StdString & production, |
---|
| 2427 | const StdString & timeStamp) |
---|
| 2428 | { |
---|
[498] | 2429 | try |
---|
| 2430 | { |
---|
| 2431 | SuperClassWriter::addAttribute("name" , name); |
---|
| 2432 | SuperClassWriter::addAttribute("description", description); |
---|
[613] | 2433 | SuperClassWriter::addAttribute("title" , description); |
---|
| 2434 | SuperClassWriter::addAttribute("Conventions", conventions); |
---|
[498] | 2435 | SuperClassWriter::addAttribute("production" , production); |
---|
| 2436 | SuperClassWriter::addAttribute("timeStamp" , timeStamp); |
---|
| 2437 | } |
---|
| 2438 | catch (CNetCdfException& e) |
---|
| 2439 | { |
---|
| 2440 | StdString msg("On writing File Attributes \n "); |
---|
| 2441 | msg.append("In the context : "); |
---|
| 2442 | CContext* context = CContext::getCurrent() ; |
---|
| 2443 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2444 | msg.append(e.what()); |
---|
| 2445 | ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \ |
---|
| 2446 | const StdString & description, \ |
---|
| 2447 | const StdString & conventions, \ |
---|
| 2448 | const StdString & production, \ |
---|
| 2449 | const StdString & timeStamp)", << msg); |
---|
| 2450 | } |
---|
[219] | 2451 | } |
---|
| 2452 | |
---|
| 2453 | //--------------------------------------------------------------- |
---|
| 2454 | |
---|
| 2455 | void CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, |
---|
| 2456 | int data_dim, |
---|
| 2457 | int data_ni, |
---|
| 2458 | int data_nj, |
---|
| 2459 | int data_ibegin, |
---|
| 2460 | int data_jbegin) |
---|
| 2461 | { |
---|
[498] | 2462 | try |
---|
| 2463 | { |
---|
| 2464 | SuperClassWriter::addAttribute("data_dim" , data_dim , &mask_name); |
---|
| 2465 | SuperClassWriter::addAttribute("data_ni" , data_ni , &mask_name); |
---|
| 2466 | SuperClassWriter::addAttribute("data_nj" , data_nj , &mask_name); |
---|
| 2467 | SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name); |
---|
| 2468 | SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name); |
---|
| 2469 | } |
---|
| 2470 | catch (CNetCdfException& e) |
---|
| 2471 | { |
---|
| 2472 | StdString msg("On writing Mask Attributes \n "); |
---|
| 2473 | msg.append("In the context : "); |
---|
| 2474 | CContext* context = CContext::getCurrent() ; |
---|
| 2475 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2476 | msg.append(e.what()); |
---|
| 2477 | ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \ |
---|
| 2478 | int data_dim, \ |
---|
| 2479 | int data_ni, \ |
---|
| 2480 | int data_nj, \ |
---|
| 2481 | int data_ibegin, \ |
---|
| 2482 | int data_jbegin)", << msg); |
---|
| 2483 | } |
---|
[219] | 2484 | } |
---|
| 2485 | |
---|
| 2486 | ///-------------------------------------------------------------- |
---|
| 2487 | |
---|
[707] | 2488 | StdSize CNc4DataOutput::getRecordFromTime(Time time) |
---|
| 2489 | { |
---|
| 2490 | std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time); |
---|
| 2491 | if (it == timeToRecordCache.end()) |
---|
| 2492 | { |
---|
[802] | 2493 | StdString timeAxisBoundsId(getTimeCounterName() + "_bounds"); |
---|
[707] | 2494 | if (!SuperClassWriter::varExist(timeAxisBoundsId)) |
---|
| 2495 | timeAxisBoundsId = "time_instant_bounds"; |
---|
| 2496 | |
---|
| 2497 | CArray<double,2> timeAxisBounds; |
---|
| 2498 | SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective); |
---|
| 2499 | |
---|
| 2500 | StdSize record = 0; |
---|
| 2501 | double dtime(time); |
---|
| 2502 | for (int n = timeAxisBounds.extent(1) - 1; n >= 0; n--) |
---|
| 2503 | { |
---|
| 2504 | if (timeAxisBounds(1, n) < dtime) |
---|
| 2505 | { |
---|
| 2506 | record = n + 1; |
---|
| 2507 | break; |
---|
| 2508 | } |
---|
| 2509 | } |
---|
| 2510 | it = timeToRecordCache.insert(std::make_pair(time, record)).first; |
---|
| 2511 | } |
---|
| 2512 | return it->second; |
---|
| 2513 | } |
---|
[774] | 2514 | |
---|
| 2515 | ///-------------------------------------------------------------- |
---|
| 2516 | |
---|
| 2517 | bool CNc4DataOutput::isWrittenDomain(const std::string& domainName) const |
---|
| 2518 | { |
---|
| 2519 | return (this->writtenDomains.find(domainName) != this->writtenDomains.end()); |
---|
| 2520 | } |
---|
| 2521 | |
---|
| 2522 | bool CNc4DataOutput::isWrittenCompressedDomain(const std::string& domainName) const |
---|
| 2523 | { |
---|
| 2524 | return (this->writtenCompressedDomains.find(domainName) != this->writtenCompressedDomains.end()); |
---|
| 2525 | } |
---|
| 2526 | |
---|
| 2527 | bool CNc4DataOutput::isWrittenAxis(const std::string& axisName) const |
---|
| 2528 | { |
---|
| 2529 | return (this->writtenAxis.find(axisName) != this->writtenAxis.end()); |
---|
| 2530 | } |
---|
| 2531 | |
---|
| 2532 | bool CNc4DataOutput::isWrittenCompressedAxis(const std::string& axisName) const |
---|
| 2533 | { |
---|
| 2534 | return (this->writtenCompressedAxis.find(axisName) != this->writtenCompressedAxis.end()); |
---|
| 2535 | } |
---|
| 2536 | |
---|
[887] | 2537 | bool CNc4DataOutput::isWrittenScalar(const std::string& scalarName) const |
---|
| 2538 | { |
---|
| 2539 | return (this->writtenScalar.find(scalarName) != this->writtenScalar.end()); |
---|
| 2540 | } |
---|
| 2541 | |
---|
[774] | 2542 | void CNc4DataOutput::setWrittenDomain(const std::string& domainName) |
---|
| 2543 | { |
---|
| 2544 | this->writtenDomains.insert(domainName); |
---|
| 2545 | } |
---|
| 2546 | |
---|
| 2547 | void CNc4DataOutput::setWrittenCompressedDomain(const std::string& domainName) |
---|
| 2548 | { |
---|
| 2549 | this->writtenCompressedDomains.insert(domainName); |
---|
| 2550 | } |
---|
| 2551 | |
---|
| 2552 | void CNc4DataOutput::setWrittenAxis(const std::string& axisName) |
---|
| 2553 | { |
---|
| 2554 | this->writtenAxis.insert(axisName); |
---|
| 2555 | } |
---|
| 2556 | |
---|
| 2557 | void CNc4DataOutput::setWrittenCompressedAxis(const std::string& axisName) |
---|
| 2558 | { |
---|
| 2559 | this->writtenCompressedAxis.insert(axisName); |
---|
| 2560 | } |
---|
[887] | 2561 | |
---|
| 2562 | void CNc4DataOutput::setWrittenScalar(const std::string& scalarName) |
---|
| 2563 | { |
---|
| 2564 | this->writtenScalar.insert(scalarName); |
---|
| 2565 | } |
---|
[335] | 2566 | } // namespace xios |
---|