Changeset 23767
- Timestamp:
- 03/06/19 15:19:25 (6 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/IoModel.cpp
r23657 r23767 1 1 /*! \file IoModel.cpp 2 * \brief file containing the methods that will help in processing the input data coming 2 * \brief file containing the methods that will help in processing the input data coming 3 3 * into ISSM, from Matlab, or through a binary file opened for reading. 4 4 */ … … 151 151 this->numberofverticalfaces=-1; 152 152 this->numberofedges=-1; 153 this->numberofverticaledges=-1; 154 this->numberofhorizontaledges=-1; 153 this->numberofverticaledges=-1; 154 this->numberofhorizontaledges=-1; 155 155 this->facescols=-1; 156 156 this->elements=NULL; … … 182 182 this->solution_enum = solution_enum_in; 183 183 184 /*If we are running in AD mode, we need to start the trace and declare our independent variables now, 185 *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and 184 /*If we are running in AD mode, we need to start the trace and declare our independent variables now, 185 *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and 186 186 iomodel->DeleteData:*/ 187 187 this->StartTrace(trace); … … 342 342 343 343 bool found; 344 int record_enum,record_length,record_name_size; 344 int record_enum,record_name_size; 345 long long record_length; 345 346 char *record_name = NULL; 346 347 const char *mddot = "md."; … … 392 393 393 394 /*Go to next Enum*/ 394 if(fread(&record_length,sizeof( int),1,fid)!=1) _error_("Could not read record_length");395 if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length"); 395 396 fseek(fid,record_length,SEEK_CUR); 396 397 xDelete<char>(record_name); … … 467 468 this->FetchData(&types,NULL,NULL,"md.autodiff.independent_object_types"); 468 469 469 /*create independent objects, and at the same time, fetch the corresponding independent variables, 470 /*create independent objects, and at the same time, fetch the corresponding independent variables, 470 471 *and declare them as such in ADOLC: */ 471 472 for(int i=0;i<num_independent_objects;i++){ … … 544 545 if(numstrings){ 545 546 for(int i=0;i<numstrings;i++){ 546 char* string=stringarray[i]; 547 char* string=stringarray[i]; 547 548 xDelete<char>(string); 548 549 } … … 557 558 char* record_name = NULL; 558 559 int record_name_size; 559 intrecord_length;560 long long record_length; 560 561 int record_code; //1 to 7 number 561 562 … … 608 609 609 610 /* Read the record length and the data type code: */ 610 if(fread(&record_length,sizeof( int),1,this->fid)!=1) _error_("Cound not read record_length");611 if(fread(&record_length,sizeof(long long),1,this->fid)!=1) _error_("Cound not read record_length"); 611 612 if(fread(&record_code ,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_code"); 612 613 … … 615 616 616 617 /*Tell other cpus the name of the data, then branch according to the data type: */ 617 ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 618 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 619 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_ INT,0,IssmComm::GetComm());618 ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 619 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 620 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm()); 620 621 621 622 switch(record_code){ 622 case 1: 623 case 1: 623 624 /*Read the boolean and broadcast it to other cpus:*/ 624 625 if(fread(&booleanint,sizeof(int),1,this->fid)!=1) _error_("could not read boolean "); 625 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 626 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 626 627 627 628 /*create BoolParam: */ … … 644 645 645 646 /*Broadcast to other cpus*/ 646 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 647 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 647 648 648 649 /*create IntParam: */ … … 664 665 if(!exists){ 665 666 if(fread(&pscalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar "); 666 ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 667 ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 667 668 scalar=pscalar; 668 669 … … 672 673 } 673 674 break; 674 case 4: 675 case 4: 675 676 /*We have to read a string from disk. First read the dimensions of the string, then the string: */ 676 677 if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string "); 677 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 678 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 678 679 679 680 if(string_size){ … … 683 684 /*Read string, then broadcast: */ 684 685 if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string "); 685 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 686 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 686 687 } 687 688 else{ … … 724 725 xDelete<char>(string); 725 726 break; 726 case 5: 727 case 6: 728 case 7: 729 case 8: 727 case 5: 728 case 6: 729 case 7: 730 case 8: 730 731 case 10: 731 732 /*We are not interested in this record, too memory intensive. Skip it: */ … … 734 735 fseek(fid,record_length,SEEK_CUR); 735 736 break; 736 case 9: 737 case 9: 737 738 /*String Array*/ 738 739 if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array"); 739 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 740 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 740 741 /*Now allocate string array: */ 741 742 if(numstrings){ … … 747 748 748 749 if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string "); 749 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 750 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 750 751 if(string_size){ 751 752 string=xNew<char>((string_size+1)); 752 753 string[string_size]='\0'; 753 754 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 754 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 755 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 755 756 } 756 757 else{ … … 769 770 xDelete<char*>(strings); 770 771 break; 771 default: 772 _error_("unknown record type:" << record_code); 772 default: 773 _error_("unknown record type:" << record_code); 773 774 break; 774 775 } … … 786 787 _assert_(record_name_size); 787 788 record_name=xNew<char>((record_name_size+1)); record_name[record_name_size]='\0'; 788 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 789 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_ INT,0,IssmComm::GetComm());789 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 790 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm()); 790 791 switch(record_code){ 791 case 1: 792 case 1: 792 793 /*boolean. get it from cpu 0 */ 793 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 794 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 794 795 795 796 /*create BoolParam: */ … … 799 800 case 2: 800 801 /*integer. get it from cpu 0 */ 801 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 802 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 802 803 803 804 /*create IntParam: */ … … 825 826 } 826 827 break; 827 case 4: 828 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 828 case 4: 829 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 829 830 if(string_size){ 830 831 string=xNew<char>((string_size+1)); … … 832 833 833 834 /*Read string from cpu 0: */ 834 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 835 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 835 836 } 836 837 else{ … … 879 880 case 10: break; //do nothing. not interested in this type of data, which is memory intensive. 880 881 case 9: 881 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 882 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 882 883 /*Now allocate string array: */ 883 884 if(numstrings){ … … 888 889 for(int i=0;i<numstrings;i++){ 889 890 890 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 891 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 891 892 if(string_size){ 892 893 string=xNew<char>((string_size+1)); 893 894 string[string_size]='\0'; 894 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 895 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 895 896 } 896 897 else{ … … 909 910 xDelete<char*>(strings); 910 911 break; 911 default: 912 _error_("unknown record type:" << record_code); 912 default: 913 _error_("unknown record type:" << record_code); 913 914 break; 914 915 } … … 933 934 934 935 /*We have to read a boolean from disk. */ 935 if(my_rank==0){ 936 if(my_rank==0){ 936 937 if(fread(&booleanint,sizeof(int),1,fid)!=1) _error_("could not read boolean "); 937 938 } 938 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 939 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 939 940 940 941 /*cast to bool: */ … … 959 960 960 961 /*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */ 961 if(my_rank==0){ 962 if(my_rank==0){ 962 963 if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer "); 963 964 } 964 965 965 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 966 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 966 967 967 968 /*Assign output pointers: */ … … 987 988 if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar "); 988 989 } 989 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 990 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 990 991 991 992 /*Assign output pointers: */ … … 1012 1013 1013 1014 /*We have to read a string from disk. First read the dimensions of the string, then the string: */ 1014 if(my_rank==0){ 1015 if(my_rank==0){ 1015 1016 if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string "); 1016 1017 } 1017 1018 1018 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1019 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1019 1020 1020 1021 /*Now allocate string: */ … … 1024 1025 1025 1026 /*Read string on node 0, then broadcast: */ 1026 if(my_rank==0){ 1027 if(my_rank==0){ 1027 1028 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 1028 1029 } 1029 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1030 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1030 1031 } 1031 1032 else{ … … 1057 1058 /*Now fetch: */ 1058 1059 1059 if(my_rank==0){ 1060 if(my_rank==0){ 1060 1061 if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array"); 1061 1062 } 1062 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1063 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1063 1064 1064 1065 /*Now allocate string array: */ … … 1070 1071 for(int i=0;i<numstrings;i++){ 1071 1072 1072 if(my_rank==0){ 1073 if(my_rank==0){ 1073 1074 if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string "); 1074 1075 } 1075 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1076 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1076 1077 if(string_size){ 1077 1078 string=xNew<char>((string_size+1)); 1078 1079 string[string_size]='\0'; 1079 if(my_rank==0){ 1080 if(my_rank==0){ 1080 1081 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 1081 1082 } 1082 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1083 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1083 1084 } 1084 1085 else{ … … 1116 1117 /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */ 1117 1118 /*numberofelements: */ 1118 if(my_rank==0){ 1119 if(my_rank==0){ 1119 1120 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 1120 1121 } 1121 1122 1122 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1123 1124 if(my_rank==0){ 1123 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1124 1125 if(my_rank==0){ 1125 1126 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 1126 1127 } … … 1132 1133 1133 1134 /*Read matrix on node 0, then broadcast: */ 1134 if(my_rank==0){ 1135 if(my_rank==0){ 1135 1136 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1136 1137 } 1137 1138 1138 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1139 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1139 1140 } 1140 1141 … … 1194 1195 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 1195 1196 } 1196 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1197 1198 if(my_rank==0){ 1197 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1198 1199 if(my_rank==0){ 1199 1200 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 1200 1201 } 1201 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1202 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1202 1203 1203 1204 /*Now allocate matrix: */ … … 1207 1208 IssmPDouble offset,range; 1208 1209 if(my_rank==0) if(fread(&offset,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read offset"); 1209 ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1210 ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1210 1211 1211 1212 if(my_rank==0) if(fread(&range,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read range"); 1212 ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1213 ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1213 1214 1214 1215 *pmatrix=xNew<IssmDouble>(M*N); … … 1217 1218 uint8_t* rawmatrix=xNew<uint8_t>((M-1)*N); 1218 1219 if(my_rank==0) if(fread(rawmatrix,(M-1)*N*sizeof(char),1,fid)!=1) _error_("could not read matrix "); 1219 ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1220 ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1220 1221 1221 1222 for(int i=0;i<(M-1)*N;++i) (*pmatrix)[i]=offset+range*reCast<IssmDouble>(rawmatrix[i])/255.; … … 1225 1226 IssmPDouble* timematrix=xNew<IssmPDouble>(N); 1226 1227 if(my_rank==0) if(fread(timematrix,N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read time in compressed matrix"); 1227 ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1228 ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1228 1229 1229 1230 for(int i=0;i<N;++i) (*pmatrix)[(M-1)*N+i]=timematrix[i]; … … 1235 1236 matrix=xNew<IssmPDouble>(M*N); 1236 1237 if(my_rank==0) if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1237 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1238 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1238 1239 1239 1240 *pmatrix=xNew<IssmDouble>(M*N); … … 1272 1273 1273 1274 /*Now fetch: */ 1274 if(my_rank==0){ 1275 if(my_rank==0){ 1275 1276 if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array "); 1276 1277 } 1277 ISSM_MPI_Bcast(&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1278 ISSM_MPI_Bcast(&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1278 1279 1279 1280 if(numrecords){ … … 1293 1294 for(i=0;i<numrecords;i++){ 1294 1295 1295 if(my_rank==0){ 1296 if(my_rank==0){ 1296 1297 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows in " << i << "th matrix of matrix array"); 1297 1298 } 1298 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1299 1300 if(my_rank==0){ 1299 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1300 1301 if(my_rank==0){ 1301 1302 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns in " << i << "th matrix of matrix array"); 1302 1303 } 1303 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1304 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1304 1305 1305 1306 /*Now allocate matrix: */ … … 1308 1309 1309 1310 /*Read matrix on node 0, then broadcast: */ 1310 if(my_rank==0){ 1311 if(my_rank==0){ 1311 1312 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1312 1313 } 1313 1314 1314 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1315 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1315 1316 matrices[i]=xNew<IssmDouble>(M*N); 1316 1317 for (int j=0;j<M*N;++j) {matrices[i][j]=matrix[j];} … … 1338 1339 char* record_name = NULL; 1339 1340 int record_name_size; 1340 intrecord_length;1341 int record_code; 1341 long long record_length; 1342 int record_code; 1342 1343 1343 1344 /*records: */ … … 1367 1368 /*Is this the record sought for? : */ 1368 1369 if(strcmp(record_name,lastnonoption)==0){ 1369 if(fread(&record_length,sizeof( int),1,fid)!=1) _error_("Could not read record_length");1370 if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length"); 1370 1371 fseek(fid,record_length,SEEK_CUR); 1371 1372 xDelete<char>(record_name); … … 1373 1374 } 1374 1375 else{ 1375 if(fread(&record_length,sizeof( int),1,fid)!=1) _error_("Could not read record_length");1376 if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length"); 1376 1377 fseek(fid,record_length,SEEK_CUR); 1377 1378 xDelete<char>(record_name); … … 1416 1417 1417 1418 /* Read the record length and the data type code: */ 1418 if(fread(&record_length,sizeof( int),1,this->fid)!=1) _error_("Cound not read record_length");1419 if(fread(&record_length,sizeof(long long),1,this->fid)!=1) _error_("Cound not read record_length"); 1419 1420 if(fread(&record_code ,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_code"); 1420 1421 … … 1423 1424 1424 1425 /*Tell other cpus the name of the data, then branch according to the data type: */ 1425 ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1426 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1427 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_ INT,0,IssmComm::GetComm());1426 ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1427 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1428 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm()); 1428 1429 1429 1430 switch(record_code){ … … 1431 1432 { 1432 1433 if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar "); 1433 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1434 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1434 1435 GenericOption<IssmDouble>* option = new GenericOption<IssmDouble>(); 1435 1436 char* optionname=xNew<char>(strlen(record_name)-3+1); … … 1442 1443 } 1443 1444 break; 1444 case 4: 1445 case 4: 1445 1446 { 1446 1447 /*We have to read a string from disk. First read the dimensions of the string, then the string: */ 1447 1448 if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string "); 1448 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1449 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1449 1450 1450 1451 if(string_size){ … … 1454 1455 /*Read string, then broadcast: */ 1455 1456 if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string "); 1456 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1457 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1457 1458 } 1458 1459 else{ … … 1473 1474 } 1474 1475 break; 1475 default: 1476 _error_("record type not supported:" << record_code); 1476 default: 1477 _error_("record type not supported:" << record_code); 1477 1478 break; 1478 1479 } … … 1490 1491 _assert_(record_name_size); 1491 1492 record_name=xNew<char>((record_name_size+1)); record_name[record_name_size]='\0'; 1492 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1493 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_ INT,0,IssmComm::GetComm());1493 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1494 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm()); 1494 1495 switch(record_code){ 1495 1496 case 3: 1496 1497 { 1497 1498 if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar "); 1498 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1499 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1499 1500 char* optionname=xNew<char>(strlen(record_name)-3+1); 1500 1501 xMemCpy(optionname,&record_name[3],strlen(record_name)-3+1); … … 1507 1508 } 1508 1509 break; 1509 case 4: 1510 case 4: 1510 1511 { 1511 1512 /*We have to read a string from disk. First read the dimensions of the string, then the string: */ 1512 1513 if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string "); 1513 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1514 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1514 1515 1515 1516 if(string_size){ … … 1519 1520 /*Read string, then broadcast: */ 1520 1521 if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string "); 1521 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1522 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1522 1523 } 1523 1524 else{ … … 1537 1538 } 1538 1539 break; 1539 default: 1540 _error_("record type not supported:" << record_code); 1540 default: 1541 _error_("record type not supported:" << record_code); 1541 1542 break; 1542 1543 } … … 1625 1626 for(int i=0;i<elements->Size();i++){ 1626 1627 Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i)); 1627 if(!doublearray) element->AddInput(input_enum,&default_value,P0Enum); 1628 if(!doublearray) element->AddInput(input_enum,&default_value,P0Enum); 1628 1629 else element->InputCreate(doublearray,this,M,N,vector_layout,input_enum,code);//we need i to index into elements. 1629 1630 } … … 1684 1685 element->InputUpdateFromConstant(scalar,input_enum); 1685 1686 } 1686 break; 1687 break; 1687 1688 case 5: //boolean vector 1688 1689 this->FetchData(&doublearray,&M,&N,vector_name); //we still have a doublearray, because it might include times in transient mode … … 1743 1744 if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar "); 1744 1745 1745 /*Now, before we even broadcast this to other nodes, declare the scalar as an independent variable!. If we 1746 /*Now, before we even broadcast this to other nodes, declare the scalar as an independent variable!. If we 1746 1747 *have been supplied an X vector, use it instead of what we just read: */ 1747 1748 #if defined(_HAVE_CODIPACK_) … … 1765 1766 } 1766 1767 1767 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 1768 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 1768 1769 this->AddConstantIndependent(new IoConstant(scalar,constant_name)); 1769 1770 … … 1796 1797 /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */ 1797 1798 /*numberofelements: */ 1798 if(my_rank==0){ 1799 if(my_rank==0){ 1799 1800 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 1800 1801 } 1801 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1802 1803 if(my_rank==0){ 1802 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1803 1804 if(my_rank==0){ 1804 1805 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 1805 1806 } 1806 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1807 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1807 1808 1808 1809 /*Now allocate matrix: */ … … 1818 1819 1819 1820 /*Read matrix on node 0, then broadcast: */ 1820 if(my_rank==0){ 1821 if(my_rank==0){ 1821 1822 if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1822 1823 … … 1849 1850 #endif 1850 1851 } 1851 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 1852 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 1852 1853 1853 1854 xDelete<IssmPDouble>(buffer); … … 1856 1857 1857 1858 // FIXME codi is that at all relevant to CoDiPack or can we simply assume the same? 1858 1859 1859 1860 /*Add to data as independent*/ 1860 1861 this->AddDataIndependent(new IoData(matrix,code,layout,M,N,data_name)); … … 1893 1894 if(my_rank==0){ 1894 1895 /*check we are indeed finding a string, not something else: */ 1895 if(codes[i]!=4)_error_("expecting a string for \""<<data_name<<"\" ");1896 if(codes[i]!=4)_error_("expecting a string for \""<<data_name<<"\" but code is "<<codes[i]<<" not 4"); 1896 1897 1897 1898 /*We have to read a string from disk. First read the dimensions of the string, then the string: */ … … 1900 1901 } 1901 1902 1902 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1903 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1903 1904 1904 1905 /*Now allocate string: */ … … 1911 1912 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 1912 1913 } 1913 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1914 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1914 1915 } 1915 1916 else{ … … 1962 1963 /*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */ 1963 1964 fsetpos(fid,file_positions+i); 1964 if(my_rank==0){ 1965 if(my_rank==0){ 1965 1966 if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer "); 1966 1967 } 1967 1968 } 1968 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1969 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 1969 1970 1970 1971 /*Assign: */ … … 2015 2016 /*We have to read a double from disk: */ 2016 2017 fsetpos(fid,file_positions+i); 2017 if(my_rank==0){ 2018 if(my_rank==0){ 2018 2019 if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read scalar "); 2019 2020 } 2020 2021 } 2021 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 2022 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 2022 2023 2023 2024 /*Assign: */ … … 2077 2078 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 2078 2079 } 2079 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2080 2081 if(my_rank==0){ 2080 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2081 2082 if(my_rank==0){ 2082 2083 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 2083 2084 } 2084 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2085 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2085 2086 2086 2087 /*Now allocate matrix: */ … … 2089 2090 2090 2091 /*Read matrix on node 0, then broadcast: */ 2091 if(my_rank==0){ 2092 if(my_rank==0){ 2092 2093 if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 2093 2094 } 2094 ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 2095 ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 2095 2096 2096 2097 //if(this->independents[data_enum]){ FIXME 2097 // /*this data has already been checked out! So cancel all that we've done here, and return 2098 // /*this data has already been checked out! So cancel all that we've done here, and return 2098 2099 // * the data[data_enum] directly: */ 2099 2100 // matrix=this->data[data_enum]; … … 2179 2180 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 2180 2181 } 2181 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2182 2183 if(my_rank==0){ 2182 ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2183 2184 if(my_rank==0){ 2184 2185 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 2185 2186 } 2186 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2187 ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2187 2188 2188 2189 /*Now allocate matrix: */ … … 2192 2193 2193 2194 /*Read matrix on node 0, then broadcast: */ 2194 if(my_rank==0){ 2195 if(my_rank==0){ 2195 2196 if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 2196 2197 } 2197 ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 2198 ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 2198 2199 2199 2200 //if(this->independents[data_enum]){ FIXME 2200 // /*this data has already been checked out! So cancel all that we've done here, and return 2201 // /*this data has already been checked out! So cancel all that we've done here, and return 2201 2202 // * the data[data_enum] directly: */ 2202 2203 // matrix=this->data[data_enum]; … … 2382 2383 char* record_name = NULL; 2383 2384 int record_name_size; 2384 intrecord_length;2385 long long record_length; 2385 2386 int record_code; //1 to 7 number 2386 2387 int vector_type; //1 to 7 number … … 2395 2396 _assert_(strncmp(data_name,mddot,3)==0); 2396 2397 2397 /*Go find in the binary file, the data we want to fetch and count the number of 2398 /*Go find in the binary file, the data we want to fetch and count the number of 2398 2399 * instances it appears: */ 2399 2400 if(my_rank==0){ … … 2430 2431 2431 2432 /*Read the record length, and use it to skip the record: */ 2432 if(fread(&record_length,sizeof( int),1,fid)!=1) _error_("Could not read record_length");2433 if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length"); 2433 2434 fseek(fid,record_length,SEEK_CUR); 2434 2435 xDelete<char>(record_name); … … 2442 2443 } 2443 2444 2444 /*Reset FILE* position to the beginning of the file, and start again, this time saving the data information 2445 /*Reset FILE* position to the beginning of the file, and start again, this time saving the data information 2445 2446 * as we find it: */ 2446 2447 counter=0; … … 2474 2475 if(strcmp(record_name,data_name)==0){ 2475 2476 /*Ok, we have found the correct string. Pass the record length, and read data type code: */ 2476 fseek(fid,sizeof( int),SEEK_CUR);2477 fseek(fid,sizeof(long long),SEEK_CUR); 2477 2478 if(fread(&record_code,sizeof(int),1,fid)!=1) _error_("Could not read record_code"); 2478 2479 … … 2486 2487 2487 2488 /*backup and skip over the record, as we have more work to do: */ 2488 if(5<=record_code && record_code<=7) fseek(fid,-sizeof(int),SEEK_CUR); 2489 fseek(fid,-sizeof(int),SEEK_CUR); 2490 fseek(fid,-sizeof( int),SEEK_CUR);2489 if(5<=record_code && record_code<=7) fseek(fid,-sizeof(int),SEEK_CUR); /*rewind for nodal or elementary type*/ 2490 fseek(fid,-sizeof(int),SEEK_CUR);/*rewind for data code*/ 2491 fseek(fid,-sizeof(long long),SEEK_CUR);/*rewind for record length*/ 2491 2492 2492 2493 /*increment counter: */ … … 2495 2496 2496 2497 /*Read the record length, and use it to skip this record, as it has already been processed: */ 2497 if(fread(&record_length,sizeof( int),1,fid)!=1) _error_("Could not read record_length");2498 if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length"); 2498 2499 /*skip: */ 2499 2500 fseek(fid,record_length,SEEK_CUR); … … 2503 2504 2504 2505 /*Broadcast data: */ 2505 ISSM_MPI_Bcast(&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2506 ISSM_MPI_Bcast(&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2506 2507 2507 2508 /*Assign output pointers:*/ … … 2525 2526 char* record_name = NULL; 2526 2527 int record_name_size; 2527 intrecord_length;2528 long long record_length; 2528 2529 int record_code; //1 to 7 number 2529 2530 int vector_type = 0; //nodal or elementary … … 2571 2572 if(strcmp(record_name,data_name)==0){ 2572 2573 /*Ok, we have found the correct string. Pass the record length, and read data type code: */ 2573 fseek(fid,sizeof( int),SEEK_CUR);2574 fseek(fid,sizeof(long long),SEEK_CUR); 2574 2575 if(fread(&record_code,sizeof(int),1,fid)!=1) _error_("Could not read record_code"); 2575 2576 2576 /*if record_code points to a vector, get its type (nodal or elementary): */ 2577 2577 if((5<=record_code && record_code<=7) || record_code==10){ … … 2584 2584 else{ 2585 2585 /*This is not the correct string, read the record length, and use it to skip this record: */ 2586 if(fread(&record_length,sizeof( int),1,fid)!=1) _error_("Could not read record_length");2586 if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length"); 2587 2587 /*skip: */ 2588 2588 fseek(fid,record_length,SEEK_CUR); … … 2591 2591 } 2592 2592 } 2593 ISSM_MPI_Bcast(&found,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2593 ISSM_MPI_Bcast(&found,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2594 2594 if(!found)_error_("could not find data with name \"" << data_name << "\" in binary file"); 2595 2595 2596 2596 /*Broadcast code and vector type: */ 2597 ISSM_MPI_Bcast(&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2598 ISSM_MPI_Bcast(&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2597 ISSM_MPI_Bcast(&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2598 ISSM_MPI_Bcast(&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 2599 2599 2600 2600 /*Assign output pointers:*/ -
issm/trunk-jpl/src/m/solve/WriteData.m
r21704 r23767 47 47 48 48 %Step 1: write the name to identify this record uniquely 49 fwrite(fid,numel(name),'int'); 50 fwrite(fid,name,'char'); 49 fwrite(fid,numel(name),'int'); 50 fwrite(fid,name,'char'); 51 51 52 52 %Step 2: write the data itself. … … 55 55 56 56 %first write length of record 57 fwrite(fid,4+4,'int '); %1 bool (disguised as an int)+code58 59 %write data code: 60 fwrite(fid,FormatToCode(format),'int'); 57 fwrite(fid,4+4,'int64'); %1 bool (disguised as an int)+code 58 59 %write data code: 60 fwrite(fid,FormatToCode(format),'int'); 61 61 62 62 %now write integer … … 67 67 68 68 %first write length of record 69 fwrite(fid,4+4,'int '); %1 integer + code70 71 %write data code: 72 fwrite(fid,FormatToCode(format),'int'); 69 fwrite(fid,4+4,'int64'); %1 integer + code 70 71 %write data code: 72 fwrite(fid,FormatToCode(format),'int'); 73 73 74 74 %now write integer 75 fwrite(fid,data,'int'); 75 fwrite(fid,data,'int'); 76 76 % }}} 77 77 elseif strcmpi(format,'Double'), % {{{ … … 79 79 80 80 %first write length of record 81 fwrite(fid,8+4,'int '); %1 double+code82 83 %write data code: 84 fwrite(fid,FormatToCode(format),'int'); 81 fwrite(fid,8+4,'int64'); %1 double+code 82 83 %write data code: 84 fwrite(fid,FormatToCode(format),'int'); 85 85 86 86 %now write double 87 fwrite(fid,data,'double'); 87 fwrite(fid,data,'double'); 88 88 % }}} 89 89 elseif strcmpi(format,'String'), % {{{ 90 90 %first write length of record 91 fwrite(fid,length(data)+4+4,'int '); %string + string size + code92 93 %write data code: 94 fwrite(fid,FormatToCode(format),'int'); 91 fwrite(fid,length(data)+4+4,'int64'); %string + string size + code 92 93 %write data code: 94 fwrite(fid,FormatToCode(format),'int'); 95 95 96 96 %now write string 97 fwrite(fid,length(data),'int'); 98 fwrite(fid,data,'char'); 97 fwrite(fid,length(data),'int'); 98 fwrite(fid,data,'char'); 99 99 % }}} 100 100 elseif strcmpi(format,'BooleanMat'), % {{{ … … 108 108 109 109 %first write length of record 110 fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int '); %2 integers (32 bits) + the double matrix + code + matrix type111 112 %write data code and matrix type: 113 fwrite(fid,FormatToCode(format),'int'); 110 fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int64'); %2 integers (32 bits) + the double matrix + code + matrix type 111 112 %write data code and matrix type: 113 fwrite(fid,FormatToCode(format),'int'); 114 114 fwrite(fid,mattype,'int'); 115 115 116 116 %now write matrix 117 fwrite(fid,s(1),'int'); 118 fwrite(fid,s(2),'int'); 117 fwrite(fid,s(1),'int'); 118 fwrite(fid,s(2),'int'); 119 119 if s(1)*s(2), 120 120 fwrite(fid,data','double'); %get to the "c" convention, hence the transpose … … 131 131 132 132 %first write length of record 133 fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int '); %2 integers (32 bits) + the double matrix + code + matrix type134 135 %write data code and matrix type: 136 fwrite(fid,FormatToCode(format),'int'); 133 fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int64'); %2 integers (32 bits) + the double matrix + code + matrix type 134 135 %write data code and matrix type: 136 fwrite(fid,FormatToCode(format),'int'); 137 137 fwrite(fid,mattype,'int'); 138 138 139 139 %now write matrix 140 fwrite(fid,s(1),'int'); 141 fwrite(fid,s(2),'int'); 140 fwrite(fid,s(1),'int'); 141 fwrite(fid,s(2),'int'); 142 142 if s(1)*s(2), 143 143 fwrite(fid,data','double'); %get to the "c" convention, hence the transpose … … 155 155 %first write length of record 156 156 recordlength=4+4+8*s(1)*s(2)+4+4; %2 integers (32 bits) + the double matrix + code + matrix type 157 if recordlength>2^ 31; error(['field ' name ' cannot be marshalled because it is larger than 2^31bytes!']); end158 fwrite(fid,recordlength,'int ');159 160 %write data code and matrix type: 161 fwrite(fid,FormatToCode(format),'int'); 157 if recordlength>2^63; error(['field ' name ' cannot be marshalled because it is larger than 2^63 bytes!']); end 158 fwrite(fid,recordlength,'int64'); 159 160 %write data code and matrix type: 161 fwrite(fid,FormatToCode(format),'int'); 162 162 fwrite(fid,mattype,'int'); 163 163 164 164 %now write matrix 165 fwrite(fid,s(1),'int'); 166 fwrite(fid,s(2),'int'); 165 fwrite(fid,s(1),'int'); 166 fwrite(fid,s(2),'int'); 167 167 if s(1)*s(2), 168 168 fwrite(fid,data','double'); %get to the "c" convention, hence the transpose … … 180 180 %first write length of record 181 181 recordlength=4+4+8+8+1*(s(1)-1)*s(2)+8*s(2)+4+4; %2 integers (32 bits) + the matrix + code + matrix type 182 if recordlength>2^ 31; error(['field ' name ' cannot be marshalled because it is larger than 2^31bytes!']); end183 fwrite(fid,recordlength,'int ');184 185 %write data code and matrix type: 186 fwrite(fid,FormatToCode(format),'int'); 182 if recordlength>2^63; error(['field ' name ' cannot be marshalled because it is larger than 2^63 bytes!']); end 183 fwrite(fid,recordlength,'int64'); 184 185 %write data code and matrix type: 186 fwrite(fid,FormatToCode(format),'int'); 187 187 fwrite(fid,mattype,'int'); 188 188 189 189 %write matrix size 190 fwrite(fid,s(1),'int'); 191 fwrite(fid,s(2),'int'); 190 fwrite(fid,s(1),'int'); 191 fwrite(fid,s(2),'int'); 192 192 193 193 if s(1)*s(2), … … 205 205 206 206 %Write last row as double (time) 207 fwrite(fid,data(end,:),'double'); 207 fwrite(fid,data(end,:),'double'); 208 208 else 209 209 … … 227 227 228 228 %write length of record 229 fwrite(fid,recordlength,'int ');230 231 %write data code: 232 fwrite(fid,FormatToCode(format),'int'); 229 fwrite(fid,recordlength,'int64'); 230 231 %write data code: 232 fwrite(fid,FormatToCode(format),'int'); 233 233 234 234 %write data, first number of records 235 fwrite(fid,numrecords,'int'); 236 237 %write each matrix: 235 fwrite(fid,numrecords,'int'); 236 237 %write each matrix: 238 238 for i=1:numrecords, 239 239 matrix=data{i}; 240 240 s=size(matrix); 241 fwrite(fid,s(1),'int'); 242 fwrite(fid,s(2),'int'); 241 fwrite(fid,s(1),'int'); 242 fwrite(fid,s(2),'int'); 243 243 fwrite(fid,matrix','double'); 244 244 end … … 246 246 elseif strcmpi(format,'StringArray'), % {{{ 247 247 248 %first get length of string array: 248 %first get length of string array: 249 249 num=numel(data); 250 250 if isnumeric(data) & num==1 & isnan(data), … … 252 252 end 253 253 254 %now get length of record: 254 %now get length of record: 255 255 recordlength=4+4; %for length of array + code 256 256 for i=1:num, … … 260 260 261 261 %write length of record 262 fwrite(fid,recordlength,'int ');263 264 %write data code: 265 fwrite(fid,FormatToCode(format),'int'); 262 fwrite(fid,recordlength,'int64'); 263 264 %write data code: 265 fwrite(fid,FormatToCode(format),'int'); 266 266 267 267 %now write length of string array 268 fwrite(fid,num,'int'); 268 fwrite(fid,num,'int'); 269 269 270 270 %now write the strings 271 271 for i=1:num, 272 272 string=data{i}; 273 fwrite(fid,length(string),'int'); 274 fwrite(fid,string,'char'); 273 fwrite(fid,length(string),'int'); 274 fwrite(fid,string,'char'); 275 275 end 276 276 % }}} … … 281 281 282 282 function code=FormatToCode(format) % {{{ 283 %This routine takes the format string, and hardcodes it into an integer, which 284 %is passed along the record, in order to identify the nature of the dataset being 283 %This routine takes the format string, and hardcodes it into an integer, which 284 %is passed along the record, in order to identify the nature of the dataset being 285 285 %sent. 286 286 if strcmpi(format,'Boolean'), 287 287 code=1; 288 elseif strcmpi(format,'Integer'), 288 elseif strcmpi(format,'Integer'), 289 289 code=2; 290 elseif strcmpi(format,'Double'), 290 elseif strcmpi(format,'Double'), 291 291 code=3; 292 elseif strcmpi(format,'String'), 292 elseif strcmpi(format,'String'), 293 293 code=4; 294 294 elseif strcmpi(format,'BooleanMat'), … … 298 298 elseif strcmpi(format,'DoubleMat'), 299 299 code=7; 300 elseif strcmpi(format,'MatArray'), 300 elseif strcmpi(format,'MatArray'), 301 301 code=8; 302 302 elseif strcmpi(format,'StringArray'), … … 304 304 elseif strcmpi(format,'CompressedMat'), 305 305 code=10; 306 else 306 else 307 307 error('FormatToCode error message: data type not supported yet!'); 308 308 end
Note:
See TracChangeset
for help on using the changeset viewer.