clear all
load science_mat.mat;

% Do name change...

t = time;
d = depth; 
chl = mass_concentration_of_chlorophyll_in_sea_water;
temp = sea_water_temperature;
salt = sea_water_salinity;
s470 = volume_scattering_470_nm;
s650 = volume_scattering_650_nm;
nit = mole_concentration_of_nitrate_in_sea_water;
o2 = mass_concentration_of_oxygen_in_sea_water;
lat = latitude;
long = longitude;

clear('time', 'depth', 'mass_concentration_of_chlorophyll_in_sea_water', 'sea_water_temperature', 'volume_scattering_470_nm','volume_scattering_650_nm');
clear('mole_concentration_of_nitrate_in_sea_water', 'mass_concentration_of_oxygen_in_sea_water', 'latitude', 'longitude');
% Remove NaNs and data repeats (where the value does not change) and adjust
% time for each variable.

nn = length(t);
disp(['Dataset size ' int2str(nn) ' points, '])

ii = (find(~isnan(d)));
td = t(ii);
d = d(ii);
new = find(~(diff(d)==0));
d = d(new+1);
td = td(new+1);
disp(['depth '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(lat)));
tlat = t(ii);
lat = lat(ii);
new = find(~(diff(lat)==0));
lat = lat(new+1);
tlat = tlat(new+1);
disp(['lat '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(long)));
tlong = t(ii);
long = long(ii);
new = find(~(diff(long)==0));
long = long(new+1);
tlong = tlong(new+1);
disp(['long '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(temp)));
ttemp = t(ii);
temp = temp(ii);
new = find(~(diff(temp)==0));
temp = temp(new+1);
ttemp = ttemp(new+1);
disp(['temp '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(salt)));
tsalt = t(ii);
salt = salt(ii);
new = find(~(diff(salt)==0));
salt = salt(new+1);
tsalt = tsalt(new+1);
disp(['salt '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(chl)));
tchl = t(ii);
chl = chl(ii);
new = find(~(diff(chl)==0));
chl = chl(new+1);
tchl = tchl(new+1);
disp(['chlf '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(s650)));
ts650 = t(ii);
s650 = s650(ii);
new = find(~(diff(s650)==0));
s650 = s650(new+1);
ts650 = ts650(new+1);
disp(['s650 '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(s470)));
ts470 = t(ii);
s470 = s470(ii);
new = find(~(diff(s470)==0));
s470 = s470(new+1);
ts470 = ts470(new+1);
disp(['s470 '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(nit)));
tnit = t(ii);
nit = nit(ii);
new = find(~(diff(nit)==0));
nit = nit(new+1);
tnit = tnit(new+1);
disp(['nit '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])

ii = (find(~isnan(o2)));
to2 = t(ii);
o2 = o2(ii);
new = find(~(diff(o2)==0));
o2 = o2(new+1);
to2 = to2(new+1);
disp(['o2 '  num2str(100*(nn-length(ii))/nn) '% NaNs and ' num2str(100*length(new)/(length(ii))) ' new'])
