Changeset 12382
- Timestamp:
- 06/07/12 10:34:56 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Makefile.am
r12377 r12382 331 331 ./solvers/solver_linear.cpp\ 332 332 ./solvers/solver_nonlinear.cpp\ 333 ./solvers/solver_newton.cpp 333 ./solvers/solver_newton.cpp\ 334 ./objects/Options/Option.cpp\ 335 ./objects/Options/Option.h\ 336 ./objects/Options/OptionDouble.cpp\ 337 ./objects/Options/OptionDouble.h\ 338 ./objects/Options/OptionChar.cpp\ 339 ./objects/Options/OptionChar.h\ 340 ./objects/Options/OptionUtilities.cpp\ 341 ./objects/Options/OptionUtilities.h 342 334 343 #}}} 335 344 #DAKOTA sources {{{1 -
issm/trunk-jpl/src/c/objects/IoModel.cpp
r12377 r12382 867 867 } 868 868 /*}}}*/ 869 /*FUNCTION IoModel::FetchData(Option** poption,int data_enum){{{*/ 870 void IoModel::FetchData(Option** poption,int index){ 871 872 extern int my_rank; 873 extern int num_procs; 874 875 /*output: */ 876 int code; 877 Option *option = NULL; 878 char *name = NULL; 879 880 /*First get option name*/ 881 this->FetchData(&name,index); 882 _printf_(true,"Option name is %s\n",name); 883 884 /*Get option value*/ 885 fid=this->SetFilePointerToData(&code,NULL,index+1); 886 switch(code){ 887 case 3: {//double 888 double *value = NULL; 889 value=(double*)xmalloc(1*sizeof(double)); 890 FetchData(value,index+1); 891 _printf_(true,"value = %g\n",*value); 892 option = new OptionDouble(); 893 ((OptionDouble*)option)->values = value; 894 option->name = name; 895 option->numel = 1; 896 option->ndims = 1; 897 option->size = NULL; 898 break; 899 } 900 case 4: {//char 901 char* value = NULL; 902 FetchData(&value,index+1); 903 _printf_(true,"value = %s\n",value); 904 option = new OptionChar(); 905 ((OptionChar*)option)->values = value; 906 option->name = name; 907 option->numel = 1; 908 option->ndims = 1; 909 option->size = NULL; 910 break; 911 } 912 default: 913 _error_("Option of format %i not supported yet",code); 914 } 915 916 /*Assign output pointers: */ 917 *poption=option; 918 } 919 /*}}}*/ 869 920 /*FUNCTION IoModel::FetchData(int num,...){{{*/ 870 921 void IoModel::FetchData(int num,...){ … … 1097 1148 xfree((void**)&string); 1098 1149 } 1150 /*FUNCTION IoModel::LastIndex{{{*/ 1151 void IoModel::LastIndex(int *pindex){ 1152 1153 extern int my_rank; 1154 int lastindex,index; 1155 int record_length; 1156 1157 /*Go find in the binary file, the position of the data we want to fetch: */ 1158 if(my_rank==0){ 1159 1160 /*First set FILE* position to the beginning of the file: */ 1161 fseek(fid,0,SEEK_SET); 1162 1163 /*Now march through file looking for the correct data identifier: */ 1164 for(;;){ 1165 /*Read enum for this size of first string name: */ 1166 if(fread(&index,sizeof(int),1,fid)==0){ 1167 /*Ok, we have reached the end of the file. break: */ 1168 break; 1169 } 1170 1171 /*read the record length, and use it to skip this record: */ 1172 fread(&record_length,sizeof(int),1,fid); 1173 fseek(fid,record_length,SEEK_CUR); 1174 lastindex=index; 1175 } 1176 } 1177 /*Broadcast code and vector type: */ 1178 #ifdef _HAVE_MPI_ 1179 MPI_Bcast(&lastindex,1,MPI_INT,0,MPI_COMM_WORLD); 1180 #endif 1181 1182 /*Assign output pointers:*/ 1183 *pindex=lastindex; 1184 } 1099 1185 /*FUNCTION IoModel::SetFilePointerToData{{{*/ 1100 1186 FILE* IoModel::SetFilePointerToData(int* pcode,int* pvector_type, int data_enum){ … … 1102 1188 extern int my_rank; 1103 1189 extern int num_procs; 1104 1190 1105 1191 int found=0; 1106 1192 int record_enum; … … 1108 1194 int record_code; //1 to 7 number 1109 1195 int vector_type; //nodal or elementary 1110 1196 1111 1197 /*Go find in the binary file, the position of the data we want to fetch: */ 1112 1198 if(my_rank==0){ 1113 1199 1114 1200 /*First set FILE* position to the beginning of the file: */ 1115 1201 fseek(fid,0,SEEK_SET); … … 1123 1209 break; 1124 1210 } 1125 1211 1126 1212 /*Is this the record sought for? : */ 1127 1213 if (data_enum==record_enum){ … … 1143 1229 } 1144 1230 } 1145 1231 #ifdef _HAVE_MPI_ 1146 1232 MPI_Bcast(&found,1,MPI_INT,0,MPI_COMM_WORLD); 1147 1233 if(!found)_error_("%s %s ","could not find data with name",EnumToStringx(data_enum)); 1148 1234 #endif 1149 1235 1150 1236 /*Broadcast code and vector type: */ 1151 1237 #ifdef _HAVE_MPI_ 1152 1238 MPI_Bcast(&record_code,1,MPI_INT,0,MPI_COMM_WORLD); 1153 1239 MPI_Bcast(&vector_type,1,MPI_INT,0,MPI_COMM_WORLD); 1154 1240 if(record_code==5) MPI_Bcast(&vector_type,1,MPI_INT,0,MPI_COMM_WORLD); 1155 1241 #endif 1156 1242 1157 1243 /*Assign output pointers:*/ -
issm/trunk-jpl/src/c/objects/IoModel.h
r12377 r12382 13 13 class Elements; 14 14 class Param; 15 15 class Option; 16 16 17 17 class IoModel { … … 23 23 public: 24 24 /*This data needs to stay memory resident at all time, even if it's memory intensive: */ 25 FILE 25 FILE *fid; //pointer to input file 26 26 bool *my_elements; 27 27 bool *my_nodes; … … 41 41 42 42 /*Input/Output*/ 43 void CheckEnumSync(void);44 void Constant(bool*poutput,int constant_enum);45 void Constant(int*poutput,int constant_enum);46 void Constant(IssmDouble *poutput,int constant_enum);47 void Constant(char**poutput,int constant_enum);48 Param *CopyConstantObject(int constant_enum);43 void CheckEnumSync(void); 44 void Constant(bool *poutput,int constant_enum); 45 void Constant(int *poutput,int constant_enum); 46 void Constant(IssmDouble *poutput,int constant_enum); 47 void Constant(char **poutput,int constant_enum); 48 Param *CopyConstantObject(int constant_enum); 49 49 IssmDouble *Data(int dataenum); 50 void DeleteData(int num,...); 51 void FetchConstants(void); 52 void FetchData(bool* pboolean,int data_enum); 53 void FetchData(int* pinteger,int data_enum); 54 void FetchData(IssmDouble* pscalar,int data_enum); 55 void FetchData(char** pstring,int data_enum); 56 void FetchData(int** pmatrix,int* pM,int* pN,int data_enum); 57 void FetchData(IssmDouble** pscalarmatrix,int* pM,int* pN,int data_enum); 58 void FetchData(char*** pstringarray,int* pnumstrings,int data_enum); 59 void FetchData(IssmDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum); 60 void FetchData(int num,...); 61 void FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmDouble default_value=0); 62 FILE* SetFilePointerToData(int* pcode,int* pvector_type, int data_enum); 50 void DeleteData(int num,...); 51 void FetchConstants(void); 52 void FetchData(bool* pboolean,int data_enum); 53 void FetchData(int* pinteger,int data_enum); 54 void FetchData(IssmDouble* pscalar,int data_enum); 55 void FetchData(char** pstring,int data_enum); 56 void FetchData(int** pmatrix,int* pM,int* pN,int data_enum); 57 void FetchData(IssmDouble** pscalarmatrix,int* pM,int* pN,int data_enum); 58 void FetchData(char*** pstringarray,int* pnumstrings,int data_enum); 59 void FetchData(IssmDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum); 60 void FetchData(Option **poption,int data_enum); 61 void FetchData(int num,...); 62 void FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmDouble default_value=0); 63 void LastIndex(int *pindex); 64 FILE* SetFilePointerToData(int* pcode,int* pvector_type, int data_enum); 63 65 }; 64 66 -
issm/trunk-jpl/src/c/solutions/kriging.cpp
r12381 r12382 136 136 void ProcessInputfile(double **px,double **py,double **pdata,int *pnobs,double **px_interp,double **py_interp,int *pninterp,Options **poptions,FILE* fid){ 137 137 138 int ninterp,nobs ;138 int ninterp,nobs,numoptions; 139 139 double *x = NULL; 140 140 double *y = NULL; … … 143 143 double *y_interp = NULL; 144 144 Options *options = NULL; 145 Option *option = NULL; 145 146 146 147 int dummy,M,N; … … 148 149 iomodel->fid=fid; 149 150 iomodel->CheckEnumSync(); 150 151 /*Read x*/ 152 fid=iomodel->SetFilePointerToData(&dummy,&dummy,0); 153 if(my_rank==0){ 154 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 155 } 156 MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 157 if(my_rank==0){ 158 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 159 } 160 MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 161 if(M*N){ 162 x=(double*)xmalloc(M*N*sizeof(double)); 163 if(my_rank==0){ 164 if(fread(x,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix "); 165 } 166 MPI_Bcast(x,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 167 } 168 nobs=M*N; 169 170 /*Read y*/ 171 fid=iomodel->SetFilePointerToData(&dummy,&dummy,1); 172 if(my_rank==0){ 173 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 174 } 175 MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 176 if(my_rank==0){ 177 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 178 } 179 MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 180 if(M*N){ 181 y=(double*)xmalloc(M*N*sizeof(double)); 182 if(my_rank==0){ 183 if(fread(y,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix "); 184 } 185 MPI_Bcast(y,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 186 } 187 _assert_(M*N==nobs); 188 189 /*Read data*/ 190 fid=iomodel->SetFilePointerToData(&dummy,&dummy,2); 191 if(my_rank==0){ 192 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 193 } 194 MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 195 if(my_rank==0){ 196 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 197 } 198 MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 199 if(M*N){ 200 data=(double*)xmalloc(M*N*sizeof(double)); 201 if(my_rank==0){ 202 if(fread(data,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix "); 203 } 204 MPI_Bcast(data,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 205 } 206 _assert_(M*N==nobs); 207 208 /*Read x_interp*/ 209 fid=iomodel->SetFilePointerToData(&dummy,&dummy,3); 210 if(my_rank==0){ 211 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 212 } 213 MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 214 if(my_rank==0){ 215 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 216 } 217 MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 218 if(M*N){ 219 x_interp=(double*)xmalloc(M*N*sizeof(double)); 220 if(my_rank==0){ 221 if(fread(x_interp,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix "); 222 } 223 MPI_Bcast(x_interp,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 224 } 225 ninterp=N*M; 226 227 /*Read y_interp*/ 228 fid=iomodel->SetFilePointerToData(&dummy,&dummy,4); 229 if(my_rank==0){ 230 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 231 } 232 MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 233 if(my_rank==0){ 234 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 235 } 236 MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 237 if(M*N){ 238 y_interp=(double*)xmalloc(M*N*sizeof(double)); 239 if(my_rank==0){ 240 if(fread(y_interp,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix "); 241 } 242 MPI_Bcast(y_interp,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 243 } 244 _assert_(N*M==ninterp); 151 iomodel->FetchData(&x,&M,&N,0); nobs=M*N; 152 iomodel->FetchData(&y,&M,&N,1); _assert_(M*N==nobs); 153 iomodel->FetchData(&data,&M,&N,2); _assert_(M*N==nobs); 154 iomodel->FetchData(&x_interp,&M,&N,3); ninterp=M*N; 155 iomodel->FetchData(&y_interp,&M,&N,4); _assert_(M*N==ninterp); 245 156 246 157 /*Read options*/ 247 158 options = new Options(); 159 iomodel->LastIndex(&N); 160 numoptions=(int)((N-4)/2); 161 for(int i=0;i<numoptions;i++){ 162 iomodel->FetchData(&option,5+2*i); 163 options->AddOption(option); 164 option=NULL; 165 } 248 166 249 167 /*Assign output pointer*/
Note:
See TracChangeset
for help on using the changeset viewer.