Changeset 1050 for XIOS/trunk/src
- Timestamp:
- 02/07/17 11:52:03 (7 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/array_new.hpp
r731 r1050 539 539 TinyVector<int,N_rank> vect; 540 540 size_t ne; 541 541 542 542 ret = buffer.get(numDim); 543 543 ret &= buffer.get(vect.data(), N_rank); … … 551 551 } 552 552 }; 553 554 555 #define macro(NRANK)\ 556 \ 557 template <>\ 558 inline size_t CArray<StdString,NRANK>::size(void) const\ 559 {\ 560 size_t size=(1 + NRANK) * sizeof(int) ;\ 561 Array<StdString,NRANK>::const_iterator it, itb=this->begin(), ite=this->end() ;\ 562 \ 563 for(it=itb;it!=ite;++it)\ 564 {\ 565 size+= sizeof(size_t) ;\ 566 size+= (*it).size();\ 567 } \ 568 return size ;\ 569 }\ 570 \ 571 /* for array string this function is an evaluation of maximum size of the array, considering stringArrayLen is the maximum size of the strings*/ \ 572 template <>\ 573 inline size_t CArray<StdString,NRANK>::size(sizeType numElements)\ 574 {\ 575 return (NRANK + 1) * sizeof(int) + numElements * stringArrayLen;\ 576 }\ 577 \ 578 template <>\ 579 inline bool CArray<StdString,NRANK>::toBuffer(CBufferOut& buffer) const\ 580 {\ 581 bool ret;\ 582 ret = buffer.put(this->dimensions());\ 583 ret &= buffer.put(this->shape().data(), this->dimensions());\ 584 \ 585 Array<StdString,NRANK>::const_iterator it, itb=this->begin(), ite=this->end() ;\ 586 \ 587 for(it=itb;it!=ite;++it)\ 588 {\ 589 ret &= buffer.put((*it).size()) ;\ 590 ret &= buffer.put((*it).data(),(*it).size());\ 591 } \ 592 return ret;\ 593 }\ 594 \ 595 template <>\ 596 inline bool CArray<StdString,NRANK>::fromBuffer(CBufferIn& buffer)\ 597 {\ 598 bool ret;\ 599 int numDim;\ 600 TinyVector<int,NRANK> vect;\ 601 size_t ne;\ 602 \ 603 ret = buffer.get(numDim);\ 604 ret &= buffer.get(vect.data(), NRANK);\ 605 this->resize(vect);\ 606 \ 607 Array<StdString,NRANK>::iterator it, itb=this->begin(), ite=this->end() ;\ 608 for(it=itb;it!=ite;++it)\ 609 {\ 610 ret &= buffer.get(ne) ;\ 611 char* str = new char[ne] ;\ 612 ret &= buffer.get(str, ne);\ 613 *it = string(str,ne) ;\ 614 delete [] str ;\ 615 }\ 616 initialized = true;\ 617 return ret;\ 618 } 619 macro(1) 620 macro(2) 621 macro(3) 622 macro(4) 623 macro(5) 624 macro(6) 625 macro(7) 626 627 #undef macro 553 628 554 629 template <typename T_numtype,int N_rank> inline CBufferOut& operator<<(CBufferOut& buffer, const CArray<T_numtype,N_rank>& array) -
XIOS/trunk/src/attribute_array_decl.cpp
r932 r1050 17 17 template class CAttributeArray<bool,6> ; 18 18 template class CAttributeArray<bool,7> ; 19 template class CAttributeArray<StdString,1> ; 20 template class CAttributeArray<StdString,2> ; 19 21 } -
XIOS/trunk/src/config/axis_attribute.conf
r1045 r1050 30 30 DECLARE_ARRAY(double, 2 , bounds) 31 31 DECLARE_ATTRIBUTE(int, prec) 32 DECLARE_ARRAY(StdString ,1 , label) -
XIOS/trunk/src/generate_interface_impl.hpp
r966 r1050 547 547 #undef macro 548 548 549 #define macro(N,EXTENT)\ 550 template <>\ 551 void CInterface::AttributeCInterface<CArray<StdString,N> >(ostream& oss, const string& className, const string& name)\ 552 { \ 553 oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << "char* " << name <<", int str_len, int* str_size, int* extent)" << iendl; \ 554 oss << "{" << iendl; \ 555 oss << " CTimer::get(\"XIOS\").resume();" << iendl; \ 556 oss << " "<<className<<"_hdl->"<<name<<".resize(shape("<<EXTENT<<"));"<<iendl;\ 557 oss << " Array<StdString,"<<#N<<">::iterator it, itb="<<className<<"_hdl->"<<name<<".begin(), ite="<<className<<"_hdl->"<<name<<".end() ;"<<iendl ;\ 558 oss << " int i, n ;"<< iendl; \ 559 oss << " for(it=itb, i=0, n=0 ; it!=ite ; ++it,n+=str_len,++i) *it=StdString(&"<<name<<"[n],str_size[i]) ;"<<iendl ;\ 560 oss << " CTimer::get(\"XIOS\").suspend();" << iendl; \ 561 oss << "}" << std::endl; \ 562 oss << iendl; \ 563 oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << "char* " << name << ", int str_size, int* extent)" << iendl; \ 564 oss << "{" << iendl; \ 565 oss << " CTimer::get(\"XIOS\").resume();" << iendl; \ 566 oss << " Array<StdString,"<<#N<<">::const_iterator it, itb="<<className<<"_hdl->"<<name<<".getInheritedValue().begin(), ite="<<className<<"_hdl->"<<name<<".getInheritedValue().end() ;" << iendl; \ 567 oss << " int n ;"<< iendl; \ 568 oss << " for(it=itb, n=0 ; it!=ite ; ++it, n+=str_size) it->copy(&"<<name<<"[n],it->size()) ; "<< iendl; \ 569 oss << " CTimer::get(\"XIOS\").suspend();" << iendl; \ 570 oss << "}" << std::endl; \ 571 } 572 573 macro(1,"extent[0]") 574 macro(2,"extent[0],extent[1]") 575 macro(3,"extent[0],extent[1],extent[2]") 576 macro(4,"extent[0],extent[1],extent[2],extent[3]") 577 macro(5,"extent[0],extent[1],extent[2],extent[3],extent[4]") 578 macro(6,"extent[0],extent[1],extent[2],extent[3],extent[4],extent[5]") 579 macro(7,"extent[0],extent[1],extent[2],extent[3],extent[4],extent[5],extent[6]") 580 #undef macro 549 581 // ///////////////////////////////////////////////// 550 582 // // Fortran 2003 Interface // … … 705 737 #undef macro 706 738 739 #define macro(T)\ 740 template <>\ 741 void CInterface::AttributeFortran2003Interface<CArray<StdString,T> >(ostream& oss, const string& className, const string& name)\ 742 {\ 743 oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", str_len, str_size, extent) BIND(C)" << iendl; \ 744 oss << " USE ISO_C_BINDING" << iendl; \ 745 oss << " INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl; \ 746 oss << " CHARACTER (KIND=C_CHAR), DIMENSION(*) :: " << name << iendl; \ 747 oss << " INTEGER (kind = C_INT), VALUE :: str_len" << iendl; \ 748 oss << " INTEGER (kind = C_INT), DIMENSION(*) :: str_size" << iendl; \ 749 oss << " INTEGER (kind = C_INT), DIMENSION(*) :: extent" << iendl; \ 750 oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \ 751 oss << iendl; \ 752 oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", str_size, extent) BIND(C)" << iendl; \ 753 oss << " USE ISO_C_BINDING" << iendl; \ 754 oss << " INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl; \ 755 oss << " CHARACTER (KIND=C_CHAR), DIMENSION(*) :: " << name << iendl; \ 756 oss << " INTEGER (kind = C_INT), VALUE :: str_size" << iendl; \ 757 oss << " INTEGER (kind = C_INT), DIMENSION(*) :: extent" << iendl; \ 758 oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \ 759 } 760 macro(1) 761 macro(2) 762 macro(3) 763 macro(4) 764 macro(5) 765 macro(6) 766 macro(7) 767 768 #undef macro 769 707 770 #define macro(T) \ 708 771 template <> \ … … 808 871 809 872 #undef macro 873 874 #define macro(T,EXTENT)\ 875 template <> \ 876 void CInterface::AttributeFortranInterfaceDeclaration<CArray<StdString,T> >(ostream& oss, const string& className, const string& name)\ 877 {\ 878 oss << "CHARACTER(len=*) , OPTIONAL, INTENT(IN) :: " << name << "("<<EXTENT<<")"; \ 879 }\ 880 \ 881 template <>\ 882 void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<StdString,T> >(ostream& oss, const string& className, const string& name)\ 883 {\ 884 oss << "CHARACTER(len=*) , OPTIONAL, INTENT(OUT) :: " << name << "("<<EXTENT<<")"; \ 885 } 886 macro(1,":") 887 macro(2,":,:") 888 macro(3,":,:,:") 889 macro(4,":,:,:,:") 890 macro(5,":,:,:,:,:") 891 macro(6,":,:,:,:,:,:") 892 macro(7,":,:,:,:,:,:,:") 893 894 #undef macro 895 896 897 898 899 810 900 811 901 #define macro(T) \ … … 947 1037 #undef macro 948 1038 1039 #define macro(T)\ 1040 template <>\ 1041 void CInterface::AttributeFortranInterfaceBody< CArray<StdString,T> >(ostream& oss, const string& className, const string& name)\ 1042 {\ 1043 oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \ 1044 oss << " CALL cxios_set_" << className << "_" << name << " &" << iendl; \ 1045 oss << "(" << className << "_hdl%daddr, " << name <<"_, LEN("<<name<<"_), LEN_TRIM("<<name<< "_), SHAPE(" << name << "_))" << iendl; \ 1046 oss << "ENDIF"; \ 1047 } 1048 1049 macro(1) 1050 macro(2) 1051 #undef macro 1052 949 1053 #define macro(T) \ 950 1054 template <> \ … … 1084 1188 1085 1189 #undef macro 1190 1191 #define macro(T)\ 1192 template <> \ 1193 void CInterface::AttributeFortranInterfaceGetBody< CArray<StdString,T> >(ostream& oss, const string& className, const string& name)\ 1194 {\ 1195 oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \ 1196 oss << " CALL cxios_get_" << className << "_" << name << " &" << iendl; \ 1197 oss << "(" << className << "_hdl%daddr, " << name << "_, LEN("<<name<<"_), SHAPE(" << name << "_))" << iendl; \ 1198 oss << "ENDIF"; \ 1199 } 1200 macro(1) 1201 macro(2) 1202 macro(3) 1203 macro(4) 1204 macro(5) 1205 macro(6) 1206 macro(7) 1207 1208 #undef macro 1209 1086 1210 } 1087 1211 #endif -
XIOS/trunk/src/io/nc4_data_output.cpp
r1048 r1050 1060 1060 else if (axis->prec==8) typePrec = NC_DOUBLE ; 1061 1061 1062 if (!axis->label.isEmpty()) typePrec = NC_CHAR ; 1063 string strId="str_len" ; 1062 1064 try 1063 1065 { 1064 1066 SuperClassWriter::addDimension(axisid, zoom_size); 1067 if (!axis->label.isEmpty()) SuperClassWriter::addDimension(strId, stringArrayLen); 1065 1068 if (axis->hasValue) 1066 1069 { 1067 1070 dims.push_back(axisid); 1071 if (!axis->label.isEmpty()) dims.push_back(strId); 1068 1072 SuperClassWriter::addVariable(axisid, typePrec, dims); 1069 1073 … … 1104 1108 CArray<double,1> axis_value(zoom_size_srv); 1105 1109 for (int i = 0; i < zoom_size_srv; i++) axis_value(i) = axis->value_srv(i); 1106 SuperClassWriter::writeData(axis_value, axisid, isCollective, 0);1107 1108 if (!axis->bounds.isEmpty() )1110 if (axis->label.isEmpty()) SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); 1111 1112 if (!axis->bounds.isEmpty() && axis->label.isEmpty()) 1109 1113 SuperClassWriter::writeData(axis->bound_srv, axisBoundsId, isCollective, 0); 1110 1114 1115 if (! axis->label.isEmpty()) SuperClassWriter::writeData(axis->label_srv, axisid, isCollective, 0); 1116 1111 1117 SuperClassWriter::definition_start(); 1112 1113 1118 break; 1114 1119 } … … 1124 1129 startBounds[1] = 0; 1125 1130 countBounds[1] = 2; 1126 SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count);1127 1128 if (!axis->bounds.isEmpty() )1131 if (axis->label.isEmpty()) SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count); 1132 1133 if (!axis->bounds.isEmpty()&& axis->label.isEmpty()) 1129 1134 SuperClassWriter::writeData(axis->bound_srv, axisBoundsId, isCollective, 0, &startBounds, &countBounds); 1135 1136 if (! axis->label.isEmpty()) SuperClassWriter::writeData(axis->label_srv, axisid, isCollective, 0); 1130 1137 1131 1138 SuperClassWriter::definition_start(); -
XIOS/trunk/src/io/netCdfInterface.cpp
r972 r1050 967 967 } 968 968 969 template<> 970 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, char* data) 971 { 972 return nc_get_vara_text(ncid, varid, start, count, data); 973 } 974 969 975 // Some specializations of putVariableType 970 976 template<> … … 984 990 { 985 991 return nc_put_vara_int(ncid, varid, start, count, data); 992 } 993 994 template<> 995 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const char* data) 996 { 997 return nc_put_vara_text(ncid, varid, start, count, data); 986 998 } 987 999 -
XIOS/trunk/src/io/netCdfInterface_decl.cpp
r686 r1050 33 33 macroPutVar(float) 34 34 macroPutVar(int) 35 35 macroPutVar(char) 36 36 37 #define macroType(type, ncType) \ 37 38 template<> nc_type CNetCdfInterface::getNcType<type>() { return ncType; } -
XIOS/trunk/src/io/onetcdf4.cpp
r878 r1050 503 503 void CONetCDF4::writeData_(int grpid, int varid, 504 504 const std::vector<StdSize>& sstart, 505 const std::vector<StdSize>& scount, char* data) 506 { 507 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 508 } 509 510 template <> 511 512 void CONetCDF4::writeData_(int grpid, int varid, 513 const std::vector<StdSize>& sstart, 505 514 const std::vector<StdSize>& scount, const int* data) 506 515 { 507 516 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 508 517 } 509 510 518 //--------------------------------------------------------------- 511 519 -
XIOS/trunk/src/io/onetcdf4_decl.cpp
r924 r1050 14 14 macro(double, 2) 15 15 macro(double, 3) 16 macro(StdString, 1) 16 17 17 18 template void CONetCDF4::setDefaultValue<double>(const StdString & varname, const double* value) ; -
XIOS/trunk/src/io/onetcdf4_impl.hpp
r685 r1050 36 36 } 37 37 38 template <> 39 void CONetCDF4::writeData(const CArray<StdString, 1>& data, const StdString & name, 40 bool collective, StdSize record, 41 const std::vector<StdSize> * start, 42 const std::vector<StdSize> * count) 43 { 44 int grpid = this->getCurrentGroup(); 45 int varid = this->getVariable(name); 46 StdSize array_size = 1; 47 std::vector<StdSize> sstart, scount; 48 49 if (this->wmpi && collective) 50 CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE); 51 if (this->wmpi && !collective) 52 CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT); 53 54 this->getWriteDataInfos 55 (name, record, array_size, sstart, scount, start, count); 56 if (data.numElements()*stringArrayLen != array_size) 57 { 58 ERROR("CONetCDF4::writeData(...)", 59 << "[ input array size = " << data.numElements() 60 << ", intern array size = " << array_size 61 << " ] Invalid input data !" ); 62 } 63 char* ArrayStr ; 64 char *PtrArrayStr ; 65 PtrArrayStr=ArrayStr=new char[data.numElements()*stringArrayLen] ; 66 Array<StdString,1>::const_iterator it, itb=data.begin(), ite=data.end() ; 67 for(it=itb;it!=ite;++it,PtrArrayStr+=stringArrayLen) 68 { 69 it->copy(PtrArrayStr,it->size()) ; 70 PtrArrayStr[it->size()]='\0' ; 71 } 72 this->writeData_(grpid, varid, sstart, scount, ArrayStr); 73 delete [] ArrayStr ; 74 } 75 38 76 //---------------------------------------------------------------- 39 77 -
XIOS/trunk/src/node/axis.cpp
r995 r1050 27 27 , isDistributed_(false), hasBounds_(false), isCompressible_(false) 28 28 , numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) 29 , transformationMap_(), hasValue(false) 29 , transformationMap_(), hasValue(false), hasLabel(false) 30 30 { 31 31 } … … 37 37 , isDistributed_(false), hasBounds_(false), isCompressible_(false) 38 38 , numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) 39 , transformationMap_(), hasValue(false) 39 , transformationMap_(), hasValue(false), hasLabel(false) 40 40 { 41 41 } … … 176 176 if (hasBounds_) 177 177 sizeValEvent += CArray<double,2>::size(2 * it->second.size()); 178 179 if (hasLabel) 180 sizeValEvent += CArray<StdString,1>::size(it->second.size()); 178 181 179 182 size_t size = CEventClient::headerSize + getId().size() + sizeof(size_t) + std::max(sizeIndexEvent, sizeValEvent); … … 261 264 this->checkMask(); 262 265 this->checkBounds(); 266 this->checkLabel(); 263 267 264 268 isDistributed_ = (!this->begin.isEmpty() && !this->n.isEmpty() && (this->begin + this->n < this->n_glo)) || … … 333 337 } 334 338 339 void CAxis::checkLabel() 340 { 341 if (!label.isEmpty()) 342 { 343 if (label.extent(0) != n) 344 ERROR("CAxis::checkLabel(void)", 345 << "The label array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension of axis size." << std::endl 346 << "Axis size is " << n.getValue() << "." << std::endl 347 << "label size is "<< label.extent(0)<< " ."); 348 hasLabel = true; 349 } 350 else hasLabel = false; 351 } 335 352 void CAxis::checkEligibilityForCompressedOutput() 336 353 { … … 657 674 list<CArray<double,1> > list_val; 658 675 list<CArray<double,2> > list_bounds; 676 list<CArray<StdString,1> > list_label; 659 677 660 678 std::map<int, std::vector<size_t> >::const_iterator it, iteMap; … … 675 693 list_bounds.push_back(CArray<double,2>(2,nbData)); 676 694 } 695 696 if (hasLabel) 697 { 698 list_label.push_back(CArray<StdString,1>(nbData)); 699 } 677 700 678 701 CArray<int,1>& indi = list_indi.back(); … … 693 716 boundsVal(1, n) = bounds(1,n); 694 717 } 718 719 if (hasLabel) 720 { 721 CArray<StdString,1>& labelVal = list_label.back(); 722 labelVal(n) = label(n); 723 } 695 724 } 696 725 … … 716 745 { 717 746 list_msgsVal.back() << list_bounds.back(); 747 } 748 749 if (hasLabel) 750 { 751 list_msgsVal.back() << list_label.back(); 718 752 } 719 753 … … 783 817 CArray<double,1> val; 784 818 CArray<double,2> boundsVal; 819 CArray<StdString,1> labelVal; 785 820 786 821 buffer >> val; 787 822 if (hasBounds_) buffer >> boundsVal; 823 if (hasLabel) buffer >> labelVal; 788 824 789 825 int i, j, ind_srv; … … 798 834 bound_srv(1,ind_srv) = boundsVal(1, ind); 799 835 } 836 837 if (hasLabel) 838 { 839 label_srv(ind_srv) = labelVal( ind); 840 } 841 800 842 } 801 843 } … … 836 878 bound_srv(0,ind) = bounds(0,ind); 837 879 bound_srv(1,ind) = bounds(1,ind); 880 } 881 if (hasLabel) 882 { 883 label_srv(ind) = label(ind); 838 884 } 839 885 } … … 927 973 value_srv.resize(zoom_size_srv); 928 974 if (hasBounds_) bound_srv.resize(2,zoom_size_srv); 975 if (hasLabel) label_srv.resize(zoom_size_srv); 929 976 } 930 977 } -
XIOS/trunk/src/node/axis.hpp
r927 r1050 123 123 CArray<double,1> value_srv; 124 124 CArray<double,2> bound_srv; 125 CArray<StdString,1> label_srv; 125 126 bool hasValue; 126 127 … … 130 131 void checkZoom(); 131 132 void checkBounds(); 133 void checkLabel(); 132 134 void checkTransformations(); 133 135 void sendValue(); … … 163 165 std::map<int, CArray<int,1> > indiSrv_; 164 166 bool hasBounds_; 167 bool hasLabel; 165 168 166 169 private:
Note: See TracChangeset
for help on using the changeset viewer.