%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%                    LATEXtools                         %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  This  file  is  free software ;  it  is distributed  in  %
%%  the hope that  it  will  be  useful,  but  without  any  %
%%  warranty.  You  can  redistribute  it and/or modify  it  %
%%  under  the  terms  of  the  GNU  General Public License  %
%%  as  published  by  the   Free  Software  Foundation  at  %
%%       http://www.gnu.org/copyleft/gpl.html                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% function load_TSG
%%
%% load TSG data from an .ASC file
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 26/11/2015 AD: modificated to simply read the .mat file prepared by P.Marrec 
%% 25/11/2015 AD: creation 
%% credits : louise.rousselet@mio.osupytheas.fr 
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [DATE_TIME_Cyto,DAY_Cyto,LON_Cyto,LAT_Cyto,TransectId_Cyto,...
Prochlo_ABD,Prochlo_Fper,Prochlo_Cper,...
Synecho_ABD,Synecho_Fper,Synecho_Cper,...
Pico_ABD,Pico_Fper,Pico_Cper,...
Crypto_ABD,Crypto_Fper,...;
Nano_ABD,Nano_Fper,Nano_Cper,...
Micro_ABD,Micro_Fper,...
shannon]=load_CYTO(fname)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load(fname);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Prochlo_ABD=ProchlorococcusAbd;
Synecho_ABD=SynechococcusAbd;
Pico_ABD=(Pico1Abd+Pico2Abd);
Crypto_ABD=Cryptophytes_likeAbd;
Nano_ABD=(Nano1Abd+Nano2Abd);
Micro_ABD=(Micro1Abd+Micro2Abd);

%Contribution of each cluster to the total Red Fluorescence recorded by the
%cytometer

ProchlorococcusFLRt=Prochlo_ABD.*ProchlorococcusFLRm;
SynechococcusFLRt=Synecho_ABD.*SynechococcusFLRm;
Pico1FLRt=Pico1Abd.*Pico1FLRm;
Pico2FLRt=Pico2Abd.*Pico2FLRm;
PicoTFLRt=Pico1FLRt+Pico2FLRt;
Cryptophytes_likeFLRt=Cryptophytes_likeAbd.*Cryptophytes_likeFLRm;
Nano1FLRt=Nano1Abd.*Nano1FLRm;
Nano2FLRt=Nano2Abd.*Nano2FLRm;
NanoTFLRt=Nano1FLRt+Nano2FLRt;
Micro1FLRt=Micro1Abd.*Micro1FLRm;
Micro2FLRt=Micro2Abd.*Micro2FLRm;
MicroTFLRt=Micro1FLRt+Micro2FLRt;
Unidentified2FLRt=Unidentified2Abd.*Unidentified2FLRm;

FLRt=[ProchlorococcusFLRt SynechococcusFLRt PicoTFLRt Cryptophytes_likeFLRt NanoTFLRt MicroTFLRt];% Unidentified2FLRt];
TotalFLR=sum(FLRt,2);

Prochlo_Fper = ProchlorococcusFLRt./TotalFLR*100;
Synecho_Fper = SynechococcusFLRt./TotalFLR*100;
Pico_Fper    = PicoTFLRt./TotalFLR*100;
Crypto_Fper  = Cryptophytes_likeFLRt./TotalFLR*100;
Nano_Fper    = NanoTFLRt./TotalFLR*100;
Micro_Fper   = MicroTFLRt./TotalFLR*100;
%Unidef_Fper  = Unidentified2FLRt./TotalFLR*100;

%FLRcontribution=[Prochlo_FLR Synecho_FLR Pico_FLR Crypto_FLR Nano_FLR Micro_TFLR];% Unidentified2FLR];

%Carbon biomass conversion factors (in fg C cell-1)
coeff_synecho=250;
coeff_prochlo=49;
coeff_pico=671;
coeff_nano=3498;

Prochlo_C = Prochlo_ABD*coeff_prochlo;
Synecho_C = Synecho_ABD*coeff_synecho;
Pico_C    = Pico_ABD*coeff_pico;
Nano_C    = Nano_ABD*coeff_nano;

Biomass_C = Prochlo_C+Synecho_C+Pico_C+Nano_C;

Prochlo_Cper = Prochlo_C./Biomass_C*100;
Synecho_Cper = Synecho_C./Biomass_C*100;
Pico_Cper    = Pico_C./Biomass_C*100;
Nano_Cper    = Nano_C./Biomass_C*100;

%BiomassC=[ProchlorococcusC SynechococcusC PicoTC NanoTC];

%BiomassCper=[ProchlorococcusCper SynechococcusCper PicoTCper NanoTCper];

shannon=(Prochlo_ABD + Synecho_ABD + Pico_ABD + ...
Crypto_ABD + Nano_ABD + Micro_ABD);


return

%function [numdate,lat,lon,sst,sss,fluo]=load_TSG(fname)
%
%	fid=fopen(fname);
%	data = textscan(fid,'%s %s %f %f %f %f %f %d %d');
%	fclose(fid);
%
%	date=data{1};
%	hour=data{2};
%
%[ismax,toto]=size(date);
%for is=1:ismax
%numdate=datenum([date{is},hour{is}],'mm/dd/yyyyHH:MM:SS');
%end
%	lat=data{3};
%	lon=data{4};
%	sst=data{5};
%	conductivity=data{6};
%	sss=data{7};
%	fluo=data{8};
%	unknown=data{9};
%
%return
