%LOD_Eup_Stages_2.m

%In the euphausiid stages from NBP cruises for plotting by
%"Pl_Eup_Stages.m"

%do Bathymetry
load C:\MATBAK\basemap\antarctic\surface_12_2_C0_topo30_T25_1m.xyz
hold on
%v=[-600,-400,-200 -100];
lonb = surface_12_2_C0_topo30_T25_1m(:,1);
latb =surface_12_2_C0_topo30_T25_1m(:,2);
elevations=surface_12_2_C0_topo30_T25_1m(:,3);
lonb=reshape(lonb,781,361);
lonb=lonb(:,1)';
latb=reshape(latb,781,361);
latb=latb(1,:)';
elevations= (reshape(elevations,781,361))';
v=[0 -500, -1000];
%end of bathymetry

cstr= ['g';'b';'c';'r';'y';'k';'m']; % create string with color point designations
%set up plot
m_proj('albers equal-area','lat',[-70 -65],'long',[-76 -64],'rect','on');
disp('starting coastline extraction');
%m_gshhs_h('save','WAP'); %do this only when first doing extraction - rem it out after first use
disp('Finished saving westnatl');
%end setup plot
%hold on
cd C:\Antarctic\Antarctic\AO_synthesis\MOCNESS_Krill_sample_workup\EuphausiidDataCounts
%load in directory
d_info = dir; 
[d_row,d_col] = size(d_info);

% load up tow information for each cruise  - format is:
% cruiseid  year  station  tow  month_local  day_local  time_local lat         lon


for i = 7:14 %start with row 8 because first 6 are not good dat files
    nam = getfield(d_info(i),'name');
    eval(['load ' nam]); %load the data in for the given stage on a given cruise
end
disp('Finished Loading Cruise/Tow information');
whos
pause
%cd C:\Antarctic\Antarctic\AO_synthesis\MOCNESS_Krill_sample_workup\EuphausiidDataCounts\Etri
%cd C:\Antarctic\Antarctic\AO_synthesis\MOCNESS_Krill_sample_workup\EuphausiidDataCounts\Emacura
%cd C:\Antarctic\Antarctic\AO_synthesis\MOCNESS_Krill_sample_workup\EuphausiidDataCounts\Ecrystal
cd C:\Antarctic\Antarctic\AO_synthesis\MOCNESS_Krill_sample_workup\EuphausiidDataCounts\Esuperba
%load in directory
d_info = dir; 
[d_row,d_col] = size(d_info);

cnt =1; %This counter keeps track of the number of cruises processd (total should be four) 
%create variable to store sum of all stages abundance /m2 for each station and cruise
sumallstage=[];

for i = 5:d_row %start with row 5 because first 4 are not cruise files with the stage data
    nam = getfield(d_info(i),'name');
    stageNameCruise(cnt,:) = nam;
    eval(['load ' stageNameCruise(cnt,:)]); %load the data in for all stages on a given cruise
    cruiseid=nam(1,10:16)
    if (nam(1,18:21) == 'Tmac' | nam(1,18:21) == 'Etri')
        sortstage_mactri;
        %Pl_eup_total_2; % call the subroutine to plot the total abundance of all stages.
    else
        %don't use this Pl_eup_stages_2  % call the subroutine to plot the abundance of all stages.
        sortstage %use this to sort stages of superba or crysallorophias
        %sortstage_mactri;  %use this if just want total superba or crystallorophias
    end
   %return 
    %clear some variables
    clear abundance            dlat                 latjnet              scale6               
    clear                   dlon                 lon                  scale7               
    clear colr                 event                lonjnet              sp                   
    clear comments             f6                   month_local          stage                
    clear cruiseid             h1                   nam                      
    clear cstr                 h2                   net                  station              
    clear                h3                   no_counted           taxon                
    clear            h4                   numm2                taxon_group          
    clear                h5                   region               time_local           
    clear clear day_local            h6                   samp_fraction_denom  tow                  
    clear depth_close          h7                   scale1               towlen               
    clear depth_mid                               scale2               vol_filt             
    clear depth_open                              scale3               year                 
    clear depth_w              jnet                 scale4               yrday_local          
    clear displ_vol            lat                  scale5               
    
    clear abun  dopen dclose tw latt long num hmat is js  outstuff plotnam ct
    % end clear variabls
    
    
    

    cnt = cnt + 1;
end; % for i loop

