help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading matrix-market format files in octave


From: Carlo de Falco
Subject: Re: reading matrix-market format files in octave
Date: Mon, 4 Dec 2006 11:32:57 +0100

David,
I had to apply the following modifications to mmread.m and mmwrite.m
to have them working properly under octave 2.9.4 (I am now using 2.9.9
and they still seem to work properly).


MMWRITE:
--------------------------------------------------------------

*** mmwrite.m.orig      Mon Dec  4 11:23:54 2006
--- mmwrite.m   Mon Aug 28 12:41:29 2006
***************
*** 1,4 ****
! function [ err ] = mmwrite(filename,A,comment,field,precision)
  %
  % Function: mmwrite(filename,A,comment,field,precision)
  %
--- 1,4 ----
! function [ err ] = mmwrite(filename,A,comment,mattype,precision)
  %
  % Function: mmwrite(filename,A,comment,field,precision)
  %
***************
*** 37,43 ****
  %

  if ( nargin == 5)
!   precision = 16;
  elseif ( nargin == 4)
    precision = 16;
  elseif ( nargin == 3)
--- 37,43 ----
  %

  if ( nargin == 5)
!   %precision = 16;
  elseif ( nargin == 4)
    precision = 16;
  elseif ( nargin == 3)
***************
*** 271,274 ****
--- 271,277 ----
    end
  end

+ err = 0;
+
  fclose(mmfile);
+
--------------------------------------------------------------


MMREAD:
--------------------------------------------------------------
*** mmread.m.orig       Mon Dec  4 11:23:44 2006
--- mmread.m    Mon Aug 28 12:41:29 2006
***************
*** 25,31 ****
   error('File not found');
  end;

! header = fgets(mmfile);
  if (header == -1 )
    error('Empty file.')
  end
--- 25,31 ----
   error('File not found');
  end;

! header = fgetl(mmfile);
  if (header == -1 )
    error('Empty file.')
  end
***************
*** 34,44 ****
  %       defined, substitute 'gettok' for 'strtok' in the
  %       following lines, and download gettok.m from the
  %       Matrix Market site.
! [head0,header]   = strtok(header);  % see note above
! [head1,header]   = strtok(header);
! [rep,header]     = strtok(header);
! [field,header]   = strtok(header);
! [symm,header]    = strtok(header);
  head1 = lower(head1);
  rep   = lower(rep);
  field = lower(field);
--- 34,44 ----
  %       defined, substitute 'gettok' for 'strtok' in the
  %       following lines, and download gettok.m from the
  %       Matrix Market site.
! [head0,header]   = gettok(header);  % see note above
! [head1,header]   = gettok(header);
! [rep,header]     = gettok(header);
! [field,header]   = gettok(header);
! [symm,header]    = gettok(header);
  head1 = lower(head1);
  rep   = lower(rep);
  field = lower(field);
***************
*** 69,77 ****
  % Read size information, then branch according to
  % sparse or dense format

  if ( strcmp(rep,'coordinate')) %  read matrix given in sparse
                                %  coordinate matrix format
!
    [sizeinfo,count] = sscanf(commentline,'%d%d%d');
    while ( count == 0 )
       commentline =  fgets(mmfile);
--- 69,82 ----
  % Read size information, then branch according to
  % sparse or dense format

+ ### CDF ###
+ usingsparse = 0;
+ ### END ###
  if ( strcmp(rep,'coordinate')) %  read matrix given in sparse
    %  coordinate matrix format
! ### CDF ###
!   usingsparse = 1;
! ### END ###
    [sizeinfo,count] = sscanf(commentline,'%d%d%d');
    while ( count == 0 )
       commentline =  fgets(mmfile);
***************
*** 206,221 ****
  % triangular part and modify entries as appropriate:
  %

! if ( strcmp(symm,'symmetric') )
     A = A + A.' - diag(diag(A));
     entries = nnz(A);
! elseif ( strcmp(symm,'hermitian') )
     A = A + A' - diag(diag(A));
     entries = nnz(A);
! elseif ( strcmp(symm,'skew-symmetric') )
     A = A - A';
     entries = nnz(A);
  end

  fclose(mmfile);
  % Done.
--- 211,245 ----
  % triangular part and modify entries as appropriate:
  %

! ### CDF ###
! if usingsparse
!
!   if ( strcmp(symm,'symmetric') )
!     A = A + A.' - spdiag(spdiag(A));
!     entries = nnz(A);
!   elseif ( strcmp(symm,'hermitian') )
!     A = A + A' - spdiag(spdiag(A));
!     entries = nnz(A);
!   elseif ( strcmp(symm,'skew-symmetric') )
!     A = A - A';
!     entries = nnz(A);
!   end
!
! else
!
!   if ( strcmp(symm,'symmetric') )
      A = A + A.' - diag(diag(A));
      entries = nnz(A);
!   elseif ( strcmp(symm,'hermitian') )
      A = A + A' - diag(diag(A));
      entries = nnz(A);
!   elseif ( strcmp(symm,'skew-symmetric') )
      A = A - A';
      entries = nnz(A);
+   end
+
  end
+ ### END ###

  fclose(mmfile);
  % Done.
--------------------------------------------------------------


Hope this helps,
Carlo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]