Date: 2021-03-03T22:28:22+00:00

Actual source code: PetscReadBinaryMatlab.m
petsc-3.14.5 2021-03-03
Report Typos and Errors

      1: function Set = PetscReadBinaryMatlab(filename)
      2: % PETSCREADBINARYMATLAB - Reads and interprets matlab specific lines
      3: %   from the .info files produced by PetscViewerBinaryMatlab
      4: %
      5: %   Input filename can be the name of the binary file with or without
      6: %   the .info suffix
      7: %
      8: %   This function returns a single struct containing all objects submitted
      9: %   to the PetscViewerBinaryMatlab viewer.

     11:   matlabHeader = ['%$$ '; '#$$ ']; % string that marks a matlab line for evaluation (could be passed)
     12:   matlabHeaderLen = size(matlabHeader,2);

     14:   if (isempty(strfind(filename,'.info')))
     15:      filename = [filename,'.info'];
     16:   end
     17:   fid=fopen(filename,'r');
     18:   if (fid == -1)
     19:      error(sprintf('PetscReadBinaryMatlab: cannot load file %s',filename))
     20:   end
     21:   str=fgets(fid);
     22:   while (ischar(str))

     24:      % check for output lines that start matlabHeader
     25:      if strncmp(str,matlabHeader(1,:),matlabHeaderLen) || strncmp(str,matlabHeader(2,:),matlabHeaderLen)
     26:          str = str(1+matlabHeaderLen:end);

     28:               % check for old-style file open/close commands
     29:          if strfind(str,'fopen(Set.filename')
     30:             str = 'fd = PetscOpenFile(Set.filename);';
     31:          elseif strfind(str,'if (fd < 0) error'); % ignore this line
     32:             str = '%';
     33:          elseif strfind(str,'fclose(fd)');
     34:             str = 'close(fd);';
     35:          end

     37:          eval(str);
     38:      end
     39:      str=fgets(fid);
     40:   end
     41:   fclose(fid);
     42:   return