%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% M-file to make a comparison plot of the ADCP trancduce temperature
% and the surface ctd temp and the top microcat temp.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% define an array
fpath=['/data/span9/bahr/perlprogs/'];
mond=[0,31,59,90,120,151,181,212,243,273,305,334];
monn=[31,28,31,30,31,30,31,31,30,31,30,31];
monc=['jan',
      'feb',
      'mar',
      'apr',
      'may',
      'jun',
      'jul',
      'aug',
      'sep',
      'oct',
      'nov',
      'dec'];
% open file with mooring number which we will be working on
eval(['load ',fpath,'mooringid.dat']);
eval(['mid=mooringid;']);
% grab time
eval(['load ',fpath,'time.dat']);
eval(['gtime=time;']);
year=gtime(1);
month=gtime(2);
day=gtime(3);
hour=gtime(4);
minu=gtime(5);
sec=0;
yday=gtime(6);
yearo=year;
nowtime=datenum(year,month,day,hour,minu,sec);
% create the arrays that data loader needs to load data
stop=[year month];
if(month==1)&(day < 8),
	yearo=year-1;
	month=12;
end
if(day < 8)&(month ~=1),
		month=month-1;
end
start=[yearo month];
% load ctd data
	[ctd fctd]=dataloader(mid,start,stop,2);
% load microcat data
[t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 tt f1 f2 f3 f4 f5 f6 f7 f8 f9 f10]=dataloader(mid,start,stop,3);
% load adcp data
[atime au av auf avf agps agf atemp atf e cm g pg3 pg4]=dataloader(mid,start,stop,4);
clear au; clear av; clear auf; clear avf; clear agps;
clear agf; clear e; clear cm; clear g; clear pg3; clear pg4;
% clear other arrays
% keep only ADCP temp and it's flag
% need to check for empty arrays.
if isempty(atemp)==0,
	atemp=atemp(:,8);
	atf=atf(:,7);
end
clear t2; clear t3; clear t4; clear t5; clear t6; clear t7; clear t8; clear t9;
clear f2; clear f3; clear f4; clear f5; clear f6; clear f7; clear f8; clear f9;
clear f10; clear t10;
% now cut arrays down to just the time period we want to plot.
% Note times in the above arrays are in matlab time format
%nowtime=datenum(year,month,day,hour,minu,00);
pretime=nowtime-7;
% need to check if arrays are empty before doing the following.
if isempty(ctd)==0,
ll=(ctd(:,1) > pretime)&(ctd(:,1) <= nowtime);
ctd=ctd(ll,[1 3]); fctd=fctd(ll,2);
end
if isempty(t1)==0,
ll=(t1(:,1) > pretime)&(t1(:,1) <=nowtime);
t1=t1(ll,[1 4]); f1=f1(ll,3);
end
if isempty(atime)==0,
ll=(atime > pretime)&(atime <= nowtime);
atime=atime(ll); atemp=atemp(ll); atf=atf(ll);
end
surftplot(ctd,fctd,t1,f1,atime,atemp,atf);
quit
