function [res] = readCadenceOcnPrint( filename )
% function [res] = readCadenceOcnPrint( filename )
% Reads an output file from Cadence function ocnprint into a matlab variable
% It assumes that each line starting with anumeric value is a data line.
% Usually the first column is time and the second is the trace exported
% from ocnprint

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% first parse to determine size of matrix %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    f=fopen(filename);

    s=fgets(f);
    m=0;
    while ((-1~=s)&( isempty(regexp(s(1),'[\-0-9]')) ))
            s=fgets(f);
    end; %while
    [line,n]=sscanf(s,'%f');
    while (-1~=s)
        if ( ~isempty(regexp(s(1),'[\-0-9]')) )
            m=m+1;
        end; %if
        s=fgets(f);
   end; %while
    fclose(f);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % second parse to fill variable %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 f=fopen(filename);
 s=fgets(f);
 res=zeros(m,n);
 i=1;
    while (-1~=s)
        if ( ~isempty(regexp(s(1),'[\-0-9]')) )
            [res(i,:),n]=sscanf(s,'%f');
            i=i+1;
        end; %if
        s=fgets(f);
   end; %while
    fclose(f);
 
end

