%MAKE_IMAGE_SW save ++

%+
% module
% ======
%
% ++
%
% DESCRIPTION
% ===========
%
% From ../Images/S1999251.L3m_DAY_T865_9 (HDF4 file)
% and ../Images/Valid_Pixels_251.dat (ASCII),
% ``make_image_sw.m`` produce an ASCII data file Tau_standard.dat
% containing ++
%
% EXAMPLES
% ========
%
% ::
%
% >> addpath('../toolbox')
% >> tp_mlp_aerosols_startup
% >> make_image_sw
%
% SEE ALSO
% ========
%
% tp_mlp_aerosols_startup.m_
%
% .. _tp_mlp_aerosols_startup.m : tp_mlp_aerosols_startup.m.html
%
% TODO
% ====
%
% improve description
%
% avoid overriding existing output file
%
% make it launchable from everywhere (path and IO directories)
%
% Find a way to read HDF4 file using octave or an equivalent of
% ../Images/S1999251.L3m_DAY_T865_9 in an other format (HDF5 or NetCDF)
%
% EVOLUTIONS
% ==========
%
% $Id$
%
% - fplod 2009-08-13T10:57:39Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%    * add header
%    * add octave save instruction (useless because for now HDF4 file
%      is not readable by octave)
%
%-

indir='../Images/';
cfile='S1999251.L3m_DAY_T865_9';
if (run_octave == 0)
 info=hdfinfo([indir cfile]);
else
 error(' eee : octave can not read HDF4 file');
end

Tau=hdfread([indir cfile],'l3m_data');

Slope=info.SDS.Attributes(3).Value;
Intercept=info.SDS.Attributes(4).Value;
Tau=double(Tau)*Slope + Intercept;
Tau(Tau>0.508)=nan;
[Lat0,Lon0]=meshgrid(linspace(-180,180,4320),linspace(90,-90,2160));
[Lat,Lon]=meshgrid(linspace(-9.5,41.5,1024),linspace(49,29,512));

Tau_interp=interp2(Lat0,Lon0,Tau,Lat,Lon,'nearest');

%mise au format des autres données
load([indir 'Valid_Pixels_251.dat']);
Tau_1d=nan*ones(size(Valid_Pixels_251));
Tau_1d=double(Tau_interp(Valid_Pixels_251));

if (run_octave == 0)
 save([indir 'Tau_standard.dat'],'Tau_1d','-ascii');
else
 save('-ascii',[indir 'Tau_standard.dat'],'Tau_1d');
end
