%% LOAD simrad data from NBP0104 simandmnow.pl
DAY=236;
        fid = fopen('day.dat','w');
        fprintf(fid,'%d',DAY);
        fclose(fid);


!perl simandmnow.pl % last run 212 to f220

 freak=['38 ';'120';'200';];               
[lengthofday,sd]=size(DAY);
%%freq=1;  %  38 khz
%%freq=2; % 120 kHz
%%freq=3; % 200 kHz
jetter=jet;
jetter=[0 0 0;jetter];
depths=[50 100 150 200 250]';
tlabels=['2000';'2100';'2200';'2300';'0000';'0100';...
        '0200';'0300';'0400';'0500';'0600';'0700';...
        '0800';'0900';'1000';'1100';'1200';'1300';...
        '1400';'1500';'1600';'1700';'1800';'1900'];
for i=1:lengthofday
    for freq=1:3
    simfile=['SIMf', num2str(DAY(i,:)), 'out', num2str(freq)];
    load([simfile,'.dat']);
    simtfile=['SIMf', num2str(DAY(i,:)), 'time', num2str(freq)];
   load([simtfile,'.dat']); 
[rsim, csim]=size(simfile);
    figure(freq);
colormap(jetter);
eval(['imagesc(rot90(fliplr(', simfile, ')), [-100 -40]);colorbar;'])
title(['NBP0104 Simrad ' freak(freq,:), 'kHz on Day:  ', num2str(DAY(i,:)) ]);
if (freq==1)
    set(gca, 'ytick', depths, 'yticklabel', num2str(depths.*4))
end
    eval(['difft=diff('simtfile '(:,2));']);
difft=[0; difft];
    eval(['timepoints =find(' simtfile '(:,3)==0 & (difft>0) );']);
eval(['timelabels='simtfile '(timepoints,2)+1']);
plottimelabels=tlabels(timelabels,:);
set(gca, 'xtick', timepoints, 'xticklabel', plottimelabels);
xlabel('Hour of Day (Local Time)'); ylabel('Depth (meters)');


orient landscape
pfile=([simfile, 'j3.jpg'])
print(gcf,'-djpeg99',  pfile)

end
end



