Changeset 12552
- Timestamp:
- 06/26/12 10:56:58 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/objects/IoModel.cpp
r12519 r12552 50 50 /*Initialize and read constants:*/ 51 51 this->constants=new Parameters(); 52 this->FetchConstants(); /*this routine goes through the input file, and fetches bools, ints, Issm PDoubles and strings only, nothing memory intensive*/52 this->FetchConstants(); /*this routine goes through the input file, and fetches bools, ints, IssmDoubles and strings only, nothing memory intensive*/ 53 53 54 54 /*Initialize data: */ 55 this->data=xNew<Issm PDouble*>(MaximumNumberOfEnums);55 this->data=xNew<IssmDouble*>(MaximumNumberOfEnums); 56 56 for(int i=0;i<MaximumNumberOfEnums;i++) this->data[i]=NULL; 57 57 … … 84 84 #endif 85 85 86 xDelete<Issm PDouble*>(this->data);86 xDelete<IssmDouble*>(this->data); 87 87 xDelete<bool>(this->my_elements); 88 88 xDelete<bool>(this->my_nodes); … … 152 152 } 153 153 /*}}}*/ 154 /*FUNCTION IoModel::Constant(Issm PDouble* poutput,int constant_enum){{{*/155 void IoModel::Constant(Issm PDouble* poutput,int constant_enum){154 /*FUNCTION IoModel::Constant(IssmDouble* poutput,int constant_enum){{{*/ 155 void IoModel::Constant(IssmDouble* poutput,int constant_enum){ 156 156 157 157 _assert_(constant_enum>=0); … … 183 183 /*}}}*/ 184 184 /*FUNCTION IoModel::Data{{{*/ 185 Issm PDouble* IoModel::Data(int data_enum){185 IssmDouble* IoModel::Data(int data_enum){ 186 186 187 187 _assert_(data_enum<MaximumNumberOfEnums); … … 205 205 dataenum=va_arg(ap, int); 206 206 _assert_(dataenum<MaximumNumberOfEnums); 207 xDelete< double>(this->data[dataenum]);207 xDelete<IssmDouble>(this->data[dataenum]); 208 208 } 209 209 va_end(ap); … … 237 237 fseek(this->fid,0,SEEK_SET); 238 238 239 /*Now march through file looking for the correct data identifiers (bool,int,Issm PDouble or string): */239 /*Now march through file looking for the correct data identifiers (bool,int,IssmDouble or string): */ 240 240 for(;;){ 241 241 if(fread(&record_enum,sizeof(int),1,this->fid)==0){ … … 499 499 } 500 500 /*}}}*/ 501 /*FUNCTION IoModel::FetchData(Issm PDouble* pscalar,int data_enum){{{*/502 void IoModel::FetchData(Issm PDouble* pscalar,int data_enum){501 /*FUNCTION IoModel::FetchData(IssmDouble* pscalar,int data_enum){{{*/ 502 void IoModel::FetchData(IssmDouble* pscalar,int data_enum){ 503 503 504 504 … … 514 514 fid=this->SetFilePointerToData(&code,NULL,data_enum); 515 515 516 if(code!=3)_error2_("expecting a Issm PDouble for enum " << EnumToStringx(data_enum));516 if(code!=3)_error2_("expecting a IssmDouble for enum " << EnumToStringx(data_enum)); 517 517 518 518 /*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */ … … 598 598 fid=this->SetFilePointerToData(&code,&vector_type,data_enum); 599 599 600 if((code!=5) && (code!=6) && (code!=7))_error2_("expecting a Issm PDouble, integer or boolean matrix for enum " << EnumToStringx(data_enum));600 if((code!=5) && (code!=6) && (code!=7))_error2_("expecting a IssmDouble, integer or boolean matrix for enum " << EnumToStringx(data_enum)); 601 601 602 602 /*Now fetch: */ … … 655 655 } 656 656 /*}}}*/ 657 /*FUNCTION IoModel::FetchData(Issm PDouble** pIssmPDoublematrix,int* pM,int* pN,int data_enum){{{*/658 void IoModel::FetchData(Issm PDouble** pmatrix,int* pM,int* pN,int data_enum){657 /*FUNCTION IoModel::FetchData(IssmDouble** pIssmDoublematrix,int* pM,int* pN,int data_enum){{{*/ 658 void IoModel::FetchData(IssmDouble** pmatrix,int* pM,int* pN,int data_enum){ 659 659 660 660 extern int my_rank; … … 669 669 /*Set file pointer to beginning of the data: */ 670 670 fid=this->SetFilePointerToData(&code,&vector_type,data_enum); 671 if((code!=5) && (code!=6) && (code!=7))_error2_("expecting a Issm PDouble, integer or boolean matrix for enum " << EnumToStringx(data_enum));671 if((code!=5) && (code!=6) && (code!=7))_error2_("expecting a IssmDouble, integer or boolean matrix for enum " << EnumToStringx(data_enum)); 672 672 673 673 /*Now fetch: */ … … 700 700 MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 701 701 #endif 702 } 703 702 *pmatrix=xNew<IssmDouble>(M*N); 703 for (int i=0;i<M*N;++i) (*pmatrix)[i]=matrix[i]; 704 xDelete<IssmPDouble>(matrix); 705 } 706 else 707 *pmatrix=NULL; 704 708 /*Assign output pointers: */ 705 *pmatrix=matrix;706 709 if (pM)*pM=M; 707 710 if (pN)*pN=N; … … 778 781 } 779 782 /*}}}*/ 780 /*FUNCTION IoModel::FetchData(Issm PDouble*** pmatrices,int** pmdims,int** pndims, int* pM,int data_enum){{{*/781 void IoModel::FetchData(Issm PDouble*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,int data_enum){783 /*FUNCTION IoModel::FetchData(IssmDouble*** pmatrices,int** pmdims,int** pndims, int* pM,int data_enum){{{*/ 784 void IoModel::FetchData(IssmDouble*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,int data_enum){ 782 785 783 786 int i; … … 787 790 788 791 /*output: */ 789 Issm PDouble** matrices=NULL;792 IssmDouble** matrices=NULL; 790 793 int* mdims=NULL; 791 794 int* ndims=NULL; … … 799 802 /*Set file pointer to beginning of the data: */ 800 803 fid=this->SetFilePointerToData(&code,NULL,data_enum); 801 if(code!=8)_error2_("expecting a Issm PDouble mat array for enum " << EnumToStringx(data_enum));804 if(code!=8)_error2_("expecting a IssmDouble mat array for enum " << EnumToStringx(data_enum)); 802 805 803 806 /*Now fetch: */ … … 812 815 813 816 /*Allocate matrices :*/ 814 matrices=xNew<Issm PDouble*>(numrecords);817 matrices=xNew<IssmDouble*>(numrecords); 815 818 mdims=xNew<int>(numrecords); 816 819 ndims=xNew<int>(numrecords); … … 851 854 MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 852 855 #endif 853 } 854 856 matrices[i]=xNew<IssmDouble>(M*N); 857 for (int j=0;j<M*N;++j) {matrices[i][j]=matrix[j];} 858 xDelete<IssmPDouble>(matrix); 859 } 860 else 861 matrices[i]=NULL; 855 862 /*Assign: */ 856 matrices[i]=matrix;857 863 mdims[i]=M; 858 864 ndims[i]=N; … … 884 890 fid=this->SetFilePointerToData(&code,NULL,index+1); 885 891 switch(code){ 886 case 3: {//Issm PDouble887 Issm PDouble *value = NULL;888 value=xNew<Issm PDouble>(1);892 case 3: {//IssmDouble 893 IssmDouble *value = NULL; 894 value=xNew<IssmDouble>(1); 889 895 FetchData(value,index+1); 890 896 option = new OptionDouble(); … … 920 926 va_list ap; 921 927 int dataenum; 922 Issm PDouble* matrix=NULL;928 IssmDouble* matrix=NULL; 923 929 int M,N; 924 930 int i; 925 931 926 932 /*Go through the entire list of enums and fetch the corresponding data. Add it to the iomodel->data dataset. Everything 927 *we fetch is a Issm PDouble* : */933 *we fetch is a IssmDouble* : */ 928 934 929 935 va_start(ap,num); … … 951 957 /*}}}*/ 952 958 /*FUNCTION IoModel::FetchDataToInput{{{*/ 953 void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum,Issm PDouble default_value){959 void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum,IssmDouble default_value){ 954 960 955 961 /*intermediary: */ … … 970 976 bool boolean; 971 977 int integer; 972 Issm PDouble scalar;978 IssmDouble scalar; 973 979 char *string = NULL; 974 Issm PDouble *IssmPDoublevector = NULL;980 IssmDouble *IssmDoublevector = NULL; 975 981 int M,N; 976 982 … … 990 996 if(this->my_elements[i]){ 991 997 Element* element=(Element*)elements->GetObjectByOffset(counter); 992 element->InputCreate((Issm PDouble)boolean,vector_enum,code);998 element->InputCreate((IssmDouble)boolean,vector_enum,code); 993 999 counter++; 994 1000 } … … 1003 1009 if(this->my_elements[i]){ 1004 1010 Element* element=(Element*)elements->GetObjectByOffset(counter); 1005 element->InputCreate((Issm PDouble)integer,vector_enum,code);1011 element->InputCreate((IssmDouble)integer,vector_enum,code); 1006 1012 counter++; 1007 1013 } 1008 1014 } 1009 1015 break; /*}}}*/ 1010 case 3: //Issm PDouble constant. {{{1016 case 3: //IssmDouble constant. {{{ 1011 1017 this->FetchData(&scalar,vector_enum); 1012 1018 1013 /*Add Issm PDouble constant input to all elements: */1019 /*Add IssmDouble constant input to all elements: */ 1014 1020 counter=0; 1015 1021 for (i=0;i<numberofelements;i++){ … … 1024 1030 1025 1031 /*Fetch vector:*/ 1026 this->FetchData(&Issm PDoublevector,&M,&N,vector_enum); //we still have a IssmPDoublevector, because it might include times in transient mode1032 this->FetchData(&IssmDoublevector,&M,&N,vector_enum); //we still have a IssmDoublevector, because it might include times in transient mode 1027 1033 /*Check we got something, otherwise fetch default: */ 1028 if(Issm PDoublevector){1034 if(IssmDoublevector){ 1029 1035 defaulting=false; //we are not defaulting, because we do have a vector 1030 1036 } … … 1033 1039 if(default_vector_enum!=NoneEnum){ 1034 1040 /*yes. fetch it: */ 1035 this->FetchData(&Issm PDoublevector,&M,&N,default_vector_enum);1036 if(Issm PDoublevector){1041 this->FetchData(&IssmDoublevector,&M,&N,default_vector_enum); 1042 if(IssmDoublevector){ 1037 1043 defaulting=false; //we are not defaulting, because we do have a vector 1038 1044 } … … 1054 1060 Element* element=(Element*)elements->GetObjectByOffset(counter); 1055 1061 if(defaulting) element->InputCreate(default_value,vector_enum,code); 1056 else element->InputCreate(Issm PDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.1062 else element->InputCreate(IssmDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements. 1057 1063 counter++; 1058 1064 } … … 1062 1068 1063 1069 /*Fetch vector:*/ 1064 this->FetchData(&Issm PDoublevector,&M,&N,vector_enum); //we still have a IssmPDoublevector, because it might include times in transient mode1070 this->FetchData(&IssmDoublevector,&M,&N,vector_enum); //we still have a IssmDoublevector, because it might include times in transient mode 1065 1071 /*Check we got something, otherwise fetch default: */ 1066 if(Issm PDoublevector){1072 if(IssmDoublevector){ 1067 1073 defaulting=false; //we are not defaulting, because we do have a vector 1068 1074 } … … 1071 1077 if(default_vector_enum!=NoneEnum){ 1072 1078 /*yes. fetch it: */ 1073 this->FetchData(&Issm PDoublevector,&M,&N,default_vector_enum);1074 if(Issm PDoublevector){1079 this->FetchData(&IssmDoublevector,&M,&N,default_vector_enum); 1080 if(IssmDoublevector){ 1075 1081 defaulting=false; //we are not defaulting, because we do have a vector 1076 1082 } … … 1092 1098 Element* element=(Element*)elements->GetObjectByOffset(counter); 1093 1099 if(defaulting) element->InputCreate(default_value,vector_enum,code); 1094 else element->InputCreate(Issm PDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.1100 else element->InputCreate(IssmDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements. 1095 1101 counter++; 1096 1102 } 1097 1103 } 1098 1104 break; /*}}}*/ 1099 case 7: //Issm PDouble vector{{{1105 case 7: //IssmDouble vector{{{ 1100 1106 1101 1107 /*Fetch vector:*/ 1102 this->FetchData(&Issm PDoublevector,&M,&N,vector_enum);1108 this->FetchData(&IssmDoublevector,&M,&N,vector_enum); 1103 1109 /*Check we got something, otherwise fetch default: */ 1104 if(Issm PDoublevector){1110 if(IssmDoublevector){ 1105 1111 defaulting=false; //we are not defaulting, because we do have a vector 1106 1112 } … … 1109 1115 if(default_vector_enum!=NoneEnum){ 1110 1116 /*yes. fetch it: */ 1111 this->FetchData(&Issm PDoublevector,&M,&N,default_vector_enum);1112 if(Issm PDoublevector){1117 this->FetchData(&IssmDoublevector,&M,&N,default_vector_enum); 1118 if(IssmDoublevector){ 1113 1119 defaulting=false; //we are not defaulting, because we do have a vector 1114 1120 } … … 1130 1136 Element* element=(Element*)elements->GetObjectByOffset(counter); 1131 1137 if(defaulting) element->InputCreate(default_value,vector_enum,code); 1132 else element->InputCreate(Issm PDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.1138 else element->InputCreate(IssmDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements. 1133 1139 counter++; 1134 1140 } … … 1142 1148 } 1143 1149 /*Free ressources:*/ 1144 xDelete<Issm PDouble>(IssmPDoublevector);1150 xDelete<IssmDouble>(IssmDoublevector); 1145 1151 xDelete<char>(string); 1146 1152 } -
issm/trunk-jpl/src/c/objects/IoModel.h
r12416 r12552 18 18 19 19 private: 20 Issm PDouble **data; //this dataset holds temporary data, memory intensive.21 Parameters *constants; //this dataset holds all Issm PDouble, int, bool and char *parameters read in from the input file.*20 IssmDouble **data; //this dataset holds temporary data, memory intensive. 21 Parameters *constants; //this dataset holds all IssmDouble, int, bool and char *parameters read in from the input file.* 22 22 23 23 public: … … 44 44 void Constant(bool *poutput,int constant_enum); 45 45 void Constant(int *poutput,int constant_enum); 46 void Constant(Issm PDouble *poutput,int constant_enum);46 void Constant(IssmDouble *poutput,int constant_enum); 47 47 void Constant(char **poutput,int constant_enum); 48 48 Param *CopyConstantObject(int constant_enum); 49 Issm PDouble *Data(int dataenum);49 IssmDouble *Data(int dataenum); 50 50 void DeleteData(int num,...); 51 51 void FetchConstants(void); 52 52 void FetchData(bool* pboolean,int data_enum); 53 53 void FetchData(int* pinteger,int data_enum); 54 void FetchData(Issm PDouble* pscalar,int data_enum);54 void FetchData(IssmDouble* pscalar,int data_enum); 55 55 void FetchData(char** pstring,int data_enum); 56 56 void FetchData(int** pmatrix,int* pM,int* pN,int data_enum); 57 void FetchData(Issm PDouble** pscalarmatrix,int* pM,int* pN,int data_enum);57 void FetchData(IssmDouble** pscalarmatrix,int* pM,int* pN,int data_enum); 58 58 void FetchData(char*** pstringarray,int* pnumstrings,int data_enum); 59 void FetchData(Issm PDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum);59 void FetchData(IssmDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum); 60 60 void FetchData(Option **poption,int data_enum); 61 61 void FetchData(int num,...); 62 void FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,Issm PDouble default_value=0);62 void FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmDouble default_value=0); 63 63 void LastIndex(int *pindex); 64 64 FILE* SetFilePointerToData(int* pcode,int* pvector_type, int data_enum);
Note:
See TracChangeset
for help on using the changeset viewer.