Changeset 12416
- Timestamp:
- 06/13/12 15:00:23 (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
r12382 r12416 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, doubles and strings only, nothing memory intensive*/52 this->FetchConstants(); /*this routine goes through the input file, and fetches bools, ints, IssmPDoubles and strings only, nothing memory intensive*/ 53 53 54 54 /*Initialize data: */ 55 this->data=( double**)xmalloc(MaximumNumberOfEnums*sizeof(double*));55 this->data=(IssmPDouble**)xmalloc(MaximumNumberOfEnums*sizeof(IssmPDouble*)); 56 56 for(int i=0;i<MaximumNumberOfEnums;i++) this->data[i]=NULL; 57 57 … … 152 152 } 153 153 /*}}}*/ 154 /*FUNCTION IoModel::Constant( double* poutput,int constant_enum){{{*/155 void IoModel::Constant( double* poutput,int constant_enum){154 /*FUNCTION IoModel::Constant(IssmPDouble* poutput,int constant_enum){{{*/ 155 void IoModel::Constant(IssmPDouble* poutput,int constant_enum){ 156 156 157 157 _assert_(constant_enum>=0); … … 183 183 /*}}}*/ 184 184 /*FUNCTION IoModel::Data{{{*/ 185 double* IoModel::Data(int data_enum){185 IssmPDouble* IoModel::Data(int data_enum){ 186 186 187 187 _assert_(data_enum<MaximumNumberOfEnums); … … 223 223 int booleanint=0; 224 224 int integer=0; 225 double scalar=0;225 IssmPDouble scalar=0; 226 226 char* string=NULL; 227 227 int string_size; … … 237 237 fseek(this->fid,0,SEEK_SET); 238 238 239 /*Now march through file looking for the correct data identifiers (bool,int, double or string): */239 /*Now march through file looking for the correct data identifiers (bool,int,IssmPDouble or string): */ 240 240 for(;;){ 241 241 if(fread(&record_enum,sizeof(int),1,this->fid)==0){ … … 288 288 case 3: 289 289 /*Read the scalar and broadcast it to other cpus:*/ 290 if(fread(&scalar,sizeof( double),1,this->fid)!=1) _error_(" could not read scalar ");290 if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_(" could not read scalar "); 291 291 #ifdef _HAVE_MPI_ 292 292 MPI_Bcast(&scalar,1,MPI_DOUBLE,0,MPI_COMM_WORLD); … … 499 499 } 500 500 /*}}}*/ 501 /*FUNCTION IoModel::FetchData( double* pscalar,int data_enum){{{*/502 void IoModel::FetchData( double* pscalar,int data_enum){501 /*FUNCTION IoModel::FetchData(IssmPDouble* pscalar,int data_enum){{{*/ 502 void IoModel::FetchData(IssmPDouble* pscalar,int data_enum){ 503 503 504 504 … … 508 508 509 509 /*output: */ 510 double scalar;510 IssmPDouble scalar; 511 511 int code; 512 512 … … 514 514 fid=this->SetFilePointerToData(&code,NULL,data_enum); 515 515 516 if(code!=3)_error_("expecting a double for enum %s",EnumToStringx(data_enum));516 if(code!=3)_error_("expecting a IssmPDouble for enum %s",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: */ 519 519 if(my_rank==0){ 520 if(fread(&scalar,sizeof( double),1,fid)!=1)_error_(" could not read scalar ");520 if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_(" could not read scalar "); 521 521 } 522 522 #ifdef _HAVE_MPI_ … … 589 589 /*output: */ 590 590 int M,N; 591 double* matrix=NULL;591 IssmPDouble* matrix=NULL; 592 592 int* integer_matrix=NULL; 593 593 int code=0; … … 598 598 fid=this->SetFilePointerToData(&code,&vector_type,data_enum); 599 599 600 if((code!=5) && (code!=6) && (code!=7))_error_("expecting a double, integer or boolean matrix for enum %s",EnumToStringx(data_enum));600 if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmPDouble, integer or boolean matrix for enum %s",EnumToStringx(data_enum)); 601 601 602 602 /*Now fetch: */ … … 621 621 /*Now allocate matrix: */ 622 622 if(M*N){ 623 matrix=( double*)xmalloc(M*N*sizeof(double));623 matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble)); 624 624 625 625 /*Read matrix on node 0, then broadcast: */ 626 626 if(my_rank==0){ 627 if(fread(matrix,M*N*sizeof( double),1,fid)!=1) _error_("could not read matrix ");627 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 628 628 } 629 629 … … 655 655 } 656 656 /*}}}*/ 657 /*FUNCTION IoModel::FetchData( double** pdoublematrix,int* pM,int* pN,int data_enum){{{*/658 void IoModel::FetchData( double** pmatrix,int* pM,int* pN,int data_enum){657 /*FUNCTION IoModel::FetchData(IssmPDouble** pIssmPDoublematrix,int* pM,int* pN,int data_enum){{{*/ 658 void IoModel::FetchData(IssmPDouble** pmatrix,int* pM,int* pN,int data_enum){ 659 659 660 660 extern int my_rank; … … 663 663 /*output: */ 664 664 int M,N; 665 double* matrix=NULL;665 IssmPDouble* matrix=NULL; 666 666 int code=0; 667 667 int vector_type=0; … … 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))_error_("expecting a double, integer or boolean matrix for enum %s",EnumToStringx(data_enum));671 if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmPDouble, integer or boolean matrix for enum %s",EnumToStringx(data_enum)); 672 672 673 673 /*Now fetch: */ … … 691 691 /*Now allocate matrix: */ 692 692 if(M*N){ 693 matrix=( double*)xmalloc(M*N*sizeof(double));693 matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble)); 694 694 695 695 /*Read matrix on node 0, then broadcast: */ 696 696 if(my_rank==0){ 697 if(fread(matrix,M*N*sizeof( double),1,fid)!=1) _error_("could not read matrix ");697 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 698 698 } 699 699 #ifdef _HAVE_MPI_ … … 778 778 } 779 779 /*}}}*/ 780 /*FUNCTION IoModel::FetchData( double*** pmatrices,int** pmdims,int** pndims, int* pM,int data_enum){{{*/781 void IoModel::FetchData( double*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,int data_enum){780 /*FUNCTION IoModel::FetchData(IssmPDouble*** pmatrices,int** pmdims,int** pndims, int* pM,int data_enum){{{*/ 781 void IoModel::FetchData(IssmPDouble*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,int data_enum){ 782 782 783 783 int i; … … 787 787 788 788 /*output: */ 789 double** matrices=NULL;789 IssmPDouble** matrices=NULL; 790 790 int* mdims=NULL; 791 791 int* ndims=NULL; … … 794 794 /*intermediary: */ 795 795 int M, N; 796 double *matrix = NULL;796 IssmPDouble *matrix = NULL; 797 797 int code; 798 798 799 799 /*Set file pointer to beginning of the data: */ 800 800 fid=this->SetFilePointerToData(&code,NULL,data_enum); 801 if(code!=8)_error_("expecting a double mat array for enum %s",EnumToStringx(data_enum));801 if(code!=8)_error_("expecting a IssmPDouble mat array for enum %s",EnumToStringx(data_enum)); 802 802 803 803 /*Now fetch: */ … … 812 812 813 813 /*Allocate matrices :*/ 814 matrices=( double**)xmalloc(numrecords*sizeof(double*));814 matrices=(IssmPDouble**)xmalloc(numrecords*sizeof(IssmPDouble*)); 815 815 mdims=(int*)xmalloc(numrecords*sizeof(int)); 816 816 ndims=(int*)xmalloc(numrecords*sizeof(int)); … … 841 841 /*Now allocate matrix: */ 842 842 if(M*N){ 843 matrix=( double*)xmalloc(M*N*sizeof(double));843 matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble)); 844 844 845 845 /*Read matrix on node 0, then broadcast: */ 846 846 if(my_rank==0){ 847 if(fread(matrix,M*N*sizeof( double),1,fid)!=1) _error_("could not read matrix ");847 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 848 848 } 849 849 … … 885 885 fid=this->SetFilePointerToData(&code,NULL,index+1); 886 886 switch(code){ 887 case 3: {// double888 double *value = NULL;889 value=( double*)xmalloc(1*sizeof(double));887 case 3: {//IssmPDouble 888 IssmPDouble *value = NULL; 889 value=(IssmPDouble*)xmalloc(1*sizeof(IssmPDouble)); 890 890 FetchData(value,index+1); 891 891 _printf_(true,"value = %g\n",*value); … … 923 923 va_list ap; 924 924 int dataenum; 925 double* matrix=NULL;925 IssmPDouble* matrix=NULL; 926 926 int M,N; 927 927 int i; 928 928 929 929 /*Go through the entire list of enums and fetch the corresponding data. Add it to the iomodel->data dataset. Everything 930 *we fetch is a double* : */930 *we fetch is a IssmPDouble* : */ 931 931 932 932 va_start(ap,num); … … 954 954 /*}}}*/ 955 955 /*FUNCTION IoModel::FetchDataToInput{{{*/ 956 void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum, double default_value){956 void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum,IssmPDouble default_value){ 957 957 958 958 /*intermediary: */ … … 973 973 bool boolean; 974 974 int integer; 975 double scalar;975 IssmPDouble scalar; 976 976 char *string = NULL; 977 double *doublevector = NULL;977 IssmPDouble *IssmPDoublevector = NULL; 978 978 int M,N; 979 979 … … 993 993 if(this->my_elements[i]){ 994 994 Element* element=(Element*)elements->GetObjectByOffset(counter); 995 element->InputCreate(( double)boolean,vector_enum,code);995 element->InputCreate((IssmPDouble)boolean,vector_enum,code); 996 996 counter++; 997 997 } … … 1006 1006 if(this->my_elements[i]){ 1007 1007 Element* element=(Element*)elements->GetObjectByOffset(counter); 1008 element->InputCreate(( double)integer,vector_enum,code);1008 element->InputCreate((IssmPDouble)integer,vector_enum,code); 1009 1009 counter++; 1010 1010 } 1011 1011 } 1012 1012 break; /*}}}*/ 1013 case 3: // double constant. {{{1013 case 3: //IssmPDouble constant. {{{ 1014 1014 this->FetchData(&scalar,vector_enum); 1015 1015 1016 /*Add double constant input to all elements: */1016 /*Add IssmPDouble constant input to all elements: */ 1017 1017 counter=0; 1018 1018 for (i=0;i<numberofelements;i++){ … … 1027 1027 1028 1028 /*Fetch vector:*/ 1029 this->FetchData(& doublevector,&M,&N,vector_enum); //we still have a doublevector, because it might include times in transient mode1029 this->FetchData(&IssmPDoublevector,&M,&N,vector_enum); //we still have a IssmPDoublevector, because it might include times in transient mode 1030 1030 /*Check we got something, otherwise fetch default: */ 1031 if( doublevector){1031 if(IssmPDoublevector){ 1032 1032 defaulting=false; //we are not defaulting, because we do have a vector 1033 1033 } … … 1036 1036 if(default_vector_enum!=NoneEnum){ 1037 1037 /*yes. fetch it: */ 1038 this->FetchData(& doublevector,&M,&N,default_vector_enum);1039 if( doublevector){1038 this->FetchData(&IssmPDoublevector,&M,&N,default_vector_enum); 1039 if(IssmPDoublevector){ 1040 1040 defaulting=false; //we are not defaulting, because we do have a vector 1041 1041 } … … 1057 1057 Element* element=(Element*)elements->GetObjectByOffset(counter); 1058 1058 if(defaulting) element->InputCreate(default_value,vector_enum,code); 1059 else element->InputCreate( doublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.1059 else element->InputCreate(IssmPDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements. 1060 1060 counter++; 1061 1061 } … … 1065 1065 1066 1066 /*Fetch vector:*/ 1067 this->FetchData(& doublevector,&M,&N,vector_enum); //we still have a doublevector, because it might include times in transient mode1067 this->FetchData(&IssmPDoublevector,&M,&N,vector_enum); //we still have a IssmPDoublevector, because it might include times in transient mode 1068 1068 /*Check we got something, otherwise fetch default: */ 1069 if( doublevector){1069 if(IssmPDoublevector){ 1070 1070 defaulting=false; //we are not defaulting, because we do have a vector 1071 1071 } … … 1074 1074 if(default_vector_enum!=NoneEnum){ 1075 1075 /*yes. fetch it: */ 1076 this->FetchData(& doublevector,&M,&N,default_vector_enum);1077 if( doublevector){1076 this->FetchData(&IssmPDoublevector,&M,&N,default_vector_enum); 1077 if(IssmPDoublevector){ 1078 1078 defaulting=false; //we are not defaulting, because we do have a vector 1079 1079 } … … 1095 1095 Element* element=(Element*)elements->GetObjectByOffset(counter); 1096 1096 if(defaulting) element->InputCreate(default_value,vector_enum,code); 1097 else element->InputCreate( doublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.1097 else element->InputCreate(IssmPDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements. 1098 1098 counter++; 1099 1099 } 1100 1100 } 1101 1101 break; /*}}}*/ 1102 case 7: // double vector{{{1102 case 7: //IssmPDouble vector{{{ 1103 1103 1104 1104 /*Fetch vector:*/ 1105 this->FetchData(& doublevector,&M,&N,vector_enum);1105 this->FetchData(&IssmPDoublevector,&M,&N,vector_enum); 1106 1106 /*Check we got something, otherwise fetch default: */ 1107 if( doublevector){1107 if(IssmPDoublevector){ 1108 1108 defaulting=false; //we are not defaulting, because we do have a vector 1109 1109 } … … 1112 1112 if(default_vector_enum!=NoneEnum){ 1113 1113 /*yes. fetch it: */ 1114 this->FetchData(& doublevector,&M,&N,default_vector_enum);1115 if( doublevector){1114 this->FetchData(&IssmPDoublevector,&M,&N,default_vector_enum); 1115 if(IssmPDoublevector){ 1116 1116 defaulting=false; //we are not defaulting, because we do have a vector 1117 1117 } … … 1133 1133 Element* element=(Element*)elements->GetObjectByOffset(counter); 1134 1134 if(defaulting) element->InputCreate(default_value,vector_enum,code); 1135 else element->InputCreate( doublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.1135 else element->InputCreate(IssmPDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements. 1136 1136 counter++; 1137 1137 } … … 1145 1145 } 1146 1146 /*Free ressources:*/ 1147 xfree((void**)& doublevector);1147 xfree((void**)&IssmPDoublevector); 1148 1148 xfree((void**)&string); 1149 1149 } -
issm/trunk-jpl/src/c/objects/IoModel.h
r12382 r12416 18 18 19 19 private: 20 Issm Double**data; //this dataset holds temporary data, memory intensive.21 Parameters *constants; //this dataset holds all Issm Double, int, bool and char *parameters read in from the input file.*20 IssmPDouble **data; //this dataset holds temporary data, memory intensive. 21 Parameters *constants; //this dataset holds all IssmPDouble, 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 Double *poutput,int constant_enum);46 void Constant(IssmPDouble *poutput,int constant_enum); 47 47 void Constant(char **poutput,int constant_enum); 48 48 Param *CopyConstantObject(int constant_enum); 49 Issm Double *Data(int dataenum);49 IssmPDouble *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 Double* pscalar,int data_enum);54 void FetchData(IssmPDouble* 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 Double** pscalarmatrix,int* pM,int* pN,int data_enum);57 void FetchData(IssmPDouble** pscalarmatrix,int* pM,int* pN,int data_enum); 58 58 void FetchData(char*** pstringarray,int* pnumstrings,int data_enum); 59 void FetchData(Issm Double*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum);59 void FetchData(IssmPDouble*** 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 Double default_value=0);62 void FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmPDouble 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.