[219] | 1 | #include "nc4_data_output.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "group_template.hpp" |
---|
[219] | 5 | |
---|
| 6 | #include "file.hpp" |
---|
| 7 | #include "calendar.hpp" |
---|
[278] | 8 | #include "context.hpp" |
---|
[300] | 9 | #include "context_server.hpp" |
---|
[498] | 10 | #include "netCdfException.hpp" |
---|
| 11 | #include "exception.hpp" |
---|
[1158] | 12 | #include "timer.hpp" |
---|
| 13 | #include "uuid.hpp" |
---|
[335] | 14 | namespace xios |
---|
[219] | 15 | { |
---|
[878] | 16 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
[219] | 17 | CNc4DataOutput::CNc4DataOutput |
---|
[1158] | 18 | (CFile* file, const StdString & filename, bool exist) |
---|
[219] | 19 | : SuperClass() |
---|
| 20 | , SuperClassWriter(filename, exist) |
---|
| 21 | , filename(filename) |
---|
[1158] | 22 | , file(file),hasTimeInstant(false),hasTimeCentered(false), timeCounterType(none) |
---|
[219] | 23 | { |
---|
[1158] | 24 | SuperClass::type = MULTI_FILE; |
---|
[1456] | 25 | compressionLevel= file->compression_level.isEmpty() ? 0 :file->compression_level ; |
---|
[219] | 26 | } |
---|
| 27 | |
---|
| 28 | CNc4DataOutput::CNc4DataOutput |
---|
[1158] | 29 | (CFile* file, const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, |
---|
[1601] | 30 | ep_lib::MPI_Comm comm_file, bool multifile, bool isCollective, const StdString& timeCounterName) |
---|
[219] | 31 | : SuperClass() |
---|
[878] | 32 | , SuperClassWriter(filename, exist, useClassicFormat, useCFConvention, &comm_file, multifile, timeCounterName) |
---|
[379] | 33 | , comm_file(comm_file) |
---|
[219] | 34 | , filename(filename) |
---|
[335] | 35 | , isCollective(isCollective) |
---|
[1158] | 36 | , file(file),hasTimeInstant(false),hasTimeCentered(false), timeCounterType(none) |
---|
[219] | 37 | { |
---|
[1158] | 38 | SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; |
---|
[1459] | 39 | if (file==NULL) compressionLevel = 0 ; |
---|
| 40 | else compressionLevel= file->compression_level.isEmpty() ? 0 :file->compression_level ; |
---|
[219] | 41 | } |
---|
| 42 | |
---|
| 43 | CNc4DataOutput::~CNc4DataOutput(void) |
---|
[879] | 44 | { /* Ne rien faire de plus */ } |
---|
[219] | 45 | |
---|
| 46 | ///-------------------------------------------------------------- |
---|
| 47 | |
---|
| 48 | const StdString & CNc4DataOutput::getFileName(void) const |
---|
| 49 | { |
---|
| 50 | return (this->filename); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | //--------------------------------------------------------------- |
---|
| 54 | |
---|
[347] | 55 | void CNc4DataOutput::writeDomain_(CDomain* domain) |
---|
[1646] | 56 | TRY |
---|
[219] | 57 | { |
---|
[1391] | 58 | StdString lonName,latName ; |
---|
| 59 | |
---|
[1129] | 60 | domain->computeWrittenIndex(); |
---|
[1249] | 61 | domain->computeWrittenCompressedIndex(comm_file); |
---|
| 62 | |
---|
[881] | 63 | if (domain->type == CDomain::type_attr::unstructured) |
---|
| 64 | { |
---|
| 65 | if (SuperClassWriter::useCFConvention) |
---|
| 66 | writeUnstructuredDomain(domain) ; |
---|
| 67 | else |
---|
| 68 | writeUnstructuredDomainUgrid(domain) ; |
---|
| 69 | return ; |
---|
| 70 | } |
---|
[488] | 71 | |
---|
[347] | 72 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 73 | CContextServer* server=context->server ; |
---|
[488] | 74 | |
---|
[219] | 75 | if (domain->IsWritten(this->filename)) return; |
---|
| 76 | domain->checkAttributes(); |
---|
[488] | 77 | |
---|
| 78 | if (domain->isEmpty()) |
---|
[881] | 79 | if (SuperClass::type==MULTI_FILE) return; |
---|
[219] | 80 | |
---|
| 81 | std::vector<StdString> dim0, dim1; |
---|
[772] | 82 | StdString domid = domain->getDomainOutputName(); |
---|
[318] | 83 | StdString appendDomid = (singleDomain) ? "" : "_"+domid ; |
---|
[706] | 84 | if (isWrittenDomain(domid)) return ; |
---|
[774] | 85 | else setWrittenDomain(domid); |
---|
[1132] | 86 | |
---|
| 87 | int nvertex = (domain->nvertex.isEmpty()) ? 0 : domain->nvertex; |
---|
[449] | 88 | |
---|
[488] | 89 | |
---|
[1158] | 90 | StdString dimXid, dimYid ; |
---|
| 91 | |
---|
| 92 | nc_type typePrec ; |
---|
| 93 | if (domain->prec.isEmpty()) typePrec = NC_FLOAT ; |
---|
| 94 | else if (domain->prec==4) typePrec = NC_FLOAT ; |
---|
| 95 | else if (domain->prec==8) typePrec = NC_DOUBLE ; |
---|
| 96 | |
---|
[664] | 97 | bool isRegularDomain = (domain->type == CDomain::type_attr::rectilinear); |
---|
[449] | 98 | switch (domain->type) |
---|
[433] | 99 | { |
---|
[449] | 100 | case CDomain::type_attr::curvilinear : |
---|
[1391] | 101 | |
---|
| 102 | if (domain->lon_name.isEmpty()) lonName = "nav_lon"; |
---|
| 103 | else lonName = domain->lon_name; |
---|
| 104 | |
---|
| 105 | if (domain->lat_name.isEmpty()) latName = "nav_lat"; |
---|
| 106 | else latName = domain->lat_name; |
---|
| 107 | |
---|
[1430] | 108 | if (domain->dim_i_name.isEmpty()) dimXid=StdString("x").append(appendDomid); |
---|
| 109 | else dimXid=domain->dim_i_name.getValue() + appendDomid; |
---|
| 110 | |
---|
| 111 | if (domain->dim_j_name.isEmpty()) dimYid=StdString("y").append(appendDomid); |
---|
| 112 | else dimYid=domain->dim_j_name.getValue() + appendDomid; |
---|
| 113 | |
---|
[449] | 114 | break ; |
---|
[1391] | 115 | |
---|
[664] | 116 | case CDomain::type_attr::rectilinear : |
---|
[1391] | 117 | |
---|
[1430] | 118 | if (domain->lon_name.isEmpty()) |
---|
| 119 | { |
---|
| 120 | if (domain->dim_i_name.isEmpty()) |
---|
| 121 | lonName = "lon"; |
---|
| 122 | else |
---|
| 123 | lonName = domain->dim_i_name.getValue(); |
---|
| 124 | } |
---|
[1391] | 125 | else lonName = domain->lon_name; |
---|
| 126 | |
---|
[1430] | 127 | if (domain->lat_name.isEmpty()) |
---|
| 128 | { |
---|
| 129 | if (domain->dim_j_name.isEmpty()) |
---|
| 130 | latName = "lat"; |
---|
| 131 | else |
---|
| 132 | latName = domain->dim_j_name.getValue(); |
---|
| 133 | } |
---|
[1391] | 134 | else latName = domain->lat_name; |
---|
| 135 | |
---|
[1430] | 136 | if (domain->dim_i_name.isEmpty()) dimXid = lonName+appendDomid; |
---|
| 137 | else dimXid = domain->dim_i_name.getValue()+appendDomid; |
---|
| 138 | |
---|
| 139 | if (domain->dim_j_name.isEmpty()) dimYid = latName+appendDomid; |
---|
| 140 | else dimYid = domain->dim_j_name.getValue()+appendDomid; |
---|
[449] | 141 | break; |
---|
[488] | 142 | } |
---|
| 143 | |
---|
[617] | 144 | StdString dimVertId = StdString("nvertex").append(appendDomid); |
---|
| 145 | |
---|
[449] | 146 | string lonid,latid,bounds_lonid,bounds_latid ; |
---|
[611] | 147 | string areaId = "area" + appendDomid; |
---|
[391] | 148 | /* |
---|
[300] | 149 | StdString lonid_loc = (server->intraCommSize > 1) |
---|
[318] | 150 | ? StdString("lon").append(appendDomid).append("_local") |
---|
[278] | 151 | : lonid; |
---|
[300] | 152 | StdString latid_loc = (server->intraCommSize > 1) |
---|
[318] | 153 | ? StdString("lat").append(appendDomid).append("_local") |
---|
[278] | 154 | : latid; |
---|
[391] | 155 | */ |
---|
[219] | 156 | |
---|
[1646] | 157 | CArray<int, 1>& indexToWrite = domain->localIndexToWriteOnServer; |
---|
[1129] | 158 | int nbWritten = indexToWrite.numElements(); |
---|
| 159 | CArray<double,1> writtenLat, writtenLon; |
---|
| 160 | CArray<double,2> writtenBndsLat, writtenBndsLon; |
---|
| 161 | CArray<double,1> writtenArea; |
---|
| 162 | |
---|
| 163 | if (domain->hasLonLat) |
---|
| 164 | { |
---|
| 165 | writtenLat.resize(nbWritten); |
---|
| 166 | writtenLon.resize(nbWritten); |
---|
| 167 | for (int idx = 0; idx < nbWritten; ++idx) |
---|
| 168 | { |
---|
[1646] | 169 | if (indexToWrite(idx) < 0) |
---|
| 170 | { |
---|
| 171 | writtenLat(idx) = -1.; // hole |
---|
| 172 | writtenLon(idx) = -1.; |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | writtenLat(idx) = domain->latvalue(indexToWrite(idx)); |
---|
| 177 | writtenLon(idx) = domain->lonvalue(indexToWrite(idx)); |
---|
| 178 | } |
---|
[1129] | 179 | } |
---|
| 180 | |
---|
| 181 | if (domain->hasBounds) |
---|
| 182 | { |
---|
| 183 | int nvertex = domain->nvertex, idx; |
---|
| 184 | writtenBndsLat.resize(nvertex, nbWritten); |
---|
| 185 | writtenBndsLon.resize(nvertex, nbWritten); |
---|
| 186 | CArray<double,2>& boundslat = domain->bounds_latvalue; |
---|
| 187 | CArray<double,2>& boundslon = domain->bounds_lonvalue; |
---|
| 188 | for (idx = 0; idx < nbWritten; ++idx) |
---|
| 189 | for (int nv = 0; nv < nvertex; ++nv) |
---|
| 190 | { |
---|
[1646] | 191 | if (indexToWrite(idx) < 0) |
---|
| 192 | { |
---|
| 193 | writtenBndsLat(nv, idx) = -1.; // hole |
---|
| 194 | writtenBndsLon(nv, idx) = -1.; |
---|
| 195 | } |
---|
| 196 | else |
---|
| 197 | { |
---|
[1390] | 198 | writtenBndsLat(nv, idx) = boundslat(nv, int(indexToWrite(idx))); |
---|
| 199 | writtenBndsLon(nv, idx) = boundslon(nv, int(indexToWrite(idx))); |
---|
[1646] | 200 | } |
---|
[1129] | 201 | } |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | if (domain->hasArea) |
---|
| 206 | { |
---|
| 207 | writtenArea.resize(nbWritten); |
---|
| 208 | for (int idx = 0; idx < nbWritten; ++idx) |
---|
| 209 | { |
---|
[1646] | 210 | if (indexToWrite(idx) < 0) |
---|
| 211 | writtenArea(idx) = -1.; |
---|
[1390] | 212 | else |
---|
[1646] | 213 | writtenArea(idx) = domain->areavalue(indexToWrite(idx)); |
---|
[1129] | 214 | } |
---|
| 215 | } |
---|
| 216 | |
---|
[498] | 217 | try |
---|
[219] | 218 | { |
---|
[498] | 219 | switch (SuperClass::type) |
---|
| 220 | { |
---|
| 221 | case (MULTI_FILE) : |
---|
| 222 | { |
---|
| 223 | switch (domain->type) |
---|
| 224 | { |
---|
| 225 | case CDomain::type_attr::curvilinear : |
---|
| 226 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
[1415] | 227 | lonid = lonName+appendDomid; |
---|
| 228 | latid = latName+appendDomid; |
---|
[498] | 229 | break ; |
---|
[664] | 230 | case CDomain::type_attr::rectilinear : |
---|
[1415] | 231 | lonid = lonName+appendDomid; |
---|
| 232 | latid = latName+appendDomid; |
---|
[498] | 233 | dim0.push_back(dimYid); |
---|
| 234 | dim1.push_back(dimXid); |
---|
| 235 | break; |
---|
| 236 | } |
---|
[1430] | 237 | if (!domain->bounds_lon_name.isEmpty()) bounds_lonid = domain->bounds_lon_name; |
---|
| 238 | else bounds_lonid = "bounds_"+lonName+appendDomid; |
---|
| 239 | if (!domain->bounds_lat_name.isEmpty()) bounds_latid = domain->bounds_lat_name; |
---|
| 240 | else bounds_latid = "bounds_"+latName+appendDomid; |
---|
[488] | 241 | |
---|
[1553] | 242 | SuperClassWriter::addDimension(dimXid, domain->ni); |
---|
| 243 | SuperClassWriter::addDimension(dimYid, domain->nj); |
---|
[488] | 244 | |
---|
[617] | 245 | if (domain->hasBounds) |
---|
| 246 | SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 247 | |
---|
[498] | 248 | if (server->intraCommSize > 1) |
---|
| 249 | { |
---|
[1553] | 250 | this->writeLocalAttributes(domain->ibegin, |
---|
| 251 | domain->ni, |
---|
| 252 | domain->jbegin, |
---|
| 253 | domain->nj, |
---|
[616] | 254 | appendDomid); |
---|
[488] | 255 | |
---|
[628] | 256 | if (singleDomain) |
---|
| 257 | this->writeLocalAttributes_IOIPSL(dimXid, dimYid, |
---|
[1553] | 258 | domain->ibegin, |
---|
| 259 | domain->ni, |
---|
| 260 | domain->jbegin, |
---|
| 261 | domain->nj, |
---|
[628] | 262 | domain->ni_glo,domain->nj_glo, |
---|
| 263 | server->intraCommRank,server->intraCommSize); |
---|
[449] | 264 | } |
---|
[488] | 265 | |
---|
[665] | 266 | if (domain->hasLonLat) |
---|
[498] | 267 | { |
---|
[665] | 268 | switch (domain->type) |
---|
| 269 | { |
---|
| 270 | case CDomain::type_attr::curvilinear : |
---|
[1456] | 271 | SuperClassWriter::addVariable(latid, typePrec, dim0, compressionLevel); |
---|
| 272 | SuperClassWriter::addVariable(lonid, typePrec, dim0, compressionLevel); |
---|
[665] | 273 | break ; |
---|
| 274 | case CDomain::type_attr::rectilinear : |
---|
[1456] | 275 | SuperClassWriter::addVariable(latid, typePrec, dim0, compressionLevel); |
---|
| 276 | SuperClassWriter::addVariable(lonid, typePrec, dim1, compressionLevel); |
---|
[665] | 277 | break ; |
---|
| 278 | } |
---|
[488] | 279 | |
---|
[665] | 280 | this->writeAxisAttributes(lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 281 | this->writeAxisAttributes(latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid); |
---|
[219] | 282 | |
---|
[665] | 283 | if (domain->hasBounds) |
---|
| 284 | { |
---|
| 285 | SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid); |
---|
| 286 | SuperClassWriter::addAttribute("bounds", bounds_latid, &latid); |
---|
[617] | 287 | |
---|
[665] | 288 | dim0.clear(); |
---|
| 289 | dim0.push_back(dimYid); |
---|
| 290 | dim0.push_back(dimXid); |
---|
| 291 | dim0.push_back(dimVertId); |
---|
[1456] | 292 | SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0, compressionLevel); |
---|
| 293 | SuperClassWriter::addVariable(bounds_latid, typePrec, dim0, compressionLevel); |
---|
[665] | 294 | } |
---|
[617] | 295 | } |
---|
| 296 | |
---|
[498] | 297 | dim0.clear(); |
---|
[616] | 298 | dim0.push_back(dimYid); |
---|
[498] | 299 | dim0.push_back(dimXid); |
---|
[219] | 300 | |
---|
| 301 | |
---|
[498] | 302 | // supress mask if (server->intraCommSize > 1) |
---|
| 303 | // supress mask { |
---|
| 304 | // supress mask SuperClassWriter::addVariable(maskid, NC_INT, dim0); |
---|
| 305 | // supress mask |
---|
| 306 | // supress mask this->writeMaskAttributes(maskid, |
---|
| 307 | // supress mask domain->data_dim.getValue()/*, |
---|
| 308 | // supress mask domain->data_ni.getValue(), |
---|
| 309 | // supress mask domain->data_nj.getValue(), |
---|
| 310 | // supress mask domain->data_ibegin.getValue(), |
---|
| 311 | // supress mask domain->data_jbegin.getValue()*/); |
---|
| 312 | // supress mask } |
---|
[488] | 313 | |
---|
[498] | 314 | //SuperClassWriter::setDefaultValue(maskid, &dvm); |
---|
[219] | 315 | |
---|
[611] | 316 | if (domain->hasArea) |
---|
| 317 | { |
---|
[1456] | 318 | SuperClassWriter::addVariable(areaId, typePrec, dim0, compressionLevel); |
---|
[614] | 319 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 320 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 321 | } |
---|
| 322 | |
---|
[498] | 323 | SuperClassWriter::definition_end(); |
---|
[449] | 324 | |
---|
[665] | 325 | if (domain->hasLonLat) |
---|
[498] | 326 | { |
---|
[665] | 327 | switch (domain->type) |
---|
| 328 | { |
---|
[1129] | 329 | case CDomain::type_attr::curvilinear : |
---|
| 330 | SuperClassWriter::writeData(writtenLat, latid, isCollective, 0); |
---|
| 331 | SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0); |
---|
[665] | 332 | break; |
---|
| 333 | case CDomain::type_attr::rectilinear : |
---|
[1553] | 334 | CArray<double,1> lat = writtenLat(Range(fromStart,toEnd,domain->ni)) ; |
---|
[665] | 335 | SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0); |
---|
[1553] | 336 | CArray<double,1> lon = writtenLon(Range(0,domain->ni-1)) ; |
---|
[665] | 337 | SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0); |
---|
| 338 | break; |
---|
| 339 | } |
---|
[611] | 340 | |
---|
[665] | 341 | if (domain->hasBounds) |
---|
| 342 | { |
---|
[1129] | 343 | SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0); |
---|
| 344 | SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0); |
---|
[665] | 345 | } |
---|
[617] | 346 | } |
---|
| 347 | |
---|
[611] | 348 | if (domain->hasArea) |
---|
[1129] | 349 | { |
---|
[1132] | 350 | SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0); |
---|
[1129] | 351 | } |
---|
| 352 | |
---|
[498] | 353 | SuperClassWriter::definition_start(); |
---|
[219] | 354 | |
---|
[498] | 355 | break; |
---|
| 356 | } |
---|
| 357 | case (ONE_FILE) : |
---|
| 358 | { |
---|
[1553] | 359 | SuperClassWriter::addDimension(dimXid, domain->ni_glo); |
---|
| 360 | SuperClassWriter::addDimension(dimYid, domain->nj_glo); |
---|
[286] | 361 | |
---|
[617] | 362 | if (domain->hasBounds) |
---|
| 363 | SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 364 | |
---|
[665] | 365 | if (domain->hasLonLat) |
---|
[498] | 366 | { |
---|
[665] | 367 | switch (domain->type) |
---|
| 368 | { |
---|
| 369 | case CDomain::type_attr::curvilinear : |
---|
| 370 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
[1415] | 371 | lonid = lonName+appendDomid; |
---|
| 372 | latid = latName+appendDomid; |
---|
[1456] | 373 | SuperClassWriter::addVariable(latid, typePrec, dim0, compressionLevel); |
---|
| 374 | SuperClassWriter::addVariable(lonid, typePrec, dim0, compressionLevel); |
---|
[665] | 375 | break; |
---|
[449] | 376 | |
---|
[665] | 377 | case CDomain::type_attr::rectilinear : |
---|
| 378 | dim0.push_back(dimYid); |
---|
| 379 | dim1.push_back(dimXid); |
---|
[1415] | 380 | lonid = lonName+appendDomid; |
---|
| 381 | latid = latName+appendDomid; |
---|
[1456] | 382 | SuperClassWriter::addVariable(latid, typePrec, dim0, compressionLevel); |
---|
| 383 | SuperClassWriter::addVariable(lonid, typePrec, dim1, compressionLevel); |
---|
[665] | 384 | break; |
---|
| 385 | } |
---|
[1430] | 386 | if (!domain->bounds_lon_name.isEmpty()) bounds_lonid = domain->bounds_lon_name; |
---|
| 387 | else bounds_lonid = "bounds_"+lonName+appendDomid; |
---|
| 388 | if (!domain->bounds_lat_name.isEmpty()) bounds_latid = domain->bounds_lat_name; |
---|
| 389 | else bounds_latid = "bounds_"+latName+appendDomid; |
---|
[665] | 390 | |
---|
| 391 | this->writeAxisAttributes |
---|
| 392 | (lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 393 | this->writeAxisAttributes |
---|
| 394 | (latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid); |
---|
| 395 | |
---|
| 396 | if (domain->hasBounds) |
---|
| 397 | { |
---|
| 398 | SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid); |
---|
| 399 | SuperClassWriter::addAttribute("bounds", bounds_latid, &latid); |
---|
| 400 | |
---|
| 401 | dim0.clear(); |
---|
[498] | 402 | dim0.push_back(dimYid); |
---|
[665] | 403 | dim0.push_back(dimXid); |
---|
| 404 | dim0.push_back(dimVertId); |
---|
[1456] | 405 | SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0, compressionLevel); |
---|
| 406 | SuperClassWriter::addVariable(bounds_latid, typePrec, dim0, compressionLevel); |
---|
[665] | 407 | } |
---|
[498] | 408 | } |
---|
[611] | 409 | |
---|
| 410 | if (domain->hasArea) |
---|
| 411 | { |
---|
| 412 | dim0.clear(); |
---|
| 413 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
[1456] | 414 | SuperClassWriter::addVariable(areaId, typePrec, dim0, compressionLevel); |
---|
[614] | 415 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 416 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 417 | dim0.clear(); |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | SuperClassWriter::definition_end(); |
---|
[286] | 421 | |
---|
[498] | 422 | switch (domain->type) |
---|
[384] | 423 | { |
---|
[498] | 424 | case CDomain::type_attr::curvilinear : |
---|
[449] | 425 | { |
---|
[498] | 426 | std::vector<StdSize> start(2) ; |
---|
| 427 | std::vector<StdSize> count(2) ; |
---|
[1646] | 428 | // Comment out: it is not working for a hole |
---|
| 429 | // if (domain->isEmpty()) |
---|
| 430 | // { |
---|
| 431 | // start[0]=0 ; start[1]=0 ; |
---|
| 432 | // count[0]=0 ; count[1]=0 ; |
---|
| 433 | // } |
---|
| 434 | // else |
---|
[498] | 435 | { |
---|
[1553] | 436 | start[1]=domain->ibegin; |
---|
| 437 | start[0]=domain->jbegin; |
---|
| 438 | count[1]=domain->ni ; count[0]=domain->nj ; |
---|
[498] | 439 | } |
---|
[488] | 440 | |
---|
[665] | 441 | if (domain->hasLonLat) |
---|
| 442 | { |
---|
[1129] | 443 | SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count); |
---|
| 444 | SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count); |
---|
[665] | 445 | } |
---|
[498] | 446 | break; |
---|
| 447 | } |
---|
[664] | 448 | case CDomain::type_attr::rectilinear : |
---|
[449] | 449 | { |
---|
[665] | 450 | if (domain->hasLonLat) |
---|
[498] | 451 | { |
---|
[665] | 452 | std::vector<StdSize> start(1) ; |
---|
| 453 | std::vector<StdSize> count(1) ; |
---|
| 454 | if (domain->isEmpty()) |
---|
| 455 | { |
---|
| 456 | start[0]=0 ; |
---|
| 457 | count[0]=0 ; |
---|
[1129] | 458 | SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count); |
---|
| 459 | SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count); |
---|
[665] | 460 | } |
---|
| 461 | else |
---|
[1129] | 462 | { |
---|
[1553] | 463 | start[0]=domain->jbegin; |
---|
| 464 | count[0]=domain->nj; |
---|
| 465 | CArray<double,1> lat = writtenLat(Range(fromStart,toEnd,domain->ni)); |
---|
[665] | 466 | SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); |
---|
| 467 | |
---|
[1553] | 468 | start[0]=domain->ibegin; |
---|
| 469 | count[0]=domain->ni; |
---|
| 470 | CArray<double,1> lon = writtenLon(Range(0,domain->ni-1)); |
---|
[665] | 471 | SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); |
---|
| 472 | } |
---|
[498] | 473 | } |
---|
| 474 | break; |
---|
[449] | 475 | } |
---|
[384] | 476 | } |
---|
[611] | 477 | |
---|
[617] | 478 | if (domain->hasBounds) |
---|
| 479 | { |
---|
| 480 | std::vector<StdSize> start(3); |
---|
| 481 | std::vector<StdSize> count(3); |
---|
| 482 | if (domain->isEmpty()) |
---|
| 483 | { |
---|
| 484 | start[2] = start[1] = start[0] = 0; |
---|
| 485 | count[2] = count[1] = count[0] = 0; |
---|
| 486 | } |
---|
| 487 | else |
---|
| 488 | { |
---|
| 489 | start[2] = 0; |
---|
[1553] | 490 | start[1] = domain->ibegin; |
---|
| 491 | start[0] = domain->jbegin; |
---|
[1099] | 492 | count[2] = domain->nvertex; |
---|
[1553] | 493 | count[1] = domain->ni; |
---|
| 494 | count[0] = domain->nj; |
---|
[617] | 495 | } |
---|
[1143] | 496 | |
---|
[1129] | 497 | SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0, &start, &count); |
---|
| 498 | SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0, &start, &count); |
---|
[617] | 499 | } |
---|
| 500 | |
---|
[611] | 501 | if (domain->hasArea) |
---|
| 502 | { |
---|
| 503 | std::vector<StdSize> start(2); |
---|
| 504 | std::vector<StdSize> count(2); |
---|
| 505 | |
---|
| 506 | if (domain->isEmpty()) |
---|
| 507 | { |
---|
| 508 | start[0] = 0; start[1] = 0; |
---|
| 509 | count[0] = 0; count[1] = 0; |
---|
| 510 | } |
---|
| 511 | else |
---|
| 512 | { |
---|
[1553] | 513 | start[1] = domain->ibegin; |
---|
| 514 | start[0] = domain->jbegin; |
---|
| 515 | count[1] = domain->ni; |
---|
| 516 | count[0] = domain->nj; |
---|
[611] | 517 | } |
---|
[1143] | 518 | |
---|
[1129] | 519 | SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0, &start, &count); |
---|
[611] | 520 | } |
---|
| 521 | |
---|
[498] | 522 | SuperClassWriter::definition_start(); |
---|
| 523 | break; |
---|
| 524 | } |
---|
| 525 | default : |
---|
| 526 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 527 | << "[ type = " << SuperClass::type << "]" |
---|
| 528 | << " not implemented yet !"); |
---|
| 529 | } |
---|
[449] | 530 | } |
---|
[498] | 531 | catch (CNetCdfException& e) |
---|
| 532 | { |
---|
| 533 | StdString msg("On writing the domain : "); |
---|
| 534 | msg.append(domid); msg.append("\n"); |
---|
| 535 | msg.append("In the context : "); |
---|
| 536 | msg.append(context->getId()); msg.append("\n"); |
---|
| 537 | msg.append(e.what()); |
---|
| 538 | ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg); |
---|
| 539 | } |
---|
| 540 | |
---|
[449] | 541 | domain->addRelFile(this->filename); |
---|
| 542 | } |
---|
[1646] | 543 | CATCH |
---|
[449] | 544 | |
---|
[879] | 545 | //-------------------------------------------------------------- |
---|
[878] | 546 | |
---|
[879] | 547 | void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain) |
---|
| 548 | { |
---|
| 549 | CContext* context = CContext::getCurrent() ; |
---|
| 550 | CContextServer* server=context->server ; |
---|
[878] | 551 | |
---|
[879] | 552 | if (domain->IsWritten(this->filename)) return; |
---|
[1494] | 553 | |
---|
| 554 | StdString domid = domain->getDomainOutputName(); |
---|
| 555 | |
---|
| 556 | // The first domain for the same mesh that will be written is that with the highest value of nvertex. |
---|
| 557 | // Thus the entire mesh connectivity will be generated at once. |
---|
| 558 | if (isWrittenDomain(domid)) return ; |
---|
| 559 | else setWrittenDomain(domid); |
---|
| 560 | |
---|
[879] | 561 | domain->checkAttributes(); |
---|
| 562 | if (domain->isEmpty()) |
---|
| 563 | if (SuperClass::type==MULTI_FILE) return ; |
---|
[878] | 564 | |
---|
[1158] | 565 | nc_type typePrec ; |
---|
| 566 | if (domain->prec.isEmpty()) typePrec = NC_FLOAT ; |
---|
| 567 | else if (domain->prec==4) typePrec = NC_FLOAT ; |
---|
| 568 | else if (domain->prec==8) typePrec = NC_DOUBLE ; |
---|
| 569 | |
---|
[879] | 570 | std::vector<StdString> dim0; |
---|
| 571 | StdString domainName = domain->name; |
---|
[924] | 572 | domain->assignMesh(domainName, domain->nvertex); |
---|
[1025] | 573 | domain->mesh->createMeshEpsilon(server->intraComm, domain->lonvalue, domain->latvalue, domain->bounds_lonvalue, domain->bounds_latvalue); |
---|
[878] | 574 | |
---|
[879] | 575 | StdString node_x = domainName + "_node_x"; |
---|
| 576 | StdString node_y = domainName + "_node_y"; |
---|
[878] | 577 | |
---|
[879] | 578 | StdString edge_x = domainName + "_edge_x"; |
---|
| 579 | StdString edge_y = domainName + "_edge_y"; |
---|
| 580 | StdString edge_nodes = domainName + "_edge_nodes"; |
---|
[878] | 581 | |
---|
[879] | 582 | StdString face_x = domainName + "_face_x"; |
---|
| 583 | StdString face_y = domainName + "_face_y"; |
---|
| 584 | StdString face_nodes = domainName + "_face_nodes"; |
---|
[902] | 585 | StdString face_edges = domainName + "_face_edges"; |
---|
| 586 | StdString edge_faces = domainName + "_edge_face_links"; |
---|
| 587 | StdString face_faces = domainName + "_face_links"; |
---|
[878] | 588 | |
---|
[879] | 589 | StdString dimNode = "n" + domainName + "_node"; |
---|
| 590 | StdString dimEdge = "n" + domainName + "_edge"; |
---|
| 591 | StdString dimFace = "n" + domainName + "_face"; |
---|
| 592 | StdString dimVertex = "n" + domainName + "_vertex"; |
---|
| 593 | StdString dimTwo = "Two"; |
---|
[878] | 594 | |
---|
[879] | 595 | if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2); |
---|
[1494] | 596 | dim0.clear(); |
---|
| 597 | SuperClassWriter::addVariable(domainName, NC_INT, dim0, compressionLevel); |
---|
| 598 | SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName); |
---|
| 599 | SuperClassWriter::addAttribute("long_name", StdString("Topology data of 2D unstructured mesh"), &domainName); |
---|
| 600 | SuperClassWriter::addAttribute("topology_dimension", 2, &domainName); |
---|
| 601 | SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName); |
---|
[878] | 602 | |
---|
[879] | 603 | try |
---|
| 604 | { |
---|
| 605 | switch (SuperClass::type) |
---|
| 606 | { |
---|
| 607 | case (ONE_FILE) : |
---|
| 608 | { |
---|
| 609 | // Adding nodes |
---|
| 610 | if (domain->nvertex == 1) |
---|
| 611 | { |
---|
| 612 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
| 613 | { |
---|
[902] | 614 | SuperClassWriter::addDimension(dimNode, domain->ni_glo); |
---|
[879] | 615 | dim0.clear(); |
---|
| 616 | dim0.push_back(dimNode); |
---|
[1456] | 617 | SuperClassWriter::addVariable(node_x, typePrec, dim0, compressionLevel); |
---|
[879] | 618 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
[924] | 619 | SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
[879] | 620 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
[1456] | 621 | SuperClassWriter::addVariable(node_y, typePrec, dim0, compressionLevel); |
---|
[879] | 622 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
[924] | 623 | SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
[879] | 624 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
| 625 | } |
---|
| 626 | } // domain->nvertex == 1 |
---|
[878] | 627 | |
---|
[879] | 628 | // Adding edges and nodes, if nodes have not been defined previously |
---|
| 629 | if (domain->nvertex == 2) |
---|
| 630 | { |
---|
| 631 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
| 632 | { |
---|
[924] | 633 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodesGlo); |
---|
[879] | 634 | dim0.clear(); |
---|
| 635 | dim0.push_back(dimNode); |
---|
[1456] | 636 | SuperClassWriter::addVariable(node_x, typePrec, dim0, compressionLevel); |
---|
[879] | 637 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
[924] | 638 | SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
[879] | 639 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
[1456] | 640 | SuperClassWriter::addVariable(node_y, typePrec, dim0, compressionLevel); |
---|
[879] | 641 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
[924] | 642 | SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
[879] | 643 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
| 644 | } |
---|
[924] | 645 | SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); |
---|
| 646 | SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); |
---|
| 647 | SuperClassWriter::addDimension(dimEdge, domain->ni_glo); |
---|
| 648 | dim0.clear(); |
---|
| 649 | dim0.push_back(dimEdge); |
---|
[1456] | 650 | SuperClassWriter::addVariable(edge_x, typePrec, dim0, compressionLevel); |
---|
[924] | 651 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); |
---|
| 652 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x); |
---|
| 653 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); |
---|
[1456] | 654 | SuperClassWriter::addVariable(edge_y, typePrec, dim0, compressionLevel); |
---|
[924] | 655 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); |
---|
| 656 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y); |
---|
| 657 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); |
---|
| 658 | dim0.clear(); |
---|
| 659 | dim0.push_back(dimEdge); |
---|
| 660 | dim0.push_back(dimTwo); |
---|
[1456] | 661 | SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0, compressionLevel); |
---|
[924] | 662 | SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); |
---|
| 663 | SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); |
---|
| 664 | SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); |
---|
[879] | 665 | } // domain->nvertex == 2 |
---|
[878] | 666 | |
---|
[879] | 667 | // Adding faces, edges, and nodes, if edges and nodes have not been defined previously |
---|
| 668 | if (domain->nvertex > 2) |
---|
| 669 | { |
---|
| 670 | // Nodes |
---|
| 671 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
| 672 | { |
---|
[924] | 673 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodesGlo); |
---|
[879] | 674 | dim0.clear(); |
---|
| 675 | dim0.push_back(dimNode); |
---|
[1456] | 676 | SuperClassWriter::addVariable(node_x, typePrec, dim0, compressionLevel); |
---|
[879] | 677 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
[924] | 678 | SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
[879] | 679 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
[1456] | 680 | SuperClassWriter::addVariable(node_y, typePrec, dim0, compressionLevel); |
---|
[879] | 681 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
[924] | 682 | SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
[879] | 683 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
| 684 | } |
---|
| 685 | if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y)) |
---|
| 686 | { |
---|
| 687 | SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); |
---|
| 688 | SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); |
---|
[924] | 689 | SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdgesGlo); |
---|
[879] | 690 | dim0.clear(); |
---|
| 691 | dim0.push_back(dimEdge); |
---|
[1456] | 692 | SuperClassWriter::addVariable(edge_x, typePrec, dim0, compressionLevel); |
---|
[879] | 693 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); |
---|
[924] | 694 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x); |
---|
[879] | 695 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); |
---|
[1456] | 696 | SuperClassWriter::addVariable(edge_y, typePrec, dim0, compressionLevel); |
---|
[879] | 697 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); |
---|
[924] | 698 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y); |
---|
[879] | 699 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); |
---|
| 700 | dim0.clear(); |
---|
| 701 | dim0.push_back(dimEdge); |
---|
| 702 | dim0.push_back(dimTwo); |
---|
[1456] | 703 | SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0, compressionLevel); |
---|
[879] | 704 | SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); |
---|
| 705 | SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); |
---|
| 706 | SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); |
---|
| 707 | } |
---|
[924] | 708 | SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName); |
---|
| 709 | SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName); |
---|
| 710 | SuperClassWriter::addDimension(dimFace, domain->ni_glo); |
---|
| 711 | SuperClassWriter::addDimension(dimVertex, domain->nvertex); |
---|
| 712 | dim0.clear(); |
---|
| 713 | dim0.push_back(dimFace); |
---|
[1456] | 714 | SuperClassWriter::addVariable(face_x, typePrec, dim0, compressionLevel); |
---|
[924] | 715 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x); |
---|
| 716 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh faces."), &face_x); |
---|
| 717 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x); |
---|
[1456] | 718 | SuperClassWriter::addVariable(face_y, typePrec, dim0, compressionLevel); |
---|
[924] | 719 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y); |
---|
| 720 | SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh faces."), &face_y); |
---|
| 721 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y); |
---|
| 722 | dim0.clear(); |
---|
| 723 | dim0.push_back(dimFace); |
---|
| 724 | dim0.push_back(dimVertex); |
---|
[1456] | 725 | SuperClassWriter::addVariable(face_nodes, NC_INT, dim0, compressionLevel); |
---|
[924] | 726 | SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes); |
---|
| 727 | SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes); |
---|
| 728 | SuperClassWriter::addAttribute("start_index", 0, &face_nodes); |
---|
| 729 | dim0.clear(); |
---|
| 730 | dim0.push_back(dimFace); |
---|
| 731 | dim0.push_back(dimVertex); |
---|
[1456] | 732 | SuperClassWriter::addVariable(face_edges, NC_INT, dim0, compressionLevel); |
---|
[924] | 733 | SuperClassWriter::addAttribute("cf_role", StdString("face_edge_connectivity"), &face_edges); |
---|
| 734 | SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its edges."), &face_edges); |
---|
| 735 | SuperClassWriter::addAttribute("start_index", 0, &face_edges); |
---|
[929] | 736 | SuperClassWriter::addAttribute("_FillValue", 999999, &face_edges); |
---|
[924] | 737 | dim0.clear(); |
---|
| 738 | dim0.push_back(dimEdge); |
---|
| 739 | dim0.push_back(dimTwo); |
---|
[1456] | 740 | SuperClassWriter::addVariable(edge_faces, NC_INT, dim0, compressionLevel); |
---|
[924] | 741 | SuperClassWriter::addAttribute("cf_role", StdString("edge_face connectivity"), &edge_faces); |
---|
| 742 | SuperClassWriter::addAttribute("long_name", StdString("neighbor faces for edges"), &edge_faces); |
---|
| 743 | SuperClassWriter::addAttribute("start_index", 0, &edge_faces); |
---|
| 744 | SuperClassWriter::addAttribute("_FillValue", -999, &edge_faces); |
---|
| 745 | SuperClassWriter::addAttribute("comment", StdString("missing neighbor faces are indicated using _FillValue"), &edge_faces); |
---|
| 746 | dim0.clear(); |
---|
| 747 | dim0.push_back(dimFace); |
---|
| 748 | dim0.push_back(dimVertex); |
---|
[1456] | 749 | SuperClassWriter::addVariable(face_faces, NC_INT, dim0, compressionLevel); |
---|
[924] | 750 | SuperClassWriter::addAttribute("cf_role", StdString("face_face connectivity"), &face_faces); |
---|
| 751 | SuperClassWriter::addAttribute("long_name", StdString("Indicates which other faces neighbor each face"), &face_faces); |
---|
| 752 | SuperClassWriter::addAttribute("start_index", 0, &face_faces); |
---|
[929] | 753 | SuperClassWriter::addAttribute("_FillValue", 999999, &face_faces); |
---|
[924] | 754 | SuperClassWriter::addAttribute("flag_values", -1, &face_faces); |
---|
| 755 | SuperClassWriter::addAttribute("flag_meanings", StdString("out_of_mesh"), &face_faces); |
---|
[879] | 756 | } // domain->nvertex > 2 |
---|
[878] | 757 | |
---|
[879] | 758 | SuperClassWriter::definition_end(); |
---|
[878] | 759 | |
---|
[924] | 760 | std::vector<StdSize> startEdges(1) ; |
---|
| 761 | std::vector<StdSize> countEdges(1) ; |
---|
| 762 | std::vector<StdSize> startNodes(1) ; |
---|
| 763 | std::vector<StdSize> countNodes(1) ; |
---|
| 764 | std::vector<StdSize> startFaces(1) ; |
---|
| 765 | std::vector<StdSize> countFaces(1) ; |
---|
| 766 | std::vector<StdSize> startEdgeNodes(2) ; |
---|
| 767 | std::vector<StdSize> countEdgeNodes(2) ; |
---|
| 768 | std::vector<StdSize> startEdgeFaces(2) ; |
---|
| 769 | std::vector<StdSize> countEdgeFaces(2) ; |
---|
| 770 | std::vector<StdSize> startFaceConctv(2) ; |
---|
| 771 | std::vector<StdSize> countFaceConctv(2) ; |
---|
[902] | 772 | |
---|
[1494] | 773 | if (domain->nvertex == 1) |
---|
[879] | 774 | { |
---|
[1494] | 775 | if (domain->isEmpty()) |
---|
| 776 | { |
---|
| 777 | startNodes[0]=0 ; |
---|
| 778 | countNodes[0]=0 ; |
---|
| 779 | } |
---|
| 780 | else |
---|
| 781 | { |
---|
[1553] | 782 | startNodes[0] = domain->ibegin; |
---|
| 783 | countNodes[0] = domain->ni ; |
---|
[1494] | 784 | } |
---|
[924] | 785 | |
---|
[1494] | 786 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes); |
---|
| 787 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes); |
---|
| 788 | } |
---|
| 789 | else if (domain->nvertex == 2) |
---|
| 790 | { |
---|
| 791 | if (domain->isEmpty()) |
---|
| 792 | { |
---|
| 793 | startEdges[0]=0 ; |
---|
| 794 | countEdges[0]=0 ; |
---|
| 795 | startNodes[0]=0 ; |
---|
| 796 | countNodes[0]=0 ; |
---|
| 797 | startEdgeNodes[0]=0; |
---|
| 798 | startEdgeNodes[1]=0; |
---|
| 799 | countEdgeNodes[0]=0; |
---|
| 800 | countEdgeNodes[1]=0; |
---|
[924] | 801 | |
---|
[1494] | 802 | } |
---|
| 803 | else |
---|
| 804 | { |
---|
[1553] | 805 | startEdges[0] = domain->ibegin; |
---|
| 806 | countEdges[0] = domain->ni; |
---|
[1494] | 807 | startNodes[0] = domain->mesh->node_start; |
---|
| 808 | countNodes[0] = domain->mesh->node_count; |
---|
[1553] | 809 | startEdgeNodes[0] = domain->ibegin; |
---|
[1494] | 810 | startEdgeNodes[1] = 0; |
---|
[1553] | 811 | countEdgeNodes[0] = domain->ni; |
---|
[1494] | 812 | countEdgeNodes[1] = 2; |
---|
| 813 | } |
---|
| 814 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes); |
---|
| 815 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes); |
---|
| 816 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges); |
---|
| 817 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges); |
---|
| 818 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes); |
---|
| 819 | } |
---|
[879] | 820 | else |
---|
| 821 | { |
---|
[1494] | 822 | if (domain->isEmpty()) |
---|
| 823 | { |
---|
| 824 | startFaces[0] = 0 ; |
---|
| 825 | countFaces[0] = 0 ; |
---|
| 826 | startNodes[0] = 0; |
---|
| 827 | countNodes[0] = 0; |
---|
| 828 | startEdges[0] = 0; |
---|
| 829 | countEdges[0] = 0; |
---|
| 830 | startEdgeFaces[0] = 0; |
---|
| 831 | startEdgeFaces[1] = 0; |
---|
| 832 | countEdgeFaces[0] = 0; |
---|
| 833 | countEdgeFaces[1] = 0; |
---|
| 834 | startFaceConctv[0] = 0; |
---|
| 835 | startFaceConctv[1] = 0; |
---|
| 836 | countFaceConctv[0] = 0; |
---|
| 837 | countFaceConctv[1] = 0; |
---|
| 838 | } |
---|
| 839 | else |
---|
| 840 | { |
---|
[1553] | 841 | startFaces[0] = domain->ibegin; |
---|
| 842 | countFaces[0] = domain->ni ; |
---|
[1494] | 843 | startNodes[0] = domain->mesh->node_start; |
---|
| 844 | countNodes[0] = domain->mesh->node_count; |
---|
| 845 | startEdges[0] = domain->mesh->edge_start; |
---|
| 846 | countEdges[0] = domain->mesh->edge_count; |
---|
| 847 | startEdgeNodes[0] = domain->mesh->edge_start; |
---|
| 848 | startEdgeNodes[1] = 0; |
---|
| 849 | countEdgeNodes[0] = domain->mesh->edge_count; |
---|
| 850 | countEdgeNodes[1]= 2; |
---|
| 851 | startEdgeFaces[0] = domain->mesh->edge_start; |
---|
| 852 | startEdgeFaces[1]= 0; |
---|
| 853 | countEdgeFaces[0] = domain->mesh->edge_count; |
---|
| 854 | countEdgeFaces[1]= 2; |
---|
[1553] | 855 | startFaceConctv[0] = domain->ibegin; |
---|
[1494] | 856 | startFaceConctv[1] = 0; |
---|
[1553] | 857 | countFaceConctv[0] = domain->ni; |
---|
[1494] | 858 | countFaceConctv[1] = domain->nvertex; |
---|
| 859 | } |
---|
| 860 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes); |
---|
| 861 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes); |
---|
| 862 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges); |
---|
| 863 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges); |
---|
| 864 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes); |
---|
| 865 | SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0, &startFaces, &countFaces); |
---|
| 866 | SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0, &startFaces, &countFaces); |
---|
| 867 | SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 868 | SuperClassWriter::writeData(domain->mesh->face_edges, face_edges, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 869 | SuperClassWriter::writeData(domain->mesh->edge_faces, edge_faces, isCollective, 0, &startEdgeFaces, &countEdgeFaces); |
---|
| 870 | SuperClassWriter::writeData(domain->mesh->face_faces, face_faces, isCollective, 0, &startFaceConctv, &countFaceConctv); |
---|
| 871 | } |
---|
[879] | 872 | SuperClassWriter::definition_start(); |
---|
[878] | 873 | |
---|
[879] | 874 | break; |
---|
| 875 | } // ONE_FILE |
---|
[878] | 876 | |
---|
[879] | 877 | case (MULTI_FILE) : |
---|
| 878 | { |
---|
[1646] | 879 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 880 | << "[ type = multiple_file ]" |
---|
| 881 | << " is not yet implemented for UGRID files !"); |
---|
[879] | 882 | break; |
---|
| 883 | } |
---|
[878] | 884 | |
---|
[879] | 885 | default : |
---|
| 886 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 887 | << "[ type = " << SuperClass::type << "]" |
---|
| 888 | << " not implemented yet !"); |
---|
| 889 | } // switch |
---|
| 890 | } // try |
---|
[878] | 891 | |
---|
[879] | 892 | catch (CNetCdfException& e) |
---|
| 893 | { |
---|
| 894 | StdString msg("On writing the domain : "); |
---|
| 895 | msg.append(domid); msg.append("\n"); |
---|
| 896 | msg.append("In the context : "); |
---|
| 897 | msg.append(context->getId()); msg.append("\n"); |
---|
| 898 | msg.append(e.what()); |
---|
[924] | 899 | ERROR("CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain)", << msg); |
---|
[879] | 900 | } |
---|
[878] | 901 | |
---|
[879] | 902 | domain->addRelFile(this->filename); |
---|
| 903 | } |
---|
[878] | 904 | |
---|
[879] | 905 | //-------------------------------------------------------------- |
---|
[878] | 906 | |
---|
[879] | 907 | void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain) |
---|
[449] | 908 | { |
---|
| 909 | CContext* context = CContext::getCurrent() ; |
---|
| 910 | CContextServer* server=context->server ; |
---|
[488] | 911 | |
---|
[449] | 912 | if (domain->IsWritten(this->filename)) return; |
---|
| 913 | domain->checkAttributes(); |
---|
[488] | 914 | |
---|
| 915 | if (domain->isEmpty()) |
---|
[449] | 916 | if (SuperClass::type==MULTI_FILE) return ; |
---|
| 917 | |
---|
| 918 | std::vector<StdString> dim0, dim1; |
---|
[772] | 919 | StdString domid = domain->getDomainOutputName(); |
---|
[705] | 920 | if (isWrittenDomain(domid)) return ; |
---|
[774] | 921 | else setWrittenDomain(domid); |
---|
[705] | 922 | |
---|
[449] | 923 | StdString appendDomid = (singleDomain) ? "" : "_"+domid ; |
---|
| 924 | |
---|
[1430] | 925 | StdString lonName,latName, cellName ; |
---|
[1391] | 926 | if (domain->lon_name.isEmpty()) lonName = "lon"; |
---|
| 927 | else lonName = domain->lon_name; |
---|
| 928 | |
---|
| 929 | if (domain->lat_name.isEmpty()) latName = "lat"; |
---|
| 930 | else latName = domain->lat_name; |
---|
| 931 | |
---|
[1430] | 932 | if (!domain->dim_i_name.isEmpty()) cellName=domain->dim_i_name; |
---|
| 933 | else cellName="cell"; |
---|
| 934 | StdString dimXid = cellName+appendDomid; |
---|
[449] | 935 | StdString dimVertId = StdString("nvertex").append(appendDomid); |
---|
[488] | 936 | |
---|
[449] | 937 | string lonid,latid,bounds_lonid,bounds_latid ; |
---|
[611] | 938 | string areaId = "area" + appendDomid; |
---|
[449] | 939 | |
---|
[1158] | 940 | nc_type typePrec ; |
---|
| 941 | if (domain->prec.isEmpty()) typePrec = NC_FLOAT ; |
---|
| 942 | else if (domain->prec==4) typePrec = NC_FLOAT ; |
---|
| 943 | else if (domain->prec==8) typePrec = NC_DOUBLE ; |
---|
| 944 | |
---|
[1132] | 945 | int nvertex = (domain->nvertex.isEmpty()) ? 0 : domain->nvertex; |
---|
[1025] | 946 | |
---|
[1646] | 947 | CArray<int, 1>& indexToWrite = domain->localIndexToWriteOnServer; |
---|
[1132] | 948 | int nbWritten = indexToWrite.numElements(); |
---|
| 949 | CArray<double,1> writtenLat, writtenLon; |
---|
| 950 | CArray<double,2> writtenBndsLat, writtenBndsLon; |
---|
| 951 | CArray<double,1> writtenArea; |
---|
| 952 | |
---|
| 953 | if (domain->hasLonLat) |
---|
| 954 | { |
---|
| 955 | writtenLat.resize(nbWritten); |
---|
| 956 | writtenLon.resize(nbWritten); |
---|
| 957 | for (int idx = 0; idx < nbWritten; ++idx) |
---|
| 958 | { |
---|
[1646] | 959 | if (indexToWrite(idx) < 0) |
---|
| 960 | { |
---|
| 961 | writtenLat(idx) = -1.; |
---|
| 962 | writtenLon(idx) = -1.; |
---|
| 963 | } |
---|
| 964 | else |
---|
| 965 | { |
---|
| 966 | writtenLat(idx) = domain->latvalue(indexToWrite(idx)); |
---|
| 967 | writtenLon(idx) = domain->lonvalue(indexToWrite(idx)); |
---|
| 968 | } |
---|
[1132] | 969 | } |
---|
[1390] | 970 | } |
---|
[1132] | 971 | |
---|
[1390] | 972 | if (domain->hasBounds) |
---|
| 973 | { |
---|
| 974 | int nvertex = domain->nvertex, idx; |
---|
| 975 | writtenBndsLat.resize(nvertex, nbWritten); |
---|
| 976 | writtenBndsLon.resize(nvertex, nbWritten); |
---|
| 977 | CArray<double,2>& boundslat = domain->bounds_latvalue; |
---|
| 978 | CArray<double,2>& boundslon = domain->bounds_lonvalue; |
---|
| 979 | for (idx = 0; idx < nbWritten; ++idx) |
---|
| 980 | { |
---|
| 981 | for (int nv = 0; nv < nvertex; ++nv) |
---|
| 982 | { |
---|
[1646] | 983 | if (indexToWrite(idx) < 0) |
---|
[1132] | 984 | { |
---|
[1646] | 985 | writtenBndsLat(nv, idx) = -1.; |
---|
| 986 | writtenBndsLon(nv, idx) = -1.; |
---|
[1132] | 987 | } |
---|
[1390] | 988 | else |
---|
| 989 | { |
---|
[1646] | 990 | writtenBndsLat(nv, idx) = boundslat(nv, int(indexToWrite(idx))); |
---|
| 991 | writtenBndsLon(nv, idx) = boundslon(nv, int(indexToWrite(idx))); |
---|
[1390] | 992 | } |
---|
| 993 | } |
---|
[1132] | 994 | } |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | if (domain->hasArea) |
---|
| 998 | { |
---|
| 999 | writtenArea.resize(nbWritten); |
---|
| 1000 | for (int idx = 0; idx < nbWritten; ++idx) |
---|
| 1001 | { |
---|
[1646] | 1002 | if (indexToWrite(idx) < 0) |
---|
| 1003 | writtenArea(idx) = -1.; |
---|
| 1004 | else |
---|
| 1005 | writtenArea(idx) = domain->areavalue(indexToWrite(idx)); |
---|
[1132] | 1006 | } |
---|
| 1007 | } |
---|
| 1008 | |
---|
[498] | 1009 | try |
---|
[449] | 1010 | { |
---|
[498] | 1011 | switch (SuperClass::type) |
---|
| 1012 | { |
---|
| 1013 | case (MULTI_FILE) : |
---|
| 1014 | { |
---|
| 1015 | dim0.push_back(dimXid); |
---|
[1553] | 1016 | SuperClassWriter::addDimension(dimXid, domain->ni); |
---|
[488] | 1017 | |
---|
[1415] | 1018 | lonid = lonName+appendDomid; |
---|
| 1019 | latid = latName+appendDomid; |
---|
[1430] | 1020 | if (!domain->bounds_lon_name.isEmpty()) bounds_lonid = domain->bounds_lon_name; |
---|
| 1021 | else bounds_lonid = "bounds_"+lonName+appendDomid; |
---|
| 1022 | if (!domain->bounds_lat_name.isEmpty()) bounds_latid = domain->bounds_lat_name; |
---|
| 1023 | else bounds_latid = "bounds_"+latName+appendDomid; |
---|
| 1024 | |
---|
[665] | 1025 | if (domain->hasLonLat) |
---|
| 1026 | { |
---|
[1456] | 1027 | SuperClassWriter::addVariable(latid, typePrec, dim0, compressionLevel); |
---|
| 1028 | SuperClassWriter::addVariable(lonid, typePrec, dim0, compressionLevel); |
---|
[665] | 1029 | this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 1030 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); |
---|
| 1031 | this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid); |
---|
| 1032 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); |
---|
| 1033 | if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
| 1034 | } |
---|
[498] | 1035 | dim0.clear(); |
---|
| 1036 | if (domain->hasBounds) |
---|
| 1037 | { |
---|
| 1038 | dim0.push_back(dimXid); |
---|
| 1039 | dim0.push_back(dimVertId); |
---|
[1456] | 1040 | SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0, compressionLevel); |
---|
| 1041 | SuperClassWriter::addVariable(bounds_latid, typePrec, dim0, compressionLevel); |
---|
[498] | 1042 | } |
---|
| 1043 | |
---|
| 1044 | dim0.clear(); |
---|
[449] | 1045 | dim0.push_back(dimXid); |
---|
[611] | 1046 | if (domain->hasArea) |
---|
| 1047 | { |
---|
[1456] | 1048 | SuperClassWriter::addVariable(areaId, typePrec, dim0, compressionLevel); |
---|
[614] | 1049 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 1050 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 1051 | } |
---|
| 1052 | |
---|
[498] | 1053 | SuperClassWriter::definition_end(); |
---|
[449] | 1054 | |
---|
[665] | 1055 | if (domain->hasLonLat) |
---|
[498] | 1056 | { |
---|
[1132] | 1057 | SuperClassWriter::writeData(writtenLat, latid, isCollective, 0); |
---|
| 1058 | SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0); |
---|
[665] | 1059 | if (domain->hasBounds) |
---|
| 1060 | { |
---|
[1132] | 1061 | SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0); |
---|
| 1062 | SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0); |
---|
[665] | 1063 | } |
---|
[498] | 1064 | } |
---|
[611] | 1065 | |
---|
| 1066 | if (domain->hasArea) |
---|
[1132] | 1067 | SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0); |
---|
[611] | 1068 | |
---|
[498] | 1069 | SuperClassWriter::definition_start(); |
---|
| 1070 | break ; |
---|
| 1071 | } |
---|
[488] | 1072 | |
---|
[498] | 1073 | case (ONE_FILE) : |
---|
| 1074 | { |
---|
[1415] | 1075 | lonid = lonName+appendDomid; |
---|
| 1076 | latid = latName+appendDomid; |
---|
[1430] | 1077 | if (!domain->bounds_lon_name.isEmpty()) bounds_lonid = domain->bounds_lon_name; |
---|
| 1078 | else bounds_lonid = "bounds_"+lonName+appendDomid; |
---|
| 1079 | if (!domain->bounds_lat_name.isEmpty()) bounds_latid = domain->bounds_lat_name; |
---|
| 1080 | else bounds_latid = "bounds_"+latName+appendDomid; |
---|
[1391] | 1081 | |
---|
[498] | 1082 | dim0.push_back(dimXid); |
---|
[1132] | 1083 | SuperClassWriter::addDimension(dimXid, domain->ni_glo); |
---|
[665] | 1084 | if (domain->hasLonLat) |
---|
| 1085 | { |
---|
[1456] | 1086 | SuperClassWriter::addVariable(latid, typePrec, dim0, compressionLevel); |
---|
| 1087 | SuperClassWriter::addVariable(lonid, typePrec, dim0, compressionLevel); |
---|
[665] | 1088 | |
---|
| 1089 | this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); |
---|
| 1090 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); |
---|
| 1091 | this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid); |
---|
| 1092 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); |
---|
[1025] | 1093 | if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, nvertex); |
---|
[665] | 1094 | } |
---|
[498] | 1095 | dim0.clear(); |
---|
[449] | 1096 | |
---|
[498] | 1097 | if (domain->hasBounds) |
---|
| 1098 | { |
---|
| 1099 | dim0.push_back(dimXid); |
---|
| 1100 | dim0.push_back(dimVertId); |
---|
[1456] | 1101 | SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0, compressionLevel); |
---|
| 1102 | SuperClassWriter::addVariable(bounds_latid, typePrec, dim0, compressionLevel); |
---|
[498] | 1103 | } |
---|
[488] | 1104 | |
---|
[611] | 1105 | if (domain->hasArea) |
---|
| 1106 | { |
---|
| 1107 | dim0.clear(); |
---|
| 1108 | dim0.push_back(dimXid); |
---|
[1456] | 1109 | SuperClassWriter::addVariable(areaId, typePrec, dim0, compressionLevel); |
---|
[614] | 1110 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
[611] | 1111 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
| 1112 | } |
---|
| 1113 | |
---|
[498] | 1114 | SuperClassWriter::definition_end(); |
---|
[488] | 1115 | |
---|
[498] | 1116 | std::vector<StdSize> start(1), startBounds(2) ; |
---|
| 1117 | std::vector<StdSize> count(1), countBounds(2) ; |
---|
| 1118 | if (domain->isEmpty()) |
---|
| 1119 | { |
---|
| 1120 | start[0]=0 ; |
---|
| 1121 | count[0]=0 ; |
---|
| 1122 | startBounds[1]=0 ; |
---|
[1025] | 1123 | countBounds[1]=nvertex ; |
---|
[498] | 1124 | startBounds[0]=0 ; |
---|
| 1125 | countBounds[0]=0 ; |
---|
| 1126 | } |
---|
| 1127 | else |
---|
| 1128 | { |
---|
[1553] | 1129 | start[0]=domain->ibegin; |
---|
| 1130 | count[0]=domain->ni; |
---|
| 1131 | startBounds[0]=domain->ibegin; |
---|
[498] | 1132 | startBounds[1]=0 ; |
---|
[1553] | 1133 | countBounds[0]=domain->ni; |
---|
[1025] | 1134 | countBounds[1]=nvertex ; |
---|
[498] | 1135 | } |
---|
[665] | 1136 | |
---|
| 1137 | if (domain->hasLonLat) |
---|
[498] | 1138 | { |
---|
[1132] | 1139 | SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count); |
---|
| 1140 | SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count); |
---|
[665] | 1141 | if (domain->hasBounds) |
---|
| 1142 | { |
---|
[1132] | 1143 | SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0,&startBounds,&countBounds); |
---|
| 1144 | SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0,&startBounds,&countBounds); |
---|
[665] | 1145 | } |
---|
[498] | 1146 | } |
---|
[488] | 1147 | |
---|
[611] | 1148 | if (domain->hasArea) |
---|
[1132] | 1149 | SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0, &start, &count); |
---|
[488] | 1150 | |
---|
[498] | 1151 | SuperClassWriter::definition_start(); |
---|
[488] | 1152 | |
---|
[498] | 1153 | break; |
---|
| 1154 | } |
---|
| 1155 | default : |
---|
| 1156 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
| 1157 | << "[ type = " << SuperClass::type << "]" |
---|
| 1158 | << " not implemented yet !"); |
---|
| 1159 | } |
---|
[219] | 1160 | } |
---|
[498] | 1161 | catch (CNetCdfException& e) |
---|
| 1162 | { |
---|
| 1163 | StdString msg("On writing the domain : "); |
---|
| 1164 | msg.append(domid); msg.append("\n"); |
---|
| 1165 | msg.append("In the context : "); |
---|
| 1166 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1167 | msg.append(e.what()); |
---|
| 1168 | ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg); |
---|
| 1169 | } |
---|
[219] | 1170 | domain->addRelFile(this->filename); |
---|
| 1171 | } |
---|
| 1172 | //-------------------------------------------------------------- |
---|
| 1173 | |
---|
[347] | 1174 | void CNc4DataOutput::writeAxis_(CAxis* axis) |
---|
[219] | 1175 | { |
---|
[1030] | 1176 | if (axis->IsWritten(this->filename)) return; |
---|
| 1177 | axis->checkAttributes(); |
---|
[488] | 1178 | |
---|
[1129] | 1179 | axis->computeWrittenIndex(); |
---|
[1249] | 1180 | axis->computeWrittenCompressedIndex(comm_file); |
---|
[1129] | 1181 | |
---|
[1559] | 1182 | int size = (MULTI_FILE == SuperClass::type) ? axis->n.getValue() |
---|
| 1183 | : axis->n_glo.getValue(); |
---|
[1099] | 1184 | |
---|
[1559] | 1185 | if ((0 == axis->n) && (MULTI_FILE == SuperClass::type)) return; |
---|
[1235] | 1186 | |
---|
[1030] | 1187 | std::vector<StdString> dims; |
---|
| 1188 | StdString axisid = axis->getAxisOutputName(); |
---|
[1435] | 1189 | StdString axisDim, axisBoundsId; |
---|
[1030] | 1190 | if (isWrittenAxis(axisid)) return ; |
---|
| 1191 | else setWrittenAxis(axisid); |
---|
[705] | 1192 | |
---|
[1158] | 1193 | nc_type typePrec ; |
---|
| 1194 | if (axis->prec.isEmpty()) typePrec = NC_FLOAT ; |
---|
[1235] | 1195 | else if (axis->prec==4) typePrec = NC_FLOAT ; |
---|
[1158] | 1196 | else if (axis->prec==8) typePrec = NC_DOUBLE ; |
---|
| 1197 | |
---|
| 1198 | if (!axis->label.isEmpty()) typePrec = NC_CHAR ; |
---|
| 1199 | string strId="str_len" ; |
---|
[1030] | 1200 | try |
---|
| 1201 | { |
---|
[1433] | 1202 | if (axis->dim_name.isEmpty()) axisDim = axisid; |
---|
| 1203 | else axisDim=axis->dim_name.getValue(); |
---|
[1559] | 1204 | SuperClassWriter::addDimension(axisDim, size); |
---|
[1433] | 1205 | dims.push_back(axisDim); |
---|
| 1206 | |
---|
[1439] | 1207 | if (!axis->label.isEmpty() && !SuperClassWriter::dimExist(strId)) SuperClassWriter::addDimension(strId, stringArrayLen); |
---|
[1433] | 1208 | |
---|
[1435] | 1209 | if (axis->hasValue || !axis->label.isEmpty()) |
---|
[816] | 1210 | { |
---|
[1158] | 1211 | if (!axis->label.isEmpty()) dims.push_back(strId); |
---|
[1430] | 1212 | |
---|
[1456] | 1213 | SuperClassWriter::addVariable(axisid, typePrec, dims, compressionLevel); |
---|
[219] | 1214 | |
---|
[1030] | 1215 | if (!axis->name.isEmpty()) |
---|
| 1216 | SuperClassWriter::addAttribute("name", axis->name.getValue(), &axisid); |
---|
[219] | 1217 | |
---|
[1030] | 1218 | if (!axis->standard_name.isEmpty()) |
---|
| 1219 | SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisid); |
---|
[540] | 1220 | |
---|
[1030] | 1221 | if (!axis->long_name.isEmpty()) |
---|
| 1222 | SuperClassWriter::addAttribute("long_name", axis->long_name.getValue(), &axisid); |
---|
[219] | 1223 | |
---|
[1030] | 1224 | if (!axis->unit.isEmpty()) |
---|
| 1225 | SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisid); |
---|
[219] | 1226 | |
---|
[1430] | 1227 | if (!axis->axis_type.isEmpty()) |
---|
| 1228 | { |
---|
| 1229 | switch(axis->axis_type) |
---|
| 1230 | { |
---|
| 1231 | case CAxis::axis_type_attr::X : |
---|
| 1232 | SuperClassWriter::addAttribute("axis", string("X"), &axisid); |
---|
| 1233 | break; |
---|
| 1234 | case CAxis::axis_type_attr::Y : |
---|
| 1235 | SuperClassWriter::addAttribute("axis", string("Y"), &axisid); |
---|
| 1236 | break; |
---|
| 1237 | case CAxis::axis_type_attr::Z : |
---|
| 1238 | SuperClassWriter::addAttribute("axis", string("Z"), &axisid); |
---|
| 1239 | break; |
---|
| 1240 | case CAxis::axis_type_attr::T : |
---|
| 1241 | SuperClassWriter::addAttribute("axis", string("T"), &axisid); |
---|
| 1242 | break; |
---|
| 1243 | } |
---|
| 1244 | } |
---|
| 1245 | |
---|
[1030] | 1246 | if (!axis->positive.isEmpty()) |
---|
| 1247 | { |
---|
| 1248 | SuperClassWriter::addAttribute("positive", |
---|
| 1249 | (axis->positive == CAxis::positive_attr::up) ? string("up") : string("down"), |
---|
| 1250 | &axisid); |
---|
| 1251 | } |
---|
[399] | 1252 | |
---|
[1266] | 1253 | if (!axis->formula.isEmpty()) |
---|
| 1254 | SuperClassWriter::addAttribute("formula", axis->formula.getValue(), &axisid); |
---|
| 1255 | |
---|
| 1256 | if (!axis->formula_term.isEmpty()) |
---|
| 1257 | SuperClassWriter::addAttribute("formula_term", axis->formula_term.getValue(), &axisid); |
---|
| 1258 | |
---|
[1435] | 1259 | axisBoundsId = (axis->bounds_name.isEmpty()) ? axisid + "_bounds" : axis->bounds_name; |
---|
[1249] | 1260 | if (!axis->bounds.isEmpty() && axis->label.isEmpty()) |
---|
[1030] | 1261 | { |
---|
| 1262 | dims.push_back("axis_nbounds"); |
---|
[1456] | 1263 | SuperClassWriter::addVariable(axisBoundsId, typePrec, dims, compressionLevel); |
---|
[1030] | 1264 | SuperClassWriter::addAttribute("bounds", axisBoundsId, &axisid); |
---|
[1288] | 1265 | |
---|
| 1266 | if (!axis->standard_name.isEmpty()) |
---|
| 1267 | SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisBoundsId); |
---|
| 1268 | |
---|
| 1269 | if (!axis->unit.isEmpty()) |
---|
| 1270 | SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisBoundsId); |
---|
| 1271 | |
---|
[1266] | 1272 | if (!axis->formula_bounds.isEmpty()) |
---|
[1288] | 1273 | SuperClassWriter::addAttribute("formula", axis->formula_bounds.getValue(), &axisBoundsId); |
---|
[1266] | 1274 | |
---|
| 1275 | if (!axis->formula_term_bounds.isEmpty()) |
---|
[1288] | 1276 | SuperClassWriter::addAttribute("formula_term", axis->formula_term_bounds.getValue(), &axisBoundsId); |
---|
[1030] | 1277 | } |
---|
[1435] | 1278 | } |
---|
[816] | 1279 | |
---|
[1435] | 1280 | SuperClassWriter::definition_end(); |
---|
| 1281 | |
---|
[1646] | 1282 | CArray<int, 1>& indexToWrite = axis->localIndexToWriteOnServer; |
---|
[1435] | 1283 | int nbWritten = indexToWrite.numElements(); |
---|
| 1284 | CArray<double,1> axis_value(indexToWrite.numElements()); |
---|
| 1285 | if (!axis->value.isEmpty()) |
---|
| 1286 | { |
---|
[1421] | 1287 | for (int i = 0; i < nbWritten; i++) |
---|
| 1288 | { |
---|
[1646] | 1289 | if (indexToWrite(i) < 0) |
---|
| 1290 | axis_value(i) = -1; // Some value in case of a hole |
---|
| 1291 | else |
---|
[1421] | 1292 | axis_value(i) = axis->value(indexToWrite(i)); |
---|
| 1293 | } |
---|
[1435] | 1294 | } |
---|
| 1295 | CArray<double,2> axis_bounds; |
---|
| 1296 | CArray<string,1> axis_label; |
---|
| 1297 | if (!axis->label.isEmpty()) |
---|
| 1298 | { |
---|
| 1299 | axis_label.resize(indexToWrite.numElements()); |
---|
| 1300 | for (int i = 0; i < nbWritten; i++) |
---|
[1235] | 1301 | { |
---|
[1646] | 1302 | if (indexToWrite(i) < 0) |
---|
| 1303 | axis_label(i) = boost::lexical_cast<string>(-1); // Some value in case of a hole |
---|
| 1304 | else |
---|
[1435] | 1305 | axis_label(i) = axis->label(indexToWrite(i)); |
---|
[1235] | 1306 | } |
---|
[1435] | 1307 | } |
---|
[1129] | 1308 | |
---|
[1435] | 1309 | switch (SuperClass::type) |
---|
| 1310 | { |
---|
| 1311 | case MULTI_FILE: |
---|
[1030] | 1312 | { |
---|
[1435] | 1313 | if (axis->label.isEmpty()) |
---|
[1437] | 1314 | { |
---|
| 1315 | if (!axis->value.isEmpty()) |
---|
| 1316 | SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); |
---|
[633] | 1317 | |
---|
[1437] | 1318 | if (!axis->bounds.isEmpty()) |
---|
| 1319 | { |
---|
[1129] | 1320 | axis_bounds.resize(2, indexToWrite.numElements()); |
---|
| 1321 | for (int i = 0; i < nbWritten; ++i) |
---|
| 1322 | { |
---|
[1646] | 1323 | if (indexToWrite(i) < 0) |
---|
[1421] | 1324 | { |
---|
[1646] | 1325 | axis_bounds(0, i) = -1.; // Some value in case of a hole |
---|
| 1326 | axis_bounds(1, i) = -1.; |
---|
[1421] | 1327 | } |
---|
| 1328 | else |
---|
| 1329 | { |
---|
[1646] | 1330 | axis_bounds(0, i) = axis->bounds(0, int(indexToWrite(i))); |
---|
| 1331 | axis_bounds(1, i) = axis->bounds(1, int(indexToWrite(i))); |
---|
[1421] | 1332 | } |
---|
[1129] | 1333 | } |
---|
[1437] | 1334 | SuperClassWriter::writeData(axis_bounds, axisBoundsId, isCollective, 0); |
---|
| 1335 | } |
---|
[1435] | 1336 | } |
---|
[1437] | 1337 | else |
---|
[1435] | 1338 | SuperClassWriter::writeData(axis_label, axisid, isCollective, 0); |
---|
| 1339 | |
---|
| 1340 | SuperClassWriter::definition_start(); |
---|
| 1341 | break; |
---|
| 1342 | } |
---|
| 1343 | case ONE_FILE: |
---|
| 1344 | { |
---|
| 1345 | std::vector<StdSize> start(1), startBounds(2) ; |
---|
| 1346 | std::vector<StdSize> count(1), countBounds(2) ; |
---|
[1559] | 1347 | start[0] = startBounds[0] = axis->begin; |
---|
| 1348 | count[0] = countBounds[0] = axis->n; |
---|
[1435] | 1349 | startBounds[1] = 0; |
---|
| 1350 | countBounds[1] = 2; |
---|
| 1351 | |
---|
| 1352 | if (axis->label.isEmpty()) |
---|
[1437] | 1353 | { |
---|
| 1354 | if (!axis->value.isEmpty()) |
---|
| 1355 | SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count); |
---|
[1435] | 1356 | |
---|
[1437] | 1357 | if (!axis->bounds.isEmpty()) |
---|
[1235] | 1358 | { |
---|
[1437] | 1359 | axis_bounds.resize(2, indexToWrite.numElements()); |
---|
| 1360 | for (int i = 0; i < nbWritten; ++i) |
---|
[1435] | 1361 | { |
---|
[1646] | 1362 | if (indexToWrite(i) < 0) |
---|
[1437] | 1363 | { |
---|
[1646] | 1364 | axis_bounds(0, i) = -1.; |
---|
| 1365 | axis_bounds(1, i) = -1.; |
---|
[1437] | 1366 | } |
---|
| 1367 | else |
---|
| 1368 | { |
---|
[1646] | 1369 | axis_bounds(0, i) = axis->bounds(0, int(indexToWrite(i))); |
---|
| 1370 | axis_bounds(1, i) = axis->bounds(1, int(indexToWrite(i))); |
---|
[1437] | 1371 | } |
---|
[1435] | 1372 | } |
---|
[1437] | 1373 | SuperClassWriter::writeData(axis_bounds, axisBoundsId, isCollective, 0, &startBounds, &countBounds); |
---|
[1235] | 1374 | } |
---|
[1435] | 1375 | } |
---|
[1437] | 1376 | else |
---|
[1435] | 1377 | { |
---|
| 1378 | std::vector<StdSize> startLabel(2), countLabel(2); |
---|
| 1379 | startLabel[0] = start[0]; startLabel[1] = 0; |
---|
| 1380 | countLabel[0] = count[0]; countLabel[1] = stringArrayLen; |
---|
| 1381 | SuperClassWriter::writeData(axis_label, axisid, isCollective, 0, &startLabel, &countLabel); |
---|
| 1382 | } |
---|
[609] | 1383 | |
---|
[1435] | 1384 | SuperClassWriter::definition_start(); |
---|
| 1385 | |
---|
| 1386 | break; |
---|
[609] | 1387 | } |
---|
[1435] | 1388 | default : |
---|
| 1389 | ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", |
---|
| 1390 | << "[ type = " << SuperClass::type << "]" |
---|
| 1391 | << " not implemented yet !"); |
---|
[609] | 1392 | } |
---|
[1030] | 1393 | } |
---|
| 1394 | catch (CNetCdfException& e) |
---|
| 1395 | { |
---|
| 1396 | StdString msg("On writing the axis : "); |
---|
| 1397 | msg.append(axisid); msg.append("\n"); |
---|
| 1398 | msg.append("In the context : "); |
---|
| 1399 | CContext* context = CContext::getCurrent() ; |
---|
| 1400 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1401 | msg.append(e.what()); |
---|
| 1402 | ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg); |
---|
| 1403 | } |
---|
[1158] | 1404 | axis->addRelFile(this->filename); |
---|
[391] | 1405 | } |
---|
[488] | 1406 | |
---|
[887] | 1407 | void CNc4DataOutput::writeScalar_(CScalar* scalar) |
---|
| 1408 | { |
---|
| 1409 | if (scalar->IsWritten(this->filename)) return; |
---|
| 1410 | scalar->checkAttributes(); |
---|
| 1411 | int scalarSize = 1; |
---|
| 1412 | |
---|
| 1413 | StdString scalaId = scalar->getScalarOutputName(); |
---|
[1430] | 1414 | StdString boundsId; |
---|
[887] | 1415 | if (isWrittenAxis(scalaId)) return ; |
---|
| 1416 | else setWrittenAxis(scalaId); |
---|
| 1417 | |
---|
[1158] | 1418 | nc_type typePrec ; |
---|
| 1419 | if (scalar->prec.isEmpty()) typePrec = NC_FLOAT ; |
---|
| 1420 | else if (scalar->prec==4) typePrec = NC_FLOAT ; |
---|
| 1421 | else if (scalar->prec==8) typePrec = NC_DOUBLE ; |
---|
| 1422 | |
---|
[1435] | 1423 | if (!scalar->label.isEmpty()) typePrec = NC_CHAR ; |
---|
| 1424 | string strId="str_len" ; |
---|
| 1425 | |
---|
[887] | 1426 | try |
---|
| 1427 | { |
---|
[1439] | 1428 | if (!scalar->label.isEmpty() && !SuperClassWriter::dimExist(strId)) SuperClassWriter::addDimension(strId, stringArrayLen); |
---|
[1435] | 1429 | |
---|
| 1430 | if (!scalar->value.isEmpty() || !scalar->label.isEmpty()) |
---|
[887] | 1431 | { |
---|
[1430] | 1432 | std::vector<StdString> dims; |
---|
| 1433 | StdString scalarDim = scalaId; |
---|
| 1434 | |
---|
[1435] | 1435 | if (!scalar->label.isEmpty()) dims.push_back(strId); |
---|
| 1436 | |
---|
[1158] | 1437 | SuperClassWriter::addVariable(scalaId, typePrec, dims); |
---|
[887] | 1438 | |
---|
| 1439 | if (!scalar->name.isEmpty()) |
---|
| 1440 | SuperClassWriter::addAttribute("name", scalar->name.getValue(), &scalaId); |
---|
| 1441 | |
---|
| 1442 | if (!scalar->standard_name.isEmpty()) |
---|
| 1443 | SuperClassWriter::addAttribute("standard_name", scalar->standard_name.getValue(), &scalaId); |
---|
| 1444 | |
---|
| 1445 | if (!scalar->long_name.isEmpty()) |
---|
| 1446 | SuperClassWriter::addAttribute("long_name", scalar->long_name.getValue(), &scalaId); |
---|
| 1447 | |
---|
| 1448 | if (!scalar->unit.isEmpty()) |
---|
| 1449 | SuperClassWriter::addAttribute("units", scalar->unit.getValue(), &scalaId); |
---|
| 1450 | |
---|
[1430] | 1451 | if (!scalar->axis_type.isEmpty()) |
---|
| 1452 | { |
---|
| 1453 | switch(scalar->axis_type) |
---|
| 1454 | { |
---|
| 1455 | case CScalar::axis_type_attr::X : |
---|
| 1456 | SuperClassWriter::addAttribute("axis", string("X"), &scalaId); |
---|
| 1457 | break; |
---|
| 1458 | case CScalar::axis_type_attr::Y : |
---|
| 1459 | SuperClassWriter::addAttribute("axis", string("Y"), &scalaId); |
---|
| 1460 | break; |
---|
| 1461 | case CScalar::axis_type_attr::Z : |
---|
| 1462 | SuperClassWriter::addAttribute("axis", string("Z"), &scalaId); |
---|
| 1463 | break; |
---|
| 1464 | case CScalar::axis_type_attr::T : |
---|
| 1465 | SuperClassWriter::addAttribute("axis", string("T"), &scalaId); |
---|
| 1466 | break; |
---|
| 1467 | } |
---|
| 1468 | } |
---|
| 1469 | |
---|
[1435] | 1470 | if (!scalar->positive.isEmpty()) |
---|
[1430] | 1471 | { |
---|
[1435] | 1472 | SuperClassWriter::addAttribute("positive", |
---|
| 1473 | (scalar->positive == CScalar::positive_attr::up) ? string("up") : string("down"), |
---|
| 1474 | &scalaId); |
---|
| 1475 | } |
---|
| 1476 | |
---|
| 1477 | if (!scalar->bounds.isEmpty() && scalar->label.isEmpty()) |
---|
| 1478 | { |
---|
[1436] | 1479 | dims.clear(); |
---|
| 1480 | dims.push_back("axis_nbounds"); |
---|
[1435] | 1481 | boundsId = (scalar->bounds_name.isEmpty()) ? (scalaId + "_bounds") : scalar->bounds_name.getValue(); |
---|
[1430] | 1482 | SuperClassWriter::addVariable(boundsId, typePrec, dims); |
---|
[1436] | 1483 | SuperClassWriter::addAttribute("bounds", boundsId, &scalaId); |
---|
[1430] | 1484 | } |
---|
| 1485 | |
---|
[887] | 1486 | SuperClassWriter::definition_end(); |
---|
| 1487 | |
---|
| 1488 | switch (SuperClass::type) |
---|
| 1489 | { |
---|
| 1490 | case MULTI_FILE: |
---|
| 1491 | { |
---|
| 1492 | CArray<double,1> scalarValue(scalarSize); |
---|
[1435] | 1493 | CArray<string,1> scalarLabel(scalarSize); |
---|
[1436] | 1494 | CArray<double,1> scalarBounds(scalarSize*2); |
---|
[1435] | 1495 | |
---|
| 1496 | if (!scalar->value.isEmpty() && scalar->label.isEmpty()) |
---|
[1430] | 1497 | { |
---|
[1435] | 1498 | scalarValue(0) = scalar->value; |
---|
| 1499 | SuperClassWriter::writeData(scalarValue, scalaId, isCollective, 0); |
---|
| 1500 | } |
---|
| 1501 | |
---|
| 1502 | if (!scalar->bounds.isEmpty() && scalar->label.isEmpty()) |
---|
| 1503 | { |
---|
[1436] | 1504 | scalarBounds(0) = scalar->bounds(0); |
---|
| 1505 | scalarBounds(1) = scalar->bounds(1); |
---|
| 1506 | SuperClassWriter::writeData(scalarBounds, boundsId, isCollective, 0); |
---|
[1430] | 1507 | } |
---|
[1435] | 1508 | |
---|
| 1509 | if (!scalar->label.isEmpty()) |
---|
| 1510 | { |
---|
| 1511 | scalarLabel(0) = scalar->label; |
---|
| 1512 | SuperClassWriter::writeData(scalarLabel, scalaId, isCollective, 0); |
---|
| 1513 | } |
---|
| 1514 | |
---|
[887] | 1515 | SuperClassWriter::definition_start(); |
---|
| 1516 | |
---|
| 1517 | break; |
---|
| 1518 | } |
---|
| 1519 | case ONE_FILE: |
---|
| 1520 | { |
---|
| 1521 | CArray<double,1> scalarValue(scalarSize); |
---|
[1435] | 1522 | CArray<string,1> scalarLabel(scalarSize); |
---|
[1436] | 1523 | CArray<double,1> scalarBounds(scalarSize*2); |
---|
[887] | 1524 | |
---|
| 1525 | std::vector<StdSize> start(1); |
---|
| 1526 | std::vector<StdSize> count(1); |
---|
| 1527 | start[0] = 0; |
---|
| 1528 | count[0] = 1; |
---|
[1435] | 1529 | if (!scalar->value.isEmpty() && scalar->label.isEmpty()) |
---|
[1430] | 1530 | { |
---|
[1435] | 1531 | scalarValue(0) = scalar->value; |
---|
| 1532 | SuperClassWriter::writeData(scalarValue, scalaId, isCollective, 0, &start, &count); |
---|
| 1533 | } |
---|
| 1534 | if (!scalar->bounds.isEmpty() && scalar->label.isEmpty()) |
---|
| 1535 | { |
---|
[1436] | 1536 | scalarBounds(0) = scalar->bounds(0); |
---|
| 1537 | scalarBounds(1) = scalar->bounds(1); |
---|
| 1538 | count[0] = 2; |
---|
| 1539 | SuperClassWriter::writeData(scalarBounds, boundsId, isCollective, 0, &start, &count); |
---|
[1430] | 1540 | } |
---|
[1435] | 1541 | if (!scalar->label.isEmpty()) |
---|
| 1542 | { |
---|
| 1543 | scalarLabel(0) = scalar->label; |
---|
| 1544 | count[0] = stringArrayLen; |
---|
| 1545 | SuperClassWriter::writeData(scalarLabel, scalaId, isCollective, 0, &start, &count); |
---|
| 1546 | } |
---|
| 1547 | |
---|
[887] | 1548 | SuperClassWriter::definition_start(); |
---|
| 1549 | |
---|
| 1550 | break; |
---|
| 1551 | } |
---|
| 1552 | default : |
---|
| 1553 | ERROR("CNc4DataOutput::writeAxis_(CAxis* scalar)", |
---|
| 1554 | << "[ type = " << SuperClass::type << "]" |
---|
| 1555 | << " not implemented yet !"); |
---|
| 1556 | } |
---|
| 1557 | } |
---|
| 1558 | } |
---|
| 1559 | catch (CNetCdfException& e) |
---|
| 1560 | { |
---|
| 1561 | StdString msg("On writing the scalar : "); |
---|
| 1562 | msg.append(scalaId); msg.append("\n"); |
---|
| 1563 | msg.append("In the context : "); |
---|
| 1564 | CContext* context = CContext::getCurrent() ; |
---|
| 1565 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1566 | msg.append(e.what()); |
---|
| 1567 | ERROR("CNc4DataOutput::writeScalar_(CScalar* scalar)", << msg); |
---|
| 1568 | } |
---|
| 1569 | scalar->addRelFile(this->filename); |
---|
| 1570 | } |
---|
| 1571 | |
---|
[676] | 1572 | //-------------------------------------------------------------- |
---|
| 1573 | |
---|
| 1574 | void CNc4DataOutput::writeGridCompressed_(CGrid* grid) |
---|
| 1575 | { |
---|
| 1576 | if (grid->isScalarGrid() || grid->isWrittenCompressed(this->filename)) return; |
---|
| 1577 | |
---|
| 1578 | try |
---|
| 1579 | { |
---|
[887] | 1580 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[676] | 1581 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 1582 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
[887] | 1583 | std::vector<StdString> scalarList = grid->getScalarList(); |
---|
| 1584 | int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[676] | 1585 | |
---|
| 1586 | std::vector<StdString> dims; |
---|
| 1587 | |
---|
| 1588 | if (grid->isCompressible()) |
---|
| 1589 | { |
---|
| 1590 | StdString varId = grid->getId() + "_points"; |
---|
| 1591 | |
---|
| 1592 | int nbIndexes = (SuperClass::type == MULTI_FILE) ? grid->getNumberWrittenIndexes() : grid->getTotalNumberWrittenIndexes(); |
---|
| 1593 | SuperClassWriter::addDimension(varId, nbIndexes); |
---|
| 1594 | |
---|
| 1595 | dims.push_back(varId); |
---|
| 1596 | SuperClassWriter::addVariable(varId, NC_INT, dims); |
---|
| 1597 | |
---|
| 1598 | StdOStringStream compress; |
---|
| 1599 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 1600 | { |
---|
[887] | 1601 | if (2 == axisDomainOrder(i)) |
---|
[676] | 1602 | { |
---|
| 1603 | CDomain* domain = CDomain::get(domainList[domainList.size() - idxDomain - 1]); |
---|
[772] | 1604 | StdString domId = domain->getDomainOutputName(); |
---|
[676] | 1605 | StdString appendDomId = singleDomain ? "" : "_" + domId; |
---|
| 1606 | |
---|
| 1607 | switch (domain->type) |
---|
| 1608 | { |
---|
| 1609 | case CDomain::type_attr::curvilinear: |
---|
| 1610 | compress << "y" << appendDomId << " x" << appendDomId; |
---|
| 1611 | break; |
---|
| 1612 | case CDomain::type_attr::rectilinear: |
---|
| 1613 | compress << "lat" << appendDomId << " lon" << appendDomId; |
---|
| 1614 | break; |
---|
| 1615 | case CDomain::type_attr::unstructured: |
---|
[1430] | 1616 | StdString cellName = (!domain->dim_i_name.isEmpty()) ? cellName=domain->dim_i_name : "cell"; |
---|
| 1617 | compress << cellName << appendDomId; |
---|
| 1618 | // compress << "cell" << appendDomId; |
---|
[676] | 1619 | break; |
---|
| 1620 | } |
---|
| 1621 | ++idxDomain; |
---|
| 1622 | } |
---|
[887] | 1623 | else if (1 == axisDomainOrder(i)) |
---|
[676] | 1624 | { |
---|
| 1625 | CAxis* axis = CAxis::get(axisList[axisList.size() - idxAxis - 1]); |
---|
[772] | 1626 | compress << axis->getAxisOutputName(); |
---|
[676] | 1627 | ++idxAxis; |
---|
| 1628 | } |
---|
[887] | 1629 | else |
---|
| 1630 | { |
---|
| 1631 | CScalar* scalar = CScalar::get(scalarList[scalarList.size() - idxScalar - 1]); |
---|
| 1632 | compress << scalar->getScalarOutputName(); |
---|
| 1633 | ++idxScalar; |
---|
| 1634 | } |
---|
[676] | 1635 | |
---|
| 1636 | if (i != 0) compress << ' '; |
---|
| 1637 | } |
---|
[1144] | 1638 | SuperClassWriter::addAttribute("compress", compress.str(), &varId); |
---|
[676] | 1639 | |
---|
| 1640 | CArray<int, 1> indexes(grid->getNumberWrittenIndexes()); |
---|
[1143] | 1641 | indexes = grid->localIndexToWriteOnServer; |
---|
[676] | 1642 | |
---|
| 1643 | switch (SuperClass::type) |
---|
| 1644 | { |
---|
| 1645 | case (MULTI_FILE): |
---|
| 1646 | { |
---|
| 1647 | SuperClassWriter::writeData(indexes, varId, isCollective, 0); |
---|
| 1648 | break; |
---|
| 1649 | } |
---|
| 1650 | case (ONE_FILE): |
---|
| 1651 | { |
---|
| 1652 | if (grid->doGridHaveDataDistributed()) |
---|
| 1653 | grid->getDistributionServer()->computeGlobalIndex(indexes); |
---|
| 1654 | |
---|
| 1655 | std::vector<StdSize> start, count; |
---|
| 1656 | start.push_back(grid->getOffsetWrittenIndexes()); |
---|
| 1657 | count.push_back(grid->getNumberWrittenIndexes()); |
---|
| 1658 | |
---|
| 1659 | SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count); |
---|
| 1660 | break; |
---|
| 1661 | } |
---|
| 1662 | } |
---|
| 1663 | } |
---|
| 1664 | else |
---|
| 1665 | { |
---|
| 1666 | for (int i = 0; i < numElement; ++i) |
---|
| 1667 | { |
---|
| 1668 | StdString varId, compress; |
---|
| 1669 | CArray<int, 1> indexes; |
---|
| 1670 | bool isDistributed; |
---|
| 1671 | StdSize nbIndexes, totalNbIndexes, offset; |
---|
| 1672 | int firstGlobalIndex; |
---|
| 1673 | |
---|
[887] | 1674 | if (2 == axisDomainOrder(i)) |
---|
[676] | 1675 | { |
---|
| 1676 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
[774] | 1677 | StdString domId = domain->getDomainOutputName(); |
---|
| 1678 | |
---|
[676] | 1679 | if (!domain->isCompressible() |
---|
| 1680 | || domain->type == CDomain::type_attr::unstructured |
---|
[774] | 1681 | || domain->isWrittenCompressed(this->filename) |
---|
| 1682 | || isWrittenCompressedDomain(domId)) |
---|
[676] | 1683 | continue; |
---|
| 1684 | |
---|
| 1685 | StdString appendDomId = singleDomain ? "" : "_" + domId; |
---|
| 1686 | |
---|
| 1687 | varId = domId + "_points"; |
---|
| 1688 | switch (domain->type) |
---|
| 1689 | { |
---|
| 1690 | case CDomain::type_attr::curvilinear: |
---|
| 1691 | compress = "y" + appendDomId + " x" + appendDomId; |
---|
| 1692 | break; |
---|
| 1693 | case CDomain::type_attr::rectilinear: |
---|
| 1694 | compress = "lat" + appendDomId + " lon" + appendDomId; |
---|
| 1695 | break; |
---|
| 1696 | } |
---|
| 1697 | |
---|
[1249] | 1698 | // indexes.resize(domain->compressedIndexToWriteOnServer[comm_file].numElements()); |
---|
| 1699 | // indexes = domain->compressedIndexToWriteOnServer[com_file]; |
---|
| 1700 | indexes.resize(domain->getCompressedIndexToWriteOnServer(comm_file).numElements()); |
---|
| 1701 | indexes = domain->getCompressedIndexToWriteOnServer(comm_file); |
---|
[1143] | 1702 | |
---|
[676] | 1703 | isDistributed = domain->isDistributed(); |
---|
[1249] | 1704 | nbIndexes = domain->getNumberWrittenIndexes(comm_file); |
---|
| 1705 | totalNbIndexes = domain->getTotalNumberWrittenIndexes(comm_file); |
---|
| 1706 | offset = domain->getOffsetWrittenIndexes(comm_file); |
---|
[676] | 1707 | firstGlobalIndex = domain->ibegin + domain->jbegin * domain->ni_glo; |
---|
| 1708 | |
---|
| 1709 | domain->addRelFileCompressed(this->filename); |
---|
[774] | 1710 | setWrittenCompressedDomain(domId); |
---|
[676] | 1711 | ++idxDomain; |
---|
| 1712 | } |
---|
[887] | 1713 | else if (1 == axisDomainOrder(i)) |
---|
[676] | 1714 | { |
---|
| 1715 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
[774] | 1716 | StdString axisId = axis->getAxisOutputName(); |
---|
| 1717 | |
---|
| 1718 | if (!axis->isCompressible() |
---|
| 1719 | || axis->isWrittenCompressed(this->filename) |
---|
| 1720 | || isWrittenCompressedAxis(axisId)) |
---|
[676] | 1721 | continue; |
---|
| 1722 | |
---|
| 1723 | varId = axisId + "_points"; |
---|
| 1724 | compress = axisId; |
---|
| 1725 | |
---|
[1249] | 1726 | // indexes.resize(axis->compressedIndexToWriteOnServer.numElements()); |
---|
| 1727 | // indexes = axis->compressedIndexToWriteOnServer; |
---|
[1143] | 1728 | |
---|
[1249] | 1729 | indexes.resize(axis->getCompressedIndexToWriteOnServer(comm_file).numElements()); |
---|
| 1730 | indexes = axis->getCompressedIndexToWriteOnServer(comm_file); |
---|
| 1731 | |
---|
[676] | 1732 | isDistributed = axis->isDistributed(); |
---|
[1249] | 1733 | nbIndexes = axis->getNumberWrittenIndexes(comm_file); |
---|
| 1734 | totalNbIndexes = axis->getTotalNumberWrittenIndexes(comm_file); |
---|
| 1735 | offset = axis->getOffsetWrittenIndexes(comm_file); |
---|
[676] | 1736 | firstGlobalIndex = axis->begin; |
---|
| 1737 | |
---|
| 1738 | axis->addRelFileCompressed(this->filename); |
---|
[774] | 1739 | setWrittenCompressedAxis(axisId); |
---|
[676] | 1740 | ++idxAxis; |
---|
| 1741 | } |
---|
[887] | 1742 | else |
---|
| 1743 | { |
---|
| 1744 | } |
---|
[676] | 1745 | |
---|
| 1746 | if (!varId.empty()) |
---|
| 1747 | { |
---|
| 1748 | SuperClassWriter::addDimension(varId, (SuperClass::type == MULTI_FILE) ? nbIndexes : totalNbIndexes); |
---|
| 1749 | |
---|
| 1750 | dims.clear(); |
---|
| 1751 | dims.push_back(varId); |
---|
| 1752 | SuperClassWriter::addVariable(varId, NC_INT, dims); |
---|
| 1753 | |
---|
| 1754 | SuperClassWriter::addAttribute("compress", compress, &varId); |
---|
| 1755 | |
---|
| 1756 | switch (SuperClass::type) |
---|
| 1757 | { |
---|
| 1758 | case (MULTI_FILE): |
---|
| 1759 | { |
---|
| 1760 | indexes -= firstGlobalIndex; |
---|
| 1761 | SuperClassWriter::writeData(indexes, varId, isCollective, 0); |
---|
| 1762 | break; |
---|
| 1763 | } |
---|
| 1764 | case (ONE_FILE): |
---|
| 1765 | { |
---|
| 1766 | std::vector<StdSize> start, count; |
---|
| 1767 | start.push_back(offset); |
---|
| 1768 | count.push_back(nbIndexes); |
---|
| 1769 | |
---|
| 1770 | SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count); |
---|
| 1771 | break; |
---|
| 1772 | } |
---|
| 1773 | } |
---|
| 1774 | } |
---|
[1144] | 1775 | } |
---|
[676] | 1776 | } |
---|
| 1777 | |
---|
| 1778 | grid->addRelFileCompressed(this->filename); |
---|
| 1779 | } |
---|
| 1780 | catch (CNetCdfException& e) |
---|
| 1781 | { |
---|
| 1782 | StdString msg("On writing compressed grid : "); |
---|
| 1783 | msg.append(grid->getId()); msg.append("\n"); |
---|
| 1784 | msg.append("In the context : "); |
---|
| 1785 | CContext* context = CContext::getCurrent(); |
---|
| 1786 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1787 | msg.append(e.what()); |
---|
| 1788 | ERROR("CNc4DataOutput::writeGridCompressed_(CGrid* grid)", << msg); |
---|
| 1789 | } |
---|
| 1790 | } |
---|
| 1791 | |
---|
| 1792 | //-------------------------------------------------------------- |
---|
| 1793 | |
---|
[391] | 1794 | void CNc4DataOutput::writeTimeDimension_(void) |
---|
| 1795 | { |
---|
[498] | 1796 | try |
---|
| 1797 | { |
---|
[802] | 1798 | SuperClassWriter::addDimension(getTimeCounterName()); |
---|
[498] | 1799 | } |
---|
| 1800 | catch (CNetCdfException& e) |
---|
| 1801 | { |
---|
[614] | 1802 | StdString msg("On writing time dimension : time_couter\n"); |
---|
[498] | 1803 | msg.append("In the context : "); |
---|
| 1804 | CContext* context = CContext::getCurrent() ; |
---|
| 1805 | msg.append(context->getId()); msg.append("\n"); |
---|
| 1806 | msg.append(e.what()); |
---|
| 1807 | ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg); |
---|
| 1808 | } |
---|
[391] | 1809 | } |
---|
[676] | 1810 | |
---|
[219] | 1811 | //-------------------------------------------------------------- |
---|
| 1812 | |
---|
[347] | 1813 | void CNc4DataOutput::writeField_(CField* field) |
---|
[219] | 1814 | { |
---|
[1158] | 1815 | CContext* context = CContext::getCurrent() ; |
---|
| 1816 | CContextServer* server=context->server ; |
---|
[300] | 1817 | |
---|
[1158] | 1818 | std::vector<StdString> dims, coodinates; |
---|
| 1819 | CGrid* grid = field->grid; |
---|
| 1820 | if (!grid->doGridHaveDataToWrite()) |
---|
[567] | 1821 | if (SuperClass::type==MULTI_FILE) return ; |
---|
[488] | 1822 | |
---|
[1158] | 1823 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
| 1824 | int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
| 1825 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 1826 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
| 1827 | std::vector<StdString> scalarList = grid->getScalarList(); |
---|
[219] | 1828 | |
---|
[1158] | 1829 | StdString timeid = getTimeCounterName(); |
---|
| 1830 | StdString dimXid,dimYid; |
---|
| 1831 | std::deque<StdString> dimIdList, dimCoordList; |
---|
| 1832 | bool hasArea = false; |
---|
| 1833 | StdString cellMeasures = "area:"; |
---|
| 1834 | bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output; |
---|
[488] | 1835 | |
---|
[1158] | 1836 | for (int i = 0; i < numElement; ++i) |
---|
| 1837 | { |
---|
| 1838 | if (2 == axisDomainOrder(i)) |
---|
| 1839 | { |
---|
| 1840 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
| 1841 | StdString domId = domain->getDomainOutputName(); |
---|
| 1842 | StdString appendDomId = singleDomain ? "" : "_" + domId ; |
---|
[1391] | 1843 | StdString lonName,latName ; |
---|
[1430] | 1844 | StdString dimIname,dimJname ; |
---|
[676] | 1845 | |
---|
[1415] | 1846 | if (domain->lon_name.isEmpty()) |
---|
| 1847 | { |
---|
| 1848 | if (domain->type==CDomain::type_attr::curvilinear) lonName = "nav_lon"; |
---|
| 1849 | else lonName = "lon"; |
---|
| 1850 | } |
---|
[1391] | 1851 | else lonName = domain->lon_name; |
---|
| 1852 | |
---|
[1415] | 1853 | if (domain->lat_name.isEmpty()) |
---|
| 1854 | { |
---|
| 1855 | if (domain->type==CDomain::type_attr::curvilinear) latName = "nav_lat"; |
---|
| 1856 | else latName = "lat"; |
---|
| 1857 | } |
---|
[1391] | 1858 | else latName = domain->lat_name; |
---|
[1430] | 1859 | |
---|
| 1860 | if (domain->dim_i_name.isEmpty()) |
---|
| 1861 | { |
---|
| 1862 | if (domain->type==CDomain::type_attr::curvilinear) dimIname = "x"; |
---|
| 1863 | else if (domain->type==CDomain::type_attr::unstructured) dimIname = "cell"; |
---|
| 1864 | else dimIname = lonName; |
---|
| 1865 | } |
---|
| 1866 | else dimIname = domain->dim_i_name; |
---|
| 1867 | |
---|
| 1868 | if (domain->dim_j_name.isEmpty()) |
---|
| 1869 | { |
---|
| 1870 | if (domain->type==CDomain::type_attr::curvilinear) dimJname = "y"; |
---|
| 1871 | else dimJname = latName; |
---|
| 1872 | } |
---|
| 1873 | else dimJname = domain->dim_j_name; |
---|
[1391] | 1874 | |
---|
[1158] | 1875 | if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured) |
---|
| 1876 | { |
---|
| 1877 | dimIdList.push_back(domId + "_points"); |
---|
| 1878 | field->setUseCompressedOutput(); |
---|
| 1879 | } |
---|
[676] | 1880 | |
---|
[1158] | 1881 | switch (domain->type) |
---|
[879] | 1882 | { |
---|
[1158] | 1883 | case CDomain::type_attr::curvilinear: |
---|
| 1884 | if (!compressedOutput || !domain->isCompressible()) |
---|
| 1885 | { |
---|
[1430] | 1886 | dimXid=dimIname+appendDomId; |
---|
| 1887 | dimYid=dimJname+appendDomId; |
---|
[1158] | 1888 | dimIdList.push_back(dimXid); |
---|
| 1889 | dimIdList.push_back(dimYid); |
---|
| 1890 | } |
---|
[1415] | 1891 | dimCoordList.push_back(lonName+appendDomId); |
---|
| 1892 | dimCoordList.push_back(latName+appendDomId); |
---|
[1158] | 1893 | break ; |
---|
| 1894 | case CDomain::type_attr::rectilinear: |
---|
| 1895 | if (!compressedOutput || !domain->isCompressible()) |
---|
| 1896 | { |
---|
[1430] | 1897 | dimXid = dimIname+appendDomId; |
---|
| 1898 | dimYid = dimJname+appendDomId; |
---|
[1158] | 1899 | dimIdList.push_back(dimXid); |
---|
| 1900 | dimIdList.push_back(dimYid); |
---|
| 1901 | } |
---|
[1430] | 1902 | if (lonName != dimIname) dimCoordList.push_back(lonName+appendDomId); |
---|
| 1903 | if (latName != dimJname) dimCoordList.push_back(latName+appendDomId); |
---|
| 1904 | |
---|
[1158] | 1905 | break ; |
---|
| 1906 | case CDomain::type_attr::unstructured: |
---|
| 1907 | { |
---|
| 1908 | if (SuperClassWriter::useCFConvention) |
---|
| 1909 | { |
---|
[1430] | 1910 | dimXid = dimIname + appendDomId; |
---|
[1158] | 1911 | dimIdList.push_back(dimXid); |
---|
[1415] | 1912 | dimCoordList.push_back(lonName+appendDomId); |
---|
| 1913 | dimCoordList.push_back(latName+appendDomId); |
---|
[1158] | 1914 | } |
---|
| 1915 | else |
---|
| 1916 | { |
---|
| 1917 | StdString domainName = domain->name; |
---|
| 1918 | if (domain->nvertex == 1) |
---|
| 1919 | { |
---|
| 1920 | dimXid = "n" + domainName + "_node"; |
---|
| 1921 | dimIdList.push_back(dimXid); |
---|
| 1922 | dimCoordList.push_back(StdString(domainName + "_node_x")); |
---|
| 1923 | dimCoordList.push_back(StdString(domainName + "_node_y")); |
---|
| 1924 | } |
---|
| 1925 | else if (domain->nvertex == 2) |
---|
| 1926 | { |
---|
| 1927 | dimXid = "n" + domainName + "_edge"; |
---|
| 1928 | dimIdList.push_back(dimXid); |
---|
| 1929 | dimCoordList.push_back(StdString(domainName + "_edge_x")); |
---|
| 1930 | dimCoordList.push_back(StdString(domainName + "_edge_y")); |
---|
| 1931 | } |
---|
| 1932 | else |
---|
| 1933 | { |
---|
| 1934 | dimXid = "n" + domainName + "_face"; |
---|
| 1935 | dimIdList.push_back(dimXid); |
---|
| 1936 | dimCoordList.push_back(StdString(domainName + "_face_x")); |
---|
| 1937 | dimCoordList.push_back(StdString(domainName + "_face_y")); |
---|
| 1938 | } |
---|
| 1939 | } // ugrid convention |
---|
| 1940 | } // case unstructured domain |
---|
[879] | 1941 | } |
---|
[1158] | 1942 | |
---|
| 1943 | if (domain->hasArea) |
---|
[879] | 1944 | { |
---|
[1158] | 1945 | hasArea = true; |
---|
| 1946 | cellMeasures += " area" + appendDomId; |
---|
[879] | 1947 | } |
---|
[1158] | 1948 | ++idxDomain; |
---|
| 1949 | } |
---|
| 1950 | else if (1 == axisDomainOrder(i)) |
---|
| 1951 | { |
---|
| 1952 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
| 1953 | StdString axisId = axis->getAxisOutputName(); |
---|
[1430] | 1954 | StdString axisDim; |
---|
[1158] | 1955 | |
---|
[1430] | 1956 | if (axis->dim_name.isEmpty()) axisDim = axisId; |
---|
| 1957 | else axisDim=axis->dim_name.getValue(); |
---|
| 1958 | |
---|
[1158] | 1959 | if (compressedOutput && axis->isCompressible()) |
---|
[879] | 1960 | { |
---|
[1430] | 1961 | dimIdList.push_back(axisDim + "_points"); |
---|
[1158] | 1962 | field->setUseCompressedOutput(); |
---|
[879] | 1963 | } |
---|
[1158] | 1964 | else |
---|
[1430] | 1965 | dimIdList.push_back(axisDim); |
---|
[878] | 1966 | |
---|
[1430] | 1967 | if (axisDim != axisId) dimCoordList.push_back(axisId); |
---|
[1158] | 1968 | ++idxAxis; |
---|
| 1969 | } |
---|
[1430] | 1970 | else |
---|
[1158] | 1971 | { |
---|
[1430] | 1972 | CScalar* scalar = CScalar::get(scalarList[idxScalar]); |
---|
| 1973 | StdString scalarId = scalar->getScalarOutputName(); |
---|
[1446] | 1974 | if (!scalar->value.isEmpty() || !scalar->label.isEmpty()) |
---|
| 1975 | dimCoordList.push_back(scalarId); |
---|
[1430] | 1976 | ++idxScalar; |
---|
[1158] | 1977 | } |
---|
| 1978 | } |
---|
[488] | 1979 | |
---|
[1158] | 1980 | StdString fieldid = field->getFieldOutputName(); |
---|
[219] | 1981 | |
---|
[1158] | 1982 | nc_type type ; |
---|
| 1983 | if (field->prec.isEmpty()) type = NC_FLOAT ; |
---|
| 1984 | else |
---|
| 1985 | { |
---|
| 1986 | if (field->prec==2) type = NC_SHORT ; |
---|
| 1987 | else if (field->prec==4) type = NC_FLOAT ; |
---|
| 1988 | else if (field->prec==8) type = NC_DOUBLE ; |
---|
| 1989 | } |
---|
[488] | 1990 | |
---|
[1158] | 1991 | bool wtime = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once); |
---|
[488] | 1992 | |
---|
[1158] | 1993 | if (wtime) |
---|
| 1994 | { |
---|
| 1995 | if (field->hasTimeInstant && hasTimeInstant) coodinates.push_back(string("time_instant")); |
---|
| 1996 | else if (field->hasTimeCentered && hasTimeCentered) coodinates.push_back(string("time_centered")); |
---|
| 1997 | dims.push_back(timeid); |
---|
| 1998 | } |
---|
[488] | 1999 | |
---|
[1158] | 2000 | if (compressedOutput && grid->isCompressible()) |
---|
| 2001 | { |
---|
| 2002 | dims.push_back(grid->getId() + "_points"); |
---|
| 2003 | field->setUseCompressedOutput(); |
---|
| 2004 | } |
---|
| 2005 | else |
---|
| 2006 | { |
---|
| 2007 | while (!dimIdList.empty()) |
---|
| 2008 | { |
---|
| 2009 | dims.push_back(dimIdList.back()); |
---|
| 2010 | dimIdList.pop_back(); |
---|
| 2011 | } |
---|
| 2012 | } |
---|
[219] | 2013 | |
---|
[1158] | 2014 | while (!dimCoordList.empty()) |
---|
| 2015 | { |
---|
| 2016 | coodinates.push_back(dimCoordList.back()); |
---|
| 2017 | dimCoordList.pop_back(); |
---|
| 2018 | } |
---|
[219] | 2019 | |
---|
[1158] | 2020 | try |
---|
| 2021 | { |
---|
[498] | 2022 | SuperClassWriter::addVariable(fieldid, type, dims); |
---|
[488] | 2023 | |
---|
[498] | 2024 | if (!field->standard_name.isEmpty()) |
---|
| 2025 | SuperClassWriter::addAttribute |
---|
| 2026 | ("standard_name", field->standard_name.getValue(), &fieldid); |
---|
[219] | 2027 | |
---|
[498] | 2028 | if (!field->long_name.isEmpty()) |
---|
| 2029 | SuperClassWriter::addAttribute |
---|
| 2030 | ("long_name", field->long_name.getValue(), &fieldid); |
---|
[219] | 2031 | |
---|
[498] | 2032 | if (!field->unit.isEmpty()) |
---|
| 2033 | SuperClassWriter::addAttribute |
---|
| 2034 | ("units", field->unit.getValue(), &fieldid); |
---|
[463] | 2035 | |
---|
[1158] | 2036 | // Ugrid field attributes "mesh" and "location" |
---|
| 2037 | if (!SuperClassWriter::useCFConvention) |
---|
| 2038 | { |
---|
| 2039 | if (!domainList.empty()) |
---|
| 2040 | { |
---|
| 2041 | CDomain* domain = CDomain::get(domainList[0]); // Suppose that we have only domain |
---|
| 2042 | StdString mesh = domain->name; |
---|
| 2043 | SuperClassWriter::addAttribute("mesh", mesh, &fieldid); |
---|
| 2044 | StdString location; |
---|
| 2045 | if (domain->nvertex == 1) |
---|
| 2046 | location = "node"; |
---|
| 2047 | else if (domain->nvertex == 2) |
---|
| 2048 | location = "edge"; |
---|
| 2049 | else if (domain->nvertex > 2) |
---|
| 2050 | location = "face"; |
---|
| 2051 | SuperClassWriter::addAttribute("location", location, &fieldid); |
---|
| 2052 | } |
---|
| 2053 | |
---|
| 2054 | } |
---|
| 2055 | |
---|
| 2056 | if (!field->valid_min.isEmpty()) |
---|
[498] | 2057 | SuperClassWriter::addAttribute |
---|
| 2058 | ("valid_min", field->valid_min.getValue(), &fieldid); |
---|
[463] | 2059 | |
---|
[498] | 2060 | if (!field->valid_max.isEmpty()) |
---|
| 2061 | SuperClassWriter::addAttribute |
---|
| 2062 | ("valid_max", field->valid_max.getValue(), &fieldid); |
---|
[464] | 2063 | |
---|
[498] | 2064 | if (!field->scale_factor.isEmpty()) |
---|
| 2065 | SuperClassWriter::addAttribute |
---|
| 2066 | ("scale_factor", field->scale_factor.getValue(), &fieldid); |
---|
[464] | 2067 | |
---|
[498] | 2068 | if (!field->add_offset.isEmpty()) |
---|
| 2069 | SuperClassWriter::addAttribute |
---|
| 2070 | ("add_offset", field->add_offset.getValue(), &fieldid); |
---|
[488] | 2071 | |
---|
[498] | 2072 | SuperClassWriter::addAttribute |
---|
| 2073 | ("online_operation", field->operation.getValue(), &fieldid); |
---|
[472] | 2074 | |
---|
[498] | 2075 | // write child variables as attributes |
---|
[488] | 2076 | |
---|
| 2077 | |
---|
[1021] | 2078 | bool alreadyAddCellMethod = false; |
---|
| 2079 | StdString cellMethodsPrefix(""), cellMethodsSuffix(""); |
---|
| 2080 | if (!field->cell_methods.isEmpty()) |
---|
| 2081 | { |
---|
[1158] | 2082 | StdString cellMethodString = field->cell_methods; |
---|
| 2083 | if (field->cell_methods_mode.isEmpty() || |
---|
[1021] | 2084 | (CField::cell_methods_mode_attr::overwrite == field->cell_methods_mode)) |
---|
[1158] | 2085 | { |
---|
| 2086 | SuperClassWriter::addAttribute("cell_methods", cellMethodString, &fieldid); |
---|
| 2087 | alreadyAddCellMethod = true; |
---|
| 2088 | } |
---|
| 2089 | else |
---|
| 2090 | { |
---|
| 2091 | switch (field->cell_methods_mode) |
---|
| 2092 | { |
---|
| 2093 | case (CField::cell_methods_mode_attr::prefix): |
---|
| 2094 | cellMethodsPrefix = cellMethodString; |
---|
| 2095 | cellMethodsPrefix += " "; |
---|
| 2096 | break; |
---|
| 2097 | case (CField::cell_methods_mode_attr::suffix): |
---|
| 2098 | cellMethodsSuffix = " "; |
---|
| 2099 | cellMethodsSuffix += cellMethodString; |
---|
| 2100 | break; |
---|
| 2101 | case (CField::cell_methods_mode_attr::none): |
---|
| 2102 | break; |
---|
| 2103 | default: |
---|
| 2104 | break; |
---|
| 2105 | } |
---|
| 2106 | } |
---|
[1021] | 2107 | } |
---|
[488] | 2108 | |
---|
[1021] | 2109 | |
---|
[498] | 2110 | if (wtime) |
---|
| 2111 | { |
---|
[614] | 2112 | CDuration freqOp = field->freq_op.getValue(); |
---|
| 2113 | freqOp.solveTimeStep(*context->calendar); |
---|
| 2114 | StdString freqOpStr = freqOp.toStringUDUnits(); |
---|
[612] | 2115 | SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid); |
---|
[437] | 2116 | |
---|
[614] | 2117 | CDuration freqOut = field->getRelFile()->output_freq.getValue(); |
---|
| 2118 | freqOut.solveTimeStep(*context->calendar); |
---|
| 2119 | SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid); |
---|
[612] | 2120 | |
---|
[1021] | 2121 | StdString cellMethods(cellMethodsPrefix + "time: "); |
---|
[612] | 2122 | if (field->operation.getValue() == "instant") cellMethods += "point"; |
---|
| 2123 | else if (field->operation.getValue() == "average") cellMethods += "mean"; |
---|
| 2124 | else if (field->operation.getValue() == "accumulate") cellMethods += "sum"; |
---|
| 2125 | else cellMethods += field->operation; |
---|
[614] | 2126 | if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar)) |
---|
| 2127 | cellMethods += " (interval: " + freqOpStr + ")"; |
---|
[1021] | 2128 | cellMethods += cellMethodsSuffix; |
---|
| 2129 | if (!alreadyAddCellMethod) |
---|
| 2130 | SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid); |
---|
[498] | 2131 | } |
---|
[488] | 2132 | |
---|
[611] | 2133 | if (hasArea) |
---|
| 2134 | SuperClassWriter::addAttribute("cell_measures", cellMeasures, &fieldid); |
---|
| 2135 | |
---|
[498] | 2136 | if (!field->default_value.isEmpty()) |
---|
| 2137 | { |
---|
[1424] | 2138 | double default_value = field->default_value.getValue(); |
---|
| 2139 | if (type == NC_DOUBLE) |
---|
| 2140 | { |
---|
| 2141 | SuperClassWriter::setDefaultValue(fieldid, &default_value); |
---|
| 2142 | } |
---|
| 2143 | else if (type == NC_SHORT) |
---|
| 2144 | { |
---|
| 2145 | short sdefault_value = (short)default_value; |
---|
| 2146 | SuperClassWriter::setDefaultValue(fieldid, &sdefault_value); |
---|
| 2147 | } |
---|
| 2148 | else |
---|
| 2149 | { |
---|
| 2150 | float fdefault_value = (float)default_value; |
---|
| 2151 | SuperClassWriter::setDefaultValue(fieldid, &fdefault_value); |
---|
| 2152 | } |
---|
[498] | 2153 | } |
---|
| 2154 | else |
---|
[517] | 2155 | SuperClassWriter::setDefaultValue(fieldid, (double*)NULL); |
---|
[219] | 2156 | |
---|
[606] | 2157 | if (field->compression_level.isEmpty()) |
---|
| 2158 | field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level; |
---|
| 2159 | SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); |
---|
| 2160 | |
---|
[878] | 2161 | { // Ecriture des coordonnes |
---|
[488] | 2162 | |
---|
[498] | 2163 | StdString coordstr; //boost::algorithm::join(coodinates, " ") |
---|
| 2164 | std::vector<StdString>::iterator |
---|
| 2165 | itc = coodinates.begin(), endc = coodinates.end(); |
---|
[488] | 2166 | |
---|
[498] | 2167 | for (; itc!= endc; itc++) |
---|
| 2168 | { |
---|
| 2169 | StdString & coord = *itc; |
---|
| 2170 | if (itc+1 != endc) |
---|
| 2171 | coordstr.append(coord).append(" "); |
---|
| 2172 | else coordstr.append(coord); |
---|
| 2173 | } |
---|
[219] | 2174 | |
---|
[498] | 2175 | SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid); |
---|
[219] | 2176 | |
---|
[498] | 2177 | } |
---|
[1222] | 2178 | |
---|
| 2179 | vector<CVariable*> listVars = field->getAllVariables() ; |
---|
| 2180 | for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ; |
---|
| 2181 | |
---|
[219] | 2182 | } |
---|
[498] | 2183 | catch (CNetCdfException& e) |
---|
| 2184 | { |
---|
| 2185 | StdString msg("On writing field : "); |
---|
| 2186 | msg.append(fieldid); msg.append("\n"); |
---|
| 2187 | msg.append("In the context : "); |
---|
| 2188 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2189 | msg.append(e.what()); |
---|
| 2190 | ERROR("CNc4DataOutput::writeField_(CField* field)", << msg); |
---|
| 2191 | } |
---|
[879] | 2192 | } // writeField_() |
---|
[219] | 2193 | |
---|
| 2194 | //-------------------------------------------------------------- |
---|
| 2195 | |
---|
[347] | 2196 | void CNc4DataOutput::writeFile_ (CFile* file) |
---|
[219] | 2197 | { |
---|
[773] | 2198 | StdString filename = file->getFileOutputName(); |
---|
[219] | 2199 | StdString description = (!file->description.isEmpty()) |
---|
| 2200 | ? file->description.getValue() |
---|
[335] | 2201 | : StdString("Created by xios"); |
---|
[609] | 2202 | |
---|
| 2203 | singleDomain = (file->nbDomains == 1); |
---|
| 2204 | |
---|
[1158] | 2205 | StdString conv_str ; |
---|
| 2206 | if (file->convention_str.isEmpty()) |
---|
| 2207 | { |
---|
| 2208 | if (SuperClassWriter::useCFConvention) conv_str="CF-1.6" ; |
---|
| 2209 | else conv_str="UGRID" ; |
---|
| 2210 | } |
---|
| 2211 | else conv_str=file->convention_str ; |
---|
| 2212 | |
---|
[498] | 2213 | try |
---|
| 2214 | { |
---|
[1309] | 2215 | if (!appendMode) this->writeFileAttributes(filename, description, |
---|
| 2216 | conv_str, |
---|
| 2217 | StdString("An IPSL model"), |
---|
| 2218 | this->getTimeStamp()); |
---|
[609] | 2219 | |
---|
[701] | 2220 | if (!appendMode) |
---|
| 2221 | SuperClassWriter::addDimension("axis_nbounds", 2); |
---|
[498] | 2222 | } |
---|
| 2223 | catch (CNetCdfException& e) |
---|
| 2224 | { |
---|
| 2225 | StdString msg("On writing file : "); |
---|
| 2226 | msg.append(filename); msg.append("\n"); |
---|
| 2227 | msg.append("In the context : "); |
---|
| 2228 | CContext* context = CContext::getCurrent() ; |
---|
| 2229 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2230 | msg.append(e.what()); |
---|
| 2231 | ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg); |
---|
| 2232 | } |
---|
[219] | 2233 | } |
---|
[488] | 2234 | |
---|
[472] | 2235 | void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId) |
---|
| 2236 | { |
---|
[773] | 2237 | StdString name = var->getVariableOutputName(); |
---|
[488] | 2238 | |
---|
[498] | 2239 | try |
---|
| 2240 | { |
---|
[527] | 2241 | if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32) |
---|
| 2242 | addAttribute(name, var->getData<int>(), &fieldId); |
---|
| 2243 | else if (var->type.getValue() == CVariable::type_attr::t_int16) |
---|
| 2244 | addAttribute(name, var->getData<short int>(), &fieldId); |
---|
| 2245 | else if (var->type.getValue() == CVariable::type_attr::t_float) |
---|
| 2246 | addAttribute(name, var->getData<float>(), &fieldId); |
---|
| 2247 | else if (var->type.getValue() == CVariable::type_attr::t_double) |
---|
| 2248 | addAttribute(name, var->getData<double>(), &fieldId); |
---|
| 2249 | else if (var->type.getValue() == CVariable::type_attr::t_string) |
---|
| 2250 | addAttribute(name, var->getData<string>(), &fieldId); |
---|
| 2251 | else |
---|
| 2252 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", |
---|
| 2253 | << "Unsupported variable of type " << var->type.getStringValue()); |
---|
[498] | 2254 | } |
---|
| 2255 | catch (CNetCdfException& e) |
---|
| 2256 | { |
---|
| 2257 | StdString msg("On writing attributes of variable with name : "); |
---|
| 2258 | msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n"); |
---|
| 2259 | msg.append("In the context : "); |
---|
| 2260 | CContext* context = CContext::getCurrent() ; |
---|
| 2261 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2262 | msg.append(e.what()); |
---|
| 2263 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg); |
---|
| 2264 | } |
---|
[472] | 2265 | } |
---|
[488] | 2266 | |
---|
[472] | 2267 | void CNc4DataOutput::writeAttribute_ (CVariable* var) |
---|
| 2268 | { |
---|
[773] | 2269 | StdString name = var->getVariableOutputName(); |
---|
| 2270 | |
---|
[498] | 2271 | try |
---|
| 2272 | { |
---|
[527] | 2273 | if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32) |
---|
| 2274 | addAttribute(name, var->getData<int>()); |
---|
| 2275 | else if (var->type.getValue() == CVariable::type_attr::t_int16) |
---|
| 2276 | addAttribute(name, var->getData<short int>()); |
---|
| 2277 | else if (var->type.getValue() == CVariable::type_attr::t_float) |
---|
| 2278 | addAttribute(name, var->getData<float>()); |
---|
| 2279 | else if (var->type.getValue() == CVariable::type_attr::t_double) |
---|
| 2280 | addAttribute(name, var->getData<double>()); |
---|
| 2281 | else if (var->type.getValue() == CVariable::type_attr::t_string) |
---|
| 2282 | addAttribute(name, var->getData<string>()); |
---|
| 2283 | else |
---|
| 2284 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", |
---|
| 2285 | << "Unsupported variable of type " << var->type.getStringValue()); |
---|
[498] | 2286 | } |
---|
| 2287 | catch (CNetCdfException& e) |
---|
| 2288 | { |
---|
| 2289 | StdString msg("On writing attributes of variable with name : "); |
---|
| 2290 | msg.append(name); msg.append("\n"); |
---|
| 2291 | msg.append("In the context : "); |
---|
| 2292 | CContext* context = CContext::getCurrent() ; |
---|
| 2293 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2294 | msg.append(e.what()); |
---|
| 2295 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg); |
---|
| 2296 | } |
---|
[488] | 2297 | } |
---|
| 2298 | |
---|
[321] | 2299 | void CNc4DataOutput::syncFile_ (void) |
---|
| 2300 | { |
---|
[498] | 2301 | try |
---|
| 2302 | { |
---|
| 2303 | SuperClassWriter::sync() ; |
---|
| 2304 | } |
---|
| 2305 | catch (CNetCdfException& e) |
---|
| 2306 | { |
---|
| 2307 | StdString msg("On synchronizing the write among processes"); |
---|
| 2308 | msg.append("In the context : "); |
---|
| 2309 | CContext* context = CContext::getCurrent() ; |
---|
| 2310 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2311 | msg.append(e.what()); |
---|
| 2312 | ERROR("CNc4DataOutput::syncFile_ (void)", << msg); |
---|
| 2313 | } |
---|
[321] | 2314 | } |
---|
[219] | 2315 | |
---|
[286] | 2316 | void CNc4DataOutput::closeFile_ (void) |
---|
| 2317 | { |
---|
[498] | 2318 | try |
---|
| 2319 | { |
---|
| 2320 | SuperClassWriter::close() ; |
---|
| 2321 | } |
---|
| 2322 | catch (CNetCdfException& e) |
---|
| 2323 | { |
---|
| 2324 | StdString msg("On closing file"); |
---|
| 2325 | msg.append("In the context : "); |
---|
| 2326 | CContext* context = CContext::getCurrent() ; |
---|
| 2327 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2328 | msg.append(e.what()); |
---|
| 2329 | ERROR("CNc4DataOutput::syncFile_ (void)", << msg); |
---|
| 2330 | } |
---|
| 2331 | |
---|
[286] | 2332 | } |
---|
| 2333 | |
---|
[219] | 2334 | //--------------------------------------------------------------- |
---|
| 2335 | |
---|
| 2336 | StdString CNc4DataOutput::getTimeStamp(void) const |
---|
| 2337 | { |
---|
| 2338 | const int buffer_size = 100; |
---|
| 2339 | time_t rawtime; |
---|
| 2340 | struct tm * timeinfo = NULL; |
---|
| 2341 | char buffer [buffer_size]; |
---|
[1158] | 2342 | StdString formatStr; |
---|
| 2343 | if (file->time_stamp_format.isEmpty()) formatStr="%Y-%b-%d %H:%M:%S %Z" ; |
---|
| 2344 | else formatStr=file->time_stamp_format; |
---|
[219] | 2345 | |
---|
[1158] | 2346 | // time ( &rawtime ); |
---|
| 2347 | // timeinfo = localtime ( &rawtime ); |
---|
[219] | 2348 | time ( &rawtime ); |
---|
[1158] | 2349 | timeinfo = gmtime ( &rawtime ); |
---|
| 2350 | strftime (buffer, buffer_size, formatStr.c_str(), timeinfo); |
---|
[219] | 2351 | |
---|
| 2352 | return (StdString(buffer)); |
---|
| 2353 | } |
---|
[488] | 2354 | |
---|
[219] | 2355 | //--------------------------------------------------------------- |
---|
[488] | 2356 | |
---|
[347] | 2357 | void CNc4DataOutput::writeFieldData_ (CField* field) |
---|
[219] | 2358 | { |
---|
[707] | 2359 | CContext* context = CContext::getCurrent(); |
---|
| 2360 | CContextServer* server = context->server; |
---|
| 2361 | CGrid* grid = field->grid; |
---|
[300] | 2362 | |
---|
[1158] | 2363 | if (field->getNStep()<1) |
---|
| 2364 | { |
---|
| 2365 | return; |
---|
| 2366 | } |
---|
[952] | 2367 | |
---|
[707] | 2368 | if (!grid->doGridHaveDataToWrite()) |
---|
[1158] | 2369 | if (SuperClass::type == MULTI_FILE || !isCollective) |
---|
| 2370 | { |
---|
| 2371 | return; |
---|
| 2372 | } |
---|
[488] | 2373 | |
---|
[770] | 2374 | StdString fieldid = field->getFieldOutputName(); |
---|
[286] | 2375 | |
---|
[707] | 2376 | StdOStringStream oss; |
---|
| 2377 | string timeAxisId; |
---|
[1158] | 2378 | if (field->hasTimeInstant) timeAxisId = "time_instant"; |
---|
| 2379 | else if (field->hasTimeCentered) timeAxisId = "time_centered"; |
---|
[488] | 2380 | |
---|
[802] | 2381 | StdString timeBoundId = getTimeCounterName() + "_bounds"; |
---|
[449] | 2382 | |
---|
[707] | 2383 | StdString timeAxisBoundId; |
---|
[1158] | 2384 | if (field->hasTimeInstant) timeAxisBoundId = "time_instant_bounds"; |
---|
| 2385 | else if (field->hasTimeCentered) timeAxisBoundId = "time_centered_bounds"; |
---|
[488] | 2386 | |
---|
[707] | 2387 | if (!field->wasWritten()) |
---|
| 2388 | { |
---|
[1158] | 2389 | if (appendMode && field->file->record_offset.isEmpty() && |
---|
| 2390 | field->getOperationTimeType() != func::CFunctor::once) |
---|
[707] | 2391 | { |
---|
[1158] | 2392 | double factorUnit; |
---|
| 2393 | if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) |
---|
| 2394 | factorUnit=context->getCalendar()->getDayLengthInSeconds() ; |
---|
| 2395 | else factorUnit=1 ; |
---|
| 2396 | field->resetNStep(getRecordFromTime(field->last_Write_srv,factorUnit) + 1); |
---|
[707] | 2397 | } |
---|
[488] | 2398 | |
---|
[707] | 2399 | field->setWritten(); |
---|
| 2400 | } |
---|
[488] | 2401 | |
---|
| 2402 | |
---|
[707] | 2403 | CArray<double,1> time_data(1); |
---|
| 2404 | CArray<double,1> time_data_bound(2); |
---|
| 2405 | CArray<double,1> time_counter(1); |
---|
| 2406 | CArray<double,1> time_counter_bound(2); |
---|
| 2407 | |
---|
| 2408 | bool wtime = (field->getOperationTimeType() != func::CFunctor::once); |
---|
[1158] | 2409 | bool wtimeCounter =false ; |
---|
| 2410 | bool wtimeData =false ; |
---|
| 2411 | |
---|
[707] | 2412 | |
---|
[444] | 2413 | if (wtime) |
---|
| 2414 | { |
---|
[692] | 2415 | Time lastWrite = field->last_Write_srv; |
---|
| 2416 | Time lastLastWrite = field->lastlast_Write_srv; |
---|
| 2417 | |
---|
[1158] | 2418 | |
---|
| 2419 | if (field->hasTimeInstant) |
---|
| 2420 | { |
---|
| 2421 | time_data(0) = time_data_bound(1) = lastWrite; |
---|
[692] | 2422 | time_data_bound(0) = time_data_bound(1) = lastWrite; |
---|
[1158] | 2423 | if (timeCounterType==instant) |
---|
| 2424 | { |
---|
| 2425 | time_counter(0) = time_data(0); |
---|
| 2426 | time_counter_bound(0) = time_data_bound(0); |
---|
| 2427 | time_counter_bound(1) = time_data_bound(1); |
---|
| 2428 | wtimeCounter=true ; |
---|
| 2429 | } |
---|
| 2430 | if (hasTimeInstant) wtimeData=true ; |
---|
| 2431 | } |
---|
| 2432 | else if (field->hasTimeCentered) |
---|
[488] | 2433 | { |
---|
[1158] | 2434 | time_data(0) = (lastWrite + lastLastWrite) / 2; |
---|
[692] | 2435 | time_data_bound(0) = lastLastWrite; |
---|
| 2436 | time_data_bound(1) = lastWrite; |
---|
[1158] | 2437 | if (timeCounterType==centered) |
---|
| 2438 | { |
---|
| 2439 | time_counter(0) = time_data(0) ; |
---|
| 2440 | time_counter_bound(0) = time_data_bound(0) ; |
---|
| 2441 | time_counter_bound(1) = time_data_bound(1) ; |
---|
| 2442 | wtimeCounter=true ; |
---|
| 2443 | } |
---|
| 2444 | if (hasTimeCentered) wtimeData=true ; |
---|
[488] | 2445 | } |
---|
| 2446 | |
---|
[1158] | 2447 | if (timeCounterType==record) |
---|
| 2448 | { |
---|
[692] | 2449 | time_counter(0) = field->getNStep() - 1; |
---|
[1158] | 2450 | time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1; |
---|
| 2451 | wtimeCounter=true ; |
---|
| 2452 | } |
---|
[692] | 2453 | |
---|
[1158] | 2454 | if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) |
---|
[692] | 2455 | { |
---|
[1158] | 2456 | double secByDay=context->getCalendar()->getDayLengthInSeconds() ; |
---|
| 2457 | time_data/=secByDay; |
---|
| 2458 | time_data_bound/=secByDay; |
---|
| 2459 | time_counter/=secByDay; |
---|
| 2460 | time_counter_bound/=secByDay; |
---|
[692] | 2461 | } |
---|
| 2462 | } |
---|
| 2463 | |
---|
[707] | 2464 | bool isRoot = (server->intraCommRank == 0); |
---|
[488] | 2465 | |
---|
[464] | 2466 | if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) |
---|
| 2467 | { |
---|
[707] | 2468 | double scaleFactor = 1.0; |
---|
| 2469 | double addOffset = 0.0; |
---|
| 2470 | if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor; |
---|
| 2471 | if (!field->add_offset.isEmpty()) addOffset = field->add_offset; |
---|
| 2472 | field->scaleFactorAddOffset(scaleFactor, addOffset); |
---|
[464] | 2473 | } |
---|
[488] | 2474 | |
---|
[498] | 2475 | try |
---|
[219] | 2476 | { |
---|
[676] | 2477 | size_t writtenSize; |
---|
| 2478 | if (field->getUseCompressedOutput()) |
---|
| 2479 | writtenSize = grid->getNumberWrittenIndexes(); |
---|
| 2480 | else |
---|
| 2481 | writtenSize = grid->getWrittenDataSize(); |
---|
| 2482 | |
---|
| 2483 | CArray<double,1> fieldData(writtenSize); |
---|
[567] | 2484 | if (!field->default_value.isEmpty()) fieldData = field->default_value; |
---|
[676] | 2485 | |
---|
| 2486 | if (field->getUseCompressedOutput()) |
---|
| 2487 | field->outputCompressedField(fieldData); |
---|
| 2488 | else |
---|
| 2489 | field->outputField(fieldData); |
---|
| 2490 | |
---|
[707] | 2491 | if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); |
---|
[567] | 2492 | |
---|
| 2493 | switch (SuperClass::type) |
---|
[498] | 2494 | { |
---|
[567] | 2495 | case (MULTI_FILE) : |
---|
| 2496 | { |
---|
[1158] | 2497 | CTimer::get("Files : writing data").resume(); |
---|
[692] | 2498 | SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1); |
---|
[1158] | 2499 | CTimer::get("Files : writing data").suspend(); |
---|
[567] | 2500 | if (wtime) |
---|
| 2501 | { |
---|
[1158] | 2502 | CTimer::get("Files : writing time axis").resume(); |
---|
| 2503 | if ( wtimeData) |
---|
[692] | 2504 | { |
---|
[1158] | 2505 | SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); |
---|
| 2506 | SuperClassWriter::writeTimeAxisDataBounds(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
| 2507 | } |
---|
| 2508 | if (wtimeCounter) |
---|
| 2509 | { |
---|
| 2510 | SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1,isRoot); |
---|
| 2511 | if (timeCounterType!=record) SuperClassWriter::writeTimeAxisDataBounds(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
[692] | 2512 | } |
---|
[1158] | 2513 | CTimer::get("Files : writing time axis").suspend(); |
---|
[567] | 2514 | } |
---|
[707] | 2515 | break; |
---|
[567] | 2516 | } |
---|
| 2517 | case (ONE_FILE) : |
---|
| 2518 | { |
---|
[464] | 2519 | |
---|
[676] | 2520 | std::vector<StdSize> start, count; |
---|
[464] | 2521 | |
---|
[676] | 2522 | if (field->getUseCompressedOutput()) |
---|
| 2523 | { |
---|
| 2524 | if (grid->isCompressible()) |
---|
| 2525 | { |
---|
| 2526 | start.push_back(grid->getOffsetWrittenIndexes()); |
---|
| 2527 | count.push_back(grid->getNumberWrittenIndexes()); |
---|
| 2528 | } |
---|
| 2529 | else |
---|
| 2530 | { |
---|
[887] | 2531 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[676] | 2532 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 2533 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
| 2534 | int numElement = axisDomainOrder.numElements(); |
---|
| 2535 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1; |
---|
[1553] | 2536 | int idx = domainList.size() * 2 + axisList.size() - 1; |
---|
[464] | 2537 | |
---|
[1553] | 2538 | start.reserve(idx+1); |
---|
| 2539 | count.reserve(idx+1); |
---|
[676] | 2540 | |
---|
| 2541 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 2542 | { |
---|
[887] | 2543 | if (2 == axisDomainOrder(i)) |
---|
[676] | 2544 | { |
---|
| 2545 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
| 2546 | |
---|
| 2547 | if (domain->isCompressible()) |
---|
| 2548 | { |
---|
[1249] | 2549 | start.push_back(domain->getOffsetWrittenIndexes(comm_file)); |
---|
| 2550 | count.push_back(domain->getNumberWrittenIndexes(comm_file)); |
---|
[710] | 2551 | idx -= 2; |
---|
[676] | 2552 | } |
---|
| 2553 | else |
---|
| 2554 | { |
---|
[710] | 2555 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
| 2556 | { |
---|
[1553] | 2557 | start.push_back(domain->jbegin); |
---|
| 2558 | count.push_back(domain->nj); |
---|
[710] | 2559 | } |
---|
| 2560 | --idx; |
---|
[1553] | 2561 | start.push_back(domain->ibegin); |
---|
| 2562 | count.push_back(domain->ni); |
---|
[710] | 2563 | --idx; |
---|
[676] | 2564 | } |
---|
| 2565 | --idxDomain; |
---|
| 2566 | } |
---|
[887] | 2567 | else if (1 == axisDomainOrder(i)) |
---|
[676] | 2568 | { |
---|
| 2569 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
| 2570 | |
---|
| 2571 | if (axis->isCompressible()) |
---|
| 2572 | { |
---|
[1249] | 2573 | start.push_back(axis->getOffsetWrittenIndexes(comm_file)); |
---|
| 2574 | count.push_back(axis->getNumberWrittenIndexes(comm_file)); |
---|
[676] | 2575 | } |
---|
| 2576 | else |
---|
| 2577 | { |
---|
[1553] | 2578 | start.push_back(axis->begin); |
---|
| 2579 | count.push_back(axis->n); |
---|
[676] | 2580 | } |
---|
| 2581 | --idxAxis; |
---|
| 2582 | --idx; |
---|
| 2583 | } |
---|
| 2584 | } |
---|
[1158] | 2585 | } |
---|
[676] | 2586 | } |
---|
| 2587 | else |
---|
[498] | 2588 | { |
---|
[887] | 2589 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[705] | 2590 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 2591 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
| 2592 | int numElement = axisDomainOrder.numElements(); |
---|
| 2593 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1; |
---|
[1553] | 2594 | int idx = domainList.size() * 2 + axisList.size() - 1; |
---|
[705] | 2595 | |
---|
[1553] | 2596 | start.reserve(idx+1); |
---|
| 2597 | count.reserve(idx+1); |
---|
[705] | 2598 | |
---|
| 2599 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 2600 | { |
---|
[887] | 2601 | if (2 == axisDomainOrder(i)) |
---|
[705] | 2602 | { |
---|
| 2603 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
[710] | 2604 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
[705] | 2605 | { |
---|
[1553] | 2606 | start.push_back(domain->jbegin); |
---|
| 2607 | count.push_back(domain->nj); |
---|
[705] | 2608 | } |
---|
| 2609 | --idx ; |
---|
[1143] | 2610 | |
---|
[1553] | 2611 | start.push_back(domain->ibegin); |
---|
| 2612 | count.push_back(domain->ni); |
---|
[705] | 2613 | --idx ; |
---|
| 2614 | --idxDomain; |
---|
| 2615 | } |
---|
[887] | 2616 | else if (1 == axisDomainOrder(i)) |
---|
[705] | 2617 | { |
---|
[1143] | 2618 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
[1559] | 2619 | start.push_back(axis->begin); |
---|
| 2620 | count.push_back(axis->n); |
---|
[705] | 2621 | --idx; |
---|
[1025] | 2622 | --idxAxis; |
---|
[887] | 2623 | } |
---|
| 2624 | else |
---|
| 2625 | { |
---|
| 2626 | if (1 == axisDomainOrder.numElements()) |
---|
| 2627 | { |
---|
| 2628 | start.push_back(0); |
---|
| 2629 | count.push_back(1); |
---|
| 2630 | } |
---|
| 2631 | --idx; |
---|
| 2632 | } |
---|
[705] | 2633 | } |
---|
[498] | 2634 | } |
---|
[488] | 2635 | |
---|
[1158] | 2636 | |
---|
| 2637 | CTimer::get("Files : writing data").resume(); |
---|
[676] | 2638 | SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count); |
---|
[1158] | 2639 | CTimer::get("Files : writing data").suspend(); |
---|
| 2640 | |
---|
| 2641 | if (wtime) |
---|
| 2642 | { |
---|
| 2643 | CTimer::get("Files : writing time axis").resume(); |
---|
| 2644 | if ( wtimeData) |
---|
[692] | 2645 | { |
---|
[1158] | 2646 | SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); |
---|
| 2647 | SuperClassWriter::writeTimeAxisDataBounds(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
[692] | 2648 | } |
---|
[1158] | 2649 | if (wtimeCounter) |
---|
| 2650 | { |
---|
| 2651 | SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1,isRoot); |
---|
| 2652 | if (timeCounterType!=record) SuperClassWriter::writeTimeAxisDataBounds(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
[586] | 2653 | |
---|
[1158] | 2654 | } |
---|
| 2655 | CTimer::get("Files : writing time axis").suspend(); |
---|
| 2656 | } |
---|
| 2657 | |
---|
[586] | 2658 | break; |
---|
[286] | 2659 | } |
---|
[567] | 2660 | } |
---|
[219] | 2661 | } |
---|
[498] | 2662 | catch (CNetCdfException& e) |
---|
| 2663 | { |
---|
| 2664 | StdString msg("On writing field data: "); |
---|
| 2665 | msg.append(fieldid); msg.append("\n"); |
---|
| 2666 | msg.append("In the context : "); |
---|
| 2667 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2668 | msg.append(e.what()); |
---|
[1130] | 2669 | ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); |
---|
[498] | 2670 | } |
---|
[219] | 2671 | } |
---|
| 2672 | |
---|
| 2673 | //--------------------------------------------------------------- |
---|
| 2674 | |
---|
| 2675 | void CNc4DataOutput::writeTimeAxis_ |
---|
[347] | 2676 | (CField* field, |
---|
[1542] | 2677 | const std::shared_ptr<CCalendar> cal) |
---|
[219] | 2678 | { |
---|
| 2679 | StdOStringStream oss; |
---|
[1158] | 2680 | bool createInstantAxis=false ; |
---|
| 2681 | bool createCenteredAxis=false ; |
---|
| 2682 | bool createTimeCounterAxis=false ; |
---|
| 2683 | |
---|
[645] | 2684 | if (field->getOperationTimeType() == func::CFunctor::once) return ; |
---|
[488] | 2685 | |
---|
| 2686 | |
---|
[1158] | 2687 | StdString axisId ; |
---|
| 2688 | StdString axisBoundId; |
---|
[802] | 2689 | StdString timeid(getTimeCounterName()); |
---|
[614] | 2690 | StdString timeBoundId("axis_nbounds"); |
---|
[488] | 2691 | |
---|
[1158] | 2692 | StdString strTimeUnits ; |
---|
| 2693 | if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) strTimeUnits="days since " ; |
---|
| 2694 | else strTimeUnits="seconds since " ; |
---|
| 2695 | |
---|
| 2696 | if (field->getOperationTimeType() == func::CFunctor::instant) field->hasTimeInstant = true; |
---|
| 2697 | if (field->getOperationTimeType() == func::CFunctor::centered) field->hasTimeCentered = true; |
---|
| 2698 | |
---|
| 2699 | |
---|
| 2700 | if (field->file->time_counter.isEmpty()) |
---|
[488] | 2701 | { |
---|
[1158] | 2702 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2703 | if (field->hasTimeCentered) |
---|
| 2704 | { |
---|
| 2705 | timeCounterType=centered ; |
---|
| 2706 | if (!hasTimeCentered) createCenteredAxis=true ; |
---|
| 2707 | } |
---|
| 2708 | if (field->hasTimeInstant) |
---|
| 2709 | { |
---|
| 2710 | if (timeCounterType==none) timeCounterType=instant ; |
---|
| 2711 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2712 | } |
---|
[488] | 2713 | } |
---|
[1158] | 2714 | else if (field->file->time_counter==CFile::time_counter_attr::instant) |
---|
| 2715 | { |
---|
| 2716 | if (field->hasTimeCentered) |
---|
| 2717 | { |
---|
| 2718 | if (!hasTimeCentered) createCenteredAxis=true ; |
---|
| 2719 | } |
---|
| 2720 | if (field->hasTimeInstant) |
---|
| 2721 | { |
---|
| 2722 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2723 | timeCounterType=instant ; |
---|
| 2724 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2725 | } |
---|
| 2726 | } |
---|
| 2727 | else if (field->file->time_counter==CFile::time_counter_attr::centered) |
---|
| 2728 | { |
---|
| 2729 | if (field->hasTimeCentered) |
---|
| 2730 | { |
---|
| 2731 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2732 | timeCounterType=centered ; |
---|
| 2733 | if (!hasTimeCentered) createCenteredAxis=true ; |
---|
| 2734 | } |
---|
| 2735 | if (field->hasTimeInstant) |
---|
| 2736 | { |
---|
| 2737 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2738 | } |
---|
| 2739 | } |
---|
| 2740 | else if (field->file->time_counter==CFile::time_counter_attr::instant_exclusive) |
---|
| 2741 | { |
---|
| 2742 | if (field->hasTimeCentered) |
---|
| 2743 | { |
---|
| 2744 | if (!hasTimeCentered) createCenteredAxis=true ; |
---|
| 2745 | } |
---|
| 2746 | if (field->hasTimeInstant) |
---|
| 2747 | { |
---|
| 2748 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2749 | timeCounterType=instant ; |
---|
| 2750 | } |
---|
| 2751 | } |
---|
| 2752 | else if (field->file->time_counter==CFile::time_counter_attr::centered_exclusive) |
---|
| 2753 | { |
---|
| 2754 | if (field->hasTimeCentered) |
---|
| 2755 | { |
---|
| 2756 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2757 | timeCounterType=centered ; |
---|
| 2758 | } |
---|
| 2759 | if (field->hasTimeInstant) |
---|
| 2760 | { |
---|
| 2761 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2762 | } |
---|
| 2763 | } |
---|
| 2764 | else if (field->file->time_counter==CFile::time_counter_attr::exclusive) |
---|
| 2765 | { |
---|
| 2766 | if (field->hasTimeCentered) |
---|
| 2767 | { |
---|
| 2768 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2769 | if (timeCounterType==instant) createInstantAxis=true ; |
---|
| 2770 | timeCounterType=centered ; |
---|
| 2771 | } |
---|
| 2772 | if (field->hasTimeInstant) |
---|
| 2773 | { |
---|
| 2774 | if (timeCounterType==none) |
---|
| 2775 | { |
---|
| 2776 | createTimeCounterAxis=true ; |
---|
| 2777 | timeCounterType=instant ; |
---|
| 2778 | } |
---|
| 2779 | if (timeCounterType==centered) |
---|
| 2780 | { |
---|
| 2781 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2782 | } |
---|
| 2783 | } |
---|
| 2784 | } |
---|
| 2785 | else if (field->file->time_counter==CFile::time_counter_attr::none) |
---|
| 2786 | { |
---|
| 2787 | if (field->hasTimeCentered) |
---|
| 2788 | { |
---|
| 2789 | if (!hasTimeCentered) createCenteredAxis=true ; |
---|
| 2790 | } |
---|
| 2791 | if (field->hasTimeInstant) |
---|
| 2792 | { |
---|
| 2793 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2794 | } |
---|
| 2795 | } |
---|
| 2796 | else if (field->file->time_counter==CFile::time_counter_attr::record) |
---|
| 2797 | { |
---|
| 2798 | if (timeCounterType==none) createTimeCounterAxis=true ; |
---|
| 2799 | timeCounterType=record ; |
---|
| 2800 | if (field->hasTimeCentered) |
---|
| 2801 | { |
---|
| 2802 | if (!hasTimeCentered) createCenteredAxis=true ; |
---|
| 2803 | } |
---|
| 2804 | if (field->hasTimeInstant) |
---|
| 2805 | { |
---|
| 2806 | if (!hasTimeInstant) createInstantAxis=true ; |
---|
| 2807 | } |
---|
| 2808 | } |
---|
| 2809 | |
---|
| 2810 | if (createInstantAxis) |
---|
| 2811 | { |
---|
| 2812 | axisId="time_instant" ; |
---|
| 2813 | axisBoundId="time_instant_bounds"; |
---|
| 2814 | hasTimeInstant=true ; |
---|
| 2815 | } |
---|
[488] | 2816 | |
---|
[1158] | 2817 | if (createCenteredAxis) |
---|
| 2818 | { |
---|
| 2819 | axisId="time_centered" ; |
---|
| 2820 | axisBoundId="time_centered_bounds"; |
---|
| 2821 | hasTimeCentered=true ; |
---|
| 2822 | } |
---|
| 2823 | |
---|
| 2824 | |
---|
[498] | 2825 | try |
---|
[219] | 2826 | { |
---|
[1158] | 2827 | std::vector<StdString> dims; |
---|
| 2828 | |
---|
| 2829 | if (createInstantAxis || createCenteredAxis) |
---|
| 2830 | { |
---|
| 2831 | // Adding time_instant or time_centered |
---|
| 2832 | dims.push_back(timeid); |
---|
| 2833 | if (!SuperClassWriter::varExist(axisId)) |
---|
| 2834 | { |
---|
| 2835 | SuperClassWriter::addVariable(axisId, NC_DOUBLE, dims); |
---|
[488] | 2836 | |
---|
[1158] | 2837 | CDate timeOrigin=cal->getTimeOrigin() ; |
---|
| 2838 | StdOStringStream oss2; |
---|
| 2839 | StdString strInitdate=oss2.str() ; |
---|
| 2840 | StdString strTimeOrigin=timeOrigin.toString() ; |
---|
| 2841 | this->writeTimeAxisAttributes(axisId, cal->getType(),strTimeUnits+strTimeOrigin, |
---|
| 2842 | strTimeOrigin, axisBoundId); |
---|
| 2843 | } |
---|
[219] | 2844 | |
---|
[1158] | 2845 | // Adding time_instant_bounds or time_centered_bounds variables |
---|
| 2846 | if (!SuperClassWriter::varExist(axisBoundId)) |
---|
| 2847 | { |
---|
| 2848 | dims.clear() ; |
---|
| 2849 | dims.push_back(timeid); |
---|
| 2850 | dims.push_back(timeBoundId); |
---|
| 2851 | SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); |
---|
| 2852 | } |
---|
[498] | 2853 | } |
---|
[488] | 2854 | |
---|
[1158] | 2855 | if (createTimeCounterAxis) |
---|
[498] | 2856 | { |
---|
[692] | 2857 | // Adding time_counter |
---|
[1158] | 2858 | axisId = getTimeCounterName(); |
---|
[802] | 2859 | axisBoundId = getTimeCounterName() + "_bounds"; |
---|
[692] | 2860 | dims.clear(); |
---|
| 2861 | dims.push_back(timeid); |
---|
[1158] | 2862 | if (!SuperClassWriter::varExist(axisId)) |
---|
[692] | 2863 | { |
---|
[1158] | 2864 | SuperClassWriter::addVariable(axisId, NC_DOUBLE, dims); |
---|
| 2865 | SuperClassWriter::addAttribute("axis", string("T"), &axisId); |
---|
[488] | 2866 | |
---|
[1158] | 2867 | if (field->file->time_counter.isEmpty() || |
---|
| 2868 | (field->file->time_counter != CFile::time_counter_attr::record)) |
---|
[692] | 2869 | { |
---|
| 2870 | CDate timeOrigin = cal->getTimeOrigin(); |
---|
| 2871 | StdString strTimeOrigin = timeOrigin.toString(); |
---|
[498] | 2872 | |
---|
[1158] | 2873 | this->writeTimeAxisAttributes(axisId, cal->getType(), |
---|
| 2874 | strTimeUnits+strTimeOrigin, |
---|
[692] | 2875 | strTimeOrigin, axisBoundId); |
---|
| 2876 | } |
---|
| 2877 | } |
---|
| 2878 | |
---|
| 2879 | // Adding time_counter_bound dimension |
---|
[1158] | 2880 | if (field->file->time_counter.isEmpty() || (field->file->time_counter != CFile::time_counter_attr::record)) |
---|
[692] | 2881 | { |
---|
| 2882 | if (!SuperClassWriter::varExist(axisBoundId)) |
---|
| 2883 | { |
---|
| 2884 | dims.clear(); |
---|
| 2885 | dims.push_back(timeid); |
---|
| 2886 | dims.push_back(timeBoundId); |
---|
| 2887 | SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); |
---|
| 2888 | } |
---|
| 2889 | } |
---|
[498] | 2890 | } |
---|
[488] | 2891 | } |
---|
[498] | 2892 | catch (CNetCdfException& e) |
---|
[488] | 2893 | { |
---|
[498] | 2894 | StdString msg("On writing time axis data: "); |
---|
| 2895 | msg.append("In the context : "); |
---|
| 2896 | CContext* context = CContext::getCurrent() ; |
---|
| 2897 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2898 | msg.append(e.what()); |
---|
| 2899 | ERROR("CNc4DataOutput::writeTimeAxis_ (CField* field, \ |
---|
[1542] | 2900 | const std::shared_ptr<CCalendar> cal)", << msg); |
---|
[488] | 2901 | } |
---|
[219] | 2902 | } |
---|
| 2903 | |
---|
| 2904 | //--------------------------------------------------------------- |
---|
[488] | 2905 | |
---|
[219] | 2906 | void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, |
---|
| 2907 | const StdString & calendar, |
---|
| 2908 | const StdString & units, |
---|
| 2909 | const StdString & time_origin, |
---|
[488] | 2910 | const StdString & time_bounds, |
---|
[219] | 2911 | const StdString & standard_name, |
---|
[613] | 2912 | const StdString & long_name) |
---|
[219] | 2913 | { |
---|
[498] | 2914 | try |
---|
| 2915 | { |
---|
| 2916 | SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); |
---|
| 2917 | SuperClassWriter::addAttribute("long_name", long_name , &axis_name); |
---|
| 2918 | SuperClassWriter::addAttribute("calendar", calendar , &axis_name); |
---|
| 2919 | SuperClassWriter::addAttribute("units", units , &axis_name); |
---|
| 2920 | SuperClassWriter::addAttribute("time_origin", time_origin , &axis_name); |
---|
| 2921 | SuperClassWriter::addAttribute("bounds", time_bounds , &axis_name); |
---|
| 2922 | } |
---|
| 2923 | catch (CNetCdfException& e) |
---|
| 2924 | { |
---|
| 2925 | StdString msg("On writing time axis Attribute: "); |
---|
| 2926 | msg.append("In the context : "); |
---|
| 2927 | CContext* context = CContext::getCurrent() ; |
---|
| 2928 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2929 | msg.append(e.what()); |
---|
| 2930 | ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \ |
---|
[613] | 2931 | const StdString & calendar,\ |
---|
| 2932 | const StdString & units, \ |
---|
| 2933 | const StdString & time_origin, \ |
---|
| 2934 | const StdString & time_bounds, \ |
---|
| 2935 | const StdString & standard_name, \ |
---|
| 2936 | const StdString & long_name)", << msg); |
---|
[498] | 2937 | } |
---|
[219] | 2938 | } |
---|
[488] | 2939 | |
---|
[219] | 2940 | //--------------------------------------------------------------- |
---|
| 2941 | |
---|
| 2942 | void CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, |
---|
| 2943 | const StdString & axis, |
---|
| 2944 | const StdString & standard_name, |
---|
| 2945 | const StdString & long_name, |
---|
| 2946 | const StdString & units, |
---|
| 2947 | const StdString & nav_model) |
---|
| 2948 | { |
---|
[498] | 2949 | try |
---|
| 2950 | { |
---|
[613] | 2951 | if (!axis.empty()) |
---|
| 2952 | SuperClassWriter::addAttribute("axis" , axis , &axis_name); |
---|
| 2953 | |
---|
[498] | 2954 | SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); |
---|
| 2955 | SuperClassWriter::addAttribute("long_name" , long_name , &axis_name); |
---|
| 2956 | SuperClassWriter::addAttribute("units" , units , &axis_name); |
---|
[973] | 2957 | // SuperClassWriter::addAttribute("nav_model" , nav_model , &axis_name); |
---|
[498] | 2958 | } |
---|
| 2959 | catch (CNetCdfException& e) |
---|
| 2960 | { |
---|
| 2961 | StdString msg("On writing Axis Attribute: "); |
---|
| 2962 | msg.append("In the context : "); |
---|
| 2963 | CContext* context = CContext::getCurrent() ; |
---|
| 2964 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2965 | msg.append(e.what()); |
---|
| 2966 | ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \ |
---|
[613] | 2967 | const StdString & axis, \ |
---|
| 2968 | const StdString & standard_name, \ |
---|
| 2969 | const StdString & long_name, \ |
---|
| 2970 | const StdString & units, \ |
---|
| 2971 | const StdString & nav_model)", << msg); |
---|
[498] | 2972 | } |
---|
[219] | 2973 | } |
---|
| 2974 | |
---|
| 2975 | //--------------------------------------------------------------- |
---|
[488] | 2976 | |
---|
[219] | 2977 | void CNc4DataOutput::writeLocalAttributes |
---|
| 2978 | (int ibegin, int ni, int jbegin, int nj, StdString domid) |
---|
| 2979 | { |
---|
[498] | 2980 | try |
---|
| 2981 | { |
---|
[318] | 2982 | SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin); |
---|
| 2983 | SuperClassWriter::addAttribute(StdString("ni" ).append(domid), ni); |
---|
| 2984 | SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin); |
---|
| 2985 | SuperClassWriter::addAttribute(StdString("nj" ).append(domid), nj); |
---|
[498] | 2986 | } |
---|
| 2987 | catch (CNetCdfException& e) |
---|
| 2988 | { |
---|
| 2989 | StdString msg("On writing Local Attributes: "); |
---|
| 2990 | msg.append("In the context : "); |
---|
| 2991 | CContext* context = CContext::getCurrent() ; |
---|
| 2992 | msg.append(context->getId()); msg.append("\n"); |
---|
| 2993 | msg.append(e.what()); |
---|
| 2994 | ERROR("CNc4DataOutput::writeLocalAttributes \ |
---|
| 2995 | (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg); |
---|
| 2996 | } |
---|
| 2997 | |
---|
[219] | 2998 | } |
---|
| 2999 | |
---|
[628] | 3000 | void CNc4DataOutput::writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid, |
---|
| 3001 | int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size) |
---|
[391] | 3002 | { |
---|
| 3003 | CArray<int,1> array(2) ; |
---|
| 3004 | |
---|
[498] | 3005 | try |
---|
| 3006 | { |
---|
| 3007 | SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ; |
---|
| 3008 | SuperClassWriter::addAttribute("DOMAIN_number", rank) ; |
---|
[629] | 3009 | array = SuperClassWriter::getDimension(dimXid) + 1, SuperClassWriter::getDimension(dimYid) + 1; |
---|
[498] | 3010 | SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ; |
---|
| 3011 | array=ni_glo,nj_glo ; |
---|
| 3012 | SuperClassWriter::addAttribute("DOMAIN_size_global", array) ; |
---|
| 3013 | array=ni,nj ; |
---|
| 3014 | SuperClassWriter::addAttribute("DOMAIN_size_local", array) ; |
---|
[819] | 3015 | array=ibegin+1,jbegin+1 ; |
---|
[498] | 3016 | SuperClassWriter::addAttribute("DOMAIN_position_first", array) ; |
---|
[819] | 3017 | array=ibegin+ni-1+1,jbegin+nj-1+1 ; |
---|
[498] | 3018 | SuperClassWriter::addAttribute("DOMAIN_position_last",array) ; |
---|
| 3019 | array=0,0 ; |
---|
| 3020 | SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ; |
---|
| 3021 | SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array); |
---|
| 3022 | SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ; |
---|
| 3023 | /* |
---|
| 3024 | SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ; |
---|
| 3025 | SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ; |
---|
| 3026 | SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ; |
---|
| 3027 | SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ; |
---|
| 3028 | */ |
---|
| 3029 | } |
---|
| 3030 | catch (CNetCdfException& e) |
---|
| 3031 | { |
---|
[628] | 3032 | StdString msg("On writing Local Attributes IOIPSL \n"); |
---|
[498] | 3033 | msg.append("In the context : "); |
---|
| 3034 | CContext* context = CContext::getCurrent() ; |
---|
| 3035 | msg.append(context->getId()); msg.append("\n"); |
---|
| 3036 | msg.append(e.what()); |
---|
| 3037 | ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \ |
---|
| 3038 | (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg); |
---|
| 3039 | } |
---|
[391] | 3040 | } |
---|
[219] | 3041 | //--------------------------------------------------------------- |
---|
| 3042 | |
---|
| 3043 | void CNc4DataOutput:: writeFileAttributes(const StdString & name, |
---|
| 3044 | const StdString & description, |
---|
| 3045 | const StdString & conventions, |
---|
| 3046 | const StdString & production, |
---|
| 3047 | const StdString & timeStamp) |
---|
| 3048 | { |
---|
[498] | 3049 | try |
---|
| 3050 | { |
---|
| 3051 | SuperClassWriter::addAttribute("name" , name); |
---|
| 3052 | SuperClassWriter::addAttribute("description", description); |
---|
[613] | 3053 | SuperClassWriter::addAttribute("title" , description); |
---|
| 3054 | SuperClassWriter::addAttribute("Conventions", conventions); |
---|
[1158] | 3055 | // SuperClassWriter::addAttribute("production" , production); |
---|
| 3056 | |
---|
| 3057 | StdString timeStampStr ; |
---|
| 3058 | if (file->time_stamp_name.isEmpty()) timeStampStr="timeStamp" ; |
---|
| 3059 | else timeStampStr=file->time_stamp_name ; |
---|
| 3060 | SuperClassWriter::addAttribute(timeStampStr, timeStamp); |
---|
| 3061 | |
---|
| 3062 | StdString uuidName ; |
---|
| 3063 | if (file->uuid_name.isEmpty()) uuidName="uuid" ; |
---|
| 3064 | else uuidName=file->uuid_name ; |
---|
| 3065 | |
---|
| 3066 | if (file->uuid_format.isEmpty()) SuperClassWriter::addAttribute(uuidName, getUuidStr()); |
---|
| 3067 | else SuperClassWriter::addAttribute(uuidName, getUuidStr(file->uuid_format)); |
---|
| 3068 | |
---|
[498] | 3069 | } |
---|
| 3070 | catch (CNetCdfException& e) |
---|
| 3071 | { |
---|
| 3072 | StdString msg("On writing File Attributes \n "); |
---|
| 3073 | msg.append("In the context : "); |
---|
| 3074 | CContext* context = CContext::getCurrent() ; |
---|
| 3075 | msg.append(context->getId()); msg.append("\n"); |
---|
| 3076 | msg.append(e.what()); |
---|
| 3077 | ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \ |
---|
| 3078 | const StdString & description, \ |
---|
| 3079 | const StdString & conventions, \ |
---|
| 3080 | const StdString & production, \ |
---|
| 3081 | const StdString & timeStamp)", << msg); |
---|
| 3082 | } |
---|
[219] | 3083 | } |
---|
| 3084 | |
---|
| 3085 | //--------------------------------------------------------------- |
---|
| 3086 | |
---|
| 3087 | void CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, |
---|
| 3088 | int data_dim, |
---|
| 3089 | int data_ni, |
---|
| 3090 | int data_nj, |
---|
| 3091 | int data_ibegin, |
---|
| 3092 | int data_jbegin) |
---|
| 3093 | { |
---|
[498] | 3094 | try |
---|
| 3095 | { |
---|
| 3096 | SuperClassWriter::addAttribute("data_dim" , data_dim , &mask_name); |
---|
| 3097 | SuperClassWriter::addAttribute("data_ni" , data_ni , &mask_name); |
---|
| 3098 | SuperClassWriter::addAttribute("data_nj" , data_nj , &mask_name); |
---|
| 3099 | SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name); |
---|
| 3100 | SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name); |
---|
| 3101 | } |
---|
| 3102 | catch (CNetCdfException& e) |
---|
| 3103 | { |
---|
| 3104 | StdString msg("On writing Mask Attributes \n "); |
---|
| 3105 | msg.append("In the context : "); |
---|
| 3106 | CContext* context = CContext::getCurrent() ; |
---|
| 3107 | msg.append(context->getId()); msg.append("\n"); |
---|
| 3108 | msg.append(e.what()); |
---|
| 3109 | ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \ |
---|
| 3110 | int data_dim, \ |
---|
| 3111 | int data_ni, \ |
---|
| 3112 | int data_nj, \ |
---|
| 3113 | int data_ibegin, \ |
---|
| 3114 | int data_jbegin)", << msg); |
---|
| 3115 | } |
---|
[219] | 3116 | } |
---|
| 3117 | |
---|
| 3118 | ///-------------------------------------------------------------- |
---|
| 3119 | |
---|
[1158] | 3120 | StdSize CNc4DataOutput::getRecordFromTime(Time time, double factorUnit) |
---|
[707] | 3121 | { |
---|
| 3122 | std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time); |
---|
| 3123 | if (it == timeToRecordCache.end()) |
---|
| 3124 | { |
---|
[802] | 3125 | StdString timeAxisBoundsId(getTimeCounterName() + "_bounds"); |
---|
[1158] | 3126 | if (!SuperClassWriter::varExist(timeAxisBoundsId)) timeAxisBoundsId = "time_centered_bounds"; |
---|
| 3127 | if (!SuperClassWriter::varExist(timeAxisBoundsId)) timeAxisBoundsId = "time_instant_bounds"; |
---|
[707] | 3128 | |
---|
| 3129 | CArray<double,2> timeAxisBounds; |
---|
[1158] | 3130 | std::vector<StdSize> dimSize(SuperClassWriter::getDimensions(timeAxisBoundsId)) ; |
---|
| 3131 | |
---|
[707] | 3132 | StdSize record = 0; |
---|
| 3133 | double dtime(time); |
---|
[1158] | 3134 | for (int n = dimSize[0] - 1; n >= 0; n--) |
---|
[707] | 3135 | { |
---|
[1158] | 3136 | SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective, n); |
---|
| 3137 | timeAxisBounds*=factorUnit ; |
---|
| 3138 | if (timeAxisBounds(1, 0) < dtime) |
---|
[707] | 3139 | { |
---|
| 3140 | record = n + 1; |
---|
| 3141 | break; |
---|
| 3142 | } |
---|
| 3143 | } |
---|
| 3144 | it = timeToRecordCache.insert(std::make_pair(time, record)).first; |
---|
| 3145 | } |
---|
| 3146 | return it->second; |
---|
| 3147 | } |
---|
[774] | 3148 | |
---|
| 3149 | ///-------------------------------------------------------------- |
---|
| 3150 | |
---|
| 3151 | bool CNc4DataOutput::isWrittenDomain(const std::string& domainName) const |
---|
| 3152 | { |
---|
| 3153 | return (this->writtenDomains.find(domainName) != this->writtenDomains.end()); |
---|
| 3154 | } |
---|
| 3155 | |
---|
| 3156 | bool CNc4DataOutput::isWrittenCompressedDomain(const std::string& domainName) const |
---|
| 3157 | { |
---|
| 3158 | return (this->writtenCompressedDomains.find(domainName) != this->writtenCompressedDomains.end()); |
---|
| 3159 | } |
---|
| 3160 | |
---|
| 3161 | bool CNc4DataOutput::isWrittenAxis(const std::string& axisName) const |
---|
| 3162 | { |
---|
| 3163 | return (this->writtenAxis.find(axisName) != this->writtenAxis.end()); |
---|
| 3164 | } |
---|
| 3165 | |
---|
| 3166 | bool CNc4DataOutput::isWrittenCompressedAxis(const std::string& axisName) const |
---|
| 3167 | { |
---|
| 3168 | return (this->writtenCompressedAxis.find(axisName) != this->writtenCompressedAxis.end()); |
---|
| 3169 | } |
---|
| 3170 | |
---|
[887] | 3171 | bool CNc4DataOutput::isWrittenScalar(const std::string& scalarName) const |
---|
| 3172 | { |
---|
| 3173 | return (this->writtenScalar.find(scalarName) != this->writtenScalar.end()); |
---|
| 3174 | } |
---|
| 3175 | |
---|
[774] | 3176 | void CNc4DataOutput::setWrittenDomain(const std::string& domainName) |
---|
| 3177 | { |
---|
| 3178 | this->writtenDomains.insert(domainName); |
---|
| 3179 | } |
---|
| 3180 | |
---|
| 3181 | void CNc4DataOutput::setWrittenCompressedDomain(const std::string& domainName) |
---|
| 3182 | { |
---|
| 3183 | this->writtenCompressedDomains.insert(domainName); |
---|
| 3184 | } |
---|
| 3185 | |
---|
| 3186 | void CNc4DataOutput::setWrittenAxis(const std::string& axisName) |
---|
| 3187 | { |
---|
| 3188 | this->writtenAxis.insert(axisName); |
---|
| 3189 | } |
---|
| 3190 | |
---|
| 3191 | void CNc4DataOutput::setWrittenCompressedAxis(const std::string& axisName) |
---|
| 3192 | { |
---|
| 3193 | this->writtenCompressedAxis.insert(axisName); |
---|
| 3194 | } |
---|
[887] | 3195 | |
---|
| 3196 | void CNc4DataOutput::setWrittenScalar(const std::string& scalarName) |
---|
| 3197 | { |
---|
| 3198 | this->writtenScalar.insert(scalarName); |
---|
| 3199 | } |
---|
[335] | 3200 | } // namespace xios |
---|