disp('ICEALOT_mailbox_daily');
%read in processed SCI daily file
clear all;
close all

pngflg = 1;

inpath = 'S:\ICEALOT_2008\KNORR\radiometer\Mailbox\Processed\12102009\SCI\';
outpath = 'S:\ICEALOT_2008\KNORR\radiometer\Mailbox\Processed_Images\'
%mday =input('Input monthday to evaluate (0401....): ','s');
% 0705 is YYMM
%fname=[inpath '2008' mday '.sci'];
fname=[inpath '*.sci'];
ls(fname)
s=outpath;

dr=dir(fname);
[n m]=size(dr);
mx=n;

for i=3:mx  %loop through days
    flnm=dr(i).name
    mbnm=[inpath flnm];
    
    mb = load(mbnm);
    
    %     YYYY mm dd hh mm ss type #freq azimuth elevation vapor liquid    CBT Stemp   Shumd Spres   tb1         tau1    tb2        tau2
    % 2008  4  1  0  2  0  2  2   0.000  90.000   1.51735 849.71052   0.00 279.01  85.30 996.70 51.710264  0.180841 55.389412  0.181232    0.000000    0.000000 0
    % 2008  4  1  0  2 16  2  2   0.000  90.000   1.62926 689.74856   0.00 279.01  85.30 996.70 48.762483  0.187857 48.839472  0.195159    0.000000    0.000000 0
    
    ln = length(mb);
    
    mb(:,24) = datenum(mb(:,1),mb(:,2),mb(:,3),mb(:,4),mb(:,5),mb(:,6))-datenum(mb(:,1)-1,12,31);
    bjd = fix(mb(1,24));
    ejd = bjd + 1;
    % Plot
    s='c:\data\icealot\data\Mailbox\Raw_Images\';
    
    figure;
    
    plot(mb(:,24),mb(:,11));axis([bjd ejd 0 8]);
    xlabel('Year Day (UTC)');ylabel('Integrated atmospheric water vapor (cm)');
    title('ICEALOT 2008')
    if pngflg
        print_buffer = [outpath 'ICEALOT_MWR_vap_' flnm(1:4) '_' flnm(5:6) '_' flnm(7:8) '.png'];
        print('-dpng ', print_buffer);
    end
    
    figure;
    
    plot(mb(:,24),mb(:,12)*1e-1);axis([bjd ejd -10 500]);
    xlabel('Year Day (UTC)');ylabel('Integrated cloud liquid content (g/m^2)');
    title('ICEALOT 2008')
    if pngflg
        print_buffer = [outpath 'ICEALOT_MWR_liq_' flnm(1:4) '_' flnm(5:6) '_' flnm(7:8) '.png'];
        print('-dpng ', print_buffer);
    end
    
    if 0
        figure(3)
        plot(daty(:,1),daty(:,5));
        %axis([bjd ejd 0 8]);
        hold
        plot(daty(:,1),daty(:,7),'r');
        axis([bjd ejd -10 300]);
        title('ICEALOT 2008')
        ylabel('TBs')
        xlabel('Year Day (UTC)')
        legend('20 GHz','30GHz')
        print_buffer = [s 'ICEALOT_MWR_TBs_' fname(1:2) '_' fname(3:4) '_' fname(5:6) '.png'];
        print('-dpng ', print_buffer);
        
        figure(4)
        subplot(2,1,1),plot(daty(:,1),daty(:,22),'k');
        title('ICEALOT 2008')
        ylabel('Degrees')
        legend('Pitch')
        subplot(2,1,2),plot(daty(:,1),daty(:,23),'k');
        axis([bjd ejd -10 10]);
        title('ICEALOT 2008')
        ylabel('Degrees')
        xlabel('Year Day (UTC)')
        legend('Roll')
        print_buffer = [s 'ICEALOT_MWR_PR_' fname(1:2) '_' fname(3:4) '_' fname(5:6) '.png'];
        print('-dpng ', print_buffer);
        
    end  %Skip plotting
    mwr(:,1) = mb(:,24);
    mwr(:,2) = mb(:,11);
    mwr(:,3) = mb(:,12);
    
    if 1
        f=[outpath 'ICEALOT_mwr_' flnm(3:8) '.txt'];
        flist=fopen(f,'w');
        save( f, 'mwr', '-ascii','-tabs')
        fclose('all');
    end;
    
    clear mwr mb
end % day loop
