- Timestamp:
- 10/09/14 12:28:26 (10 years ago)
- Location:
- XIOS/trunk/src/output
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/output/nc4_data_output.cpp
r488 r498 10 10 #include "context.hpp" 11 11 #include "context_server.hpp" 12 #include "netCdfException.hpp" 13 #include "exception.hpp" 12 14 13 15 namespace xios … … 105 107 */ 106 108 107 switch (SuperClass::type) 108 { 109 case (MULTI_FILE) : 110 { 111 // if (domain->isEmpty()) return; 112 113 if (server->intraCommSize > 1) 114 { 115 // SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue()); 116 // SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue()); 117 } 118 119 switch (domain->type) 120 { 121 case CDomain::type_attr::curvilinear : 122 dim0.push_back(dimYid); dim0.push_back(dimXid); 123 lonid = StdString("nav_lon").append(appendDomid); 124 latid = StdString("nav_lat").append(appendDomid); 125 break ; 126 case CDomain::type_attr::regular : 127 lonid = StdString("lon").append(appendDomid); 128 latid = StdString("lat").append(appendDomid); 129 dim0.push_back(dimYid); 130 dim1.push_back(dimXid); 131 break; 132 case CDomain::type_attr::unstructured : 133 lonid = StdString("lon").append(appendDomid); 134 latid = StdString("lat").append(appendDomid); 135 bounds_lonid=string("bounds_lon").append(appendDomid); 136 bounds_latid=string("bounds_lat").append(appendDomid); 137 dim0.push_back(dimXid); 138 break; 139 } 140 141 if (domain->type == CDomain::type_attr::unstructured) 142 { 143 SuperClassWriter::addDimension(dimXid, domain->nj_glo); 144 } 145 else 146 { 147 SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv); 148 SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv); 149 } 150 151 if (server->intraCommSize > 1) 152 { 153 if (domain->type != CDomain::type_attr::unstructured) 154 { 155 this->writeLocalAttributes(domain->zoom_ibegin_srv, 156 domain->zoom_ni_srv, 157 domain->zoom_jbegin_srv, 158 domain->zoom_nj_srv, 159 appendDomid); 160 161 if (singleDomain) this->writeLocalAttributes_IOIPSL(domain->zoom_ibegin_srv, 162 domain->zoom_ni_srv, 163 domain->zoom_jbegin_srv, 164 domain->zoom_nj_srv, 165 domain->ni_glo,domain->nj_glo, 166 server->intraCommRank,server->intraCommSize); 167 } 168 } 169 170 switch (domain->type) 171 { 172 case CDomain::type_attr::curvilinear : 173 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 174 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 175 break ; 176 case CDomain::type_attr::regular : 177 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 178 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); 179 break ; 180 case CDomain::type_attr::unstructured : 181 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 182 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 183 } 184 185 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid); 186 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid); 187 188 dim0.clear(); 189 if (domain->type != CDomain::type_attr::unstructured) dim0.push_back(dimYid); 190 dim0.push_back(dimXid); 191 192 193 // supress mask if (server->intraCommSize > 1) 194 // supress mask { 195 // supress mask SuperClassWriter::addVariable(maskid, NC_INT, dim0); 196 // supress mask 197 // supress mask this->writeMaskAttributes(maskid, 198 // supress mask domain->data_dim.getValue()/*, 199 // supress mask domain->data_ni.getValue(), 200 // supress mask domain->data_nj.getValue(), 201 // supress mask domain->data_ibegin.getValue(), 202 // supress mask domain->data_jbegin.getValue()*/); 203 // supress mask } 204 205 //SuperClassWriter::setDefaultValue(maskid, &dvm); 206 207 SuperClassWriter::definition_end(); 208 209 switch (domain->type) 210 { 211 case CDomain::type_attr::curvilinear : 212 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); 213 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); 214 break; 215 case CDomain::type_attr::regular : 216 CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; 217 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0); 218 CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; 219 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0); 220 break; 221 } 222 SuperClassWriter::definition_start(); 223 224 break; 225 } 226 case (ONE_FILE) : 227 { 228 SuperClassWriter::addDimension(dimXid, domain->zoom_ni.getValue()); 229 SuperClassWriter::addDimension(dimYid, domain->zoom_nj.getValue()); 230 231 232 switch (domain->type) 233 { 234 case CDomain::type_attr::curvilinear : 235 dim0.push_back(dimYid); dim0.push_back(dimXid); 236 lonid = StdString("nav_lon").append(appendDomid); 237 latid = StdString("nav_lat").append(appendDomid); 238 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 239 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 240 break; 241 242 case CDomain::type_attr::regular : 243 dim0.push_back(dimYid); 244 dim1.push_back(dimXid); 245 lonid = StdString("lon").append(appendDomid); 246 latid = StdString("lat").append(appendDomid); 247 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 248 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); 249 break; 250 } 251 this->writeAxisAttributes 252 (lonid, "X", "longitude", "Longitude", "degrees_east", domid); 253 this->writeAxisAttributes 254 (latid, "Y", "latitude", "Latitude", "degrees_north", domid); 255 256 257 SuperClassWriter::definition_end(); 258 switch (domain->type) 259 { 260 case CDomain::type_attr::curvilinear : 261 { 262 std::vector<StdSize> start(2) ; 263 std::vector<StdSize> count(2) ; 264 if (domain->isEmpty()) 109 try 110 { 111 switch (SuperClass::type) 112 { 113 case (MULTI_FILE) : 114 { 115 // if (domain->isEmpty()) return; 116 117 if (server->intraCommSize > 1) 118 { 119 // SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue()); 120 // SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue()); 121 } 122 123 switch (domain->type) 124 { 125 case CDomain::type_attr::curvilinear : 126 dim0.push_back(dimYid); dim0.push_back(dimXid); 127 lonid = StdString("nav_lon").append(appendDomid); 128 latid = StdString("nav_lat").append(appendDomid); 129 break ; 130 case CDomain::type_attr::regular : 131 lonid = StdString("lon").append(appendDomid); 132 latid = StdString("lat").append(appendDomid); 133 dim0.push_back(dimYid); 134 dim1.push_back(dimXid); 135 break; 136 case CDomain::type_attr::unstructured : 137 lonid = StdString("lon").append(appendDomid); 138 latid = StdString("lat").append(appendDomid); 139 bounds_lonid=string("bounds_lon").append(appendDomid); 140 bounds_latid=string("bounds_lat").append(appendDomid); 141 dim0.push_back(dimXid); 142 break; 143 } 144 145 if (domain->type == CDomain::type_attr::unstructured) 146 { 147 SuperClassWriter::addDimension(dimXid, domain->nj_glo); 148 } 149 else 150 { 151 SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv); 152 SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv); 153 } 154 155 if (server->intraCommSize > 1) 156 { 157 if (domain->type != CDomain::type_attr::unstructured) 158 { 159 this->writeLocalAttributes(domain->zoom_ibegin_srv, 160 domain->zoom_ni_srv, 161 domain->zoom_jbegin_srv, 162 domain->zoom_nj_srv, 163 appendDomid); 164 165 if (singleDomain) this->writeLocalAttributes_IOIPSL(domain->zoom_ibegin_srv, 166 domain->zoom_ni_srv, 167 domain->zoom_jbegin_srv, 168 domain->zoom_nj_srv, 169 domain->ni_glo,domain->nj_glo, 170 server->intraCommRank,server->intraCommSize); 171 } 172 } 173 174 switch (domain->type) 175 { 176 case CDomain::type_attr::curvilinear : 177 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 178 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 179 break ; 180 case CDomain::type_attr::regular : 181 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 182 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); 183 break ; 184 case CDomain::type_attr::unstructured : 185 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 186 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 187 } 188 189 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid); 190 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid); 191 192 dim0.clear(); 193 if (domain->type != CDomain::type_attr::unstructured) dim0.push_back(dimYid); 194 dim0.push_back(dimXid); 195 196 197 // supress mask if (server->intraCommSize > 1) 198 // supress mask { 199 // supress mask SuperClassWriter::addVariable(maskid, NC_INT, dim0); 200 // supress mask 201 // supress mask this->writeMaskAttributes(maskid, 202 // supress mask domain->data_dim.getValue()/*, 203 // supress mask domain->data_ni.getValue(), 204 // supress mask domain->data_nj.getValue(), 205 // supress mask domain->data_ibegin.getValue(), 206 // supress mask domain->data_jbegin.getValue()*/); 207 // supress mask } 208 209 //SuperClassWriter::setDefaultValue(maskid, &dvm); 210 211 SuperClassWriter::definition_end(); 212 213 switch (domain->type) 214 { 215 case CDomain::type_attr::curvilinear : 216 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); 217 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); 218 break; 219 case CDomain::type_attr::regular : 220 CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; 221 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0); 222 CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; 223 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0); 224 break; 225 } 226 SuperClassWriter::definition_start(); 227 228 break; 229 } 230 case (ONE_FILE) : 231 { 232 SuperClassWriter::addDimension(dimXid, domain->zoom_ni.getValue()); 233 SuperClassWriter::addDimension(dimYid, domain->zoom_nj.getValue()); 234 235 236 switch (domain->type) 237 { 238 case CDomain::type_attr::curvilinear : 239 dim0.push_back(dimYid); dim0.push_back(dimXid); 240 lonid = StdString("nav_lon").append(appendDomid); 241 latid = StdString("nav_lat").append(appendDomid); 242 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 243 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 244 break; 245 246 case CDomain::type_attr::regular : 247 dim0.push_back(dimYid); 248 dim1.push_back(dimXid); 249 lonid = StdString("lon").append(appendDomid); 250 latid = StdString("lat").append(appendDomid); 251 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 252 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); 253 break; 254 } 255 this->writeAxisAttributes 256 (lonid, "X", "longitude", "Longitude", "degrees_east", domid); 257 this->writeAxisAttributes 258 (latid, "Y", "latitude", "Latitude", "degrees_north", domid); 259 260 261 SuperClassWriter::definition_end(); 262 switch (domain->type) 263 { 264 case CDomain::type_attr::curvilinear : 265 265 { 266 start[0]=0 ; start [1]=0 ; 267 count[0]=0 ; count[1]=0 ; 266 std::vector<StdSize> start(2) ; 267 std::vector<StdSize> count(2) ; 268 if (domain->isEmpty()) 269 { 270 start[0]=0 ; start [1]=0 ; 271 count[0]=0 ; count[1]=0 ; 272 } 273 else 274 { 275 start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 276 count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 277 } 278 279 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); 280 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); 281 break; 268 282 } 269 else283 case CDomain::type_attr::regular : 270 284 { 271 start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 272 count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 285 std::vector<StdSize> start(1) ; 286 std::vector<StdSize> count(1) ; 287 if (domain->isEmpty()) 288 { 289 start[0]=0 ; 290 count[0]=0 ; 291 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); 292 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); } 293 else 294 { 295 start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 296 count[0]=domain->zoom_nj_srv ; 297 CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; 298 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); 299 300 start[0]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; 301 count[0]=domain->zoom_ni_srv ; 302 CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; 303 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); 304 } 305 break; 273 306 } 274 275 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); 276 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); 277 break; 278 } 279 case CDomain::type_attr::regular : 280 { 281 std::vector<StdSize> start(1) ; 282 std::vector<StdSize> count(1) ; 283 if (domain->isEmpty()) 284 { 285 start[0]=0 ; 286 count[0]=0 ; 287 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); 288 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); } 289 else 290 { 291 start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 292 count[0]=domain->zoom_nj_srv ; 293 CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; 294 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); 295 296 start[0]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; 297 count[0]=domain->zoom_ni_srv ; 298 CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; 299 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); 300 } 301 break; 302 } 303 } 304 SuperClassWriter::definition_start(); 305 break; 306 } 307 default : 308 ERROR("CNc4DataOutput::writeDomain(domain)", 309 << "[ type = " << SuperClass::type << "]" 310 << " not implemented yet !"); 311 } 307 } 308 SuperClassWriter::definition_start(); 309 break; 310 } 311 default : 312 ERROR("CNc4DataOutput::writeDomain(domain)", 313 << "[ type = " << SuperClass::type << "]" 314 << " not implemented yet !"); 315 } 316 } 317 catch (CNetCdfException& e) 318 { 319 StdString msg("On writing the domain : "); 320 msg.append(domid); msg.append("\n"); 321 msg.append("In the context : "); 322 msg.append(context->getId()); msg.append("\n"); 323 msg.append(e.what()); 324 ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg); 325 } 326 312 327 domain->addRelFile(this->filename); 313 328 } … … 335 350 string lonid,latid,bounds_lonid,bounds_latid ; 336 351 337 switch (SuperClass::type) 338 { 339 case (MULTI_FILE) : 340 { 341 lonid = StdString("lon").append(appendDomid); 342 latid = StdString("lat").append(appendDomid); 343 dim0.push_back(dimXid); 344 345 SuperClassWriter::addDimension(dimXid, domain->zoom_nj_srv); 346 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 347 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 348 349 bounds_lonid = StdString("bounds_lon").append(appendDomid); 350 bounds_latid = StdString("bounds_lat").append(appendDomid); 351 352 353 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid); 354 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); 355 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid); 356 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); 357 if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); 358 dim0.clear(); 359 if (domain->hasBounds) 360 { 352 try 353 { 354 switch (SuperClass::type) 355 { 356 case (MULTI_FILE) : 357 { 358 lonid = StdString("lon").append(appendDomid); 359 latid = StdString("lat").append(appendDomid); 361 360 dim0.push_back(dimXid); 362 dim0.push_back(dimVertId); 363 SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 364 SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 365 } 366 367 dim0.clear(); 368 dim0.push_back(dimXid); 369 370 SuperClassWriter::definition_end(); 371 372 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); 373 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); 374 375 if (domain->hasBounds) 376 { 377 SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0); 378 SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0); 379 } 380 SuperClassWriter::definition_start(); 381 break ; 382 } 383 384 case (ONE_FILE) : 385 { 386 lonid = StdString("lon").append(appendDomid); 387 latid = StdString("lat").append(appendDomid); 388 bounds_lonid = StdString("bounds_lon").append(appendDomid); 389 bounds_latid = StdString("bounds_lat").append(appendDomid); 390 dim0.push_back(dimXid); 391 SuperClassWriter::addDimension(dimXid, domain->nj_glo); 392 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 393 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 394 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid); 395 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); 396 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid); 397 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); 398 if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); 399 dim0.clear(); 400 401 if (domain->hasBounds) 402 { 361 362 SuperClassWriter::addDimension(dimXid, domain->zoom_nj_srv); 363 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 364 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 365 366 bounds_lonid = StdString("bounds_lon").append(appendDomid); 367 bounds_latid = StdString("bounds_lat").append(appendDomid); 368 369 370 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid); 371 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); 372 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid); 373 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); 374 if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); 375 dim0.clear(); 376 if (domain->hasBounds) 377 { 378 dim0.push_back(dimXid); 379 dim0.push_back(dimVertId); 380 SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 381 SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 382 } 383 384 dim0.clear(); 403 385 dim0.push_back(dimXid); 404 dim0.push_back(dimVertId); 405 SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 406 SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 407 } 408 409 SuperClassWriter::definition_end(); 410 411 std::vector<StdSize> start(1), startBounds(2) ; 412 std::vector<StdSize> count(1), countBounds(2) ; 413 if (domain->isEmpty()) 414 { 415 start[0]=0 ; 416 count[0]=0 ; 417 startBounds[1]=0 ; 418 countBounds[1]=domain->nvertex ; 419 startBounds[0]=0 ; 420 countBounds[0]=0 ; 421 } 422 else 423 { 424 start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ; 425 count[0]=domain->zoom_nj_srv ; 426 startBounds[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ; 427 startBounds[1]=0 ; 428 countBounds[0]=domain->zoom_nj_srv ; 429 countBounds[1]=domain->nvertex ; 430 } 431 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); 432 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); 433 if (domain->hasBounds) 434 { 435 SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0,&startBounds,&countBounds); 436 SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0,&startBounds,&countBounds); 437 } 438 439 440 SuperClassWriter::definition_start(); 441 442 break; 443 } 444 default : 445 ERROR("CNc4DataOutput::writeDomain(domain)", 446 << "[ type = " << SuperClass::type << "]" 447 << " not implemented yet !"); 386 387 SuperClassWriter::definition_end(); 388 389 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); 390 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); 391 392 if (domain->hasBounds) 393 { 394 SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0); 395 SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0); 396 } 397 SuperClassWriter::definition_start(); 398 break ; 399 } 400 401 case (ONE_FILE) : 402 { 403 lonid = StdString("lon").append(appendDomid); 404 latid = StdString("lat").append(appendDomid); 405 bounds_lonid = StdString("bounds_lon").append(appendDomid); 406 bounds_latid = StdString("bounds_lat").append(appendDomid); 407 dim0.push_back(dimXid); 408 SuperClassWriter::addDimension(dimXid, domain->nj_glo); 409 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 410 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 411 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid); 412 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); 413 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid); 414 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); 415 if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); 416 dim0.clear(); 417 418 if (domain->hasBounds) 419 { 420 dim0.push_back(dimXid); 421 dim0.push_back(dimVertId); 422 SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 423 SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 424 } 425 426 SuperClassWriter::definition_end(); 427 428 std::vector<StdSize> start(1), startBounds(2) ; 429 std::vector<StdSize> count(1), countBounds(2) ; 430 if (domain->isEmpty()) 431 { 432 start[0]=0 ; 433 count[0]=0 ; 434 startBounds[1]=0 ; 435 countBounds[1]=domain->nvertex ; 436 startBounds[0]=0 ; 437 countBounds[0]=0 ; 438 } 439 else 440 { 441 start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ; 442 count[0]=domain->zoom_nj_srv ; 443 startBounds[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ; 444 startBounds[1]=0 ; 445 countBounds[0]=domain->zoom_nj_srv ; 446 countBounds[1]=domain->nvertex ; 447 } 448 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); 449 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); 450 if (domain->hasBounds) 451 { 452 SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0,&startBounds,&countBounds); 453 SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0,&startBounds,&countBounds); 454 } 455 456 457 SuperClassWriter::definition_start(); 458 459 break; 460 } 461 default : 462 ERROR("CNc4DataOutput::writeDomain(domain)", 463 << "[ type = " << SuperClass::type << "]" 464 << " not implemented yet !"); 465 } 466 } 467 catch (CNetCdfException& e) 468 { 469 StdString msg("On writing the domain : "); 470 msg.append(domid); msg.append("\n"); 471 msg.append("In the context : "); 472 msg.append(context->getId()); msg.append("\n"); 473 msg.append(e.what()); 474 ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg); 448 475 } 449 476 domain->addRelFile(this->filename); … … 458 485 StdSize zoom_begin=axis->zoom_begin.getValue()-1 ; 459 486 487 460 488 std::vector<StdString> dims; 461 489 StdString axisid = (!axis->name.isEmpty()) 462 490 ? axis->name.getValue() : axis->getId(); 463 SuperClassWriter::addDimension(axisid, zoom_size); 464 dims.push_back(axisid); 465 466 switch (SuperClass::type) 467 { 468 case (MULTI_FILE ) : 469 {} 470 case (ONE_FILE) : 471 { 472 SuperClassWriter::addVariable(axisid, NC_FLOAT, dims); 473 474 SuperClassWriter::addAttribute("axis", StdString("Z"), &axisid); 475 476 if (!axis->standard_name.isEmpty()) 477 SuperClassWriter::addAttribute 478 ("standard_name", axis->standard_name.getValue(), &axisid); 479 480 if (!axis->long_name.isEmpty()) 481 SuperClassWriter::addAttribute 482 ("long_name", axis->long_name.getValue(), &axisid); 483 484 if (!axis->unit.isEmpty()) 485 SuperClassWriter::addAttribute 486 ("units", axis->unit.getValue(), &axisid); 487 488 if (!axis->positive.isEmpty()) 489 if (axis->positive==CAxis::positive_attr::up) SuperClassWriter::addAttribute("positive", string("up"), &axisid); 490 else SuperClassWriter::addAttribute("positive", string("down"), &axisid); 491 492 SuperClassWriter::definition_end(); 493 494 CArray<double,1> axis_value(zoom_size) ; 495 for(StdSize i = 0 ; i < zoom_size ; i++) axis_value(i)=axis->value(i+zoom_begin) ; 496 SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); 497 498 SuperClassWriter::definition_start(); 499 500 break; 501 } 502 default : 503 ERROR("CNc4DataOutput::writeDomain(domain)", 504 << "[ type = " << SuperClass::type << "]" 505 << " not implemented yet !"); 491 try 492 { 493 SuperClassWriter::addDimension(axisid, zoom_size); 494 dims.push_back(axisid); 495 496 switch (SuperClass::type) 497 { 498 case (MULTI_FILE ) : 499 {} 500 case (ONE_FILE) : 501 { 502 SuperClassWriter::addVariable(axisid, NC_FLOAT, dims); 503 504 SuperClassWriter::addAttribute("axis", StdString("Z"), &axisid); 505 506 if (!axis->standard_name.isEmpty()) 507 SuperClassWriter::addAttribute 508 ("standard_name", axis->standard_name.getValue(), &axisid); 509 510 if (!axis->long_name.isEmpty()) 511 SuperClassWriter::addAttribute 512 ("long_name", axis->long_name.getValue(), &axisid); 513 514 if (!axis->unit.isEmpty()) 515 SuperClassWriter::addAttribute 516 ("units", axis->unit.getValue(), &axisid); 517 518 if (!axis->positive.isEmpty()) 519 if (axis->positive==CAxis::positive_attr::up) SuperClassWriter::addAttribute("positive", string("up"), &axisid); 520 else SuperClassWriter::addAttribute("positive", string("down"), &axisid); 521 522 SuperClassWriter::definition_end(); 523 524 CArray<double,1> axis_value(zoom_size) ; 525 for(StdSize i = 0 ; i < zoom_size ; i++) axis_value(i)=axis->value(i+zoom_begin) ; 526 SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); 527 528 SuperClassWriter::definition_start(); 529 530 break; 531 } 532 default : 533 ERROR("CNc4DataOutput::writeDomain(domain)", 534 << "[ type = " << SuperClass::type << "]" 535 << " not implemented yet !"); 536 } 537 } 538 catch (CNetCdfException& e) 539 { 540 StdString msg("On writing the axis : "); 541 msg.append(axisid); msg.append("\n"); 542 msg.append("In the context : "); 543 CContext* context = CContext::getCurrent() ; 544 msg.append(context->getId()); msg.append("\n"); 545 msg.append(e.what()); 546 ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg); 506 547 } 507 548 axis->addRelFile(this->filename); … … 510 551 void CNc4DataOutput::writeTimeDimension_(void) 511 552 { 512 SuperClassWriter::addDimension("time_counter"); 513 SuperClassWriter::addDimension("time_bounds", 2); 553 try 554 { 555 SuperClassWriter::addDimension("time_counter"); 556 SuperClassWriter::addDimension("time_bounds", 2); 557 } 558 catch (CNetCdfException& e) 559 { 560 StdString msg("On writing time dimension : time_couter, time_bounds \n"); 561 msg.append("In the context : "); 562 CContext* context = CContext::getCurrent() ; 563 msg.append(context->getId()); msg.append("\n"); 564 msg.append(e.what()); 565 ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg); 566 } 514 567 } 515 568 //-------------------------------------------------------------- … … 614 667 dims.push_back(dimXid); 615 668 616 SuperClassWriter::addVariable(fieldid, type, dims); 617 618 if (!field->standard_name.isEmpty()) 619 SuperClassWriter::addAttribute 620 ("standard_name", field->standard_name.getValue(), &fieldid); 621 622 if (!field->long_name.isEmpty()) 623 SuperClassWriter::addAttribute 624 ("long_name", field->long_name.getValue(), &fieldid); 625 626 if (!field->unit.isEmpty()) 627 SuperClassWriter::addAttribute 628 ("units", field->unit.getValue(), &fieldid); 629 630 if (!field->valid_min.isEmpty()) 631 SuperClassWriter::addAttribute 632 ("valid_min", field->valid_min.getValue(), &fieldid); 633 634 if (!field->valid_max.isEmpty()) 635 SuperClassWriter::addAttribute 636 ("valid_max", field->valid_max.getValue(), &fieldid); 637 638 if (!field->scale_factor.isEmpty()) 639 SuperClassWriter::addAttribute 640 ("scale_factor", field->scale_factor.getValue(), &fieldid); 641 642 if (!field->add_offset.isEmpty()) 643 SuperClassWriter::addAttribute 644 ("add_offset", field->add_offset.getValue(), &fieldid); 645 646 SuperClassWriter::addAttribute 647 ("online_operation", field->operation.getValue(), &fieldid); 648 649 // write child variables as attributes 650 651 652 vector<CVariable*> listVars = field->getAllVariables() ; 653 for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ; 654 655 656 if (wtime) 657 { 658 CDuration duration ; 659 660 duration=CDuration::FromString(field->freq_op) ; 661 duration.solveTimeStep(*(context->calendar)); 662 SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid); 663 664 duration=CDuration::FromString(field->getRelFile()->output_freq) ; 665 duration.solveTimeStep(*(context->calendar)); 666 SuperClassWriter::addAttribute("interval_write", duration.toString(), &fieldid); 667 } 668 669 if (!field->default_value.isEmpty()) 670 { 671 double default_value = field->default_value.getValue(); 672 float fdefault_value = (float)default_value; 673 if (type == NC_DOUBLE) 674 SuperClassWriter::setDefaultValue(fieldid, &default_value); 675 else 676 SuperClassWriter::setDefaultValue(fieldid, &fdefault_value); 677 } 678 else 679 { 680 double * default_value = NULL; 681 SuperClassWriter::setDefaultValue(fieldid, default_value); 682 } 683 684 { // Ecriture des coordonnées 685 686 StdString coordstr; //boost::algorithm::join(coodinates, " ") 687 std::vector<StdString>::iterator 688 itc = coodinates.begin(), endc = coodinates.end(); 689 690 for (; itc!= endc; itc++) 691 { 692 StdString & coord = *itc; 693 if (itc+1 != endc) 694 coordstr.append(coord).append(" "); 695 else coordstr.append(coord); 696 } 697 698 SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid); 699 700 } 701 669 try 670 { 671 SuperClassWriter::addVariable(fieldid, type, dims); 672 673 if (!field->standard_name.isEmpty()) 674 SuperClassWriter::addAttribute 675 ("standard_name", field->standard_name.getValue(), &fieldid); 676 677 if (!field->long_name.isEmpty()) 678 SuperClassWriter::addAttribute 679 ("long_name", field->long_name.getValue(), &fieldid); 680 681 if (!field->unit.isEmpty()) 682 SuperClassWriter::addAttribute 683 ("units", field->unit.getValue(), &fieldid); 684 685 if (!field->valid_min.isEmpty()) 686 SuperClassWriter::addAttribute 687 ("valid_min", field->valid_min.getValue(), &fieldid); 688 689 if (!field->valid_max.isEmpty()) 690 SuperClassWriter::addAttribute 691 ("valid_max", field->valid_max.getValue(), &fieldid); 692 693 if (!field->scale_factor.isEmpty()) 694 SuperClassWriter::addAttribute 695 ("scale_factor", field->scale_factor.getValue(), &fieldid); 696 697 if (!field->add_offset.isEmpty()) 698 SuperClassWriter::addAttribute 699 ("add_offset", field->add_offset.getValue(), &fieldid); 700 701 SuperClassWriter::addAttribute 702 ("online_operation", field->operation.getValue(), &fieldid); 703 704 // write child variables as attributes 705 706 707 vector<CVariable*> listVars = field->getAllVariables() ; 708 for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ; 709 710 711 if (wtime) 712 { 713 CDuration duration ; 714 715 duration=CDuration::FromString(field->freq_op) ; 716 duration.solveTimeStep(*(context->calendar)); 717 SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid); 718 719 duration=CDuration::FromString(field->getRelFile()->output_freq) ; 720 duration.solveTimeStep(*(context->calendar)); 721 SuperClassWriter::addAttribute("interval_write", duration.toString(), &fieldid); 722 } 723 724 if (!field->default_value.isEmpty()) 725 { 726 double default_value = field->default_value.getValue(); 727 float fdefault_value = (float)default_value; 728 if (type == NC_DOUBLE) 729 SuperClassWriter::setDefaultValue(fieldid, &default_value); 730 else 731 SuperClassWriter::setDefaultValue(fieldid, &fdefault_value); 732 } 733 else 734 { 735 double * default_value = NULL; 736 SuperClassWriter::setDefaultValue(fieldid, default_value); 737 } 738 739 { // Ecriture des coordonnées 740 741 StdString coordstr; //boost::algorithm::join(coodinates, " ") 742 std::vector<StdString>::iterator 743 itc = coodinates.begin(), endc = coodinates.end(); 744 745 for (; itc!= endc; itc++) 746 { 747 StdString & coord = *itc; 748 if (itc+1 != endc) 749 coordstr.append(coord).append(" "); 750 else coordstr.append(coord); 751 } 752 753 SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid); 754 755 } 756 } 757 catch (CNetCdfException& e) 758 { 759 StdString msg("On writing field : "); 760 msg.append(fieldid); msg.append("\n"); 761 msg.append("In the context : "); 762 msg.append(context->getId()); msg.append("\n"); 763 msg.append(e.what()); 764 ERROR("CNc4DataOutput::writeField_(CField* field)", << msg); 765 } 702 766 } 703 767 … … 711 775 ? file->description.getValue() 712 776 : StdString("Created by xios"); 713 this->writeFileAttributes(filename, description, 714 StdString ("CF-1.1"), 715 StdString("An IPSL model"), 716 this->getTimeStamp()); 777 try 778 { 779 this->writeFileAttributes(filename, description, 780 StdString ("CF-1.1"), 781 StdString("An IPSL model"), 782 this->getTimeStamp()); 783 } 784 catch (CNetCdfException& e) 785 { 786 StdString msg("On writing file : "); 787 msg.append(filename); msg.append("\n"); 788 msg.append("In the context : "); 789 CContext* context = CContext::getCurrent() ; 790 msg.append(context->getId()); msg.append("\n"); 791 msg.append(e.what()); 792 ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg); 793 } 717 794 if (file->nbDomain==1) singleDomain=true ; 718 795 else singleDomain=false ; … … 726 803 else return ; 727 804 728 if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>(),&fieldId) ; 729 else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>(),&fieldId) ; 730 else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>(),&fieldId) ; 731 else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>(),&fieldId) ; 732 else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>(),&fieldId) ; 733 else addAttribute(name,var->getData<string>(),&fieldId) ; 805 try 806 { 807 if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>(),&fieldId) ; 808 else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>(),&fieldId) ; 809 else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>(),&fieldId) ; 810 else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>(),&fieldId) ; 811 else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>(),&fieldId) ; 812 else addAttribute(name,var->getData<string>(),&fieldId) ; 813 } 814 catch (CNetCdfException& e) 815 { 816 StdString msg("On writing attributes of variable with name : "); 817 msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n"); 818 msg.append("In the context : "); 819 CContext* context = CContext::getCurrent() ; 820 msg.append(context->getId()); msg.append("\n"); 821 msg.append(e.what()); 822 ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg); 823 } 734 824 } 735 825 … … 740 830 else if (var->hasId()) name=var->getId() ; 741 831 else return ; 742 743 if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>()) ; 744 else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>()) ; 745 else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>()) ; 746 else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>()) ; 747 else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>()) ; 748 else addAttribute(name,var->getData<string>()) ; 832 try 833 { 834 if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>()) ; 835 else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>()) ; 836 else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>()) ; 837 else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>()) ; 838 else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>()) ; 839 else addAttribute(name,var->getData<string>()) ; 840 } 841 catch (CNetCdfException& e) 842 { 843 StdString msg("On writing attributes of variable with name : "); 844 msg.append(name); msg.append("\n"); 845 msg.append("In the context : "); 846 CContext* context = CContext::getCurrent() ; 847 msg.append(context->getId()); msg.append("\n"); 848 msg.append(e.what()); 849 ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg); 850 } 749 851 } 750 852 751 853 void CNc4DataOutput::syncFile_ (void) 752 854 { 753 SuperClassWriter::sync() ; 855 try 856 { 857 SuperClassWriter::sync() ; 858 } 859 catch (CNetCdfException& e) 860 { 861 StdString msg("On synchronizing the write among processes"); 862 msg.append("In the context : "); 863 CContext* context = CContext::getCurrent() ; 864 msg.append(context->getId()); msg.append("\n"); 865 msg.append(e.what()); 866 ERROR("CNc4DataOutput::syncFile_ (void)", << msg); 867 } 754 868 } 755 869 756 870 void CNc4DataOutput::closeFile_ (void) 757 871 { 758 SuperClassWriter::close() ; 872 try 873 { 874 SuperClassWriter::close() ; 875 } 876 catch (CNetCdfException& e) 877 { 878 StdString msg("On closing file"); 879 msg.append("In the context : "); 880 CContext* context = CContext::getCurrent() ; 881 msg.append(context->getId()); msg.append("\n"); 882 msg.append(e.what()); 883 ERROR("CNc4DataOutput::syncFile_ (void)", << msg); 884 } 885 759 886 } 760 887 … … 842 969 } 843 970 844 if (grid->hasAxis()) // 3D 845 { 846 CAxis* axis = grid->axis ; 847 CArray<double,3> field_data3D(domain->zoom_ni_srv,domain->zoom_nj_srv,axis->zoom_size) ; 848 if (!field->default_value.isEmpty()) field_data3D = field->default_value ; 849 850 field->outputField(field_data3D); 851 852 if (!field->prec.isEmpty() && field->prec==2) field_data3D=round(field_data3D) ; 853 854 switch (SuperClass::type) 971 try 972 { 973 if (grid->hasAxis()) // 3D 855 974 { 856 case (MULTI_FILE) : 975 CAxis* axis = grid->axis ; 976 CArray<double,3> field_data3D(domain->zoom_ni_srv,domain->zoom_nj_srv,axis->zoom_size) ; 977 if (!field->default_value.isEmpty()) field_data3D = field->default_value ; 978 979 field->outputField(field_data3D); 980 981 if (!field->prec.isEmpty() && field->prec==2) field_data3D=round(field_data3D) ; 982 983 switch (SuperClass::type) 984 { 985 case (MULTI_FILE) : 986 { 987 SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1); 988 if (wtime) 989 { 990 SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1); 991 SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1); 992 SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1); 993 SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1); 994 } 995 break ; 996 } 997 case (ONE_FILE) : 998 { 999 std::vector<StdSize> start(3) ; 1000 std::vector<StdSize> count(3) ; 1001 if (domain->isEmpty()) 1002 { 1003 start[0]=0 ; start[1]=0 ; start[2]=0 ; 1004 count[0]=0 ; count[1]=0 ; start[2]=0 ; 1005 } 1006 else 1007 { 1008 // start[2]=domain->zoom_ibegin_loc.getValue()-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_loc.getValue()-domain->zoom_jbegin.getValue() ; start[0]=0 ; 1009 start[2]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; start[0]=0 ; 1010 count[2]=domain->zoom_ni_srv ; count[1]=domain->zoom_nj_srv ; count[0] = axis->zoom_size.getValue(); 1011 } 1012 SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1,&start,&count ); 1013 if (wtime) 1014 { 1015 SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep()-1,isRoot ); 1016 SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep()-1,isRoot ); 1017 SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1, isRoot ); 1018 SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1, isRoot); 1019 } 1020 break; 1021 } 1022 } 1023 1024 } 1025 else // 2D 1026 { 1027 CArray<double,2> field_data2D(domain->zoom_ni_srv,domain->zoom_nj_srv) ; 1028 if (!field->default_value.isEmpty()) field_data2D = field->default_value ; 1029 field->outputField(field_data2D); 1030 if (!field->prec.isEmpty() && field->prec==2) field_data2D=round(field_data2D) ; 1031 switch (SuperClass::type) 857 1032 { 858 SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1); 859 if (wtime) 860 { 861 SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1); 862 SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1); 863 SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1); 864 SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1); 865 } 866 break ; 1033 case (MULTI_FILE) : 1034 { 1035 SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1); 1036 if (wtime) 1037 { 1038 SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1); 1039 SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1); 1040 SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1); 1041 SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1); 1042 } 1043 break; 1044 } 1045 case (ONE_FILE) : 1046 { 1047 std::vector<StdSize> start(2) ; 1048 std::vector<StdSize> count(2) ; 1049 if (domain->isEmpty()) 1050 { 1051 start[0]=0 ; start[1]=0 ; 1052 count[0]=0 ; count[1]=0 ; 1053 } 1054 else 1055 { 1056 start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 1057 count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 1058 } 1059 1060 SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1,&start,&count); 1061 if (wtime) 1062 { 1063 SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep()-1,isRoot); 1064 SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep()-1,isRoot); 1065 SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1, isRoot); 1066 SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1, isRoot); 1067 } 1068 break; 1069 1070 } 867 1071 } 868 case (ONE_FILE) : 869 { 870 std::vector<StdSize> start(3) ; 871 std::vector<StdSize> count(3) ; 872 if (domain->isEmpty()) 873 { 874 start[0]=0 ; start[1]=0 ; start[2]=0 ; 875 count[0]=0 ; count[1]=0 ; start[2]=0 ; 876 } 877 else 878 { 879 // start[2]=domain->zoom_ibegin_loc.getValue()-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_loc.getValue()-domain->zoom_jbegin.getValue() ; start[0]=0 ; 880 start[2]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; start[0]=0 ; 881 count[2]=domain->zoom_ni_srv ; count[1]=domain->zoom_nj_srv ; count[0] = axis->zoom_size.getValue(); 882 } 883 SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1,&start,&count ); 884 if (wtime) 885 { 886 SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep()-1,isRoot ); 887 SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep()-1,isRoot ); 888 SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1, isRoot ); 889 SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1, isRoot); 890 } 891 break; 892 } 893 } 894 895 } 896 else // 2D 897 { 898 CArray<double,2> field_data2D(domain->zoom_ni_srv,domain->zoom_nj_srv) ; 899 if (!field->default_value.isEmpty()) field_data2D = field->default_value ; 900 field->outputField(field_data2D); 901 if (!field->prec.isEmpty() && field->prec==2) field_data2D=round(field_data2D) ; 902 switch (SuperClass::type) 903 { 904 case (MULTI_FILE) : 905 { 906 SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1); 907 if (wtime) 908 { 909 SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1); 910 SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1); 911 SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1); 912 SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1); 913 } 914 break; 915 } 916 case (ONE_FILE) : 917 { 918 std::vector<StdSize> start(2) ; 919 std::vector<StdSize> count(2) ; 920 if (domain->isEmpty()) 921 { 922 start[0]=0 ; start[1]=0 ; 923 count[0]=0 ; count[1]=0 ; 924 } 925 else 926 { 927 start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 928 count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 929 } 930 931 SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1,&start,&count); 932 if (wtime) 933 { 934 SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep()-1,isRoot); 935 SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep()-1,isRoot); 936 SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1, isRoot); 937 SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1, isRoot); 938 } 939 break; 940 941 } 942 } 1072 } 1073 } 1074 catch (CNetCdfException& e) 1075 { 1076 StdString msg("On writing field data: "); 1077 msg.append(fieldid); msg.append("\n"); 1078 msg.append("In the context : "); 1079 msg.append(context->getId()); msg.append("\n"); 1080 msg.append(e.what()); 1081 ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); 943 1082 } 944 1083 } … … 973 1112 } 974 1113 975 // Adding time_instant or time_centered 976 std::vector<StdString> dims; 977 dims.push_back(timeid); 978 if (!SuperClassWriter::varExist(axisid)) 979 { 980 SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 981 982 CDate timeOrigin=cal->getTimeOrigin() ; 983 StdOStringStream oss2; 984 // oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " 985 // <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; 986 StdString strInitdate=oss2.str() ; 987 StdString strTimeOrigin=timeOrigin.toString() ; 988 this->writeTimeAxisAttributes 989 (axisid, cal->getType(), 990 StdString("seconds since ").append(strTimeOrigin), 991 strTimeOrigin, axisBoundId); 992 } 993 994 // Adding time_instant_bounds or time_centered_bounds variables 995 if (!SuperClassWriter::varExist(axisBoundId)) 996 { 997 dims.clear() ; 998 dims.push_back(timeid); 999 dims.push_back(timeBoundId); 1000 SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); 1001 } 1002 1003 // Adding time_counter 1004 axisid = "time_counter" ; 1005 axisBoundId = "time_counter_bounds" ; 1006 dims.clear() ; 1007 dims.push_back(timeid); 1008 if (!SuperClassWriter::varExist(axisid)) 1009 { 1010 SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 1011 SuperClassWriter::addAttribute("axis", string("T"), &axisid); 1012 CDate timeOrigin=cal->getTimeOrigin() ; 1013 StdString strTimeOrigin=timeOrigin.toString() ; 1014 1015 this->writeTimeAxisAttributes 1016 (axisid, cal->getType(), 1017 StdString("seconds since ").append(strTimeOrigin), 1018 strTimeOrigin, axisBoundId); 1019 } 1020 1021 // Adding time_counter_bound dimension 1022 if (!SuperClassWriter::varExist(axisBoundId)) 1023 { 1024 dims.clear(); 1025 dims.push_back(timeid); 1026 dims.push_back(timeBoundId); 1027 SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); 1114 try 1115 { 1116 // Adding time_instant or time_centered 1117 std::vector<StdString> dims; 1118 dims.push_back(timeid); 1119 if (!SuperClassWriter::varExist(axisid)) 1120 { 1121 SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 1122 1123 CDate timeOrigin=cal->getTimeOrigin() ; 1124 StdOStringStream oss2; 1125 // oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " 1126 // <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; 1127 StdString strInitdate=oss2.str() ; 1128 StdString strTimeOrigin=timeOrigin.toString() ; 1129 this->writeTimeAxisAttributes 1130 (axisid, cal->getType(), 1131 StdString("seconds since ").append(strTimeOrigin), 1132 strTimeOrigin, axisBoundId); 1133 } 1134 1135 // Adding time_instant_bounds or time_centered_bounds variables 1136 if (!SuperClassWriter::varExist(axisBoundId)) 1137 { 1138 dims.clear() ; 1139 dims.push_back(timeid); 1140 dims.push_back(timeBoundId); 1141 SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); 1142 } 1143 1144 // Adding time_counter 1145 axisid = "time_counter" ; 1146 axisBoundId = "time_counter_bounds" ; 1147 dims.clear() ; 1148 dims.push_back(timeid); 1149 if (!SuperClassWriter::varExist(axisid)) 1150 { 1151 SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 1152 SuperClassWriter::addAttribute("axis", string("T"), &axisid); 1153 CDate timeOrigin=cal->getTimeOrigin() ; 1154 StdString strTimeOrigin=timeOrigin.toString() ; 1155 1156 this->writeTimeAxisAttributes 1157 (axisid, cal->getType(), 1158 StdString("seconds since ").append(strTimeOrigin), 1159 strTimeOrigin, axisBoundId); 1160 } 1161 1162 // Adding time_counter_bound dimension 1163 if (!SuperClassWriter::varExist(axisBoundId)) 1164 { 1165 dims.clear(); 1166 dims.push_back(timeid); 1167 dims.push_back(timeBoundId); 1168 SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); 1169 } 1170 } 1171 catch (CNetCdfException& e) 1172 { 1173 StdString msg("On writing time axis data: "); 1174 msg.append("In the context : "); 1175 CContext* context = CContext::getCurrent() ; 1176 msg.append(context->getId()); msg.append("\n"); 1177 msg.append(e.what()); 1178 ERROR("CNc4DataOutput::writeTimeAxis_ (CField* field, \ 1179 const boost::shared_ptr<CCalendar> cal)", << msg); 1028 1180 } 1029 1181 } … … 1040 1192 const StdString & title) 1041 1193 { 1042 SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); 1043 SuperClassWriter::addAttribute("long_name", long_name , &axis_name); 1044 SuperClassWriter::addAttribute("title", title , &axis_name); 1045 SuperClassWriter::addAttribute("calendar", calendar , &axis_name); 1046 SuperClassWriter::addAttribute("units", units , &axis_name); 1047 SuperClassWriter::addAttribute("time_origin", time_origin , &axis_name); 1048 SuperClassWriter::addAttribute("bounds", time_bounds , &axis_name); 1194 try 1195 { 1196 SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); 1197 SuperClassWriter::addAttribute("long_name", long_name , &axis_name); 1198 SuperClassWriter::addAttribute("title", title , &axis_name); 1199 SuperClassWriter::addAttribute("calendar", calendar , &axis_name); 1200 SuperClassWriter::addAttribute("units", units , &axis_name); 1201 SuperClassWriter::addAttribute("time_origin", time_origin , &axis_name); 1202 SuperClassWriter::addAttribute("bounds", time_bounds , &axis_name); 1203 } 1204 catch (CNetCdfException& e) 1205 { 1206 StdString msg("On writing time axis Attribute: "); 1207 msg.append("In the context : "); 1208 CContext* context = CContext::getCurrent() ; 1209 msg.append(context->getId()); msg.append("\n"); 1210 msg.append(e.what()); 1211 ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \ 1212 const StdString & calendar,\ 1213 const StdString & units, \ 1214 const StdString & time_origin, \ 1215 const StdString & time_bounds, \ 1216 const StdString & standard_name, \ 1217 const StdString & long_name, \ 1218 const StdString & title)", << msg); 1219 } 1049 1220 } 1050 1221 … … 1058 1229 const StdString & nav_model) 1059 1230 { 1060 SuperClassWriter::addAttribute("axis" , axis , &axis_name); 1061 SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); 1062 SuperClassWriter::addAttribute("long_name" , long_name , &axis_name); 1063 SuperClassWriter::addAttribute("units" , units , &axis_name); 1064 SuperClassWriter::addAttribute("nav_model" , nav_model , &axis_name); 1231 try 1232 { 1233 SuperClassWriter::addAttribute("axis" , axis , &axis_name); 1234 SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); 1235 SuperClassWriter::addAttribute("long_name" , long_name , &axis_name); 1236 SuperClassWriter::addAttribute("units" , units , &axis_name); 1237 SuperClassWriter::addAttribute("nav_model" , nav_model , &axis_name); 1238 } 1239 catch (CNetCdfException& e) 1240 { 1241 StdString msg("On writing Axis Attribute: "); 1242 msg.append("In the context : "); 1243 CContext* context = CContext::getCurrent() ; 1244 msg.append(context->getId()); msg.append("\n"); 1245 msg.append(e.what()); 1246 ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \ 1247 const StdString & axis, \ 1248 const StdString & standard_name, \ 1249 const StdString & long_name, \ 1250 const StdString & units, \ 1251 const StdString & nav_model)", << msg); 1252 } 1065 1253 } 1066 1254 … … 1070 1258 (int ibegin, int ni, int jbegin, int nj, StdString domid) 1071 1259 { 1260 try 1261 { 1072 1262 SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin); 1073 1263 SuperClassWriter::addAttribute(StdString("ni" ).append(domid), ni); 1074 1264 SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin); 1075 1265 SuperClassWriter::addAttribute(StdString("nj" ).append(domid), nj); 1266 } 1267 catch (CNetCdfException& e) 1268 { 1269 StdString msg("On writing Local Attributes: "); 1270 msg.append("In the context : "); 1271 CContext* context = CContext::getCurrent() ; 1272 msg.append(context->getId()); msg.append("\n"); 1273 msg.append(e.what()); 1274 ERROR("CNc4DataOutput::writeLocalAttributes \ 1275 (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg); 1276 } 1277 1076 1278 } 1077 1279 … … 1081 1283 CArray<int,1> array(2) ; 1082 1284 1083 SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ; 1084 SuperClassWriter::addAttribute("DOMAIN_number", rank) ; 1085 array=1,2 ; 1086 SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ; 1087 array=ni_glo,nj_glo ; 1088 SuperClassWriter::addAttribute("DOMAIN_size_global", array) ; 1089 array=ni,nj ; 1090 SuperClassWriter::addAttribute("DOMAIN_size_local", array) ; 1091 array=ibegin,jbegin ; 1092 SuperClassWriter::addAttribute("DOMAIN_position_first", array) ; 1093 array=ibegin+ni-1,jbegin+nj-1 ; 1094 SuperClassWriter::addAttribute("DOMAIN_position_last",array) ; 1095 array=0,0 ; 1096 SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ; 1097 SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array); 1098 SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ; 1099 /* 1100 SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ; 1101 SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ; 1102 SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ; 1103 SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ; 1104 */ 1105 1285 try 1286 { 1287 SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ; 1288 SuperClassWriter::addAttribute("DOMAIN_number", rank) ; 1289 array=1,2 ; 1290 SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ; 1291 array=ni_glo,nj_glo ; 1292 SuperClassWriter::addAttribute("DOMAIN_size_global", array) ; 1293 array=ni,nj ; 1294 SuperClassWriter::addAttribute("DOMAIN_size_local", array) ; 1295 array=ibegin,jbegin ; 1296 SuperClassWriter::addAttribute("DOMAIN_position_first", array) ; 1297 array=ibegin+ni-1,jbegin+nj-1 ; 1298 SuperClassWriter::addAttribute("DOMAIN_position_last",array) ; 1299 array=0,0 ; 1300 SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ; 1301 SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array); 1302 SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ; 1303 /* 1304 SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ; 1305 SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ; 1306 SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ; 1307 SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ; 1308 */ 1309 } 1310 catch (CNetCdfException& e) 1311 { 1312 StdString msg("On writing Local Attributes IOI PSL \n"); 1313 msg.append("In the context : "); 1314 CContext* context = CContext::getCurrent() ; 1315 msg.append(context->getId()); msg.append("\n"); 1316 msg.append(e.what()); 1317 ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \ 1318 (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg); 1319 } 1106 1320 } 1107 1321 //--------------------------------------------------------------- … … 1113 1327 const StdString & timeStamp) 1114 1328 { 1115 SuperClassWriter::addAttribute("name" , name); 1116 SuperClassWriter::addAttribute("description", description); 1117 SuperClassWriter::addAttribute("conventions", conventions); 1118 SuperClassWriter::addAttribute("production" , production); 1119 SuperClassWriter::addAttribute("timeStamp" , timeStamp); 1329 try 1330 { 1331 SuperClassWriter::addAttribute("name" , name); 1332 SuperClassWriter::addAttribute("description", description); 1333 SuperClassWriter::addAttribute("conventions", conventions); 1334 SuperClassWriter::addAttribute("production" , production); 1335 SuperClassWriter::addAttribute("timeStamp" , timeStamp); 1336 } 1337 catch (CNetCdfException& e) 1338 { 1339 StdString msg("On writing File Attributes \n "); 1340 msg.append("In the context : "); 1341 CContext* context = CContext::getCurrent() ; 1342 msg.append(context->getId()); msg.append("\n"); 1343 msg.append(e.what()); 1344 ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \ 1345 const StdString & description, \ 1346 const StdString & conventions, \ 1347 const StdString & production, \ 1348 const StdString & timeStamp)", << msg); 1349 } 1120 1350 } 1121 1351 … … 1129 1359 int data_jbegin) 1130 1360 { 1131 SuperClassWriter::addAttribute("data_dim" , data_dim , &mask_name); 1132 SuperClassWriter::addAttribute("data_ni" , data_ni , &mask_name); 1133 SuperClassWriter::addAttribute("data_nj" , data_nj , &mask_name); 1134 SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name); 1135 SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name); 1361 try 1362 { 1363 SuperClassWriter::addAttribute("data_dim" , data_dim , &mask_name); 1364 SuperClassWriter::addAttribute("data_ni" , data_ni , &mask_name); 1365 SuperClassWriter::addAttribute("data_nj" , data_nj , &mask_name); 1366 SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name); 1367 SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name); 1368 } 1369 catch (CNetCdfException& e) 1370 { 1371 StdString msg("On writing Mask Attributes \n "); 1372 msg.append("In the context : "); 1373 CContext* context = CContext::getCurrent() ; 1374 msg.append(context->getId()); msg.append("\n"); 1375 msg.append(e.what()); 1376 ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \ 1377 int data_dim, \ 1378 int data_ni, \ 1379 int data_nj, \ 1380 int data_ibegin, \ 1381 int data_jbegin)", << msg); 1382 } 1136 1383 } 1137 1384 -
XIOS/trunk/src/output/onetcdf4.cpp
r472 r498 3 3 #include "mpi.hpp" 4 4 #include "netcdf.hpp" 5 #include "netCdfInterface.hpp" 6 #include "netCdfException.hpp" 5 7 6 8 namespace xios … … 15 17 this->initialize(filename, exist, comm,multifile); 16 18 } 17 18 //--------------------------------------------------------------- 19 20 19 20 //--------------------------------------------------------------- 21 21 22 22 23 CONetCDF4::~CONetCDF4(void) … … 34 35 if (comm != NULL) 35 36 { 36 if (!multifile) CheckError(xios::nc_create_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp));37 else CheckError(nc_create(filename.c_str(), NC_NETCDF4, &this->ncidp));37 if (!multifile) (CNetCdfInterface::createPar(filename, NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, (this->ncidp))); 38 else (CNetCdfInterface::create(filename, NC_NETCDF4, this->ncidp)); 38 39 } 39 else CheckError(nc_create(filename.c_str(), NC_NETCDF4, &this->ncidp));40 else (CNetCdfInterface::create(filename, NC_NETCDF4, this->ncidp)); 40 41 } 41 42 else … … 43 44 if (comm != NULL) 44 45 { 45 if (!multifile) CheckError(xios::nc_open_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp));46 else CheckError(nc_open(filename.c_str(), NC_NETCDF4, &this->ncidp));46 if (!multifile) (CNetCdfInterface::openPar(filename, NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, this->ncidp)); 47 else (CNetCdfInterface::open(filename, NC_NETCDF4, this->ncidp)); 47 48 } 48 else CheckError(nc_open(filename.c_str(), NC_NETCDF4, &this->ncidp));49 } 50 } 51 49 else (CNetCdfInterface::open(filename, NC_NETCDF4, this->ncidp)); 50 } 51 } 52 52 53 void CONetCDF4::close() 53 54 { 54 CheckError(nc_close(this->ncidp));55 } 56 57 //--------------------------------------------------------------- 58 55 (CNetCdfInterface::close(this->ncidp)); 56 } 57 58 //--------------------------------------------------------------- 59 59 60 void CONetCDF4::definition_start(void) 60 { 61 CheckError(nc_redef(this->ncidp));62 } 63 64 //--------------------------------------------------------------- 65 61 { 62 (CNetCdfInterface::reDef(this->ncidp)); 63 } 64 65 //--------------------------------------------------------------- 66 66 67 void CONetCDF4::definition_end(void) 67 { 68 CheckError(nc_enddef(this->ncidp)); 69 } 70 71 //--------------------------------------------------------------- 72 73 void CONetCDF4::CheckError(int status) 74 { 75 if (status != NC_NOERR) 76 { 77 StdString errormsg (nc_strerror(status)); // fuite mémoire ici ? 78 ERROR("CONetCDF4::CheckError(int status)", 79 << "[ status = " << status << " ] " << errormsg); 80 } 81 } 82 83 //--------------------------------------------------------------- 84 68 { 69 (CNetCdfInterface::endDef(this->ncidp)); 70 } 71 72 //--------------------------------------------------------------- 73 74 // Don't need it anymore? 75 // void CONetCDF4::CheckError(int status) 76 // { 77 // if (status != NC_NOERR) 78 // { 79 // StdString errormsg (nc_strerror(status)); // fuite mémoire ici ? 80 // ERROR("CONetCDF4::CheckError(int status)", 81 // << "[ status = " << status << " ] " << errormsg); 82 // } 83 // } 84 85 //--------------------------------------------------------------- 86 85 87 int CONetCDF4::getCurrentGroup(void) 86 88 { 87 89 return (this->getGroup(this->getCurrentPath())); 88 90 } 89 90 //--------------------------------------------------------------- 91 91 92 //--------------------------------------------------------------- 93 92 94 int CONetCDF4::getGroup(const CONetCDF4Path & path) 93 95 { 94 96 int retvalue = this->ncidp; 95 97 96 98 CONetCDF4Path::const_iterator 97 99 it = path.begin(), end = path.end(); … … 100 102 { 101 103 const StdString & groupid = *it; 102 CheckError(nc_inq_ncid(retvalue, const_cast<char*>(groupid.c_str()), &retvalue));104 (CNetCdfInterface::inqNcId(retvalue, groupid, retvalue)); 103 105 } 104 106 return (retvalue); 105 107 } 106 107 //--------------------------------------------------------------- 108 108 109 //--------------------------------------------------------------- 110 109 111 int CONetCDF4::getVariable(const StdString & varname) 110 112 { 111 113 int varid = 0; 112 114 int grpid = this->getCurrentGroup(); 113 CheckError(nc_inq_varid (grpid, varname.c_str(), &varid));115 (CNetCdfInterface::inqVarId(grpid, varname, varid)); 114 116 return (varid); 115 117 } 116 117 //--------------------------------------------------------------- 118 118 119 //--------------------------------------------------------------- 120 119 121 int CONetCDF4::getDimension(const StdString & dimname) 120 122 { 121 123 int dimid = 0; 122 124 int grpid = this->getCurrentGroup(); 123 CheckError(nc_inq_dimid (grpid, dimname.c_str(), &dimid));125 (CNetCdfInterface::inqDimId(grpid, dimname, dimid)); 124 126 return (dimid); 125 127 } 126 127 //--------------------------------------------------------------- 128 128 129 //--------------------------------------------------------------- 130 129 131 int CONetCDF4::getUnlimitedDimension(void) 130 132 { 131 133 int dimid = 0; 132 134 int grpid = this->getCurrentGroup(); 133 CheckError(nc_inq_unlimdim (grpid, &dimid));135 (CNetCdfInterface::inqUnLimDim(grpid, dimid)); 134 136 return (dimid); 135 137 } 136 138 137 139 StdString CONetCDF4::getUnlimitedDimensionName(void) 138 140 { 139 char full_name_in[NC_MAX_NAME +1];140 141 int grpid = this->getGroup(path); 141 142 int dimid = this->getUnlimitedDimension(); 142 143 143 144 if (dimid == -1) return (std::string()); 144 CheckError(nc_inq_dimname(grpid, dimid, full_name_in));145 146 StdString dimname(full_name_in); 145 StdString dimname; 146 (CNetCdfInterface::inqDimName(grpid, dimid, dimname)); 147 147 148 return (dimname); 148 149 } 149 150 //--------------------------------------------------------------- 151 150 151 //--------------------------------------------------------------- 152 152 153 std::vector<StdSize> CONetCDF4::getDimensions(const StdString & varname) 153 154 { … … 158 159 int nbdim = 0, *dimid = NULL; 159 160 160 CheckError(nc_inq_varndims(grpid, varid, &nbdim));161 (CNetCdfInterface::inqVarNDims(grpid, varid, nbdim)); 161 162 dimid = new int[nbdim](); 162 CheckError(nc_inq_vardimid(grpid, varid, dimid));163 (CNetCdfInterface::inqVarDimId(grpid, varid, dimid)); 163 164 164 165 for (int i = 0; i < nbdim; i++) 165 166 { 166 CheckError(nc_inq_dimlen (grpid, dimid[i], &size));167 (CNetCdfInterface::inqDimLen(grpid, dimid[i], size)); 167 168 if (size == NC_UNLIMITED) 168 169 size = UNLIMITED_DIM; … … 175 176 std::vector<std::string> CONetCDF4::getDimensionsIdList (const std::string * _varname) 176 177 { 177 char full_name_in[NC_MAX_NAME +1];178 int nDimNull = 0; 178 179 int nbdim = 0, *dimid = NULL; 179 180 int grpid = this->getCurrentGroup(); 180 181 int varid = (_varname != NULL) ? this->getVariable(*_varname) : NC_GLOBAL; 181 182 std::vector<std::string> retvalue; 182 183 183 184 if (_varname != NULL) 184 185 { 185 CheckError(nc_inq_varndims(grpid, varid, &nbdim));186 (CNetCdfInterface::inqVarNDims(grpid, varid, nbdim)); 186 187 dimid = new int[nbdim](); 187 CheckError(nc_inq_vardimid(grpid, varid, dimid));188 (CNetCdfInterface::inqVarDimId(grpid, varid, dimid)); 188 189 } 189 190 else 190 191 { 191 CheckError(nc_inq_dimids(grpid, &nbdim, NULL, 1));192 (CNetCdfInterface::inqDimIds(grpid, nbdim, NULL, 1)); 192 193 dimid = new int[nbdim](); 193 CheckError(nc_inq_dimids(grpid, NULL, dimid, 1));194 } 195 194 (CNetCdfInterface::inqDimIds(grpid, nDimNull, dimid, 1)); 195 } 196 196 197 for (int i = 0; i < nbdim; i++) 197 198 { 198 CheckError(nc_inq_dimname(grpid, dimid[i], full_name_in));199 std::string dimname(full_name_in);199 std::string dimname; 200 (CNetCdfInterface::inqDimName(grpid, dimid[i], dimname)); 200 201 retvalue.push_back(dimname); 201 202 } 202 203 delete [] dimid; 203 204 204 205 return (retvalue); 205 206 } … … 220 221 int retvalue = 0; 221 222 int grpid = this->getCurrentGroup(); 222 CheckError(nc_def_grp(grpid, const_cast<char*>(name.c_str()), &retvalue));223 (CNetCdfInterface::defGrp(grpid, name, retvalue)); 223 224 return (retvalue); 224 225 } 225 226 //--------------------------------------------------------------- 227 226 227 //--------------------------------------------------------------- 228 228 229 int CONetCDF4::addDimension(const StdString& name, const StdSize size) 229 230 { … … 231 232 int grpid = this->getCurrentGroup(); 232 233 if (size != UNLIMITED_DIM) 233 CheckError(nc_def_dim (grpid, name.c_str(), size, &retvalue));234 (CNetCdfInterface::defDim(grpid, name, size, retvalue)); 234 235 else 235 CheckError(nc_def_dim (grpid, name.c_str(), NC_UNLIMITED, &retvalue));236 (CNetCdfInterface::defDim(grpid, name, NC_UNLIMITED, retvalue)); 236 237 return (retvalue); 237 238 } 238 239 //--------------------------------------------------------------- 240 239 240 //--------------------------------------------------------------- 241 241 242 int CONetCDF4::addVariable(const StdString & name, nc_type type, 242 243 const std::vector<StdString> & dim) … … 248 249 StdSize totalSize ; 249 250 StdSize maxSize=1024*1024*256 ; // == 2GB/8 if output double 250 251 int grpid = this->getCurrentGroup(); 252 251 252 int grpid = this->getCurrentGroup(); 253 253 254 std::vector<StdString>::const_iterator 254 255 it = dim.begin(), end = dim.end(); … … 258 259 const StdString & dimid = *it; 259 260 dimids.push_back(this->getDimension(dimid)); 260 CheckError(nc_inq_dimlen (grpid, this->getDimension(dimid), &size));261 (CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size)); 261 262 if (size==NC_UNLIMITED) size=1 ; 262 263 dimsizes.push_back(size) ; 263 264 } 264 265 CheckError(nc_def_var (grpid, name.c_str(), type, dimids.size(), &(dimids[0]), &varid));265 266 (CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &(dimids[0]), varid)); 266 267 267 268 // set chunksize : size of one record … … 274 275 } 275 276 276 CheckError(nc_def_var_chunking(grpid, varid, NC_CHUNKED, &(dimsizes[0])));277 CheckError(nc_def_var_fill(grpid, varid, true, NULL));277 (CNetCdfInterface::defVarChunking(grpid, varid, NC_CHUNKED, &(dimsizes[0]))); 278 (CNetCdfInterface::defVarFill(grpid, varid, true, NULL)); 278 279 return (varid); 279 280 } … … 287 288 int grpid = this->getCurrentGroup(); 288 289 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 289 CheckError(nc_put_att(grpid, varid, name.c_str(), NC_CHAR, value.size(), value.c_str()));290 (CNetCdfInterface::putAtt(grpid, varid, name, NC_CHAR, value.size(), value.c_str())); 290 291 //CheckError(nc_put_att_string(grpid, varid, name.c_str(), 1, &str)); 291 292 } 292 293 //--------------------------------------------------------------- 294 293 294 //--------------------------------------------------------------- 295 295 296 template <> 296 297 void CONetCDF4::addAttribute … … 299 300 int grpid = this->getCurrentGroup(); 300 301 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 301 CheckError(nc_put_att_double(grpid, varid, name.c_str(), NC_DOUBLE,1, &value));302 (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 302 303 } 303 304 … … 308 309 int grpid = this->getCurrentGroup(); 309 310 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 310 CheckError(nc_put_att_double(grpid, varid, name.c_str(), NC_DOUBLE,value.numElements(), value.dataFirst()));311 } 312 //--------------------------------------------------------------- 313 311 (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 312 } 313 //--------------------------------------------------------------- 314 314 315 template <> 315 316 void CONetCDF4::addAttribute … … 318 319 int grpid = this->getCurrentGroup(); 319 320 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 320 CheckError(nc_put_att_float(grpid, varid, name.c_str(), NC_FLOAT, 1, &value));321 (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 321 322 } 322 323 … … 327 328 int grpid = this->getCurrentGroup(); 328 329 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 329 CheckError(nc_put_att_float(grpid, varid, name.c_str(), NC_FLOAT,value.numElements(), value.dataFirst()));330 } 331 332 //--------------------------------------------------------------- 333 330 (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 331 } 332 333 //--------------------------------------------------------------- 334 334 335 template <> 335 336 void CONetCDF4::addAttribute … … 338 339 int grpid = this->getCurrentGroup(); 339 340 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 340 CheckError(nc_put_att_int(grpid, varid, name.c_str(), NC_INT,1, &value));341 (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 341 342 } 342 343 … … 347 348 int grpid = this->getCurrentGroup(); 348 349 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 349 CheckError(nc_put_att_int(grpid, varid, name.c_str(), NC_INT,value.numElements(), value.dataFirst())); 350 } 351 352 353 350 (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 351 } 352 354 353 template <> 355 354 void CONetCDF4::addAttribute … … 358 357 int grpid = this->getCurrentGroup(); 359 358 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 360 CheckError(nc_put_att_short(grpid, varid, name.c_str(), NC_SHORT,1, &value));359 (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 361 360 } 362 361 … … 367 366 int grpid = this->getCurrentGroup(); 368 367 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 369 CheckError(nc_put_att_short(grpid, varid, name.c_str(), NC_SHORT,value.numElements(), value.dataFirst()));370 } 371 372 373 368 (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 369 } 370 371 372 374 373 template <> 375 374 void CONetCDF4::addAttribute … … 378 377 int grpid = this->getCurrentGroup(); 379 378 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 380 CheckError(nc_put_att_long(grpid, varid, name.c_str(), NC_LONG,1, &value));379 (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 381 380 } 382 381 … … 387 386 int grpid = this->getCurrentGroup(); 388 387 int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 389 CheckError(nc_put_att_long(grpid, varid, name.c_str(), NC_LONG, value.numElements(), value.dataFirst()));390 } 391 392 393 388 (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 389 } 390 391 392 394 393 //--------------------------------------------------------------- 395 394 … … 399 398 const std::vector<StdSize> * start, 400 399 const std::vector<StdSize> * count) 401 { 400 { 402 401 std::vector<std::size_t> sizes = this->getDimensions(name); 403 std::vector<std::string> iddims = this->getDimensionsIdList (&name); 402 std::vector<std::string> iddims = this->getDimensionsIdList (&name); 404 403 std::vector<std::size_t>::const_iterator 405 404 it = sizes.begin(), end = sizes.end(); … … 416 415 417 416 for (;it != end; it++) 418 { 417 { 419 418 if ((start != NULL) && (count != NULL)) 420 419 { … … 432 431 } 433 432 } 434 435 } 436 437 438 433 434 } 435 436 437 439 438 template <> 440 439 void CONetCDF4::writeData_(int grpid, int varid, … … 442 441 const std::vector<StdSize> & scount, const double * data) 443 442 { 444 CheckError(nc_put_vara_double(grpid, varid, &(sstart[0]), &(scount[0]), data));443 (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data)); 445 444 // sync() ; 446 445 } 447 448 //--------------------------------------------------------------- 449 446 447 //--------------------------------------------------------------- 448 450 449 template <> 451 450 void CONetCDF4::writeData_(int grpid, int varid, … … 453 452 const std::vector<StdSize> & scount, const int * data) 454 453 { 455 CheckError(nc_put_vara_int(grpid, varid, &(sstart[0]), &(scount[0]), data));454 (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data)); 456 455 // sync() ; 457 456 } 458 459 //--------------------------------------------------------------- 460 457 458 //--------------------------------------------------------------- 459 461 460 template <> 462 461 void CONetCDF4::writeData_(int grpid, int varid, … … 464 463 const std::vector<StdSize> & scount, const float * data) 465 464 { 466 CheckError(nc_put_vara_float(grpid, varid, &(sstart[0]), &(scount[0]), data));465 (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data)); 467 466 // sync() ; 468 467 } … … 486 485 int grpid = this->getCurrentGroup(); 487 486 int varid = this->getVariable(name); 488 487 489 488 map<int,size_t>::iterator it=timeAxis.find(varid) ; 490 489 if (it==timeAxis.end()) timeAxis[varid]=record ; 491 else 490 else 492 491 { 493 492 if (it->second >= record) return ; 494 493 else it->second =record ; 495 494 } 496 495 497 496 StdSize array_size = 1; 498 497 std::vector<StdSize> sstart, scount; 499 498 500 499 if (this->wmpi && collective) 501 CheckError(nc_var_par_access(grpid, varid, NC_COLLECTIVE));500 (CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE)); 502 501 if (this->wmpi && !collective) 503 CheckError(nc_var_par_access(grpid, varid, NC_INDEPENDENT));504 502 (CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT)); 503 505 504 this->getWriteDataInfos(name, record, array_size, sstart, scount, NULL, NULL); 506 505 if (using_netcdf_internal) if (!isRoot) { sstart[0]=sstart[0]+1 ; scount[0]=0 ;} … … 509 508 510 509 //--------------------------------------------------------------- 511 510 512 511 bool CONetCDF4::varExist(const StdString & varname) 513 512 { 514 int varid = 0; 515 int grpid = this->getCurrentGroup(); 516 return (nc_inq_varid (grpid, varname.c_str(), &varid) == NC_NOERR); 513 int grpid = this->getCurrentGroup(); 514 return (CNetCdfInterface::isVarExisted(grpid, varname)); 517 515 } 518 516 519 517 void CONetCDF4::sync(void) 520 518 { 521 CheckError(nc_sync(this->ncidp)) ;522 } 519 (CNetCdfInterface::sync(this->ncidp)) ; 520 } 523 521 ///-------------------------------------------------------------- 524 522 } // namespace xios -
XIOS/trunk/src/output/onetcdf4_impl.hpp
r369 r498 3 3 4 4 #include "onetcdf4.hpp" 5 #include "netCdfInterface.hpp" 5 6 6 7 namespace xios … … 18 19 19 20 if (this->wmpi && collective) 20 C heckError(nc_var_par_access(grpid, varid, NC_COLLECTIVE));21 CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE); 21 22 if (this->wmpi && !collective) 22 C heckError(nc_var_par_access(grpid, varid, NC_INDEPENDENT));23 CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT); 23 24 24 25 this->getWriteDataInfos … … 31 32 << " ] Invalid input data !" ); 32 33 } 33 34 34 35 this->writeData_(grpid, varid, sstart, scount, data.dataFirst()); 35 36 } 36 37 37 38 //---------------------------------------------------------------- 38 39 39 40 template <class T> 40 41 void CONetCDF4::setDefaultValue(const StdString & varname, const T * value) … … 42 43 int grpid = this->getCurrentGroup(); 43 44 int varid = this->getVariable(varname); 44 45 45 46 if (value != NULL) 46 47 { 47 C heckError(nc_def_var_fill(grpid, varid, 0, (void*)value));48 CNetCdfInterface::defVarFill(grpid, varid, 0, (void*)value); 48 49 this->addAttribute(StdString("missing_value"), *value, &varname); 49 50 } 50 else C heckError(nc_def_var_fill(grpid, varid, 1, NULL));51 else CNetCdfInterface::defVarFill(grpid, varid, 1, NULL); 51 52 } 52 53 53 54 ///--------------------------------------------------------------- 54 55
Note: See TracChangeset
for help on using the changeset viewer.