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