% loads the moorSPICE CTD: piece of code used by calctd and cleansalt
% GlazeO, le 16/01/2015
%----------------------
% from read_bifurcation_nc by A. Ganachaud 2014
%-------------------------------------------
% read uncalibrated data files and match local sigmas
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ctd files
%-----------
fnamectd = strcat(dirctd, lower(cruiseName), '-all_ctd.nc');
ncdisp(fnamectd)

if gisensorT~=1
    disp('WARNING: taking secoundary Temperature data');
end
if gisensorS~=1
    disp('WARNING: taking secoundary Salinity data');
end
if gisensorO~=1
    disp('WARNING: taking secoundary Oxygen data');
end

actd.dpres=ncread(fnamectd,'PRES');

disp(['  Converting temperature from ITS-90 to IPTS-68'])
eval(sprintf(['actd.dtemp68=1.00024*ncread(fnamectd,' '''' 'TE0%d' '''' ');'],gisensorT));%UNESCO report, 1992
eval(sprintf(['actd.dsali=ncread(fnamectd,' '''' 'PSA%d' '''' ');'],gisensorS));
eval(sprintf(['actd.doxv=ncread(fnamectd,' '''' 'DOV%d' '''' ');'],gisensorO));
eval(sprintf(['actd.ddvdt=ncread(fnamectd,' '''' 'DVT%d' '''' ');'],gisensorO));
eval(sprintf(['actd.doxum=ncread(fnamectd,' '''' 'DO%d2' '''' ');'],gisensorO)); %for graphics only
%Does not load QCs at this point (it was not set, all to zero)
%eval(sprintf(['presqc=ncread(fnamectd,' '''' 'PRES_QC' '''' ');']));
%eval(sprintf(['atqc=ncread(fnamectd,' '''' 'TE01_QC' '''' ');']));
%eval(sprintf(['asqc=ncread(fnamectd,' '''' 'PSA1_QC' '''' ');']));
%eval(sprintf(['acoxvo_qc=ncread(fnamectd,' '''' 'DOV%d_QC' '''' ');'],gisensorO));

%-------------------------
% Modif glazeO -16/01/2015
% actd.dayd=ncread(fnamectd,'DAYD'); % Decimal Julian Days, time origin=0
% from REFERENCE_DATE_TIME
% actd.latx=ncread(fnamectd,'LATX');
% actd.lonx=ncread(fnamectd,'LONX');
% actd.profileid=ncread(fnamectd,'PROFILE');
actd.dayd=ncread(fnamectd,'TIME'); % Days since 1950/01/01
actd.latx=ncread(fnamectd,'LATITUDE'); % LATITUDE, degrees north from [-90;+90]
actd.lonx=ncread(fnamectd,'LONGITUDE'); % LONGITUDE, degrees east from [-180;+180]
actd.profileid=ncread(fnamectd,'PROFILE');
% end modif glazeO - 16/01/2015
%------------------------------
Stat=floor(actd.profileid/100);
Cast=actd.profileid-100*Stat;
actd.stat=Stat;
actd.cast=Cast;

%
%ctd. variable contains current ctd profile while actd contails all profiles
%
varstr={'ctd.dpres' 'ctd.dtemp68' 'ctd.dsali' 'ctd.doxv' 'ctd.ddvdt' 'ctd.doxum'};
