here is a possible implementation of textread.m:

function res = textread(file, formatstr, prop, val)

  if nargin<2
    print_usage;
  endif

  comment_flag=false;

  if nargin>2
    switch prop
      case "commentstyle"
        comment_flag=true;
        comment_val=val;
    endswitch
  endif

  # open file
  fid = fopen(file,"r");

  # parse format string
  idx=strfind(formatstr,"%")';
  specif=formatstr([idx,idx+1]);

  # create output structure
  n=length(idx);
  res=cell(n,1);

  # read line
  k = 1;
  while ~feof(fid)
    this = fgetl(fid);

    if comment_flag
      buffer=strjust(this,"left");
      if buffer(1)=="#"
        continue
      endif
    endif

    for m=1:n
      switch specif(m,:)
          case "%s"
            data=sscanf(this,"%s",1);
            res{m,k}=setstr(data);
            this=this(length(data)+2:end);
          case "%d"
            data=sscanf(this,"%s",1);
            res{m,k}=str2num(data);
            this=this(length(data)+2:end);
          case "%f"
            data=sscanf(this,"%s",1);
            res{m,k}=str2num(data);
            this=this(length(data)+2:end);
        endswitch
      endfor
      k++;
    endwhile

  # close file
  fclose(fid);

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to