Changeset 21668
- Timestamp:
- 04/12/17 15:49:49 (8 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/IoModel.cpp
r21615 r21668 683 683 case 7: 684 684 case 8: 685 case 10: 685 686 /*We are not interested in this record, too memory intensive. Skip it: */ 686 687 /*skip: */ … … 825 826 case 7: break; //do nothing. not interested in this type of data, which is memory intensive. 826 827 case 8: break; //do nothing. not interested in this type of data, which is memory intensive. 828 case 10: break; //do nothing. not interested in this type of data, which is memory intensive. 827 829 case 9: 828 830 ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); … … 1132 1134 /*Set file pointer to beginning of the data: */ 1133 1135 fid=this->SetFilePointerToData(&code,NULL,data_name); 1134 if(code!=5 && code!=6 && code!=7 )_error_("expecting a IssmDouble, integer or boolean matrix for \""<<data_name<<"\""<<" (Code is "<<code<<")");1136 if(code!=5 && code!=6 && code!=7 && code!=10)_error_("expecting a IssmDouble, integer or boolean matrix for \""<<data_name<<"\""<<" (Code is "<<code<<")"); 1135 1137 1136 1138 /*Now fetch: */ … … 1150 1152 /*Now allocate matrix: */ 1151 1153 if(M*N){ 1152 matrix=xNew<IssmPDouble>(M*N); 1153 1154 /*Read matrix on node 0, then broadcast: */ 1155 if(my_rank==0){ 1156 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1157 } 1158 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1159 1160 *pmatrix=xNew<IssmDouble>(M*N); 1161 for(int i=0;i<M*N;++i) (*pmatrix)[i]=matrix[i]; 1162 xDelete<IssmPDouble>(matrix); 1163 } 1164 else 1165 *pmatrix=NULL; 1154 if(code==10){ 1155 /*Special case for Compressed mat*/ 1156 IssmPDouble offset,range; 1157 if(my_rank==0) if(fread(&offset,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read offset"); 1158 ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1159 1160 if(my_rank==0) if(fread(&range,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read range"); 1161 ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1162 1163 *pmatrix=xNew<IssmDouble>(M*N); 1164 1165 /*Read matrix*/ 1166 uint8_t* rawmatrix=xNew<uint8_t>((M-1)*N); 1167 if(my_rank==0) if(fread(rawmatrix,(M-1)*N*sizeof(char),1,fid)!=1) _error_("could not read matrix "); 1168 ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 1169 1170 for(int i=0;i<(M-1)*N;++i) (*pmatrix)[i]=offset+range*reCast<IssmDouble>(rawmatrix[i])/255.; 1171 xDelete<uint8_t>(rawmatrix); 1172 1173 /*read time now*/ 1174 IssmPDouble* timematrix=xNew<IssmDouble>(N); 1175 if(my_rank==0) if(fread(timematrix,N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read time in compressed matrix"); 1176 ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1177 1178 for(int i=0;i<N;++i) (*pmatrix)[(M-1)*N+i]=timematrix[i]; 1179 xDelete<IssmPDouble>(timematrix); 1180 1181 } 1182 else{ 1183 /*Read matrix on node 0, then broadcast: */ 1184 matrix=xNew<IssmPDouble>(M*N); 1185 if(my_rank==0) if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1186 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 1187 1188 *pmatrix=xNew<IssmDouble>(M*N); 1189 for(int i=0;i<M*N;++i) (*pmatrix)[i]=matrix[i]; 1190 xDelete<IssmPDouble>(matrix); 1191 } 1192 } 1193 else{ 1194 *pmatrix=NULL; 1195 } 1166 1196 /*Assign output pointers: */ 1167 1197 if(pM) *pM=M; … … 1542 1572 1543 1573 /*Defaulting only supported for double arrays*/ 1544 if(code!=7 ) _error_(vector_name<<" is not a double array");1574 if(code!=7 && code!=10) _error_(vector_name<<" is not a double array"); 1545 1575 1546 1576 this->FetchData(&doublearray,&M,&N,vector_name); … … 2466 2496 2467 2497 /*if record_code points to a vector, get its type (nodal or elementary): */ 2468 if( 5<=record_code && record_code<=7){2498 if((5<=record_code && record_code<=7) || record_code==10){ 2469 2499 if(fread(&vector_type,sizeof(int),1,fid)!=1) _error_("Could not read vector_type"); 2470 2500 } -
issm/trunk-jpl/src/m/classes/SMBforcing.m
r21049 r21668 69 69 WriteData(fid,prefix,'name','md.smb.model','data',1,'format','Integer'); 70 70 WriteData(fid,prefix,'object',self,'class','smb','fieldname','mass_balance','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts); 71 %WriteData(fid,prefix,'object',self,'class','smb','fieldname','mass_balance','format','CompressedMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts); 71 72 72 73 %process requested outputs -
issm/trunk-jpl/src/m/solve/WriteData.m
r21144 r21668 168 168 fwrite(fid,data','double'); %get to the "c" convention, hence the transpose 169 169 end 170 % }}} 171 elseif strcmpi(format,'CompressedMat'), % {{{ 172 173 %Get size 174 s=size(data); 175 176 if s(1)==1 | s(2)==1, 177 %No need to use Compressed format 178 error('Not needed (should call WriteData with DoubleMat)'); 179 end 180 181 %first write length of record 182 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 183 if recordlength>2^31; error(['field ' name ' cannot be marshalled because it is larger than 2^31 bytes!']); end 184 fwrite(fid,recordlength,'int'); 185 186 %write data code and matrix type: 187 fwrite(fid,FormatToCode(format),'int'); 188 fwrite(fid,mattype,'int'); 189 190 %write matrix size 191 fwrite(fid,s(1),'int'); 192 fwrite(fid,s(2),'int'); 193 194 %Write offset and range 195 A = data(1:end-1,:); 196 offset = min(A(:)); 197 range = max(A(:)) - offset; 198 fwrite(fid,offset,'double'); 199 fwrite(fid,range,'double'); 200 201 %Convert data to uint8 and write it 202 A=uint8((A-offset)/range*255); 203 fwrite(fid,A','uint8'); %get to the "c" convention, hence the transpose 204 205 %Write last row as double (time) 206 fwrite(fid,data(end,:),'double'); 170 207 % }}} 171 208 elseif strcmpi(format,'MatArray'), % {{{ … … 258 295 elseif strcmpi(format,'StringArray'), 259 296 code=9; 297 elseif strcmpi(format,'CompressedMat'), 298 code=10; 260 299 else 261 300 error('FormatToCode error message: data type not supported yet!');
Note:
See TracChangeset
for help on using the changeset viewer.