function [ V, SNR, COR, time ] = winadv_read(filename, n_skip);
%======================================================================
%
% This program read winadv data from Sontek/Nortek Acoustic Doppler 
% Velocimetry (ADV).
%
% Input
%   filename :  file name for text formatted data from winadv
%   n_skip   :  number of column to be skipped as a header
%               this parameter is optional. If there is no input to
%               n_skip, 44 is automatically selected.
%
% Output
%   V        :  3D velocity component with (n,3) dimension
%   SNR      :  3D signal to noise ratio with (n,3) dimension
%   COR      :  3D correation with (n,3) dimension
%   time     :  time [s] with (n,1) dimension
%
% Example: [V,SNR,COR,time] = winadv_read('test.txt');
%
%
%======================================================================
% Terms:
%
%       Distributed under the terms of the terms of the 
%       GNU General Public License
%
% Copyright:
%
%========================================================================
%
% Update:
%       1.00    2004/09/01 Modified by Nobuhito Mori, Osaka City University
%       0.99    2004/09/01 Takuma Suzuki, Osaka City University
%
%========================================================================

n_in = nargin;
if n_in==1
  n_header = 44;
else
  n_header = n_skip;
end

[number,tmp,evnt,V0,Vx,Vy,Vz,Sx,Sy,Sz,Cx,Cy,Cz] = textread(filename, ...
  '%d %*s %*s %f %d %f %f %f %f %d %d %d %d %d %d','headerlines', n_header);

  V(:,1) = Vx;
  V(:,2) = Vy;
  V(:,3) = Vz;
  V(:,4) = V0;
SNR(:,1) = Sx;
SNR(:,2) = Sy;
SNR(:,3) = Sy;
COR(:,1) = Cx;
COR(:,2) = Cy;
COR(:,3) = Cy;

dt = abs(tmp(2)-tmp(1));
time = dt*(number-1);
