%MAKE_LUT save ++
%+
% module
% ======
%
% ++
%
% DESCRIPTION
% ===========
%
% From ../LUT/lut_junge_nir.dat,
% ``make_lut`` produce a ASCII data file ../LUT/LUT_NIR.dat
% containing ++
%
% EXAMPLES
% ==========
%
% ::
%
% >> addpath('../toolbox')
% >> tp_mlp_aerosols_startup
% >> make_lut
%
% 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)
%
% EVOLUTIONS
% ==========
%
% $Id$
%
% - fplod 2009-08-13T16:05:03Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%    * add header
%    * heaven if no modification is needed by octave now, I use
%      tp_mlp_aerosols_startup in the example to point out IO directories
%      and path future modifications.
%      
%-

infile='../LUT/lut_junge_nir.dat';
outfile='../LUT/LUT_NIR.dat';

fid=fopen(infile,'r');
fgetl(fid);

lut=fscanf(fid,'%f',[9 inf]);
lut=lut';
fclose(fid);

I=find(lut(:,2)>=0.9 & lut(:,5)<200 & lut(:,6)<0.6);
lut=lut(I,:);

theta=[0:6:60];

Itheta=[];
for js=1:length(theta)
  for jv=1:length(theta)
    Itheta=union(Itheta,find(lut(:,3)==theta(js)&lut(:,4)==theta(jv)));
  end
end

lut=lut(Itheta,:);

[B,I,type]=unique(lut(:,1:2),'rows');

fid=fopen(outfile,'w');
fprintf(fid,'%d %f %f %f %f %f %f\n',[type' ; lut(:,[6 3 4 5 7 ... 8])']);
fclose(fid);
