

function plot_sbdart_output()

   for isalb = [1,6]
   for iaer  = [0,3]  
   
      datafile = ['./ex02','_',num2str(iaer,'%1d'),'_',num2str(isalb,'%1d'),'.out'];

      %-- read the SBDART out file.
      fid=fopen(datafile,'r');
      dat = textscan(fid, '%f', 'HeaderLines',3);
      fclose(fid);
   
      %-- reformat to a Matlab matrix
      dat = cell2mat(dat);
      dat = reshape(dat, 8,[]);
   
      %-- compute integrated broad band fluxes.
      dwl = dat(1,(2:end)) - dat(1,(1:end-1)); %wavelength increments.
      flx = bsxfun( @times, dwl, ( 0.5*(dat(:,2:end)+dat(:,1:end-1)) ) );
      flx = sum(flx,2);

         
      %-- display the flux values
      %   the SBDART output format for iout=1 is 
      %    1   2    3     4     5      6     7     8
      %    WL,FFV,TOPDN,TOPUP,TOPDIR,BOTDN,BOTUP,BOTDIR
      %
      disp(sprintf('iaer=%1d isalb=%1d: ',iaer,isalb));
      disp(sprintf(['Ftopdn=%-6.1f',...
                    'Ftopup=%-6.1f',...
                    'Fbotdn=%-6.1f',...
                    'Fbotup=%-6.1f',...
                    'Fbotdir=%-6.1f\n'], flx([3,4,6,7,8]) ))

      %-- save the spectral fluxes for later use.
      if     iaer==0 && isalb==6  datM.noAer_veg  = dat; 
      elseif iaer==0 && isalb==1  datM.noAer_snow = dat;
      elseif iaer==3 && isalb==6  datM.rural_veg  = dat;
      elseif iaer==3 && isalb==1  datM.rural_snow = dat; end
   
   end %--for iaer  = [0,3]  
   end %--for isalb = [1,6]


   wl = datM.noAer_veg(1,:); %wavelength 
   
   %-- plot difference between fluxes with and w/o aerosol.
   %
   diff = datM.rural_veg - datM.noAer_veg;
   figure(10);clf
   set(gca,'FontSize',16)
   plot(wl,diff([4,6],:)) %plot diff. of TOPUP and BOTDN
   grid on
   legend({'topup','botdn'},'Location','Best')
   title({['Difference between spectral fluxes with and w/o aerosol,'],...
          ['rural arosol over vegitation surface']})
   ylabel('W/m^2/{\mu}m');
   xlabel('Wavelength ({\mu}m)');


   diff = datM.rural_snow - datM.noAer_snow;
   figure(11);clf
   set(gca,'FontSize',16)
   plot(wl,diff([4,6],:)) %plot diff. of TOPUP and BOTDN
   grid on
   legend({'topup','botdn'},'Location','Best')
   title({['Difference between spectral fluxes with and w/o aerosol,'],...
          ['rural arosol over snow surface']})
   ylabel('W/m^2/{\mu}m');
   xlabel('Wavelength ({\mu}m)');

   
%keyboard
end
