function [b,diag]=vprproc(vprdata)

% function [b,diag]=vprproc(vprdata)
% B: 10 columns containing:
%         1  dtime 
%         2  pcodelat 
%         3  pcodelon 
%         4  pressure
%         5  temperature
%         6  salinity
%         7  sigma t
%         8  fluorescence in volts 
%         9  chelsea fluor
%         10 li
%
% VPRDATA: 23 columns containing: 
%         1  yr
%         2  mon
%         3  dy
%         4  lhr
%         5  lmin
%         6  lsec
%         7  hr
%         8  mn
%         9  sc
%         10 frame
%         11 pcodelat
%         12 pcodelon
%         13 chirpz
%         14 roll
%         15 pitch
%         16 flowcount
%         17 tempcount
%         18 saltcount
%         19 fluorv
%         20 transv
%         21 altim
%         22 press
%         23 light
%         24 vprlatd
%         25 vprlatm
%         26 vprlond
%         27 vprlonm
%
% Calls STCA, JULIAN, DIST

% time of day in UT hours

ut = vprdata(:,7)         + ...
     vprdata(:,8)  / 60   + ...
     vprdata(:,9)  / 3600 + ...
     vprdata(:,10) / 3600 / 30 ;

% Calculate Daynum

dtime = julian(vprdata(:,1),vprdata(:,2),vprdata(:,3),ut)-...
	julian(vprdata(1,1),1,1,0);

% Calculate latitude and longitude from vpr gps data. 
%
% NOTE: Although the names of the variables are "pcodelat" and
% "pcodelon", these are really data from the VPR DGPS unit.

% $$$ pcodelat=vprdata(:,24)+vprdata(:,25)/60;
% $$$ pcodelon=vprdata(:,26)+vprdata(:,27)/60;

pcodelat=fix(vprdata(:,11) / 100) + ...
	 (( vprdata(:,11) / 100 - ...
	    fix(vprdata(:,11) / 100)) * 100) / 60;
pcodelon=fix( vprdata(:,12) / 100) + ...
	 (( vprdata(:,12) / 100 - ...
	    fix(vprdata(:,12) / 100)) * 100) / 60;

% Pressure

pr = ( vprdata(:,22) * 13.5381 + 0.0305) * 10;

% $$$ Determine which are good variables
% $$$ in=find(pcodelat>=42.3333 & pcodelat<=42.4500 &...
% $$$        pcodelon>=70.7050 & pcodelon<=70.8667);
% $$$ in=find(pcodelat>=39.5 & pcodelat<=43 &...
% $$$        pcodelon>=65 & pcodelon<=71);

%Run stca (wiebe.m)

[p,t,theta,s2,sigma,flvolt,lptr] = ...
    stca(pr,vprdata(:,17),vprdata(:,18),vprdata(:,19),vprdata(:,20));

li=(vprdata(:,23)*16.715);
lptr=vprdata(:,20);

%lptr(lptr<0)=0.;
%lptr=(.01*( (10.^lptr) - (10^1.05) )) ./ (1.027.^(t-9));

%Calculate cumulative distance between points using dglat and dglon 

[range,af,ar]=geodist(pcodelat,pcodelon);
range=[0; range/1000];
diag.totkm=cumsum(range);

%plotsetup;

b=[dtime pcodelat pcodelon pr t s2 sigma flvolt lptr li];
