Changeset 686 for XIOS/trunk/src/io/netCdfInterface.cpp
- Timestamp:
- 09/15/15 15:15:57 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/io/netCdfInterface.cpp
r685 r686 22 22 int CNetCdfInterface::create(const StdString& fileName, int cMode, int& ncId) 23 23 { 24 int status = nc_create( (fileName.c_str()), cMode, &ncId);25 if (NC_NOERR != status) 26 { 27 StdString errormsg(nc_strerror(status)); 28 StdStringStream sstr; 29 sstr << "Error in calling function : nc_create((fileName.c_str()), cMode, &ncId) " << std::endl30 << errormsg << std::endl 31 << "Unable to create file, given its name 24 int status = nc_create(fileName.c_str(), cMode, &ncId); 25 if (NC_NOERR != status) 26 { 27 StdString errormsg(nc_strerror(status)); 28 StdStringStream sstr; 29 sstr << "Error when calling function: nc_create(fileName.c_str(), cMode, &ncId) " << std::endl 30 << errormsg << std::endl 31 << "Unable to create file, given its name: " << fileName 32 32 << "and its creation mode " << creationMode2String(cMode) << std::endl; 33 33 StdString e = sstr.str(); … … 49 49 int CNetCdfInterface::createPar(const StdString& fileName, int cMode, MPI_Comm comm, MPI_Info info, int& ncId) 50 50 { 51 int status = xios::nc_create_par( (fileName.c_str()), cMode, comm, info, &ncId);52 if (NC_NOERR != status) 53 { 54 StdString errormsg(nc_strerror(status)); 55 StdStringStream sstr; 56 sstr << "Error in calling function : nc_create_par((fileName.c_str()), cMode, comm, info, &ncId) " << std::endl57 << errormsg << std::endl 58 << "Unable to create file on parallel file sys, given its name: " << std::endl51 int status = xios::nc_create_par(fileName.c_str(), cMode, comm, info, &ncId); 52 if (NC_NOERR != status) 53 { 54 StdString errormsg(nc_strerror(status)); 55 StdStringStream sstr; 56 sstr << "Error when calling function: nc_create_par(fileName.c_str(), cMode, comm, info, &ncId) " << std::endl 57 << errormsg << std::endl 58 << "Unable to create file on parallel file system, given its name: " << std::endl 59 59 << "and its creation mode " << creationMode2String(cMode) << std::endl; 60 60 StdString e = sstr.str(); … … 74 74 int CNetCdfInterface::open(const StdString& fileName, int oMode, int& ncId) 75 75 { 76 int status = nc_open( (fileName.c_str()), oMode, &ncId);77 if (NC_NOERR != status) 78 { 79 StdString errormsg(nc_strerror(status)); 80 StdStringStream sstr; 81 sstr << "Error in calling function : nc_open((fileName.c_str()), oMode, &ncId) "<< std::endl82 << errormsg << std::endl 83 << "Unable to open file, given its name 76 int status = nc_open(fileName.c_str(), oMode, &ncId); 77 if (NC_NOERR != status) 78 { 79 StdString errormsg(nc_strerror(status)); 80 StdStringStream sstr; 81 sstr << "Error when calling function: nc_open(fileName.c_str(), oMode, &ncId) "<< std::endl 82 << errormsg << std::endl 83 << "Unable to open file, given its name: " << fileName 84 84 << "and its open mode " << openMode2String(oMode) << std::endl; 85 85 StdString e = sstr.str(); … … 102 102 int CNetCdfInterface::openPar(const StdString& fileName, int oMode, MPI_Comm comm, MPI_Info info, int& ncId) 103 103 { 104 int status = xios::nc_open_par( (fileName.c_str()), oMode, comm, info, &ncId);105 if (NC_NOERR != status) 106 { 107 StdString errormsg(nc_strerror(status)); 108 StdStringStream sstr; 109 sstr << "Error in calling function " << "nc_open_par((fileName.c_str()), oMode, comm, info, &ncId) " << std::endl110 << errormsg << std::endl 111 << "Unable to open file on parallel file sys, given its name: " << fileName104 int status = xios::nc_open_par(fileName.c_str(), oMode, comm, info, &ncId); 105 if (NC_NOERR != status) 106 { 107 StdString errormsg(nc_strerror(status)); 108 StdStringStream sstr; 109 sstr << "Error when calling function nc_open_par(fileName.c_str(), oMode, comm, info, &ncId) " << std::endl 110 << errormsg << std::endl 111 << "Unable to open file on parallel file system, given its name: " << fileName 112 112 << "and its open mode " << openMode2String(oMode) << std::endl; 113 113 StdString e = sstr.str(); … … 130 130 StdString errormsg(nc_strerror(status)); 131 131 StdStringStream sstr; 132 sstr << "Error in calling function " << "nc_close(ncId)" << std::endl133 << errormsg << std::endl 134 << "Unable to close file, given its id 132 sstr << "Error when calling function nc_close(ncId)" << std::endl 133 << errormsg << std::endl 134 << "Unable to close file, given its id: " << ncId << std::endl; 135 135 StdString e = sstr.str(); 136 136 throw CNetCdfException(e); … … 152 152 StdString errormsg(nc_strerror(status)); 153 153 StdStringStream sstr; 154 sstr << "Error in calling function " << "nc_redef(ncId)" << std::endl154 sstr << "Error when calling function nc_redef(ncId)" << std::endl 155 155 << errormsg << std::endl 156 << "Unable to put this file into define mode given its id 156 << "Unable to put this file into define mode given its id: " << ncId << std::endl; 157 157 StdString e = sstr.str(); 158 158 throw CNetCdfException(e); … … 175 175 StdStringStream sstr; 176 176 177 sstr << "Error in calling function " << "nc_enddef(ncId)" << std::endl178 << errormsg << std::endl 179 << "Unable to end define mode of this file, given its id 177 sstr << "Error when calling function nc_enddef(ncId)" << std::endl 178 << errormsg << std::endl 179 << "Unable to end define mode of this file, given its id: " << ncId << std::endl; 180 180 StdString e = sstr.str(); 181 181 throw CNetCdfException(e); … … 194 194 int CNetCdfInterface::inqNcId(int ncid, const StdString& grpName, int& grpId) 195 195 { 196 int status = nc_inq_ncid(ncid, (grpName.c_str()), &grpId);197 if (NC_NOERR != status) 198 { 199 StdString errormsg(nc_strerror(status)); 200 StdStringStream sstr; 201 202 sstr << "Error in calling function " << "nc_inq_ncid(ncid, (grpName.c_str()), &grpId)" << std::endl203 << errormsg << std::endl 204 << "Unable to get id of a group (File), given its name 196 int status = nc_inq_ncid(ncid, grpName.c_str(), &grpId); 197 if (NC_NOERR != status) 198 { 199 StdString errormsg(nc_strerror(status)); 200 StdStringStream sstr; 201 202 sstr << "Error when calling function nc_inq_ncid(ncid, grpName.c_str(), &grpId)" << std::endl 203 << errormsg << std::endl 204 << "Unable to get id of a group (File), given its name: " << grpName << std::endl; 205 205 StdString e = sstr.str(); 206 206 throw CNetCdfException(e); … … 218 218 \return Status code 219 219 */ 220 int CNetCdfInterface::inqVarId(int ncid, const StdString& varName, int& varId)221 { 222 int status = nc_inq_varid(ncid, (varName.c_str()), &varId);223 if (NC_NOERR != status) 224 { 225 StdString errormsg(nc_strerror(status)); 226 StdStringStream sstr; 227 228 sstr << "Error in calling function : nc_inq_varid(ncid, (varName.c_str()), &varId)" << std::endl220 int CNetCdfInterface::inqVarId(int ncid, const StdString& varName, int& varId) 221 { 222 int status = nc_inq_varid(ncid, varName.c_str(), &varId); 223 if (NC_NOERR != status) 224 { 225 StdString errormsg(nc_strerror(status)); 226 StdStringStream sstr; 227 228 sstr << "Error when calling function: nc_inq_varid(ncid, varName.c_str(), &varId)" << std::endl 229 229 << (errormsg) << std::endl 230 << "Unable to get id of variable with name 230 << "Unable to get id of variable with name: " << varName << std::endl; 231 231 StdString e = sstr.str(); 232 232 throw CNetCdfException(e); … … 243 243 \return Status code 244 244 */ 245 int CNetCdfInterface::inqDimId(int ncid,const StdString& dimName, int& dimId) 246 { 247 int status = nc_inq_dimid(ncid, (dimName.c_str()), &dimId); 248 if (NC_NOERR != status) 249 { 250 StdString errormsg(nc_strerror(status)); 251 StdStringStream sstr; 252 253 sstr << "Error in calling function " << "nc_inq_dimid(ncid, (dimName.c_str()), &dimId)" << std::endl 254 << errormsg << std::endl 255 << "Unable to get id of dimension, given its name : " << dimName << std::endl; 256 StdString e = sstr.str(); 257 throw CNetCdfException(e); 258 } 259 245 int CNetCdfInterface::inqDimId(int ncid, const StdString& dimName, int& dimId) 246 { 247 int status = nc_inq_dimid(ncid, dimName.c_str(), &dimId); 248 if (NC_NOERR != status) 249 { 250 StdString errormsg(nc_strerror(status)); 251 StdStringStream sstr; 252 253 sstr << "Error when calling function nc_inq_dimid(ncid, dimName.c_str(), &dimId)" << std::endl 254 << errormsg << std::endl 255 << "Unable to get id of dimension, given its name: " << dimName << std::endl; 256 StdString e = sstr.str(); 257 throw CNetCdfException(e); 258 } 259 260 return status; 261 } 262 263 /*! 264 This function queries the name of a variable given its id. 265 \param [in] ncid Groupd id (or File Id) 266 \param [in] varId Id of desired variable 267 \param [out] varName name of desired variable 268 \return Status code 269 */ 270 int CNetCdfInterface::inqVarName(int ncid, int varId, StdString& varName) 271 { 272 char varNameBuff[NC_MAX_NAME + 1]; 273 int status = nc_inq_varname(ncid, varId, varNameBuff); 274 if (NC_NOERR != status) 275 { 276 StdString errormsg(nc_strerror(status)); 277 StdStringStream sstr; 278 279 sstr << "Error when calling function nc_inq_varname(ncid, varId, varNameBuff)" << std::endl 280 << errormsg << std::endl 281 << "Unable to get variable name given its id: " << varId << std::endl; 282 StdString e = sstr.str(); 283 throw CNetCdfException(e); 284 } 285 varName = varNameBuff; 260 286 return status; 261 287 } … … 275 301 StdStringStream sstr; 276 302 277 sstr << "Error in calling function " << "nc_inq_dimid" << std::endl303 sstr << "Error when calling function nc_inq_dimid" << std::endl 278 304 << errormsg << std::endl 279 305 << "Unable to get id of unlimited dimension " << std::endl; … … 289 315 \param [in] ncid Groupd id (or File Id) 290 316 \param [in] dimId Id of desired dimension 291 \param [ in/out] dimName Name of desired dimension317 \param [out] dimName Name of desired dimension 292 318 \return Status code 293 319 */ 294 320 int CNetCdfInterface::inqDimName(int ncid, int dimId, StdString& dimName) 295 321 { 296 char fullNameIn[NC_MAX_NAME + 1];322 char fullNameIn[NC_MAX_NAME + 1]; 297 323 int status = nc_inq_dimname(ncid, dimId, fullNameIn); 298 324 if (NC_NOERR != status) … … 301 327 StdStringStream sstr; 302 328 303 sstr << "Error in calling function " << "nc_inq_dimname(ncid, dimId, fullNameIn)" << std::endl304 << errormsg << std::endl 305 << "Unable to get dimension name from its id: " << dimId << std::endl;329 sstr << "Error when calling function nc_inq_dimname(ncid, dimId, fullNameIn)" << std::endl 330 << errormsg << std::endl 331 << "Unable to get dimension name given its id: " << dimId << std::endl; 306 332 StdString e = sstr.str(); 307 333 throw CNetCdfException(e); … … 326 352 StdStringStream sstr; 327 353 328 sstr << "Error in calling function " << "nc_inq_dimlen(ncid, dimId, &dimLen)" << std::endl329 << errormsg << std::endl 330 << "Unable to get dimension length fromits id: " << dimId << std::endl;354 sstr << "Error when calling function nc_inq_dimlen(ncid, dimId, &dimLen)" << std::endl 355 << errormsg << std::endl 356 << "Unable to get dimension length given its id: " << dimId << std::endl; 331 357 StdString e = sstr.str(); 332 358 throw CNetCdfException(e); … … 351 377 StdStringStream sstr; 352 378 353 sstr << "Error in calling function " << "nc_inq_varndims(ncid, varId, &nDims)" << std::endl354 << errormsg << std::endl 355 << "Unable to get the number of dimension of variable with Id 379 sstr << "Error when calling function nc_inq_varndims(ncid, varId, &nDims)" << std::endl 380 << errormsg << std::endl 381 << "Unable to get the number of dimension of variable with Id: " << varId << std::endl; 356 382 StdString e = sstr.str(); 357 383 throw CNetCdfException(e); … … 376 402 StdStringStream sstr; 377 403 378 sstr << "Error in calling function " << "nc_inq_vardimid(ncid, varId, dimIds)" << std::endl404 sstr << "Error when calling function nc_inq_vardimid(ncid, varId, dimIds)" << std::endl 379 405 << errormsg << std::endl 380 406 << "Unable to get list of dimension id of the variable with id " << varId << std::endl; … … 402 428 StdStringStream sstr; 403 429 404 sstr << "Error in calling function " << "nc_inq_dimids(ncid, &nDims, dimIds, includeParents)" << std::endl;405 sstr << errormsg << std::endl; 406 sstr << "Unable to retrieve number of dimension in the group with id 430 sstr << "Error when calling function nc_inq_dimids(ncid, &nDims, dimIds, includeParents)" << std::endl; 431 sstr << errormsg << std::endl; 432 sstr << "Unable to retrieve number of dimension in the group with id: " << ncid << std::endl; 407 433 sstr << "With number of Parents " << includeParents << std::endl; 434 StdString e = sstr.str(); 435 throw CNetCdfException(e); 436 } 437 438 return status; 439 } 440 441 /*! 442 This function queries the full name of a group given its id. 443 \param [in] ncid Groupd id (or File Id) 444 \param [in/out] grpFullName the full name of the group 445 \return Status code 446 */ 447 int CNetCdfInterface::inqGrpFullName(int ncid, StdString& grpFullName) 448 { 449 StdSize strlen = 0; 450 std::vector<char> buff; 451 int status = nc_inq_grpname_full(ncid, &strlen, NULL); 452 if (NC_NOERR == status) 453 { 454 buff.resize(strlen + 1); 455 status = nc_inq_grpname_full(ncid, NULL, &buff[0]); 456 } 457 458 if (NC_NOERR != status) 459 { 460 StdString errormsg(nc_strerror(status)); 461 StdStringStream sstr; 462 463 sstr << "Error when calling function nc_inq_grpname_full(ncid, &strlen, &buff[0])" << std::endl 464 << errormsg << std::endl 465 << "Unable to get the full group name given its id: " << ncid << std::endl; 466 StdString e = sstr.str(); 467 throw CNetCdfException(e); 468 } 469 470 grpFullName.assign(buff.begin(), buff.end()); 471 472 return status; 473 } 474 475 /*! 476 This function queries the list of group ids given a location id. 477 \param [in] ncid Groupd id (or File Id) 478 \param [in/out] numgrps number of groups 479 \param [in/out] ncids list of group ids 480 \return Status code 481 */ 482 int CNetCdfInterface::inqGrpIds(int ncid, int& numgrps, int* ncids) 483 { 484 int status = nc_inq_grps(ncid, &numgrps, ncids); 485 if (NC_NOERR != status) 486 { 487 StdString errormsg(nc_strerror(status)); 488 StdStringStream sstr; 489 490 sstr << "Error when calling function nc_inq_grps(ncid, &numgrps, ncids)" << std::endl; 491 sstr << errormsg << std::endl; 492 sstr << "Unable to retrieve the list of groups for location id: " << ncid << std::endl; 493 StdString e = sstr.str(); 494 throw CNetCdfException(e); 495 } 496 497 return status; 498 } 499 500 /*! 501 This function queries the list of variable ids given a location id. 502 \param [in] ncid Groupd id (or File Id) 503 \param [in/out] nvars number of variables 504 \param [in/out] varids list of variable ids 505 \return Status code 506 */ 507 int CNetCdfInterface::inqVarIds(int ncid, int& nvars, int* varids) 508 { 509 int status = nc_inq_varids(ncid, &nvars, varids); 510 if (NC_NOERR != status) 511 { 512 StdString errormsg(nc_strerror(status)); 513 StdStringStream sstr; 514 515 sstr << "Error when calling function nc_inq_varids(ncid, &nvars, varids)" << std::endl; 516 sstr << errormsg << std::endl; 517 sstr << "Unable to retrieve the list of variables for location id: " << ncid << std::endl; 518 StdString e = sstr.str(); 519 throw CNetCdfException(e); 520 } 521 522 return status; 523 } 524 525 /*! 526 This function queries the type and the size of an attribute given its name and the id of the variable to which it is attached. 527 \param [in] ncid Groupd id (or File Id) 528 \param [in] varid the id of the variable to which the attribute is attached 529 \param [in] name the name of the attribute 530 \param [out] type the type of the attribute 531 \param [out] len the size of the attribute 532 \return Status code 533 */ 534 int CNetCdfInterface::inqAtt(int ncid, int varid, const StdString& name, nc_type& type, size_t& len) 535 { 536 int status = nc_inq_att(ncid, varid, name.c_str(), &type, &len); 537 if (NC_NOERR != status) 538 { 539 StdString errormsg(nc_strerror(status)); 540 StdStringStream sstr; 541 542 sstr << "Error when calling function nc_inq_att(ncid, varid, name.c_str(), &type, &len)" << std::endl; 543 sstr << errormsg << std::endl; 544 sstr << "Unable to query the attribute information given its name: " << name << " and its variable id:" << varid << std::endl; 545 StdString e = sstr.str(); 546 throw CNetCdfException(e); 547 } 548 549 return status; 550 } 551 552 /*! 553 This function queries the number of global attributes given a location id. 554 \param [in] ncid Groupd id (or File Id) 555 \param [out] ngatts the number of global attributes 556 \return Status code 557 */ 558 int CNetCdfInterface::inqNAtts(int ncid, int& ngatts) 559 { 560 int status = nc_inq_natts(ncid, &ngatts); 561 if (NC_NOERR != status) 562 { 563 StdString errormsg(nc_strerror(status)); 564 StdStringStream sstr; 565 566 sstr << "Error when calling function nc_inq_natts(ncid, &ngatts)" << std::endl; 567 sstr << errormsg << std::endl; 568 sstr << "Unable to query the number of global attributes given the location id:" << ncid << std::endl; 569 StdString e = sstr.str(); 570 throw CNetCdfException(e); 571 } 572 573 return status; 574 } 575 576 /*! 577 This function queries the number of global attributes given a location id and a variable id. 578 \param [in] ncid Groupd id (or File Id) 579 \param [in] varid the id of the variable 580 \param [out] natts the number of global attributes 581 \return Status code 582 */ 583 int CNetCdfInterface::inqVarNAtts(int ncid, int varid, int& natts) 584 { 585 int status = nc_inq_varnatts(ncid, varid, &natts); 586 if (NC_NOERR != status) 587 { 588 StdString errormsg(nc_strerror(status)); 589 StdStringStream sstr; 590 591 sstr << "Error when calling function nc_inq_varnatts(ncid, varid, &natts)" << std::endl; 592 sstr << errormsg << std::endl; 593 sstr << "Unable to query the number of attributes given the location id:" << ncid << " and the variable id:" << varid << std::endl; 594 StdString e = sstr.str(); 595 throw CNetCdfException(e); 596 } 597 598 return status; 599 } 600 601 602 //! Query the name of an attribute given a location id, a variable id and the attribute number 603 int CNetCdfInterface::inqAttName(int ncid, int varid, int attnum, StdString& name) 604 { 605 char attName[NC_MAX_NAME + 1]; 606 int status = nc_inq_attname(ncid, varid, attnum, attName); 607 if (NC_NOERR != status) 608 { 609 StdString errormsg(nc_strerror(status)); 610 StdStringStream sstr; 611 612 sstr << "Error when calling function nc_inq_attname(ncid, varid, attnum, attName)" << std::endl; 613 sstr << errormsg << std::endl; 614 sstr << "Unable to query the name of attribute " << attnum << " given the location id:" << ncid << " and the variable id:" << varid << std::endl; 408 615 StdString e = sstr.str(); 409 616 throw CNetCdfException(e); … … 422 629 int CNetCdfInterface::defGrp(int parentNcid, const StdString& grpName, int& grpId) 423 630 { 424 int status = nc_def_grp(parentNcid, (grpName.c_str()), &grpId);425 if (NC_NOERR != status) 426 { 427 StdString errormsg(nc_strerror(status)); 428 StdStringStream sstr; 429 430 sstr << "Error in calling function " << "nc_def_grp(parentNcid, (grpName.c_str()), &grpId)" << std::endl;431 sstr << errormsg << std::endl; 432 sstr << "Unable to create group Id, given its name 631 int status = nc_def_grp(parentNcid, grpName.c_str(), &grpId); 632 if (NC_NOERR != status) 633 { 634 StdString errormsg(nc_strerror(status)); 635 StdStringStream sstr; 636 637 sstr << "Error when calling function nc_def_grp(parentNcid, grpName.c_str(), &grpId)" << std::endl; 638 sstr << errormsg << std::endl; 639 sstr << "Unable to create group Id, given its name: " << grpName << std::endl; 433 640 StdString e = sstr.str(); 434 641 throw CNetCdfException(e); … … 447 654 int CNetCdfInterface::defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId) 448 655 { 449 int status = nc_def_dim(ncid, (dimName.c_str()), dimLen, &dimId);450 if (NC_NOERR != status) 451 { 452 StdString errormsg(nc_strerror(status)); 453 StdStringStream sstr; 454 455 sstr << "Error in calling function " << "nc_def_dim(ncid, (dimName.c_str()), dimLen, &dimId)" << std::endl;456 sstr << errormsg << std::endl; 457 sstr << "Unable to create dimension with name 656 int status = nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId); 657 if (NC_NOERR != status) 658 { 659 StdString errormsg(nc_strerror(status)); 660 StdStringStream sstr; 661 662 sstr << "Error when calling function nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId)" << std::endl; 663 sstr << errormsg << std::endl; 664 sstr << "Unable to create dimension with name: " << dimName 458 665 << " and with length " << dimLen << std::endl; 459 666 StdString e = sstr.str(); … … 475 682 \return Status code 476 683 */ 477 int CNetCdfInterface::defVar(int ncid, const StdString& varName, nc_type xtype,478 int nDims, const int dimIds[], int& varId)479 { 480 int status = nc_def_var(ncid, (varName.c_str()), xtype, nDims, dimIds, &varId);481 if (NC_NOERR != status) 482 { 483 StdString errormsg(nc_strerror(status)); 484 StdStringStream sstr; 485 486 sstr << "Error in calling function " << " nc_def_var(ncid, (varName.c_str()), xtype, nDims, dimIds, &varId)" << std::endl;487 sstr << errormsg << std::endl; 488 sstr << "Unable to add a new variable with name 684 int CNetCdfInterface::defVar(int ncid, const StdString& varName, nc_type xtype, 685 int nDims, const int dimIds[], int& varId) 686 { 687 int status = nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId); 688 if (NC_NOERR != status) 689 { 690 StdString errormsg(nc_strerror(status)); 691 StdStringStream sstr; 692 693 sstr << "Error when calling function nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId)" << std::endl; 694 sstr << errormsg << std::endl; 695 sstr << "Unable to add a new variable with name: " << varName 489 696 << " with type " << xtype 490 697 << " and number of dimension " << nDims << std::endl; … … 501 708 \param [in] ncid Id groupd(or File Id) 502 709 \param [in] varId Id of the variable 503 \param [in] storage Type of storage (It can be 710 \param [in] storage Type of storage (It can be: NC_CONTIGUOUS, NC_CHUNKED) 504 711 \param [in/out] chunkSize array list of chunk sizes 505 712 \return Status code … … 513 720 StdStringStream sstr; 514 721 515 sstr << "Error in calling function " << "nc_def_var_chunking(ncid, varId, storage, chunkSize)" << std::endl;516 sstr << errormsg << std::endl; 517 sstr << "Unable to set chunk size of the variable with id 722 sstr << "Error when calling function nc_def_var_chunking(ncid, varId, storage, chunkSize)" << std::endl; 723 sstr << errormsg << std::endl; 724 sstr << "Unable to set chunk size of the variable with id: " << varId 518 725 << " and storage type " << storage << std::endl; 519 726 StdString e = sstr.str(); … … 539 746 StdStringStream sstr; 540 747 541 sstr << "Error in calling function " << "nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl;748 sstr << "Error when calling function nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl; 542 749 sstr << errormsg << std::endl; 543 750 sstr << "Unable to set the compression level of the variable with id: " << varId … … 559 766 { 560 767 int old_fill_mode; 561 int status = nc_set_fill(ncid, fill ? NC_FILL 562 if (NC_NOERR != status) 563 { 564 StdString errormsg(nc_strerror(status)); 565 StdStringStream sstr; 566 567 sstr << "Error when calling function nc_set_fill(ncid, fill ? NC_FILL 568 sstr << errormsg << std::endl; 569 sstr << "Unable to set the fill mode to : " << (fill ? "NC_FILL": "NC_NOFILL") << std::endl;768 int status = nc_set_fill(ncid, fill ? NC_FILL: NC_NOFILL, &old_fill_mode); 769 if (NC_NOERR != status) 770 { 771 StdString errormsg(nc_strerror(status)); 772 StdStringStream sstr; 773 774 sstr << "Error when calling function nc_set_fill(ncid, fill ? NC_FILL: NC_NOFILL, &old_fill_mode)" << std::endl; 775 sstr << errormsg << std::endl; 776 sstr << "Unable to set the fill mode to: " << (fill ? "NC_FILL": "NC_NOFILL") << std::endl; 570 777 StdString e = sstr.str(); 571 778 throw CNetCdfException(e); … … 592 799 StdStringStream sstr; 593 800 594 sstr << "Error in calling function " << "nc_def_var_fill(ncid, varId, noFill, fillValue)" << std::endl;595 sstr << errormsg << std::endl; 596 sstr << "Unable to set fill parameters of the variable with id 801 sstr << "Error when calling function nc_def_var_fill(ncid, varId, noFill, fillValue)" << std::endl; 802 sstr << errormsg << std::endl; 803 sstr << "Unable to set fill parameters of the variable with id: " << varId 597 804 << " and fill option " << noFill << std::endl; 598 805 StdString e = sstr.str(); … … 620 827 StdStringStream sstr; 621 828 622 sstr << "Error in calling function " << "nc_var_par_access(ncid, varId, access)" << std::endl;623 sstr << errormsg << std::endl; 624 sstr << "Unable to change read/write option of the variable with id 829 sstr << "Error when calling function nc_var_par_access(ncid, varId, access)" << std::endl; 830 sstr << errormsg << std::endl; 831 sstr << "Unable to change read/write option of the variable with id: " << varId << std::endl; 625 832 StdString e = sstr.str(); 626 833 throw CNetCdfException(e); … … 643 850 StdStringStream sstr; 644 851 645 sstr << "Error in calling function " << "nc_sync(ncid)" << std::endl; 646 sstr << errormsg << std::endl; 647 sstr << "Unable to make a synchronization of a netCDF file with id : " << ncid << std::endl; 648 StdString e = sstr.str(); 649 throw CNetCdfException(e); 650 } 651 652 return status; 653 } 654 655 /*! 656 This function makes a request to netcdf with its id, to add or change a variable attribute or gloabl attribute, 657 given its name, type, number of values provided for attribute 658 \param [in] ncid Id of groupd(or File Id) 659 \param [in] varId Id of the variable 660 \param [in] attrName Name of the attribute 661 \param [in] xtypes One of the set of predefined netCDF data types 662 \param [in] numVal Number of values 663 \param [in] op Array of values provided for attribute 664 \return Status code 665 */ 666 int CNetCdfInterface::putAtt(int ncid, int varId, const StdString& attrName, nc_type xtype, 667 StdSize numVal, const void* op) 668 { 669 int status = nc_put_att(ncid, varId, (attrName.c_str()), xtype, numVal, op); 670 if (NC_NOERR != status) 671 { 672 StdString errormsg(nc_strerror(status)); 673 StdStringStream sstr; 674 675 sstr << "Error in calling function " << "nc_put_att(ncid, varId, (attrName.c_str()), xtype, numVal, op)" << std::endl; 676 sstr << errormsg << std::endl; 677 sstr << "Unable to set attribute " << attrName << " for a variable with id : " << varId 678 << " with number of attribute " << numVal 679 << " with type " << xtype << std::endl; 680 StdString e = sstr.str(); 681 throw CNetCdfException(e); 682 } 683 684 return status; 685 } 686 687 // Some specilization of putAttributeType 852 sstr << "Error when calling function nc_sync(ncid)" << std::endl; 853 sstr << errormsg << std::endl; 854 sstr << "Unable to make a synchronization of a netCDF file with id: " << ncid << std::endl; 855 StdString e = sstr.str(); 856 throw CNetCdfException(e); 857 } 858 859 return status; 860 } 861 862 // Some specializations of getAttributeType 863 template<> 864 int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, double* data) 865 { 866 return nc_get_att_double(ncid, varid, attrName, data); 867 } 868 869 template<> 870 int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, float* data) 871 { 872 return nc_get_att_float(ncid, varid, attrName, data); 873 } 874 875 template<> 876 int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, int* data) 877 { 878 return nc_get_att_int(ncid, varid, attrName, data); 879 } 880 881 template<> 882 int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, long* data) 883 { 884 return nc_get_att_long(ncid, varid, attrName, data); 885 } 886 887 template<> 888 int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, short* data) 889 { 890 return nc_get_att_short(ncid, varid, attrName, data); 891 } 892 893 template<> 894 int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, char* data) 895 { 896 return nc_get_att_text(ncid, varid, attrName, data); 897 } 898 899 // Some specializations of putAttributeType 688 900 template<> 689 901 int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 690 StdSize numVal, const double* op)691 { 692 return (nc_put_att_double(ncid, varid, attrName, NC_DOUBLE, numVal, op));902 StdSize numVal, const double* data) 903 { 904 return nc_put_att_double(ncid, varid, attrName, NC_DOUBLE, numVal, data); 693 905 } 694 906 695 907 template<> 696 908 int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 697 StdSize numVal, const float* op)698 { 699 return (nc_put_att_float(ncid, varid, attrName, NC_FLOAT, numVal, op));909 StdSize numVal, const float* data) 910 { 911 return nc_put_att_float(ncid, varid, attrName, NC_FLOAT, numVal, data); 700 912 } 701 913 702 914 template<> 703 915 int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 704 StdSize numVal, const int* op)705 { 706 return (nc_put_att_int(ncid, varid, attrName, NC_INT, numVal, op));916 StdSize numVal, const int* data) 917 { 918 return nc_put_att_int(ncid, varid, attrName, NC_INT, numVal, data); 707 919 } 708 920 709 921 template<> 710 922 int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 711 StdSize numVal, const long* op)712 { 713 return (nc_put_att_long(ncid, varid, attrName, NC_LONG, numVal, op));923 StdSize numVal, const long* data) 924 { 925 return nc_put_att_long(ncid, varid, attrName, NC_LONG, numVal, data); 714 926 } 715 927 716 928 template<> 717 929 int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 718 StdSize numVal, const short* op) 719 { 720 return (nc_put_att_short(ncid, varid, attrName, NC_SHORT, numVal, op)); 721 } 722 723 724 // Some specilization of putVariableType 725 template<> 726 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const double* op) 727 { 728 return (nc_put_vara_double(ncid, varid, start, count, op)); 729 } 730 731 template<> 732 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const float* op) 733 { 734 return (nc_put_vara_float(ncid, varid, start, count, op)); 735 } 736 737 template<> 738 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const int* op) 739 { 740 return (nc_put_vara_int(ncid, varid, start, count, op)); 930 StdSize numVal, const short* data) 931 { 932 return nc_put_att_short(ncid, varid, attrName, NC_SHORT, numVal, data); 933 } 934 935 template<> 936 int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 937 StdSize numVal, const char* data) 938 { 939 return nc_put_att_text(ncid, varid, attrName, numVal, data); 940 } 941 942 // Some specializations of getVariableType 943 template<> 944 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, double* data) 945 { 946 return nc_get_vara_double(ncid, varid, start, count, data); 947 } 948 949 template<> 950 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, float* data) 951 { 952 return nc_get_vara_float(ncid, varid, start, count, data); 953 } 954 955 template<> 956 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, int* data) 957 { 958 return nc_get_vara_int(ncid, varid, start, count, data); 959 } 960 961 // Some specializations of putVariableType 962 template<> 963 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const double* data) 964 { 965 return nc_put_vara_double(ncid, varid, start, count, data); 966 } 967 968 template<> 969 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const float* data) 970 { 971 return nc_put_vara_float(ncid, varid, start, count, data); 972 } 973 974 template<> 975 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const int* data) 976 { 977 return nc_put_vara_int(ncid, varid, start, count, data); 741 978 } 742 979 … … 760 997 { 761 998 case NC_NOWRITE: 762 modeMes = StdString("NC_NOWRITE 999 modeMes = StdString("NC_NOWRITE: Opening netCDF file with read-only access with buffering and caching access"); 763 1000 break; 764 1001 case NC_SHARE: 765 modeMes = StdString("NC_SHARE 1002 modeMes = StdString("NC_SHARE: Several processes can read the file concurrently"); 766 1003 break; 767 1004 case NC_WRITE: 768 modeMes = StdString("NC_WRITE 1005 modeMes = StdString("NC_WRITE: NetCDF file is readable and writable"); 769 1006 break; 770 1007 default: … … 781 1018 { 782 1019 case NC_NOCLOBBER: 783 modeMes = StdString("NC_NOCLOBBER 1020 modeMes = StdString("NC_NOCLOBBER: Not overwrite an exisiting netCDF file "); 784 1021 break; 785 1022 case NC_SHARE: 786 modeMes = StdString("NC_SHARE 1023 modeMes = StdString("NC_SHARE: Several processes can read from and write into the file concurrently"); 787 1024 break; 788 1025 case NC_64BIT_OFFSET: 789 modeMes = StdString("NC_64BIT_OFFSET 1026 modeMes = StdString("NC_64BIT_OFFSET: NetCDF file is 64-bit offset"); 790 1027 break; 791 1028 case NC_NETCDF4: 792 modeMes = StdString("NC_NETCDF4 1029 modeMes = StdString("NC_NETCDF4: NetCDF file is HDF5/NetCDF-4"); 793 1030 break; 794 1031 case NC_CLASSIC_MODEL: 795 modeMes = StdString("NC_CLASSIC_MODEL 1032 modeMes = StdString("NC_CLASSIC_MODEL: NetCDF file is classical model"); 796 1033 break; 797 1034 default:
Note: See TracChangeset
for help on using the changeset viewer.