Changeset 21668


Ignore:
Timestamp:
04/12/17 15:49:49 (8 years ago)
Author:
Mathieu Morlighem
Message:

NEW: new marshall format for SMB using uint8

Location:
issm/trunk-jpl/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r21615 r21668  
    683683                                case 7:
    684684                                case 8:
     685                                case 10:
    685686                                        /*We are not interested in this record, too memory intensive. Skip it: */
    686687                                        /*skip: */
     
    825826                                        case 7: break; //do nothing. not interested in this type of data, which is memory intensive.
    826827                                        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.
    827829                                        case 9:
    828830                                                          ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     
    11321134        /*Set file pointer to beginning of the data: */
    11331135        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<<")");
    11351137
    11361138        /*Now fetch: */
     
    11501152        /*Now allocate matrix: */
    11511153        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        }
    11661196        /*Assign output pointers: */
    11671197        if(pM) *pM=M;
     
    15421572
    15431573        /*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");
    15451575
    15461576        this->FetchData(&doublearray,&M,&N,vector_name);
     
    24662496
    24672497                                /*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){
    24692499                                        if(fread(&vector_type,sizeof(int),1,fid)!=1) _error_("Could not read vector_type");
    24702500                                }
  • issm/trunk-jpl/src/m/classes/SMBforcing.m

    r21049 r21668  
    6969                        WriteData(fid,prefix,'name','md.smb.model','data',1,'format','Integer');
    7070                        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);
    7172                       
    7273                        %process requested outputs
  • issm/trunk-jpl/src/m/solve/WriteData.m

    r21144 r21668  
    168168                fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
    169169        end
     170        % }}}
     171elseif 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');
    170207        % }}}
    171208elseif strcmpi(format,'MatArray'), % {{{
     
    258295        elseif strcmpi(format,'StringArray'),
    259296                code=9;
     297        elseif strcmpi(format,'CompressedMat'),
     298                code=10;
    260299        else
    261300                error('FormatToCode error message: data type not supported yet!');
Note: See TracChangeset for help on using the changeset viewer.