clear all
close all

addpath /home/stephdut/matlab/m_map

 runstr=['surface_may'];
%runstr=['surface_allmonths'];
%runstr=['0to250m_may'];
%runstr=['0to250m_allmonths'];


(eval['filename=/nfs/mick001/stephdut/WORKSHOP/darwin_tranect_',runstr,'.nc']);
lat=ncread(filename,'lat');
depth=ncread(filename,'depth');
month=ncread(filename,'month');
biomass=ncread(filename,'biomass');

ntim=length(month);
ndep=length(depth);
ny=length(lat);

eval['filename=/nfs/mick001/stephdut/WORKSHOP/workshop_breycurtis_forinfomap_',runstr,'.nc']);

matrixCB=ncread(filename,'CBmatrix');
matrixLat=ncread(filename,'matrixLat');
matrixDepth=ncread(filename,'matrixDepth');
matrixMonth=ncread(filename,'matrixTime');

thresht=[2:9]; nthresh=length(thresht);
if (ndep==1 & ntim==1), mmemb=zeros(ny,nthresh); end
if (ndep>1 & ntim==1), mmemb=zeros(ny,ndep,nthresh); end
if (ndep==1 & ntim>1), mmemb=zeros(ny,ntim,nthresh); end
if (ndep>1 & ntim>1), mmemb=zeros(ny,ndep,ntim,nthresh); end

threshs=thresht/10;
for itr=thresht,
  itr1=itr1+1;
  thresh=['th',num2str(itr)];
  eval(['load /nfs/micklab001/stephdut/WORKSHOP/INFOMAP/workshop_breycurtis_forinfomap_',runstr,'_',thresh,'.infomapmemb']);
  eval(['tmp=',runstr,'_',thresh,';']);

 infolat=tmp(:,1);
 infodepth=tmp(:,2);
 informonth=tmp(:,3);
 infomemb=tmp(:,4)+1;

 maxmm=max(infomemb)+1;

 ld1=depth(1); ld2=depth(ndep);
 lt1=lat(1); lt2=lat(ny);
 lm1=month(1); lm2=month(ntim);
 for imon=lm1:lm2,
  for idep=ld1:ld2,
   for ilat=lt1:lt2
    fi=find(infomon==imon & infodep==idep & ...
            infolat==ilat)
    if (ndep==1 & ntim==1), mmemb(ilat,itr1)=memb(fi); end
    if (ndep>1 & ntim==1), mmemb(ilat,idep,itr1)=memb(fi); end
    if (ndep==1 & ntim>1), mmemb(ilat,imon,itr1)=memb(fi); end
    if (ndep>1 & ntim>1), mmemb(ilat,idep,imon,itr1)=memb(fi); end
   end % ilat
  end % idep
 end % imon
end % for itr
fi=find(mmemb==0); mmemb(fi)=NaN;


pltnt=1;
if (pltnt==1),
 figure
 colormap('colorcube'); cmap=colormap;
 colormap(cmap([27 8 9 13 7 3 25 21 17 19 23 4 1 48 ],:));
%
 for itr=1:itr1,
  tmp=squeeze(smmembr(1,itr,:,:));
  subplot(3,4,itr)
  pcolor(lat,depth,tmp'); shading flat
 end % for itr

end % if
